Search in sources :

Example 1 with MailText

use of cz.metacentrum.perun.webgui.model.MailText in project perun by CESNET.

the class SetSendingEnabled method prepareJSONObject.

/**
	 * Prepares a JSON object.
	 * @return JSONObject - the whole query
	 */
private JSONObject prepareJSONObject() {
    JSONArray mails = new JSONArray();
    int i = 0;
    for (ApplicationMail appMail : appMails) {
        JSONObject mail = new JSONObject();
        // update send
        mail.put("send", JSONBoolean.getInstance(appMail.isSend()));
        JSONObject mailTexts = new JSONObject();
        // update texts
        MailText mt = appMail.getMessage("en");
        mailTexts.put("en", new JSONObject(mt));
        if (!Utils.getNativeLanguage().isEmpty()) {
            MailText mt2 = appMail.getMessage(Utils.getNativeLanguage().get(0));
            mailTexts.put(Utils.getNativeLanguage().get(0), new JSONObject(mt2));
        }
        mail.put("message", mailTexts);
        // sending other values just for sure
        mail.put("id", new JSONNumber(appMail.getId()));
        mail.put("appType", new JSONString(appMail.getAppType()));
        mail.put("mailType", new JSONString(appMail.getMailType()));
        mail.put("formId", new JSONNumber(appMail.getFormId()));
        // put in list
        mails.set(i, mail);
        i++;
    }
    JSONObject request = new JSONObject();
    request.put("mails", mails);
    if (enabled == true) {
        request.put("enabled", new JSONNumber(1));
    } else {
        request.put("enabled", new JSONNumber(0));
    }
    return request;
}
Also used : MailText(cz.metacentrum.perun.webgui.model.MailText) ApplicationMail(cz.metacentrum.perun.webgui.model.ApplicationMail)

Example 2 with MailText

use of cz.metacentrum.perun.webgui.model.MailText in project perun by CESNET.

the class EditMailTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Edit notification");
    // languages
    ArrayList<String> languages = appMail.getLocales();
    if (!Utils.getNativeLanguage().isEmpty() && !languages.contains(Utils.getNativeLanguage().get(0))) {
        languages.add(Utils.getNativeLanguage().get(0));
    }
    if (!languages.contains("en"))
        languages.add(0, "en");
    // vertical panel
    VerticalPanel vp = new VerticalPanel();
    vp.setWidth("500px");
    vp.setHeight("350px");
    // tab panel
    tabPanel.addStyleName("smallTabPanel");
    tabPanel.addStyleName("smallTabPanelWithBorder");
    tabPanel.setHeight("350px");
    // basic settings
    tabPanel.add(basicInformationTab(), "Basic settings");
    // for each locale add tab
    for (String locale : languages) {
        tabPanel.add(messageTab(locale), "Lang: " + locale);
    }
    tabPanel.add(availableTagsTab(), "Available tags");
    // add menu
    final TabItem tab = this;
    TabMenu tabMenu = new TabMenu();
    saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveEmailNotificationForApplication(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            // values
            boolean send = sendingEnabledCheckBox.getValue();
            appMail.setSend(send);
            // messages
            for (Map.Entry<String, TextArea> entry : messagesTextAreas.entrySet()) {
                String locale = entry.getKey();
                String subject = messagesSubjects.get(entry.getKey()).getValue();
                String text = entry.getValue().getText();
                MailText mt = MailText.construct(locale, subject, text);
                appMail.setMessage(locale, mt);
            }
            // request
            UpdateApplicationMail req = new UpdateApplicationMail(JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab));
            req.updateMail(appMail);
        }
    });
    tabMenu.addWidget(saveButton);
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    // add tab panel to main panel
    vp.add(tabPanel);
    vp.setCellWidth(tabPanel, "500px");
    vp.setCellHeight(tabPanel, "350px");
    vp.add(tabMenu);
    vp.setCellHeight(tabMenu, "30px");
    vp.setCellHorizontalAlignment(tabMenu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) UpdateApplicationMail(cz.metacentrum.perun.webgui.json.registrarManager.UpdateApplicationMail) MailText(cz.metacentrum.perun.webgui.model.MailText) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with MailText

