001
014
015 package com.liferay.portlet.calendar.action;
016
017 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018 import com.liferay.portal.kernel.servlet.SessionErrors;
019 import com.liferay.portal.kernel.servlet.SessionMessages;
020 import com.liferay.portal.kernel.util.Constants;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portlet.PortletPreferencesFactoryUtil;
024
025 import javax.portlet.ActionRequest;
026 import javax.portlet.ActionResponse;
027 import javax.portlet.PortletConfig;
028 import javax.portlet.PortletPreferences;
029 import javax.portlet.RenderRequest;
030 import javax.portlet.RenderResponse;
031
032
036 public class ConfigurationActionImpl extends BaseConfigurationAction {
037
038 public void processAction(
039 PortletConfig portletConfig, ActionRequest actionRequest,
040 ActionResponse actionResponse)
041 throws Exception {
042
043 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
044
045 if (!cmd.equals(Constants.UPDATE)) {
046 return;
047 }
048
049 String portletResource = ParamUtil.getString(
050 actionRequest, "portletResource");
051
052 PortletPreferences preferences =
053 PortletPreferencesFactoryUtil.getPortletSetup(
054 actionRequest, portletResource);
055
056 String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
057
058 if (tabs2.equals("display-settings")) {
059 updateDisplaySettings(actionRequest, preferences);
060 }
061 else if (tabs2.equals("email-from")) {
062 updateEmailFrom(actionRequest, preferences);
063 }
064 else if (tabs2.equals("event-reminder-email")) {
065 updateEmailEventReminder(actionRequest, preferences);
066 }
067
068 if (SessionErrors.isEmpty(actionRequest)) {
069 preferences.store();
070
071 SessionMessages.add(
072 actionRequest, portletConfig.getPortletName() + ".doConfigure");
073 }
074 }
075
076 public String render(
077 PortletConfig portletConfig, RenderRequest renderRequest,
078 RenderResponse renderResponse)
079 throws Exception {
080
081 return "/html/portlet/calendar/configuration.jsp";
082 }
083
084 protected void updateDisplaySettings(
085 ActionRequest actionRequest, PortletPreferences preferences)
086 throws Exception {
087
088 String tabs1Default = ParamUtil.getString(
089 actionRequest, "tabs1Default");
090 String summaryTabOrientation = ParamUtil.getString(
091 actionRequest, "summaryTabOrientation");
092 String summaryTabShowMiniMonth = ParamUtil.getString(
093 actionRequest, "summaryTabShowMiniMonth");
094 String summaryTabShowTodaysEvents = ParamUtil.getString(
095 actionRequest, "summaryTabShowTodaysEvents");
096 boolean enableComments = ParamUtil.getBoolean(
097 actionRequest, "enableComments");
098
099 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 preferences.setValue("enable-comments", String.valueOf(enableComments));
106 }
107
108 protected void updateEmailFrom(
109 ActionRequest actionRequest, PortletPreferences preferences)
110 throws Exception {
111
112 String emailFromName = ParamUtil.getString(
113 actionRequest, "emailFromName");
114 String emailFromAddress = ParamUtil.getString(
115 actionRequest, "emailFromAddress");
116
117 if (Validator.isNull(emailFromName)) {
118 SessionErrors.add(actionRequest, "emailFromName");
119 }
120 else if (!Validator.isEmailAddress(emailFromAddress)) {
121 SessionErrors.add(actionRequest, "emailFromAddress");
122 }
123 else {
124 preferences.setValue("email-from-name", emailFromName);
125 preferences.setValue("email-from-address", emailFromAddress);
126 }
127 }
128
129 protected void updateEmailEventReminder(
130 ActionRequest actionRequest, PortletPreferences preferences)
131 throws Exception {
132
133 boolean emailEventReminderEnabled = ParamUtil.getBoolean(
134 actionRequest, "emailEventReminderEnabled");
135 String emailEventReminderSubject = ParamUtil.getString(
136 actionRequest, "emailEventReminderSubject");
137 String emailEventReminderBody = ParamUtil.getString(
138 actionRequest, "emailEventReminderBody");
139
140 if (Validator.isNull(emailEventReminderSubject)) {
141 SessionErrors.add(actionRequest, "emailEventReminderSubject");
142 }
143 else if (Validator.isNull(emailEventReminderBody)) {
144 SessionErrors.add(actionRequest, "emailEventReminderBody");
145 }
146 else {
147 preferences.setValue(
148 "email-event-reminder-enabled",
149 String.valueOf(emailEventReminderEnabled));
150 preferences.setValue(
151 "email-event-reminder-subject", emailEventReminderSubject);
152 preferences.setValue(
153 "email-event-reminder-body", emailEventReminderBody);
154 }
155 }
156
157 }