Search in sources :

Example 71 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.

the class ResourceGroupSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": group settings");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final ListBoxWithObjects<Group> groupListBox = new ListBoxWithObjects<>();
    final ListBoxWithObjects<Service> serviceListBox = new ListBoxWithObjects<>();
    // load
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    // to get attributes for all services
    final GetResourceRequiredAttributesV2 resReqAttrs = new GetResourceRequiredAttributesV2();
    final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2(ids, JsonCallbackEvents.passDataToAnotherCallback(resReqAttrs));
    // puts first table
    final CellTable<Attribute> table = resReqAttrs.getEmptyTable();
    // get assigned groups
    final GetAssignedGroups groups = new GetAssignedGroups(resourceId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            groupListBox.removeAllOption();
            groupListBox.clear();
            ArrayList<Group> grp = JsonUtils.jsoAsList(jso);
            grp = new TableSorter<Group>().sortByName(grp);
            if (grp == null || grp.isEmpty()) {
                groupListBox.addItem("No groups assigned");
                lastSelectedGroup = 0;
                ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see their resource setting.");
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                return;
            }
            groupListBox.addAllItems(grp);
            for (Group g : groupListBox.getAllObjects()) {
                if (lastSelectedGroup != 0 && g.getId() == lastSelectedGroup)
                    groupListBox.setSelected(g, true);
            }
            groupCallDone = true;
            if (lastSelectedService == 0) {
                // load resource-required
                if (servCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                if (servCallDone) {
                    // load resource-service-group
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            groupListBox.removeAllOption();
            groupListBox.clear();
            groupListBox.addItem("Error while loading");
            groupCallDone = true;
        }

        @Override
        public void onLoadingStart() {
            groupListBox.removeAllOption();
            groupListBox.clear();
            groupListBox.addItem("Loading...");
            groupCallDone = false;
        }
    });
    groups.retrieveData();
    GetAssignedServices services = new GetAssignedServices(resourceId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            if (srv == null || srv.isEmpty()) {
                serviceListBox.addItem("No services assigned");
                lastSelectedService = 0;
                ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see their resource setting.");
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                return;
            }
            serviceListBox.addAllItems(srv);
            serviceListBox.addAllOption();
            if (lastSelectedService == 0)
                serviceListBox.setSelectedIndex(0);
            for (Service s : serviceListBox.getAllObjects()) {
                if (lastSelectedService != 0 && s.getId() == lastSelectedService)
                    serviceListBox.setSelected(s, true);
            }
            servCallDone = true;
            if (lastSelectedService == 0) {
                // load resource-required
                if (groupCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                if (groupCallDone) {
                    // load resource-service-group
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            serviceListBox.addItem("Error while loading");
            servCallDone = true;
        }

        @Override
        public void onLoadingStart() {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            serviceListBox.addItem("Loading...");
            servCallDone = false;
        }
    });
    services.retrieveData();
    ChangeHandler changeHandler = new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (groupCallDone && servCallDone) {
                if (groupListBox.getSelectedObject() != null) {
                    lastSelectedGroup = groupListBox.getSelectedObject().getId();
                } else {
                    lastSelectedGroup = 0;
                }
                if (serviceListBox.getSelectedIndex() > 0) {
                    lastSelectedService = serviceListBox.getSelectedObject().getId();
                } else {
                    lastSelectedService = 0;
                }
                if (lastSelectedService == 0) {
                    // load resource-required
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                } else {
                    // load resource-service-group
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }
    };
    groupListBox.addChangeHandler(changeHandler);
    serviceListBox.addChangeHandler(changeHandler);
    final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resReqAttrs);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        resReqAttrs.setCheckable(false);
    // add save changes to menu
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(saveChangesButton);
    // set button disable event
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                ids.put("group", groupListBox.getSelectedObject().getId());
                ids.put("workWithGroupAttributes", 1);
                SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    // add set new to menu
    CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("resource", resourceId);
            ids.put("group", groupListBox.getSelectedObject().getId());
            ids.put("workWithGroupAttributes", 1);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, resReqAttrs.getList()), true);
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        setNewAttributeButton.setEnabled(false);
    menu.addWidget(setNewAttributeButton);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        removeButton.setEnabled(false);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                ids.put("group", groupListBox.getSelectedObject().getId());
                ids.put("workWithGroupAttributes", 1);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add group selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;group: </strong>"));
    menu.addWidget(groupListBox);
    // add group selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
    menu.addWidget(serviceListBox);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAssignedGroups(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 72 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project opennms by OpenNMS.

the class AlarmControl method doOnAdd.

public Element doOnAdd() {
    LOG.info("AlarmControl.doOnAdd()");
    final AlarmControlCss css = AlarmControlBundle.INSTANCE.css();
    css.ensureInjected();
    m_eventManager.addHandler(AlarmSeverityUpdatedEvent.TYPE, this);
    this.setStylePrimaryName("leaflet-control-alarm");
    this.addStyleName("leaflet-bar");
    this.addStyleName("leaflet-control");
    final Label label = new Label("Show Severity >=");
    label.getElement().setAttribute("for", "alarmControl");
    label.addStyleName(css.label());
    m_severityBox = new ListBox(false);
    m_severityBox.getElement().setId("alarmControl");
    for (final AlarmSeverity sev : AlarmSeverity.values()) {
        m_severityBox.addItem(sev.getLabel());
    }
    m_severityBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(final ChangeEvent event) {
            final int selected = m_severityBox.getSelectedIndex();
            LOG.info("new selection index = " + selected);
            final String value = m_severityBox.getValue(selected);
            LOG.info("new severity = " + value);
            m_eventManager.fireEvent(new AlarmSeverityUpdatedEvent(AlarmSeverity.get(value)));
            event.stopPropagation();
        }
    });
    m_severityBox.addStyleName(css.label());
    this.add(label);
    this.add(m_severityBox);
    LOG.info("AlarmControl.doOnAdd(): finished, returning: " + this.getElement());
    m_componentTracker.ready(getClass());
    return this.getElement();
}
Also used : AlarmSeverity(org.opennms.features.vaadin.nodemaps.internal.gwt.client.AlarmSeverity) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Label(com.google.gwt.user.client.ui.Label) AlarmSeverityUpdatedEvent(org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.AlarmSeverityUpdatedEvent) ListBox(com.google.gwt.user.client.ui.ListBox)

