Search in sources :

Example 1 with CreateFormItemTabItem

use of cz.metacentrum.perun.webgui.tabs.registrartabs.CreateFormItemTabItem 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 CreateFormItemTabItem

use of cz.metacentrum.perun.webgui.tabs.registrartabs.CreateFormItemTabItem 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)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 GetApplicationForm (cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm)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 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2