Search in sources :

Example 11 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class UrlMapper method addEntityToList.

/**
 * Private helper method
 * @param entity
 * @param id
 * @param i
 * @param list
 */
private static <T extends JavaScriptObject> void addEntityToList(PerunEntity entity, int id, final int i, final ArrayList<T> list) {
    JsonCallbackEvents events = new JsonCallbackEvents() {

        @SuppressWarnings("unchecked")
        public void onFinished(JavaScriptObject jso) {
            JavaScriptObject obj = jso.cast();
            list.add(i, (T) obj.cast());
        }
    };
    switch(entity) {
        case USER:
            new GetEntityById(PerunEntity.USER, id, events).retrieveData();
            break;
        case VIRTUAL_ORGANIZATION:
            new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, id, events).retrieveData();
            break;
        case GROUP:
            new GetEntityById(PerunEntity.GROUP, id, events).retrieveData();
            break;
        case MEMBER:
            new GetEntityById(PerunEntity.MEMBER, id, events).retrieveData();
            break;
        case FACILITY:
            new GetEntityById(PerunEntity.FACILITY, id, events).retrieveData();
            break;
        case RESOURCE:
            new GetEntityById(PerunEntity.RESOURCE, id, events).retrieveData();
            break;
        case SERVICE:
            new GetEntityById(PerunEntity.SERVICE, id, events).retrieveData();
            break;
        default:
            throw new RuntimeException("This entity is not supported.");
    }
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById)

Example 12 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class SelfApplicationDetailTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Application detail");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    String header = "<h2>";
    if (application.getType().equalsIgnoreCase("INITIAL") || application.getType().equalsIgnoreCase("EMBEDDED")) {
        header += "Initial application for ";
    } else {
        header += "Extension application for ";
    }
    if (application.getGroup() == null) {
        header += "VO " + application.getVo().getName();
    } else {
        header += "group " + application.getGroup().getShortName() + " in VO " + application.getVo().getName();
    }
    String submitted = "</h2><p>Submitted on <strong>" + ((application.getCreatedAt().contains(".")) ? application.getCreatedAt().substring(0, application.getCreatedAt().indexOf(".")) : application.getCreatedAt());
    submitted += "</strong> is in state <strong>" + application.getState().toUpperCase() + "</strong>";
    vp.add(new HTML(header + submitted));
    vp.add(new HTML("<hr size=\"1\" style=\"color: #ccc;\" />"));
    ScrollPanel sp = new ScrollPanel();
    sp.setSize("100%", "100%");
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    if (application.getType().equalsIgnoreCase("EMBEDDED")) {
        final FlexTable ft = new FlexTable();
        ft.setCellSpacing(5);
        String userName = application.getUser().getFullNameWithTitles();
        if (userName != null) {
            ft.setHTML(0, 0, "<strong>Name:</strong> " + SafeHtmlUtils.fromString(userName).asString());
        }
        new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, application.getUser().getId(), new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                User user = jso.cast();
                Attribute preferredMail = user.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
                if (preferredMail != null) {
                    ft.setHTML(1, 0, "<strong>Preferred mail:</strong> " + SafeHtmlUtils.fromString(preferredMail.getValue()).asString());
                }
            }
        }).retrieveData();
        sp.setWidget(ft);
    } else {
        GetApplicationDataById data = new GetApplicationDataById(applicationId);
        data.setShowAdminItems(false);
        data.retrieveData();
        sp.setWidget(data.getContents());
    }
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) User(cz.metacentrum.perun.webgui.model.User) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Attribute(cz.metacentrum.perun.webgui.model.Attribute) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) GetApplicationDataById(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationDataById)

Example 13 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class SelfPasswordTabItem method draw.

