Search in sources :

Example 1 with AjaxLoaderImage

use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.

the class ApplicationFormGui method prepareGui.

/**
	 * Prepares the GUI
	 * @param entity PerunEntity GROUP or VO
	 * @param applicationType INITIAL | EXTENSION
	 */
protected void prepareGui(PerunEntity entity, String applicationType) {
    if (Location.getParameterMap().keySet().contains("m") && Location.getParameterMap().keySet().contains("i")) {
        String verifyI = Location.getParameter("i");
        String verifyM = Location.getParameter("m");
        if (verifyI != null && !verifyI.isEmpty() && verifyM != null && !verifyM.isEmpty()) {
            final SimplePanel verifContent = new SimplePanel();
            Anchor a = leftMenu.addItem(ApplicationMessages.INSTANCE.emailValidationMenuItem(), SmallIcons.INSTANCE.emailIcon(), verifContent);
            a.fireEvent(new ClickEvent() {
            });
            ValidateEmail request = new ValidateEmail(verifyI, verifyM, new JsonCallbackEvents() {

                @Override
                public void onLoadingStart() {
                    verifContent.clear();
                    verifContent.add(new AjaxLoaderImage());
                }

                @Override
                public void onFinished(JavaScriptObject jso) {
                    BasicOverlayType obj = jso.cast();
                    if (obj.getBoolean() == true) {
                        verifContent.clear();
                        FlexTable ft = new FlexTable();
                        ft.setSize("100%", "300px");
                        ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.acceptIcon()) + "<h2>" + ApplicationMessages.INSTANCE.emailValidationSuccess() + "</h2>");
                        ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                        ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                        verifContent.add(ft);
                    } else {
                        verifContent.clear();
                        FlexTable ft = new FlexTable();
                        ft.setSize("100%", "300px");
                        ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.deleteIcon()) + "<h2>" + ApplicationMessages.INSTANCE.emailValidationFail() + "</h2>");
                        ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                        ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                        verifContent.add(ft);
                    }
                }

                @Override
                public void onError(PerunError error) {
                    ((AjaxLoaderImage) verifContent.getWidget()).loadingError(error);
                }
            });
            request.retrieveData();
            leftMenu.addLogoutItem();
            return;
        }
    }
    // group and extension is not allowed
    if (group != null && applicationType.equalsIgnoreCase("EXTENSION")) {
        RootLayoutPanel panel = RootLayoutPanel.get();
        panel.clear();
        FlexTable ft = new FlexTable();
        ft.setSize("100%", "300px");
        ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Error: " + ApplicationMessages.INSTANCE.groupMembershipCantBeExtended(group.getName()) + "</h2>");
        ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
        ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
        panel.add(ft);
        // redirect if possible
        if (Location.getParameter("targetexisting") != null) {
            Location.replace(Location.getParameter("targetexisting"));
        }
        return;
    }
    // application form page
    ApplicationFormPage formPage = new ApplicationFormPage(vo, group, applicationType);
    // even user "not yet in perun" can have some applications sent (therefore display by session info)
    UsersApplicationsPage appsPage = new UsersApplicationsPage();
    // if rt test
    if ("true".equals(Location.getParameter("rttest"))) {
        TestRtReportingTabItem tabItem = new TestRtReportingTabItem();
        Widget rtTab = tabItem.draw();
        leftMenu.addItem("RT test", SmallIcons.INSTANCE.settingToolsIcon(), rtTab);
    }
    // proper menu text
    String appMenuText = ApplicationMessages.INSTANCE.applicationFormForVo(vo.getName());
    if (group != null) {
        appMenuText = ApplicationMessages.INSTANCE.applicationFormForGroup(group.getName());
    }
    if (applicationType.equalsIgnoreCase("EXTENSION")) {
        appMenuText = ApplicationMessages.INSTANCE.membershipExtensionForVo(vo.getName());
        if (group != null) {
            appMenuText = ApplicationMessages.INSTANCE.membershipExtensionForGroup(group.getName());
        }
    }
    // load list of applications first if param in session
    if ("apps".equals(Location.getParameter("page"))) {
        Anchor a = leftMenu.addItem(ApplicationMessages.INSTANCE.applications(), SmallIcons.INSTANCE.applicationFromStorageIcon(), appsPage);
        leftMenu.addItem(appMenuText, SmallIcons.INSTANCE.applicationFormIcon(), formPage);
        a.fireEvent(new ClickEvent() {
        });
    //appsPage.menuClick(); // load list of apps
    } else {
        Anchor a = leftMenu.addItem(appMenuText, SmallIcons.INSTANCE.applicationFormIcon(), formPage);
        leftMenu.addItem(ApplicationMessages.INSTANCE.applications(), SmallIcons.INSTANCE.applicationFromStorageIcon(), appsPage);
        a.fireEvent(new ClickEvent() {
        });
    //formPage.menuClick(); // load application form
    }
    leftMenu.addLogoutItem();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ValidateEmail(cz.metacentrum.perun.webgui.json.registrarManager.ValidateEmail) TestRtReportingTabItem(cz.metacentrum.perun.webgui.tabs.testtabs.TestRtReportingTabItem) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) RecaptchaWidget(cz.metacentrum.perun.webgui.widgets.recaptcha.RecaptchaWidget) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) UsersApplicationsPage(cz.metacentrum.perun.webgui.client.applicationresources.pages.UsersApplicationsPage) ApplicationFormPage(cz.metacentrum.perun.webgui.client.applicationresources.pages.ApplicationFormPage)

Example 2 with AjaxLoaderImage

use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.

the class WebGui method checkIfMailVerification.

/**
 * Check if URL parameters contains data for mail verification and display different GUI instead.
 *
 * @return TRUE if parameters are contained and valid in URL, FALSE otherwise.
 */
public boolean checkIfMailVerification() {
    // Trigger validation if necessary
    if (Location.getParameterMap().keySet().contains("token") && Location.getParameterMap().keySet().contains("u")) {
        String verifyToken = Location.getParameter("token");
        String verifyU = Location.getParameter("u");
        if (verifyToken != null && !verifyToken.isEmpty() && verifyU != null && !verifyU.isEmpty() && JsonUtils.checkParseInt(verifyU)) {
            ValidatePreferredEmailChange call = new ValidatePreferredEmailChange(verifyToken, Integer.parseInt(verifyU), new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    BasicOverlayType over = jso.cast();
                    RootLayoutPanel body = RootLayoutPanel.get();
                    body.clear();
                    FlexTable ft = new FlexTable();
                    ft.setSize("100%", "300px");
                    ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.acceptIcon()) + "<h2>" + "The email address: <i>" + (SafeHtmlUtils.fromString(over.getString())).asString() + "</i></h2><h2>was verified and set as your preferred email.</h2>");
                    ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                    body.add(ft);
                }

                @Override
                public void onLoadingStart() {
                    RootLayoutPanel body = RootLayoutPanel.get();
                    body.clear();
                    FlexTable ft = new FlexTable();
                    ft.setSize("100%", "300px");
                    ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                    ft.setWidget(0, 0, new AjaxLoaderImage());
                    body.add(ft);
                }

                @Override
                public void onError(PerunError error) {
                    RootLayoutPanel body = RootLayoutPanel.get();
                    body.clear();
                    FlexTable ft = new FlexTable();
                    ft.setSize("100%", "300px");
                    ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.deleteIcon()) + "<h2>Your new email address couldn't be verified !</h2>");
                    ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                    if (error == null) {
                        ft.setHTML(1, 0, "Request timeout exceeded.");
                        ft.getFlexCellFormatter().setStyleName(1, 0, "serverResponseLabelError");
                    } else {
                        // display raw message
                        ft.setHTML(1, 0, "<strong>" + error.getErrorInfo() + "</strong>");
                    }
                    ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                    body.add(ft);
                }
            });
            call.retrieveData();
        }
        return true;
    }
    return false;
}
Also used : ValidatePreferredEmailChange(cz.metacentrum.perun.webgui.json.usersManager.ValidatePreferredEmailChange) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType) PerunError(cz.metacentrum.perun.webgui.model.PerunError) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)

