View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }