1 | <%-- $Id: settings.jsp 7501 2018-08-09 06:40:57Z 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.util.json.JsonUtil" |
---|
45 | import="net.sf.basedb.util.json.JsonConverter" |
---|
46 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
47 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
48 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
49 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
50 | import="net.sf.basedb.clients.web.extensions.tabcontrol.TabAction" |
---|
51 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
52 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
53 | import="org.json.simple.JSONObject" |
---|
54 | import="org.json.simple.JSONArray" |
---|
55 | import="java.util.Date" |
---|
56 | import="java.util.List" |
---|
57 | %> |
---|
58 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
59 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
60 | <% |
---|
61 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
62 | final String ID = sc.getId(); |
---|
63 | final String activePage = request.getParameter("page"); |
---|
64 | final float scale = Base.getScale(sc); |
---|
65 | final DbControl dc = sc.newDbControl(); |
---|
66 | final ItemContext cc = Base.getAndSetCurrentContext(sc, Item.USER, null, null); |
---|
67 | try |
---|
68 | { |
---|
69 | final User user = User.getById(dc, sc.getLoggedInUserId()); |
---|
70 | final String title = "Information for " + HTML.encodeTags(user.getName()); |
---|
71 | final boolean writePermission = user.hasPermission(Permission.RESTRICTED_WRITE); |
---|
72 | final String ifDisabled = writePermission ? "" : "disabled"; |
---|
73 | final String passwordDisabled = writePermission && Application.isUsingInternalAuthentication() ? |
---|
74 | "" : "disabled"; |
---|
75 | dc.detachItem(user); |
---|
76 | sc.setSessionSetting("user", user); |
---|
77 | |
---|
78 | List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData"); |
---|
79 | JSONArray jsonExtendedProperties = JsonUtil.toArray(extendedProperties, new JsonConverter<ExtendedProperty>() |
---|
80 | { |
---|
81 | public Object convert(ExtendedProperty ep) |
---|
82 | { |
---|
83 | if (ep.isRestrictedEdit()) return null; |
---|
84 | JSONObject json = new JSONObject(); |
---|
85 | json.put("name", ep.getName()); |
---|
86 | json.put("valueType", ep.getType().name()); |
---|
87 | json.put("title", ep.getTitle()); |
---|
88 | json.put("nullable", ep.isNullable()); |
---|
89 | return json; |
---|
90 | } |
---|
91 | }); |
---|
92 | |
---|
93 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
94 | String dateFormat = FormatterSettings.getDateFormat(sc); |
---|
95 | String jsDateFormat = HTML.javaScriptEncode(dateFormat); |
---|
96 | String htmlDateFormat = HTML.encodeTags(dateFormat); |
---|
97 | Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc); |
---|
98 | String dateTimeFormat = FormatterSettings.getDateTimeFormat(sc); |
---|
99 | String jsDateTimeFormat = HTML.javaScriptEncode(dateTimeFormat); |
---|
100 | String htmlDateTimeFormat = HTML.encodeTags(dateTimeFormat); |
---|
101 | JspContext context = ExtensionsControl.createContext(dc, pageContext, null, user); |
---|
102 | ExtensionsInvoker<TabAction> tabsInvoker = (ExtensionsInvoker<TabAction>)ExtensionsControl.useExtensions(context, EditUtil.EP_PREFIX_EDIT+"user-information"); |
---|
103 | %> |
---|
104 | <base:page type="popup" title="<%=title%>"> |
---|
105 | <base:head scripts="tabcontrol-2.js,~settings.js" styles="tabcontrol.css" /> |
---|
106 | <base:body> |
---|
107 | <h1><%=title%><base:help tabcontrol="settings" /></h1> |
---|
108 | |
---|
109 | <div id="page-data" class="datacontainer" |
---|
110 | data-date-format="<%=htmlDateFormat%>" |
---|
111 | data-datetime-format="<%=htmlDateTimeFormat%>" |
---|
112 | data-extended-properties="<%=HTML.encodeTags(jsonExtendedProperties.toJSONString())%>" |
---|
113 | ></div> |
---|
114 | |
---|
115 | <form action="submit_user.jsp?ID=<%=ID%>" method="post" name="user"> |
---|
116 | <input type=hidden name="cmd" value="SaveSettings"> |
---|
117 | |
---|
118 | <t:tabcontrol |
---|
119 | subclass="content dialogtabcontrol" |
---|
120 | active="<%=activePage%>" id="settings" |
---|
121 | extensions="<%=tabsInvoker%>" |
---|
122 | position="bottom" remember="false"> |
---|
123 | |
---|
124 | <t:tab id="contact" title="Contact information" helpid="userpreferences.contact"> |
---|
125 | <table class="fullform input100"> |
---|
126 | <tr> |
---|
127 | <th>Full name</th> |
---|
128 | <td><%=HTML.encodeTags(user.getName())%></td> |
---|
129 | <td></td> |
---|
130 | </tr> |
---|
131 | <tr> |
---|
132 | <th>Email</th> |
---|
133 | <td><input <%=ifDisabled%> type="text" name="email" value="<%=HTML.encodeTags(user.getEmail())%>" maxlength="<%=User.MAX_EMAIL_LENGTH%>"></td> |
---|
134 | <td></td> |
---|
135 | </tr> |
---|
136 | <% |
---|
137 | if (EmailUtil.isEnabled() && writePermission) |
---|
138 | { |
---|
139 | %> |
---|
140 | <tr> |
---|
141 | <th class="subprompt"></th> |
---|
142 | <td> |
---|
143 | <% |
---|
144 | boolean sendMessagesAsEmail = user.getSendMessagesAsEmail(); |
---|
145 | %> |
---|
146 | <input type="checkbox" name="sendMessagesAsEmail" id="sendMessagesAsEmail" value="1" <%=sendMessagesAsEmail ? "checked" : ""%> |
---|
147 | ><label for="sendMessagesAsEmail">Send system messages as email</label> |
---|
148 | </td> |
---|
149 | <td></td> |
---|
150 | </tr> |
---|
151 | <tr> |
---|
152 | <th class="subprompt"></th> |
---|
153 | <td> |
---|
154 | <% |
---|
155 | boolean useDeviceVerification = user.getUseDeviceVerification(); |
---|
156 | %> |
---|
157 | <input type="checkbox" name="useDeviceVerification" id="useDeviceVerification" value="1" <%=useDeviceVerification ? "checked" : ""%> |
---|
158 | ><label for="useDeviceVerification">Enable 2-factor login</label> |
---|
159 | </td> |
---|
160 | <td></td> |
---|
161 | </tr> |
---|
162 | <% |
---|
163 | } |
---|
164 | %> |
---|
165 | <tr> |
---|
166 | <th>Organisation</th> |
---|
167 | <td><input <%=ifDisabled%> type="text" name="organisation" value="<%=HTML.encodeTags(user.getOrganisation())%>" maxlength="<%=User.MAX_ORGANISATION_LENGTH%>"></td> |
---|
168 | <td></td> |
---|
169 | </tr> |
---|
170 | <tr class="big"> |
---|
171 | <th>Address</th> |
---|
172 | <td> |
---|
173 | <textarea <%=ifDisabled%> rows="4" name="address" id="address"><%=HTML.encodeTags(user.getAddress())%></textarea> |
---|
174 | </td> |
---|
175 | <td style="width: 20px;"> |
---|
176 | <base:zoom textarea="address" title="Address" /> |
---|
177 | </td> |
---|
178 | </tr> |
---|
179 | <tr> |
---|
180 | <th>Phone</th> |
---|
181 | <td><input <%=ifDisabled%> type="text" name="phone" value="<%=HTML.encodeTags(user.getPhone())%>" maxlength="<%=User.MAX_PHONE_LENGTH%>"></td> |
---|
182 | <td></td> |
---|
183 | </tr> |
---|
184 | <tr> |
---|
185 | <th>Fax</th> |
---|
186 | <td><input <%=ifDisabled%> type="text" name="fax" value="<%=HTML.encodeTags(user.getFax())%>" maxlength="<%=User.MAX_FAX_LENGTH%>"></td> |
---|
187 | <td></td> |
---|
188 | </tr> |
---|
189 | <tr> |
---|
190 | <th>Url</th> |
---|
191 | <td><input <%=ifDisabled%> type="text" name="url" value="<%=HTML.encodeTags(user.getUrl())%>" maxlength="<%=User.MAX_URL_LENGTH%>"></td> |
---|
192 | <td></td> |
---|
193 | </tr> |
---|
194 | <tr class="dynamic"> |
---|
195 | <th></th> |
---|
196 | <td></td> |
---|
197 | <td></td> |
---|
198 | </tr> |
---|
199 | </table> |
---|
200 | </t:tab> |
---|
201 | |
---|
202 | <t:tab id="password" title="Password" helpid="userpreferences.password"> |
---|
203 | <table class="fullform input100"> |
---|
204 | <% if (!Application.isUsingInternalAuthentication() && writePermission) |
---|
205 | { |
---|
206 | %> |
---|
207 | <tr> |
---|
208 | <td colspan="2"> |
---|
209 | <div class="messagecontainer error">Base is using external authentication. Password cannot be changed here.</div> |
---|
210 | </td> |
---|
211 | </tr> |
---|
212 | <% |
---|
213 | } |
---|
214 | %> |
---|
215 | <tr> |
---|
216 | <th>Login</th> |
---|
217 | <td><%=HTML.encodeTags(user.getLogin())%></td> |
---|
218 | </tr> |
---|
219 | <tr> |
---|
220 | <th>New password</th> |
---|
221 | <td><input <%=passwordDisabled%> type="password" name="password" value="" maxlength="30"></td> |
---|
222 | </tr> |
---|
223 | <tr> |
---|
224 | <th>Retype password</th> |
---|
225 | <td><input <%=passwordDisabled%> type="password" name="retype_password" value="" maxlength="30"></td> |
---|
226 | </tr> |
---|
227 | <tr class="dynamic"> |
---|
228 | <th></th> |
---|
229 | <td><i>- leave empty to not change the password</i></td> |
---|
230 | </tr> |
---|
231 | </table> |
---|
232 | </t:tab> |
---|
233 | |
---|
234 | <t:tab id="other" title="Other information" |
---|
235 | helpid="userpreferences.other"> |
---|
236 | <table class="fullform input100"> |
---|
237 | <% |
---|
238 | if (extendedProperties != null) |
---|
239 | { |
---|
240 | for (ExtendedProperty ep : extendedProperties) |
---|
241 | { |
---|
242 | String name = ep.getName(); |
---|
243 | String fieldName = "ep."+name; |
---|
244 | Type type = ep.getType(); |
---|
245 | boolean required = !ep.isNullable(); |
---|
246 | Object value = user == null ? cc.getPropertyValue(name) : user.getExtended(name); |
---|
247 | String isRequired = required ? "class=\"required\"" : ""; |
---|
248 | final String isDisabled = ep.isRestrictedEdit() ? "disabled" : ""; |
---|
249 | boolean addZoom = false; |
---|
250 | %> |
---|
251 | <tr> |
---|
252 | <th><%=HTML.encodeTags(ep.getTitle())%></th> |
---|
253 | <td> |
---|
254 | <% |
---|
255 | if (type == Type.INT || type == Type.LONG) |
---|
256 | { |
---|
257 | %> |
---|
258 | <input <%=isRequired%> <%=isDisabled %> type="text" name="<%=fieldName%>" id="<%=fieldName%>" |
---|
259 | value="<%=value == null ? "" : value%>" style="width: 15em;" maxlength="20"> |
---|
260 | <% |
---|
261 | } |
---|
262 | else if (type == Type.FLOAT || type == Type.DOUBLE) |
---|
263 | { |
---|
264 | %> |
---|
265 | <input <%=isRequired%> <%=isDisabled%> type="text" name="<%=fieldName%>" id="<%=fieldName%>" |
---|
266 | value="<%=value == null ? "" : value%>" style="width: 15em;" maxlength="20"> |
---|
267 | <% |
---|
268 | } |
---|
269 | else if (type == Type.STRING) |
---|
270 | { |
---|
271 | %> |
---|
272 | <input <%=isRequired%> <%=isDisabled%> type="text" name="<%=fieldName%>" |
---|
273 | value="<%=HTML.encodeTags((String)value)%>" |
---|
274 | maxlength="<%=ep.getLength()%>"> |
---|
275 | <% |
---|
276 | } |
---|
277 | else if (type == Type.TEXT) |
---|
278 | { |
---|
279 | addZoom = true; |
---|
280 | %> |
---|
281 | <textarea <%=isRequired%> <%=isDisabled%> name="<%=fieldName%>" id="<%=fieldName%>" rows="6" |
---|
282 | ><%=HTML.encodeTags((String)value)%></textarea> |
---|
283 | <% |
---|
284 | } |
---|
285 | else if (type == Type.BOOLEAN) |
---|
286 | { |
---|
287 | Boolean b = (Boolean)value; |
---|
288 | if (!required) |
---|
289 | { |
---|
290 | %> |
---|
291 | <input type="radio" <%=isDisabled%> name="<%=fieldName%>" id="<%=fieldName%>.null" value="" |
---|
292 | <%=b == null ? "checked" : ""%> |
---|
293 | ><label for="<%=fieldName%>.null"><i>- not specified -</i></label><br> |
---|
294 | <% |
---|
295 | } |
---|
296 | %> |
---|
297 | <input type="radio" <%=isDisabled%> name="<%=fieldName%>" id="<%=fieldName%>.true" value="true" |
---|
298 | <%=b != null && b == true ? "checked" : ""%> |
---|
299 | ><label for="<%=fieldName%>.true">true</label> |
---|
300 | <input type="radio" <%=isDisabled%> name="<%=fieldName%>" id="<%=fieldName%>.false" value="false" |
---|
301 | <%=b != null && b == false || required && b == null ? "checked" : ""%> |
---|
302 | ><label for="<%=fieldName%>.false">false</label> |
---|
303 | <% |
---|
304 | } |
---|
305 | else if (type == Type.DATE) |
---|
306 | { |
---|
307 | %> |
---|
308 | <table> |
---|
309 | <tr> |
---|
310 | <td> |
---|
311 | <input <%=isRequired%> <%=isDisabled%> type="text" name="<%=fieldName%>" id="<%=fieldName%>" |
---|
312 | value="<%=dateFormatter.format((Date)value)%>" style="width: 15em;" |
---|
313 | maxlength="20" title="Enter date in format: <%=dateFormat%>" |
---|
314 | > |
---|
315 | </td> |
---|
316 | <td> |
---|
317 | <base:button |
---|
318 | id="<%="btn."+fieldName%>" |
---|
319 | data-extended-property="<%=name%>" |
---|
320 | image="calendar.png" |
---|
321 | title="Calendar…" |
---|
322 | tooltip="Select a date from a calendar" |
---|
323 | visible="<%=writePermission%>" |
---|
324 | /> |
---|
325 | </td> |
---|
326 | </tr> |
---|
327 | </table> |
---|
328 | <% |
---|
329 | } |
---|
330 | else if (type == Type.TIMESTAMP) |
---|
331 | { |
---|
332 | %> |
---|
333 | <table> |
---|
334 | <tr> |
---|
335 | <td> |
---|
336 | <input <%=isRequired%> <%=isDisabled%> type="text" name="<%=fieldName%>" id="<%=fieldName%>" |
---|
337 | value="<%=dateTimeFormatter.format((Date)value)%>" style="width: 15em;" |
---|
338 | maxlength="20" title="Enter timestamp in format: <%=dateTimeFormat%>" |
---|
339 | > |
---|
340 | </td> |
---|
341 | <td> |
---|
342 | <base:button |
---|
343 | id="<%="btn."+fieldName%>" |
---|
344 | data-extended-property="<%=name%>" |
---|
345 | image="calendar.png" |
---|
346 | title="Calendar…" |
---|
347 | tooltip="Select a timestamp from a calendar" |
---|
348 | visible="<%=writePermission%>" |
---|
349 | /> |
---|
350 | </td> |
---|
351 | </tr> |
---|
352 | </table> |
---|
353 | <% |
---|
354 | } |
---|
355 | %> |
---|
356 | </td> |
---|
357 | <td style="width: 20px;"> |
---|
358 | <% |
---|
359 | if (addZoom) |
---|
360 | { |
---|
361 | %> |
---|
362 | <base:zoom textarea="<%=fieldName%>" title="<%=HTML.encodeTags(ep.getTitle()) %>" /> |
---|
363 | <% |
---|
364 | } |
---|
365 | %> |
---|
366 | </td> |
---|
367 | </tr> |
---|
368 | <% |
---|
369 | } |
---|
370 | } |
---|
371 | %> |
---|
372 | <tr class="dynamic"> |
---|
373 | <th>Description</th> |
---|
374 | <td> |
---|
375 | <textarea <%=ifDisabled%> rows="5" name="description" id="description"><%=HTML.encodeTags(user.getDescription())%></textarea> |
---|
376 | </td> |
---|
377 | <td style="width: 20px;"> |
---|
378 | <base:zoom textarea="description" title="Description" /> |
---|
379 | </td> |
---|
380 | </tr> |
---|
381 | </table> |
---|
382 | </t:tab> |
---|
383 | </t:tabcontrol> |
---|
384 | </form> |
---|
385 | |
---|
386 | <base:buttongroup subclass="dialogbuttons"> |
---|
387 | <base:button id="btnSave" title="Save" visible="<%=writePermission%>"/> |
---|
388 | <base:button id="close" title="Cancel" visible="<%=writePermission%>"/> |
---|
389 | <base:button id="close" title="Close" visible="<%=!writePermission%>"/> |
---|
390 | </base:buttongroup> |
---|
391 | |
---|
392 | </base:body> |
---|
393 | </base:page> |
---|
394 | <% |
---|
395 | } |
---|
396 | finally |
---|
397 | { |
---|
398 | if (dc != null) dc.close(); |
---|
399 | } |
---|
400 | %> |
---|