source: branches/2.2.2/www/my_base/user/preferences.jsp @ 3138

Last change on this file since 3138 was 3138, checked in by Nicklas Nordborg, 16 years ago

Fixes #497: Floating point numbers with leading zeroes in the decimal part are not correctly displayed

Also added an option in the File/Preferences?... dialog to allow a user to specify the number
of decimals to display. This solves the 0.004 issue. Another (better) solution would be to make
it possible to specify a default number of decimals to display for each annotation type. But it
requires a lot more work and should be a tast of it's own.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.7 KB
Line 
1<%-- $Id: preferences.jsp 3138 2007-02-20 07:34:13Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  This page is used to display and modify the preferences for
25  the logged in user. It displays a tabbed dialogue:
26
27  @param page
28    The name active page of the tabbed dialog.
29    - appearance: Font sizes, scale factor, etc.
30
31  Saving the form invokes the submit_user.jsp page with cmd=SavePreferences
32
33  @author Nicklas
34  @version 2.0
35--%>
36<%@ page session="false"
37  import="net.sf.basedb.core.SessionControl"
38  import="net.sf.basedb.core.Item"
39  import="net.sf.basedb.core.DbControl"
40  import="net.sf.basedb.core.User"
41  import="net.sf.basedb.core.Metadata"
42  import="net.sf.basedb.core.ItemContext"
43  import="net.sf.basedb.core.Permission"
44  import="net.sf.basedb.util.ToStringComparator"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.clients.web.util.HTML"
47  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
48  import="net.sf.basedb.util.Values"
49  import="java.util.List"
50  import="java.util.Set"
51  import="java.util.TreeSet"
52  import="java.util.HashSet"
53  import="java.util.Arrays"
54%>
55<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
56<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
57<%
58final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
59final String ID = sc.getId();
60final float scale = Base.getScale(sc);
61final String activePage = request.getParameter("page");
62final DbControl dc = sc.newDbControl();
63try
64{
65  final User user = User.getById(dc, sc.getLoggedInUserId());
66 
67  final boolean hasImages = Values.getBoolean(sc.getUserClientSetting("toolbar.images"), true);
68  final boolean hasText = Values.getBoolean(sc.getUserClientSetting("toolbar.text"), true);
69 
70  final String minColor = Values.getString(sc.getUserClientSetting("ratiocolor.min"), "0000FF");
71  final String midColor = Values.getString(sc.getUserClientSetting("ratiocolor.mid"), "FFFFFF");
72  final String maxColor = Values.getString(sc.getUserClientSetting("ratiocolor.max"), "FFFF00");
73 
74  ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
75  List<String> recentColors = cc.getRecent("colors");
76  List<String> recentDateFormats = cc.getRecent("dateFormats");
77  List<String> recentDateTimeFormats = cc.getRecent("dateTimeFormats");
78  %>
79
80  <base:page type="popup" title="<%="Preferences for "+HTML.encodeTags(user.getName())%>">
81  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
82    <script language="JavaScript">
83    // Validate the Appearance tab
84    function validateAppearance()
85    {
86      var frm = document.forms['preferences'];
87      var scale = parseInt(frm.scale.value);
88      if (!Numbers.isInteger(frm.scale.value) || scale < 50 || scale > 200)
89      {
90        frm.scale.focus();
91        frm.scale.select();
92        alert("Please enter a scale value between 50 and 200.");
93        return false;
94      }
95      var recent = parseInt(frm.recent.value);
96      if (!Numbers.isInteger(frm.recent.value) || recent < 0 || recent > 10)
97      {
98        frm.recent.focus();
99        frm.recent.select();
100        alert("Please enter a value between 0 and 10.");
101        return false;
102      }
103      return true;
104    }
105    function validatePlugins()
106    {
107      return true;
108    }
109    function validateMostRecent()
110    {
111      return true;
112    }
113    // Changes the scale value
114    function setScale(newScale)
115    {
116      var frm = document.forms['preferences'];
117      frm.scale.value = newScale;
118    }
119    // Submit the form
120    function savePreferences()
121    {
122      var frm = document.forms['preferences'];
123      if (TabControl.validateActiveTab('settings'))
124      {
125        var enabled = frm.enabled;
126        for (var i = 0; i < enabled.length; i++) // >
127        {
128          enabled.options[i].selected = true;
129        }
130        frm.submit();
131      }
132    }
133   
134    function selectColor(title, field)
135    {
136      Main.selectColor(title, 'preferences', field, 'setColorCallback');
137    }
138   
139    function setColorCallback(form, input, color)
140    {
141      var frm = document.forms['preferences'];
142      frm[input].value = color;
143      var display = document.getElementById(input);
144      display.style.background = '#' + color;
145    }
146   
147    function presetColorOnChange()
148    {
149      var frm = document.forms['preferences'];
150      var colors = frm.presets[frm.presets.selectedIndex].value.split(',');
151      setColorCallback('preferences', 'mincolor', colors[0]);
152      setColorCallback('preferences', 'midcolor', colors[1]);
153      setColorCallback('preferences', 'maxcolor', colors[2]);
154      frm.presets.selectedIndex = 0;
155    }
156   
157    function datePresetOnChange()
158    {
159      var frm = document.forms['preferences'];
160      frm.date_format.value = frm.datePresets[frm.datePresets.selectedIndex].value;
161      frm.datePresets.selectedIndex = 0;
162    }
163   
164    function dateTimePresetOnChange()
165    {
166      var frm = document.forms['preferences'];
167      frm.datetime_format.value = frm.dateTimePresets[frm.dateTimePresets.selectedIndex].value;
168      frm.dateTimePresets.selectedIndex = 0;
169    }
170   
171    function initItemTypes()
172    {
173      var frm = document.forms['preferences'];
174      var enabled = frm.enabled;
175      var disabled = frm.disabled;
176      <%
177      String mostRecent = Values.getString(sc.getUserClientSetting("menu.mostRecent"),
178        "EXPERIMENT:BIOASSAYSET:TRANSFORMATION");
179      Set<String> current = new HashSet<String>(Arrays.asList(mostRecent.split(":")));
180      Set<Item> items = new TreeSet<Item>(new ToStringComparator<Item>(false));
181      items.addAll(Metadata.getOwnableItems());
182      items.add(Item.BIOASSAYSET);
183      for (Item item : items)
184      {
185        String list = current.contains(item.name()) ? "enabled" : "disabled";
186        %>
187        var option = new Option('<%=item.toString()%>', '<%=item.name()%>');
188        Forms.addListOption(<%=list%>, -1, option);
189        <%
190      }
191      %>
192    }
193   
194    // Moves all selected items in list1 to list2
195    function moveBetween(list1, list2)
196    {
197      var moved = 0;
198      for(i=0; i < list1.options.length; i++) // >
199      {
200        if (list1.options[i].selected)
201        {
202          moved++;
203          list2.options[list2.options.length] = new Option(list1.options[i].text, list1.options[i].value, false, true);
204          list1.options[i] = null;
205          i--;
206        }
207      }
208    }
209   
210    // Move all selected items in the list up or down
211    function moveSelected(list, up)
212    {
213      var moved = Forms.moveListOptions(list, up);
214    }
215    </script>
216  </base:head>
217  <base:body onload="initItemTypes()">
218  <p>
219
220  <form action="submit_user.jsp?ID=<%=ID%>" method="post" name="preferences" 
221    onsubmit="return false;">
222  <input type=hidden name="cmd" value="SavePreferences">
223  <input type="hidden" name="mincolor" value="0000FF">
224  <input type="hidden" name="midcolor" value="000000">
225  <input type="hidden" name="maxcolor" value="FFFF00">
226
227  <h3 class="docked">Preferences for <%=HTML.encodeTags(user.getName())%> <base:help tabcontrol="settings" /></h3>
228  <t:tabcontrol active="<%=activePage%>" id="settings" 
229    contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" 
230    position="bottom">
231  <t:tab 
232    id="appearance" 
233    title="Appearance" 
234    validate="validateAppearance()" 
235    helpid="userpreferences.appearance"
236    >
237    <table class="form" cellspacing=0>
238    <tr>
239      <td class="prompt">Font size</td>
240      <td>
241        <%
242        String fontsize = Values.getString(sc.getUserClientSetting("appearance.fontsize"), "size_m.css");
243        %>
244        <input type="radio" name="fontsize" value="size_xs.css" 
245          <%="size_xs.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(80)"
246          ><a href="javascript:document.forms['preferences'].fontsize[0].click()">XS</a>
247        <input type="radio" name="fontsize" value="size_s.css" 
248          <%="size_s.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(90)"
249          ><a href="javascript:document.forms['preferences'].fontsize[1].click()">S</a>
250        <input type="radio" name="fontsize" value="size_m.css" 
251          <%="size_m.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(100)"
252          ><a href="javascript:document.forms['preferences'].fontsize[2].click()">M</a>
253        <input type="radio" name="fontsize" value="size_l.css" 
254          <%="size_l.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(120)"
255          ><a href="javascript:document.forms['preferences'].fontsize[3].click()">L</a>
256        <input type="radio" name="fontsize" value="size_xl.css" 
257          <%="size_xl.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(140)"
258          ><a href="javascript:document.forms['preferences'].fontsize[4].click()">XL</a>
259      </td>
260    </tr>
261    <tr>
262      <td class="prompt">Scale factor</td>
263      <td>
264        <input class="text required" type="text" name="scale" 
265        value="<%=Values.getInt(sc.getUserClientSetting("appearance.scale"), 100)%>" 
266        size="4" maxlength="3"  onkeypress="return Numbers.integerOnly(event);">%
267        (50 - 200)
268      </td>
269    </tr>
270    <tr>
271      <td class="prompt">Toolbar</td>
272      <td>
273        <input type="radio" name="toolbar" value="both" 
274          <%=hasImages && hasText ? "checked" : "" %>
275          ><a href="javascript:document.forms['preferences'].toolbar[0].click()">Images and text</a>
276        <input type="radio" name="toolbar" value="images" 
277          <%=hasImages && !hasText ? "checked" : "" %>
278          ><a href="javascript:document.forms['preferences'].toolbar[1].click()">Images only</a>
279        <input type="radio" name="toolbar" value="text" 
280          <%=!hasImages && hasText ? "checked" : "" %>
281          ><a href="javascript:document.forms['preferences'].toolbar[2].click()">Text only</a>
282      </td>
283    </tr>
284    <tr>
285      <td class="prompt">Recently used items</td>
286      <td>
287        <input class="text required" type="text" name="recent" 
288          value="<%=Values.getInt(sc.getUserClientSetting("appearance.recent"), 4)%>" 
289          size="4" maxlength="2"  onkeypress="return Numbers.integerOnly(event);">
290        (0 - 10)
291      </td>
292    </tr>
293   
294    <tr>
295      <td class="prompt">Ratio color range</td>
296      <td>
297        <table>
298        <tr>
299        <td><a href="javascript:selectColor('Color for min value', 'mincolor')"><div 
300          id="mincolor" style="background: #<%=minColor%>;" class="colorbox"></div>Min</a></td>
301        <td><a href="javascript:selectColor('Color for midpoint value', 'midcolor')"><div 
302          id="midcolor" style="background: #<%=midColor%>;" class="colorbox"></div>Mid</a></td>
303        <td><a href="javascript:selectColor('Color for max value', 'maxcolor')"><div 
304          id="maxcolor" style="background: #<%=maxColor%>;" class="colorbox"></div>Max</td>
305       
306        <td>
307          <select name="presets" onchange="presetColorOnChange()" class="selectionlist">
308          <option value="">- presets -
309          <option value="FF0000,FFFF00,00FF00">Red - Yellow - Green
310          <option value="0000FF,FFFFFF,FFFF00">Blue - White - Yellow
311          <option value="000000,999999,FFFFFF">Black - Grey - White
312          <%
313          if (recentColors != null && recentColors.size() > 0)
314          {
315            %>
316            <option value="" class="recentheader">- recently used -
317            <%
318            for (int i = 0; i < recentColors.size(); ++i)
319            {
320              String color = recentColors.get(i);
321              %>
322              <option value="<%=color%>" class="recent"><%=color%>
323              <%
324            }
325          }
326          %>
327          </select>
328        </td>
329        </tr>
330        </table>
331      </td>
332    </tr>
333    <tr>
334      <td class="prompt">Date format</td>
335      <td>
336        <input class="text" type="text" name="date_format" 
337        value="<%=HTML.encodeTags(FormatterSettings.getDateFormat(sc))%>" 
338        size="20">
339        <select name="datePresets" onchange="datePresetOnChange()" class="selectionlist">
340          <option value="">- presets -
341          <option value="yyyy-MM-dd">yyyy-MM-dd
342          <option value="d/M/yyyy">d/M/yyyy
343          <option value="M/d/yyyy">M/d/yyyy
344          <%
345          if (recentDateFormats != null && recentDateFormats.size() > 0)
346          {
347            %>
348            <option value="" class="recentheader">- recently used -
349            <%
350            for (int i = 0; i < recentDateFormats.size(); ++i)
351            {
352              String format = HTML.encodeTags(recentDateFormats.get(i));
353              %>
354              <option value="<%=format%>" class="recent"><%=format%>
355              <%
356            }
357          }
358          %>
359        </select>
360      </td>
361    </tr>
362   
363    <tr>
364      <td class="prompt">Date-time format</td>
365      <td>
366        <input class="text" type="text" name="datetime_format" 
367        value="<%=HTML.encodeTags(FormatterSettings.getDateTimeFormat(sc))%>" 
368        size="20">
369        <select name="dateTimePresets" onchange="dateTimePresetOnChange()" class="selectionlist">
370          <option value="">- presets -
371          <option value="yyyy-MM-dd hh:mm:ss">yyyy-MM-dd hh:mm:ss
372          <option value="d/M/yyyy hh:mm:ss">d/M/yyyy hh:mm:ss
373          <option value="M/d/yyyy hh:mm:ss">M/d/yyyy hh:mm:ss
374          <%
375          if (recentDateTimeFormats != null && recentDateTimeFormats.size() > 0)
376          {
377            %>
378            <option value="" class="recentheader">- recently used -
379            <%
380            for (int i = 0; i < recentDateFormats.size(); ++i)
381            {
382              String format = HTML.encodeTags(recentDateTimeFormats.get(i));
383              %>
384              <option value="<%=format%>" class="recent"><%=format%>
385              <%
386            }
387          }
388          %>
389        </select>
390      </td>
391    </tr>
392    <%
393    int numDecimals = FormatterSettings.getNumDecimals(sc);
394    %>
395    <tr>
396      <td class="prompt">Decimals</td>
397      <td>
398        <select name="decimals">
399        <%
400        for (int i = 0; i < 8; i++)
401        {
402          %>
403          <option value="<%=i%>" <%=numDecimals == i ? "selected" : ""%>><%=i%>
404          <%
405        }
406        %>
407        <option value="-1" <%=numDecimals < 0 ? "selected" : ""%>>all
408        </select>
409      </td>
410    </tr>
411   
412    </table>
413    <div align="right">&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
414  </t:tab>
415 
416  <t:tab
417    id="plugins" 
418    title="Plugins" 
419    validate="validatePlugins()" 
420    helpid="userpreferences.plugins"
421    >
422    <table class="form" cellspacing=0>
423    <tr>
424      <td class="prompt">Messages</td>
425      <td>
426        <%
427        boolean sendMessage = Values.getBoolean(sc.getUserClientSetting("plugins.sendmessage"), true);
428        %>
429        <input type=checkbox name="sendmessage" value="1" <%=sendMessage ? "checked" : ""%>
430          ><a href="javascript:document.forms['preferences'].sendmessage.click()">Send message when plugin completes</a>
431      </td>
432    </tr>
433    </table>
434  </t:tab>
435 
436  <t:tab
437    id="mostRecent"
438    title="Most recent"
439    validate="validateMostRecent()"
440    helpid="userpreferences.mostrecent"
441    tooltip="Specify which items should be shown in the 'Most recent' menu."
442    >
443    <table border=0 cellspacing=0 cellpadding=2>
444    <tr>
445      <td style="vertical-align: middle">
446        <br>
447        <base:button
448          onclick="moveSelected(document.forms['preferences'].enabled, false)" 
449          title="<img src='../../images/move_up.gif' alt='' style='vertical-align: middle;'>" 
450          tooltip="Move up" 
451        /><p>
452        <base:button 
453          onclick="moveSelected(document.forms['preferences'].enabled, true)" 
454          title="<img src='../../images/move_down.gif' alt='' style='vertical-align: middle;'>" 
455          tooltip="Move down" 
456        />
457        <br>
458      </td>
459      <td>
460        <b>Show in 'Most recent' menu</b><br>
461        <select name="enabled" multiple size="14" style="width: 12em;"
462          ondblclick="moveBetween(document.forms['preferences'].enabled, document.forms['preferences'].disabled)">
463        </select>
464      </td>
465 
466      <td>
467         <br>
468        <base:button
469          onclick="moveBetween(document.forms['preferences'].disabled, document.forms['preferences'].enabled)" 
470          title="<img src='../../images/move_left.gif' alt='' style='vertical-align: middle;'>" 
471          tooltip="Show this item in the 'Most recent' menu" 
472        /><p>
473        <base:button 
474          onclick="moveBetween(document.forms['preferences'].enabled, document.forms['preferences'].disabled)" 
475          title="<img src='../../images/move_right.gif' alt='' style='vertical-align: middle;'>" 
476          tooltip="Don't show this item in the 'Most recent' menu" 
477        />
478        <br>
479      </td>
480 
481      <td>
482        <b>Don't show</b><br>
483        <select name="disabled" multiple size="14" style="width: 12em;" 
484          ondblclick="moveBetween(document.forms['preferences'].disabled, document.forms['preferences'].enabled)">
485        </select>
486      </td>
487    </tr>
488    </table>
489    <%
490    boolean loadNames = Values.getBoolean(sc.getUserClientSetting("menu.mostRecent.loadNames"), false);
491    %>
492    <input type="checkbox" name="loadNames" value="1" <%=loadNames ? "checked" : ""%>> 
493      <a href="javascript:document.forms['preferences'].loadNames.click()"
494        >Load the names of all recent items</a>
495  </t:tab>
496  </t:tabcontrol>
497
498  <p>
499  <div align=center>
500    <table align="center">
501    <tr>
502      <td width="50%"><base:button onclick="savePreferences();" title="Save" /></td>
503      <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td>
504    </tr>
505    </table>
506  </div>
507  </form>
508  </base:body>
509  </base:page>
510  <%
511}
512finally
513{
514  if (dc != null) dc.close();
515}
516%>
Note: See TracBrowser for help on using the repository browser.