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