Search in sources :

Example 46 with Confirm

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

the class FindPublicationsByGUIFilter method getEmptyTable.

/**
 * Returns table of users publications
 * @return
 */
public CellTable<Publication> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Publication>(list);
    // Cell table
    table = new PerunTable<Publication>(list);
    // display row-count for perun admin only
    if (!session.isPerunAdmin()) {
        table.removeRowCountChangeHandler();
    }
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Publication> columnSortHandler = new ListHandler<Publication>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Publication>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No publications found. Try to change filtering options.");
    // show checkbox column
    if (this.checkable) {
        table.addCheckBoxColumn();
    }
    // ID COLUMN
    table.addIdColumn("Publication ID", tableFieldUpdater, 60);
    Column<Publication, ImageResource> lockedColumn = new Column<Publication, ImageResource>(new CustomImageResourceCell("click")) {

        public ImageResource getValue(Publication object) {
            if (object.isLocked()) {
                return SmallIcons.INSTANCE.lockIcon();
            } else {
                return SmallIcons.INSTANCE.lockOpenIcon();
            }
        }

        public void onBrowserEvent(final Context context, final Element elem, final Publication object, NativeEvent event) {
            // on click and for perun admin
            if ("click".equals(event.getType()) && session.isPerunAdmin()) {
                final ImageResource value;
                if (object.isLocked()) {
                    value = SmallIcons.INSTANCE.lockOpenIcon();
                    object.setLocked(false);
                } else {
                    value = SmallIcons.INSTANCE.lockIcon();
                    object.setLocked(true);
                }
                LockUnlockPublications request = new LockUnlockPublications(new JsonCallbackEvents() {

                    @Override
                    public void onLoadingStart() {
                        getCell().setValue(context, elem, SmallIcons.INSTANCE.updateIcon());
                    }

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // change picture (object already changed)
                        getCell().setValue(context, elem, value);
                    }

                    @Override
                    public void onError(PerunError error) {
                        // on error switch object back
                        if (object.isLocked()) {
                            object.setLocked(false);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockOpenIcon());
                        } else {
                            object.setLocked(true);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockIcon());
                        }
                    }
                });
                // send request
                ArrayList<Publication> list = new ArrayList<Publication>();
                list.add(object);
                request.lockUnlockPublications(object.isLocked(), list);
            }
        }
    };
    table.addColumn(lockedColumn, "Lock");
    // TITLE COLUMN
    Column<Publication, String> titleColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getTitle();
        }
    }, this.tableFieldUpdater);
    titleColumn.setSortable(true);
    columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
    table.addColumn(titleColumn, "Title");
    // if display authors
    if (ids.containsKey("authors")) {
        if ((Integer) ids.get("authors") == 1) {
            // AUTHORS COLUMN
            Column<Publication, String> authorColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

                public String getValue(Publication object) {
                    return object.getAuthorsFormatted();
                }
            }, this.tableFieldUpdater);
            authorColumn.setSortable(true);
            columnSortHandler.setComparator(authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
            table.addColumn(authorColumn, "Reported by");
        }
    }
    // YEAR COLUMN
    Column<Publication, String> yearColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return String.valueOf(object.getYear());
        }
    }, this.tableFieldUpdater);
    yearColumn.setSortable(true);
    columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
    table.addColumn(yearColumn, "Year");
    // CATEGORY COLUMN
    Column<Publication, String> categoryColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getCategoryName();
        }
    }, this.tableFieldUpdater);
    categoryColumn.setSortable(true);
    columnSortHandler.setComparator(categoryColumn, new PublicationComparator(PublicationComparator.Column.CATEGORY));
    table.addColumn(categoryColumn, "Category");
    // THANKS COLUMN
    Column<Publication, String> thanksColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            String result = "";
            JsArray<Thanks> thks = object.getThanks();
            for (int i = 0; i < thks.length(); i++) {
                result += thks.get(i).getOwnerName() + ", ";
            }
            if (result.length() >= 2) {
                result = result.substring(0, result.length() - 2);
            }
            return result;
        }
    }, this.tableFieldUpdater);
    thanksColumn.setSortable(true);
    columnSortHandler.setComparator(thanksColumn, new PublicationComparator(PublicationComparator.Column.THANKS));
    table.addColumn(thanksColumn, "Thanked to");
    /*
		 * HIDE ISBN COLUMN FOR NOW
		// ISBN COLUMN
		Column<Publication, String> isbnColumn = JsonUtils.addColumn(
		new CustomClickableTextCell(), "",
		new JsonUtils.GetValue<Publication, String>() {
		public String getValue(Publication object) {
		return object.getIsbn();
		}
		}, this.tableFieldUpdater);

		isbnColumn.setSortable(true);
		columnSortHandler.setComparator(isbnColumn, new PublicationComparator(PublicationComparator.Column.ISBN));
		table.addColumn(isbnColumn, "ISBN");
		*/
    // CITE COLUMN
    Column<Publication, String> citaceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return "Cite";
        }
    }, new FieldUpdater<Publication, String>() {

        public void update(int index, Publication object, String value) {
            SimplePanel sp = new SimplePanel();
            sp.add(new HTML(object.getMain()));
            Confirm cf = new Confirm("Cite publication", sp, true);
            cf.show();
        }
    });
    table.addColumn(citaceColumn, "Cite");
    return table;
}
Also used : PublicationComparator(cz.metacentrum.perun.webgui.json.comparators.PublicationComparator) Element(com.google.gwt.dom.client.Element) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) ImageResource(com.google.gwt.resources.client.ImageResource) Column(com.google.gwt.user.cellview.client.Column) Context(com.google.gwt.cell.client.Cell.Context) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) CustomImageResourceCell(cz.metacentrum.perun.webgui.widgets.cells.CustomImageResourceCell) JsArray(com.google.gwt.core.client.JsArray) Publication(cz.metacentrum.perun.webgui.model.Publication) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 47 with Confirm

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