Example 73 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.

the class ChangeStatusTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Change member's status");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("300px", "100%");
    FlexTable layout = new FlexTable();
    layout.setSize("100%", "100%");
    layout.setStyleName("inputFormFlexTable");
    final HTML text = new HTML("");
    final ListBox lb = new ListBox(false);
    lb.addItem("VALID", "VALID");
    lb.addItem("INVALID", "INVALID");
    lb.addItem("SUSPENDED", "SUSPENDED");
    lb.addItem("EXPIRED", "EXPIRED");
    lb.addItem("DISABLED", "DISABLED");
    layout.setHTML(0, 0, "Current status:");
    layout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    layout.setHTML(0, 1, member.getStatus());
    if (member.getStatus().equalsIgnoreCase("VALID")) {
        layout.setHTML(1, 0, "Member is properly configured and have access on provided resources.");
    } else if (member.getStatus().equalsIgnoreCase("INVALID")) {
        layout.setHTML(1, 0, "Member have configuration error and DON'T have access on provided resources. You can check what is wrong by changing member's status to VALID. If possible, procedure will configure all necessary settings by itself.");
    } else if (member.getStatus().equalsIgnoreCase("SUSPENDED")) {
        layout.setHTML(1, 0, "Member violated some rules and DON'T have access on provided resources.");
    } else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
        layout.setHTML(1, 0, "Member didn't extend membership and DON'T have access on provided resources.");
    } else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
        layout.setHTML(1, 0, "Member didn't extend membership long time ago or was manually disabled and DON'T have access on provided resources.");
    }
    layout.getFlexCellFormatter().setColSpan(1, 0, 2);
    layout.getFlexCellFormatter().setStyleName(1, 0, "inputFormInlineComment");
    layout.setHTML(2, 0, "New status:");
    layout.getFlexCellFormatter().setStyleName(2, 0, "itemName");
    layout.setWidget(2, 1, lb);
    layout.setWidget(3, 0, text);
    layout.getFlexCellFormatter().setColSpan(3, 0, 2);
    layout.getFlexCellFormatter().setStyleName(3, 0, "inputFormInlineComment");
    // pick which one is already set
    for (int i = 0; i < lb.getItemCount(); i++) {
        if (lb.getItemText(i).equalsIgnoreCase(member.getStatus())) {
            lb.setSelectedIndex(i);
        }
    }
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    final CustomButton changeButton = new CustomButton("Change status", ButtonTranslation.INSTANCE.changeStatus(member.getUser().getFullName()), SmallIcons.INSTANCE.diskIcon());
    // by default false
    changeButton.setEnabled(false);
    changeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            SetStatus request = new SetStatus(memberId, JsonCallbackEvents.disableButtonEvents(changeButton, JsonCallbackEvents.mergeEvents(events, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // close without refresh
                    session.getTabManager().closeTab(tab, false);
                }
            })));
            request.setStatus(lb.getValue(lb.getSelectedIndex()));
        }
    });
    menu.addWidget(changeButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, ButtonTranslation.INSTANCE.cancelButton(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    // listbox change handler
    lb.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (lb.getValue(lb.getSelectedIndex()).equalsIgnoreCase(member.getStatus())) {
                changeButton.setEnabled(false);
            } else {
                changeButton.setEnabled(true);
            }
            // clear
            text.setHTML("");
            if (lb.getSelectedIndex() == 0) {
                // VALIDATING NOTICE
                if (!member.getStatus().equalsIgnoreCase("VALID"))
                    text.setHTML("Changing status to VALID <strong>will trigger automatic configuration</strong> for provided resources. <br/><strong>If successful</strong>, member will have access on provided resources. <br /><strong>If not</strong>, see displayed error message and do manual configuration on 'settings' tab on members detail.");
            } else {
                // INVALIDATING NOTICE
                if (member.getStatus().equalsIgnoreCase("VALID"))
                    text.setHTML("Changing status to " + lb.getValue(lb.getSelectedIndex()) + " will <strong>prevent member from access to provided resources (based on provided service's rules)</strong>.<br /><br />");
            }
            // SET INFO
            if (lb.getSelectedIndex() == 1) {
                text.setHTML(text.getHTML() + "INVALID status means there is configuration error, which prevents him from access on provided resources.");
            } else if (lb.getSelectedIndex() == 2) {
                text.setHTML(text.getHTML() + "SUSPENDED status means, that member did something bad (against VO rules).");
            } else if (lb.getSelectedIndex() == 3) {
                text.setHTML(text.getHTML() + "EXPIRED status means, that member didn't extend his membership in VO, but it's still possible for him to do so.");
            } else if (lb.getSelectedIndex() == 4) {
                text.setHTML(text.getHTML() + "DISABLED status means, that member didn't extend his membership long ago or was manually disabled by administrator. Member can't enable/extend membership by himself.");
            }
        }
    });
    vp.add(layout);
    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) 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) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetStatus(cz.metacentrum.perun.webgui.json.membersManager.SetStatus)