Example 3 with AjaxLoaderImage

use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.

the class ResourceSettingsTabItem method draw.

public Widget draw() {
    if (service != null) {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": " + service.getName() + " configuration");
    } else {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": service configuration");
    }
    vp.setSize("100%", "100%");
    vp.clear();
    // menu
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    // callback
    final GetRequiredAttributesV2 resAttrs = new GetRequiredAttributesV2();
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resource", resourceId);
    resAttrs.setIds(ids);
    final GetAttributesV2 attrs = new GetAttributesV2();
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        resAttrs.setCheckable(false);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        attrs.setCheckable(false);
    // puts first table
    final CellTable<Attribute> table = resAttrs.getEmptyTable();
    final CellTable<Attribute> table2 = attrs.getEmptyTable();
    // if for one service only modify empty table message
    if (service != null) {
        AjaxLoaderImage empty = (AjaxLoaderImage) table.getEmptyTableWidget();
        empty.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
        AjaxLoaderImage empty2 = (AjaxLoaderImage) table2.getEmptyTableWidget();
        empty2.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
    }
    final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
    sp.setWidget(table);
    sp2.setWidget(table2);
    // switch between assigned and all
    final CheckBox chb = new CheckBox();
    chb.setText(WidgetTranslation.INSTANCE.offerAvailableServicesOnly());
    chb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
    // default true
    chb.setValue(lastOfferAvailableOnly);
    // event which fills the listbox and call getRequiredAttributes
    JsonCallbackEvents event = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // clear services list
            servList.clear();
            // process services
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            for (int i = 0; i < srv.size(); i++) {
                // fill listbox
                servList.addItem(srv.get(i));
            }
            if (servList.isEmpty()) {
                servList.addNotSelectedOption();
                lastSelectedService = 0;
                indexInList = 0;
                attrs.retrieveData();
                setTable(false);
                return;
            }
            if (lastSelectedService == 0 && chb.getValue() == true) {
                servList.addNotSelectedOption();
                servList.addAllOption();
                if (indexInList == 0) {
                    servList.setSelectedIndex(0);
                    attrs.retrieveData();
                    setTable(false);
                    return;
                } else if (indexInList == 1) {
                    servList.setSelectedIndex(1);
                }
            } else if (lastSelectedService == 0 && chb.getValue() == false) {
                servList.addNotSelectedOption();
                servList.setSelectedIndex(0);
                attrs.retrieveData();
                setTable(false);
                return;
            } else if (lastSelectedService != 0) {
                if (chb.getValue() == true) {
                    servList.addNotSelectedOption();
                    servList.addAllOption();
                } else {
                    servList.addNotSelectedOption();
                }
                // remove last service, we can't be sure it was loaded again
                ids.remove("service");
                // either all or specific service
                servList.setSelectedIndex(1);
                for (Service s : servList.getAllObjects()) {
                    if (s.getId() == lastSelectedService) {
                        // service selected last time was found in a list
                        servList.setSelected(s, true);
                        ids.put("service", s.getId());
                        break;
                    }
                }
            }
            // make call
            resAttrs.clearTable();
            resAttrs.setIds(ids);
            resAttrs.retrieveData();
            setTable(true);
        }

        @Override
        public void onError(PerunError error) {
            servList.clear();
            servList.addItem("Error while loading");
            if (required) {
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
            } else {
                ((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
            }
        }

        @Override
        public void onLoadingStart() {
            servList.removeAllOption();
            servList.removeNotSelectedOption();
            servList.clear();
            servList.addItem("Loading...");
        }
    };
    final GetAssignedServices services = new GetAssignedServices(resourceId, event);
    final GetServices allServices = new GetServices(event);
    // offer services selection
    if (serviceId == 0) {
        // services listbox
        servList.setTitle("Services");
        attrs.setIds(ids);
        // on change of service update table
        servList.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                // if service selected
                if (servList.getSelectedIndex() == 0) {
                    attrs.retrieveData();
                    setTable(false);
                    lastSelectedService = 0;
                    indexInList = 0;
                    return;
                } else if (chb.getValue() == true && servList.getSelectedIndex() == 1) {
                    ids.remove("service");
                    lastSelectedService = 0;
                    indexInList = 1;
                } else if ((chb.getValue() == true && servList.getSelectedIndex() > 1) || (chb.getValue() == false && servList.getSelectedIndex() > 0)) {
                    ids.put("service", servList.getSelectedObject().getId());
                    lastSelectedService = servList.getSelectedObject().getId();
                }
                lastOfferAvailableOnly = chb.getValue();
                resAttrs.clearTable();
                resAttrs.setIds(ids);
                resAttrs.retrieveData();
                setTable(true);
            }
        });
        if (chb.getValue() == false) {
            allServices.retrieveData();
        } else {
            services.retrieveData();
        }
    } else {
        // retrieve data for selected service only
        lastSelectedService = serviceId;
        lastOfferAvailableOnly = chb.getValue();
        ids.put("service", serviceId);
        resAttrs.setIds(ids);
        resAttrs.retrieveData();
        setTable(true);
    }
    // refresh table event - refresh only on finished / on error keep selected
    final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resAttrs);
    final JsonCallbackEvents refreshTable2 = JsonCallbackEvents.refreshTableEvents(attrs);
    // 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);
    final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable2);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getTableSelectedList();
            } else {
                list = attrs.getTableSelectedList();
            }
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
                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) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getList();
            } else {
                list = attrs.getList();
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("resource", resourceId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, list), true);
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        setNewAttributeButton.setEnabled(false);
    if (service == null) {
        menu.addWidget(setNewAttributeButton);
    }
    // fill button
    final CustomButton fillDefaultButton = TabMenu.getPredefinedButton(ButtonType.FILL, ButtonTranslation.INSTANCE.fillResourceAttributes());
    menu.addWidget(fillDefaultButton);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
    final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable2);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        removeButton.setEnabled(false);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getTableSelectedList();
            } else {
                list = attrs.getTableSelectedList();
            }
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add service selection to menu and switcher
    if (serviceId == 0) {
        menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
        menu.addWidget(servList);
        menu.addWidget(chb);
    }
    // checkbox switcher on click
    chb.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (chb.getValue() == false) {
                lastOfferAvailableOnly = false;
                allServices.retrieveData();
            } else {
                lastOfferAvailableOnly = true;
                services.retrieveData();
            }
        }
    });
    fillDefaultButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // automatically try to fill all attributes
            ArrayList<Attribute> prepareList = new ArrayList<Attribute>();
            if (required) {
                prepareList = resAttrs.getTableSelectedList();
            } else {
                prepareList = attrs.getTableSelectedList();
            }
            final ArrayList<Attribute> list = prepareList;
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                FillAttributes request = new FillAttributes(JsonCallbackEvents.disableButtonEvents(fillDefaultButton, new JsonCallbackEvents() {

                    boolean wasRequiredTable = required;

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // remove attribute from original table and put new ones
                        ArrayList<Attribute> newList = JsonUtils.jsoAsList(jso);
                        for (Attribute a : newList) {
                            for (Attribute oldA : list) {
                                // deselect old
                                if (a.getId() == oldA.getId()) {
                                    if (wasRequiredTable) {
                                        resAttrs.getSelectionModel().setSelected(oldA, false);
                                        resAttrs.removeFromTable(oldA);
                                    } else {
                                        attrs.getSelectionModel().setSelected(oldA, false);
                                        attrs.removeFromTable(oldA);
                                    }
                                }
                            }
                            if (wasRequiredTable) {
                                // add new
                                resAttrs.addToTable(a);
                                // select returned
                                resAttrs.getSelectionModel().setSelected(a, true);
                            } else {
                                // add new
                                attrs.addToTable(a);
                                // select returned
                                attrs.getSelectionModel().setSelected(a, true);
                            }
                        }
                        if (wasRequiredTable) {
                            resAttrs.sortTable();
                        } else {
                            attrs.sortTable();
                        }
                    }
                }));
                request.fillAttributes(ids, list);
            }
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        fillDefaultButton.setEnabled(false);
    /* TODO - not implemented

			 Button checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon());
			 menu.addWidget(checkValuesButton);
			 checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");


			 checkValuesButton.addClickHandler(new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });

*/
    table.addStyleName("perun-table");
    table.setWidth("100%");
    table2.addStyleName("perun-table");
    table2.setWidth("100%");
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    sp2.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp2, 350, this);
    // default is required attributes
    setTable(true);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) 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) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) Service(cz.metacentrum.perun.webgui.model.Service) 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) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with AjaxLoaderImage

