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