the class CreateGroup method testCreating.

/**
 * Tests the values, if the process can continue
 *
 * @return
 */
private boolean testCreating() {
    boolean result = true;
    String errorMsg = "";
    if (groupName.length() == 0) {
        errorMsg += "You must fill in the parameter <strong>Name</strong>.<br />";
        result = false;
    }
    if (groupDescription.length() == 0) {
        errorMsg += "You must fill in the parameter <strong>Description</strong>.<br />";
        result = false;
    }
    if (errorMsg.length() > 0) {
        Confirm c = new Confirm("Error while creating Group", new HTML(errorMsg), true);
        c.show();
    }
    return result;
}
Also used : Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) JSONString(com.google.gwt.json.client.JSONString)

Example 48 with Confirm

use of cz.metacentrum.perun.webgui.widgets.Confirm 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 += SafeHtmlUtils.fromString(app.getUser().getFullNameWithTitles() + " (" + app.getCreatedBy() + ")").asString();
    } else {
        text += SafeHtmlUtils.fromString(app.getCreatedBy()).asString();
    }
    text += " <strong>from External Source:</strong> " + SafeHtmlUtils.fromString(app.getExtSourceName()).asString() + " <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>" + SafeHtmlUtils.fromString((app.getGroup().getName() != null) ? app.getGroup().getName() : "").asString() + "<strong> in VO: </strong>" + SafeHtmlUtils.fromString((app.getVo().getName() != null) ? app.getVo().getName() : "").asString());
    } else {
        ft.setHTML(row, 0, "<strong>Application for VO: </strong>" + SafeHtmlUtils.fromString((app.getVo().getName() != null) ? app.getVo().getName() : "").asString());
    }
    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> " + SafeHtmlUtils.fromString(basic.getString()).asString());
                }
            }
        });
        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> " + SafeHtmlUtils.fromString(basic.getString()).asString());
                }
            }
        });
        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();
                            refreshParent = true;
                        }
                    }));
                    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) {
                        refreshParent = true;
                        session.getTabManager().closeTab(tab, isRefreshParentOnClose());
                    }
                }));
                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) {
                                refreshParent = true;
                                session.getTabManager().closeTab(tab, isRefreshParentOnClose());
                            }
                        }));
                        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) {
                        refreshParent = true;
                        session.getTabManager().closeTab(tab, isRefreshParentOnClose());
                    }
                }));
                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");
                }
            // FIXME - how to handle APPROVABLE_GROUP_APP_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.setEditable(app.getState().equals("VERIFIED") || app.getState().equals("NEW"));
    data.setEmbedded(app.getType().equals("EMBEDDED"), app.getUser());
    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 49 with Confirm

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

the class FacilityStatusTabItem method draw.

