1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.notifications;
20
21 import org.apache.syncope.client.console.SyncopeConsoleSession;
22 import org.apache.syncope.client.console.pages.BasePage;
23 import org.apache.syncope.client.console.panels.AbstractModalPanel;
24 import org.apache.syncope.client.console.rest.NotificationRestClient;
25 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
26 import org.apache.syncope.client.ui.commons.Constants;
27 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
28 import org.apache.syncope.common.lib.SyncopeClientException;
29 import org.apache.syncope.common.lib.to.MailTemplateTO;
30 import org.apache.wicket.PageReference;
31 import org.apache.wicket.ajax.AjaxRequestTarget;
32 import org.apache.wicket.model.PropertyModel;
33
34 public class TemplateModal extends AbstractModalPanel<MailTemplateTO> {
35
36 private static final long serialVersionUID = 2053048734388383021L;
37
38 private final MailTemplateTO templateTO;
39
40 private final NotificationRestClient restClient;
41
42 public TemplateModal(
43 final BaseModal<MailTemplateTO> modal,
44 final NotificationRestClient restClient,
45 final MailTemplateTO templateTO,
46 final PageReference pageRef) {
47
48 super(modal, pageRef);
49 this.restClient = restClient;
50 this.templateTO = templateTO;
51
52 AjaxTextFieldPanel key = new AjaxTextFieldPanel(
53 Constants.KEY_FIELD_NAME,
54 Constants.KEY_FIELD_NAME,
55 new PropertyModel<>(templateTO, Constants.KEY_FIELD_NAME), false);
56 key.setOutputMarkupPlaceholderTag(true);
57 add(key.setRenderBodyOnly(true));
58 }
59
60 @Override
61 public MailTemplateTO getItem() {
62 return this.templateTO;
63 }
64
65 @Override
66 public void onSubmit(final AjaxRequestTarget target) {
67 try {
68 restClient.createTemplate(templateTO);
69 SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
70 modal.close(target);
71 } catch (SyncopeClientException e) {
72 LOG.error("While creating template for {}", templateTO.getKey(), e);
73 SyncopeConsoleSession.get().onException(e);
74 }
75 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
76 }
77 }