ContactPanelShort: Use REST API to update account name and preferred email
Change-Id: I57dd5f6d527653c79e001076f3fad5d76874d49e
This commit is contained in:

committed by
Edwin Kempin

parent
dd884f9e3b
commit
576df448d7
@@ -83,6 +83,14 @@ public class AccountApi {
|
|||||||
new RestApi("/accounts/").id(account).view("name").get(cb);
|
new RestApi("/accounts/").id(account).view("name").get(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set the account name */
|
||||||
|
public static void setName(String account, String name,
|
||||||
|
AsyncCallback<NativeString> cb) {
|
||||||
|
AccountNameInput input = AccountNameInput.create();
|
||||||
|
input.name(name);
|
||||||
|
new RestApi("/accounts/").id(account).view("name").put(input, cb);
|
||||||
|
}
|
||||||
|
|
||||||
/** Retrieve email addresses */
|
/** Retrieve email addresses */
|
||||||
public static void getEmails(String account,
|
public static void getEmails(String account,
|
||||||
AsyncCallback<JsArray<EmailInfo>> cb) {
|
AsyncCallback<JsArray<EmailInfo>> cb) {
|
||||||
@@ -97,6 +105,13 @@ public class AccountApi {
|
|||||||
.ifNoneMatch().put(in, cb);
|
.ifNoneMatch().put(in, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set preferred email address */
|
||||||
|
public static void setPreferredEmail(String account, String email,
|
||||||
|
AsyncCallback<NativeString> cb) {
|
||||||
|
new RestApi("/accounts/").id(account).view("emails")
|
||||||
|
.id(email).view("preferred").put(cb);
|
||||||
|
}
|
||||||
|
|
||||||
/** Retrieve SSH keys */
|
/** Retrieve SSH keys */
|
||||||
public static void getSshKeys(String account,
|
public static void getSshKeys(String account,
|
||||||
AsyncCallback<JsArray<SshKeyInfo>> cb) {
|
AsyncCallback<JsArray<SshKeyInfo>> cb) {
|
||||||
@@ -227,6 +242,17 @@ public class AccountApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class AccountNameInput extends JavaScriptObject {
|
||||||
|
final native void name(String n) /*-{ if(n)this.name=n; }-*/;
|
||||||
|
|
||||||
|
static AccountNameInput create() {
|
||||||
|
return createObject().cast();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AccountNameInput() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void addGpgKey(String account, String armored,
|
public static void addGpgKey(String account, String armored,
|
||||||
AsyncCallback<NativeMap<GpgKeyInfo>> cb) {
|
AsyncCallback<NativeMap<GpgKeyInfo>> cb) {
|
||||||
new RestApi("/accounts/")
|
new RestApi("/accounts/")
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
package com.google.gerrit.client.account;
|
package com.google.gerrit.client.account;
|
||||||
|
|
||||||
import com.google.gerrit.client.ErrorDialog;
|
import com.google.gerrit.client.ErrorDialog;
|
||||||
import com.google.gerrit.client.FormatUtil;
|
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
import com.google.gerrit.client.info.AccountInfo;
|
import com.google.gerrit.client.info.AccountInfo;
|
||||||
import com.google.gerrit.client.rpc.CallbackGroup;
|
import com.google.gerrit.client.rpc.CallbackGroup;
|
||||||
@@ -46,7 +45,6 @@ import com.google.gwt.user.client.ui.VerticalPanel;
|
|||||||
import com.google.gwt.user.client.ui.Widget;
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||||
import com.google.gwtexpui.user.client.AutoCenterDialogBox;
|
import com.google.gwtexpui.user.client.AutoCenterDialogBox;
|
||||||
import com.google.gwtjsonrpc.common.AsyncCallback;
|
|
||||||
|
|
||||||
class ContactPanelShort extends Composite {
|
class ContactPanelShort extends Composite {
|
||||||
protected final FlowPanel body;
|
protected final FlowPanel body;
|
||||||
@@ -146,7 +144,7 @@ class ContactPanelShort extends Composite {
|
|||||||
save.addClickHandler(new ClickHandler() {
|
save.addClickHandler(new ClickHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final ClickEvent event) {
|
public void onClick(final ClickEvent event) {
|
||||||
doSave(null);
|
doSave();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -347,10 +345,13 @@ class ContactPanelShort extends Composite {
|
|||||||
inEmail.setFocus(true);
|
inEmail.setFocus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doSave(final AsyncCallback<Account> onSave) {
|
void doSave() {
|
||||||
String newName = canEditFullName() ? nameTxt.getText() : null;
|
final String newName;
|
||||||
if (newName != null && newName.trim().isEmpty()) {
|
String name = canEditFullName() ? nameTxt.getText() : null;
|
||||||
|
if (name != null && name.trim().isEmpty()) {
|
||||||
newName = null;
|
newName = null;
|
||||||
|
} else {
|
||||||
|
newName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String newEmail;
|
final String newEmail;
|
||||||
@@ -368,24 +369,40 @@ class ContactPanelShort extends Composite {
|
|||||||
save.setEnabled(false);
|
save.setEnabled(false);
|
||||||
registerNewEmail.setEnabled(false);
|
registerNewEmail.setEnabled(false);
|
||||||
|
|
||||||
Util.ACCOUNT_SEC.updateContact(newName, newEmail,
|
CallbackGroup group = new CallbackGroup();
|
||||||
new GerritCallback<Account>() {
|
if (!newEmail.equals(currentEmail)) {
|
||||||
@Override
|
AccountApi.setPreferredEmail("self", newEmail,
|
||||||
public void onSuccess(Account result) {
|
group.add(new GerritCallback<NativeString>() {
|
||||||
registerNewEmail.setEnabled(true);
|
@Override
|
||||||
onSaveSuccess(FormatUtil.asInfo(result));
|
public void onSuccess(NativeString result) {
|
||||||
if (onSave != null) {
|
}
|
||||||
onSave.onSuccess(result);
|
}));
|
||||||
}
|
}
|
||||||
}
|
AccountApi.setName("self", newName,
|
||||||
|
group.add(new GerritCallback<NativeString>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(NativeString result) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(final Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
save.setEnabled(true);
|
save.setEnabled(true);
|
||||||
registerNewEmail.setEnabled(true);
|
registerNewEmail.setEnabled(true);
|
||||||
super.onFailure(caught);
|
super.onFailure(caught);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
group.done();
|
||||||
|
group.addListener(new GerritCallback<Void>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Void result) {
|
||||||
|
currentEmail = newEmail;
|
||||||
|
AccountInfo me = Gerrit.getUserAccount();
|
||||||
|
me.email(currentEmail);
|
||||||
|
me.name(newName);
|
||||||
|
onSaveSuccess(me);
|
||||||
|
registerNewEmail.setEnabled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void onSaveSuccess(AccountInfo result) {
|
void onSaveSuccess(AccountInfo result) {
|
||||||
|
Reference in New Issue
Block a user