Search in sources :

Example 66 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class AddMemberToResourceTabItem method draw.

@Override
public Widget draw() {
    this.titleWidget.setText("Add member(s) to resource");
    final TabItem tab = this;
    if (state == State.SELECT_MEMBERS) {
        this.contentWidget.clear();
        session.getTabManager().changeStyleOfInnerTab(true);
        // main tab
        FlexTable hp = new FlexTable();
        hp.setSize("100%", "100%");
        hp.setCellPadding(5);
        // members list
        VerticalPanel membersListPanel = new VerticalPanel();
        membersListPanel.setSize("100%", "100%");
        TabMenu membersListMenu = new TabMenu();
        membersListPanel.add(membersListMenu);
        membersListPanel.setCellHeight(membersListMenu, "30px");
        // members list callback
        final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, "", null);
        membersListMenu.addSearchWidget(new PerunSearchEvent() {

            @Override
            public void searchFor(String text) {
                if (UiElements.searchStingCantBeEmpty(text)) {
                    findMembers.searchFor(text);
                }
            }
        }, ButtonTranslation.INSTANCE.searchMemberInVo());
        final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected members to list", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                ArrayList<RichMember> list = findMembers.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(list)) {
                    selectedMembers.addItems(list);
                    findMembers.clearTableSelectedSet();
                }
            }
        });
        membersListMenu.addWidget(addButton);
        membersListMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                session.getTabManager().closeTab(tab);
            }
        }));
        final CustomButton continueButton = TabMenu.getPredefinedButton(ButtonType.CONTINUE, "Continue to resource selection", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // change state
                state = State.SELECT_RESOURCE_OR_FACILITY;
                // redraw the page
                tab.draw();
            }
        });
        membersListMenu.addWidget(continueButton);
        // if no member selected, disable
        if (selectedMembers.getList().size() == 0) {
            continueButton.setEnabled(false);
        }
        // selection of some member will enable continue button
        selectedMembers.setEvents(new AddRemoveItemsTable.HandleItemsAction<RichMember>() {

            @Override
            public void onAdd(RichMember object) {
                continueButton.setEnabled(true);
            }

            @Override
            public void onRemove(RichMember object) {
                if (selectedMembers.getList().size() == 0) {
                    continueButton.setEnabled(false);
                }
            }
        });
        // put table in content
        ScrollPanel tableWrapper = new ScrollPanel();
        tableWrapper.setWidth("100%");
        CellTable<RichMember> table = findMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {

            // when user click on a row -> open new tab
            public void update(int index, RichMember object, RichMember value) {
                session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), 0));
            }
        });
        addButton.setEnabled(false);
        JsonUtils.addTableManagedButton(findMembers, table, addButton);
        table.addStyleName("perun-table");
        table.setWidth("100%");
        tableWrapper.setWidget(table);
        tableWrapper.addStyleName("perun-tableScrollPanel");
        session.getUiElements().resizeSmallTabPanel(tableWrapper, 350, this);
        membersListPanel.add(tableWrapper);
        // selected members
        VerticalPanel selectedMembersPanel = new VerticalPanel();
        selectedMembersPanel.setSize("100%", "100%");
        TabMenu selectedMembersMenu = new TabMenu();
        selectedMembersPanel.add(selectedMembersMenu);
        selectedMembersPanel.setCellHeight(selectedMembersMenu, "30px");
        selectedMembersMenu.addWidget(new HTML("<h3>Selected&nbsp;members:</h3>"));
        selectedMembersPanel.add(selectedMembers);
        hp.setWidget(0, 0, membersListPanel);
        hp.setWidget(0, 1, selectedMembersPanel);
        hp.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
        hp.getFlexCellFormatter().setWidth(0, 0, "80%");
        hp.getFlexCellFormatter().setWidth(0, 1, "20%");
        this.contentWidget.add(hp);
    } else if (state == State.SELECT_RESOURCE_OR_FACILITY) {
        this.contentWidget.clear();
        session.getTabManager().changeStyleOfInnerTab(false);
        FlexTable layout = new FlexTable();
        layout.setSize("100%", "100%");
        TabMenu menu = new TabMenu();
        if (!startedAtTwo) {
            menu.addWidget(TabMenu.getPredefinedButton(ButtonType.BACK, "Back to members selection", new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // get back and reload
                    state = State.SELECT_MEMBERS;
                    tab.draw();
                }
            }));
        } else {
            this.titleWidget.setText("Add member to resource");
        }
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CONTINUE, "", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                state = State.SELECT_GROUP;
                tab.draw();
            }
        }));
        // RESOURCE LAYOUT
        FlexTable resourceLayout = new FlexTable();
        resourceLayout.setStyleName("inputFormFlexTable");
        // by default do not choose facility or service
        facilitiesListbox.addNotSelectedOption();
        servicesListbox.addNotSelectedOption();
        // TODO
        servicesListbox.setEnabled(false);
        // fill services event
        final JsonCallbackEvents fillServEvent = new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                services.setHTML("");
                ArrayList<Service> servList = JsonUtils.jsoAsList(jso);
                servList = new TableSorter<Service>().sortByName(servList);
                for (Service s : servList) {
                    services.setHTML(services.getHTML().concat(s.getName() + "</br>"));
                }
            }

            @Override
            public void onError(PerunError errro) {
                services.setHTML("Error while loading available services.");
            }
        };
        // fill resources event
        final JsonCallbackEvents fillResEvent = new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                // list of VO facilities filled by loaded resources
                ArrayList<Facility> facs = new ArrayList<Facility>();
                ArrayList<RichResource> resList = JsonUtils.jsoAsList(jso);
                resList = new TableSorter<RichResource>().sortByName(resList);
                Set<String> unificator = new HashSet<String>();
                for (RichResource r : resList) {
                    allResources.add(r);
                    resourcesListbox.addItem(r);
                    if (r.getFacility() != null && !unificator.contains(r.getFacility().getName())) {
                        unificator.add(r.getFacility().getName());
                        facs.add(r.getFacility());
                    }
                }
                // sort and fill facilities
                facs = new TableSorter<Facility>().sortByName(facs);
                facilitiesListbox.addAllItems(facs);
                // initial setup
                // refresh rest
                description.setText(resourcesListbox.getSelectedObject().getDescription());
                GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
                servCall.retrieveData();
            }

            @Override
            public void onLoadingStart() {
                resourcesListbox.clear();
            }

            @Override
            public void onError(PerunError error) {
                resourcesListbox.addItem("Error while loading");
            }
        };
        resourcesListbox.addChangeHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent changeEvent) {
                description.setText(resourcesListbox.getSelectedObject().getDescription());
                // fill information about services on resource
                GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
                servCall.retrieveData();
            }
        });
        facilitiesListbox.addChangeHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent changeEvent) {
                if (facilitiesListbox.getSelectedIndex() > 0) {
                    // fill only resources on facility
                    resourcesListbox.clear();
                    for (RichResource r : allResources) {
                        if (r.getFacility().getId() == facilitiesListbox.getSelectedObject().getId()) {
                            resourcesListbox.addItem(r);
                        }
                    }
                } else {
                    // fill all resources
                    resourcesListbox.clear();
                    resourcesListbox.addAllItems(allResources);
                }
                // refresh rest
                description.setText(resourcesListbox.getSelectedObject().getDescription());
                GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
                servCall.retrieveData();
            }
        });
        GetRichResources resCall = new GetRichResources(voId, fillResEvent);
        if (allResources.isEmpty()) {
            resCall.retrieveData();
        }
        resourceLayout.setHTML(0, 0, "Filter by Facility:");
        resourceLayout.setWidget(0, 1, facilitiesListbox);
        //resourceLayout.setHTML(1, 0, "Filter by Service:");
        //resourceLayout.setWidget(1, 1, servicesListbox);
        resourceLayout.setHTML(1, 0, "Selected resource:");
        resourceLayout.setWidget(1, 1, resourcesListbox);
        resourceLayout.setHTML(2, 0, "Description:");
        resourceLayout.setWidget(2, 1, description);
        resourceLayout.setHTML(3, 0, "Services on Resource:");
        resourceLayout.setWidget(3, 1, services);
        for (int i = 0; i < resourceLayout.getRowCount(); i++) {
            resourceLayout.getFlexCellFormatter().addStyleName(i, 0, "itemName");
        }
        // set layout
        layout.setWidget(0, 0, menu);
        layout.setWidget(1, 0, resourceLayout);
        this.contentWidget.add(layout);
    } else if (state == State.SELECT_GROUP) {
        this.contentWidget.clear();
        session.getTabManager().changeStyleOfInnerTab(true);
        final GetAssignedGroups assGroupCall = new GetAssignedGroups(resourcesListbox.getSelectedObject().getId());
        assGroupCall.setSingleSelection(true);
        assGroupCall.setCoreGroupsCheckable(false);
        VerticalPanel vp = new VerticalPanel();
        vp.setSize("100%", "100%");
        TabMenu menu = new TabMenu();
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.BACK, "Back to resource selection", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // get back and reload
                state = State.SELECT_RESOURCE_OR_FACILITY;
                tab.draw();
            }
        }));
        final CustomButton addToGroupButton = new CustomButton("Add to Group", "Add members to selected Group", SmallIcons.INSTANCE.addIcon());
        menu.addWidget(addToGroupButton);
        addToGroupButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                if (UiElements.cantSaveEmptyListDialogBox(assGroupCall.getTableSelectedList())) {
                    final Group grp = assGroupCall.getTableSelectedList().get(0);
                    final FlexTable content = new FlexTable();
                    GetAssignedResources getRes = new GetAssignedResources(grp.getId(), PerunEntity.GROUP, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            ArrayList<Resource> rr = JsonUtils.jsoAsList(jso);
                            String items = new String("<ul>");
                            for (Resource r : rr) {
                                items += "<li>" + r.getName() + "</li>";
                            }
                            items += "</ul>";
                            ScrollPanel sp = new ScrollPanel();
                            sp.add(new HTML(items));
                            sp.setSize("300px", "150px");
                            content.setWidget(1, 0, sp);
                        }

                        public void onError(PerunError error) {
                            content.setWidget(1, 0, new AjaxLoaderImage().loadingError(error));
                        }
                    });
                    getRes.retrieveData();
                    content.setHTML(0, 0, "<p><strong>By adding member into this group, he/she will gain access to following resources:</strong>");
                    content.setWidget(1, 0, new AjaxLoaderImage().loadingStart());
                    Confirm c = new Confirm("Confirm add action", content, new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addToGroupButton));
                            for (RichMember m : selectedMembers.getList()) {
                                request.addMemberToGroup(grp, m);
                            }
                        }
                    }, true);
                    c.setNonScrollable(true);
                    c.show();
                }
            }
        });
        menu.addWidget(new CustomButton("Create group…", "Create new empty group", SmallIcons.INSTANCE.addIcon(), new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // get back and reload
                state = State.CREATE_GROUP;
                tab.draw();
            }
        }));
        CustomButton finish = TabMenu.getPredefinedButton(ButtonType.FINISH, "Close the tab", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                session.getTabManager().closeTab(tab, false);
            }
        });
        finish.setImageAlign(true);
        menu.addWidget(finish);
        menu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
        menu.addWidget(new HTML("<strong>Please select group in which you wish to add members to."));
        CellTable<Group> table = assGroupCall.getTable();
        addToGroupButton.setEnabled(false);
        JsonUtils.addTableManagedButton(assGroupCall, table, addToGroupButton);
        // add a class to the table and wrap it into scroll panel
        table.addStyleName("perun-table");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        session.getUiElements().resizeSmallTabPanel(sp, 350, this);
        vp.add(menu);
        vp.add(sp);
        this.contentWidget.add(vp);
    } else if (state == State.CREATE_GROUP) {
        session.getTabManager().changeStyleOfInnerTab(false);
        VerticalPanel vp = new VerticalPanel();
        // form inputs
        final ExtendedTextBox groupNameTextBox = new ExtendedTextBox();
        final TextBox groupDescriptionTextBox = new TextBox();
        final ListBoxWithObjects<Group> vosGroups = new ListBoxWithObjects<Group>();
        vosGroups.setVisible(false);
        final CheckBox asSubGroup = new CheckBox("", false);
        cz.metacentrum.perun.webgui.widgets.TabMenu menu = new cz.metacentrum.perun.webgui.widgets.TabMenu();
        final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "");
        final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
        final HTML parentGroupText = new HTML("Parent group:");
        parentGroupText.setVisible(false);
        final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

            @Override
            public boolean validateTextBox() {
                if (groupNameTextBox.getTextBox().getText().trim().isEmpty()) {
                    groupNameTextBox.setError("Name can't be empty.");
                } else if (!groupNameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
                    groupNameTextBox.setError("Name can contain only letters, numbers, spaces, dots, '_' and '-'.");
                } else {
                    groupNameTextBox.setOk();
                    return true;
                }
                return false;
            }
        };
        groupNameTextBox.setValidator(validator);
        final GetAllGroups groupsCall = new GetAllGroups(voId, new JsonCallbackEvents() {

            public void onFinished(JavaScriptObject jso) {
                vosGroups.clear();
                ArrayList<Group> retGroups = JsonUtils.jsoAsList(jso);
                retGroups = new TableSorter<Group>().sortByName(retGroups);
                for (Group g : retGroups) {
                    if (g.isCoreGroup()) {
                        // SKIP CORE GROUPS !!
                        continue;
                    }
                    vosGroups.addItem(g);
                }
                createButton.setEnabled(true);
            }

            public void onLoadingStart() {
                vosGroups.clear();
                vosGroups.addItem("Loading...");
                createButton.setEnabled(false);
            }

            public void onError(PerunError error) {
                vosGroups.clear();
                vosGroups.addItem("Error while loading");
                if (asSubGroup.getValue()) {
                    createButton.setEnabled(false);
                } else {
                    createButton.setEnabled(true);
                }
            }
        });
        asSubGroup.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

            @Override
            public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
                if (booleanValueChangeEvent.getValue() == true) {
                    // set title
                    vosGroups.setVisible(true);
                    parentGroupText.setVisible(true);
                    groupsCall.retrieveData();
                    createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
                } else {
                    createButton.setEnabled(true);
                    vosGroups.setVisible(false);
                    parentGroupText.setVisible(false);
                    createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
                }
            }
        });
        // layout
        FlexTable layout = new FlexTable();
        layout.setStyleName("inputFormFlexTable");
        FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
        // send button
        createButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                if (!validator.validateTextBox())
                    return;
                // redirect event
                final JsonCallbackEvents redirectEvent = new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        state = State.SELECT_GROUP;
                        session.getTabManager().changeStyleOfInnerTab(true);
                        tab.draw();
                    }
                };
                // assign group after creation
                final JsonCallbackEvents assignEvent = new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        Group g = jso.cast();
                        if (g != null) {
                            AssignGroupToResources assign = new AssignGroupToResources(JsonCallbackEvents.disableButtonEvents(createButton, redirectEvent));
                            assign.assignGroupToResources(g, JsonUtils.<RichResource>toList(resourcesListbox.getSelectedObject()));
                        }
                    }
                };
                // creates a new request
                CreateGroup cg = new CreateGroup(JsonCallbackEvents.disableButtonEvents(createButton, assignEvent));
                if (asSubGroup.getValue()) {
                    if (vosGroups.getSelectedObject() != null) {
                        cg.createGroupInGroup(vosGroups.getSelectedObject().getId(), groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText());
                    } else {
                        UiElements.generateInfo("No parent group selected", "You checked create this group as sub-group, but no parent group is selected. Please select parent group.");
                    }
                } else {
                    cg.createGroupInVo(voId, groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText());
                }
            }
        });
        // cancel button
        cancelButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // redirect back to select group
                state = State.SELECT_GROUP;
                session.getTabManager().changeStyleOfInnerTab(true);
                tab.draw();
            }
        });
        // Add some standard form options
        layout.setHTML(0, 0, "Name:");
        layout.setWidget(0, 1, groupNameTextBox);
        layout.setHTML(1, 0, "Description:");
        layout.setWidget(1, 1, groupDescriptionTextBox);
        layout.setHTML(2, 0, "As sub-group:");
        layout.setWidget(2, 1, asSubGroup);
        layout.setWidget(3, 0, parentGroupText);
        layout.setWidget(3, 1, vosGroups);
        for (int i = 0; i < layout.getRowCount(); i++) {
            cellFormatter.addStyleName(i, 0, "itemName");
        }
        // button align
        menu.addWidget(createButton);
        menu.addWidget(cancelButton);
        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) ArrayList(java.util.ArrayList) AddMember(cz.metacentrum.perun.webgui.json.groupsManager.AddMember) ImageResource(com.google.gwt.resources.client.ImageResource) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) CreateGroup(cz.metacentrum.perun.webgui.json.groupsManager.CreateGroup) HashSet(java.util.HashSet) Set(java.util.Set) cz.metacentrum.perun.webgui.widgets(cz.metacentrum.perun.webgui.widgets) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) CreateGroup(cz.metacentrum.perun.webgui.json.groupsManager.CreateGroup) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Example 67 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class AddMemberToVoTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add member(s)");
    // draw the main tab
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    final TabMenu tabMenu = new TabMenu();
    mainTab.add(tabMenu);
    mainTab.setCellHeight(tabMenu, "30px");
    addCandidatesButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedCandidateToVo());
    inviteCandidatesButton = new CustomButton("Invite selected", SmallIcons.INSTANCE.emailIcon());
    final FindCandidatesOrUsersToAddToVo findAll = new FindCandidatesOrUsersToAddToVo(voId, 0, "");
    final CustomButton searchButton = new CustomButton("Search", SmallIcons.INSTANCE.findIcon());
    final CellTable<Candidate> candidatesTable = findAll.getEmptyTable();
    final ScrollPanel scrollPanel = new ScrollPanel();
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            findAll.searchFor(text);
        }
    }, searchButton);
    searchBox.getTextBox().setText(searchString);
    // search candidate - select if found one
    JsonCallbackEvents selectOneEvent = JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(searchButton), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            searchBox.getTextBox().setEnabled(true);
            // check in candidates table
            if (findAll.getList().size() == 1) {
                findAll.setSelected(findAll.getList().get(0));
            }
            tabMenu.addWidget(2, addCandidatesButton);
        }

        @Override
        public void onLoadingStart() {
            searchBox.getTextBox().setEnabled(false);
        }

        @Override
        public void onError(PerunError error) {
            searchBox.getTextBox().setEnabled(true);
        }
    });
    // set event for search
    findAll.setEvents(selectOneEvent);
    tabMenu.addWidget(2, addCandidatesButton);
    tabMenu.addWidget(3, inviteCandidatesButton);
    inviteCandidatesButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // we expect, that candidate is always single
            Candidate candid = findAll.getSelected();
            if (candid != null) {
                if (candid.getObjectType().equalsIgnoreCase("Candidate")) {
                    SendInvitation invite = new SendInvitation(voId, 0);
                    invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteCandidatesButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            findAll.clearTableSelectedSet();
                        }
                    }));
                    invite.inviteUser(candid);
                } else {
                    SendInvitation invite = new SendInvitation(voId, 0);
                    invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteCandidatesButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            findAll.clearTableSelectedSet();
                        }
                    }));
                    User user = candid.cast();
                    invite.inviteUser(user);
                }
            }
        }
    });
    final TabItem tab = this;
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
        }
    }));
    // add candidate button
    addCandidatesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Candidate candidateToBeAdded = findAll.getSelected();
            if (candidateToBeAdded == null) {
                UiElements.cantSaveEmptyListDialogBox(null);
            } else {
                if (candidateToBeAdded.getObjectType().equalsIgnoreCase("Candidate")) {
                    CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addCandidatesButton, new JsonCallbackEvents() {

                        private Candidate saveSelected;

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // put names to already added
                            if (saveSelected != null) {
                                GeneralObject go = saveSelected.cast();
                                alreadyAddedList.add(go);
                            }
                            findAll.clearTableSelectedSet();
                            rebuildAlreadyAddedWidget();
                            // clear search
                            searchBox.getTextBox().setText("");
                        }

                        @Override
                        public void onLoadingStart() {
                            saveSelected = findAll.getSelected();
                        }
                    }));
                    request.createMember(voId, candidateToBeAdded);
                } else {
                    CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addCandidatesButton, new JsonCallbackEvents() {

                        private User saveSelected;

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // put names to already added
                            if (saveSelected != null) {
                                GeneralObject go = saveSelected.cast();
                                alreadyAddedList.add(go);
                                findAll.clearTableSelectedSet();
                                rebuildAlreadyAddedWidget();
                                // clear search
                                searchBox.getTextBox().setText("");
                            }
                        }

                        @Override
                        public void onLoadingStart() {
                            Candidate cand = findAll.getSelected();
                            saveSelected = cand.cast();
                        }
                    }));
                    User user = candidateToBeAdded.cast();
                    request.createMember(voId, user);
                }
            }
        }
    });
    addCandidatesButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findAll, candidatesTable, addCandidatesButton);
    inviteCandidatesButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findAll, candidatesTable, inviteCandidatesButton);
    // tables
    candidatesTable.addStyleName("perun-table");
    scrollPanel.add(candidatesTable);
    scrollPanel.addStyleName("perun-tableScrollPanel");
    // load if stored search string is not empty
    findAll.searchFor(searchString);
    rebuildAlreadyAddedWidget();
    mainTab.add(alreadyAdded);
    // style
    // do not use resizePerunTable() when tab is in overlay - wrong width is calculated
    session.getUiElements().resizeSmallTabPanel(scrollPanel, 350, this);
    // add table to page
    mainTab.add(scrollPanel);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CreateMember(cz.metacentrum.perun.webgui.json.membersManager.CreateMember) FindCandidatesOrUsersToAddToVo(cz.metacentrum.perun.webgui.json.vosManager.FindCandidatesOrUsersToAddToVo) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SendInvitation(cz.metacentrum.perun.webgui.json.registrarManager.SendInvitation)

