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