public Widget draw() {
    // title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Services status");
    // main content
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // get empty table
    final GetFacilityServicesState callback = new GetFacilityServicesState(facility.getId());
    CustomButton refreshButton = UiElements.getRefreshButton(this);
    // callback.setEvents(JsonCallbackEvents.disableButtonEvents(refreshButton));
    final CellTable<ServiceState> table = callback.getTable(new FieldUpdater<ServiceState, String>() {

        // on row click
        public void update(int index, final ServiceState object, String value) {
            // show results if any present
            if (object.getTask() != null) {
                session.getTabManager().addTab(new TaskResultsTabItem(object.getTask()));
            }
        }
    });
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    final CustomButton forceButton = new CustomButton(ButtonTranslation.INSTANCE.forcePropagationButton(), ButtonTranslation.INSTANCE.forcePropagation(), SmallIcons.INSTANCE.arrowRightIcon());
    forceButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> forceList = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(forceList)) {
                // TODO - translated Widget
                boolean denied = false;
                VerticalPanel vp = new VerticalPanel();
                vp.add(new HTML("<p>Some services can't be forcefully propagated, because they are <strong>blocked on facility</strong>. Please change their state to 'Allowed' before starting force propagation.</p>"));
                for (int i = 0; i < forceList.size(); i++) {
                    if (forceList.get(i).isBlockedOnFacility() || forceList.get(i).isBlockedGlobally()) {
                        vp.add(new Label(" - " + forceList.get(i).getService().getName()));
                        denied = true;
                    }
                }
                if (denied) {
                    // show conf
                    Confirm c = new Confirm("Can't propagated blocked services", vp, true);
                    c.show();
                    return;
                }
            }
            // show propagation status page on last call start
            JsonCallbackEvents events = new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // unselect all services
                    for (ServiceState service : forceList) {
                        callback.getSelectionModel().setSelected(service, false);
                    }
                }
            };
            // starts propagation for all selected services
            for (int i = 0; i < forceList.size(); i++) {
                if (i != forceList.size() - 1) {
                    // force propagation
                    ForceServicePropagation request = new ForceServicePropagation(JsonCallbackEvents.disableButtonEvents(forceButton));
                    request.forcePropagation(facility.getId(), forceList.get(i).getService().getId());
                } else {
                    // force propagation with show status page
                    ForceServicePropagation request = new ForceServicePropagation(JsonCallbackEvents.disableButtonEvents(forceButton, events));
                    request.forcePropagation(facility.getId(), forceList.get(i).getService().getId());
                }
            }
        }
    });
    final CustomButton blockButton = new CustomButton(ButtonTranslation.INSTANCE.blockPropagationButton(), ButtonTranslation.INSTANCE.blockServicesOnFacility(), SmallIcons.INSTANCE.stopIcon());
    final CustomButton allowButton = new CustomButton(ButtonTranslation.INSTANCE.allowPropagationButton(), ButtonTranslation.INSTANCE.allowServicesOnFacility(), SmallIcons.INSTANCE.acceptIcon());
    final CustomButton deleteButton = new CustomButton(ButtonTranslation.INSTANCE.deleteButton(), ButtonTranslation.INSTANCE.deleteTasks(), SmallIcons.INSTANCE.deleteIcon());
    blockButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> list = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    BlockServiceOnFacility sendRequest = new BlockServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(blockButton));
                    JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(blockButton, JsonCallbackEvents.refreshTableEvents(callback));
                    if (i == list.size() - 1)
                        sendRequest.setEvents(events);
                    if (list.get(i).getTask() != null)
                        sendRequest.blockService(list.get(i).getTask().getService().getId());
                }
            }
        }
    });
    allowButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> list = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    UnblockServiceOnFacility sendRequest = new UnblockServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(allowButton));
                    JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(allowButton, JsonCallbackEvents.refreshTableEvents(callback));
                    if (i == list.size() - 1)
                        sendRequest.setEvents(events);
                    if (list.get(i).getTask() != null)
                        sendRequest.unblockService(list.get(i).getTask().getService().getId());
                }
            }
        }
    });
    TabMenu menu = new TabMenu();
    menu.addWidget(refreshButton);
    menu.addWidget(forceButton);
    menu.addWidget(allowButton);
    menu.addWidget(blockButton);
    if (session.isPerunAdmin()) {
        menu.addWidget(deleteButton);
        deleteButton.setEnabled(false);
        JsonUtils.addTableManagedButton(callback, table, deleteButton);
        deleteButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                final ArrayList<ServiceState> list = callback.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(list)) {
                    UiElements.generateAlert("", "This action will also delete all propagation results. <p>If service is still assigned to any resource, it will be listed in a table.", new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            for (ServiceState ss : list) {
                                DeleteTask deleteTask = new DeleteTask(JsonCallbackEvents.disableButtonEvents(deleteButton));
                                deleteTask.setEvents(JsonCallbackEvents.disableButtonEvents(deleteButton, JsonCallbackEvents.refreshTableEvents(callback)));
                                if (ss.getTask() != null)
                                    deleteTask.deleteTask(ss.getTask().getId());
                            }
                        }
                    });
                }
            }
        });
    }
    forceButton.setEnabled(false);
    allowButton.setEnabled(false);
    blockButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, forceButton);
    JsonUtils.addTableManagedButton(callback, table, allowButton);
    JsonUtils.addTableManagedButton(callback, table, blockButton);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ForceServicePropagation(cz.metacentrum.perun.webgui.json.servicesManager.ForceServicePropagation) GetFacilityServicesState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityServicesState) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) DeleteTask(cz.metacentrum.perun.webgui.json.tasksManager.DeleteTask) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) UnblockServiceOnFacility(cz.metacentrum.perun.webgui.json.servicesManager.UnblockServiceOnFacility) BlockServiceOnFacility(cz.metacentrum.perun.webgui.json.servicesManager.BlockServiceOnFacility)

Aggregations

Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)49 HTML (com.google.gwt.user.client.ui.HTML)26 JSONString (com.google.gwt.json.client.JSONString)19 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)16 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)16 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)15 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)12 Label (com.google.gwt.user.client.ui.Label)8 PerunError (cz.metacentrum.perun.webgui.model.PerunError)8 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)8 Column (com.google.gwt.user.cellview.client.Column)5 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)5 ArrayList (java.util.ArrayList)5 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)4 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)4 FlexTable (com.google.gwt.user.client.ui.FlexTable)3 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)3 RegistrarFormItemGenerator (cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)3 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 Context (com.google.gwt.cell.client.Cell.Context)2