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
99 preferences.setValue("tabs1-default", tabs1Default);
100 preferences.setValue("summary-tab-orientation", summaryTabOrientation);
101 preferences.setValue(
102 "summary-tab-show-mini-month", summaryTabShowMiniMonth);
103 preferences.setValue(
104 "summary-tab-show-todays-events", summaryTabShowTodaysEvents);
105 }
106
107 protected void updateEmailFrom(
108 ActionRequest actionRequest, PortletPreferences preferences)
109 throws Exception {
110
111 String emailFromName = ParamUtil.getString(
112 actionRequest, "emailFromName");
113 String emailFromAddress = ParamUtil.getString(
114 actionRequest, "emailFromAddress");
115
116 if (Validator.isNull(emailFromName)) {
117 SessionErrors.add(actionRequest, "emailFromName");
118 }
119 else if (!Validator.isEmailAddress(emailFromAddress)) {
120 SessionErrors.add(actionRequest, "emailFromAddress");
121 }
122 else {
123 preferences.setValue("email-from-name", emailFromName);
124 preferences.setValue("email-from-address", emailFromAddress);
125 }
126 }
127
128 protected void updateEmailEventReminder(
129 ActionRequest actionRequest, PortletPreferences preferences)
130 throws Exception {
131
132 boolean emailEventReminderEnabled = ParamUtil.getBoolean(
133 actionRequest, "emailEventReminderEnabled");
134 String emailEventReminderSubject = ParamUtil.getString(
135 actionRequest, "emailEventReminderSubject");
136 String emailEventReminderBody = ParamUtil.getString(
137 actionRequest, "emailEventReminderBody");
138
139 if (Validator.isNull(emailEventReminderSubject)) {
140 SessionErrors.add(actionRequest, "emailEventReminderSubject");
141 }
142 else if (Validator.isNull(emailEventReminderBody)) {
143 SessionErrors.add(actionRequest, "emailEventReminderBody");
144 }
145 else {
146 preferences.setValue(
147 "email-event-reminder-enabled",
148 String.valueOf(emailEventReminderEnabled));
149 preferences.setValue(
150 "email-event-reminder-subject", emailEventReminderSubject);
151 preferences.setValue(
152 "email-event-reminder-body", emailEventReminderBody);
153 }
154 }
155
156 }