Search in sources :

Example 1 with GetApplicationForm

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

the class GroupApplicationFormSettingsTabItem method draw.

public Widget draw() {
    // MAIN PANEL
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveApplicationFormSettings());
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addNewAppFormItem());
    final CustomButton emailButton = new CustomButton(ButtonTranslation.INSTANCE.emailNotificationsButton() + "…", ButtonTranslation.INSTANCE.emailNotifications(), SmallIcons.INSTANCE.emailIcon());
    final CustomButton copyButton = new CustomButton(ButtonTranslation.INSTANCE.copyFromVoButton() + "…", ButtonTranslation.INSTANCE.copyFromVo(), SmallIcons.INSTANCE.copyIcon());
    final CustomButton previewButton = TabMenu.getPredefinedButton(ButtonType.PREVIEW, ButtonTranslation.INSTANCE.previewAppForm());
    // request
    final GetFormItems itemsRequest = new GetFormItems(PerunEntity.GROUP, group.getId(), true, group, new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            // DISABLE BUTTONS
            save.setEnabled(false);
            addButton.setEnabled(false);
            emailButton.setEnabled(false);
            copyButton.setEnabled(false);
            previewButton.setEnabled(false);
        }
    });
    sourceList = itemsRequest.getList();
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": " + "application form");
    // HORIZONTAL MENU
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // refresh table events
    final JsonCallbackEvents refreshEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            itemsRequest.prepareSettings(sourceList);
        }
    };
    // save button
    save.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            UpdateFormItems request = new UpdateFormItems(PerunEntity.GROUP, groupId, JsonCallbackEvents.disableButtonEvents(save, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    itemsRequest.retrieveData();
                }
            }));
            // reset item ordnum to correct state defined by list
            // keep counter
            int counter = 0;
            // process
            for (int i = 0; i < itemsRequest.getList().size(); i++) {
                // if not for deletion
                if (!itemsRequest.getList().get(i).isForDelete()) {
                    // set
                    itemsRequest.getList().get(i).setOrdnum(counter);
                    counter++;
                }
            }
            // send request
            request.updateFormItems(itemsRequest.getList());
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        save.setEnabled(false);
    menu.addWidget(save);
    // add button
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateFormItemTabItem(sourceList, refreshEvents));
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        addButton.setEnabled(false);
    menu.addWidget(addButton);
    copyButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CopyFormTabItem(group.getVoId(), groupId));
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        copyButton.setEnabled(false);
    menu.addWidget(copyButton);
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        previewButton.setEnabled(false);
    menu.addWidget(previewButton);
    // AUTO APPROVAL + NOTIFICATIONS
    // auto-approval widget already defined
    GetApplicationForm form = new GetApplicationForm(PerunEntity.GROUP, groupId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            final ApplicationForm form = jso.cast();
            previewButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    session.getTabManager().addTab(new PreviewFormTabItem(form, sourceList), true);
                }
            });
        }
    });
    form.setHidden(true);
    form.retrieveData();
    menu.addWidget(form.getApprovalWidget());
    emailButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTab(new MailsTabItem(group.getVoId(), group.getId()));
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        emailButton.setEnabled(false);
    menu.addWidget(emailButton);
    // load elements
    itemsRequest.retrieveData();
    // wrap table to the scroll panel
    ScrollPanel sp = new ScrollPanel(itemsRequest.getContents());
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 100, this);
    // add scroll table to the main panel
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) PreviewFormTabItem(cz.metacentrum.perun.webgui.tabs.registrartabs.PreviewFormTabItem) GetApplicationForm(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm) UpdateFormItems(cz.metacentrum.perun.webgui.json.registrarManager.UpdateFormItems) GetFormItems(cz.metacentrum.perun.webgui.json.registrarManager.GetFormItems) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CreateFormItemTabItem(cz.metacentrum.perun.webgui.tabs.registrartabs.CreateFormItemTabItem) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetApplicationForm(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm) MailsTabItem(cz.metacentrum.perun.webgui.tabs.registrartabs.MailsTabItem) CopyFormTabItem(cz.metacentrum.perun.webgui.tabs.registrartabs.CopyFormTabItem)

Example 2 with GetApplicationForm

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

the class ApplicationFormPage method prepareVoForm.

/**
	 * Prepares a VO form
	 */
