source: trunk/www/my_base/user/preferences.jsp @ 3492

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

Fixes #578

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.9 KB
Line 
1<%-- $Id: preferences.jsp 3492 2007-06-14 08:44:39Z 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      return true;
96    }
97    function validatePlugins()
98    {
99      return true;
100    }
101    function validateMostRecent()
102    {
103      var frm = document.forms['preferences'];
104      var maxViewed = parseInt(frm.maxViewed.value);
105      if (!Numbers.isInteger(frm.maxViewed.value) || maxViewed < 0 || maxViewed > 10)
106      {
107        frm.maxViewed.focus();
108        frm.maxViewed.select();
109        alert("Please enter a value between 0 and 10.");
110        return false;
111      }
112      var maxUsed = parseInt(frm.maxUsed.value);
113      if (!Numbers.isInteger(frm.maxUsed.value) || maxUsed < 0 || maxUsed > 10)
114      {
115        frm.maxUsed.focus();
116        frm.maxUsed.select();
117        alert("Please enter a value between 0 and 10.");
118        return false;
119      }
120      return true;
121    }
122    // Changes the scale value
123    function setScale(newScale)
124    {
125      var frm = document.forms['preferences'];
126      frm.scale.value = newScale;
127    }
128    // Submit the form
129    function savePreferences()
130    {
131      var frm = document.forms['preferences'];
132      if (TabControl.validateActiveTab('settings'))
133      {
134        var sticky_items = frm.sticky_items;
135        for (var i = 0; i < sticky_items.length; i++) // >
136        {
137          sticky_items.options[i].selected = true;
138        }
139        frm.submit();
140      }
141    }
142   
143    function selectColor(title, field)
144    {
145      Main.selectColor(title, 'preferences', field, 'setColorCallback');
146    }
147   
148    function setColorCallback(form, input, color)
149    {
150      var frm = document.forms['preferences'];
151      frm[input].value = color;
152      var display = document.getElementById(input);
153      display.style.background = '#' + color;
154    }
155   
156    function presetColorOnChange()
157    {
158      var frm = document.forms['preferences'];
159      var colors = frm.presets[frm.presets.selectedIndex].value.split(',');
160      setColorCallback('preferences', 'mincolor', colors[0]);
161      setColorCallback('preferences', 'midcolor', colors[1]);
162      setColorCallback('preferences', 'maxcolor', colors[2]);
163      frm.presets.selectedIndex = 0;
164    }
165   
166    function datePresetOnChange()
167    {
168      var frm = document.forms['preferences'];
169      frm.date_format.value = frm.datePresets[frm.datePresets.selectedIndex].value;
170      frm.datePresets.selectedIndex = 0;
171    }
172   
173    function dateTimePresetOnChange()
174    {
175      var frm = document.forms['preferences'];
176      frm.datetime_format.value = frm.dateTimePresets[frm.dateTimePresets.selectedIndex].value;
177      frm.dateTimePresets.selectedIndex = 0;
178    }
179   
180    function initItemTypes()
181    {
182      var frm = document.forms['preferences'];
183      var sticky_items = frm.sticky_items;
184      var all_items = frm.all_items;
185      <%
186      String mostRecent = Values.getString(sc.getUserClientSetting("menu.mostRecent"),
187        "EXPERIMENT:BIOASSAYSET:TRANSFORMATION");
188      Set<String> current = new HashSet<String>(Arrays.asList(mostRecent.split(":")));
189      Set<Item> items = new TreeSet<Item>(new ToStringComparator<Item>(false));
190      items.addAll(Metadata.getOwnableItems());
191      items.add(Item.BIOASSAYSET);
192      for (Item item : items)
193      {
194        String list = current.contains(item.name()) ? "sticky_items" : "all_items";
195        %>
196        var option = new Option('<%=item.toString()%>', '<%=item.name()%>');
197        Forms.addListOption(<%=list%>, -1, option);
198        <%
199      }
200      %>
201    }
202   
203    // Moves all selected items in list1 to list2
204    function moveBetween(list1, list2)
205    {
206      var moved = 0;
207      for(i=0; i < list1.options.length; i++) // >
208      {
209        if (list1.options[i].selected)
210        {
211          moved++;
212          list2.options[list2.options.length] = new Option(list1.options[i].text, list1.options[i].value, false, true);
213          list1.options[i] = null;
214          i--;
215        }
216      }
217    }
218   
219    // Move all selected items in the list up or down
220    function moveSelected(list, up)
221    {
222      var moved = Forms.moveListOptions(list, up);
223    }
224    </script>
225  </base:head>
226  <base:body onload="initItemTypes()">
227  <p>
228
229  <form action="submit_user.jsp?ID=<%=ID%>" method="post" name="preferences" 
230    onsubmit="return false;">
231  <input type=hidden name="cmd" value="SavePreferences">
232  <input type="hidden" name="mincolor" value="0000FF">
233  <input type="hidden" name="midcolor" value="000000">
234  <input type="hidden" name="maxcolor" value="FFFF00">
235
236  <h3 class="docked">Preferences for <%=HTML.encodeTags(user.getName())%> <base:help tabcontrol="settings" /></h3>
237  <t:tabcontrol active="<%=activePage%>" id="settings" 
238    contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" 
239    position="bottom">
240  <t:tab 
241    id="appearance" 
242    title="Appearance" 
243    validate="validateAppearance()" 
244    helpid="userpreferences.appearance"
245    >
246    <table class="form" cellspacing=0>
247    <tr>
248      <td class="prompt">Font size</td>
249      <td>
250        <%
251        String fontsize = Values.getString(sc.getUserClientSetting("appearance.fontsize"), "size_m.css");
252        %>
253        <input type="radio" name="fontsize" value="size_xs.css" 
254          <%="size_xs.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(80)"
255          ><a href="javascript:document.forms['preferences'].fontsize[0].click()">XS</a>
256        <input type="radio" name="fontsize" value="size_s.css" 
257          <%="size_s.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(90)"
258          ><a href="javascript:document.forms['preferences'].fontsize[1].click()">S</a>
259        <input type="radio" name="fontsize" value="size_m.css" 
260          <%="size_m.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(100)"
261          ><a href="javascript:document.forms['preferences'].fontsize[2].click()">M</a>
262        <input type="radio" name="fontsize" value="size_l.css" 
263          <%="size_l.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(120)"
264          ><a href="javascript:document.forms['preferences'].fontsize[3].click()">L</a>
265        <input type="radio" name="fontsize" value="size_xl.css" 
266          <%="size_xl.css".equals(fontsize) ? "checked" : ""%> onclick="setScale(140)"
267          ><a href="javascript:document.forms['preferences'].fontsize[4].click()">XL</a>
268      </td>
269    </tr>
270    <tr>
271      <td class="prompt">Scale factor</td>
272      <td>
273        <input class="text required" type="text" name="scale" 
274        value="<%=Values.getInt(sc.getUserClientSetting("appearance.scale"), 100)%>" 
275        size="4" maxlength="3"  onkeypress="return Numbers.integerOnly(event);">%
276        (50 - 200)
277      </td>
278    </tr>
279    <tr>
280      <td class="prompt">Toolbar</td>
281      <td>
282        <input type="radio" name="toolbar" value="both" 
283          <%=hasImages && hasText ? "checked" : "" %>
284          ><a href="javascript:document.forms['preferences'].toolbar[0].click()">Images and text</a>
285        <input type="radio" name="toolbar" value="images" 
286          <%=hasImages && !hasText ? "checked" : "" %>
287          ><a href="javascript:document.forms['preferences'].toolbar[1].click()">Images only</a>
288        <input type="radio" name="toolbar" value="text" 
289          <%=!hasImages && hasText ? "checked" : "" %>
290          ><a href="javascript:document.forms['preferences'].toolbar[2].click()">Text only</a>
291      </td>
292    </tr>   
293    <tr>
294      <td class="prompt">Ratio color range</td>
295      <td>
296        <table>
297        <tr>
298        <td><a href="javascript:selectColor('Color for min value', 'mincolor')"><div 
299          id="mincolor" style="background: #<%=minColor%>;" class="colorbox"></div>Min</a></td>
300        <td><a href="javascript:selectColor('Color for midpoint value', 'midcolor')"><div 
301          id="midcolor" style="background: #<%=midColor%>;" class="colorbox"></div>Mid</a></td>
302        <td><a href="javascript:selectColor('Color for max value', 'maxcolor')"><div 
303          id="maxcolor" style="background: #<%=maxColor%>;" class="colorbox"></div>Max</td>
304       
305        <td>
306          <select name="presets" onchange="presetColorOnChange()" class="selectionlist">
307          <option value="">- presets -
308          <option value="FF0000,FFFF00,00FF00">Red - Yellow - Green
309          <option value="0000FF,FFFFFF,FFFF00">Blue - White - Yellow
310          <option value="000000,999999,FFFFFF">Black - Grey - White
311          <%
312          if (recentColors != null && recentColors.size() > 0)
313          {
314            %>
315            <option value="" class="recentheader">- recently used -
316            <%
317            for (int i = 0; i < recentColors.size(); ++i)
318            {
319              String color = recentColors.get(i);
320              %>
321              <option value="<%=color%>" class="recent"><%=color%>
322              <%
323            }
324          }
325          %>
326          </select>
327        </td>
328        </tr>
329        </table>
330      </td>
331    </tr>
332    <tr>
333      <td class="prompt">Date format</td>
334      <td>
335        <input class="text" type="text" name="date_format" 
336        value="<%=HTML.encodeTags(FormatterSettings.getDateFormat(sc))%>" 
337        size="20">
338        <select name="datePresets" onchange="datePresetOnChange()" class="selectionlist">
339          <option value="">- presets -
340          <option value="yyyy-MM-dd">yyyy-MM-dd
341          <option value="d/M/yyyy">d/M/yyyy
342          <option value="M/d/yyyy">M/d/yyyy
343          <%
344          if (recentDateFormats != null && recentDateFormats.size() > 0)
345          {
346            %>
347            <option value="" class="recentheader">- recently used -
348            <%
349            for (int i = 0; i < recentDateFormats.size(); ++i)
350            {
351              String format = HTML.encodeTags(recentDateFormats.get(i));
352              %>
353              <option value="<%=format%>" class="recent"><%=format%>
354              <%
355            }
356          }
357          %>
358        </select>
359      </td>
360    </tr>
361   
362    <tr>
363      <td class="prompt">Date-time format</td>
364      <td>
365        <input class="text" type="text" name="datetime_format" 
366        value="<%=HTML.encodeTags(FormatterSettings.getDateTimeFormat(sc))%>" 
367        size="20">
368        <select name="dateTimePresets" onchange="dateTimePresetOnChange()" class="selectionlist">
369          <option value="">- presets -
370          <option value="yyyy-MM-dd HH:mm:ss">yyyy-MM-dd HH:mm:ss
371          <option value="d/M/yyyy HH:mm:ss">d/M/yyyy HH:mm:ss
372          <option value="M/d/yyyy HH:mm:ss">M/d/yyyy HH:mm:ss
373          <%
374          if (recentDateTimeFormats != null && recentDateTimeFormats.size() > 0)
375          {
376            %>
377            <option value="" class="recentheader">- recently used -
378            <%
379            for (int i = 0; i < recentDateFormats.size(); ++i)
380            {
381              String format = HTML.encodeTags(recentDateTimeFormats.get(i));
382              %>
383              <option value="<%=format%>" class="recent"><%=format%>
384              <%
385            }
386          }
387          %>
388        </select>
389      </td>
390    </tr>
391    <%
392    int numDecimals = FormatterSettings.getNumDecimals(sc);
393    %>
394    <tr>
395      <td class="prompt">Decimals</td>
396      <td>
397        <select name="decimals">
398        <%
399        for (int i = 0; i < 8; i++)
400        {
401          %>
402          <option value="<%=i%>" <%=numDecimals == i ? "selected" : ""%>><%=i%>
403          <%
404        }
405        %>
406        <option value="-1" <%=numDecimals < 0 ? "selected" : ""%>>all
407        </select>
408      </td>
409    </tr>
410   
411    </table>
412    <div align="right">&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
413  </t:tab>
414 
415  <t:tab
416    id="plugins" 
417    title="Plugins" 
418    validate="validatePlugins()" 
419    helpid="userpreferences.plugins"
420    >
421    <table class="form" cellspacing=0>
422    <tr>
423      <td class="prompt">Messages</td>
424      <td>
425        <%
426        boolean sendMessage = Values.getBoolean(sc.getUserClientSetting("plugins.sendmessage"), true);
427        %>
428        <input type=checkbox name="sendmessage" value="1" <%=sendMessage ? "checked" : ""%>
429          ><a href="javascript:document.forms['preferences'].sendmessage.click()">Send message when plugin completes</a>
430      </td>
431    </tr>
432    <tr>
433      <td class="prompt">Remove jobs</td>     
434      <td>
435        <%
436        boolean removeJobWhenFinished = Values.getBoolean(sc.getUserClientSetting("plugins.removejob"), false);
437        %>
438        <input type="checkbox" name="removejob" value="1" <%=removeJobWhenFinished ? "checked" : "" %>>
439        <a href="javascript:document.forms['preferences'].removejob.click();">Remove import and export jobs when they are finished.</a>
440      </td>
441    </tr>
442    </table>
443  </t:tab>
444 
445  <t:tab
446    id="mostRecent"
447    title="Recent items"
448    validate="validateMostRecent()"
449    helpid="userpreferences.mostrecent"
450    tooltip="Specify how many items to remember in lists of 'most recent items'"
451    >
452    <%
453    boolean loadNames = Values.getBoolean(sc.getUserClientSetting("menu.mostRecent.loadNames"), false);
454    %>
455    <table border=0 cellspacing=0 cellpadding=2 class="form">
456    <tr valign="baseline">
457      <td class="prompt">Recently viewed items</td>
458      <td>
459        <input class="text required" type="text" name="maxViewed" 
460          value="<%=Values.getInt(sc.getUserClientSetting("menu.mostRecent.maxViewed"), 6)%>" 
461          size="4" maxlength="2"  onkeypress="return Numbers.integerOnly(event);">
462        (0 - 10)
463      </td>
464    </tr>
465    <tr>
466      <td class="prompt">Recently used items</td>
467      <td>
468        <input class="text required" type="text" name="maxUsed" 
469          value="<%=Values.getInt(sc.getUserClientSetting("appearance.recent"), 4)%>" 
470          size="4" maxlength="2"  onkeypress="return Numbers.integerOnly(event);">
471        (0 - 10)
472      </td>
473    </tr>
474    <tr>
475      <td class="prompt">Load the names of all items</td>
476      <td>
477        <input type="checkbox" name="loadNames" value="1" <%=loadNames ? "checked" : ""%>>
478      </td>
479    </tr>
480    </table>
481    <table border=0 cellspacing=0 cellpadding=2>
482   
483    <tr>
484      <td style="vertical-align: middle">
485        <br>
486        <base:button
487          onclick="moveSelected(document.forms['preferences'].sticky_items, false)" 
488          title="<img src='../../images/move_up.gif' alt='' style='vertical-align: middle;'>" 
489          tooltip="Move up" 
490        /><p>
491        <base:button 
492          onclick="moveSelected(document.forms['preferences'].sticky_items, true)" 
493          title="<img src='../../images/move_down.gif' alt='' style='vertical-align: middle;'>" 
494          tooltip="Move down" 
495        />
496        <br>
497      </td>
498      <td>
499        <b>Sticky items</b><br>
500        <select name="sticky_items" multiple size="10" style="width: 12em;"
501          ondblclick="moveBetween(document.forms['preferences'].sticky_items, document.forms['preferences'].all_items)">
502        </select>
503      </td>
504 
505      <td>
506         <br>
507        <base:button
508          onclick="moveBetween(document.forms['preferences'].all_items, document.forms['preferences'].sticky_items)" 
509          title="<img src='../../images/move_left.gif' alt='' style='vertical-align: middle;'>" 
510          tooltip="Show this item in the 'Most recent' menu" 
511        /><p>
512        <base:button 
513          onclick="moveBetween(document.forms['preferences'].sticky_items, document.forms['preferences'].all_items)" 
514          title="<img src='../../images/move_right.gif' alt='' style='vertical-align: middle;'>" 
515          tooltip="Don't show this item in the 'Most recent' menu" 
516        />
517        <br>
518      </td>
519 
520      <td>
521        <b>All items</b><br>
522        <select name="all_items" multiple size="10" style="width: 12em;" 
523          ondblclick="moveBetween(document.forms['preferences'].all_items, document.forms['preferences'].sticky_items)">
524        </select>
525      </td>
526    </tr>
527    </table>
528  </t:tab>
529  </t:tabcontrol>
530
531  <p>
532  <div align=center>
533    <table align="center">
534    <tr>
535      <td width="50%"><base:button onclick="savePreferences();" title="Save" /></td>
536      <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td>
537    </tr>
538    </table>
539  </div>
540  </form>
541  </base:body>
542  </base:page>
543  <%
544}
545finally
546{
547  if (dc != null) dc.close();
548}
549%>
Note: See TracBrowser for help on using the repository browser.