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