source: extensions/net.sf.basedb.reggie/trunk/resources/partitionform.jsp @ 1403

Last change on this file since 1403 was 1403, checked in by Martin Svensson, 11 years ago

References #317 Added partition registration form.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.5 KB
Line 
1<%@ page
2  pageEncoding="UTF-8"
3  session="false"
4  import="net.sf.basedb.core.User"
5  import="net.sf.basedb.core.DbControl"
6  import="net.sf.basedb.core.SessionControl"
7  import="net.sf.basedb.clients.web.Base" 
8%>
9<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
10<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
11<%
12final SessionControl sc = Base.getExistingSessionControl(request, true);
13final String ID = sc.getId();
14final float scale = Base.getScale(sc);
15DbControl dc = null;
16try
17{
18  dc = sc.newDbControl();
19  final User user = User.getById(dc, sc.getLoggedInUserId());
20%>
21<base:page type="default" >
22<base:head scripts="ajax.js" styles="path.css">
23  <link rel="stylesheet" type="text/css" href="reggie.css">
24  <script language="JavaScript" src="reggie.js" type="text/javascript" charset="UTF-8"></script>
25 
26 
27<script language="JavaScript">
28var debug = false;
29var currentStep = 1;
30
31var caseSpecimenTubes = null;
32
33var partitionDateIsValid = false;
34
35var spWeightsAreValid;
36var apWeightsAreValid;
37var hisWeightsAreValid;
38var nofPiecesAreValid;
39
40function init()
41{
42  var frm = document.forms['reggie'];
43  frm.caseName.focus();
44}
45
46function goNext()
47{
48  setInnerHTML('gonext.message', '');
49  if (currentStep == 1)
50  {   
51    gotoStep2();
52  }
53  else if (currentStep == 2)
54  {
55    if (step2IsValid()) gotoStep3();
56  }
57}
58
59function step2IsValid()
60{
61  return partitionDateIsValid;
62}
63
64function gotoStep2()
65{
66  var frm = document.forms['reggie'];
67  var caseName = frm.caseName.value;
68  if (caseName == '')
69  {
70    setInputStatus('case', 'Missing', 'invalid');
71    return;
72  }
73  setInputStatus('case', '', 'valid');
74 
75  getSpecimenTubes();
76 
77 
78  // Change section
79  frm.caseName.disabled = true;
80 
81  Main.show('partitionSection');
82  Main.show('gocancel');
83  frm.partitionDate.focus();
84  currentStep = 2;
85}
86
87function gotoStep3()
88{
89  var frm = document.forms['reggie'];
90  frm.partitionDate.disabled = true;
91  frm.partitionComment.disabled = true;
92 
93  var tubes = caseSpecimenTubes.specimen;
94  var inputWeightHtml;
95  if (tubes.length > 0)
96  {
97    spWeightsAreValid = Array(tubes.length);
98    apWeightsAreValid = Array(tubes.length);
99    hisWeightsAreValid = Array(tubes.length);
100    nofPiecesAreValid = Array(tubes.lenth);
101   
102    inputWeightHtml = '';
103    for (var i=0;i<tubes.length; i++)
104    {
105      spInputTitle = '';
106      apInputTitle = '';
107      hisInputTitle = '';
108      nofPiecesTitle = '';
109      if (i==0)
110      {
111        spInputTitle = 'Sp<br>';
112        apInputTitle = 'Ap<br>';
113        hisInputTitle = 'His<br>';
114        nofPiecesTitle = 'NofPieces<br>';
115      }
116      inputWeightHtml += '<tr>';
117      inputWeightHtml += '<td class="prompt">Specimen tube '+caseSpecimenTubes.name+'.'+(i+1)+'</td>';
118      inputWeightHtml += '<td class="input">';
119      inputWeightHtml += '<table>';     
120      inputWeightHtml += '<tr>';
121      inputWeightHtml += '<td>' + spInputTitle + '<input size=4 type="text" onChange="spWeightOnChange('+i+')" name="spWeight'+i+'" /></td>';
122      inputWeightHtml += '<td>' + apInputTitle + '<input size=4 type="text" onChange="apWeightOnChange('+i+')" name="apWeight'+i+'" /></td>';
123      inputWeightHtml += '<td>' + hisInputTitle + '<input size=4 type="text" onChange="hisWeightOnChange('+i+')" name="hisWeight'+i+'" /></td>';
124      inputWeightHtml += '<td>' + nofPiecesTitle + '<input size=4 type="text" onChange="nofPiecesOnChange('+i+')" name="nofPieces'+i+'" /></td>';
125      inputWeightHtml += '</tr>';
126      inputWeightHtml += '</table>';
127      inputWeightHtml += '</td>';
128      inputWeightHtml += '<td id="weight'+i+'.status" class="status"></td>';
129      inputWeightHtml += '<td class="help">';
130      inputWeightHtml += '<span id="weight'+i+'.message" class="message" style="display:none;"></span>';
131      inputWeightHtml += 'Weights should be given in [mg]</td>';
132      inputWeightHtml += '</tr>';
133     
134    }   
135    setInnerHTML('weightInputs', inputWeightHtml);
136  }
137  Main.show('weightSection');
138  Main.hide('gonext');
139  Main.show('gocreate');
140  frm.spWeight0.focus();
141}
142
143function updateInputStatus(tubeIndex)
144{
145  if (spWeightsAreValid[tubeIndex] == false)
146  {
147    setInputStatus('weight'+tubeIndex, 'SpWeight is invalid','invalid');
148    return;
149  }
150  if(apWeightsAreValid[tubeIndex] == false)
151  {
152    setInputStatus('weight'+tubeIndex, 'APWeight is invalid', 'invalid');
153    return;
154  }
155  if(hisWeightsAreValid[tubeIndex] == false)
156  {
157    setInputStatus('weight'+tubeIndex, 'HisWeight is invalid', 'invalid');
158    return;
159  }
160  if(nofPiecesAreValid[tubeIndex] == false)
161  {
162    setInputStatus('weight'+tubeIndex, 'NofPieces is invalid', 'invalid');
163    return;
164  }
165  setInputStatus('weight'+tubeIndex, '', 'valid');
166}
167
168function spWeightOnChange(tubeIndex)
169{
170  var inputName = 'spWeight'+tubeIndex;
171  var frm = document.forms['reggie'];
172  var weightInput = frm.elements[inputName].value;
173  if (weightInput != '')
174  {
175    if (weightInput < 0)
176    {
177      spWeightsAreValid[tubeIndex] = false;
178      updateInputStatus(tubeIndex);
179      return;
180    }
181    if (weightInput == '0')
182    {
183      frm.elements[inputName].value = '';
184    }
185  } 
186  spWeightsAreValid[tubeIndex] = true;
187  updateInputStatus(tubeIndex);
188}
189
190function apWeightOnChange(tubeIndex)
191{
192  var inputName = 'apWeight'+tubeIndex;
193  var frm = document.forms['reggie'];
194  var weightInput = frm.elements[inputName].value;
195  if (weightInput != '')
196  {
197    if (weightInput < 0)
198    {
199      apWeightsAreValid[tubeIndex] = false;
200      updateInputStatus(tubeIndex);
201      return;
202    } 
203    if (weightInput == '0')
204    {
205      frm.elements[inputName].value = '';
206    } 
207  } 
208  apWeightsAreValid[tubeIndex] = true;
209  updateInputStatus(tubeIndex);
210}
211
212function hisWeightOnChange(tubeIndex)
213{
214  var inputName = 'hisWeight'+tubeIndex;
215  var frm = document.forms['reggie'];
216  var weightInput = frm.elements[inputName].value;
217  if (weightInput != '')
218  {
219    if (weightInput < 0)
220    {
221      hisWeightsAreValid[tubeIndex] = false;
222      updateInputStatus(tubeIndex);
223      return;
224    }
225    if (weightInput == '0')
226    {
227      frm.elements[inputName].value = '';
228    }   
229  } 
230  hisWeightsAreValid[tubeIndex] = true;
231  updateInputStatus(tubeIndex);
232}
233
234function nofPiecesOnChange(tubeIndex)
235{
236  var inputName = 'nofPieces'+tubeIndex;
237  var frm = document.forms['reggie'];
238  var fieldInput = frm.elements[inputName].value;
239  if (fieldInput != '')
240  {
241    if (fieldInput < 0)
242    {
243      nofPiecesAreValid[tubeIndex] = false;
244      updateInputStatus(tubeIndex);
245      return;
246    } 
247    if (fieldInput == '0')
248    {
249      frm.elements[inputName].value = '';
250    } 
251  } 
252  nofPiecesAreValid[tubeIndex] = true;
253  updateInputStatus(tubeIndex);
254}
255
256function partitionDateOnBlur()
257{
258  var frm = document.forms['reggie'];
259  var partitionDate = frm.partitionDate.value;
260  var todaysDate = new Date();
261  partitionDateIsValid = false;
262 
263  setInputStatus('partitionDate', '', '');
264 
265  if (partitionDate != '')
266  {
267    partitionDate = autoFillDate(partitionDate);
268    frm.partitionDate.value = partitionDate;
269   
270    if (!Dates.isDate(partitionDate, 'yyyyMMdd'))
271    {
272      setInputStatus('partitionDate', 'Not a valid date', 'invalid');
273      return;
274    }
275    if (todaysDate < new Date(partitionDate.substring(0,4), partitionDate.substring(4,6), partitionDate.substring(6)))
276    {
277      setInputStatus('partitionDate', 'Future dates are not valid','invalid');
278      return;
279    }
280    setInputStatus('partitionDate','','valid');   
281  }
282  else
283  {
284    setInputStatus('partitionDate', 'Missing', 'warning');
285  }
286  partitionDateIsValid = true;
287}
288
289function getSpecimenTubes()
290{
291  var frm = document.forms['reggie']; 
292  var caseName = frm.caseName.value;
293  var request = Ajax.getXmlHttpRequest();
294  var url = 'PartitionRegistration.servlet?ID=<%=ID%>&cmd=GetSpecimenTubes';
295  url += '&caseName=' + caseName;
296  request.open("GET", url, false);
297  request.send(null);
298
299  if (debug) Main.debug(request.responseText);
300
301  var response = JSON.parse(request.responseText);
302  if (response.status != 'ok')
303  {
304    setFatalError(response.message);
305    return false;
306  }
307  caseSpecimenTubes = response.caseInfo;
308}
309</script>
310
311
312</base:head>
313<base:body onload="init()">
314<p:path style="margin-top: 20px; margin-bottom: 10px;">
315    <p:pathelement title="Reggie" href="<%="index.jsp?ID="+ID%>" />
316    <p:pathelement title="Partition registration" />
317  </p:path>
318
319  <%
320  if (sc.getActiveProjectId() == 0)
321  {
322    %>
323    <base:note type="warning" style="width: 800px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
324      No project has been selected. You may proceed with the registration but
325      created items will not be shared.
326    </base:note>
327    <%
328  }
329  %>
330
331  <form name="reggie" onsubmit="return false;">
332 
333  <!-- 1. Case name-->
334  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
335  <tr>
336    <td rowspan="3" class="stepno">1</td>
337    <td class="steptitle">Enter Case Name</td>
338  </tr>
339  <tr>
340    <td class="stepfields">
341      <table border="0" cellspacing="0" cellpadding="0" width="100%">
342      <tr valign="top">
343        <td class="prompt">Case name</td>
344        <td class="input"><input type="text" name="caseName" 
345          size="18" maxlength="12" onkeypress="doOnTabOrEnter(event, goNext)"></td>
346        <td class="status" id="case.status"></td>
347        <td class="help"><span id="case.message" class="message" style="display: none;"></span>The case (barcode) associated with the partitions.</td>
348      </tr>
349      </table>
350    </td>
351  </tr>
352  </table>
353 
354  <!-- 2. General partition information -->
355  <div id="partitionSection" style="display: none;">
356    <p></p>
357    <table border="0" cellspacing="0" cellpadding="0" class="stepform">
358    <tr>
359      <td rowspan="2" class="stepno">2</td>
360      <td class="steptitle">Enter partition information</td>
361    </tr>
362    <tr>
363      <td class="stepfields">
364        <table border="0" cellspacing="0" cellpadding="0" width="100%">
365        <tr valign="top">
366          <td class="prompt">Partition date</td>
367          <td class="input"><input type="text" name="partitionDate" 
368            size="12" maxlength="10" onBlur="partitionDateOnBlur()"></td>
369          <td class="status" id="partitionDate.status"></td>
370          <td class="help"><span id="partitionDate.message" class="message" style="display: none;"></span>The date when the partition was done.</td>
371        </tr>
372        <tr valign="top">
373          <td class="prompt" id="partitionComment.prompt">Other partition comment</td>
374          <td class="input" id="partitionComment.input"><textarea rows="3" cols="30" 
375            name="partitionComment" value="" onkeypress="doOnTab(event, goNext)"></textarea></td>
376          <td class="status" id="partitionComment.status"></td>
377          <td class="help"><span id="partitionComment.message" class="message" style="display: none;"></span></td>
378        </tr>
379        </table>
380      </td>
381    </tr>
382    </table>
383  </div>
384 
385  <div id="weightSection" style="display:none;">
386    <p></p>
387    <table border="0" cellspacing="0" cellpadding="0" class="stepform">
388    <tr>
389      <td rowspan="2" class="stepno">3</td>
390      <td class="steptitle">Enter weight information</td>   
391    </tr>
392    <tr>
393      <td class="stepfields">
394        <table id="weightInputs" border="0" cellspacing="0" cellpadding="0" width="100%"></table>
395      </td>
396    </tr>
397    </table>
398  </div>
399   
400  <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
401 
402  <div id="done" class="success" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"></div>
403 
404  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
405    <tr>
406      <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td>
407      <td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext(true)"/></td>
408      <td><base:button id="gocreate" title="Create" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
409      <td><base:button id="goupdate" title="Update" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
410      <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td>
411      <td id="gonext.message" class="message"></td>
412    </tr>
413  </table>
414  </form>
415 
416</base:body>
417</base:page>
418<%
419}
420finally
421{
422  if (dc != null) dc.close();
423}
424%>
Note: See TracBrowser for help on using the repository browser.