use of cz.metacentrum.perun.webgui.model.MailText in project perun by CESNET.

the class EditMailTabItem method messageTab.

/**
	 * Returns message texarea
	 *
	 * @param locale
	 * @return
	 */
private Widget messageTab(String locale) {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("500px", "350px");
    vp.setSpacing(10);
    // layout
    FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    FlexCellFormatter ftf = ft.getFlexCellFormatter();
    // inputs
    TextBox tb = new TextBox();
    tb.setWidth("385px");
    messagesSubjects.put(locale, tb);
    TextArea ta = new TextArea();
    ta.setSize("450px", "190px");
    messagesTextAreas.put(locale, ta);
    // adds inputs to the flex table
    ft.setHTML(0, 0, "Subject:");
    ftf.setStyleName(0, 0, "itemName");
    ft.setWidget(0, 1, tb);
    ftf.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT);
    ft.setHTML(1, 0, "Text:");
    ftf.setStyleName(1, 0, "itemName");
    //ftf.setColSpan(1, 0, 2);
    Anchor a = new Anchor("see available tags >>");
    a.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            // select last tab
            tabPanel.selectTab(tabPanel.getWidgetCount() - 1);
        }
    });
    ft.setWidget(1, 1, a);
    ft.setWidget(2, 0, ta);
    ftf.setColSpan(2, 0, 2);
    vp.add(ft);
    vp.add(new HTML("&nbsp;"));
    // fill values
    MailText message = appMail.getMessage(locale);
    if (message != null) {
        ta.setText(message.getText());
        tb.setText(message.getSubject());
    }
    return vp;
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) MailText(cz.metacentrum.perun.webgui.model.MailText)

Example 4 with MailText

use of cz.metacentrum.perun.webgui.model.MailText in project perun by CESNET.

the class UpdateApplicationMail method prepareJSONObject.

/**
	 * Prepares a JSON object.
	 * @return JSONObject - the whole query
	 */
private JSONObject prepareJSONObject() {
    JSONObject mail = new JSONObject();
    // update send
    mail.put("send", JSONBoolean.getInstance(appMail.isSend()));
    JSONObject mailTexts = new JSONObject();
    // update texts
    MailText mt = appMail.getMessage("en");
    mailTexts.put("en", new JSONObject(mt));
    if (!Utils.getNativeLanguage().isEmpty()) {
        MailText mt2 = appMail.getMessage(Utils.getNativeLanguage().get(0));
        mailTexts.put(Utils.getNativeLanguage().get(0), new JSONObject(mt2));
    }
    mail.put("message", mailTexts);
    // sending other values just for sure
    mail.put("id", new JSONNumber(appMail.getId()));
    mail.put("appType", new JSONString(appMail.getAppType()));
    mail.put("mailType", new JSONString(appMail.getMailType()));
    mail.put("formId", new JSONNumber(appMail.getFormId()));
    JSONObject request = new JSONObject();
    request.put("mail", mail);
    return request;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) MailText(cz.metacentrum.perun.webgui.model.MailText) JSONNumber(com.google.gwt.json.client.JSONNumber) JSONString(com.google.gwt.json.client.JSONString)

Aggregations

MailText (cz.metacentrum.perun.webgui.model.MailText)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JSONNumber (com.google.gwt.json.client.JSONNumber)1 JSONObject (com.google.gwt.json.client.JSONObject)1 JSONString (com.google.gwt.json.client.JSONString)1 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)1 UpdateApplicationMail (cz.metacentrum.perun.webgui.json.registrarManager.UpdateApplicationMail)1 ApplicationMail (cz.metacentrum.perun.webgui.model.ApplicationMail)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1