Search in sources :

Example 1 with CopyMails

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

the class CopyMailsTabItem method draw.

public Widget draw() {
    final FlexTable content = new FlexTable();
    content.setStyleName("inputFormFlexTable");
    // boxes
    final ListBoxWithObjects<VirtualOrganization> vosBox = new ListBoxWithObjects<VirtualOrganization>();
    final ListBoxWithObjects<Group> groupsBox = new ListBoxWithObjects<Group>();
    final CustomButton save;
    final TabItem tab = this;
    VerticalPanel vp = new VerticalPanel();
    TabMenu menu = new TabMenu();
    titleWidget.setText("Copy form items from VO / group");
    save = TabMenu.getPredefinedButton(ButtonType.OK, ButtonTranslation.INSTANCE.copyFromVo());
    // get them
    final GetVos vos = new GetVos(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            vosBox.clear();
            ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
            vos = new TableSorter<VirtualOrganization>().sortByName(vos);
            vosBox.addAllItems(vos);
            // get them
            GetAllGroups getGroups = new GetAllGroups(voId, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    groupsBox.clear();
                    ArrayList<Group> groups = JsonUtils.jsoAsList(jso);
                    groups = new TableSorter<Group>().sortByName(groups);
                    groupsBox.addNotSelectedOption();
                    groupsBox.addAllItems(groups);
                    save.setEnabled(true);
                }

                @Override
                public void onError(PerunError error) {
                    groupsBox.removeNotSelectedOption();
                    groupsBox.clear();
                    groupsBox.addItem("Error while loading");
                    save.setEnabled(false);
                }

                @Override
                public void onLoadingStart() {
                    groupsBox.removeNotSelectedOption();
                    groupsBox.clear();
                    groupsBox.addItem("Loading...");
                    save.setEnabled(false);
                }
            });
            getGroups.retrieveData();
        }

        @Override
        public void onError(PerunError error) {
            vosBox.addItem("Error while loading");
            save.setEnabled(false);
        }

        @Override
        public void onLoadingStart() {
            vosBox.addItem("Loading...");
            save.setEnabled(false);
        }
    });
    vos.retrieveData();
    vosBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (vosBox.getSelectedObject() != null) {
                // get them
                GetAllGroups getGroups = new GetAllGroups(vosBox.getSelectedObject().getId(), new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        groupsBox.clear();
                        ArrayList<Group> groups = JsonUtils.jsoAsList(jso);
                        groups = new TableSorter<Group>().sortByName(groups);
                        groupsBox.addNotSelectedOption();
                        groupsBox.addAllItems(groups);
                        save.setEnabled(true);
                    }

                    @Override
                    public void onError(PerunError error) {
                        groupsBox.removeNotSelectedOption();
                        groupsBox.clear();
                        groupsBox.addItem("Error while loading");
                        save.setEnabled(false);
                    }

                    @Override
                    public void onLoadingStart() {
                        groupsBox.removeNotSelectedOption();
                        groupsBox.clear();
                        groupsBox.addItem("Loading...");
                        save.setEnabled(false);
                    }
                });
                getGroups.retrieveData();
            }
        }
    });
    content.setHTML(0, 0, "Source VO:");
    content.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    content.setWidget(0, 1, vosBox);
    content.setHTML(1, 0, "Source group:");
    content.getFlexCellFormatter().setStyleName(1, 0, "itemName");
    content.setWidget(1, 1, groupsBox);
    save.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            CopyMails request = null;
            if (groupsBox.getSelectedIndex() != 0 && voId != 0 && groupId == 0) {
                // from group to VO
                request = new CopyMails(PerunEntity.GROUP, groupsBox.getSelectedObject().getId(), PerunEntity.VIRTUAL_ORGANIZATION, voId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            } else if (groupsBox.getSelectedIndex() != 0 && voId != 0 && groupId != 0) {
                // from group to group
                request = new CopyMails(PerunEntity.GROUP, groupsBox.getSelectedObject().getId(), PerunEntity.GROUP, groupId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            } else if (groupsBox.getSelectedIndex() == 0 && voId != 0 && groupId == 0) {
                // from VO to VO
                request = new CopyMails(PerunEntity.VIRTUAL_ORGANIZATION, vosBox.getSelectedObject().getId(), PerunEntity.VIRTUAL_ORGANIZATION, voId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            } else if (groupsBox.getSelectedIndex() == 0 && voId != 0 && groupId != 0) {
                // from VO to group
                request = new CopyMails(PerunEntity.VIRTUAL_ORGANIZATION, vosBox.getSelectedObject().getId(), PerunEntity.GROUP, groupId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab, true));
            }
            request.copyMails();
        }
    });
    content.setHTML(2, 0, "All mail definitions will be added to yours.");
    content.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
    content.getFlexCellFormatter().setColSpan(2, 0, 2);
    menu.addWidget(save);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, isRefreshParentOnClose());
        }
    }));
    vp.add(content);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) TableSorter(cz.metacentrum.perun.webgui.client.resources.TableSorter) Group(cz.metacentrum.perun.webgui.model.Group) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) CopyMails(cz.metacentrum.perun.webgui.json.registrarManager.CopyMails) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 TableSorter (cz.metacentrum.perun.webgui.client.resources.TableSorter)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)1 CopyMails (cz.metacentrum.perun.webgui.json.registrarManager.CopyMails)1 GetVos (cz.metacentrum.perun.webgui.json.vosManager.GetVos)1 Group (cz.metacentrum.perun.webgui.model.Group)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1