Search in sources :

Example 6 with AccountInfo

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);
}
Also used : AccountInfo(com.google.gerrit.client.info.AccountInfo)

Example 7 with AccountInfo

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;
}
Also used : AvatarInfo(com.google.gerrit.client.info.AccountInfo.AvatarInfo) ArrayList(java.util.ArrayList) SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder) AccountInfo(com.google.gerrit.client.info.AccountInfo)

Example 8 with AccountInfo

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);
    }
}
Also used : NativeString(com.google.gerrit.client.rpc.NativeString) AccountInfo(com.google.gerrit.client.info.AccountInfo)

Example 9 with AccountInfo

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);
        }
    });
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) NativeString(com.google.gerrit.client.rpc.NativeString) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) NativeString(com.google.gerrit.client.rpc.NativeString) AccountInfo(com.google.gerrit.client.info.AccountInfo)

Example 10 with AccountInfo

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);
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ErrorDialog(com.google.gerrit.client.ErrorDialog) HTML(com.google.gwt.user.client.ui.HTML) NativeString(com.google.gerrit.client.rpc.NativeString) NpTextBox(com.google.gwtexpui.globalkey.client.NpTextBox) SubmitEvent(com.google.gwt.user.client.ui.FormPanel.SubmitEvent) GerritCallback(com.google.gerrit.client.rpc.GerritCallback) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) AutoCenterDialogBox(com.google.gwtexpui.user.client.AutoCenterDialogBox) FormPanel(com.google.gwt.user.client.ui.FormPanel) Button(com.google.gwt.user.client.ui.Button) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) AccountInfo(com.google.gerrit.client.info.AccountInfo)

Aggregations

AccountInfo (com.google.gerrit.client.info.AccountInfo)11 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)3 NativeString (com.google.gerrit.client.rpc.NativeString)3 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)3 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 FormPanel (com.google.gwt.user.client.ui.FormPanel)2 HTML (com.google.gwt.user.client.ui.HTML)2 AvatarImage (com.google.gerrit.client.AvatarImage)1 ErrorDialog (com.google.gerrit.client.ErrorDialog)1 EditPreferences (com.google.gerrit.client.account.EditPreferences)1 DocInfo (com.google.gerrit.client.documentation.DocInfo)1 AvatarInfo (com.google.gerrit.client.info.AccountInfo.AvatarInfo)1 GeneralPreferences (com.google.gerrit.client.info.GeneralPreferences)1 ServerInfo (com.google.gerrit.client.info.ServerInfo)1 InlineHyperlink (com.google.gerrit.client.ui.InlineHyperlink)1 SmallHeading (com.google.gerrit.client.ui.SmallHeading)1 HostPageData (com.google.gerrit.common.data.HostPageData)1 EditPreferencesInfo (com.google.gerrit.extensions.client.EditPreferencesInfo)1