Search in sources :

Example 1 with Thanks

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;
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Thanks(cz.metacentrum.perun.webgui.model.Thanks) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 2 with Thanks

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);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) Thanks(cz.metacentrum.perun.webgui.model.Thanks) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

Thanks (cz.metacentrum.perun.webgui.model.Thanks)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 JSONObject (com.google.gwt.json.client.JSONObject)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1