Minor cleanups for current user popup panel

Wrap the two links (Settings, Sign-Out) into a single div and supply a
min-width of 175px.  This prevents them from collapsing in an odd two
line display when there is no avatar present.

Remove the div altogether when viewing another user's popup panel,
rather than just hiding the links.  This makes the DOM slightly
smaller for the common case of viewing someone else's information.

Change-Id: I96c3e37ef8799b8b86a56e3a8b4a960860b2373a
This commit is contained in:
Shawn Pearce
2013-08-27 22:54:56 -07:00
parent cf61ee1f66
commit 522848d5cc
2 changed files with 36 additions and 33 deletions

View File

@@ -16,8 +16,8 @@ package com.google.gerrit.client;
import com.google.gerrit.client.account.AccountInfo;
import com.google.gerrit.client.ui.InlineHyperlink;
import com.google.gerrit.common.PageLinks;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Anchor;
@@ -26,32 +26,21 @@ import com.google.gwt.user.client.ui.Widget;
import com.google.gwtexpui.user.client.PluginSafePopupPanel;
public class UserPopupPanel extends PluginSafePopupPanel {
interface Binder extends UiBinder<Widget, UserPopupPanel> {
}
interface Binder extends UiBinder<Widget, UserPopupPanel> {}
private static final Binder binder = GWT.create(Binder.class);
@UiField(provided = true)
AvatarImage avatar;
@UiField
Label userName;
@UiField
Label userEmail;
@UiField
Anchor logout;
@UiField
InlineHyperlink settings;
@UiField(provided = true) AvatarImage avatar;
@UiField Label userName;
@UiField Label userEmail;
@UiField Element userLinks;
@UiField Anchor logout;
@UiField InlineHyperlink settings;
public UserPopupPanel(AccountInfo account, boolean canLogOut,
boolean showSettingsLink) {
super(/* auto hide */true, /* modal */false);
avatar = new AvatarImage(account, 100, false);
setWidget(binder.createAndBindUi(this));
// We must show and then hide this popup so that it is part of the DOM.
// Otherwise the image does not get any events. Calling hide() would
// remove it from the DOM so we use setVisible(false) instead.
show();
setVisible(false);
setStyleName(Gerrit.RESOURCES.css().userInfoPopup());
if (account.name() != null) {
userName.setText(account.name());
@@ -59,15 +48,24 @@ public class UserPopupPanel extends PluginSafePopupPanel {
if (account.email() != null) {
userEmail.setText(account.email());
}
if (canLogOut) {
logout.setHref(Gerrit.selfRedirect("/logout"));
} else {
logout.setVisible(false);
}
if (showSettingsLink) {
settings.setTargetHistoryToken(PageLinks.SETTINGS);
if (canLogOut) {
logout.setHref(Gerrit.selfRedirect("/logout"));
} else {
logout.setVisible(false);
}
} else {
settings.setVisible(false);
settings.removeFromParent();
settings = null;
userLinks.removeFromParent();
userLinks = null;
logout = null;
}
// We must show and then hide this popup so that it is part of the DOM.
// Otherwise the image does not get any events. Calling hide() would
// remove it from the DOM so we use setVisible(false) instead.
show();
setVisible(false);
}
}

View File

@@ -36,6 +36,9 @@ limitations under the License.
.userName {
font-weight: bold;
}
.userLinks {
min-width: 175px;
}
.email {
padding-bottom: 6px;
}
@@ -52,11 +55,13 @@ limitations under the License.
<g:Label ui:field='userName' styleName="{style.userName}" />
<g:Label ui:field='userEmail' styleName="{style.email}" />
</td></tr></table>
<u:InlineHyperlink ui:field='settings'>
<ui:msg>Settings</ui:msg>
</u:InlineHyperlink>
<g:Anchor ui:field='logout' styleName="{style.logout}">
<ui:text from='{constants.menuSignOut}' />
</g:Anchor>
<div ui:field='userLinks' class='{style.userLinks}'>
<u:InlineHyperlink ui:field='settings' targetHistoryToken='/settings/'>
<ui:msg>Settings</ui:msg>
</u:InlineHyperlink>
<g:Anchor ui:field='logout' styleName="{style.logout}">
<ui:text from='{constants.menuSignOut}' />
</g:Anchor>
</div>
</g:HTMLPanel>
</ui:UiBinder>
</ui:UiBinder>