protected void prepareVoForm() {
    if (submittedOrError)
        formContent.clear();
    bodyContents.setWidget(formContent);
    formContent.setStyleName("formContentTable");
    submittedOrError = false;
    FlexTable header = new FlexTable();
    header.setWidth("100%");
    header.setCellPadding(5);
    int row = 0;
    // display VO logo if present in attribute
    for (int i = 0; i < vo.getAttributes().length(); i++) {
        if (vo.getAttributes().get(i).getFriendlyName().equalsIgnoreCase("voLogoURL")) {
            header.setWidget(row, 0, new Image(vo.getAttributes().get(i).getValue()));
            row++;
        }
    }
    /*

		String headerString = "";

		// display application header
		if (type.equalsIgnoreCase("INITIAL")) {
			if (group != null) {
				headerString = ApplicationMessages.INSTANCE.applicationFormForGroup(group.getName());
			} else {
				headerString = ApplicationMessages.INSTANCE.applicationFormForVo(vo.getName());
			}
		} else if (type.equalsIgnoreCase("EXTENSION")) {
			if (group != null) {
				headerString = ApplicationMessages.INSTANCE.membershipExtensionForGroup(group.getName());
			} else {
				headerString = ApplicationMessages.INSTANCE.membershipExtensionForVo(vo.getName());
			}
		}

		header.setHTML(row, 0, "<h1>" + headerString + "</h1>");

		*/
    // language button
    prepareToggleLanguageButton();
    FlexTable lang = new FlexTable();
    lang.setWidget(0, 1, languageButton);
    header.setWidget(0, 1, lang);
    header.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT);
    formContent.add(header);
    final GetFormItemsWithPrefilledValues fitems;
    if (group != null) {
        fitems = new GetFormItemsWithPrefilledValues(PerunEntity.GROUP, group.getId());
    } else {
        fitems = new GetFormItemsWithPrefilledValues(PerunEntity.VIRTUAL_ORGANIZATION, vo.getId());
    }
    fitems.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // when form is auto-submitting
            ArrayList<ApplicationFormItemWithPrefilledValue> items = JsonUtils.<ApplicationFormItemWithPrefilledValue>jsoAsList(jso);
            for (ApplicationFormItemWithPrefilledValue item : items) {
                if (item.getFormItem().getType().equals("AUTO_SUBMIT_BUTTON")) {
                    if (fitems.getSendButton() != null) {
                        // enforce first click to validate and submit the form
                        fitems.getSendButton().click();
                    }
                }
            }
            // try to get user for VOs initial application (only for authz origin when form is defined)
            if (items != null && !items.isEmpty()) {
                if (session.getUser() == null && !session.getPerunPrincipal().getExtSource().equalsIgnoreCase("LOCAL")) {
                    tryToFindUserByName(null);
                }
            }
            Scheduler.get().scheduleDeferred(new Command() {

                @Override
                public void execute() {
                    positionLinker();
                }
            });
        }
    });
    if (Location.getParameter("type") != null && (Location.getParameter("type").equalsIgnoreCase("INITIAL") || Location.getParameter("type").equalsIgnoreCase("EXTENSION"))) {
        fitems.setType(Location.getParameter("type").toUpperCase());
    } else {
        fitems.setType(type);
    }
    fitems.setHidden(true);
    fitems.setSendFormHandler(new SendsApplicationForm() {

        public void sendApplicationForm(CustomButton button) {
            data = fitems.getValues();
            sendForm(button);
        }
    });
    fitems.retrieveData();
    formContent.add(fitems.getContents());
    formContent.add(new HTML("<br /><br /><br />"));
    JsonCallbackEvents formEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            form = jso.cast();
        }
    };
    GetApplicationForm formRequest;
    if (group != null) {
        formRequest = new GetApplicationForm(PerunEntity.GROUP, group.getId(), formEvent);
    } else {
        formRequest = new GetApplicationForm(PerunEntity.VIRTUAL_ORGANIZATION, vo.getId(), formEvent);
    }
    formRequest.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) GetFormItemsWithPrefilledValues(cz.metacentrum.perun.webgui.json.registrarManager.GetFormItemsWithPrefilledValues) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Command(com.google.gwt.user.client.Command) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetApplicationForm(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm) SendsApplicationForm(cz.metacentrum.perun.webgui.client.applicationresources.SendsApplicationForm)

Example 3 with GetApplicationForm

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

the class VoApplicationFormSettingsTabItem method draw.

