Merge "Move user info, settings, and logout to popup dialog"
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.google.gwtexpui.user.client.PluginSafePopupPanel;
|
||||
|
||||
public class CurrentUserPopupPanel extends PluginSafePopupPanel {
|
||||
interface Binder extends UiBinder<Widget, CurrentUserPopupPanel> {
|
||||
}
|
||||
|
||||
private static final Binder binder = GWT.create(Binder.class);
|
||||
|
||||
@UiField
|
||||
Label userName;
|
||||
@UiField
|
||||
Label userEmail;
|
||||
@UiField
|
||||
Anchor logout;
|
||||
|
||||
public CurrentUserPopupPanel(Account account, boolean canLogOut) {
|
||||
super(/* auto hide */true, /* modal */false);
|
||||
setWidget(binder.createAndBindUi(this));
|
||||
setStyleName(Gerrit.RESOURCES.css().userInfoPopup());
|
||||
if (account.getFullName() != null) {
|
||||
userName.setText(account.getFullName());
|
||||
}
|
||||
if (account.getPreferredEmail() != null) {
|
||||
userEmail.setText(account.getPreferredEmail());
|
||||
}
|
||||
if (!canLogOut) {
|
||||
logout.setVisible(false);
|
||||
} else {
|
||||
logout.setHref(Gerrit.selfRedirect("/logout"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2012 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
|
||||
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
|
||||
<ui:with field='constants' type='com.google.gerrit.client.GerritConstants'/>
|
||||
<ui:import field='com.google.gerrit.common.PageLinks.SETTINGS'/>
|
||||
|
||||
<ui:style>
|
||||
.panel {
|
||||
padding: 8px;
|
||||
}
|
||||
.userName {
|
||||
font-weight: bold;
|
||||
}
|
||||
.email {
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
.logout {
|
||||
padding-left: 16px;
|
||||
float: right;
|
||||
}
|
||||
</ui:style>
|
||||
|
||||
<g:FlowPanel styleName="{style.panel}">
|
||||
<g:Label ui:field='userName' styleName="{style.userName}" />
|
||||
<g:Label ui:field='userEmail' styleName="{style.email}" />
|
||||
<g:Anchor href='{SETTINGS}'>
|
||||
<ui:text from='{constants.menuSettings}' />
|
||||
</g:Anchor>
|
||||
<g:Anchor ui:field='logout' styleName="{style.logout}">
|
||||
<ui:text from='{constants.menuSignOut}' />
|
||||
</g:Anchor>
|
||||
</g:FlowPanel>
|
||||
</ui:UiBinder>
|
@@ -155,6 +155,16 @@ public class FormatUtil {
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an account name.
|
||||
* <p>
|
||||
* If the account has a full name, it returns only the full name. Otherwise it
|
||||
* returns a longer form that includes the email address.
|
||||
*/
|
||||
public static String name(final Account acct) {
|
||||
return name(new AccountInfo(acct));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an account name.
|
||||
* <p>
|
||||
|
@@ -53,6 +53,11 @@ import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.ScriptInjector;
|
||||
import com.google.gwt.dom.client.AnchorElement;
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyDownEvent;
|
||||
import com.google.gwt.event.dom.client.KeyDownHandler;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.event.shared.EventBus;
|
||||
@@ -68,6 +73,7 @@ import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||
import com.google.gwt.user.client.ui.FocusPanel;
|
||||
import com.google.gwt.user.client.ui.InlineHTML;
|
||||
import com.google.gwt.user.client.ui.InlineLabel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
@@ -504,8 +510,8 @@ public class Gerrit implements EntryPoint {
|
||||
gTopMenu.add(menuLine);
|
||||
final FlowPanel menuRightPanel = new FlowPanel();
|
||||
menuRightPanel.setStyleName(RESOURCES.css().topmenuMenuRight());
|
||||
menuRightPanel.add(menuRight);
|
||||
menuRightPanel.add(searchPanel);
|
||||
menuRightPanel.add(menuRight);
|
||||
menuLine.setWidget(0, 0, menuLeft);
|
||||
menuLine.setWidget(0, 1, new FlowPanel());
|
||||
menuLine.setWidget(0, 2, menuRightPanel);
|
||||
@@ -702,11 +708,7 @@ public class Gerrit implements EntryPoint {
|
||||
}
|
||||
|
||||
if (signedIn) {
|
||||
whoAmI();
|
||||
addLink(menuRight, C.menuSettings(), PageLinks.SETTINGS);
|
||||
if (cfg.getAuthType() != AuthType.CLIENT_SSL_CERT_LDAP) {
|
||||
menuRight.add(anchor(C.menuSignOut(), selfRedirect("/logout")));
|
||||
}
|
||||
whoAmI(cfg.getAuthType() != AuthType.CLIENT_SSL_CERT_LDAP);
|
||||
} else {
|
||||
switch (cfg.getAuthType()) {
|
||||
case HTTP:
|
||||
@@ -771,11 +773,39 @@ public class Gerrit implements EntryPoint {
|
||||
}
|
||||
}
|
||||
|
||||
private static void whoAmI() {
|
||||
final String name = FormatUtil.nameEmail(getUserAccount());
|
||||
final InlineLabel l = new InlineLabel(name);
|
||||
private static void whoAmI(boolean canLogOut) {
|
||||
Account account = getUserAccount();
|
||||
final CurrentUserPopupPanel userPopup =
|
||||
new CurrentUserPopupPanel(account, canLogOut);
|
||||
final InlineLabel l = new InlineLabel(FormatUtil.name(account) + " ▾");
|
||||
l.setStyleName(RESOURCES.css().menuBarUserName());
|
||||
menuRight.add(l);
|
||||
l.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
if (userPopup.isShowing()) {
|
||||
userPopup.hide();
|
||||
} else {
|
||||
userPopup.showRelativeTo(l);
|
||||
}
|
||||
}
|
||||
});
|
||||
userPopup.addAutoHidePartner(l.getElement());
|
||||
FocusPanel fp = new FocusPanel(l);
|
||||
fp.setStyleName(RESOURCES.css().menuBarUserNameFocusPanel());
|
||||
fp.addKeyDownHandler(new KeyDownHandler() {
|
||||
@Override
|
||||
public void onKeyDown(KeyDownEvent event) {
|
||||
if(event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
|
||||
if (userPopup.isShowing()) {
|
||||
userPopup.hide();
|
||||
} else {
|
||||
userPopup.showRelativeTo(l);
|
||||
}
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
menuRight.add(fp);
|
||||
}
|
||||
|
||||
private static Anchor anchor(final String text, final String to) {
|
||||
|
@@ -150,6 +150,7 @@ public interface GerritCss extends CssResource {
|
||||
String linkMenuBar();
|
||||
String linkMenuItemNotLast();
|
||||
String menuBarUserName();
|
||||
String menuBarUserNameFocusPanel();
|
||||
String menuItem();
|
||||
String menuScreenMenuBar();
|
||||
String missingApproval();
|
||||
@@ -219,6 +220,7 @@ public interface GerritCss extends CssResource {
|
||||
String topmost();
|
||||
String topMostCell();
|
||||
String useridentity();
|
||||
String userInfoPopup();
|
||||
String usernameField();
|
||||
String version();
|
||||
String watchedProjectFilter();
|
||||
|
@@ -226,6 +226,7 @@ a:hover {
|
||||
font-size: 9pt;
|
||||
display: inline;
|
||||
white-space: nowrap;
|
||||
padding-left: 6px;
|
||||
}
|
||||
.menuItem {
|
||||
padding-left: 5px;
|
||||
@@ -305,9 +306,19 @@ a:hover {
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
.menuBarUserNameFocusPanel {
|
||||
display: inline;
|
||||
}
|
||||
.userInfoPopup {
|
||||
border: 1px solid black;
|
||||
background: white;
|
||||
box-shadow: 3px 3px 5px #888;
|
||||
}
|
||||
.searchPanel {
|
||||
white-space: nowrap;
|
||||
display: inline;
|
||||
}
|
||||
.searchPanel .gwt-TextBox {
|
||||
font-size: 9pt;
|
||||
|
Reference in New Issue
Block a user