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
47 public class ConfigurationActionImpl extends BaseConfigurationAction {
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 prefs =
64 PortletPreferencesFactoryUtil.getPortletSetup(
65 actionRequest, portletResource);
66
67 String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
68
69 if (tabs2.equals("display-settings")) {
70 updateDisplaySettings(actionRequest, prefs);
71 }
72 else if (tabs2.equals("email-from")) {
73 updateEmailFrom(actionRequest, prefs);
74 }
75 else if (tabs2.equals("event-reminder-email")) {
76 updateEmailEventReminder(actionRequest, prefs);
77 }
78
79 if (SessionErrors.isEmpty(actionRequest)) {
80 prefs.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 prefs)
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 prefs.setValue("tabs1-default", tabs1Default);
109 prefs.setValue("summary-tab-orientation", summaryTabOrientation);
110 prefs.setValue("summary-tab-show-mini-month", summaryTabShowMiniMonth);
111 prefs.setValue(
112 "summary-tab-show-todays-events", summaryTabShowTodaysEvents);
113 }
114
115 protected void updateEmailFrom(
116 ActionRequest actionRequest, PortletPreferences prefs)
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 prefs.setValue("email-from-name", emailFromName);
132 prefs.setValue("email-from-address", emailFromAddress);
133 }
134 }
135
136 protected void updateEmailEventReminder(
137 ActionRequest actionRequest, PortletPreferences prefs)
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 prefs.setValue(
155 "email-event-reminder-enabled",
156 String.valueOf(emailEventReminderEnabled));
157 prefs.setValue(
158 "email-event-reminder-subject", emailEventReminderSubject);
159 prefs.setValue("email-event-reminder-body", emailEventReminderBody);
160 }
161 }
162
163 }