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

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

References #330 The partition wizard is now ready for testing. No more known bugs/issues exists.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.6 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 step3IsValid()
65{
66  for (var i=0; i<spWeightsAreValid.length; i++)
67  {
68    if (spWeightsAreValid[i] == false ||
69        apWeightsAreValid[i] == false ||
70        hisWeightsAreValid[i] == false ||
71        nofPiecesAreValid[i] == false)
72    {
73      return false;
74    }
75  } 
76  return true;
77}
78
79function gotoStep2()
80{
81  var frm = document.forms['reggie'];
82  var caseName = frm.caseName.value;
83  if (caseName == '')
84  {
85    setInputStatus('case', 'Missing', 'invalid');
86    return;
87  }
88  setInputStatus('case', '', 'valid');
89 
90  getSpecimenTubes();
91 
92 
93  // Change section
94  frm.caseName.disabled = true;
95 
96  Main.show('partitionSection');
97  Main.show('gocancel');
98  frm.partitionDate.focus();
99  currentStep = 2;
100}
101
102function gotoStep3()
103{
104  var frm = document.forms['reggie'];
105  frm.partitionDate.disabled = true;
106  frm.partitionComment.disabled = true;
107 
108  var tubes = caseInfo.specimen;
109  var inputWeightHtml;
110  if (tubes.length > 0)
111  {
112    spWeightsAreValid = Array(tubes.length);
113    apWeightsAreValid = Array(tubes.length);
114    hisWeightsAreValid = Array(tubes.length);
115    nofPiecesAreValid = Array(tubes.lenth);
116   
117   
118    inputWeightHtml = '';
119    inputWeightHtml +='<tr>';
120    inputWeightHtml += '<td class="prompt">Specimen tube</td>';
121    inputWeightHtml += '<td><table class="prompt" style=width:90% class="input"><tr><td style=width:25%>Sp</td><td style=width:25%>Ap</td><td style=width:25%>His</td><td style=width:25%>NofPieces</td></tr></table></td>';
122    inputWeightHtml += '<td>&nbsp;</td><td>&nbsp;</td>';
123    inputWeightHtml +='</tr>';
124    for (var i=0;i<tubes.length; i++)
125    {
126      spWeightsAreValid[i] = true;
127      apWeightsAreValid[i] = true;
128      hisWeightsAreValid[i] = true;
129      nofPiecesAreValid[i] = true;
130     
131      spInputTitle = '';
132      apInputTitle = '';
133      hisInputTitle = '';
134      nofPiecesTitle = '';
135     
136      var doOnTab = i==(tubes.length-1) ? 'doOnTab(event, goCreate)' : 'focusOnEnter(event, \'spWeight'+(i+1)+'\')';
137      inputWeightHtml += '<tr>';
138      inputWeightHtml += '<td class="subprompt">'+caseInfo.name+'.'+(i+1)+' ['+tubes[i].box+'&nbsp;'+tubes[i].row+tubes[i].column+']</td>';
139      inputWeightHtml += '<td class="input">';
140      inputWeightHtml += '<table style=width:90%>';     
141      inputWeightHtml += '<tr>';
142      inputWeightHtml += '<td>' + spInputTitle + '<input size=3 type="text" onkeypress="focusOnEnter(event, \'apWeight'+i+'\')" onChange="spWeightOnChange('+i+')" name="spWeight'+i+'" /></td>';
143      inputWeightHtml += '<td>' + apInputTitle + '<input size=3 type="text" onkeypress="focusOnEnter(event, \'hisWeight'+i+'\')" onChange="apWeightOnChange('+i+')" name="apWeight'+i+'" /></td>';
144      inputWeightHtml += '<td>' + hisInputTitle + '<input size=3 type="text" onkeypress="focusOnEnter(event, \'nofPieces'+i+'\')" onChange="hisWeightOnChange('+i+')" name="hisWeight'+i+'" /></td>';
145      inputWeightHtml += '<td>' + nofPiecesTitle + '<input size=3 type="text" onkeypress="'+doOnTab+'" onChange="nofPiecesOnChange('+i+')" name="nofPieces'+i+'" /></td>';
146      inputWeightHtml += '</tr>';
147      inputWeightHtml += '</table>';
148      inputWeightHtml += '</td>';
149      inputWeightHtml += '<td id="weight'+i+'.status" class="status"></td>';
150      inputWeightHtml += '<td class="help">';
151      inputWeightHtml += '<span id="weight'+i+'.message" class="message" style="display:none;"></span>';
152      inputWeightHtml += 'Weights should be given in [mg]</td>';
153      inputWeightHtml += '</tr>';     
154    }   
155    setInnerHTML('weightInputs', inputWeightHtml);
156  }
157  Main.show('weightSection');
158  Main.hide('gonext');
159  Main.show('gocreate');
160  frm.spWeight0.focus();
161}
162
163function updateInputStatus(tubeIndex)
164{
165  if (spWeightsAreValid[tubeIndex] == false)
166  {
167    setInputStatus('weight'+tubeIndex, 'SpWeight is invalid','invalid');
168    return;
169  }
170  if(apWeightsAreValid[tubeIndex] == false)
171  {
172    setInputStatus('weight'+tubeIndex, 'APWeight is invalid', 'invalid');
173    return;
174  }
175  if(hisWeightsAreValid[tubeIndex] == false)
176  {
177    setInputStatus('weight'+tubeIndex, 'HisWeight is invalid', 'invalid');
178    return;
179  }
180  if(nofPiecesAreValid[tubeIndex] == false)
181  {
182    setInputStatus('weight'+tubeIndex, 'NofPieces is invalid', 'invalid');
183    return;
184  }
185  setInputStatus('weight'+tubeIndex, '', 'valid');
186}
187
188function spWeightOnChange(tubeIndex)
189{
190  var inputName = 'spWeight'+tubeIndex;
191  var frm = document.forms['reggie'];
192  var weightInput = frm.elements[inputName].value;
193  if (weightInput != '')
194  {
195    if (weightInput < 0)
196    {
197      spWeightsAreValid[tubeIndex] = false;
198      updateInputStatus(tubeIndex);
199      return;
200    }
201    if (weightInput == '0')
202    {
203      frm.elements[inputName].value = '';
204    }
205  } 
206  spWeightsAreValid[tubeIndex] = true;
207  updateInputStatus(tubeIndex);
208}
209
210function apWeightOnChange(tubeIndex)
211{
212  var inputName = 'apWeight'+tubeIndex;
213  var frm = document.forms['reggie'];
214  var weightInput = frm.elements[inputName].value;
215  if (weightInput != '')
216  {
217    if (weightInput < 0)
218    {
219      apWeightsAreValid[tubeIndex] = false;
220      updateInputStatus(tubeIndex);
221      return;
222    } 
223    if (weightInput == '0')
224    {
225      frm.elements[inputName].value = '';
226    } 
227  }
228  apWeightsAreValid[tubeIndex] = true;
229  updateInputStatus(tubeIndex);
230}
231
232function hisWeightOnChange(tubeIndex)
233{
234  var inputName = 'hisWeight'+tubeIndex;
235  var frm = document.forms['reggie'];
236  var weightInput = frm.elements[inputName].value;
237  if (weightInput != '')
238  {
239    if (weightInput < 0)
240    {
241      hisWeightsAreValid[tubeIndex] = false;
242      updateInputStatus(tubeIndex);
243      return;
244    }
245    if (weightInput == '0')
246    {
247      frm.elements[inputName].value = '';
248    }   
249  } 
250  hisWeightsAreValid[tubeIndex] = true;
251  updateInputStatus(tubeIndex);
252}
253
254function nofPiecesOnChange(tubeIndex)
255{
256  var inputName = 'nofPieces'+tubeIndex;
257  var frm = document.forms['reggie'];
258  var fieldInput = frm.elements[inputName].value;
259  if (fieldInput != '')
260  {
261    if (fieldInput < 0)
262    {
263      nofPiecesAreValid[tubeIndex] = false;
264      updateInputStatus(tubeIndex);
265      return;
266    } 
267    if (fieldInput == '0')
268    {
269      frm.elements[inputName].value = '';
270    } 
271  } 
272  nofPiecesAreValid[tubeIndex] = true;
273  updateInputStatus(tubeIndex);
274}
275
276function partitionDateOnBlur()
277{
278  var frm = document.forms['reggie'];
279  var partitionDate = frm.partitionDate.value;
280  var todaysDate = new Date();
281  partitionDateIsValid = false;
282 
283  setInputStatus('partitionDate', '', '');
284 
285  if (partitionDate != '')
286  {
287    partitionDate = autoFillDate(partitionDate);
288    frm.partitionDate.value = partitionDate;
289   
290    if (!Dates.isDate(partitionDate, 'yyyyMMdd'))
291    {
292      setInputStatus('partitionDate', 'Not a valid date', 'invalid');
293      return;
294    }   
295    if (todaysDate < new Date(partitionDate.substring(0,4), new Number(partitionDate.substring(4,6)-1), partitionDate.substring(6)))
296    {
297      setInputStatus('partitionDate', 'Future dates are not valid','invalid');
298      return;
299    }
300    setInputStatus('partitionDate','','valid');   
301  }
302  else
303  {
304    setInputStatus('partitionDate', 'Missing', 'invalid');
305    return;
306  }
307  partitionDateIsValid = true;
308}
309
310function getSpecimenTubes()
311{
312  var frm = document.forms['reggie']; 
313  var caseName = frm.caseName.value;
314  var request = Ajax.getXmlHttpRequest();
315  var url = 'PartitionRegistration.servlet?ID=<%=ID%>&cmd=GetSpecimenTubes';
316  url += '&caseName=' + caseName;
317  request.open("GET", url, false);
318  request.send(null);
319
320  if (debug) Main.debug(request.responseText);
321
322  var response = JSON.parse(request.responseText);
323  if (response.status != 'ok')
324  {
325    setFatalError(response.message);
326    return false;
327  }
328  caseInfo = response.caseInfo;
329}
330
331function goCreate()
332{
333  if (!step3IsValid()) return;
334 
335  Main.hide('gocancel');
336  Main.hide('gocreate');
337  var frm = document.forms['reggie'];
338 
339  var specimens = caseInfo.specimen;
340  var nofTubes = specimens.length;
341  var partitionDateValue = frm.elements['partitionDate'].value;
342  var partitionCommentValue = frm.elements['partitionComment'].value;
343  caseInfo.partitionDate = partitionDateValue;
344  if (partitionCommentValue != null) caseInfo.otherPartitionComment = partitionCommentValue;
345 
346  for (var i=0; i<nofTubes; i++)
347  {
348    frm.elements['spWeight'+i].disabled = true;
349    frm.elements['apWeight'+i].disabled = true;
350    frm.elements['hisWeight'+i].disabled = true;
351    frm.elements['nofPieces'+i].disabled = true;
352   
353    var specimenTube = specimens[i];
354   
355    var spWeightValue = frm.elements['spWeight'+i].value; 
356    if (spWeightValue != '') specimenTube.spWeight = spWeightValue;
357    var apWeightValue = frm.elements['apWeight'+i].value;
358    if (apWeightValue != '') specimenTube.apWeight = apWeightValue;
359    var hisWeightValue = frm.elements['hisWeight'+i].value;
360    if (hisWeightValue != '') specimenTube.hisWeight = hisWeightValue;
361    var nofPiecesValue = frm.elements['nofPieces'+i].value;
362    if (nofPiecesValue != '') specimenTube.nofPieces = nofPiecesValue;
363   
364    caseInfo.specimen[i] = specimenTube;   
365  } 
366  var submitInfo = new Object();
367  submitInfo.caseInfo = caseInfo;
368 
369  if (debug) Main.debug(JSON.stringify(caseInfo));
370 
371  var request = Ajax.getXmlHttpRequest();
372  var url = 'PartitionRegistration.servlet?ID=<%=ID%>&cmd=CreatePartitions';
373  request.open("POST", url, false);
374  request.setRequestHeader("Content-Type", "application/json");
375  request.send(JSON.stringify(submitInfo));
376
377  if (debug) Main.debug(request.responseText);
378
379  var response = JSON.parse(request.responseText);
380  if (response.status != 'ok')
381  {
382    setFatalError(response.message);
383    return false;
384  }
385
386  var msg = '<ul>';
387  for (var i = 0; i < response.messages.length; i++)
388  {
389    msg += '<li>' + response.messages[i];
390  }
391  msg += '</ul>';
392  setInnerHTML('done', msg);
393 
394 
395  Main.show('done');
396  Main.show('gorestart');
397}
398</script>
399
400
401</base:head>
402<base:body onload="init()">
403<p:path style="margin-top: 20px; margin-bottom: 10px;">
404    <p:pathelement title="Reggie" href="<%="index.jsp?ID="+ID%>" />
405    <p:pathelement title="Partition registration" />
406  </p:path>
407
408  <%
409  if (sc.getActiveProjectId() == 0)
410  {
411    %>
412    <base:note type="warning" style="width: 800px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
413      No project has been selected. You may proceed with the registration but
414      created items will not be shared.
415    </base:note>
416    <%
417  }
418  %>
419
420  <form name="reggie" onsubmit="return false;">
421 
422  <!-- 1. Case name-->
423  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
424  <tr>
425    <td rowspan="3" class="stepno">1</td>
426    <td class="steptitle">Enter Case Name</td>
427  </tr>
428  <tr>
429    <td class="stepfields">
430      <table border="0" cellspacing="0" cellpadding="0" width="100%">
431      <tr valign="top">
432        <td class="prompt">Case name</td>
433        <td class="input"><input type="text" name="caseName" 
434          size="18" maxlength="12" onkeypress="doOnTabOrEnter(event, goNext)"></td>
435        <td class="status" id="case.status"></td>
436        <td class="help"><span id="case.message" class="message" style="display: none;"></span>The case (barcode) associated with the partitions.</td>
437      </tr>
438      </table>
439    </td>
440  </tr>
441  </table>
442 
443  <!-- 2. General partition information -->
444  <div id="partitionSection" style="display: none;">
445    <p></p>
446    <table border="0" cellspacing="0" cellpadding="0" class="stepform">
447    <tr>
448      <td rowspan="2" class="stepno">2</td>
449      <td class="steptitle">Enter partition information</td>
450    </tr>
451    <tr>
452      <td class="stepfields">
453        <table border="0" cellspacing="0" cellpadding="0" width="100%">
454        <tr valign="top">
455          <td class="prompt">Partition date</td>
456          <td class="input"><input type="text" name="partitionDate" 
457             onkeypress="focusOnEnter(event, 'partitionComment')" size="12" maxlength="10" onBlur="partitionDateOnBlur()"></td>
458          <td class="status" id="partitionDate.status"></td>
459          <td class="help"><span id="partitionDate.message" class="message" style="display: none;"></span>The date when the partition was done.</td>
460        </tr>
461        <tr valign="top">
462          <td class="prompt" id="partitionComment.prompt">Other partition comment</td>
463          <td class="input" id="partitionComment.input"><textarea rows="3" cols="30" 
464            name="partitionComment" value="" onkeypress="doOnTab(event, goNext)"></textarea></td>
465          <td class="status" id="partitionComment.status"></td>
466          <td class="help"><span id="partitionComment.message" class="message" style="display: none;"></span></td>
467        </tr>
468        </table>
469      </td>
470    </tr>
471    </table>
472  </div>
473 
474  <div id="weightSection" style="display:none;">
475    <p></p>
476    <table border="0" cellspacing="0" cellpadding="0" class="stepform">
477    <tr>
478      <td rowspan="2" class="stepno">3</td>
479      <td class="steptitle">Enter weight information</td>   
480    </tr>
481    <tr>
482      <td class="stepfields">
483        <table id="weightInputs" border="0" cellspacing="0" cellpadding="0" width="100%"></table>
484      </td>
485    </tr>
486    </table>
487  </div>
488   
489  <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
490 
491  <div id="done" class="success" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"></div>
492 
493  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
494    <tr>
495      <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td>
496      <td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext(true)"/></td>
497      <td><base:button id="gocreate" title="Create" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
498      <td><base:button id="goupdate" title="Update" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
499      <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td>
500      <td id="gonext.message" class="message"></td>
501    </tr>
502  </table>
503  </form>
504 
505</base:body>
506</base:page>
507<%
508}
509finally
510{
511  if (dc != null) dc.close();
512}
513%>
Note: See TracBrowser for help on using the repository browser.