Search in sources :

Example 71 with JsonCallbackEvents

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

the class CopyForm method copyForm.

/**
 * Send request to copy form
 */
public void copyForm() {
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Copying form failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Form successfully copied.");
            events.onFinished(jso);
        }

        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 72 with JsonCallbackEvents

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

the class GetApplicationDataById method prepareApplicationForm.

/**
 * Prepares the widgets from the items as A DISPLAY FOR THE USER
 */
public void prepareApplicationForm() {
    FlexTable ft = new FlexTable();
    ft.setWidth("100%");
    ft.setCellPadding(5);
    ft.setCellSpacing(0);
    ft.setStyleName("stripped");
    FlexCellFormatter fcf = ft.getFlexCellFormatter();
    String locale = "en";
    if (!Utils.getNativeLanguage().isEmpty() && !LocaleInfo.getCurrentLocale().getLocaleName().equals("default") && !LocaleInfo.getCurrentLocale().getLocaleName().equals("en")) {
        locale = Utils.getNativeLanguage().get(0);
    }
    if (this.embedded) {
        Attribute attr = this.user.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
        if (attr != null) {
            ft.setHTML(0, 0, "<strong>" + attr.getDisplayName() + "</strong>");
            ft.setWidget(0, 2, new HTML(SafeHtmlUtils.fromString(attr.getValue())));
            // format
            fcf.setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
            fcf.setVerticalAlignment(0, 2, HasVerticalAlignment.ALIGN_TOP);
            fcf.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
            fcf.setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_LEFT);
            fcf.setWidth(0, 0, "25%");
            fcf.setWidth(0, 2, "75%");
            contents.setWidget(ft);
        }
    } else {
        int i = 0;
        for (final ApplicationFormItemData item : applFormItems) {
            RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item.getFormItem(), (item.getValue() != null) ? SafeHtmlUtils.fromString(item.getValue()).asString() : null, locale);
            this.applFormGenerators.add(gen);
            // show only visible items - show also hidden to perun admin and vo/group admin
            if (!gen.isVisible() && !(session.isPerunAdmin() || session.isVoAdmin() || session.isGroupAdmin())) {
                continue;
            }
            // if only for admin
            if (!showAdminItems && gen.isVisibleOnlyToAdmin()) {
                continue;
            }
            // WITH LABEL (input box ...)
            if (gen.isLabelShown()) {
                // don't show password
                if (!item.getFormItem().getType().equalsIgnoreCase("PASSWORD")) {
                    // FIXME for now, we can only detect that the item was hidden for the 'ALWAYS' option. This will be for the most cases.
                    if (item.getFormItem().getHidden().equals("ALWAYS")) {
                        // hidden
                        ft.setHTML(i, 0, "<strong>" + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString() + "</strong><br /><i>(value provided by external source)</i>");
                    // FIXME for now, we can only detect that the item was disabled for the 'ALWAYS' option. This will be for the most cases.
                    } else if (item.getFormItem().getDisabled().equals("ALWAYS")) {
                        // show
                        ft.setHTML(i, 0, "<strong>" + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString() + "</strong><br /><i>(value provided by external source)</i>");
                    } else {
                        ft.setHTML(i, 0, "<strong>" + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString() + "</strong>");
                    }
                    if (PerunWebSession.getInstance().isPerunAdmin() && gen.isUpdatable() && editable) {
                        final int finalI = i;
                        CustomButton editButton = new CustomButton("", "Editor form item data.", SmallIcons.INSTANCE.applicationFormEditIcon(), new ClickHandler() {

                            @Override
                            public void onClick(ClickEvent event) {
                                TextArea content = new TextArea();
                                if (item.getValue() != null) {
                                    content.setText(item.getValue());
                                }
                                content.setSize("350px", "100px");
                                Confirm confirm = new Confirm("Edit item: " + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString(), content, new ClickHandler() {

                                    @Override
                                    public void onClick(ClickEvent event) {
                                        // save old value and push new value
                                        String previousValue = item.getValue();
                                        item.setValue(content.getText());
                                        UpdateFormItemData update = new UpdateFormItemData(new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                // update local UI
                                                ft.setWidget(finalI, 2, new HTML((item.getValue() != null) ? (SafeHtmlUtils.fromString(item.getValue()).asString()) : null));
                                            }

                                            @Override
                                            public void onError(PerunError error) {
                                                // put back old value
                                                item.setValue(previousValue);
                                            }
                                        });
                                        update.updateFormItemData(appId, item);
                                    }
                                }, "Update form item", true);
                                confirm.setNonScrollable(true);
                                confirm.show();
                            }
                        });
                        ft.setWidget(i, 1, editButton);
                    }
                    // 1 = value
                    ft.setWidget(i, 2, new HTML((item.getValue() != null) ? (SafeHtmlUtils.fromString(item.getValue()).asString()) : null));
                    // format
                    fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_TOP);
                    fcf.setVerticalAlignment(i, 2, HasVerticalAlignment.ALIGN_TOP);
                    fcf.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
                    fcf.setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_LEFT);
                    fcf.setWidth(i, 0, "25%");
                    fcf.setWidth(i, 2, "75%");
                }
            }
            i++;
        }
        // set empty text
        if (!applFormItems.isEmpty()) {
            contents.setWidget(ft);
        }
    }
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) ApplicationFormItemData(cz.metacentrum.perun.webgui.model.ApplicationFormItemData) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 73 with JsonCallbackEvents

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

the class CopyMails method copyMails.

/**
 * Send request to copy form
 */
public void copyMails() {
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Copying form failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Form successfully copied.");
            events.onFinished(jso);
        }

        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 74 with JsonCallbackEvents

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

the class CreateApplicationForm method createApplicationForm.

/**
 * Creating application form
 */
public void createApplicationForm() {
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Creating application form failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Application form created.");
            events.onFinished(jso);
        }

        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 75 with JsonCallbackEvents

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

the class CreateSpecificMember method createMember.

/**
 * Attempts to create service member in VO
 *
 * @param voId vo where member should be created
 * @param name name of service member
 * @param email email of service member
 * @param users list of real users
 * @param namespace namespace to create login in
 * @param login users login in namespace
 * @param certDN users cert DN
 * @param caCertDN users CA cert DN
 */
public void createMember(final int voId, final String name, final String email, ArrayList<User> users, String namespace, String login, String certDN, String caCertDN, String specificUserType) {
    this.voId = voId;
    this.name = name;
    this.email = email;
    this.users = users;
    this.login = login;
    this.namespace = namespace;
    this.certDN = certDN;
    this.caCertDN = caCertDN;
    this.specificUserType = specificUserType;
    // test arguments
    if (!this.testAdding()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Creating member: " + name + " failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Member " + name + " created !");
            // call validation asynchronously
            Member mem = jso.cast();
            ValidateMemberAsync request = new ValidateMemberAsync();
            request.setHidden(true);
            request.validateMemberAsync(mem);
            events.onFinished(jso);
        }

        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError) Member(cz.metacentrum.perun.webgui.model.Member)

Aggregations

JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)380 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)333 PerunError (cz.metacentrum.perun.webgui.model.PerunError)206 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)181 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)143 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)143 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)142 ArrayList (java.util.ArrayList)125 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)108 JSONObject (com.google.gwt.json.client.JSONObject)69 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)60 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)41 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)34 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)34 HashMap (java.util.HashMap)33 JSONNumber (com.google.gwt.json.client.JSONNumber)30 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)24 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)24 Group (cz.metacentrum.perun.webgui.model.Group)23 Map (java.util.Map)23