1 | <%-- $Id: settings.jsp 5901 2011-12-08 08:30:53Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
---|
5 | Copyright (C) 2007 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 is used to display and modify the attributes of |
---|
25 | the logged in user. It displays a tabbed dialogue: |
---|
26 | |
---|
27 | @param page |
---|
28 | The name active page of the tabbed dialog. |
---|
29 | - contact: Contact information for the user, address, phone, email, etc. |
---|
30 | - password: The password for the user |
---|
31 | - other: Other information |
---|
32 | |
---|
33 | Saving the form invokes the submit_user.jsp page with cmd=SaveSettings |
---|
34 | |
---|
35 | @author Nicklas |
---|
36 | @version 2.0 |
---|
37 | --%> |
---|
38 | <%@ page pageEncoding="UTF-8" session="false" |
---|
39 | import="net.sf.basedb.core.*" |
---|
40 | import="net.sf.basedb.util.EmailUtil" |
---|
41 | import="net.sf.basedb.clients.web.*" |
---|
42 | import="net.sf.basedb.clients.web.util.HTML" |
---|
43 | import="net.sf.basedb.util.formatter.Formatter" |
---|
44 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
45 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
46 | import="java.util.Date" |
---|
47 | import="java.util.List" |
---|
48 | %> |
---|
49 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
50 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
51 | <% |
---|
52 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
53 | final String ID = sc.getId(); |
---|
54 | final String activePage = request.getParameter("page"); |
---|
55 | final float scale = Base.getScale(sc); |
---|
56 | final DbControl dc = sc.newDbControl(); |
---|
57 | final ItemContext cc = Base.getAndSetCurrentContext(sc, Item.USER, null, null); |
---|
58 | try |
---|
59 | { |
---|
60 | final User user = User.getById(dc, sc.getLoggedInUserId()); |
---|
61 | final boolean writePermission = user.hasPermission(Permission.RESTRICTED_WRITE); |
---|
62 | final String clazz = writePermission ? "class=\"text\"" : "class=\"text disabled\" disabled readonly"; |
---|
63 | final String requiredClazz = writePermission ? "class=\"text required\"" : "class=\"text required disabled\" disabled readonly"; |
---|
64 | final String passwordClass = writePermission && Application.isUsingInternalAuthentication() ? |
---|
65 | "text" : "class=\"text disabled\" disabled readonly"; |
---|
66 | dc.detachItem(user); |
---|
67 | sc.setSessionSetting("user", user); |
---|
68 | |
---|
69 | List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData"); |
---|
70 | |
---|
71 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
72 | String dateFormat = FormatterSettings.getDateFormat(sc); |
---|
73 | String jsDateFormat = HTML.javaScriptEncode(dateFormat); |
---|
74 | String htmlDateFormat = HTML.encodeTags(dateFormat); |
---|
75 | Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc); |
---|
76 | String dateTimeFormat = FormatterSettings.getDateTimeFormat(sc); |
---|
77 | String jsDateTimeFormat = HTML.javaScriptEncode(dateTimeFormat); |
---|
78 | String htmlDateTimeFormat = HTML.encodeTags(dateTimeFormat); |
---|
79 | %> |
---|
80 | <base:page type="popup" title="<%="Information for "+HTML.encodeTags(user.getName())%>"> |
---|
81 | <base:head scripts="tabcontrol.js" styles="tabcontrol.css"> |
---|
82 | <script language="JavaScript"> |
---|
83 | // Validate the "Contact information" tab |
---|
84 | function validateContact() |
---|
85 | { |
---|
86 | return true; |
---|
87 | } |
---|
88 | // Validate the "Password" tab - check that both passwords match |
---|
89 | function validatePassword() |
---|
90 | { |
---|
91 | var frm = document.forms["user"]; |
---|
92 | if (frm.password.value != frm.retype_password.value) |
---|
93 | { |
---|
94 | frm.retype_password.focus(); |
---|
95 | alert("The two passwords do not match!"); |
---|
96 | return false; |
---|
97 | } |
---|
98 | return true; |
---|
99 | } |
---|
100 | |
---|
101 | // Validate the "Extended properties" tab |
---|
102 | function validateExtendedProperties() |
---|
103 | { |
---|
104 | var frm = document.forms['user']; |
---|
105 | var field; |
---|
106 | <% |
---|
107 | if (extendedProperties != null) |
---|
108 | { |
---|
109 | for (ExtendedProperty ep : extendedProperties) |
---|
110 | { |
---|
111 | Type type = ep.getType(); |
---|
112 | String name = ep.getName(); |
---|
113 | %> |
---|
114 | field = frm['<%=name%>']; |
---|
115 | <% |
---|
116 | if (type == Type.DATE) |
---|
117 | { |
---|
118 | %> |
---|
119 | if (field.value != '' && !Dates.isDate(field.value, '<%=jsDateFormat%>')) |
---|
120 | { |
---|
121 | alert("'"+field.value+"' is not a valid date for '<%=HTML.javaScriptEncode(ep.getTitle())%>'"); |
---|
122 | field.focus(); |
---|
123 | return false; |
---|
124 | } |
---|
125 | <% |
---|
126 | } |
---|
127 | else if (type == Type.TIMESTAMP) |
---|
128 | { |
---|
129 | %> |
---|
130 | if (field.value != '' && !Dates.isDate(field.value, '<%=jsDateTimeFormat%>')) |
---|
131 | { |
---|
132 | alert("'"+field.value+"' is not a valid timestamp for '<%=HTML.javaScriptEncode(ep.getTitle())%>'"); |
---|
133 | field.focus(); |
---|
134 | return false; |
---|
135 | } |
---|
136 | <% |
---|
137 | } |
---|
138 | if (!ep.isNullable()) |
---|
139 | { |
---|
140 | if (type == Type.BOOLEAN) |
---|
141 | { |
---|
142 | %> |
---|
143 | if (Forms.getCheckedRadio(field) == null) |
---|
144 | { |
---|
145 | alert("You must select a value for '<%=HTML.javaScriptEncode(ep.getTitle())%>'"); |
---|
146 | field.focus(); |
---|
147 | return false; |
---|
148 | } |
---|
149 | <% |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | %> |
---|
154 | if (Main.trimString(field.value) == '') |
---|
155 | { |
---|
156 | alert("You must enter a value for '<%=HTML.javaScriptEncode(ep.getTitle())%>'."); |
---|
157 | field.focus(); |
---|
158 | return false; |
---|
159 | } |
---|
160 | <% |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | %> |
---|
166 | return true; |
---|
167 | } |
---|
168 | |
---|
169 | // Submit the form |
---|
170 | function saveSettings() |
---|
171 | { |
---|
172 | var frm = document.forms["user"]; |
---|
173 | if (TabControl.validateActiveTab('settings')) |
---|
174 | { |
---|
175 | frm.submit(); |
---|
176 | } |
---|
177 | } |
---|
178 | </script> |
---|
179 | </base:head> |
---|
180 | <base:body> |
---|
181 | <h1>Information for <%=HTML.encodeTags(user.getName())%> <base:help tabcontrol="settings" /></h1> |
---|
182 | |
---|
183 | <br><br> |
---|
184 | |
---|
185 | <form action="submit_user.jsp?ID=<%=ID%>" method="post" name="user" onsubmit="return false;"> |
---|
186 | <input type=hidden name="cmd" value="SaveSettings"> |
---|
187 | |
---|
188 | <t:tabcontrol active="<%=activePage%>" id="settings" |
---|
189 | contentstyle="<%="height: "+(int)(scale*240)+"px;"%>" position="bottom" remember="false"> |
---|
190 | |
---|
191 | <t:tab id="contact" title="Contact information" validate="validateContact()" helpid="userpreferences.contact"> |
---|
192 | <table class="form" cellspacing=0> |
---|
193 | <tr> |
---|
194 | <td class="prompt">Full name</td> |
---|
195 | <td><%=HTML.encodeTags(user.getName())%></td> |
---|
196 | </tr> |
---|
197 | <tr> |
---|
198 | <td class="prompt">Email</td> |
---|
199 | <td><input <%=clazz%> type="text" name="email" value="<%=HTML.encodeTags(user.getEmail())%>" size="40" maxlength="<%=User.MAX_EMAIL_LENGTH%>"></td> |
---|
200 | </tr> |
---|
201 | <% |
---|
202 | if (EmailUtil.isEnabled() && writePermission) |
---|
203 | { |
---|
204 | %> |
---|
205 | <tr> |
---|
206 | <td class="prompt"></td> |
---|
207 | <td> |
---|
208 | <% |
---|
209 | boolean sendMessagesAsEmail = user.getSendMessagesAsEmail(); |
---|
210 | %> |
---|
211 | <input type="checkbox" name="sendMessagesAsEmail" id="sendMessagesAsEmail" value="1" <%=sendMessagesAsEmail ? "checked" : ""%> |
---|
212 | ><label for="sendMessagesAsEmail">Send system messages as email</label> |
---|
213 | </td> |
---|
214 | </tr> |
---|
215 | <% |
---|
216 | } |
---|
217 | %> |
---|
218 | <tr> |
---|
219 | <td class="prompt">Organisation</td> |
---|
220 | <td><input <%=clazz%> type="text" name="organisation" value="<%=HTML.encodeTags(user.getOrganisation())%>" size="40" maxlength="<%=User.MAX_ORGANISATION_LENGTH%>"></td> |
---|
221 | </tr> |
---|
222 | <tr valign=top> |
---|
223 | <td class="prompt">Address</td> |
---|
224 | <td> |
---|
225 | <textarea <%=clazz%> rows="4" cols="40" name="address" wrap="virtual"><%=HTML.encodeTags(user.getAddress())%></textarea> |
---|
226 | <a href="javascript:Main.zoom('Address', 'user', 'address', <%=!writePermission%>)" title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
227 | </td> |
---|
228 | </tr> |
---|
229 | <tr> |
---|
230 | <td class="prompt">Phone</td> |
---|
231 | <td><input <%=clazz%> type="text" name="phone" value="<%=HTML.encodeTags(user.getPhone())%>" size="40" maxlength="<%=User.MAX_PHONE_LENGTH%>"></td> |
---|
232 | </tr> |
---|
233 | <tr> |
---|
234 | <td class="prompt">Fax</td> |
---|
235 | <td><input <%=clazz%> type="text" name="fax" value="<%=HTML.encodeTags(user.getFax())%>" size="40" maxlength="<%=User.MAX_FAX_LENGTH%>"></td> |
---|
236 | </tr> |
---|
237 | <tr> |
---|
238 | <td class="prompt">Url</td> |
---|
239 | <td><input <%=clazz%> type="text" name="url" value="<%=HTML.encodeTags(user.getUrl())%>" size="40" maxlength="<%=User.MAX_URL_LENGTH%>"></td> |
---|
240 | </tr> |
---|
241 | </table> |
---|
242 | </t:tab> |
---|
243 | |
---|
244 | <t:tab id="password" title="Password" validate="validatePassword()" helpid="userpreferences.password"> |
---|
245 | <% if (!Application.isUsingInternalAuthentication() && writePermission) |
---|
246 | { |
---|
247 | %> |
---|
248 | <div class="error">Base is using external authentication. Password cannot be changed here.</div> |
---|
249 | <% |
---|
250 | } |
---|
251 | %> |
---|
252 | <table class="form" cellspacing=0> |
---|
253 | <tr> |
---|
254 | <td class="prompt">Login</td> |
---|
255 | <td><%=HTML.encodeTags(user.getLogin())%></td> |
---|
256 | </tr> |
---|
257 | <tr> |
---|
258 | <td class="prompt">New password</td> |
---|
259 | <td><input <%=passwordClass%> type="password" name="password" value="" size="30" maxlength="30"></td> |
---|
260 | </tr> |
---|
261 | <tr> |
---|
262 | <td class="prompt">Retype password</td> |
---|
263 | <td><input <%=passwordClass%> type="password" name="retype_password" value="" size="30" maxlength="30"></td> |
---|
264 | </tr> |
---|
265 | </table> |
---|
266 | <div align=right> <i>- leave empty to not change the password</i></div> |
---|
267 | </t:tab> |
---|
268 | |
---|
269 | <t:tab id="other" title="Other information" |
---|
270 | validate="validateExtendedProperties()" helpid="userpreferences.other"> |
---|
271 | <table class="form" cellspacing="0"> |
---|
272 | <% |
---|
273 | if (extendedProperties != null) |
---|
274 | { |
---|
275 | for (ExtendedProperty ep : ExtendedProperties.getProperties("UserData")) |
---|
276 | { |
---|
277 | String name = ep.getName(); |
---|
278 | Type type = ep.getType(); |
---|
279 | boolean required = !ep.isNullable(); |
---|
280 | Object value = user == null ? cc.getPropertyValue(name) : user.getExtended(name); |
---|
281 | String theClazz = required ? requiredClazz : clazz; |
---|
282 | %> |
---|
283 | <tr valign="top"> |
---|
284 | <td class="prompt"><%=HTML.encodeTags(ep.getTitle())%></td> |
---|
285 | <td> |
---|
286 | <% |
---|
287 | if (type == Type.INT || type == Type.LONG) |
---|
288 | { |
---|
289 | %> |
---|
290 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
291 | value="<%=value == null ? "" : value%>" |
---|
292 | size="20" maxlength="20" onkeypress="return Numbers.integerOnly(event)" |
---|
293 | > |
---|
294 | <% |
---|
295 | } |
---|
296 | else if (type == Type.FLOAT || type == Type.DOUBLE) |
---|
297 | { |
---|
298 | %> |
---|
299 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
300 | value="<%=value == null ? "" : value%>" |
---|
301 | size="20" maxlength="20" onkeypress="return Numbers.numberOnly(event)" |
---|
302 | > |
---|
303 | <% |
---|
304 | } |
---|
305 | else if (type == Type.STRING) |
---|
306 | { |
---|
307 | %> |
---|
308 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
309 | value="<%=HTML.encodeTags((String)value)%>" |
---|
310 | size="40" maxlength="<%=ep.getLength()%>" |
---|
311 | > |
---|
312 | <% |
---|
313 | } |
---|
314 | else if (type == Type.TEXT) |
---|
315 | { |
---|
316 | %> |
---|
317 | <textarea <%=theClazz%> name="<%=name%>" rows="6" cols="40" |
---|
318 | ><%=HTML.encodeTags((String)value)%></textarea> |
---|
319 | <a href="javascript:Main.zoom( |
---|
320 | '<%=HTML.javaScriptEncode(ep.getTitle())%>', |
---|
321 | 'reporter', '<%=name%>')" |
---|
322 | title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
323 | <% |
---|
324 | } |
---|
325 | else if (type == Type.BOOLEAN) |
---|
326 | { |
---|
327 | Boolean b = (Boolean)value; |
---|
328 | if (!required) |
---|
329 | { |
---|
330 | %> |
---|
331 | <input type="radio" name="<%=name%>" id="<%=name%>.null" value="" |
---|
332 | <%=b == null ? "checked" : ""%> |
---|
333 | ><label for="<%=name%>.null"><i>- not specified -</i></label><br> |
---|
334 | <% |
---|
335 | } |
---|
336 | %> |
---|
337 | <input type="radio" name="<%=name%>" id="<%=name%>.true" value="true" |
---|
338 | <%=b != null && b == true ? "checked" : ""%> |
---|
339 | ><label for="<%=name%>.true">true</label><br> |
---|
340 | <input type="radio" name="<%=name%>" id="<%=name%>.false" value="false" |
---|
341 | <%=b != null && b == false ? "checked" : ""%> |
---|
342 | ><label for="<%=name%>.false">false</label> |
---|
343 | <% |
---|
344 | } |
---|
345 | else if (type == Type.DATE) |
---|
346 | { |
---|
347 | %> |
---|
348 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
349 | <tr> |
---|
350 | <td> |
---|
351 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
352 | value="<%=dateFormatter.format((Date)value)%>" |
---|
353 | size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>" |
---|
354 | > |
---|
355 | </td> |
---|
356 | <td> </td> |
---|
357 | <td> |
---|
358 | <base:button |
---|
359 | onclick="<%="Dates.selectDate('"+HTML.javaScriptEncode(ep.getTitle())+"', 'user', '"+name+"', null, '"+jsDateFormat +"')"%>" |
---|
360 | image="calendar.png" |
---|
361 | title="Calendar…" |
---|
362 | tooltip="Select a date from a calendar" |
---|
363 | visible="<%=writePermission%>" |
---|
364 | /> |
---|
365 | </td> |
---|
366 | </tr> |
---|
367 | </table> |
---|
368 | <% |
---|
369 | } |
---|
370 | else if (type == Type.TIMESTAMP) |
---|
371 | { |
---|
372 | %> |
---|
373 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
374 | <tr> |
---|
375 | <td> |
---|
376 | <input <%=theClazz%> type="text" name="<%=name%>" |
---|
377 | value="<%=dateTimeFormatter.format((Date)value)%>" |
---|
378 | size="20" maxlength="20" title="Enter timestamp in format: <%=htmlDateTimeFormat%>" |
---|
379 | > |
---|
380 | </td> |
---|
381 | <td> </td> |
---|
382 | <td> |
---|
383 | <base:button |
---|
384 | onclick="<%="Dates.selectDateTime('"+HTML.javaScriptEncode(ep.getTitle())+"', 'user', '"+name+"', null, '"+jsDateTimeFormat +"')"%>" |
---|
385 | image="calendar.png" |
---|
386 | title="Calendar…" |
---|
387 | tooltip="Select a timestamp from a calendar" |
---|
388 | visible="<%=writePermission%>" |
---|
389 | /> |
---|
390 | </td> |
---|
391 | </tr> |
---|
392 | </table> |
---|
393 | <% |
---|
394 | } |
---|
395 | %> |
---|
396 | </td> |
---|
397 | </tr> |
---|
398 | <% |
---|
399 | } |
---|
400 | } |
---|
401 | %> |
---|
402 | <tr valign="top"> |
---|
403 | <td class="prompt">Description</td> |
---|
404 | <td> |
---|
405 | <textarea <%=clazz%> rows="5" cols="40" name="description" wrap="virtual"><%=HTML.encodeTags(user.getDescription())%></textarea> |
---|
406 | <a href="javascript:Main.zoom('Description', 'user', 'description', <%=!writePermission%>)" title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
407 | </td> |
---|
408 | </tr> |
---|
409 | </table> |
---|
410 | </t:tab> |
---|
411 | </t:tabcontrol> |
---|
412 | </form> |
---|
413 | |
---|
414 | <base:buttongroup subclass="dialogbuttons"> |
---|
415 | <base:button onclick="saveSettings();" title="Save" visible="<%=writePermission%>"/> |
---|
416 | <base:button onclick="window.close();" title="Cancel" visible="<%=writePermission%>"/> |
---|
417 | <base:button onclick="window.close();" title="Close" visible="<%=!writePermission%>"/> |
---|
418 | </base:buttongroup> |
---|
419 | |
---|
420 | </base:body> |
---|
421 | </base:page> |
---|
422 | <% |
---|
423 | } |
---|
424 | finally |
---|
425 | { |
---|
426 | if (dc != null) dc.close(); |
---|
427 | } |
---|
428 | %> |
---|