Search in sources :

Example 1 with NativeString

use of com.google.gerrit.client.rpc.NativeString in project gerrit by GerritCodeReview.

the class MyProfileScreen method display.

void display(AccountInfo account) {
    if (Gerrit.info().plugin().hasAvatars()) {
        avatar.setAccount(account, 93, false);
        new RestApi("/accounts/").id("self").view("avatar.change.url").get(new AsyncCallback<NativeString>() {

            @Override
            public void onSuccess(NativeString changeUrl) {
                changeAvatar.setHref(changeUrl.asString());
                changeAvatar.setVisible(true);
            }

            @Override
            public void onFailure(Throwable caught) {
            }
        });
    }
    int row = 0;
    if (Gerrit.info().auth().siteHasUsernames()) {
        info.setWidget(row++, fieldIdx, new UsernameField());
    }
    info.setText(row++, fieldIdx, account.name());
    info.setText(row++, fieldIdx, account.email());
    info.setText(row++, fieldIdx, mediumFormat(account.registeredOn()));
    info.setText(row, fieldIdx, account.getId().toString());
}
Also used : NativeString(com.google.gerrit.client.rpc.NativeString) RestApi(com.google.gerrit.client.rpc.RestApi) GerritUiExtensionPoint(com.google.gerrit.client.GerritUiExtensionPoint)

Example 2 with NativeString

use of com.google.gerrit.client.rpc.NativeString in project gerrit by GerritCodeReview.

the class MyPasswordScreen method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    ExtensionPanel extensionPanel = createExtensionPoint(GerritUiExtensionPoint.PASSWORD_SCREEN_BOTTOM);
    extensionPanel.addStyleName(Gerrit.RESOURCES.css().extensionPanel());
    add(extensionPanel);
    if (password == null) {
        display();
        return;
    }
    enableUI(false);
    AccountApi.getUsername("self", new GerritCallback<NativeString>() {

        @Override
        public void onSuccess(NativeString user) {
            Gerrit.getUserAccount().username(user.asString());
            enableUI(true);
            display();
        }

        @Override
        public void onFailure(final Throwable caught) {
            if (RestApi.isNotFound(caught)) {
                Gerrit.getUserAccount().username(null);
                display();
            } else {
                super.onFailure(caught);
            }
        }
    });
}
Also used : NativeString(com.google.gerrit.client.rpc.NativeString) ExtensionPanel(com.google.gerrit.client.api.ExtensionPanel)

Example 3 with NativeString

use of com.google.gerrit.client.rpc.NativeString in project gerrit by GerritCodeReview.

the class ContactPanelShort method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    onInitUI();
    body.add(save);
    display(Gerrit.getUserAccount());
    emailPick.clear();
    emailPick.setEnabled(false);
    registerNewEmail.setEnabled(false);
    haveAccount = false;
    haveEmails = false;
    CallbackGroup group = new CallbackGroup();
    AccountApi.getName("self", group.add(new GerritCallback<NativeString>() {

        @Override
        public void onSuccess(NativeString result) {
            nameTxt.setText(result.asString());
            haveAccount = true;
        }

        @Override
        public void onFailure(Throwable caught) {
        }
    }));
    AccountApi.getEmails("self", group.addFinal(new GerritCallback<JsArray<EmailInfo>>() {

        @Override
        public void onSuccess(JsArray<EmailInfo> result) {
            for (EmailInfo i : Natives.asList(result)) {
                emailPick.addItem(i.email());
                if (i.isPreferred()) {
                    currentEmail = i.email();
                }
            }
            haveEmails = true;
            postLoad();
        }
    }));
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) NativeString(com.google.gerrit.client.rpc.NativeString) JsArray(com.google.gwt.core.client.JsArray) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup)

Example 4 with NativeString

use of com.google.gerrit.client.rpc.NativeString 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 5 with NativeString

use of com.google.gerrit.client.rpc.NativeString in project gerrit by GerritCodeReview.

the class UsernameField method doSetUserName.

private void doSetUserName() {
    if (!canEditUserName()) {
        return;
    }
    enableUI(false);
    String newName = userNameTxt.getText();
    if ("".equals(newName)) {
        newName = null;
    }
    final String newUserName = newName;
    AccountApi.setUsername("self", newUserName, new GerritCallback<NativeString>() {

        @Override
        public void onSuccess(NativeString result) {
            Gerrit.getUserAccount().username(newUserName);
            userNameLbl.setText(newUserName);
            userNameLbl.setVisible(true);
            userNameTxt.setVisible(false);
            setUserName.setVisible(false);
        }

        @Override
        public void onFailure(Throwable caught) {
            enableUI(true);
            if (RestApi.isExpected(422)) {
                new ErrorDialog(Util.C.invalidUserName()).center();
            } else {
                super.onFailure(caught);
            }
        }
    });
}
Also used : NativeString(com.google.gerrit.client.rpc.NativeString) ErrorDialog(com.google.gerrit.client.ErrorDialog) NativeString(com.google.gerrit.client.rpc.NativeString)

Aggregations

NativeString (com.google.gerrit.client.rpc.NativeString)6 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)3 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)2 ErrorDialog (com.google.gerrit.client.ErrorDialog)1 GerritUiExtensionPoint (com.google.gerrit.client.GerritUiExtensionPoint)1 ExtensionPanel (com.google.gerrit.client.api.ExtensionPanel)1 AccountInfo (com.google.gerrit.client.info.AccountInfo)1 RestApi (com.google.gerrit.client.rpc.RestApi)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsArray (com.google.gwt.core.client.JsArray)1