Example 74 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.

the class ApplicationDetailTabItem method draw.

public Widget draw() {
    tab = this;
    row = 0;
    boolean buttonsEnabled = ((session.isVoAdmin(app.getVo().getId())) || (app.getGroup() != null && session.isGroupAdmin(app.getGroup().getId())));
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    final FlexTable ft = new FlexTable();
    String text = "<strong>Submitted by:</strong> ";
    if (app.getUser() != null) {
        text += app.getUser().getFullNameWithTitles() + " (" + app.getCreatedBy() + ")";
    } else {
        text += app.getCreatedBy();
    }
    text += " <strong>from External Source:</strong> " + app.getExtSourceName() + " <strong>with Level of Assurance:</strong> " + app.getExtSourceLoa();
    text += " <strong>on: </strong> " + app.getCreatedAt().split("\\.")[0];
    ft.setHTML(row, 0, text);
    ft.setCellSpacing(5);
    row++;
    if (app.getGroup() != null) {
        ft.setHTML(row, 0, "<strong>Application for group: </strong>" + app.getGroup().getName() + "<strong> in VO: </strong>" + app.getVo().getName());
    } else {
        ft.setHTML(row, 0, "<strong>Application for VO: </strong>" + app.getVo().getName());
    }
    if (app.getState().equalsIgnoreCase("APPROVED")) {
        row++;
        ft.setHTML(row, 0, "<strong>Approved by:</strong> " + ((app.getModifiedBy().equalsIgnoreCase("perunRegistrar")) ? "automatically" : Utils.convertCertCN(app.getModifiedBy())) + " <strong>on: </strong> " + app.getModifiedAt().split("\\.")[0]);
    }
    if (app.getState().equalsIgnoreCase("REJECTED")) {
        row++;
        ft.setHTML(row, 0, "<strong>Rejected by:</strong> " + ((app.getModifiedBy().equalsIgnoreCase("perunRegistrar")) ? "automatically" : Utils.convertCertCN(app.getModifiedBy())) + " <strong>on: </strong> " + app.getModifiedAt().split("\\.")[0]);
    }
    // for extension in VO if not approved or rejected
    if (app.getType().equalsIgnoreCase("EXTENSION") && app.getUser() != null && !app.getState().equalsIgnoreCase("APPROVED") && !app.getState().equalsIgnoreCase("REJECTED")) {
        GetNewExtendMembership ex = new GetNewExtendMembership(app.getVo().getId(), app.getUser().getId(), new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                if (jso != null) {
                    BasicOverlayType basic = jso.cast();
                    row++;
                    ft.setHTML(row, 0, "<strong>New membership expiration:</strong> " + basic.getString());
                }
            }
        });
        ex.retrieveData();
    }
    // for initial in VO, if not approved or rejected
    if (app.getType().equalsIgnoreCase("INITIAL") && app.getGroup() == null && !app.getState().equalsIgnoreCase("APPROVED") && !app.getState().equalsIgnoreCase("REJECTED")) {
        GetNewExtendMembershipLoa ex = new GetNewExtendMembershipLoa(app.getVo().getId(), app.getExtSourceLoa(), new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                if (jso != null) {
                    BasicOverlayType basic = jso.cast();
                    row++;
                    ft.setHTML(row, 0, "<strong>New membership expiration:</strong> " + basic.getString());
                }
            }
        });
        ex.retrieveData();
    }
    vp.add(ft);
    vp.add(new HTML("<hr size=\"1\" style=\"color: #ccc;\"/>"));
    // only NEW apps can be Verified
    if (app.getState().equals("NEW")) {
        if (session.isPerunAdmin()) {
            // verify button
            final CustomButton verify = TabMenu.getPredefinedButton(ButtonType.VERIFY, ButtonTranslation.INSTANCE.verifyApplication());
            menu.addWidget(verify);
            verify.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    HandleApplication request = new HandleApplication(JsonCallbackEvents.disableButtonEvents(verify, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            app = jso.cast();
                            draw();
                        }
                    }));
                    request.verifyApplication(appId);
                }
            });
        }
    }
    // only VERIFIED apps can be approved/rejected
    if (app.getState().equals("VERIFIED") || app.getState().equals("NEW")) {
        // accept button
        final CustomButton approve = TabMenu.getPredefinedButton(ButtonType.APPROVE, ButtonTranslation.INSTANCE.approveApplication());
        approve.setEnabled(buttonsEnabled);
        menu.addWidget(approve);
        approve.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                HandleApplication request = new HandleApplication(JsonCallbackEvents.disableButtonEvents(approve, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        session.getTabManager().closeTab(tab, true);
                    }
                }));
                request.approveApplication(app);
            }
        });
        //reject button
        final CustomButton reject = TabMenu.getPredefinedButton(ButtonType.REJECT, ButtonTranslation.INSTANCE.rejectApplication());
        reject.setEnabled(buttonsEnabled);
        menu.addWidget(reject);
        reject.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                // confirm content
                FlexTable content = new FlexTable();
                content.setCellSpacing(10);
                content.setHTML(0, 0, "Please specify reason of rejection to let user know why was application rejected.");
                content.getFlexCellFormatter().setColSpan(0, 0, 2);
                final TextArea reason = new TextArea();
                reason.setSize("300px", "150px");
                content.setHTML(1, 0, "<strong>Reason: </strong>");
                content.setWidget(1, 1, reason);
                Confirm c = new Confirm("Specify reason", content, new ClickHandler() {

                    public void onClick(ClickEvent event) {
                        HandleApplication request = new HandleApplication(JsonCallbackEvents.disableButtonEvents(reject, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                session.getTabManager().closeTab(tab, true);
                            }
                        }));
                        request.rejectApplication(appId, reason.getText());
                    }
                }, true);
                c.show();
            }
        });
    }
    if (app.getState().equals("NEW") || app.getState().equals("REJECTED")) {
        // delete button
        final CustomButton delete = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteApplication());
        delete.setEnabled(buttonsEnabled);
        menu.addWidget(delete);
        delete.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                HandleApplication request = new HandleApplication(JsonCallbackEvents.disableButtonEvents(delete, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        session.getTabManager().closeTab(tab, true);
                    }
                }));
                request.deleteApplication(appId);
            }
        });
    }
    // NOTIFICATION SENDER
    final CustomButton send = new CustomButton("Re-send notifications...", SmallIcons.INSTANCE.emailIcon());
    send.setEnabled(buttonsEnabled);
    menu.addWidget(send);
    send.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final FlexTable ft = new FlexTable();
            ft.setStyleName("inputFormFlexTable");
            ft.setWidth("400px");
            final ListBox selection = new ListBox();
            selection.setWidth("200px");
            if (session.isPerunAdmin()) {
                // add all except user invite
                for (ApplicationMail.MailType mail : ApplicationMail.MailType.values()) {
                    if (!mail.equals(ApplicationMail.MailType.USER_INVITE)) {
                        selection.addItem(ApplicationMail.getTranslatedMailType(mail.toString()), mail.toString());
                    }
                }
            } else {
                // add TYPEs based on actual APP-STATE
                if (app.getState().equals("NEW")) {
                    selection.addItem(ApplicationMail.getTranslatedMailType("APP_CREATED_USER"), "APP_CREATED_USER");
                    selection.addItem(ApplicationMail.getTranslatedMailType("APP_CREATED_VO_ADMIN"), "APP_CREATED_VO_ADMIN");
                    selection.addItem(ApplicationMail.getTranslatedMailType("MAIL_VALIDATION"), "MAIL_VALIDATION");
                } else if (app.getState().equals("VERIFIED")) {
                    selection.addItem(ApplicationMail.getTranslatedMailType("APP_CREATED_USER"), "APP_CREATED_USER");
                    selection.addItem(ApplicationMail.getTranslatedMailType("APP_CREATED_VO_ADMIN"), "APP_CREATED_VO_ADMIN");
                } else if (app.getState().equals("APPROVED")) {
                    selection.addItem(ApplicationMail.getTranslatedMailType("APP_APPROVED_USER"), "APP_APPROVED_USER");
                } else if (app.getState().equals("REJECTED")) {
                    selection.addItem(ApplicationMail.getTranslatedMailType("APP_REJECTED_USER"), "APP_REJECTED_USER");
                }
            }
            ft.setHTML(0, 0, "Select notification:");
            ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
            ft.setWidget(0, 1, selection);
            final TextArea reason = new TextArea();
            reason.setSize("250px", "100px");
            selection.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(ChangeEvent event) {
                    if (selection.getValue(selection.getSelectedIndex()).equals("APP_REJECTED_USER")) {
                        ft.setHTML(1, 0, "Reason:");
                        ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
                        ft.setWidget(1, 1, reason);
                    } else {
                        ft.setHTML(1, 0, "");
                        ft.setHTML(1, 1, "");
                    }
                }
            });
            // if pre-selected
            if (selection.getValue(selection.getSelectedIndex()).equals("APP_REJECTED_USER")) {
                ft.setHTML(1, 0, "Reason:");
                ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
                ft.setWidget(1, 1, reason);
            } else {
                ft.setHTML(1, 0, "");
                ft.setHTML(1, 1, "");
            }
            final Confirm c = new Confirm("Re-send notifications", ft, null, true);
            c.setOkIcon(SmallIcons.INSTANCE.emailIcon());
            c.setOkButtonText("Send");
            c.setNonScrollable(true);
            c.setOkClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    ResendNotification call = new ResendNotification(appId, JsonCallbackEvents.disableButtonEvents(c.getOkButton(), new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            c.hide();
                        }
                    }));
                    if (selection.getValue(selection.getSelectedIndex()).equals("APP_REJECTED_USER")) {
                        call.resendNotification(selection.getValue(selection.getSelectedIndex()), reason.getValue().trim());
                    } else {
                        call.resendNotification(selection.getValue(selection.getSelectedIndex()), null);
                    }
                }
            });
            c.setCancelClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    c.hide();
                }
            });
            c.show();
        }
    });
    menu.addWidget(new HTML("<strong>TYPE: </strong>" + Application.getTranslatedType(app.getType())));
    menu.addWidget(new HTML("<strong>STATE: </strong>" + Application.getTranslatedState(app.getState())));
    GetApplicationDataById data = new GetApplicationDataById(appId);
    data.retrieveData();
    ScrollPanel sp = new ScrollPanel(data.getContents());
    sp.setSize("100%", "100%");
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    vp.setCellHorizontalAlignment(sp, HasHorizontalAlignment.ALIGN_CENTER);
    session.getUiElements().resizePerunTable(sp, 400, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) HandleApplication(cz.metacentrum.perun.webgui.json.registrarManager.HandleApplication) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) GetNewExtendMembershipLoa(cz.metacentrum.perun.webgui.json.membersManager.GetNewExtendMembershipLoa) GetNewExtendMembership(cz.metacentrum.perun.webgui.json.membersManager.GetNewExtendMembership) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetApplicationDataById(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationDataById) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ResendNotification(cz.metacentrum.perun.webgui.json.registrarManager.ResendNotification) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 75 with ChangeEvent

