use of cz.metacentrum.perun.webgui.model.Author in project perun by CESNET.
the class AddAuthorTabItem method draw.
public Widget draw() {
titleWidget.setText("Add author");
this.users = new FindNewAuthors("");
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// PUB-INFO
TabMenu info = new TabMenu();
info.addWidget(new HTML("<strong>FULL CITE: </strong>" + publication.getMain()));
firstTabPanel.add(info);
// HORIZONTAL MENU
TabMenu tabMenu = new TabMenu();
// get the table
final CellTable<Author> table;
if (session.isPerunAdmin()) {
table = users.getEmptyTable(new FieldUpdater<Author, String>() {
public void update(int index, Author object, String value) {
session.getTabManager().addTab(new UserDetailTabItem(object.getId()));
}
});
} else {
table = users.getEmptyTable();
}
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected user(s) as author(s) of publication: " + publication.getTitle());
tabMenu.addWidget(addButton);
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(users, table, addButton);
final TabItem tab = this;
addButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ArrayList<Author> list = users.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// proceed
for (int i = 0; i < list.size(); i++) {
final String name = list.get(i).getDisplayName();
// add name events
JsonCallbackEvents authorshipEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
updateAlreadyAdded(name);
}
};
// merge with refresh?
if (i == list.size() - 1 && events != null) {
authorshipEvents = JsonCallbackEvents.mergeEvents(authorshipEvents, events);
}
// call
CreateAuthorship request = new CreateAuthorship(JsonCallbackEvents.disableButtonEvents(addButton, authorshipEvents));
request.createAuthorship(publicationId, list.get(i).getId());
if (i == list.size() - 1) {
users.clearTableSelectedSet();
}
}
}
}
});
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
users.searchFor(text);
searchString = text;
}
}, ButtonTranslation.INSTANCE.searchUsers());
// 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 to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
// add already added
firstTabPanel.add(alreadyAddedAuthors);
firstTabPanel.setCellHeight(alreadyAddedAuthors, "30px");
// add table to the main panel
firstTabPanel.add(sp);
// do not resize like perun table to prevent wrong width in inner tab
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.Author in project perun by CESNET.
the class FindAllAuthors method filterTable.
public void filterTable(String text) {
// store list only for first time
if (backupList.isEmpty() || backupList == null) {
backupList.addAll(list);
}
// always clear selected items
selectionModel.clear();
list.clear();
if (text.equalsIgnoreCase("")) {
list.addAll(backupList);
} else {
for (Author a : backupList) {
// store facility by filter
if (a.getFullName().toLowerCase().startsWith(text.toLowerCase())) {
list.add(a);
} else if (a.getFirstName().toLowerCase().startsWith(text.toLowerCase())) {
list.add(a);
} else if (a.getLastName().toLowerCase().startsWith(text.toLowerCase())) {
list.add(a);
}
}
}
if (list.isEmpty() && !text.isEmpty()) {
loaderImage.setEmptyResultMessage("No author matching '" + text + "' found.");
} else {
loaderImage.setEmptyResultMessage("There are no publications authors.");
}
dataProvider.flush();
dataProvider.refresh();
loaderImage.loadingFinished();
}
use of cz.metacentrum.perun.webgui.model.Author in project perun by CESNET.
the class PublicationDetailTabItem method loadAuthorsSubTab.
/**
* Returns widget with authors management for publication
*
* @return widget
*/
private Widget loadAuthorsSubTab() {
DisclosurePanel dp = new DisclosurePanel();
dp.setWidth("100%");
dp.setOpen(true);
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
dp.setContent(vp);
FlexTable header = new FlexTable();
header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.userGreenIcon()));
header.setHTML(0, 1, "<h3>Authors / Reported by</h3>");
dp.setHeader(header);
// menu
TabMenu menu = new TabMenu();
// callback
final FindAuthorsByPublicationId call = new FindAuthorsByPublicationId(publication.getId());
call.setCheckable(false);
if (!publication.isLocked()) {
// editable if not locked
vp.add(menu);
vp.setCellHeight(menu, "30px");
call.setCheckable(true);
}
final CustomButton addButton = new CustomButton("Add myself", "Add you as author of publication", SmallIcons.INSTANCE.addIcon());
addButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(call);
CreateAuthorship request = new CreateAuthorship(JsonCallbackEvents.disableButtonEvents(addButton, events));
request.createAuthorship(publicationId, session.getActiveUser().getId());
}
});
menu.addWidget(addButton);
CustomButton addOthersButton = new CustomButton("Add others", "Add more authors", SmallIcons.INSTANCE.addIcon());
addOthersButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddAuthorTabItem(publication, JsonCallbackEvents.refreshTableEvents(call)), true);
}
});
menu.addWidget(addOthersButton);
// fill table
CellTable<Author> table = call.getEmptyTable();
call.retrieveData();
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove select author(s) from publication");
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(call, table, removeButton);
menu.addWidget(removeButton);
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Author> list = call.getTableSelectedList();
String text = "Following users will be removed from publication's authors. They will lose any benefit granted by publication's rank.";
UiElements.showDeleteConfirm(list, text, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
for (int i = 0; i < list.size(); i++) {
// calls the request
if (i == list.size() - 1) {
DeleteAuthorship request = new DeleteAuthorship(JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(call)));
request.deleteAuthorship(publicationId, list.get(i).getId());
} else {
DeleteAuthorship request = new DeleteAuthorship();
request.deleteAuthorship(publicationId, list.get(i).getId());
}
}
}
});
}
});
ScrollPanel sp = new ScrollPanel();
sp.add(table);
table.addStyleName("perun-table");
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
return dp;
}
use of cz.metacentrum.perun.webgui.model.Author in project perun by CESNET.
the class AllAuthorsTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
vp.getElement().setAttribute("style", "padding-top: 5px;");
vp.setSize("100%", "100%");
// MENU
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
final FindAllAuthors callback = new FindAllAuthors();
menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
callback.filterTable(text);
}
}, ButtonTranslation.INSTANCE.filterAuthors());
CellTable<Author> table = callback.getTable(new FieldUpdater<Author, String>() {
public void update(int index, Author object, String value) {
if (session.isPerunAdmin()) {
session.getTabManager().addTab(new UsersPublicationsTabItem(object.getId()));
}
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel();
sp.add(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
// resize perun table to correct size on screen
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.Author in project perun by CESNET.
the class AllPublicationsTabItem method draw.
public Widget draw() {
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// CALLBACK
final Map<String, Object> ids = new HashMap<String, Object>();
ids.put("authors", 1);
ids.put("yearSince", JsonUtils.getCurrentYear());
final FindPublicationsByGUIFilter callback = new FindPublicationsByGUIFilter(ids);
// menus
TabMenu menu = new TabMenu();
final HTML userHtml = new HTML("<strong>User:</strong>");
userHtml.setVisible(false);
final ListBoxWithObjects<Author> users = new ListBoxWithObjects<Author>();
users.setVisible(false);
final TabMenu filterMenu = new TabMenu();
filterMenu.setVisible(false);
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Create new publication", new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTab(new AddPublicationsTabItem(session.getUser()));
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove selected publication(s)");
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<Publication> list = callback.getTableSelectedList();
String text = "Following publications will be removed.";
UiElements.showDeleteConfirm(list, text, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO - should have only one callback to core
for (int i = 0; i < list.size(); i++) {
if (i == list.size() - 1) {
DeletePublication request = new DeletePublication(JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(callback)));
request.deletePublication(list.get(i).getId());
} else {
DeletePublication request = new DeletePublication(JsonCallbackEvents.disableButtonEvents(removeButton));
request.deletePublication(list.get(i).getId());
}
}
}
});
}
});
menu.addWidget(removeButton);
// fill users listbox
final FindAllAuthors userCall = new FindAllAuthors(new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
users.removeNotSelectedOption();
users.clear();
users.addNotSelectedOption();
ArrayList<Author> list = JsonUtils.jsoAsList(jso.cast());
list = new TableSorter<Author>().sortByName(list);
for (int i = 0; i < list.size(); i++) {
users.addItem(list.get(i));
if (lastUserId != 0) {
if (lastUserId == list.get(i).getId()) {
users.setSelected(list.get(i), true);
}
}
}
if (lastUserId == 0) {
users.setSelectedIndex(0);
}
}
public void onError(PerunError error) {
users.clear();
users.removeNotSelectedOption();
users.addItem("Error while loading");
}
public void onLoadingStart() {
users.clear();
users.removeNotSelectedOption();
users.addItem("Loading...");
}
});
// fill category listbox
final ListBoxWithObjects<Category> filterCategory = new ListBoxWithObjects<Category>();
final GetCategories call = new GetCategories(new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
filterCategory.removeNotSelectedOption();
filterCategory.clear();
filterCategory.addNotSelectedOption();
ArrayList<Category> list = JsonUtils.jsoAsList(jso.cast());
list = new TableSorter<Category>().sortByName(list);
for (int i = 0; i < list.size(); i++) {
filterCategory.addItem(list.get(i));
// set last selected
if (lastCategoryId != 0) {
if (list.get(i).getId() == lastCategoryId) {
filterCategory.setSelected(list.get(i), true);
}
}
}
if (lastCategoryId == 0) {
filterCategory.setSelectedIndex(0);
}
}
public void onError(PerunError error) {
filterCategory.clear();
filterCategory.removeNotSelectedOption();
filterCategory.addItem("Error while loading");
}
public void onLoadingStart() {
filterCategory.clear();
filterCategory.removeNotSelectedOption();
filterCategory.addItem("Loading...");
}
});
// switch lock state button
final CustomButton lock = new CustomButton("Lock", "Lock selected publications", SmallIcons.INSTANCE.lockIcon());
lock.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Publication> list = callback.getTableSelectedList();
if (list != null && !list.isEmpty()) {
LockUnlockPublications request = new LockUnlockPublications(JsonCallbackEvents.disableButtonEvents(lock, JsonCallbackEvents.refreshTableEvents(callback)));
request.lockUnlockPublications(true, list);
}
}
});
// switch lock state button
final CustomButton unlock = new CustomButton("Unlock", "Unlock selected publications", SmallIcons.INSTANCE.lockOpenIcon());
unlock.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Publication> list = callback.getTableSelectedList();
if (list != null && !list.isEmpty()) {
LockUnlockPublications request = new LockUnlockPublications(JsonCallbackEvents.disableButtonEvents(unlock, JsonCallbackEvents.refreshTableEvents(callback)));
request.lockUnlockPublications(false, list);
}
}
});
menu.addWidget(lock);
menu.addWidget(unlock);
CustomButton filter = new CustomButton("Show / Hide filter", SmallIcons.INSTANCE.filterIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
if (filterMenu.isVisible() == false) {
filterMenu.setVisible(true);
userHtml.setVisible(true);
users.setVisible(true);
if (users.isEmpty()) {
userCall.retrieveData();
}
if (filterCategory.isEmpty()) {
call.retrieveData();
}
} else {
filterMenu.setVisible(false);
userHtml.setVisible(false);
users.setVisible(false);
}
}
});
menu.addWidget(filter);
// filter objects
final TextBox filterTitle = new TextBox();
filterTitle.setWidth("80px");
filterTitle.setText(lastTitle);
final TextBox filterYear = new TextBox();
filterYear.setMaxLength(4);
filterYear.setWidth("30px");
filterYear.setText(lastYear);
final TextBox filterIsbn = new TextBox();
filterIsbn.setWidth("60px");
filterIsbn.setText(lastIsbnOrDoiValue);
final TextBox filterSince = new TextBox();
filterSince.setMaxLength(4);
filterSince.setWidth("30px");
filterSince.setText(lastYearSince);
final TextBox filterTill = new TextBox();
filterTill.setMaxLength(4);
filterTill.setWidth("30px");
filterTill.setText(lastYearTill);
final ListBox codeBox = new ListBox();
codeBox.addItem("ISBN/ISSN:");
codeBox.addItem("DOI:");
if (!lastIsbnOrDoi) {
codeBox.setSelectedIndex(1);
}
// add users filter in upper menu
menu.addWidget(userHtml);
menu.addWidget(users);
// buttons
CustomButton applyFilter = new CustomButton("Apply", "Show publications based on filter", SmallIcons.INSTANCE.filterAddIcon());
CustomButton clearFilter = new CustomButton("Clear", "Show all publications", SmallIcons.INSTANCE.filterDeleteIcon());
clearFilter.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// clear last values
lastCategoryId = 0;
lastIsbnOrDoi = true;
lastIsbnOrDoiValue = "";
lastTitle = "";
lastUserId = 0;
lastYear = "";
lastYearTill = "";
lastYearSince = "";
// clear form
filterTitle.setText("");
filterYear.setText("");
filterIsbn.setText("");
filterSince.setText("");
filterTill.setText("");
filterCategory.setSelectedIndex(0);
users.setSelectedIndex(0);
ids.clear();
ids.put("authors", 1);
lastIds = ids;
callback.setIds(ids);
callback.clearTable();
callback.retrieveData();
}
});
applyFilter.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// refresh ids
ids.clear();
if (users.getSelectedIndex() > 0) {
ids.put("userId", users.getSelectedObject().getId());
lastUserId = users.getSelectedObject().getId();
} else {
ids.put("userId", 0);
lastUserId = 0;
}
ids.put("authors", 1);
// checks input
if (!filterTitle.getText().isEmpty()) {
ids.put("title", filterTitle.getText());
lastTitle = filterTitle.getText();
} else {
lastTitle = "";
}
if (!filterYear.getText().isEmpty()) {
if (!JsonUtils.checkParseInt(filterYear.getText())) {
JsonUtils.cantParseIntConfirm("YEAR", filterYear.getText());
lastYear = "";
return;
} else {
ids.put("year", filterYear.getText());
lastYear = filterYear.getText();
}
}
if (!filterIsbn.getText().isEmpty()) {
if (codeBox.getSelectedIndex() == 0) {
// ISBN/ISSN selected
lastIsbnOrDoi = true;
ids.put("isbn", filterIsbn.getText());
} else {
// DOI selected
lastIsbnOrDoi = false;
ids.put("doi", filterIsbn.getText());
}
lastIsbnOrDoiValue = filterIsbn.getText();
}
if (!filterSince.getText().isEmpty()) {
if (!JsonUtils.checkParseInt(filterSince.getText())) {
JsonUtils.cantParseIntConfirm("YEAR SINCE", filterSince.getText());
lastYearSince = "";
return;
} else {
ids.put("yearSince", filterSince.getText());
lastYearSince = filterSince.getText();
}
}
if (!filterTill.getText().isEmpty()) {
if (!JsonUtils.checkParseInt(filterTill.getText())) {
JsonUtils.cantParseIntConfirm("YEAR TILL", filterTill.getText());
lastYearTill = "";
return;
} else {
ids.put("yearTill", filterTill.getText());
lastYearTill = filterTill.getText();
}
}
if (filterCategory.getSelectedIndex() > 0) {
ids.put("category", filterCategory.getSelectedObject().getId());
lastCategoryId = filterCategory.getSelectedObject().getId();
} else {
lastCategoryId = 0;
}
lastIds = ids;
callback.setIds(ids);
callback.clearTable();
callback.retrieveData();
}
});
// add to filter menu
filterMenu.addWidget(new HTML("<strong>Title:</strong>"));
filterMenu.addWidget(filterTitle);
filterMenu.addWidget(codeBox);
filterMenu.addWidget(filterIsbn);
filterMenu.addWidget(new HTML("<strong>Category:</strong>"));
filterMenu.addWidget(filterCategory);
filterMenu.addWidget(new HTML("<strong>Year:</strong>"));
filterMenu.addWidget(filterYear);
filterMenu.addWidget(new HTML("<strong>Year between:</strong>"));
filterMenu.addWidget(filterSince);
filterMenu.addWidget(new HTML(" / "));
filterMenu.addWidget(filterTill);
filterMenu.addWidget(applyFilter);
filterMenu.addWidget(clearFilter);
vp.add(menu);
vp.setCellHeight(menu, "50px");
vp.add(filterMenu);
if (!lastIds.isEmpty()) {
callback.setIds(lastIds);
}
CellTable<Publication> table = callback.getTable(new FieldUpdater<Publication, String>() {
public void update(int index, Publication object, String value) {
session.getTabManager().addTab(new PublicationDetailTabItem(object));
}
});
removeButton.setEnabled(false);
lock.setEnabled(false);
unlock.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, removeButton);
JsonUtils.addTableManagedButton(callback, table, lock);
JsonUtils.addTableManagedButton(callback, table, unlock);
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel();
sp.add(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
// resize perun table to correct size on screen
session.getUiElements().resizeSmallTabPanel(sp, 350, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations