Adapt WebUI to use REST endpoint to retrieve emails of an account

Change-Id: I637b7e17fc5025460c61be5b1fcda990b22491c5
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-06-03 16:13:02 +02:00
committed by Edwin Kempin
parent c950bcca7e
commit 20092b132e
3 changed files with 50 additions and 33 deletions

View File

@@ -29,9 +29,15 @@ import java.util.Set;
* accounts.
*/
public class AccountApi {
/** Retrieve email addresses */
public static void getEmails(String account,
AsyncCallback<JsArray<EmailInfo>> cb) {
new RestApi("/accounts/").id(account).view("emails").get(cb);
}
/** Register a new email address */
public static void registerEmail(String account, String email,
AsyncCallback<NativeString> cb) {
AsyncCallback<EmailInfo> cb) {
JavaScriptObject in = JavaScriptObject.createObject();
new RestApi("/accounts/").id(account).view("emails").id(email)
.ifNoneMatch().put(in, cb);

View File

@@ -17,15 +17,15 @@ package com.google.gerrit.client.account;
import com.google.gerrit.client.ErrorDialog;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.ui.OnEditEnabler;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gerrit.reviewdb.client.AccountExternalId;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.ContactInformation;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
@@ -46,12 +46,6 @@ import com.google.gwtexpui.globalkey.client.NpTextBox;
import com.google.gwtexpui.user.client.AutoCenterDialogBox;
import com.google.gwtjsonrpc.common.AsyncCallback;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class ContactPanelShort extends Composite {
protected final FlowPanel body;
protected int labelIdx, fieldIdx;
@@ -210,28 +204,19 @@ class ContactPanelShort extends Composite {
postLoad();
}
});
Util.ACCOUNT_SEC
.myExternalIds(new GerritCallback<List<AccountExternalId>>() {
public void onSuccess(final List<AccountExternalId> result) {
if (!isAttached()) {
return;
}
final Set<String> emails = new HashSet<String>();
for (final AccountExternalId i : result) {
if (i.getEmailAddress() != null
&& i.getEmailAddress().length() > 0) {
emails.add(i.getEmailAddress());
}
}
final List<String> addrs = new ArrayList<String>(emails);
Collections.sort(addrs);
for (String s : addrs) {
emailPick.addItem(s);
}
haveEmails = true;
postLoad();
}
});
AccountApi.getEmails("self", new GerritCallback<JsArray<EmailInfo>>() {
@Override
public void onSuccess(JsArray<EmailInfo> result) {
if (!isAttached()) {
return;
}
for (EmailInfo i : Natives.asList(result)) {
emailPick.addItem(i.email());
}
haveEmails = true;
postLoad();
}
});
}
private void postLoad() {
@@ -284,9 +269,9 @@ class ContactPanelShort extends Composite {
inEmail.setEnabled(false);
register.setEnabled(false);
AccountApi.registerEmail("self", addr, new GerritCallback<NativeString>() {
AccountApi.registerEmail("self", addr, new GerritCallback<EmailInfo>() {
@Override
public void onSuccess(NativeString result) {
public void onSuccess(EmailInfo result) {
box.hide();
if (Gerrit.getConfig().getAuthType() == AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
currentEmail = addr;

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2013 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.account;
import com.google.gwt.core.client.JavaScriptObject;
public class EmailInfo extends JavaScriptObject {
public final native String email() /*-{ return this.email; }-*/;
public final native boolean isPreferred() /*-{ return this['preferred'] ? true : false; }-*/;
public final native boolean isConfirmationPending() /*-{ return this['pending_confirmation'] ? true : false; }-*/;
protected EmailInfo() {
}
}