public Widget draw() {
    // MAIN PANEL
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": " + "application form");
    // HORIZONTAL MENU
    final TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveApplicationFormSettings());
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addNewAppFormItem());
    final CustomButton emailButton = new CustomButton(ButtonTranslation.INSTANCE.emailNotificationsButton() + "…", ButtonTranslation.INSTANCE.emailNotifications(), SmallIcons.INSTANCE.emailIcon());
    final CustomButton copyButton = new CustomButton(ButtonTranslation.INSTANCE.copyFromVoButton() + "…", ButtonTranslation.INSTANCE.copyFromVo(), SmallIcons.INSTANCE.copyIcon());
    final CustomButton previewButton = TabMenu.getPredefinedButton(ButtonType.PREVIEW, true, ButtonTranslation.INSTANCE.previewAppForm());
    // request
    final GetFormItems itemsRequest = new GetFormItems(PerunEntity.VIRTUAL_ORGANIZATION, vo.getId(), true, null, new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            // DISABLE BUTTONS
            save.setEnabled(false);
            addButton.setEnabled(false);
            emailButton.setEnabled(false);
            copyButton.setEnabled(false);
            previewButton.setEnabled(false);
        }
    });
    sourceList = itemsRequest.getList();
    // refresh table events
    final JsonCallbackEvents refreshEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            itemsRequest.prepareSettings(sourceList);
        }
    };
    menu.addWidget(UiElements.getRefreshButton(this));
    // save button
    menu.addWidget(save);
    if (!session.isVoAdmin(voId))
        save.setEnabled(false);
    save.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            UpdateFormItems request = new UpdateFormItems(PerunEntity.VIRTUAL_ORGANIZATION, voId, JsonCallbackEvents.disableButtonEvents(save, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    itemsRequest.retrieveData();
                }
            }));
            // reset item ordnum to correct state defined by list
            // keep counter
            int counter = 0;
            // process
            for (int i = 0; i < itemsRequest.getList().size(); i++) {
                // if not for deletion
                if (!itemsRequest.getList().get(i).isForDelete()) {
                    // set
                    itemsRequest.getList().get(i).setOrdnum(counter);
                    counter++;
                }
            }
            // send request
            request.updateFormItems(itemsRequest.getList());
        }
    });
    // add button
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateFormItemTabItem(sourceList, refreshEvents));
        }
    });
    if (!session.isVoAdmin(voId))
        addButton.setEnabled(false);
    menu.addWidget(addButton);
    copyButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CopyFormTabItem(vo.getId(), 0));
        }
    });
    if (!session.isVoAdmin(voId))
        copyButton.setEnabled(false);
    menu.addWidget(copyButton);
    if (!session.isVoAdmin(voId))
        previewButton.setEnabled(false);
    menu.addWidget(previewButton);
    // AUTO APPROVAL + NOTIFICATIONS
    // auto-approval widget already defined
    GetApplicationForm form = new GetApplicationForm(PerunEntity.VIRTUAL_ORGANIZATION, voId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            final ApplicationForm form = jso.cast();
            previewButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    session.getTabManager().addTab(new PreviewFormTabItem(form, sourceList), true);
                }
            });
        }
    });
    form.setHidden(true);
    form.retrieveData();
    menu.addWidget(form.getApprovalWidget());
    emailButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTab(new MailsTabItem(voId, 0));
        }
    });
    if (!session.isVoAdmin(voId))
        emailButton.setEnabled(false);
    menu.addWidget(emailButton);
    // load elements
    itemsRequest.retrieveData();
    // wrap table to the scroll panel
    ScrollPanel sp = new ScrollPanel(itemsRequest.getContents());
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 100, this);
    // add scroll table to the main panel
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) PreviewFormTabItem(cz.metacentrum.perun.webgui.tabs.registrartabs.PreviewFormTabItem) GetApplicationForm(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm) UpdateFormItems(cz.metacentrum.perun.webgui.json.registrarManager.UpdateFormItems) GetFormItems(cz.metacentrum.perun.webgui.json.registrarManager.GetFormItems) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CreateFormItemTabItem(cz.metacentrum.perun.webgui.tabs.registrartabs.CreateFormItemTabItem) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetApplicationForm(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm) MailsTabItem(cz.metacentrum.perun.webgui.tabs.registrartabs.MailsTabItem) CopyFormTabItem(cz.metacentrum.perun.webgui.tabs.registrartabs.CopyFormTabItem)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 GetApplicationForm (cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 GetFormItems (cz.metacentrum.perun.webgui.json.registrarManager.GetFormItems)2 UpdateFormItems (cz.metacentrum.perun.webgui.json.registrarManager.UpdateFormItems)2 CopyFormTabItem (cz.metacentrum.perun.webgui.tabs.registrartabs.CopyFormTabItem)2 CreateFormItemTabItem (cz.metacentrum.perun.webgui.tabs.registrartabs.CreateFormItemTabItem)2 MailsTabItem (cz.metacentrum.perun.webgui.tabs.registrartabs.MailsTabItem)2 PreviewFormTabItem (cz.metacentrum.perun.webgui.tabs.registrartabs.PreviewFormTabItem)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 Command (com.google.gwt.user.client.Command)1 SendsApplicationForm (cz.metacentrum.perun.webgui.client.applicationresources.SendsApplicationForm)1 GetFormItemsWithPrefilledValues (cz.metacentrum.perun.webgui.json.registrarManager.GetFormItemsWithPrefilledValues)1 ArrayList (java.util.ArrayList)1