1
14
15 package com.liferay.portlet.calendar.action;
16
17 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18 import com.liferay.portal.kernel.servlet.SessionErrors;
19 import com.liferay.portal.kernel.servlet.SessionMessages;
20 import com.liferay.portal.kernel.util.Constants;
21 import com.liferay.portal.kernel.util.ParamUtil;
22 import com.liferay.portal.kernel.util.Validator;
23 import com.liferay.portlet.PortletPreferencesFactoryUtil;
24
25 import javax.portlet.ActionRequest;
26 import javax.portlet.ActionResponse;
27 import javax.portlet.PortletConfig;
28 import javax.portlet.PortletPreferences;
29 import javax.portlet.RenderRequest;
30 import javax.portlet.RenderResponse;
31
32
38 public class ConfigurationActionImpl extends BaseConfigurationAction {
39
40 public void processAction(
41 PortletConfig portletConfig, ActionRequest actionRequest,
42 ActionResponse actionResponse)
43 throws Exception {
44
45 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
46
47 if (!cmd.equals(Constants.UPDATE)) {
48 return;
49 }
50
51 String portletResource = ParamUtil.getString(
52 actionRequest, "portletResource");
53
54 PortletPreferences preferences =
55 PortletPreferencesFactoryUtil.getPortletSetup(
56 actionRequest, portletResource);
57
58 String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
59
60 if (tabs2.equals("display-settings")) {
61 updateDisplaySettings(actionRequest, preferences);
62 }
63 else if (tabs2.equals("email-from")) {
64 updateEmailFrom(actionRequest, preferences);
65 }
66 else if (tabs2.equals("event-reminder-email")) {
67 updateEmailEventReminder(actionRequest, preferences);
68 }
69
70 if (SessionErrors.isEmpty(actionRequest)) {
71 preferences.store();
72
73 SessionMessages.add(
74 actionRequest, portletConfig.getPortletName() + ".doConfigure");
75 }
76 }
77
78 public String render(
79 PortletConfig portletConfig, RenderRequest renderRequest,
80 RenderResponse renderResponse)
81 throws Exception {
82
83 return "/html/portlet/calendar/configuration.jsp";
84 }
85
86 protected void updateDisplaySettings(
87 ActionRequest actionRequest, PortletPreferences preferences)
88 throws Exception {
89
90 String tabs1Default = ParamUtil.getString(
91 actionRequest, "tabs1Default");
92 String summaryTabOrientation = ParamUtil.getString(
93 actionRequest, "summaryTabOrientation");
94 String summaryTabShowMiniMonth = ParamUtil.getString(
95 actionRequest, "summaryTabShowMiniMonth");
96 String summaryTabShowTodaysEvents = ParamUtil.getString(
97 actionRequest, "summaryTabShowTodaysEvents");
98 boolean enableComments = ParamUtil.getBoolean(
99 actionRequest, "enableComments");
100
101 preferences.setValue("tabs1-default", tabs1Default);
102 preferences.setValue("summary-tab-orientation", summaryTabOrientation);
103 preferences.setValue(
104 "summary-tab-show-mini-month", summaryTabShowMiniMonth);
105 preferences.setValue(
106 "summary-tab-show-todays-events", summaryTabShowTodaysEvents);
107 preferences.setValue("enable-comments", String.valueOf(enableComments));
108 }
109
110 protected void updateEmailFrom(
111 ActionRequest actionRequest, PortletPreferences preferences)
112 throws Exception {
113
114 String emailFromName = ParamUtil.getString(
115 actionRequest, "emailFromName");
116 String emailFromAddress = ParamUtil.getString(
117 actionRequest, "emailFromAddress");
118
119 if (Validator.isNull(emailFromName)) {
120 SessionErrors.add(actionRequest, "emailFromName");
121 }
122 else if (!Validator.isEmailAddress(emailFromAddress)) {
123 SessionErrors.add(actionRequest, "emailFromAddress");
124 }
125 else {
126 preferences.setValue("email-from-name", emailFromName);
127 preferences.setValue("email-from-address", emailFromAddress);
128 }
129 }
130
131 protected void updateEmailEventReminder(
132 ActionRequest actionRequest, PortletPreferences preferences)
133 throws Exception {
134
135 boolean emailEventReminderEnabled = ParamUtil.getBoolean(
136 actionRequest, "emailEventReminderEnabled");
137 String emailEventReminderSubject = ParamUtil.getString(
138 actionRequest, "emailEventReminderSubject");
139 String emailEventReminderBody = ParamUtil.getString(
140 actionRequest, "emailEventReminderBody");
141
142 if (Validator.isNull(emailEventReminderSubject)) {
143 SessionErrors.add(actionRequest, "emailEventReminderSubject");
144 }
145 else if (Validator.isNull(emailEventReminderBody)) {
146 SessionErrors.add(actionRequest, "emailEventReminderBody");
147 }
148 else {
149 preferences.setValue(
150 "email-event-reminder-enabled",
151 String.valueOf(emailEventReminderEnabled));
152 preferences.setValue(
153 "email-event-reminder-subject", emailEventReminderSubject);
154 preferences.setValue(
155 "email-event-reminder-body", emailEventReminderBody);
156 }
157 }
158
159 }