use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.

the class FacilitiesPropagationsTabItem method draw.

public Widget draw() {
    mainrow = 0;
    okCounter = 0;
    errorCounter = 0;
    notDeterminedCounter = 0;
    procesingCounter = 0;
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setWidth("100%");
    final TabItem tab = this;
    // MAIN PANEL
    final ScrollPanel firstTabPanel = new ScrollPanel();
    firstTabPanel.setSize("100%", "100%");
    firstTabPanel.setStyleName("perun-tableScrollPanel");
    final FlexTable help = new FlexTable();
    help.setCellPadding(4);
    help.setWidth("100%");
    help.setHTML(0, 0, "<strong>Color&nbsp;notation:</strong>");
    help.getFlexCellFormatter().setWidth(0, 0, "100px");
    help.setHTML(0, 1, "<strong>OK</strong>");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setWidth(0, 1, "50px");
    help.getFlexCellFormatter().setStyleName(0, 1, "green");
    help.setHTML(0, 2, "<strong>Error</strong>");
    help.getFlexCellFormatter().setWidth(0, 2, "50px");
    help.getFlexCellFormatter().setStyleName(0, 2, "red");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
    help.setHTML(0, 3, "<strong>Not&nbsp;determined</strong>");
    help.getFlexCellFormatter().setWidth(0, 3, "50px");
    help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    help.getFlexCellFormatter().setStyleName(0, 3, "notdetermined");
    /*
			 help.setHTML(0, 4, "<strong>Processing</strong>");
			 help.getFlexCellFormatter().setWidth(0, 4, "50px");
			 help.getFlexCellFormatter().setStyleName(0, 4, "yellow");
			 help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
			 */
    final CustomButton cb = new CustomButton(ButtonTranslation.INSTANCE.refreshButton(), ButtonTranslation.INSTANCE.refreshPropagationResults(), SmallIcons.INSTANCE.updateIcon(), new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().reloadTab(tab);
        }
    });
    help.setWidget(0, 5, cb);
    help.getFlexCellFormatter().setWidth(0, 5, "200px");
    help.setHTML(0, 6, "&nbsp;");
    help.getFlexCellFormatter().setWidth(0, 6, "50%");
    mainTab.add(help);
    mainTab.add(new HTML("<hr size=\"2\" />"));
    mainTab.add(firstTabPanel);
    final FlexTable content = new FlexTable();
    content.setWidth("100%");
    content.setBorderWidth(0);
    firstTabPanel.add(content);
    content.setStyleName("propagationTable", true);
    final AjaxLoaderImage im = new AjaxLoaderImage();
    content.setWidget(0, 0, im);
    content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    final GetFacilityState callback = new GetFacilityState(0, 0, new JsonCallbackEvents() {

        public void onLoadingStart() {
            im.loadingStart();
            cb.setProcessing(true);
        }

        public void onError(PerunError error) {
            im.loadingError(error);
            cb.setProcessing(false);
        }

        public void onFinished(JavaScriptObject jso) {
            im.loadingFinished();
            cb.setProcessing(false);
            content.clear();
            content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
            ArrayList<FacilityState> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                list = new TableSorter<FacilityState>().sortByNumberOfDestinations(list);
                ArrayList<FacilityState> clusters = new ArrayList<FacilityState>();
                ArrayList<FacilityState> hosts = new ArrayList<FacilityState>();
                for (final FacilityState state : list) {
                    if (state.getDestinations().size() > 1) {
                        clusters.add(state);
                    } else {
                        hosts.add(state);
                    }
                }
                clusters = new TableSorter<FacilityState>().sortByFacilityName(clusters);
                hosts = new TableSorter<FacilityState>().sortByFacilityName(hosts);
                for (final FacilityState state : clusters) {
                    content.setHTML(mainrow, 0, "<strong>" + SafeHtmlUtils.fromString(state.getFacility().getName()).asString() + "</strong>");
                    final FlowPanel inner = new FlowPanel();
                    content.setWidget(mainrow + 1, 0, inner);
                    content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    int width = 0;
                    for (String dest : destinations) {
                        destList.add(dest);
                        if (dest.indexOf(".") * 8 > width) {
                            width = dest.indexOf(".") * 8;
                        }
                    }
                    Collections.sort(destList, new Comparator<String>() {

                        @Override
                        public int compare(String o1, String o2) {
                            return TableSorter.smartCompare(o1, o2);
                        }
                    });
                    for (final String dest : destList) {
                        String show = dest.substring(0, dest.indexOf("."));
                        if (show.length() == 0) {
                            show = dest;
                            width = dest.length() * 8;
                        }
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + SafeHtmlUtils.fromString((show != null) ? show : "").asString() + "</span>");
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
                            }
                        });
                        inner.add(hyp);
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        notDeterminedCounter++;
                    }
                    mainrow++;
                    mainrow++;
                }
                // PROCESS HOSTS (with one or less destination)
                // FIX WIDTH
                int width = 0;
                for (FacilityState state : hosts) {
                    if (state.getDestinations().size() < 2) {
                        if (state.getFacility().getName().length() * 8 > width) {
                            width = state.getFacility().getName().length() * 8;
                        }
                    }
                }
                FlowPanel inner = new FlowPanel();
                for (final FacilityState state : hosts) {
                    Set<String> destinations = state.getDestinations().keySet();
                    ArrayList<String> destList = new ArrayList<String>();
                    for (String dest : destinations) {
                        destList.add(dest);
                    }
                    Collections.sort(destList, new Comparator<String>() {

                        @Override
                        public int compare(String o1, String o2) {
                            return TableSorter.smartCompare(o1, o2);
                        }
                    });
                    for (final String dest : destList) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + SafeHtmlUtils.fromString((dest != null) ? dest : "").asString() + "</span>");
                        inner.add(hyp);
                        hyp.addClickHandler(new ClickHandler() {

                            public void onClick(ClickEvent clickEvent) {
                                session.getTabManager().addTab(new DestinationResultsTabItem(state.getFacility(), null, dest, false));
                            }
                        });
                        // style
                        if (state.getDestinations().get(dest).equals(new JSONString("ERROR"))) {
                            hyp.addStyleName("red");
                            errorCounter++;
                        } else if (state.getDestinations().get(dest).equals(new JSONString("OK"))) {
                            hyp.addStyleName("green");
                            okCounter++;
                        } else {
                            hyp.addStyleName("notdetermined");
                            notDeterminedCounter++;
                        }
                    }
                    if (destList.isEmpty()) {
                        Anchor hyp = new Anchor();
                        hyp.setHTML("<span style=\"display: inline-block; width: " + width + "px; text-align: center;\">" + SafeHtmlUtils.fromString((state.getFacility().getName() != null) ? state.getFacility().getName() : "").asString() + "</span>");
                        inner.add(hyp);
                        hyp.addStyleName("notdetermined");
                        notDeterminedCounter++;
                    }
                }
                if (!hosts.isEmpty()) {
                    content.setHTML(mainrow, 0, "<strong>Single hosts</strong>");
                    mainrow++;
                }
                content.setWidget(mainrow, 0, inner);
                content.getFlexCellFormatter().setStyleName(mainrow, 0, "propagationTablePadding");
                mainrow++;
            }
            // set counters
            help.setHTML(0, 1, "<strong>Ok&nbsp;(" + okCounter + ")</strong>");
            help.setHTML(0, 2, "<strong>Error&nbsp;(" + errorCounter + ")</strong>");
            help.setHTML(0, 3, "<strong>Not&nbsp;determined&nbsp;(" + notDeterminedCounter + ")</strong>");
        // help.setHTML(0, 4, "<strong>Processing&nbsp;(" + procesingCounter + ")</strong>");
        }
    });
    // get for all facilities
    callback.retrieveData();
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Set(java.util.Set) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString) GetFacilityState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityState) FacilityState(cz.metacentrum.perun.webgui.model.FacilityState) Comparator(java.util.Comparator) GetFacilityState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityState) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) JSONString(com.google.gwt.json.client.JSONString) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 5 with AjaxLoaderImage

use of cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage in project perun by CESNET.

the class SelfResourcesSettingsTabItem method loadSettings.

/**
 * Load settings for each resource (loaded only once onClick on header)
 *
 * @return settings content for each resource
 */
private void loadSettings(final DisclosurePanel settings, final Resource resource) {
    // create content table
    final FlexTable layoutx = new FlexTable();
    layoutx.setCellSpacing(5);
    GetAttributesV2 resourceAttrsCall = new GetAttributesV2();
    Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resource", resource.getId());
    resourceAttrsCall.setIds(ids);
    resourceAttrsCall.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            boolean disableOptOut = false;
            ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
            for (Attribute a : attrs) {
                if ("urn:perun:resource:attribute-def:def:disableMailingListOptOut".equals(a.getName())) {
                    disableOptOut = true;
                    break;
                }
            }
            loadContent(layoutx, resource, disableOptOut);
        }

        public void onLoadingStart() {
            AjaxLoaderImage loader = new AjaxLoaderImage(true);
            layoutx.setWidget(0, 0, loader.loadingStart());
        }

        public void onError(PerunError error) {
            AjaxLoaderImage loader = new AjaxLoaderImage(true);
            layoutx.setWidget(0, 0, loader.loadingError(error));
        }
    });
    // load content on open
    settings.addOpenHandler(new OpenHandler<DisclosurePanel>() {

        public void onOpen(OpenEvent<DisclosurePanel> event) {
            if (settings.getContent() == null) {
                resourceAttrsCall.retrieveData();
                // set content
                settings.setContent(layoutx);
            }
        }
    });
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) HashMap(java.util.HashMap) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ArrayList(java.util.ArrayList) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)15 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)15 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)14 ArrayList (java.util.ArrayList)12 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)10 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)9 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)9 PerunError (cz.metacentrum.perun.webgui.model.PerunError)9 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)7 HashMap (java.util.HashMap)5 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)3 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)3 Map (java.util.Map)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 JSONString (com.google.gwt.json.client.JSONString)2 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)2 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)2 FindCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)2 GetCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers)2