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