public Widget draw() {
    String actionText = "Change";
    if (action.equals(Actions.CREATE)) {
        actionText = "Create";
    } else if (action.equals(Actions.DELETE)) {
        actionText = "Delete";
    }
    // set tab name
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": " + actionText + " password");
    // main panel
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    // widgets
    final Label namespaceLabel = new Label();
    namespaceLabel.setText(namespace);
    final Label loginLabel = new Label();
    loginLabel.setText(login);
    final ExtendedPasswordBox newPass = new ExtendedPasswordBox();
    final ExtendedPasswordBox confPass = new ExtendedPasswordBox();
    final ExtendedPasswordBox oldPass = new ExtendedPasswordBox();
    final CustomButton changeButton = new CustomButton("Change password", "Changes your password in selected namespace", SmallIcons.INSTANCE.keyIcon());
    final CustomButton createButton = new CustomButton("Create password", "Creates your password in selected namespace", SmallIcons.INSTANCE.keyAddIcon());
    final CustomButton deleteButton = new CustomButton("Delete password", "Deletes your password in selected namespace", SmallIcons.INSTANCE.keyDeleteIcon());
    final TabItem tab = this;
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (newPass.getTextBox().getValue().trim().equals("")) {
                newPass.setError("Password can't be empty!");
                return false;
            }
            // einfra check
            if ("einfra".equals(namespace)) {
                RegExp regExp2 = RegExp.compile("^[\\x20-\\x7E]{1,}$");
                if (regExp2.exec(newPass.getTextBox().getValue()) == null) {
                    newPass.setError("Password <b>can`t contain accented characters (diacritics)</b> or non-printing and control characters!");
                    return false;
                }
                // check on login in password if login is longer than 2 chars
                if (login.length() > 2) {
                    String pass = newPass.getTextBox().getValue();
                    if (Utils.normalizeString(pass).contains(Utils.normalizeString(login)) || Utils.normalizeString(pass).contains(Utils.normalizeString(Utils.reverseString((login))))) {
                        newPass.setError("Password <b>can't contain login, name or surname</b>, not even backwards!");
                        return false;
                    }
                }
                // Check that password contains at least 3 of 4 character groups
                RegExp regExpDigit = RegExp.compile("^.*[0-9].*$");
                RegExp regExpLower = RegExp.compile("^.*[a-z].*$");
                RegExp regExpUpper = RegExp.compile("^.*[A-Z].*$");
                RegExp regExpSpec = RegExp.compile("^.*[\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E].*$");
                int matchCounter = 0;
                if (regExpDigit.exec(newPass.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpLower.exec(newPass.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpUpper.exec(newPass.getTextBox().getValue()) != null)
                    matchCounter++;
                if (regExpSpec.exec(newPass.getTextBox().getValue()) != null)
                    matchCounter++;
                if (matchCounter < 3) {
                    newPass.setError("Password must consist of <b>at least 3 of 4</b> character groups<ul><li>lower-case letters</li><li>upper-case letters</li><li>digits</li><li>special characters</li></ul>");
                    return false;
                }
                // check length
                if (newPass.getTextBox().getValue().length() < 10) {
                    newPass.setError("Password must be <b>at least 10 characters</b> long!");
                    return false;
                }
            }
            if (!newPass.getTextBox().getValue().equals(confPass.getTextBox().getValue())) {
                newPass.setOk();
                confPass.setError("Password in both textboxes must be the same!");
                return false;
            }
            newPass.setOk();
            return true;
        }
    };
    final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!confPass.getTextBox().getValue().equals(newPass.getTextBox().getValue())) {
                confPass.setError("Password in both textboxes must be the same!");
                return false;
            } else {
                confPass.setOk();
                return true;
            }
        }
    };
    final ExtendedTextBox.TextBoxValidator oldValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (oldPass.getTextBox().getValue().trim().equals("")) {
                oldPass.setError("Password can't be empty!");
                return false;
            } else {
                oldPass.setOk();
                return true;
            }
        }
    };
    newPass.setValidator(validator);
    confPass.setValidator(validator2);
    oldPass.setValidator(oldValidator);
    // save changes
    changeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if ("mu".equals(namespace) && !JsonUtils.checkParseInt(login)) {
                UiElements.generateAlert("Operation not supported", "Password change/reset is not supported for non-numeric logins (UČO).");
            }
            if (session.isPerunAdmin() || user.isServiceUser()) {
                if (!validator.validateTextBox() && !validator2.validateTextBox())
                    return;
                ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab, true), false);
                changepw.changePassword(user, namespace, oldPass.getTextBox().getValue(), newPass.getTextBox().getValue());
            } else {
                if (!validator.validateTextBox() && !validator2.validateTextBox() && !oldValidator.validateTextBox())
                    return;
                ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab, true), true);
                changepw.changePassword(user, namespace, oldPass.getTextBox().getValue(), newPass.getTextBox().getValue());
            }
        }
    });
    if (user.isServiceUser()) {
        // for service users it's reset since they don't provide old password
        changeButton.setText("Reset password…");
    }
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            if (validator.validateTextBox() && validator2.validateTextBox()) {
                if ("mu".equals(namespace)) {
                    final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            BasicOverlayType basic = jso.cast();
                            final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                            SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                    // VALIDATE PASSWORD - SET EXT SOURCES
                                    CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
                                    req.validatePassword(user.getId(), login, namespace);
                                }
                            }));
                            setLogin.setLogin(user.getId(), "mu", login);
                        }
                    }));
                    final Map<String, String> params = new HashMap<String, String>();
                    GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            User usr = jso.cast();
                            params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
                            params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
                            params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
                            generateAccount.generateAccount(namespace, newPass.getTextBox().getValue(), params);
                        }
                    }));
                    get.retrieveData();
                } else {
                    // NORMAL PWD LOGIC
                    CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
                    create.createPassword(userId, login, namespace, newPass.getTextBox().getValue());
                }
            }
        }
    });
    deleteButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            UiElements.generateAlert("Not yet implemented", "Not yet implemented");
        }
    });
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    // change layout
    if (action.equals(Actions.CHANGE)) {
        int row = 0;
        layout.setHTML(row, 0, "Namespace:");
        layout.setWidget(row, 1, namespaceLabel);
        row++;
        layout.setHTML(row, 0, "Login:");
        layout.setWidget(row, 1, loginLabel);
        row++;
        // mu namespace can change without knowing old
        if (!session.isPerunAdmin()) {
            if (!user.isServiceUser()) {
                layout.setHTML(row, 0, "Old password: ");
                layout.setWidget(row, 1, oldPass);
                row++;
            }
        }
        layout.setHTML(row, 0, "New password:");
        layout.setWidget(row, 1, newPass);
        row++;
        layout.setHTML(row, 0, "Retype new pass:");
        layout.setWidget(row, 1, confPass);
        menu.addWidget(changeButton);
        vp.add(layout);
    } else if (action.equals(Actions.CREATE)) {
        layout.setHTML(0, 0, "Namespace:");
        layout.setWidget(0, 1, namespaceLabel);
        if ("mu".equals(namespace)) {
            loginLabel.setText("Will be generated...");
            loginLabel.addStyleName("inputFormInlineComment");
        }
        layout.setHTML(1, 0, "Login:");
        layout.setWidget(1, 1, loginLabel);
        layout.setHTML(2, 0, "New password:");
        layout.setWidget(2, 1, newPass);
        layout.setHTML(3, 0, "Retype new pass:");
        layout.setWidget(3, 1, confPass);
        final CustomButton skip = new CustomButton("Skip", "Will set random/empty password", SmallIcons.INSTANCE.arrowRightIcon());
        skip.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                if ("mu".equals(namespace)) {
                    final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            BasicOverlayType basic = jso.cast();
                            final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                            SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                    // VALIDATE PASSWORD - SET EXT SOURCES
                                    CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
                                    req.validatePassword(user.getId(), login, namespace);
                                }
                            }));
                            setLogin.setLogin(user.getId(), "mu", login);
                        }
                    }));
                    final Map<String, String> params = new HashMap<String, String>();
                    GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            User usr = jso.cast();
                            params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
                            params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
                            params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
                            generateAccount.generateAccount(namespace, newPass.getTextBox().getValue(), params);
                        }
                    }));
                    get.retrieveData();
                } else {
                    CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(skip, tab, true));
                    create.createRandomPassword(userId, login, namespace);
                }
            }
        });
        menu.addWidget(skip);
        menu.addWidget(createButton);
        vp.add(layout);
    } else if (action.equals(Actions.DELETE)) {
        layout.setHTML(0, 0, "Namespace:");
        layout.setWidget(0, 1, namespaceLabel);
        layout.setHTML(1, 0, "Login:");
        layout.setWidget(1, 1, loginLabel);
        menu.addWidget(deleteButton);
        vp.add(layout);
    }
    for (int i = 0; i < layout.getRowCount(); i++) {
        layout.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    int row = layout.getRowCount();
    if ("einfra".equals(namespace)) {
        layout.setHTML(row, 0, "Password must <ul><li>contain only printing (non-accented) characters<li>be at least 10 characters long<li>consist of at least 3 of 4 character groups<ul><li>lower-case letters<li>upper-case letters<li>digits<li>special characters</ul></ul>");
    } else {
        layout.setHTML(row, 0, "Please <b>avoid using accented characters</b>. It might not be supported by all backend components and services.");
    }
    layout.getFlexCellFormatter().setColSpan(row, 0, 2);
    layout.getCellFormatter().setStyleName(row, 0, "inputFormInlineComment");
    layout.setWidth("400px");
    if (!action.equals(Actions.CREATE)) {
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                session.getTabManager().closeTab(tab, isRefreshParentOnClose());
            }
        }));
    }
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : ChangePassword(cz.metacentrum.perun.webgui.json.usersManager.ChangePassword) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) User(cz.metacentrum.perun.webgui.model.User) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType) GenerateAccount(cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) CreatePassword(cz.metacentrum.perun.webgui.json.usersManager.CreatePassword) RegExp(com.google.gwt.regexp.shared.RegExp) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) SetLogin(cz.metacentrum.perun.webgui.json.usersManager.SetLogin) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HashMap(java.util.HashMap) Map(java.util.Map) ExtendedPasswordBox(cz.metacentrum.perun.webgui.widgets.ExtendedPasswordBox)

