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.panels;
20
21 import java.io.Serializable;
22 import java.util.Date;
23 import org.apache.commons.lang3.time.FastDateFormat;
24 import org.apache.syncope.client.console.SyncopeConsoleSession;
25 import org.apache.syncope.client.console.pages.BasePage;
26 import org.apache.syncope.client.console.rest.ExecutionRestClient;
27 import org.apache.syncope.client.ui.commons.Constants;
28 import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
29 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel;
30 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDateTimeFieldPanel;
31 import org.apache.syncope.common.lib.SyncopeClientException;
32 import org.apache.syncope.common.lib.SyncopeConstants;
33 import org.apache.wicket.PageReference;
34 import org.apache.wicket.ajax.AjaxRequestTarget;
35 import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
36 import org.apache.wicket.markup.html.WebMarkupContainer;
37 import org.apache.wicket.markup.html.form.Form;
38 import org.apache.wicket.model.Model;
39
40 public abstract class StartAtTogglePanel extends TogglePanel<Serializable> {
41
42 private static final long serialVersionUID = -3195479265440591519L;
43
44 protected String key;
45
46 protected final Form<?> form;
47
48 protected final Model<Date> startAtDateModel = new Model<>();
49
50 public StartAtTogglePanel(final WebMarkupContainer container, final PageReference pageRef) {
51 super("startAt", pageRef);
52
53 form = new Form<>("startAtForm");
54 addInnerObject(form);
55
56 AjaxDateTimeFieldPanel startAtDate = new AjaxDateTimeFieldPanel(
57 "startAtDate", "startAtDate", startAtDateModel,
58 FastDateFormat.getInstance(SyncopeConstants.DATE_PATTERNS[3]));
59 form.add(startAtDate.setReadOnly(true).hideLabel());
60
61 AjaxCheckBoxPanel startAtCheck = new AjaxCheckBoxPanel(
62 "startAtCheck", "startAtCheck", new Model<>(false), false);
63 startAtCheck.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
64
65 private static final long serialVersionUID = -1107858522700306810L;
66
67 @Override
68 protected void onUpdate(final AjaxRequestTarget target) {
69 target.add(startAtDate.setModelObject(null).setReadOnly(!startAtCheck.getModelObject()));
70 }
71 });
72 form.add(startAtCheck);
73
74 form.add(new AjaxSubmitLink("startAt", form) {
75
76 private static final long serialVersionUID = -7978723352517770644L;
77
78 @Override
79 protected void onSubmit(final AjaxRequestTarget target) {
80 try {
81 getRestClient().startExecution(key, startAtDateModel.getObject());
82 SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
83 toggle(target, false);
84 target.add(container);
85 } catch (SyncopeClientException e) {
86 LOG.error("While running task {}", key, e);
87 SyncopeConsoleSession.get().onException(e);
88 }
89 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
90 }
91
92 @Override
93 protected void onError(final AjaxRequestTarget target) {
94 ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
95 }
96 });
97 }
98
99 public void setExecutionDetail(final String key, final String header, final AjaxRequestTarget target) {
100 this.key = key;
101 setHeader(target, header);
102 }
103
104 protected abstract ExecutionRestClient getRestClient();
105 }