source: trunk/www/my_base/user/submit_user.jsp @ 6166

Last change on this file since 6166 was 6166, checked in by Nicklas Nordborg, 10 years ago

References #1730: Move in-page onEvent attributes to external *.js files

  • Fixed for the user settings dialog and the 'Reset list settings' dialog.
  • Added a 'zoom' taglib which should make it easier to include the 'zoom' icon for textarea fields.
  • Added new javascript function in main-2 for opening zoom dialog and calendar dialog
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.8 KB
Line 
1<%-- $Id: submit_user.jsp 6166 2012-10-11 13:47:22Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
5  Copyright (C) 2007 Johan Enell, Nicklas Nordborg, Martin Svensson
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 3
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with BASE. If not, see <http://www.gnu.org/licenses/>.
22  ------------------------------------------------------------------
23
24  This page will save user information and preferences.
25
26  @param cmd The command to execute
27    - SaveSettings: Save the settings from the settings.jsp page.
28    - SavePreferences: Save preferences from the preferences.jsp page.
29
30  @author Nicklas
31  @version 2.0
32--%>
33<%@ page pageEncoding="UTF-8" session="false"
34  import="net.sf.basedb.core.SessionControl"
35  import="net.sf.basedb.core.DbControl"
36  import="net.sf.basedb.core.Item"
37  import="net.sf.basedb.core.User"
38  import="net.sf.basedb.core.ItemContext"
39  import="net.sf.basedb.core.ExtendedProperty"
40  import="net.sf.basedb.core.ExtendedProperties"
41  import="net.sf.basedb.util.EmailUtil"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.WebException"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.util.formatter.Formatter"
47  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
48  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
49  import="java.util.Arrays"
50  import="java.util.List"
51%>
52<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
53<%
54SessionControl sc = Base.getExistingSessionControl(pageContext, true);
55String ID = sc.getId();
56String cmd = request.getParameter("cmd");
57String message = "";
58String root = request.getContextPath()+"/";
59
60DbControl dc = sc.newDbControl();
61try
62{
63  if ("SaveSettings".equals(cmd))
64  {
65    String email = Values.getStringOrNull(request.getParameter("email"));
66    if (email != null && !HTML.isValidEmail(email))
67    {
68      throw new WebException("popup", "Invalid email address",
69        "The email address {1} is not a valid email address.",
70        HTML.encodeTags(email)
71      );
72    }
73    User user = (User)sc.getSessionSetting("user");
74    dc.reattachItem(user, false);
75
76    // Contact information tab
77    user.setEmail(email);
78    if (EmailUtil.isEnabled())
79    {
80      user.setSendMessagesAsEmail(email != null && Values.getBoolean(request.getParameter("sendMessagesAsEmail")));
81    }
82    user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation")));
83    user.setAddress(Values.getStringOrNull(request.getParameter("address")));
84    user.setPhone(Values.getStringOrNull(request.getParameter("phone")));
85    user.setFax(Values.getStringOrNull(request.getParameter("fax")));
86    user.setUrl(Values.getStringOrNull(request.getParameter("url")));
87
88    // Password tab
89    String password = Values.getStringOrNull(request.getParameter("password"));
90    if (password != null) user.setPassword(password);
91
92    // Other settings tab
93    user.setDescription(Values.getStringOrNull(request.getParameter("description")));
94
95    // Extended properties
96    List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData");
97    if (extendedProperties != null)
98    {
99      for (ExtendedProperty ep : extendedProperties)
100      {
101        String name = ep.getName();
102        Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
103        Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
104        user.setExtended(name, value);
105      }
106    }
107
108    dc.commit();
109    sc.setSessionSetting("user", null);
110    message = "Information saved";
111  }
112  else if ("SavePreferences".equals(cmd))
113  {
114    int newScale = Values.getInt(request.getParameter("scale"), 100);
115    sc.setUserClientSetting("appearance.scale", Integer.toString(newScale));
116    sc.setUserClientSetting("appearance.fontsize", Values.getString(request.getParameter("fontsize"), "size_m.css"));
117    sc.setSessionSetting("appearance.scale", new Float(newScale / 100.0));
118    sc.setUserClientSetting("text.long", request.getParameter("longTexts"));
119    ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
120    int maxRecent = Base.getMaxRecent(sc);
121 
122    String toolbar = request.getParameter("toolbar");
123    boolean hasImages = true;
124    boolean hasText = true;
125    if ("text".equals(toolbar))
126    {
127      hasImages = false;
128    }
129    else if ("images".equals(toolbar))
130    {
131      hasText = false;
132    }
133    sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0");
134    sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0");
135    String minColor = Values.getString(request.getParameter("mincolor"), "0000FF");
136    String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF");
137    String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00");
138    sc.setUserClientSetting("ratiocolor.min", minColor);
139    sc.setUserClientSetting("ratiocolor.mid", midColor);
140    sc.setUserClientSetting("ratiocolor.max", maxColor);
141    cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent);
142   
143    String dateFormat = request.getParameter("date_format");
144    String dateTimeFormat = request.getParameter("datetime_format");
145    FormatterSettings.setDateFormat(sc, dateFormat);
146    FormatterSettings.setDateTimeFormat(sc, dateTimeFormat);
147    cc.setRecent("dateFormats", dateFormat, maxRecent);
148    cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent);
149
150    int numDecimals = Values.getInt(request.getParameter("decimals"), 2);
151    FormatterSettings.setNumDecimals(sc, numDecimals);
152   
153    // Plugins tab
154    sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0"));
155    sc.setUserClientSetting("plugins.removejob", Values.getString(request.getParameter("removejob"), "0"));
156    sc.setUserClientSetting("plugins.showWarnings", Values.getString(request.getParameter("show_warnings"), "0"));
157   
158    // Recent items tab
159    int newMaxUsed = Values.getInt(request.getParameter("maxUsed"), 4);
160    sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxUsed));
161    sc.setSessionSetting("appearance.recent", newMaxUsed);
162    int newMaxViewed = Values.getInt(request.getParameter("maxViewed"), 6);
163    sc.setUserClientSetting("menu.mostRecent.maxViewed", Integer.toString(newMaxViewed));
164    sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0"));
165
166    String[] stickyItems = request.getParameterValues("sticky_items");
167    sc.setUserClientSetting("menu.mostRecent", 
168      stickyItems == null ? "" : Values.getString(Arrays.asList(stickyItems), ":", true));
169   
170    message = "Preferences saved";
171  }
172  else if ("ReloadPermissions".equals(cmd))
173  {
174    sc.reloadPermissions();
175    sc.reloadSettings(true, false);
176    sc.setSessionSetting("menu.standard.html", null);
177    message = "Permissions reloaded";
178  }
179  else if ("ResetFilters".equals(cmd))
180  {
181    boolean inDatabase = Values.getBoolean(request.getParameter("database"));
182    String itemType = Values.getStringOrNull(request.getParameter("item_type"));
183    Item item = itemType == null ? null : Item.valueOf(itemType);
184    int numDeleted = sc.deleteCurrentContexts(item, true, inDatabase);
185    message = numDeleted + " list settings deleted";
186  }
187  else
188  {
189    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
190  }
191}
192finally
193{
194  if (dc != null) dc.close();
195}
196response.sendRedirect(root + "common/close_popup.jsp?ID="+ID+"&refresh_opener=1&&message="+HTML.urlEncode(message));
197%>
198
Note: See TracBrowser for help on using the repository browser.