Example 14 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class ServiceDetailTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(service.getName()));
    // main widget panel
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    AbsolutePanel dp = new AbsolutePanel();
    final FlexTable menu = new FlexTable();
    menu.setCellSpacing(5);
    // Add service information
    menu.setWidget(0, 0, new Image(LargeIcons.INSTANCE.trafficLightsIcon()));
    Label serviceName = new Label();
    serviceName.setText(Utils.getStrippedStringWithEllipsis(service.getName(), 40));
    serviceName.setStyleName("now-managing");
    serviceName.setTitle(service.getName());
    menu.setWidget(0, 1, serviceName);
    menu.setHTML(0, 2, "&nbsp;");
    menu.getFlexCellFormatter().setWidth(0, 2, "25px");
    int column = 3;
    final JsonCallbackEvents events = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            new GetEntityById(PerunEntity.SERVICE, serviceId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    service = jso.cast();
                    open();
                    draw();
                }
            }).retrieveData();
        }
    };
    CustomButton change = new CustomButton("", ButtonTranslation.INSTANCE.editFacilityDetails(), SmallIcons.INSTANCE.applicationFormEditIcon());
    change.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // prepare confirm content
            session.getTabManager().addTabToCurrentTab(new EditServiceDetailsTabItem(service, events));
        }
    });
    menu.setWidget(0, column, change);
    column++;
    menu.setHTML(0, column, "&nbsp;");
    menu.getFlexCellFormatter().setWidth(0, column, "25px");
    column++;
    if (JsonUtils.isExtendedInfoVisible()) {
        menu.setHTML(0, column, "<strong>ID:</strong><br/><span class=\"inputFormInlineComment\">" + service.getId() + "</span>");
        column++;
        menu.setHTML(0, column, "&nbsp;");
        menu.getFlexCellFormatter().setWidth(0, column, "25px");
        column++;
    }
    menu.setHTML(0, column, "<strong>Description:</strong><br/><span class=\"inputFormInlineComment\">" + service.getDescription() + "</span>");
    dp.add(menu);
    vp.add(dp);
    vp.setCellHeight(dp, "30px");
    // TAB PANEL
    tabPanel.clear();
    tabPanel.add(new ServiceRequiredAttributesTabItem(service), "Required attributes");
    tabPanel.add(new ServiceDestinationsTabItem(service), "Destinations");
    // Resize must be called after page fully displays
    Scheduler.get().scheduleDeferred(new Command() {

        @Override
        public void execute() {
            tabPanel.finishAdding();
        }
    });
    vp.add(tabPanel);
    vp.setCellHeight(tabPanel, "100%");
    // add tabs to the main panel
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Command(com.google.gwt.user.client.Command) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById)

