use of com.google.gerrit.client.info.AccountInfo in project gerrit by GerritCodeReview.
the class ContactPanelShort method onSaveSuccess.
void onSaveSuccess(AccountInfo result) {
AccountInfo me = Gerrit.getUserAccount();
me.name(result.name());
me.email(result.email());
Gerrit.refreshMenuBar();
display(me);
}
use of com.google.gerrit.client.info.AccountInfo in project gerrit by GerritCodeReview.
the class Labels method formatUserList.
static SafeHtml formatUserList(ChangeScreen.Style style, Collection<? extends AccountInfo> in, Set<Integer> removable, String label, Map<Integer, VotableInfo> votable) {
List<AccountInfo> users = new ArrayList<>(in);
Collections.sort(users, new Comparator<AccountInfo>() {
@Override
public int compare(AccountInfo a, AccountInfo b) {
String as = name(a);
String bs = name(b);
if (as.isEmpty()) {
return 1;
} else if (bs.isEmpty()) {
return -1;
}
return as.compareTo(bs);
}
private String name(AccountInfo a) {
if (a.name() != null) {
return a.name();
} else if (a.email() != null) {
return a.email();
}
return "";
}
});
SafeHtmlBuilder html = new SafeHtmlBuilder();
Iterator<? extends AccountInfo> itr = users.iterator();
while (itr.hasNext()) {
AccountInfo ai = itr.next();
AvatarInfo img = ai.avatar(AvatarInfo.DEFAULT_SIZE);
String name;
if (ai.name() != null) {
name = ai.name();
} else if (ai.email() != null) {
name = ai.email();
} else {
name = Integer.toString(ai._accountId());
}
String votableCategories = "";
if (votable != null) {
VotableInfo vi = votable.get(ai._accountId());
if (vi != null) {
Set<String> s = vi.votableLabels();
if (!s.isEmpty()) {
StringBuilder sb = new StringBuilder(Util.C.votable());
sb.append(" ");
for (Iterator<String> it = vi.votableLabels().iterator(); it.hasNext(); ) {
sb.append(it.next());
if (it.hasNext()) {
sb.append(", ");
}
}
votableCategories = sb.toString();
}
}
}
html.openSpan().setAttribute("role", "listitem").setAttribute(DATA_ID, ai._accountId()).setAttribute("title", getTitle(ai, votableCategories)).setStyleName(style.label_user());
if (label != null) {
html.setAttribute(DATA_VOTE, label);
}
if (img != null) {
html.openElement("img").setStyleName(style.avatar()).setAttribute("src", img.url());
if (img.width() > 0) {
html.setAttribute("width", img.width());
}
if (img.height() > 0) {
html.setAttribute("height", img.height());
}
html.closeSelf();
}
html.append(name);
if (removable.contains(ai._accountId())) {
html.openElement("button");
if (label != null) {
html.setAttribute("title", Util.M.removeVote(label)).setAttribute("onclick", REMOVE_VOTE + "(event)");
} else {
html.setAttribute("title", Util.M.removeReviewer(name)).setAttribute("onclick", REMOVE_REVIEWER + "(event)");
}
html.append("×").closeElement("button");
}
html.closeSpan();
if (itr.hasNext()) {
html.append(' ');
}
}
return html;
}
use of com.google.gerrit.client.info.AccountInfo in project gerrit by GerritCodeReview.
the class GroupApi method addMembers.
/** Add members to a group. */
public static void addMembers(AccountGroup.UUID group, Set<String> members, final AsyncCallback<JsArray<AccountInfo>> cb) {
if (members.size() == 1) {
addMember(group, members.iterator().next(), new AsyncCallback<AccountInfo>() {
@Override
public void onSuccess(AccountInfo result) {
cb.onSuccess(Natives.arrayOf(result));
}
@Override
public void onFailure(Throwable caught) {
cb.onFailure(caught);
}
});
} else {
MemberInput input = MemberInput.create();
for (String member : members) {
input.addMember(member);
}
members(group).post(input, cb);
}
}
use of com.google.gerrit.client.info.AccountInfo in project gerrit by GerritCodeReview.
the class ContactPanelShort method doSave.
void doSave() {
final String newName;
String name = canEditFullName() ? nameTxt.getText() : null;
if (name != null && name.trim().isEmpty()) {
newName = null;
} else {
newName = name;
}
final String newEmail;
if (emailPick.isEnabled() && emailPick.getSelectedIndex() >= 0) {
final String v = emailPick.getValue(emailPick.getSelectedIndex());
if (Util.C.buttonOpenRegisterNewEmail().equals(v)) {
newEmail = currentEmail;
} else {
newEmail = v;
}
} else {
newEmail = currentEmail;
}
save.setEnabled(false);
registerNewEmail.setEnabled(false);
CallbackGroup group = new CallbackGroup();
if (currentEmail != null && !newEmail.equals(currentEmail)) {
AccountApi.setPreferredEmail("self", newEmail, group.add(new GerritCallback<NativeString>() {
@Override
public void onSuccess(NativeString result) {
}
}));
}
AccountApi.setName("self", newName, group.add(new GerritCallback<NativeString>() {
@Override
public void onSuccess(NativeString result) {
}
@Override
public void onFailure(Throwable caught) {
save.setEnabled(true);
registerNewEmail.setEnabled(true);
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);
}
});
}
use of com.google.gerrit.client.info.AccountInfo in project gerrit by GerritCodeReview.
the class ContactPanelShort method doRegisterNewEmail.
private void doRegisterNewEmail() {
if (!canRegisterNewEmail()) {
return;
}
final AutoCenterDialogBox box = new AutoCenterDialogBox(true, true);
final VerticalPanel body = new VerticalPanel();
final NpTextBox inEmail = new NpTextBox();
inEmail.setVisibleLength(60);
final Button register = new Button(Util.C.buttonSendRegisterNewEmail());
final Button cancel = new Button(Util.C.buttonCancel());
final FormPanel form = new FormPanel();
form.addSubmitHandler(new FormPanel.SubmitHandler() {
@Override
public void onSubmit(final SubmitEvent event) {
event.cancel();
final String addr = inEmail.getText().trim();
if (!addr.contains("@")) {
new ErrorDialog(Util.C.invalidUserEmail()).center();
return;
}
inEmail.setEnabled(false);
register.setEnabled(false);
AccountApi.registerEmail("self", addr, new GerritCallback<EmailInfo>() {
@Override
public void onSuccess(EmailInfo result) {
box.hide();
if (Gerrit.info().auth().isDev()) {
currentEmail = addr;
if (emailPick.getItemCount() == 0) {
AccountInfo me = Gerrit.getUserAccount();
me.email(addr);
onSaveSuccess(me);
} else {
save.setEnabled(true);
}
updateEmailList();
}
}
@Override
public void onFailure(final Throwable caught) {
inEmail.setEnabled(true);
register.setEnabled(true);
if (caught.getMessage().startsWith(EmailException.MESSAGE)) {
final ErrorDialog d = new ErrorDialog(caught.getMessage().substring(EmailException.MESSAGE.length()));
d.setText(Util.C.errorDialogTitleRegisterNewEmail());
d.center();
} else {
super.onFailure(caught);
}
}
});
}
});
form.setWidget(body);
register.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
form.submit();
}
});
cancel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
box.hide();
}
});
final FlowPanel buttons = new FlowPanel();
buttons.setStyleName(Gerrit.RESOURCES.css().patchSetActions());
buttons.add(register);
buttons.add(cancel);
if (!Gerrit.info().auth().isDev()) {
body.add(new HTML(Util.C.descRegisterNewEmail()));
}
body.add(inEmail);
body.add(buttons);
box.setText(Util.C.titleRegisterNewEmail());
box.setWidget(form);
box.center();
inEmail.setFocus(true);
}
Aggregations