Example 68 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class CreateServiceMemberInVoTabItem method draw.

public Widget draw() {
    titleWidget.setText("Create service member");
    final TabItem tab = this;
    // draw the main tab
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    final ExtendedTextBox serviceUserName = new ExtendedTextBox();
    final ExtendedTextBox serviceUserEmail = new ExtendedTextBox();
    final ExtendedTextBox serviceUserLogin = new ExtendedTextBox();
    final ExtendedPasswordBox serviceUserPassword = new ExtendedPasswordBox();
    final ExtendedPasswordBox serviceUserPassword2 = new ExtendedPasswordBox();
    final ListBox namespace = new ListBox();
    final ExtendedTextBox certDN = new ExtendedTextBox();
    final ExtendedTextBox cacertDN = new ExtendedTextBox();
    final ListBox userType = new ListBox();
    userType.addItem("Service", "SERVICE");
    userType.addItem("Sponsored", "SPONSORED");
    serviceUserPassword.getTextBox().setWidth("200px");
    serviceUserPassword2.getTextBox().setWidth("200px");
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (serviceUserName.getTextBox().getValue().trim().isEmpty()) {
                serviceUserName.setError("Name can't be empty!");
                return false;
            }
            serviceUserName.setOk();
            return true;
        }
    };
    serviceUserName.setValidator(nameValidator);
    final ExtendedTextBox.TextBoxValidator loginValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (namespace.getSelectedIndex() == 0) {
                // do not validate if namespace is not selected
                serviceUserLogin.getTextBox().setValue(null);
                serviceUserLogin.setOk();
                return true;
            }
            if (serviceUserLogin.getTextBox().getValue().trim().isEmpty()) {
                serviceUserLogin.setError("Login can't be empty!");
                return false;
            }
            RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
            boolean match = regExp.test(serviceUserLogin.getTextBox().getValue().trim());
            if (!match) {
                serviceUserLogin.setError("Invalid format!");
                return false;
            }
            if (serviceUserLogin.isProcessing() || serviceUserLogin.isHardError()) {
                // keep original message
                return false;
            }
            serviceUserLogin.setOk();
            return true;
        }
    };
    serviceUserLogin.setValidator(loginValidator);
    final ExtendedTextBox.TextBoxValidator emailValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!JsonUtils.isValidEmail(serviceUserEmail.getTextBox().getValue().trim())) {
                serviceUserEmail.setError("Wrong email format!");
                return false;
            }
            serviceUserEmail.setOk();
            return true;
        }
    };
    serviceUserEmail.setValidator(emailValidator);
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (serviceUserPassword.getTextBox().getValue().trim().isEmpty()) {
                serviceUserPassword.setError("Password can't be empty !");
                return false;
            } else if (!serviceUserPassword.getTextBox().getValue().trim().equals(serviceUserPassword2.getTextBox().getValue().trim())) {
                serviceUserPassword.setError("Password in both textboxes must be the same !");
                return false;
            } else {
                serviceUserPassword.setOk();
                serviceUserPassword2.setOk();
                return true;
            }
        }
    };
    serviceUserPassword.setValidator(validator);
    final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (serviceUserPassword2.getTextBox().getValue().trim().isEmpty()) {
                serviceUserPassword2.setError("Password can't be empty !");
                return false;
            } else if (!serviceUserPassword2.getTextBox().getValue().trim().equals(serviceUserPassword.getTextBox().getValue().trim())) {
                serviceUserPassword2.setError("Password in both textboxes must be the same !");
                return false;
            } else {
                serviceUserPassword2.setOk();
                serviceUserPassword.setOk();
                return true;
            }
        }
    };
    serviceUserPassword2.setValidator(validator2);
    final ExtendedTextBox.TextBoxValidator certDNValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if ((certDN.getTextBox().getValue().trim().isEmpty() && cacertDN.getTextBox().getValue().trim().isEmpty()) || (!certDN.getTextBox().getValue().trim().isEmpty() && !cacertDN.getTextBox().getValue().trim().isEmpty())) {
                certDN.setOk();
                cacertDN.setOk();
                return true;
            } else {
                if (certDN.getTextBox().getValue().trim().isEmpty()) {
                    certDN.setError("Value can't be empty!");
                }
                if (cacertDN.getTextBox().getValue().trim().isEmpty()) {
                    cacertDN.setError("Value can't be empty!");
                }
            }
            return false;
        }
    };
    certDN.setValidator(certDNValidator);
    cacertDN.setValidator(certDNValidator);
    // make value empty
    namespace.addItem("Not selected", "");
    for (String name : Utils.getSupportedPasswordNamespaces()) {
        namespace.addItem(name.toUpperCase(), name);
    }
    final FlexTable layout = new FlexTable();
    layout.setCellPadding(5);
    layout.setHTML(0, 0, "<h3>1. Create service identity</h3>");
    layout.getFlexCellFormatter().setColSpan(0, 0, 3);
    layout.setHTML(1, 0, "<strong>Member's name: </strong>");
    layout.setWidget(1, 1, serviceUserName);
    layout.setHTML(2, 0, "<strong>Member's email: </strong>");
    layout.setWidget(2, 1, serviceUserEmail);
    layout.setHTML(3, 0, "<strong>Namespace: </strong>");
    layout.setWidget(3, 1, namespace);
    layout.setHTML(4, 0, "<strong>Login: </strong>");
    layout.setWidget(4, 1, serviceUserLogin);
    final Label label = new Label("You will be assigned with available login");
    label.setVisible(false);
    layout.setWidget(5, 0, label);
    layout.getFlexCellFormatter().setStyleName(5, 0, "inputFormInlineComment");
    layout.getFlexCellFormatter().setColSpan(5, 0, 2);
    layout.setHTML(6, 0, "<strong>Subject DN: </strong>");
    layout.setWidget(6, 1, certDN);
    layout.setHTML(7, 0, "<strong>Issuer DN: </strong>");
    layout.setWidget(7, 1, cacertDN);
    if (session.isPerunAdmin()) {
        layout.setHTML(8, 0, "<strong>User type: </strong>");
        layout.setWidget(8, 1, userType);
    }
    final FlexTable firstTabLayout = new FlexTable();
    firstTabLayout.setSize("100%", "100%");
    firstTabLayout.setVisible(false);
    final AddRemoveItemsTable<User> itemsTable = new AddRemoveItemsTable<User>(true);
    itemsTable.addItem(session.getUser());
    final VerticalPanel secondTabPanel = new VerticalPanel();
    secondTabPanel.setSize("100%", "100%");
    secondTabPanel.setVisible(false);
    mainTab.add(layout);
    mainTab.add(firstTabLayout);
    mainTab.add(secondTabPanel);
    // disable login by default (first option)
    serviceUserLogin.getTextBox().setEnabled(false);
    final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.addIcon(), new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            // check
            if (!namespace.getSelectedValue().equals("mu") && namespace.getSelectedIndex() != 0 && !loginValidator.validateTextBox())
                return;
            if (!nameValidator.validateTextBox())
                return;
            if (!emailValidator.validateTextBox())
                return;
            if (!certDNValidator.validateTextBox())
                return;
            // change to lager tab
            session.getTabManager().changeStyleOfInnerTab(true);
            // first tab panel
            firstTabLayout.setHTML(0, 0, "<h3>2. Associate real users</h3>");
            firstTabLayout.getFlexCellFormatter().setColSpan(0, 0, 2);
            layout.setVisible(false);
            firstTabLayout.setVisible(true);
            final FindUsersInVo callback = new FindUsersInVo();
            // Service users can't own another Service or Guest (Sponsored) account.
            callback.hideService(true);
            if (userType.getSelectedValue().equals("SPONSORED")) {
                // Sponsored account can't sponsor another !
                callback.setHideSponsored(true);
            }
            // HORIZONTAL MENU
            TabMenu tabMenu = new TabMenu();
            // get the table
            final CellTable<User> table = callback.getTable();
            // search textbox
            ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

                @Override
                public void searchFor(String text) {
                    callback.searchFor(text, voId);
                    searchString = text;
                }
            }, ButtonTranslation.INSTANCE.searchUsers());
            final CustomButton cb = new CustomButton("Continue", SmallIcons.INSTANCE.arrowRightIcon());
            cb.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent clickEvent) {
                    // check
                    if (itemsTable.getList().isEmpty()) {
                        new Confirm("No user associated", new HTML("You must associate at least one real user to service member."), true).show();
                        return;
                    }
                    // create member + user
                    CreateSpecificMember request = new CreateSpecificMember(JsonCallbackEvents.disableButtonEvents(cb, new JsonCallbackEvents() {

                        public void onFinished(JavaScriptObject jso) {
                            final Member member = jso.cast();
                            for (User u : itemsTable.getList()) {
                                if (u.getId() == session.getUser().getId()) {
                                    // set local authz if one of associated users is us
                                    session.addEditableUser(member.getUserId());
                                }
                            }
                            if (namespace.getSelectedIndex() == 0) {
                                // we didn't set login, hence skip password setting
                                session.getTabManager().closeTab(tab, true);
                                return;
                            }
                            // change to small tab
                            session.getTabManager().changeStyleOfInnerTab(false);
                            secondTabPanel.add(new HTML("<h3>3.Set password for: " + serviceUserLogin.getTextBox().getValue().trim() + "</h3>"));
                            final CustomButton button = new CustomButton("Set password", SmallIcons.INSTANCE.keyIcon());
                            button.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent clickEvent) {
                                    if (!validator.validateTextBox() && !validator2.validateTextBox()) {
                                        return;
                                    }
                                    final String namespaceValue = namespace.getSelectedValue();
                                    if ("mu".equals(namespaceValue)) {
                                        final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                BasicOverlayType basic = jso.cast();
                                                final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                                                SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                    @Override
                                                    public void onFinished(JavaScriptObject jso) {
                                                        // VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
                                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                            @Override
                                                            public void onFinished(JavaScriptObject jso) {
                                                                // validate member when all kerberos logins are set
                                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
                                                                req2.validateMemberAsync(member);
                                                            }
                                                        }));
                                                        // validate login returned from account generation
                                                        req.validateAndSetUserExtSources(member.getUserId(), login, namespaceValue);
                                                        // show assigned login
                                                        UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                                    }

                                                    @Override
                                                    public void onError(PerunError error) {
                                                        UiElements.generateError(error, "Saving login failed", "You were assigned with login <b>" + login + "</b> in namespace MU but saving it to user failed. <b>Please copy your login and contact support at <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">" + Utils.perunReportEmailAddress() + "</a>.</b>");
                                                        // validate member when all logins are set
                                                        ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
                                                        req2.validateMemberAsync(member);
                                                    }
                                                }));
                                                setLogin.setLogin(member.getUserId(), "mu", login);
                                            }
                                        }));
                                        final Map<String, String> params = new HashMap<String, String>();
                                        GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                RichMember rm = jso.cast();
                                                params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
                                                params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
                                                params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
                                                req.generateAccount(namespaceValue, serviceUserPassword.getTextBox().getValue().trim(), params);
                                            }
                                        }));
                                        get.retrieveData();
                                    } else {
                                        // create password which sets also user ext sources
                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                // validate member when all kerberos logins are set
                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
                                                req2.validateMemberAsync(member);
                                            }
                                        }));
                                        req.createPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue, serviceUserPassword.getTextBox().getValue().trim());
                                    }
                                }
                            });
                            final CustomButton skipButton = new CustomButton("Skip", SmallIcons.INSTANCE.arrowRightIcon());
                            skipButton.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent clickEvent) {
                                    final String namespaceValue = namespace.getSelectedValue();
                                    if ("mu".equals(namespaceValue)) {
                                        final GenerateAccount req = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                BasicOverlayType basic = jso.cast();
                                                final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
                                                SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                    @Override
                                                    public void onFinished(JavaScriptObject jso) {
                                                        // VALIDATE PASSWORD - SET EXT SOURCES AND VALIDATE MEMBER
                                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                                            @Override
                                                            public void onFinished(JavaScriptObject jso) {
                                                                // validate member when all kerberos logins are set
                                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
                                                                req2.validateMemberAsync(member);
                                                            }
                                                        }));
                                                        // validate login returned from account generation
                                                        req.validateAndSetUserExtSources(member.getUserId(), login, namespaceValue);
                                                        // show assigned login
                                                        UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
                                                    }

                                                    @Override
                                                    public void onError(PerunError error) {
                                                        // validate member when all logins are set
                                                        ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(button, tab));
                                                        req2.validateMemberAsync(member);
                                                    }
                                                }));
                                                setLogin.setLogin(member.getUserId(), "mu", login);
                                            }
                                        }));
                                        final Map<String, String> params = new HashMap<String, String>();
                                        GetEntityById get = new GetEntityById(PerunEntity.RICH_MEMBER, member.getId(), JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                RichMember rm = jso.cast();
                                                params.put("urn:perun:user:attribute-def:core:firstName", rm.getUser().getFirstName());
                                                params.put("urn:perun:user:attribute-def:core:lastName", rm.getUser().getLastName());
                                                params.put("urn:perun:member:attribute-def:def:mail", serviceUserEmail.getTextBox().getValue().trim());
                                                req.generateAccount(namespaceValue, null, params);
                                            }
                                        }));
                                        get.retrieveData();
                                    } else {
                                        CreatePassword req = new CreatePassword(JsonCallbackEvents.disableButtonEvents(skipButton, new JsonCallbackEvents() {

                                            public void onFinished(JavaScriptObject jso) {
                                                // validate member when all kerberos logins are set
                                                ValidateMemberAsync req2 = new ValidateMemberAsync(JsonCallbackEvents.closeTabDisableButtonEvents(skipButton, tab));
                                                req2.validateMemberAsync(member);
                                            }
                                        }));
                                        // set empty password for service member if "skipped"
                                        req.createRandomPassword(member.getUserId(), serviceUserLogin.getTextBox().getValue().trim(), namespaceValue);
                                    }
                                }
                            });
                            FlexTable ft = new FlexTable();
                            ft.setStyleName("inputFormFlexTable");
                            ft.setWidth("400px");
                            ft.setHTML(0, 0, "Password:");
                            ft.setWidget(0, 1, serviceUserPassword);
                            ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
                            ft.setHTML(1, 0, "Re-type password:");
                            ft.setWidget(1, 1, serviceUserPassword2);
                            ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
                            ft.setWidget(2, 1, skipButton);
                            ft.getFlexCellFormatter().setHorizontalAlignment(2, 1, HasHorizontalAlignment.ALIGN_RIGHT);
                            ft.setWidget(3, 1, button);
                            ft.getFlexCellFormatter().setHorizontalAlignment(3, 1, HasHorizontalAlignment.ALIGN_RIGHT);
                            secondTabPanel.add(ft);
                            // hide 2nd panel
                            firstTabLayout.setVisible(false);
                            // show 3rd panel
                            secondTabPanel.setVisible(true);
                        }

                        ;
                    }));
                    request.createMember(voId, serviceUserName.getTextBox().getValue().trim(), serviceUserEmail.getTextBox().getValue().trim(), itemsTable.getList(), namespace.getValue(namespace.getSelectedIndex()), serviceUserLogin.getTextBox().getValue().trim(), certDN.getTextBox().getValue().trim(), cacertDN.getTextBox().getValue().trim(), userType.getSelectedValue());
                }
            });
            // we have ourselves already assigned
            //cb.setEnabled(false);
            CustomButton button = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected users to service member");
            button.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent clickEvent) {
                    ArrayList<User> list = callback.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        // skip self
                        ArrayList<User> list2 = new ArrayList<User>();
                        for (User user : list) {
                            if (user != null && user.getId() != session.getUser().getId()) {
                                list2.add(user);
                            }
                        }
                        itemsTable.addItems(list2);
                        cb.setEnabled(true);
                        callback.clearTableSelectedSet();
                    }
                }
            });
            button.setEnabled(false);
            tabMenu.addWidget(button);
            JsonUtils.addTableManagedButton(callback, table, button);
            // add finish button to menu
            tabMenu.addWidget(cb);
            // if some text has been searched before
            if (!searchString.equals("")) {
                searchBox.getTextBox().setText(searchString);
                callback.searchFor(searchString, voId);
            }
            final ScrollPanel sp = new ScrollPanel(table);
            table.addStyleName("perun-table");
            sp.addStyleName("perun-tableScrollPanel");
            session.getUiElements().resizeSmallTabPanel(sp, 350, tab);
            firstTabLayout.setWidget(1, 0, tabMenu);
            firstTabLayout.setWidget(2, 0, sp);
            firstTabLayout.setHTML(1, 1, "<h3>To be associated:</h3>");
            firstTabLayout.setWidget(2, 1, itemsTable);
            firstTabLayout.getFlexCellFormatter().setWidth(2, 0, "75%");
            firstTabLayout.getFlexCellFormatter().setWidth(2, 1, "25%");
            firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 1, HasVerticalAlignment.ALIGN_TOP);
            firstTabLayout.getFlexCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_TOP);
            // actions when added items or removed items
            itemsTable.setEvents(new AddRemoveItemsTable.HandleItemsAction<User>() {

                @Override
                public void onAdd(User object) {
                    cb.setEnabled(true);
                }

                @Override
                public void onRemove(User object) {
                    if (object.equals(session.getUser())) {
                        itemsTable.addItem(object);
                        UiElements.generateInfo("Can't remove yourself", "<p>You can't remove yourself yet. You wouldn't be able to finish service member configuration. Please remove yourself afterwards.");
                    }
                    if (itemsTable.getList().isEmpty()) {
                        cb.setEnabled(false);
                    }
                }
            });
        }
    });
    // check login availability
    serviceUserLogin.getTextBox().addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent keyUpEvent) {
            if (keyUpEvent.isDownArrow() || keyUpEvent.isUpArrow() || keyUpEvent.isLeftArrow() || keyUpEvent.isRightArrow()) {
                // do not trigger when no text input
                return;
            }
            final String login = serviceUserLogin.getTextBox().getValue().trim();
            final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
            // trigger new validation on checked input or if previously was hard error
            if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
                new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            BasicOverlayType bo = jso.cast();
                            serviceUserLogin.setProcessing(false);
                            if (!bo.getBoolean()) {
                                serviceUserLogin.setHardError("Login is already in use!");
                            } else {
                                serviceUserLogin.removeHardError();
                                loginValidator.validateTextBox();
                            }
                        }
                    }

                    @Override
                    public void onLoadingStart() {
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            serviceUserLogin.removeHardError();
                            serviceUserLogin.setProcessing(true);
                        }
                    }

                    @Override
                    public void onError(PerunError error) {
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            serviceUserLogin.setProcessing(false);
                            serviceUserLogin.setHardError("Unable to check if login is available!");
                        }
                    }
                }).retrieveData();
            }
        }
    });
    namespace.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (namespace.getSelectedIndex() == 0) {
                // do not set login
                serviceUserLogin.getTextBox().setEnabled(false);
                serviceUserLogin.getTextBox().setValue(null);
                label.setVisible(false);
            } else if (namespace.getSelectedValue().equals("mu")) {
                serviceUserLogin.getTextBox().setEnabled(false);
                label.setVisible(true);
            } else {
                serviceUserLogin.getTextBox().setEnabled(true);
                label.setVisible(false);
            }
            final String login = serviceUserLogin.getTextBox().getValue().trim();
            final String loginNamespace = namespace.getValue(namespace.getSelectedIndex());
            if ((!login.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(login)) || serviceUserLogin.isHardError()) {
                new IsLoginAvailable(loginNamespace, login, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // UPDATE RESULT ONLY IF CONTENT OF LOGIN BOX IS SAME AS ON CALLBACK START
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            serviceUserLogin.setProcessing(false);
                            BasicOverlayType bo = jso.cast();
                            if (!bo.getBoolean()) {
                                serviceUserLogin.setHardError("Login is already in use!");
                            } else {
                                serviceUserLogin.removeHardError();
                                loginValidator.validateTextBox();
                            }
                        }
                    }

                    @Override
                    public void onLoadingStart() {
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            serviceUserLogin.removeHardError();
                            serviceUserLogin.setProcessing(true);
                            loginValidator.validateTextBox();
                        }
                    }

                    @Override
                    public void onError(PerunError error) {
                        if (serviceUserLogin.getTextBox().getValue().trim().equals(login)) {
                            serviceUserLogin.setProcessing(false);
                            serviceUserLogin.setHardError("Unable to check if login is available!");
                        }
                    }
                }).retrieveData();
            }
        }
    });
    if (session.isPerunAdmin()) {
        layout.setWidget(9, 0, cb);
        layout.getFlexCellFormatter().setHorizontalAlignment(9, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        layout.getFlexCellFormatter().setColSpan(9, 0, 2);
    } else {
        layout.setWidget(8, 0, cb);
        layout.getFlexCellFormatter().setHorizontalAlignment(8, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        layout.getFlexCellFormatter().setColSpan(8, 0, 2);
    }
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) IsLoginAvailable(cz.metacentrum.perun.webgui.json.usersManager.IsLoginAvailable) CellTable(com.google.gwt.user.cellview.client.CellTable) GenerateAccount(cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FindUsersInVo(cz.metacentrum.perun.webgui.json.membersManager.FindUsersInVo) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) CreatePassword(cz.metacentrum.perun.webgui.json.usersManager.CreatePassword) ValidateMemberAsync(cz.metacentrum.perun.webgui.json.membersManager.ValidateMemberAsync) CreateSpecificMember(cz.metacentrum.perun.webgui.json.membersManager.CreateSpecificMember) RegExp(com.google.gwt.regexp.shared.RegExp) CreateSpecificMember(cz.metacentrum.perun.webgui.json.membersManager.CreateSpecificMember) SetLogin(cz.metacentrum.perun.webgui.json.usersManager.SetLogin) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 69 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class MemberAddToGroupTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Add to group(s)");
    // main widget panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    final GetAllGroups groups = new GetAllGroups(member.getVoId());
    menu.addFilterWidget(new ExtendedSuggestBox(groups.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            groups.filterTable(text);
            if (groups.getList().size() == 1) {
                // select if filtered result is single group
                groups.getSelectionModel().setSelected(groups.getList().get(0), true);
            }
        }
    }, "Filter groups by name");
    final TabItem tab = this;
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add member to selected group(s)");
    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            ArrayList<Group> list = groups.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // TODO - should have only one callback to core
                for (int i = 0; i < list.size(); i++) {
                    final Group g = list.get(i);
                    AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            groups.getSelectionModel().setSelected(g, false);
                            alreadyAddedList.add(g);
                            rebuildAlreadyAddedWidget();
                        }
                    }));
                    request.addMemberToGroup(g, member);
                }
            }
        }
    });
    menu.addWidget(addButton);
    addButton.setEnabled(false);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    CellTable<Group> table = groups.getTable();
    JsonUtils.addTableManagedButton(groups, table, addButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    rebuildAlreadyAddedWidget();
    vp.add(alreadyAdded);
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AddMember(cz.metacentrum.perun.webgui.json.groupsManager.AddMember)

Example 70 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class EditFormItemTabItem method basicInformationTab.

/**
	 * Returns flex table with basic information and textboxes
	 *
	 * @return
	 */
private Widget basicInformationTab() {
    // item application types
    ArrayList<String> itemApplicationTypes = JsonUtils.listFromJsArrayString(item.getApplicationTypes());
    // federation attributes to select from
    federationAttributes.addItem("No item selected (empty value)", "");
    federationAttributes.addItem("Display name", "displayName");
    federationAttributes.addItem("Common name", "cn");
    federationAttributes.addItem("Mail", "mail");
    federationAttributes.addItem("Organization", "o");
    federationAttributes.addItem("Level of Assurance (LoA)", "loa");
    federationAttributes.addItem("First name", "givenName");
    federationAttributes.addItem("Sure name", "sn");
    federationAttributes.addItem("EPPN", "eppn");
    federationAttributes.addItem("IdP Category", "md_entityCategory");
    federationAttributes.addItem("IdP Affiliation", "affiliation");
    federationAttributes.addItem("EduPersonScopedAffiliation", "eduPersonScopedAffiliation");
    federationAttributes.addItem("schacHomeOrganization", "schacHomeOrganization");
    // application types
    GetAttributesDefinition attrDef = new GetAttributesDefinition(new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            perunDestinationAttributeListBox.clear();
            perunDestinationAttributeListBox.addItem("No item selected (empty value)", "");
            if (item.getPerunDestinationAttribute() != null && !item.getPerunDestinationAttribute().isEmpty()) {
                // add and select returned perun dest attr
                perunDestinationAttributeListBox.addItem(item.getPerunDestinationAttribute(), item.getPerunDestinationAttribute());
                perunDestinationAttributeListBox.setSelectedIndex(1);
            }
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            // clear
            perunDestinationAttributeListBox.clear();
            // set empty possibility
            perunDestinationAttributeListBox.addItem("No item selected (empty value)", "");
            ArrayList<AttributeDefinition> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                // sort
                list = new TableSorter<AttributeDefinition>().sortByFriendlyName(list);
                for (AttributeDefinition def : list) {
                    // add only member and user attributes
                    if (def.getEntity().equalsIgnoreCase("user") || def.getEntity().equalsIgnoreCase("member")) {
                        perunDestinationAttributeListBox.addItem(def.getFriendlyName() + " (" + def.getEntity() + " / " + def.getDefinition() + ")", def.getName());
                    }
                }
            } else {
                // no attr def loaded, keep as it is set
                if (item.getPerunDestinationAttribute() != null && !item.getPerunDestinationAttribute().isEmpty()) {
                    perunDestinationAttributeListBox.addItem(item.getPerunDestinationAttribute(), item.getPerunDestinationAttribute());
                }
            }
            // set selected
            for (int i = 0; i < perunDestinationAttributeListBox.getItemCount(); i++) {
                // set proper value as "selected"
                if (perunDestinationAttributeListBox.getValue(i).equalsIgnoreCase(item.getPerunDestinationAttribute())) {
                    perunDestinationAttributeListBox.setSelectedIndex(i);
                    break;
                }
            }
        }

        @Override
        public void onLoadingStart() {
            perunDestinationAttributeListBox.addItem("Loading...");
        }
    });
    // layout
    FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    FlexCellFormatter ftf = ft.getFlexCellFormatter();
    // fill values
    shortNameTextBox.setText(item.getShortname());
    for (int i = 0; i < federationAttributes.getItemCount(); i++) {
        if (federationAttributes.getValue(i).equals(item.getFederationAttribute())) {
            federationAttributes.setSelectedIndex(i);
            break;
        }
    }
    requiredCheckBox.setValue(item.isRequired());
    regexTextBox.setText(item.getRegex());
    for (Application.ApplicationType type : Application.ApplicationType.values()) {
        CheckBox cb = new CheckBox();
        boolean checked = itemApplicationTypes.contains(type.toString());
        cb.setValue(checked);
        applicationTypesCheckBoxes.add(cb);
    }
    // sizes
    shortNameTextBox.setWidth("200px");
    federationAttributes.setWidth("200px");
    perunDestinationAttributeListBox.setWidth("300px");
    regexTextBox.setWidth("200px");
    // basic info
    int row = 0;
    Label shortNameLabel = new Label("Short name:");
    ft.setWidget(row, 0, shortNameLabel);
    ft.setWidget(row, 1, shortNameTextBox);
    row++;
    ft.setHTML(row, 1, "Internal item identification (used as fallback when you forgot to set \"Label\" for some language).");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    row++;
    Label inputLabel = new Label("Input widget:");
    ft.setWidget(row, 0, inputLabel);
    ft.setHTML(row, 1, CreateFormItemTabItem.inputTypes.get(item.getType()));
    row++;
    ft.setHTML(row, 1, "Specify what input widget is used for this item.");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    // set colspan for tops
    for (int i = 0; i < ft.getRowCount(); i++) {
        ftf.setColSpan(i, 1, 2);
    }
    row++;
    Label l = new Label("Display on application:");
    l.setTitle("");
    ft.setWidget(row, 0, l);
    ftf.setWidth(row, 0, "160px");
    Application.ApplicationType.values();
    int i = 0;
    for (Application.ApplicationType type : Application.ApplicationType.values()) {
        CheckBox cb = applicationTypesCheckBoxes.get(i);
        cb.setText(Application.getTranslatedType(type.toString()));
        if (type.equals(Application.ApplicationType.INITIAL)) {
            cb.setTitle("If checked, display form item on INITIAL application");
        } else {
            cb.setTitle("If checked, display form item on EXTENSION application");
        }
        ft.setWidget(row, i + 1, cb);
        i++;
    }
    row++;
    ft.setHTML(row, 1, "Define on which application types is this item displayed.");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    ftf.setColSpan(row, 1, 2);
    row++;
    // IF BUTTON OR COMMENT, don't show these
    if (!item.getType().equals("SUBMIT_BUTTON") && !item.getType().equals("AUTO_SUBMIT_BUTTON") && !item.getType().equals("HTML_COMMENT") && !item.getType().equals("HEADING")) {
        // load attr defs only when showed
        attrDef.retrieveData();
        Label requiredLabel = new Label("Required:");
        ft.setWidget(row, 0, requiredLabel);
        ft.setWidget(row, 1, requiredCheckBox);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "If checked, user can`t submit empty value (doesn't apply to non-editable fields).");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        row++;
        Label destAttrLabel = new Label("Destination attribute:");
        ft.setWidget(row, 0, destAttrLabel);
        ft.setWidget(row, 1, perunDestinationAttributeListBox);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "Select attribute, where will be submitted value stored after accepting user`s application and where is taken to pre-fill the form.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        row++;
        Label fedAttrLabel = new Label("Federation attribute:");
        ft.setWidget(row, 0, fedAttrLabel);
        ft.setWidget(row, 1, federationAttributes);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "Select federation attribute to get pre-filed value from.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        if (!item.getType().equals("VALIDATED_EMAIL") && !item.getType().equals("TIMEZONE")) {
            row++;
            Label regexLabel = new Label("Regular expression:");
            ft.setWidget(row, 0, regexLabel);
            ft.setWidget(row, 1, regexTextBox);
            ftf.setColSpan(row, 1, 2);
            row++;
            ft.setHTML(row, 1, "Regular expression used for item value validation (before submitting by user).");
            ftf.setStyleName(row, 1, "inputFormInlineComment");
            ftf.setColSpan(row, 1, 2);
        }
    }
    // set styles
    for (int n = 0; n < ft.getRowCount(); n++) {
        ftf.setStyleName(n, 0, "itemName");
    }
    // scroll panel
    ScrollPanel sp = new ScrollPanel(ft);
    sp.addStyleName("perun-tableScrollPanel");
    sp.setSize("560px", "320px");
    sp.scrollToTop();
    return sp;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetAttributesDefinition(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)357 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)286 PerunError (cz.metacentrum.perun.webgui.model.PerunError)173 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)149 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)105 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)105 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)98 ArrayList (java.util.ArrayList)86 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)67 JSONObject (com.google.gwt.json.client.JSONObject)54 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)54 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)28 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)28 HashMap (java.util.HashMap)27 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)22 JSONNumber (com.google.gwt.json.client.JSONNumber)19 User (cz.metacentrum.perun.webgui.model.User)18 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)18 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)18 Map (java.util.Map)18