public boolean isAuthorized() { if (session.isPerunAdmin()) { return true; } else { return false; } }
public Widget draw() { titleWidget.setText("Add manager"); final CustomButton searchButton = new CustomButton( "Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon()); this.users = new FindCompleteRichUsers( "", null, JsonCallbackEvents.disableButtonEvents( searchButton, new JsonCallbackEvents() { @Override public void onFinished(JavaScriptObject jso) { // if found 1 item, select ArrayList<User> list = JsonUtils.jsoAsList(jso); if (list != null && list.size() == 1) { users.getSelectionModel().setSelected(list.get(0), true); } } })); // MAIN TAB PANEL VerticalPanel firstTabPanel = new VerticalPanel(); firstTabPanel.setSize("100%", "100%"); // HORIZONTAL MENU TabMenu tabMenu = new TabMenu(); // get the table final CellTable<User> table; if (session.isPerunAdmin()) { table = users.getTable( new FieldUpdater<User, String>() { public void update(int i, User user, String s) { session.getTabManager().addTab(new UserDetailTabItem(user)); } }); } else { table = users.getTable(); } rebuildAlreadyAddedWidget(); final CustomButton addButton = TabMenu.getPredefinedButton( ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersToVo()); final TabItem tab = this; // search textbox final ExtendedTextBox searchBox = tabMenu.addSearchWidget( new PerunSearchEvent() { @Override public void searchFor(String text) { startSearching(text); searchString = text; } }, searchButton); tabMenu.addWidget(addButton); tabMenu.addWidget( TabMenu.getPredefinedButton( ButtonType.CLOSE, "", new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty()); } })); addButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { final ArrayList<User> list = users.getTableSelectedList(); if (UiElements.cantSaveEmptyListDialogBox(list)) { for (int i = 0; i < list.size(); i++) { // FIXME - Should have only one callback to core final int n = i; AddAdmin request = new AddAdmin( JsonCallbackEvents.disableButtonEvents( addButton, new JsonCallbackEvents() { @Override public void onFinished(JavaScriptObject jso) { // put names to already added alreadyAddedList.add(list.get(n)); rebuildAlreadyAddedWidget(); // unselect added person users.getSelectionModel().setSelected(list.get(n), false); // clear search searchBox.getTextBox().setText(""); } })); request.addVoAdmin(vo, list.get(i)); } } } }); // if some text has been searched before if (!searchString.equals("")) { searchBox.getTextBox().setText(searchString); startSearching(searchString); } addButton.setEnabled(false); JsonUtils.addTableManagedButton(users, table, addButton); // 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"); // add menu and the table to the main panel firstTabPanel.add(tabMenu); firstTabPanel.setCellHeight(tabMenu, "30px"); firstTabPanel.add(alreadyAdded); firstTabPanel.add(sp); session.getUiElements().resizePerunTable(sp, 350, this); this.contentWidget.setWidget(firstTabPanel); return getWidget(); }
public boolean isAuthorized() { return session.isPerunAdmin(); }
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(); }