/** * Return URL to Password change GUI for selected namespace * * @param namespace namespace where we want to reset password * @return URL to password reset GUI */ public static String getPasswordResetLink(String namespace) { String value = PerunWebSession.getInstance().getConfiguration().getCustomProperty("getPasswordResetUrl"); if (value != null && !value.isEmpty()) { // PWD-RESET URL IS CONFIGURED AS FIXED if (namespace != null && !namespace.isEmpty()) { return value + "?login-namespace=" + namespace; } else { return value; } } else { // USE RELATIVE PWD-RESET URL String baseUrl = Window.Location.getProtocol() + "//" + Window.Location.getHost(); if (!Utils.isDevel()) { // VALID URL FOR PRODUCTION String rpc = ""; if (PerunWebSession.getInstance().getRpcServer() != null) { rpc = PerunWebSession.getInstance().getRpcServer(); } if (rpc.equalsIgnoreCase("krb")) { baseUrl += "/krb"; } else if (rpc.equalsIgnoreCase("fed")) { baseUrl += "/fed"; } else if (rpc.equalsIgnoreCase("forceAuthn-fed")) { baseUrl += "/fed-force"; } else if (rpc.equalsIgnoreCase("cert")) { baseUrl += "/cert"; } else if (rpc.equalsIgnoreCase("einfra")) { baseUrl += "/krb-einfra"; } else { // KRB AS BACKUP - "default" baseUrl += "/krb"; } baseUrl += "/pwd-reset/"; } else { // VALID URL FOR DEVEL baseUrl += "/PasswordResetKrb.html"; } if (namespace != null && !namespace.isEmpty()) { return baseUrl + "?login-namespace=" + namespace; } else { return baseUrl; } } }
public Widget draw() { this.titleWidget.setText( Utils.getStrippedStringWithEllipsis(group.getName()) + ": " + "ext sources"); // main panel VerticalPanel vp = new VerticalPanel(); vp.setSize("100%", "100%"); // HORIZONTAL MENU TabMenu menu = new TabMenu(); menu.addWidget(UiElements.getRefreshButton(this)); // get VO resources final GetGroupExtSources extSources = new GetGroupExtSources(groupId); // refresh table event final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(extSources); // create ext source button CustomButton addButton = TabMenu.getPredefinedButton( ButtonType.ADD, true, ButtonTranslation.INSTANCE.addExtSource(), new ClickHandler() { public void onClick(ClickEvent event) { session .getTabManager() .addTabToCurrentTab(new AddGroupExtSourceTabItem(groupId), true); } }); if (session.isVoAdmin(voId)) { menu.addWidget(addButton); } final CustomButton removeButton = TabMenu.getPredefinedButton( ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeExtSource()); removeButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { final ArrayList<ExtSource> extSourcesToRemove = extSources.getTableSelectedList(); String text = "Following external sources will be removed from Group. You won't be able to import members from them anymore."; UiElements.showDeleteConfirm( extSourcesToRemove, text, new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !! for (int i = 0; i < extSourcesToRemove.size(); i++) { RemoveExtSource request; if (i == extSourcesToRemove.size() - 1) { request = new RemoveExtSource( JsonCallbackEvents.disableButtonEvents(removeButton, events)); } else { request = new RemoveExtSource( JsonCallbackEvents.disableButtonEvents(removeButton)); } request.removeGroupExtSource(groupId, extSourcesToRemove.get(i).getId()); } } }); } }); if (session.isVoAdmin(voId)) { menu.addWidget(removeButton); } // authorization - enable buttons for vo admin only. if (!session.isVoAdmin(voId)) { addButton.setEnabled(false); removeButton.setEnabled(false); extSources.setCheckable(false); } menu.addFilterWidget( new ExtendedSuggestBox(extSources.getOracle()), new PerunSearchEvent() { @Override public void searchFor(String text) { extSources.filterTable(text); } }, "Filter external sources by name or type"); // add menu to the main panel vp.add(menu); vp.setCellHeight(menu, "30px"); CellTable<ExtSource> table = extSources.getTable(); if (session.isVoAdmin(voId)) { removeButton.setEnabled(false); JsonUtils.addTableManagedButton(extSources, table, removeButton); } table.addStyleName("perun-table"); table.setWidth("100%"); ScrollPanel sp = new ScrollPanel(table); sp.addStyleName("perun-tableScrollPanel"); vp.add(sp); session.getUiElements().resizePerunTable(sp, 350, this); this.contentWidget.setWidget(vp); return getWidget(); }
public Widget draw() { titleWidget.setText( Utils.getStrippedStringWithEllipsis(facility.getName()) + " (" + facility.getType() + "): create resource"); VerticalPanel vp = new VerticalPanel(); vp.setSize("100%", "100%"); // form inputs final ExtendedTextBox nameTextBox = new ExtendedTextBox(); final TextBox descriptionTextBox = new TextBox(); final ListBoxWithObjects<VirtualOrganization> vosDropDown = new ListBoxWithObjects<VirtualOrganization>(); // send button final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createResource()); // local events fills the listbox of Vos and Slds JsonCallbackEvents event = new JsonCallbackEvents() { @Override public void onFinished(JavaScriptObject jso) { // fill VOs listbox vosDropDown.clear(); ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso); vos = new TableSorter<VirtualOrganization>().sortByName(vos); for (VirtualOrganization vo : vos) { vosDropDown.addItem(vo); } if (!vos.isEmpty()) createButton.setEnabled(true); } @Override public void onLoadingStart() { vosDropDown.clear(); vosDropDown.addItem("Loading..."); createButton.setEnabled(false); } @Override public void onError(PerunError error) { vosDropDown.clear(); vosDropDown.addItem("Error while loading"); createButton.setEnabled(false); } }; // load available VOs final GetVos vos = new GetVos(event); vos.setForceAll(true); vos.retrieveData(); // layout FlexTable layout = new FlexTable(); layout.setStyleName("inputFormFlexTable"); FlexCellFormatter cellFormatter = layout.getFlexCellFormatter(); // Add some standard form options layout.setHTML(0, 0, "Name:"); layout.setWidget(0, 1, nameTextBox); layout.setHTML(1, 0, "Description:"); layout.setWidget(1, 1, descriptionTextBox); layout.setHTML(2, 0, "VO:"); layout.setWidget(2, 1, vosDropDown); layout.setHTML(3, 0, "Facility:"); layout.setHTML(3, 1, facility.getName() + " (" + facility.getType() + ")"); for (int i = 0; i < layout.getRowCount(); i++) { cellFormatter.addStyleName(i, 0, "itemName"); } layout.setWidth("350px"); TabMenu menu = new TabMenu(); final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() { @Override public boolean validateTextBox() { if (nameTextBox.getTextBox().getText().trim().isEmpty()) { nameTextBox.setError("Name can't be empty."); return false; } nameTextBox.setOk(); return true; } }; nameTextBox.setValidator(validator); createButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { // loads new tab when creating successful, also disable button JsonCallbackEvents localEvents = new JsonCallbackEvents() { public void onLoadingStart() { (JsonCallbackEvents.disableButtonEvents(createButton)).onLoadingStart(); } public void onFinished(JavaScriptObject jso) { (JsonCallbackEvents.disableButtonEvents(createButton)).onFinished(jso); Resource res = (Resource) jso; session .getTabManager() .addTabToCurrentTab( new CreateFacilityResourceManageServicesTabItem(facility, res), true); } public void onError(PerunError error) { (JsonCallbackEvents.disableButtonEvents(createButton)).onError(error); } }; if (validator.validateTextBox()) { // request CreateResource request = new CreateResource(localEvents); request.createResource( nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getText().trim(), facility.getId(), vosDropDown.getSelectedObject().getId()); } } }); menu.addWidget(createButton); final TabItem tab = this; menu.addWidget( TabMenu.getPredefinedButton( ButtonType.CANCEL, "", new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { session.getTabManager().closeTab(tab, false); } })); vp.add(layout); vp.add(menu); vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT); this.contentWidget.setWidget(vp); return getWidget(); }
public Widget draw() { this.titleWidget.setText( Utils.getStrippedStringWithEllipsis(service.getName()) + ": exec services"); final VerticalPanel vp = new VerticalPanel(); vp.setSize("100%", "100%"); TabMenu menu = new TabMenu(); vp.add(menu); vp.setCellHeight(menu, "30px"); final ListExecServices callback = new ListExecServices(serviceId); CellTable<ExecService> table = callback.getTable( new FieldUpdater<ExecService, String>() { public void update(int index, ExecService object, String value) { // manage details of exec services (dependency, status, update values?) session.getTabManager().addTab(new ViewExecServiceTabItem(object)); } }); // refresh event after deletion final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback); menu.addWidget( TabMenu.getPredefinedButton( ButtonType.CREATE, ButtonTranslation.INSTANCE.createExecService(), new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { session.getTabManager().addTabToCurrentTab(new AddExecServiceTabItem(service)); } })); final CustomButton deleteButton = TabMenu.getPredefinedButton( ButtonType.REMOVE, ButtonTranslation.INSTANCE.deleteSelectedExecServices()); menu.addWidget(deleteButton); deleteButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { final ArrayList<ExecService> execToRemove = callback.getTableSelectedList(); UiElements.showDeleteConfirm( execToRemove, new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE for (int i = 0; i < execToRemove.size(); i++) { if (i == execToRemove.size() - 1) { DeleteExecService request = new DeleteExecService( JsonCallbackEvents.disableButtonEvents(deleteButton, events)); request.deleteExecService(execToRemove.get(i).getId()); } else { DeleteExecService request = new DeleteExecService( JsonCallbackEvents.disableButtonEvents(deleteButton)); request.deleteExecService(execToRemove.get(i).getId()); } } } }); } }); table.addStyleName("perun-table"); ScrollPanel sp = new ScrollPanel(table); sp.addStyleName("perun-tableScrollPanel"); session.getUiElements().resizePerunTable(sp, 350, this); final CustomButton enable = TabMenu.getPredefinedButton(ButtonType.ENABLE, "Enable selected exec service(s)"); final CustomButton disable = TabMenu.getPredefinedButton(ButtonType.DISABLE, "Disable selected exec service(s)"); menu.addWidget(enable); menu.addWidget(disable); enable.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { ArrayList<ExecService> list = callback.getTableSelectedList(); for (int i = 0; i < list.size(); i++) { ExecService e = list.get(i); if (i < list.size() - 1) { // any call if (!e.isEnabled()) { UpdateExecService request = new UpdateExecService(JsonCallbackEvents.disableButtonEvents(enable)); e.setEnabled(true); request.updateExecService(e); } } else { // last call if (!e.isEnabled()) { UpdateExecService request = new UpdateExecService(JsonCallbackEvents.disableButtonEvents(enable, events)); e.setEnabled(true); request.updateExecService(e); } } } } }); disable.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { ArrayList<ExecService> list = callback.getTableSelectedList(); for (int i = 0; i < list.size(); i++) { ExecService e = list.get(i); if (i < list.size() - 1) { // any call if (e.isEnabled()) { UpdateExecService request = new UpdateExecService(JsonCallbackEvents.disableButtonEvents(disable)); e.setEnabled(false); request.updateExecService(e); } } else { // last call if (e.isEnabled()) { UpdateExecService request = new UpdateExecService( JsonCallbackEvents.disableButtonEvents(disable, events)); e.setEnabled(false); request.updateExecService(e); } } } } }); deleteButton.setEnabled(false); enable.setEnabled(false); disable.setEnabled(false); JsonUtils.addTableManagedButton(callback, table, deleteButton); JsonUtils.addTableManagedButton(callback, table, enable); JsonUtils.addTableManagedButton(callback, table, disable); vp.add(sp); vp.setCellHeight(sp, "100%"); // add tabs to the main panel this.contentWidget.setWidget(vp); return getWidget(); }
public Widget draw() { // show only part of title titleWidget.setText(Utils.getStrippedStringWithEllipsis(publication.getTitle())); // MAIN PANEL ScrollPanel sp = new ScrollPanel(); sp.addStyleName("perun-tableScrollPanel"); VerticalPanel vp = new VerticalPanel(); vp.addStyleName("perun-table"); sp.add(vp); // resize perun table to correct size on screen session.getUiElements().resizePerunTable(sp, 350, this); // content final FlexTable ft = new FlexTable(); ft.setStyleName("inputFormFlexTable"); if (publication.getLocked() == false) { ft.setHTML(1, 0, "Id / Origin:"); ft.setHTML(2, 0, "Title:"); ft.setHTML(3, 0, "Year:"); ft.setHTML(4, 0, "Category:"); ft.setHTML(5, 0, "Rank:"); ft.setHTML(6, 0, "ISBN / ISSN:"); ft.setHTML(7, 0, "DOI:"); ft.setHTML(8, 0, "Full cite:"); ft.setHTML(9, 0, "Created by:"); ft.setHTML(10, 0, "Created date:"); for (int i = 0; i < ft.getRowCount(); i++) { ft.getFlexCellFormatter().setStyleName(i, 0, "itemName"); } ft.getFlexCellFormatter().setWidth(1, 0, "100px"); final ListBoxWithObjects<Category> listbox = new ListBoxWithObjects<Category>(); // fill listbox JsonCallbackEvents events = new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { for (Category cat : JsonUtils.<Category>jsoAsList(jso)) { listbox.addItem(cat); // if right, selected if (publication.getCategoryId() == cat.getId()) { listbox.setSelected(cat, true); } } } }; FindAllCategories categories = new FindAllCategories(events); categories.retrieveData(); final TextBox rank = new TextBox(); rank.setWidth("30px"); rank.setMaxLength(4); rank.setText(String.valueOf(publication.getRank())); final TextBox title = new TextBox(); title.setMaxLength(1024); title.setText(publication.getTitle()); title.setWidth("500px"); final TextBox year = new TextBox(); year.setText(String.valueOf(publication.getYear())); year.setMaxLength(4); year.setWidth("30px"); final TextBox isbn = new TextBox(); isbn.setText(publication.getIsbn()); isbn.setMaxLength(32); final TextBox doi = new TextBox(); doi.setText(publication.getDoi()); doi.setMaxLength(256); final TextArea main = new TextArea(); main.setText(publication.getMain()); main.setSize("500px", "70px"); // set max length main.getElement().setAttribute("maxlength", "4000"); ft.setHTML( 1, 1, publication.getId() + " / <Strong>Ext. Id: </strong>" + publication.getExternalId() + " <Strong>System: </strong>" + publication.getPublicationSystemName()); ft.setWidget(2, 1, title); ft.setWidget(3, 1, year); ft.setWidget(4, 1, listbox); if (session.isPerunAdmin()) { // only perunadmin can change rank ft.setWidget(5, 1, rank); } else { ft.setHTML(5, 1, "" + publication.getRank()); } ft.setWidget(6, 1, isbn); ft.setWidget(7, 1, doi); ft.setWidget(8, 1, main); ft.setHTML(9, 1, String.valueOf(publication.getCreatedBy())); ft.setHTML( 10, 1, DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM) .format(new Date((long) publication.getCreatedDate()))); // update button final CustomButton change = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in publication details"); change.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { Publication pub = JsonUtils.clone(publication).cast(); if (!JsonUtils.checkParseInt(year.getText())) { JsonUtils.cantParseIntConfirm("YEAR", year.getText()); } else { pub.setYear(Integer.parseInt(year.getText())); } if (session.isPerunAdmin()) { pub.setRank(Double.parseDouble(rank.getText())); } pub.setCategoryId(listbox.getSelectedObject().getId()); pub.setTitle(title.getText()); pub.setMain(main.getText()); pub.setIsbn(isbn.getText()); pub.setDoi(doi.getText()); UpdatePublication upCall = new UpdatePublication( JsonCallbackEvents.disableButtonEvents( change, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { // refresh page content Publication p = jso.cast(); publication = p; draw(); } })); upCall.updatePublication(pub); } }); ft.setWidget(0, 0, change); } else { ft.getFlexCellFormatter().setColSpan(0, 0, 2); ft.setWidget( 0, 0, new HTML( new Image(SmallIcons.INSTANCE.lockIcon()) + " <strong>Publication is locked. Ask administrator to perform any changes for you at [email protected].</strong>")); ft.setHTML(1, 0, "Id / Origin:"); ft.setHTML(2, 0, "Title:"); ft.setHTML(3, 0, "Year:"); ft.setHTML(4, 0, "Category:"); ft.setHTML(5, 0, "Rank:"); ft.setHTML(6, 0, "ISBN / ISSN:"); ft.setHTML(7, 0, "DOI:"); ft.setHTML(8, 0, "Full cite:"); ft.setHTML(9, 0, "Created by:"); ft.setHTML(10, 0, "Created date:"); for (int i = 0; i < ft.getRowCount(); i++) { ft.getFlexCellFormatter().setStyleName(i, 0, "itemName"); } ft.getFlexCellFormatter().setWidth(1, 0, "100px"); ft.setHTML( 1, 1, publication.getId() + " / <Strong>Ext. Id: </strong>" + publication.getExternalId() + " <Strong>System: </strong>" + publication.getPublicationSystemName()); ft.setHTML(2, 1, publication.getTitle()); ft.setHTML(3, 1, String.valueOf(publication.getYear())); ft.setHTML(4, 1, publication.getCategoryName()); ft.setHTML(5, 1, String.valueOf(publication.getRank()) + " (default is 0)"); ft.setHTML(6, 1, publication.getIsbn()); ft.setHTML(7, 1, publication.getDoi()); ft.setHTML(8, 1, publication.getMain()); ft.setHTML(9, 1, String.valueOf(publication.getCreatedBy())); ft.setHTML( 10, 1, DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM) .format(new Date((long) publication.getCreatedDate()))); } // LOCK / UNLOCK button for PerunAdmin if (session.isPerunAdmin()) { final CustomButton lock; if (publication.getLocked()) { lock = new CustomButton( "Unlock", "Allow editing of publication details (for users).", SmallIcons.INSTANCE.lockOpenIcon()); ft.setWidget(0, 0, lock); ft.getFlexCellFormatter().setColSpan(0, 0, 1); ft.setWidget( 0, 1, new HTML(new Image(SmallIcons.INSTANCE.lockIcon()) + " Publication is locked.")); } else { lock = new CustomButton( "Lock", "Deny editing of publication details (for users).", SmallIcons.INSTANCE.lockIcon()); ft.setWidget(0, 1, lock); } lock.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { UpdatePublication upCall = new UpdatePublication( JsonCallbackEvents.disableButtonEvents( lock, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { // refresh page content Publication p = jso.cast(); publication = p; draw(); } })); Publication p = JsonUtils.clone(publication).cast(); p.setLocked(!publication.getLocked()); upCall.updatePublication(p); } }); } DisclosurePanel dp = new DisclosurePanel(); dp.setWidth("100%"); dp.setContent(ft); dp.setOpen(true); FlexTable detailsHeader = new FlexTable(); detailsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.bookIcon())); detailsHeader.setHTML(0, 1, "<h3>Details</h3>"); dp.setHeader(detailsHeader); vp.add(dp); vp.add(loadAuthorsSubTab()); vp.add(loadThanksSubTab()); this.contentWidget.setWidget(sp); return getWidget(); }
public Widget draw() { titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings"); // Main panel final VerticalPanel vp = new VerticalPanel(); vp.setSize("100%", "100%"); final TabMenu menu = new TabMenu(); // Adds menu to the main panel vp.add(menu); vp.setCellHeight(menu, "30px"); // IDS final Map<String, Integer> ids = new HashMap<String, Integer>(); ids.put("group", groupId); // define GET ATTRIBUTES callback final GetAttributesV2 jsonCallback = new GetAttributesV2(); jsonCallback.setIds(ids); if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId())) jsonCallback.setCheckable(false); final CellTable<Attribute> table = jsonCallback.getEmptyTable(); table.setWidth("100%"); table.addStyleName("perun-table"); ScrollPanel sp = new ScrollPanel(table); sp.addStyleName("perun-tableScrollPanel"); session.getUiElements().resizePerunTable(sp, 350, this); vp.add(sp); // define GET RES. REQ ATTRIBUTES callback final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2( null, JsonCallbackEvents.passDataToAnotherCallback(jsonCallback)); // GROUP RESOURCES LISTBOX final ListBoxWithObjects<Resource> resourceDropDown = new ListBoxWithObjects<Resource>(); resourceDropDown.setTitle( "By selecting a resource you will switch to either group-resource or member-resource setting (you must pick member too)"); // fill table with group attributes on page load if (lastSelectedMemberId == 0 && lastSelectedResourceId == 0) { jsonCallback.retrieveData(); } else { // load attrs by listbox selection after calls are done Scheduler.get() .scheduleFixedPeriod( new Scheduler.RepeatingCommand() { @Override public boolean execute() { // load proper table if something was selected if (resCallDone && memCallDone) { // trigger change event DomEvent.fireNativeEvent(Document.get().createChangeEvent(), resourceDropDown); return false; } return true; } }, 200); } // fill resources listbox if (resources == null) { // get assigned resources GetAssignedResources resources = new GetAssignedResources( groupId, PerunEntity.GROUP, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { ArrayList<Resource> resources = JsonUtils.jsoAsList(jso); resourceDropDown.clear(); if (resources != null && !resources.isEmpty()) { resources = new TableSorter<Resource>().sortByName(resources); resourceDropDown.addNotSelectedOption(); for (int i = 0; i < resources.size(); i++) { resourceDropDown.addItem(resources.get(i)); if (lastSelectedResourceId == resources.get(i).getId()) { resourceDropDown.setSelected(resources.get(i), true); } } } else { resourceDropDown.addItem("No resources available"); } resCallDone = true; } public void onError(PerunError error) { resourceDropDown.clear(); resourceDropDown.addItem("Error while loading"); resCallDone = true; } public void onLoadingStart() { resCallDone = false; resourceDropDown.clear(); resourceDropDown.addItem("Loading..."); } }); resources.retrieveData(); } else { // use predefined resources resourceDropDown.addNotSelectedOption(); resources = new TableSorter<Resource>().sortByName(resources); resourceDropDown.addAllItems(resources); } // GROUP MEMBERS LISTBOX final ListBoxWithObjects<RichMember> membersDropDown = new ListBoxWithObjects<RichMember>(); membersDropDown.setTitle( "By selecting a member you will switch to either member or member-resource settings (you must pick resource too)"); // fill members listbox GetGroupRichMembers members = new GetGroupRichMembers( groupId, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso); membersDropDown.clear(); if (mems != null && !mems.isEmpty()) { mems = new TableSorter<RichMember>().sortByName(mems); membersDropDown.addNotSelectedOption(); for (int i = 0; i < mems.size(); i++) { membersDropDown.addItem(mems.get(i)); if (mems.get(i).getId() == lastSelectedMemberId) { membersDropDown.setSelected(mems.get(i), true); } } } else { membersDropDown.addItem("No members available"); } memCallDone = true; } public void onError(PerunError error) { membersDropDown.clear(); membersDropDown.addItem("Error while loading"); memCallDone = true; } public void onLoadingStart() { memCallDone = false; membersDropDown.clear(); membersDropDown.addItem("Loading..."); } }); members.retrieveData(); // CHECKBOXES "FOR ALL MEMBERS" final CheckBox memChb = new CheckBox(); memChb.setText("To all members"); memChb.setVisible(false); memChb.setTitle("Uses this setting for all members of this group."); memChb.setValue(false); // SAVE CHANGES BUTTON final CustomButton saveChangesButton = TabMenu.getPredefinedButton( ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes()); if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId())) saveChangesButton.setEnabled(false); // click handler to save group and member-user attributes final ClickHandler saveAttrsClickHandler = new ClickHandler() { public void onClick(ClickEvent event) { final ArrayList<Attribute> list = jsonCallback.getTableSelectedList(); if (UiElements.cantSaveEmptyListDialogBox(list)) { // refresh table and disable button a event for GetAttributes final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents( saveChangesButton, JsonCallbackEvents.refreshTableEvents(jsonCallback)); if (memChb.getValue() == true) { // to all members selected UiElements.generateInfo( WidgetTranslation.INSTANCE.saveConfirmTitle(), "Same value(s) for selected attribute(s) will be set to ALL members of group.", new ClickHandler() { public void onClick(ClickEvent event) { ArrayList<RichMember> memList = membersDropDown.getAllObjects(); for (int i = 0; i < memList.size(); i++) { SetAttributes request = new SetAttributes(); if (i == memList.size() - 1) { request.setEvents(events); } else { request.setEvents( JsonCallbackEvents.disableButtonEvents(saveChangesButton)); } Map<String, Integer> ids = new HashMap<String, Integer>(); ids.put("member", memList.get(i).getId()); ids.put("workWithUserAttributes", 1); request.setAttributes(ids, list); } } }); } else { // just one group / memeber SetAttributes request = new SetAttributes(events); request.setAttributes(jsonCallback.getIds(), list); } } } }; // click handler to save required attributes final ClickHandler saveReqAttrsClickHandler = new ClickHandler() { public void onClick(ClickEvent event) { final ArrayList<Attribute> list = jsonCallback.getTableSelectedList(); // check if not empty if (UiElements.cantSaveEmptyListDialogBox(list)) { // refresh table and disable button a event for GetResourceRequiredAttributes final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents( saveChangesButton, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { jsonCallback.clearTable(); // set back resourceToGetServicesFrom Map<String, Integer> ids = reqAttrs.getIds(); if (ids.containsKey("resource")) { ids.put("resourceToGetServicesFrom", ids.get("resource")); } if (ids.containsKey("user")) { ids.put("workWithUserAttributes", 1); } if (ids.containsKey("resource") && ids.containsKey("group")) { ids.put("workWithGroupAttributes", 1); } reqAttrs.setIds(ids); reqAttrs.retrieveData(); } }); final SetAttributes request = new SetAttributes(); if (memChb.getValue() == true) { // to all members selected UiElements.generateInfo( WidgetTranslation.INSTANCE.saveConfirmTitle(), "Same value(s) for selected attribute(s) will be set to ALL members of group.", new ClickHandler() { public void onClick(ClickEvent event) { ArrayList<RichMember> memList = membersDropDown.getAllObjects(); for (int i = 0; i < memList.size(); i++) { if (i == 0) { events.onLoadingStart(); } // trigger disable button if first Map<String, Integer> ids = new HashMap<String, Integer>(); ids.put("member", memList.get(i).getId()); ids.put("user", memList.get(i).getUserId()); ids.put("resource", resourceDropDown.getSelectedObject().getId()); ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId()); if (i == memList.size() - 1) { request.setEvents(events); } // set events to last to get refresh and button enable request.setAttributes(ids, list); } } }); } else { // group or member request.setEvents(events); // disable button events request.setAttributes(reqAttrs.getIds(), list); } } } }; // REMOVE BUTTON final CustomButton removeButton = TabMenu.getPredefinedButton( ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes()); if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId())) removeButton.setEnabled(false); // click handler to remove group and member-user attributes final ClickHandler removeAttrsClickHandler = new ClickHandler() { public void onClick(ClickEvent event) { final ArrayList<Attribute> list = jsonCallback.getTableSelectedList(); if (UiElements.cantSaveEmptyListDialogBox(list)) { // refresh table and disable button a event for GetAttributes final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents( removeButton, JsonCallbackEvents.refreshTableEvents(jsonCallback)); final RemoveAttributes request = new RemoveAttributes(); if (memChb.getValue() == true) { // to all members selected UiElements.generateInfo( WidgetTranslation.INSTANCE.deleteConfirmTitle(), "Selected attribute(s) will be removed from ALL members of group.", new ClickHandler() { public void onClick(ClickEvent event) { ArrayList<RichMember> memList = membersDropDown.getAllObjects(); for (int i = 0; i < memList.size(); i++) { if (i == 0) { events.onLoadingStart(); } // trigger disable button if first Map<String, Integer> ids = new HashMap<String, Integer>(); ids.put("member", memList.get(i).getId()); ids.put("workWithUserAttributes", 1); if (i == memList.size() - 1) { request.setEvents(events); } // set events to last to get refresh and button enable request.removeAttributes(ids, list); } } }); } else { // just one group / memeber request.setEvents(events); // disable button events request.removeAttributes(jsonCallback.getIds(), list); } } } }; // click handler to remove ResourceRequiredAttributes final ClickHandler removeReqAttrsClickHandler = new ClickHandler() { public void onClick(ClickEvent event) { final ArrayList<Attribute> list = jsonCallback.getTableSelectedList(); if (UiElements.cantSaveEmptyListDialogBox(list)) { // refresh table and disable button a event for GetAttributes final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents( removeButton, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { jsonCallback.clearTable(); // set back resourceToGetServicesFrom Map<String, Integer> ids = reqAttrs.getIds(); if (ids.containsKey("resource")) { ids.put("resourceToGetServicesFrom", ids.get("resource")); } if (ids.containsKey("user")) { ids.put("workWithUserAttributes", 1); } if (ids.containsKey("resource") && ids.containsKey("group")) { ids.put("workWithGroupAttributes", 1); } reqAttrs.setIds(ids); reqAttrs.retrieveData(); } }); final RemoveAttributes request = new RemoveAttributes(); if (memChb.getValue() == true) { // to all members selected UiElements.generateInfo( WidgetTranslation.INSTANCE.deleteConfirmTitle(), "Selected attribute(s) will be removed from ALL members of group.", new ClickHandler() { @Override public void onClick(ClickEvent event) { ArrayList<RichMember> memList = membersDropDown.getAllObjects(); for (int i = 0; i < memList.size(); i++) { if (i == 0) { events.onLoadingStart(); } // trigger disable button if first Map<String, Integer> ids = new HashMap<String, Integer>(); ids.put("member", memList.get(i).getId()); ids.put("user", memList.get(i).getUserId()); ids.put("resource", resourceDropDown.getSelectedObject().getId()); ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId()); if (i == memList.size() - 1) { request.setEvents(events); } // set events to last to get refresh and button enable request.removeAttributes(ids, list); } } }); } else { // just one group / member request.setEvents(events); // disable button events request.removeAttributes(reqAttrs.getIds(), list); } } } }; // SET NEW ATTR BUTTON final CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.setNewAttributes()); if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId())) setNewAttributeButton.setEnabled(false); // click handler setNewAttributeButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { ids.clear(); if (resourceDropDown.getSelectedIndex() > 0) { if (membersDropDown.getSelectedIndex() > 0) { ids.put("member", membersDropDown.getSelectedObject().getId()); ids.put("user", membersDropDown.getSelectedObject().getUserId()); ids.put("resource", resourceDropDown.getSelectedObject().getId()); ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId()); } else { ids.put("resource", resourceDropDown.getSelectedObject().getId()); ids.put("group", groupId); ids.put("workWithGroupAttributes", 1); } } else { if (membersDropDown.getSelectedIndex() > 0) { ids.put("member", membersDropDown.getSelectedObject().getId()); ids.put("user", membersDropDown.getSelectedObject().getUserId()); } else { ids.put("group", groupId); } } session .getTabManager() .addTabToCurrentTab(new SetNewAttributeTabItem(ids, jsonCallback.getList()), true); } }); // ClickHandlersRegistration - save onClicks for GetAttributes final ArrayList<HandlerRegistration> clickHandlers = new ArrayList<HandlerRegistration>(); clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler)); clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler)); // DEFINE CHANGE HANDLER FOR ALL DROP DOWNS ChangeHandler changeHandler = new ChangeHandler() { public void onChange(ChangeEvent event) { int resIndex = resourceDropDown.getSelectedIndex(); int memIndex = membersDropDown.getSelectedIndex(); // no resource or member selected if (resIndex == 0 && memIndex == 0) { lastSelectedMemberId = 0; lastSelectedResourceId = 0; memChb.setValue(false); memChb.setVisible(false); jsonCallback.clearTable(); ids.clear(); ids.put("group", groupId); jsonCallback.setIds(ids); jsonCallback.retrieveData(); for (HandlerRegistration handler : clickHandlers) { if (handler != null) { handler.removeHandler(); } } clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler)); clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler)); } // no resource but member selected if (resIndex == 0 && memIndex > 0) { lastSelectedMemberId = membersDropDown.getSelectedObject().getId(); lastSelectedResourceId = 0; memChb.setValue(false); memChb.setVisible(true); jsonCallback.clearTable(); ids.clear(); ids.put("member", membersDropDown.getSelectedObject().getId()); ids.put("workWithUserAttributes", 1); jsonCallback.setIds(ids); jsonCallback.retrieveData(); for (HandlerRegistration handler : clickHandlers) { if (handler != null) { handler.removeHandler(); } } clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler)); clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler)); } // resource and no member selected if (resIndex > 0 && memIndex == 0) { lastSelectedMemberId = 0; lastSelectedResourceId = resourceDropDown.getSelectedObject().getId(); memChb.setValue(false); memChb.setVisible(false); jsonCallback.clearTable(); ids.clear(); ids.put("group", groupId); ids.put("resource", resourceDropDown.getSelectedObject().getId()); ids.put("resourceToGetServicesFrom", ids.get("resource")); ids.put("workWithGroupAttributes", 1); reqAttrs.setIds(ids); reqAttrs.retrieveData(); // set ids back to make saveChanges work ids.remove("resourceToGetServicesFrom"); reqAttrs.setIds(ids); for (HandlerRegistration handler : clickHandlers) { if (handler != null) { handler.removeHandler(); } } clickHandlers.add(saveChangesButton.addClickHandler(saveReqAttrsClickHandler)); clickHandlers.add(removeButton.addClickHandler(removeReqAttrsClickHandler)); } // resource and member selected if (resIndex > 0 && memIndex > 0) { lastSelectedMemberId = membersDropDown.getSelectedObject().getId(); lastSelectedResourceId = resourceDropDown.getSelectedObject().getId(); memChb.setValue(false); memChb.setVisible(true); jsonCallback.clearTable(); ids.clear(); ids.put("resource", resourceDropDown.getSelectedObject().getId()); ids.put("resourceToGetServicesFrom", ids.get("resource")); ids.put("member", membersDropDown.getSelectedObject().getId()); ids.put("workWithUserAttributes", 1); reqAttrs.setIds(ids); reqAttrs.retrieveData(); // set ids back to make saveChanges work ids.clear(); ids.put("member", membersDropDown.getSelectedObject().getId()); ids.put("user", membersDropDown.getSelectedObject().getUser().getId()); ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId()); ids.put("resource", resourceDropDown.getSelectedObject().getId()); reqAttrs.setIds(ids); for (HandlerRegistration handler : clickHandlers) { if (handler != null) { handler.removeHandler(); } } clickHandlers.add(saveChangesButton.addClickHandler(saveReqAttrsClickHandler)); clickHandlers.add(removeButton.addClickHandler(removeReqAttrsClickHandler)); } } }; // ADD CHANGE HANDLERS TO DROP-DOWN MENUS resourceDropDown.addChangeHandler(changeHandler); membersDropDown.addChangeHandler(changeHandler); // PUT ELEMENTS IN MENU menu.addWidget(saveChangesButton); // menu.addWidget(resChb); menu.addWidget(memChb); menu.addWidget(setNewAttributeButton); menu.addWidget(removeButton); menu.addWidget(new HTML("<strong>Resources:</strong>")); menu.addWidget(resourceDropDown); menu.addWidget(new HTML("<strong>Members:</strong>")); menu.addWidget(membersDropDown); this.contentWidget.setWidget(vp); return getWidget(); }
public Widget draw() { this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName())); // main widget panel final VerticalPanel vp = new VerticalPanel(); vp.setSize("100%", "100%"); AbsolutePanel dp = new AbsolutePanel(); final FlexTable menu = new FlexTable(); menu.setCellSpacing(5); // Add facility information menu.setWidget(0, 0, new Image(LargeIcons.INSTANCE.databaseServerIcon())); Label facilityName = new Label(); facilityName.setText(Utils.getStrippedStringWithEllipsis(facility.getName(), 40)); facilityName.setStyleName("now-managing"); facilityName.setTitle(facility.getName()); menu.setWidget(0, 1, facilityName); menu.setHTML(0, 2, " "); menu.getFlexCellFormatter().setWidth(0, 2, "25px"); int column = 3; final JsonCallbackEvents events = new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { new GetEntityById( PerunEntity.FACILITY, facilityId, new JsonCallbackEvents() { public void onFinished(JavaScriptObject jso) { facility = jso.cast(); open(); draw(); } }) .retrieveData(); } }; CustomButton change = new CustomButton( "", ButtonTranslation.INSTANCE.editFacilityDetails(), SmallIcons.INSTANCE.applicationFormEditIcon()); change.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { // prepare confirm content session .getTabManager() .addTabToCurrentTab(new EditFacilityDetailsTabItem(facility, events)); } }); menu.setWidget(0, column, change); column++; menu.setHTML(0, column, " "); menu.getFlexCellFormatter().setWidth(0, column, "25px"); column++; if (JsonUtils.isExtendedInfoVisible()) { menu.setHTML( 0, column, "<strong>ID:</strong><br/><span class=\"inputFormInlineComment\">" + facility.getId() + "</span>"); column++; menu.setHTML(0, column, " "); menu.getFlexCellFormatter().setWidth(0, column, "25px"); column++; } menu.setHTML( 0, column, "<strong>Description:</strong><br/><span class=\"inputFormInlineComment\">" + facility.getDescription() + " </span>"); dp.add(menu); vp.add(dp); vp.setCellHeight(dp, "30px"); // TAB PANEL tabPanel.clear(); tabPanel.add(new FacilityResourcesTabItem(facility), "Resources"); tabPanel.add(new FacilityAllowedGroupsTabItem(facility), "Allowed Groups"); tabPanel.add(new FacilityStatusTabItem(facility), "Services status"); tabPanel.add(new FacilitySettingsTabItem(facility), "Services settings"); tabPanel.add(new FacilityDestinationsTabItem(facility), "Services destinations"); tabPanel.add(new FacilityHostsTabItem(facility), "Hosts"); tabPanel.add(new FacilityManagersTabItem(facility), "Managers"); tabPanel.add(new FacilitySecurityTeamsTabItem(facility), "Security teams"); tabPanel.add(new FacilityBlacklistTabItem(facility), "Blacklist"); tabPanel.add(new FacilityOwnersTabItem(facility), "Owners"); // Resize must be called after page fully displays Scheduler.get() .scheduleDeferred( new Command() { @Override public void execute() { tabPanel.finishAdding(); } }); vp.add(tabPanel); this.contentWidget.setWidget(vp); return getWidget(); }