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