Example 15 with GetEntityById

use of cz.metacentrum.perun.webgui.json.GetEntityById in project perun by CESNET.

the class RequestQuotaChangeTabItem method draw.

public Widget draw() {
    new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, resource.getVoId(), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            vo = jso.cast();
        }
    }).retrieveData();
    VerticalPanel vp = new VerticalPanel();
    // set tab name
    this.titleWidget.setText(getQuotaTypeAsString() + " quota change request");
    // quota string
    // String quotaStr = getQuotaTypeAsString();
    // new quota input
    final ExtendedTextBox newQuota = new ExtendedTextBox();
    final ExtendedTextArea reason = new ExtendedTextArea();
    final ListBox units = new ListBox();
    units.addItem("M");
    units.addItem("G");
    units.addItem("T");
    // default G
    units.setSelectedIndex(1);
    FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    ft.setWidget(0, 0, new HTML("Resource:"));
    ft.setWidget(1, 0, new HTML("Current quota:"));
    ft.setWidget(2, 0, new HTML("Requested quota:"));
    ft.setWidget(3, 0, new HTML("Reason:"));
    for (int i = 0; i < ft.getRowCount(); i++) {
        ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }
    ft.setText(0, 1, resource.getName());
    ft.setText(1, 1, oldQuota + " (default: " + defaultQuota + ")");
    ft.setWidget(2, 1, newQuota);
    ft.getFlexCellFormatter().setColSpan(3, 1, 2);
    ft.setWidget(3, 1, reason);
    final CustomButton requestQuotaButton = new CustomButton("Send request", "Send quota change request", SmallIcons.INSTANCE.emailIcon());
    if (this.quotaType.equals(QuotaType.DATA)) {
        ft.setWidget(2, 2, units);
        ft.getFlexCellFormatter().setColSpan(4, 0, 3);
    } else {
        ft.getFlexCellFormatter().setColSpan(4, 0, 2);
    }
    final ExtendedTextBox.TextBoxValidator quotaValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (newQuota.getTextBox().getValue().trim().isEmpty()) {
                newQuota.setError("You must enter requested quota!");
            } else if (!JsonUtils.checkParseInt(newQuota.getTextBox().getValue().trim())) {
                newQuota.setError("Requested quota must be a number!");
            } else {
                newQuota.setOk();
                return true;
            }
            return false;
        }
    };
    newQuota.setValidator(quotaValidator);
    final ExtendedTextArea.TextAreaValidator reasonValidator = new ExtendedTextArea.TextAreaValidator() {

        @Override
        public boolean validateTextArea() {
            if (reason.getTextArea().getValue().trim().isEmpty()) {
                reason.setError("You must specify reason for quota change!");
                return false;
            }
            reason.setOk();
            return true;
        }
    };
    reason.setValidator(reasonValidator);
    reason.getTextArea().setSize("205px", "100px");
    requestQuotaButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (!quotaValidator.validateTextBox() && !reasonValidator.validateTextArea())
                return;
            if (quotaType.equals(QuotaType.DATA)) {
                requestQuotaChange(newQuota.getTextBox().getValue().trim() + units.getItemText(units.getSelectedIndex()), reason.getTextArea().getText());
            } else {
                requestQuotaChange(newQuota.getTextBox().getValue().trim(), reason.getTextArea().getText());
            }
        }
    });
    vp.add(ft);
    TabMenu menu = new TabMenu();
    menu.addWidget(requestQuotaButton);
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextArea(cz.metacentrum.perun.webgui.widgets.ExtendedTextArea) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)18 GetEntityById (cz.metacentrum.perun.webgui.json.GetEntityById)18 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)18 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)9 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)8 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)8 Command (com.google.gwt.user.client.Command)4 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 HashMap (java.util.HashMap)3 RegExp (com.google.gwt.regexp.shared.RegExp)2 CreatePassword (cz.metacentrum.perun.webgui.json.usersManager.CreatePassword)2 GenerateAccount (cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount)2 SetLogin (cz.metacentrum.perun.webgui.json.usersManager.SetLogin)2 Attribute (cz.metacentrum.perun.webgui.model.Attribute)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 User (cz.metacentrum.perun.webgui.model.User)2 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2