use of com.google.gwt.event.dom.client.ChangeEvent in project perun by CESNET.

the class CopyFormTabItem 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) {
            CopyForm request = null;
            if (groupsBox.getSelectedIndex() != 0 && voId != 0 && groupId == 0) {
                // from group to VO
                request = new CopyForm(PerunEntity.GROUP, groupsBox.getSelectedObject().getId(), PerunEntity.VIRTUAL_ORGANIZATION, voId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
            } else if (groupsBox.getSelectedIndex() != 0 && voId != 0 && groupId != 0) {
                // from group to group
                request = new CopyForm(PerunEntity.GROUP, groupsBox.getSelectedObject().getId(), PerunEntity.GROUP, groupId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
            } else if (groupsBox.getSelectedIndex() == 0 && voId != 0 && groupId == 0) {
                // from VO to VO
                request = new CopyForm(PerunEntity.VIRTUAL_ORGANIZATION, vosBox.getSelectedObject().getId(), PerunEntity.VIRTUAL_ORGANIZATION, voId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
            } else if (groupsBox.getSelectedIndex() == 0 && voId != 0 && groupId != 0) {
                // from VO to group
                request = new CopyForm(PerunEntity.VIRTUAL_ORGANIZATION, vosBox.getSelectedObject().getId(), PerunEntity.GROUP, groupId, JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
            }
            request.copyForm();
        }
    });
    content.setHTML(2, 0, "All form items 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, false);
        }
    }));
    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) CopyForm(cz.metacentrum.perun.webgui.json.registrarManager.CopyForm) 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) 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

ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)99 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)98 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)41 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)41 ListBox (org.gwtbootstrap3.client.ui.ListBox)32 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)31 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)28 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)27 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)27 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)27 ArrayList (java.util.ArrayList)21 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)20 PerunError (cz.metacentrum.perun.webgui.model.PerunError)16 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)15 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)13 FormStylePopup (org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup)12 HashMap (java.util.HashMap)11 Map (java.util.Map)9 Button (org.gwtbootstrap3.client.ui.Button)9 HTML (com.google.gwt.user.client.ui.HTML)7