source: trunk/www/lims/arrayslides/create_wizard.jsp @ 5136

Last change on this file since 5136 was 5136, checked in by Nicklas Nordborg, 13 years ago

Merged patch release 2.13.1 to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.9 KB
Line 
1<%-- $Id: create_wizard.jsp 5136 2009-10-15 06:33:07Z nicklas $
2  ------------------------------------------------------------------
3  BioArray Software Environment (BASE) - http://base.thep.lu.se/
4  Copyright (C) 2006 Johan Enell, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE.
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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Martin
23  @version 2.0
24--%>
25
26
27
28<%@ page session="false"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.SystemItems"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.Include"
36  import="net.sf.basedb.core.ArraySlide"
37  import="net.sf.basedb.core.ArrayBatch" 
38  import="net.sf.basedb.core.PermissionDeniedException"
39  import="net.sf.basedb.core.BaseException"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.util.HTML"
44  import="net.sf.basedb.util.Values"
45  import="java.util.List"
46 
47%>
48<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
49<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
50<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
51<%
52final Item itemType = Item.ARRAYSLIDE;
53final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
54final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
55final int itemId = cc.getId();
56final String ID = sc.getId();
57final String cmd = request.getParameter("cmd");
58final float scale = Base.getScale(sc);
59final DbControl dc = sc.newDbControl();
60
61try
62{ 
63  String title = null;
64  ArraySlide slide = null;
65  String name = "New slides.";
66 
67  boolean readCurrentArrayBatch = true;
68  ArrayBatch currentArrayBatch = null;
69 
70  // Load recently used items
71  List<ArrayBatch> recentArrayBatches = (List<ArrayBatch>)cc.getRecent(dc, Item.ARRAYBATCH);
72
73  title = "Create array slides";
74  cc.removeObject("item");
75  int arrayBatchId = Values.getInt(request.getParameter("arraybatch_id"));
76  if (arrayBatchId != 0)
77  {
78    currentArrayBatch = ArrayBatch.getById(dc, arrayBatchId);
79  }
80  else if (cc.getPropertyFilter("arrayBatch.name") != null)
81  {
82    currentArrayBatch = Base.getFirstMatching(dc, ArrayBatch.getQuery(), "name", cc.getPropertyFilter("arrayBatch.name"));
83  }
84  if (currentArrayBatch != null)
85  {
86    name = HTML.encodeTags(currentArrayBatch.getName()) + ".";
87  }
88
89  if (slide != null && !slide.hasPermission(Permission.WRITE))
90  {
91    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
92  }
93  final String clazz = "class=\"text\"";
94  final String requiredClazz = "class=\"text required\""; 
95  %>
96
97  <base:page type="popup" title="<%=title%>">
98  <base:head scripts="tabcontrol.js" styles="tabcontrol.css,toolbar.css">
99    <script language="JavaScript">
100    // Validate the "ArraySlide" tab
101    function validateArraySlide()
102    {
103      var frm = document.forms['WizardStep1'];
104      if (Main.trimString(frm.name.value) == '')
105      {
106        alert("You must enter a name");
107        frm.name.focus();
108        return false;
109      }
110      if (frm.arraybatch_id && 
111        (frm.arraybatch_id.length == 0 || frm.arraybatch_id[frm.arraybatch_id.selectedIndex].value == 0))
112      {
113        alert("You must select an array batch");
114        return false;
115      }
116      if (Main.trimString(frm.quantity.value) == '')
117      {
118        alert("You must enter a quantity of slides.");
119        frm.quantity.focus();
120        return false;
121      }
122      if (frm.quantity.value < 1)
123      {
124        alert("The quantity of array slides to be created must be at least 1.")
125        frm.quantity.value = 1;
126        frm.quantity.select();
127        return false;
128      }
129      else if (frm.quantity.value > 999)
130      {
131        alert("The quantity of array slides to be created must be lower than 1000.")
132        frm.quantity.value = 1;
133        frm.quantity.select();
134        return false;
135      }
136      return true;
137    }
138   
139    function validateNames()
140    {
141      var frm = document.forms['WizardStep2'];
142      var quantity = parseInt(frm.quantity.value);
143      for (i = 0; i < quantity; i++)
144      {
145        var name = frm['name'+i];
146        if (Main.trimString(name.value) == '')
147        {
148          name.focus();
149          alert('You must enter a name for slide ' + i);
150          return false;
151        }
152      }
153      return true;
154    }
155   
156    // Submit the step 1 form and continue to step 2
157    function nextStep()
158    {     
159      if (validateArraySlide())
160      {
161        var frm = document.forms['WizardStep1'];
162        frm.submit();
163      }
164    }   
165    // Submit and finish the wizard
166    function saveSettings()
167    {
168      if (validateNames())
169      {
170        var frm = document.forms['WizardStep2'];   
171        frm.submit();
172      }
173    }
174
175    function selectArrayBatchOnClick()
176    {
177      var frm = document.forms['WizardStep1'];
178      var url = '../../lims/arraybatches/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setArrayBatchCallback';
179      if (frm.arraybatch_id.length > 0) url += '&item_id='+frm.arraybatch_id[0].value;
180      Main.openPopup(url, 'SelectArrayBatch', 1000, 700);
181    }
182    function setArrayBatchCallback(id, name)
183    {
184      var frm = document.forms['WizardStep1'];
185      var list = frm.arraybatch_id;
186      if (list.length < 1 || list[0].value == '0') // >
187      {
188        Forms.addListOption(list, 0, new Option());
189      }
190      list[0].value = id;
191      list[0].text = name;
192      list.selectedIndex = 0;
193    }
194   
195    function pasteMultiple(prefix)
196    {
197      Main.openPopup('paste_multiple.jsp?ID=<%=ID%>&form=WizardStep2&prefix=' + prefix, 'PasteMultiple', 500, 600);
198    }
199
200    function clearAll(prefix)
201    {
202      var frm = document.forms['WizardStep2'];
203      var i = 0;
204      var field;
205      while(field = frm[prefix+i])
206      {
207        field.value = '';
208        i++;
209      }
210    }
211   
212    function init()
213    {         
214      var frm = document.forms['WizardStep1'];
215      if (frm != null)
216      {
217        frm.name.focus();
218        frm.name.select();
219      }
220      else
221      {
222        frm = document.forms['WizardStep2'];
223        frm.barcode1.focus();
224      }
225    }
226    </script>
227  </base:head>
228  <base:body onload="init()">
229    <%
230    //Wizard step1
231    if (cmd.equals("WizardStep1"))
232    {
233    %>       
234      <p>
235      <form action="create_wizard.jsp?ID=<%=ID%>" method="post" name="WizardStep1" onsubmit="return false;">
236      <input type="hidden" name="cmd" value="WizardStep2">
237     
238      <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
239      <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
240        position="bottom" remember="false">
241      <t:tab id="info" title="Array slides" validate="validateArraySlide()" 
242        helpid="arrayslide.createwizard.1">
243        <table class="form" cellspacing=0>
244        <tr>
245          <td class="prompt">Name</td>
246          <td><input <%=requiredClazz%> type="text" name="name"
247            value="<%=name%>"
248            size="40" maxlength="<%=ArraySlide.MAX_NAME_LENGTH%>"></td>
249        </tr>
250        <tr>
251          <td class="prompt">Array batch</td>
252          <td>
253            <base:select 
254              id="arraybatch_id"
255              clazz="selectionlist required"
256              required="true"
257              current="<%=currentArrayBatch%>"
258              denied="<%=!readCurrentArrayBatch%>"
259              recent="<%=recentArrayBatches%>"
260              newitem="true"
261              onselect="selectArrayBatchOnClick()"
262            />
263          </td>
264        </tr>
265        <tr>
266          <td class="prompt">Quantity</td>
267          <td><input <%=requiredClazz%> type="text" name="quantity" value="50" 
268            size="12" maxlength="3" 
269            onkeypress="return Numbers.integerOnly(event)"><i> (1-999)</i></td>
270        </tr>
271        <tr>
272          <td class="prompt">Start at</td>
273          <td><input <%=clazz%> type="text" name="start_at" value="1" 
274            size="12" maxlength="10" 
275            onkeypress="return Numbers.integerOnly(event)">
276            <b>Pad size</b>
277            <input <%=clazz%> type="text" name="pad_length" value="" 
278            size="12" maxlength="1" 
279            onkeypress="return Numbers.integerOnly(event)">
280            <br>
281            The index number will be padded with zeroes to this length
282            (ie, 1 --&gt; Slide.001; 10 --&gt; Slide.010).<br>
283            Leave empty for automatic selection.
284          </td>
285        </tr>
286        <tr>
287          <td class="prompt" valign="top">Description</td>
288          <td nowrap>
289            <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
290              ><%=HTML.encodeTags(cc.getPropertyValue("description"))%></textarea>
291            <a href="javascript:Main.zoom('Description', 'WizardStep1', 'description')"
292              title="Edit in larger window"><base:icon image="zoom.gif" /></a>
293          </td>
294        </tr>
295        </table>
296        <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
297      </t:tab>
298      </t:tabcontrol>     
299      </form>
300    <%
301    }
302    //Wizard step 2
303    else if (cmd.equals("WizardStep2"))
304    {
305      name = Values.getStringOrNull(request.getParameter("name"));
306      String description = Values.getString(request.getParameter("description"), "");
307      arrayBatchId = Values.getInt(request.getParameter("arraybatch_id"));
308      int quantity = Values.getInt(request.getParameter("quantity"));
309      int startAt = Values.getInt(request.getParameter("start_at"), 1);
310      %>   
311      <p>
312      <form action="index.jsp?ID=<%=ID%>" method="post" name="WizardStep2" onsubmit="return false;">       
313      <input type="hidden" name="cmd" value="CreateItems">
314      <input type="hidden" name="description" value="<%=HTML.encodeTags(description)%>">
315      <input type="hidden" name="arraybatch_id" value="<%=arrayBatchId%>">
316      <input type="hidden" name="quantity" value="<%=quantity%>">
317      <input type="hidden" name="start_at" value="<%=startAt%>">
318           
319      <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
320      <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
321        position="bottom" remember="false">
322      <t:tab id="barcodes" title="Names and barcodes" validate="validateArraySlide()" 
323        helpid="arrayslide.createwizard.2">
324        <table class="form" cellspacing=0>
325          <tr>
326            <td>&nbsp;</td>
327            <td class="prompt">Name:
328              <base:icon image="paste.png" onclick="pasteMultiple('name')" 
329                tooltip="Paste multiple values in a single large textarea" />
330              <base:icon image="clear_down.png" onclick="clearAll('name')" 
331                tooltip="Clear all values" />
332            </td>
333            <td class="prompt">Barcode:
334              <base:icon image="paste.png" onclick="pasteMultiple('barcode')" 
335                tooltip="Paste multiple values in a single large textarea" />
336              <base:icon image="clear_down.png" onclick="clearAll('barcode')" 
337                tooltip="Clear all values" />
338            </td>
339          </tr>
340          <%
341          int padLength = Values.getInt(request.getParameter("pad_length"));
342          if (padLength == 0)
343          {
344            int lastIndex = startAt + quantity - 1;
345            padLength = (int)Math.log10(lastIndex) + 1;
346          }
347          for (int i = 0; i < quantity; i++)
348          {
349            int index = startAt + i;
350            String paddedName = name + net.sf.basedb.util.MD5.leftPad(String.valueOf(index), '0', padLength);
351            %>
352            <tr>
353              <td class="prompt"><%=index%></td>
354              <td><input type="text" <%=requiredClazz%> name="name<%=i%>" 
355                value="<%=paddedName%>" size="40" maxlength="<%=ArraySlide.MAX_NAME_LENGTH%>"></td>
356              <td><input <%=clazz%> type="text" name="barcode<%=i%>" 
357                size="40" maxlength="<%=ArraySlide.MAX_BARCODE_LENGTH%>">
358              </td>             
359            </tr>
360            <%
361          }
362          %>
363        </table>
364      </t:tab>
365      </t:tabcontrol>
366      </form>
367    <%
368    }
369    %>   
370    <base:buttongroup align="center">
371      <base:button onclick="saveSettings();" title="Save" image="save.gif" visible="<%=cmd.equals("WizardStep2")%>" />
372      <base:button onclick="nextStep();" title="Next" image="gonext.gif" visible="<%=cmd.equals("WizardStep1")%>" />
373      <base:button onclick="window.close();" title="Cancel" image="cancel.gif" />
374    </base:buttongroup>
375  </base:body>
376  </base:page>
377<%
378}
379finally
380{
381  if (dc != null) dc.close();
382}
383%>
Note: See TracBrowser for help on using the repository browser.