use of cz.metacentrum.perun.webgui.model.Thanks in project perun by CESNET.
the class PublicationDetailTabItem method loadThanksSubTab.
/**
* Returns thanks management widget for publication
*
* @return widget
*/
private Widget loadThanksSubTab() {
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.smallBusinessIcon()));
header.setHTML(0, 1, "<h3>Acknowledgement</h3>");
dp.setHeader(header);
// menu
TabMenu menu = new TabMenu();
// callback
final GetRichThanksByPublicationId thanksCall = new GetRichThanksByPublicationId(publicationId);
thanksCall.setCheckable(false);
if (!publication.getLocked()) {
// editable if not locked
vp.add(menu);
vp.setCellHeight(menu, "30px");
thanksCall.setCheckable(true);
}
CellTable<Thanks> table = thanksCall.getTable();
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, "Add acknowledgement to publication", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateThanksTabItem(publication, JsonCallbackEvents.refreshTableEvents(thanksCall)), true);
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove acknowledgement from publication");
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(thanksCall, table, removeButton);
menu.addWidget(removeButton);
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Thanks> list = thanksCall.getTableSelectedList();
String text = "Following acknowledgements will be removed from publication.";
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) {
DeleteThanks request = new DeleteThanks(JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(thanksCall)));
request.deleteThanks(list.get(i).getId());
} else {
DeleteThanks request = new DeleteThanks(JsonCallbackEvents.disableButtonEvents(removeButton));
request.deleteThanks(list.get(i).getId());
}
}
}
});
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel();
sp.add(table);
sp.addStyleName("perun-tableScrollPanel");
vp.add(sp);
return dp;
}
use of cz.metacentrum.perun.webgui.model.Thanks in project perun by CESNET.
the class CreateThanks method createThanks.
/**
* Attempts to create a Thanks, it first tests the values and then submits them.
*
* @param ownerId owner to thank to
*/
public void createThanks(final int ownerId) {
this.ownerId = ownerId;
// test arguments
if (!this.testCreating()) {
return;
}
// json object
JSONObject jsonQuery = prepareJSONObject();
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Creating acknowledgement failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
Thanks thks = jso.cast();
session.getUiElements().setLogSuccessText("Acknowledgement : " + thks.getId() + " created.");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
Aggregations