Search in sources :

Example 61 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class AddServiceToServicesPackage method prepareJSONObject.

/**
	 * Prepares a JSON object
	 *
	 * @return JSONObject the whole query
	 */
private JSONObject prepareJSONObject() {
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("service", new JSONNumber(serviceId));
    jsonQuery.put("servicesPackage", new JSONNumber(packageId));
    return jsonQuery;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) JSONNumber(com.google.gwt.json.client.JSONNumber)

Example 62 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class EditFormItemTabItem method itemTextTab.

/**
	 * Returns flex table with settings for the language
	 *
	 * @param locale
	 * @return
	 */
private Widget itemTextTab(String locale) {
    ItemTexts itemTexts = item.getItemTexts(locale);
    if (itemTexts == null) {
        // create empty item texts
        JSONObject itemTextJson = new JSONObject();
        itemTextJson.put("label", new JSONString(""));
        itemTextJson.put("help", new JSONString(""));
        itemTextJson.put("errorMessage", new JSONString(""));
        itemTextJson.put("options", new JSONString(""));
    }
    item.setItemTexts(locale, itemTexts);
    TextArea labelTextBox = new TextArea();
    labelTextBoxes.put(locale, labelTextBox);
    TextArea helpTextBox = new TextArea();
    helpTextBoxes.put(locale, helpTextBox);
    TextArea errorTextBox = new TextArea();
    errorTextBoxes.put(locale, errorTextBox);
    // layout
    final FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    ft.setSize("550px", "100%");
    final FlexCellFormatter ftf = ft.getFlexCellFormatter();
    // sizes
    labelTextBox.setWidth("440px");
    helpTextBox.setWidth("440px");
    errorTextBox.setWidth("440px");
    // fill values
    labelTextBox.setText(itemTexts.getLabel());
    helpTextBox.setText(itemTexts.getHelp());
    errorTextBox.setText(itemTexts.getErrorMessage());
    // adding to table
    int row = 0;
    if ("HTML_COMMENT".equals(item.getType()) || "HEADING".equals(item.getType())) {
        Label label = new Label("Content:");
        ft.setWidget(row, 0, label);
        ft.setWidget(row, 1, labelTextBox);
        row++;
        ft.setHTML(row, 1, "HTML formatted content of form item. It spans through all columns to full form width.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        row++;
    } else if ("SUBMIT_BUTTON".equals(item.getType()) || "AUTO_SUBMIT_BUTTON".equals(item.getType())) {
        Label label = new Label("Label:");
        ft.setWidget(row, 0, label);
        ft.setWidget(row, 1, labelTextBox);
        row++;
        ft.setHTML(row, 1, "Label displayed on submit button.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        row++;
    } else {
        Label label = new Label("Label:");
        ft.setWidget(row, 0, label);
        ft.setWidget(row, 1, labelTextBox);
        row++;
        ft.setHTML(row, 1, "Label displayed to users to identify item on application form. If empty, \"Short name\" from basic settings is used as fallback.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        row++;
        Label helpLabel = new Label("Help:");
        ft.setWidget(row, 0, helpLabel);
        ft.setWidget(row, 1, helpTextBox);
        row++;
        ft.setHTML(row, 1, "Help text displayed to user along with input widget.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        row++;
        Label errorLabel = new Label("Error:");
        ft.setWidget(row, 0, errorLabel);
        ft.setWidget(row, 1, errorTextBox);
        row++;
        ft.setHTML(row, 1, "Error message displayed to user when enters wrong value.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
    }
    // style
    for (int i = 0; i < ft.getRowCount(); i++) {
        ftf.setStyleName(i, 0, "itemName");
    }
    // box items table
    final FlexTable boxItemTable = new FlexTable();
    boxItemTable.setStyleName("inputFormFlexTable");
    boxItemTable.setWidth("550px");
    // final layout
    VerticalPanel vp = new VerticalPanel();
    vp.add(ft);
    // values for selection and combobox
    if (Arrays.asList("SELECTIONBOX", "COMBOBOX", "CHECKBOX", "RADIO").contains(item.getType())) {
        final Map<String, String> values = new HashMap<String, String>();
        // parse values from the item
        String options = itemTexts.getOptions();
        if (options != null) {
            // for each value, add key-value
            values.putAll(RegistrarFormItemGenerator.parseSelectionBox(options));
        }
        buildItemsTable(boxItemTable, values, locale);
        vp.add(boxItemTable);
    }
    vp.addStyleName("perun-table");
    // scroll panel
    ScrollPanel sp = new ScrollPanel(vp);
    sp.addStyleName("perun-tableScrollPanel");
    sp.setSize("560px", "100%");
    return sp;
}
Also used : HashMap(java.util.HashMap) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) JSONString(com.google.gwt.json.client.JSONString) JSONObject(com.google.gwt.json.client.JSONObject) JSONString(com.google.gwt.json.client.JSONString)

Example 63 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class EditFormItemTabItem method saveItem.

/**
	 * Saves the values back to the item
	 */
protected void saveItem() {
    // TODO set only when actual change happens
    item.setEdited(true);
    // shortName is required item !!
    if (shortNameTextBox.getText() == null || (shortNameTextBox.getText().isEmpty())) {
        UiElements.generateAlert("Empty shortName", "'shortName' is required parameter and can't be empty !");
        return;
    }
    item.setFederationAttribute(federationAttributes.getValue(federationAttributes.getSelectedIndex()));
    if (perunDestinationAttributeListBox.getSelectedIndex() > 0) {
        // some value set
        item.setPerunDestinationAttribute(perunDestinationAttributeListBox.getValue(perunDestinationAttributeListBox.getSelectedIndex()));
    } else {
        // empty value set
        item.setPerunDestinationAttribute(null);
    }
    item.setRegex(regexTextBox.getText().trim());
    item.setRequired(requiredCheckBox.getValue());
    item.setShortname(shortNameTextBox.getText().trim());
    JSONArray newApplicationTypesJson = new JSONArray();
    int pointer = 0;
    int i = 0;
    for (Application.ApplicationType type : Application.ApplicationType.values()) {
        CheckBox cb = applicationTypesCheckBoxes.get(i);
        if (cb.getValue()) {
            newApplicationTypesJson.set(pointer, new JSONString(type.toString()));
            pointer++;
        }
        i++;
    }
    item.setApplicationTypes(newApplicationTypesJson.getJavaScriptObject());
    /* LANGUAGE */
    // item texts
    Map<String, ItemTexts> itemTextsMap = new HashMap<String, ItemTexts>();
    // help
    for (Map.Entry<String, TextArea> entry : helpTextBoxes.entrySet()) {
        String locale = entry.getKey();
        ItemTexts itemTexts;
        // if already
        if (itemTextsMap.containsKey(locale)) {
            itemTexts = itemTextsMap.get(locale);
        } else {
            itemTexts = new JSONObject().getJavaScriptObject().cast();
        }
        // set help
        itemTexts.setHelp(entry.getValue().getValue().trim());
        // update
        itemTextsMap.put(locale, itemTexts);
    }
    // label
    for (Map.Entry<String, TextArea> entry : labelTextBoxes.entrySet()) {
        String locale = entry.getKey();
        ItemTexts itemTexts;
        // if already
        if (itemTextsMap.containsKey(locale)) {
            itemTexts = itemTextsMap.get(locale);
        } else {
            itemTexts = new JSONObject().getJavaScriptObject().cast();
        }
        // set help
        itemTexts.setLabel(entry.getValue().getValue().trim());
        // update
        itemTextsMap.put(locale, itemTexts);
    }
    // error
    for (Map.Entry<String, TextArea> entry : errorTextBoxes.entrySet()) {
        String locale = entry.getKey();
        ItemTexts itemTexts;
        // if already
        if (itemTextsMap.containsKey(locale)) {
            itemTexts = itemTextsMap.get(locale);
        } else {
            itemTexts = new JSONObject().getJavaScriptObject().cast();
        }
        // set help
        itemTexts.setErrorMessage(entry.getValue().getValue().trim());
        // update
        itemTextsMap.put(locale, itemTexts);
    }
    // OPTIONS
    for (Map.Entry<String, Map<TextBox, TextBox>> localeTextboxes : optionsBoxes.entrySet()) {
        String locale = localeTextboxes.getKey();
        Map<String, String> keyValue = new HashMap<String, String>();
        // iterate over textboxes
        for (Map.Entry<TextBox, TextBox> textBoxes : localeTextboxes.getValue().entrySet()) {
            String key = textBoxes.getKey().getText();
            String value = textBoxes.getValue().getText();
            if (!key.equals("") && !value.equals("")) {
                keyValue.put(key.trim(), value.trim());
            }
        }
        // serialize key-value
        String options = RegistrarFormItemGenerator.serializeSelectionBox(keyValue);
        ItemTexts itemTexts;
        // if already
        if (itemTextsMap.containsKey(locale)) {
            itemTexts = itemTextsMap.get(locale);
        } else {
            itemTexts = new JSONObject().getJavaScriptObject().cast();
        }
        // set options
        itemTexts.setOptions(options);
        // update
        itemTextsMap.put(locale, itemTexts);
    }
    // FOR EACH ITEM TEXT, save it
    for (Map.Entry<String, ItemTexts> entry : itemTextsMap.entrySet()) {
        String locale = entry.getKey();
        ItemTexts itemTexts = entry.getValue();
        session.getUiElements().setLogText(itemTexts.toSource());
        // save it
        this.item.setItemTexts(locale, itemTexts);
    }
}
Also used : HashMap(java.util.HashMap) JSONArray(com.google.gwt.json.client.JSONArray) JSONString(com.google.gwt.json.client.JSONString) JSONObject(com.google.gwt.json.client.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) JSONString(com.google.gwt.json.client.JSONString)

Example 64 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class UpdatePublication method prepareJSONObject.

/**
	 * Prepares a JSON object
	 * @return JSONObject the whole query
	 */
private JSONObject prepareJSONObject() {
    // publication
    JSONObject oldPub = new JSONObject(publication);
    // reconstruct object
    JSONObject newPub = new JSONObject();
    newPub.put("id", oldPub.get("id"));
    newPub.put("year", oldPub.get("year"));
    newPub.put("categoryId", oldPub.get("categoryId"));
    newPub.put("externalId", oldPub.get("externalId"));
    newPub.put("isbn", oldPub.get("isbn"));
    newPub.put("main", oldPub.get("main"));
    newPub.put("publicationSystemId", oldPub.get("publicationSystemId"));
    newPub.put("title", oldPub.get("title"));
    newPub.put("createdBy", oldPub.get("createdBy"));
    newPub.put("createdDate", oldPub.get("createdDate"));
    newPub.put("rank", oldPub.get("rank"));
    newPub.put("doi", oldPub.get("doi"));
    newPub.put("locked", oldPub.get("locked"));
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("publication", newPub);
    return jsonQuery;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject)

Example 65 with JSONObject

use of com.google.gwt.json.client.JSONObject in project perun by CESNET.

the class UpdatePublication method updatePublication.

/**
	 * Attempts to update a Publication, it first tests the values and then submits them.
	 *
	 * @param publication Publication
	 */
public void updatePublication(final Publication publication) {
    this.publication = publication;
    // 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("Updating publication: " + publication.getId() + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            Publication pub = jso.cast();
            session.getUiElements().setLogSuccessText("Publication with ID: " + pub.getId() + " updated.");
            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) Publication(cz.metacentrum.perun.webgui.model.Publication) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

JSONObject (com.google.gwt.json.client.JSONObject)227 JSONNumber (com.google.gwt.json.client.JSONNumber)109 JSONString (com.google.gwt.json.client.JSONString)74 JSONArray (com.google.gwt.json.client.JSONArray)62 PerunError (cz.metacentrum.perun.webgui.model.PerunError)55 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)54 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)54 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)50 JSONValue (com.google.gwt.json.client.JSONValue)13 HashMap (java.util.HashMap)12 Map (java.util.Map)8 ArrayList (java.util.ArrayList)6 JsArrayString (com.google.gwt.core.client.JsArrayString)3 User (cz.metacentrum.perun.webgui.model.User)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Command (com.google.gwt.user.client.Command)2 Contact (com.googlecode.gwtphonegap.client.contacts.Contact)2 ContactField (com.googlecode.gwtphonegap.client.contacts.ContactField)2 StringCallback (com.gwtmobile.phonegap.client.plugins.Bluetooth.StringCallback)2