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

Last change on this file since 1420 was 1420, checked in by Martin Svensson, 10 years ago

References #330 Selection-list: Tubes available for partition does no longer include cases.
Box-info is only displayed for a selected specimen tube when the information is available.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.8 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 specimenTubes = null;
32var selectedTubes = null;
33
34var partitionDateIsValid = false;
35
36var spWeightsAreValid;
37var apWeightsAreValid;
38var hisWeightsAreValid;
39var nofPiecesAreValid;
40
41function init()
42{
43  var frm = document.forms['reggie'];
44  var selectList = frm.tubesSelect;
45  getSpecimenTubes();
46 
47  var specimenTubeOptions = '';
48  if (specimenTubes != null && specimenTubes.length > 0)
49  {
50    for (var i=0;i<specimenTubes.length;i++)
51    {
52      var tube = specimenTubes[i];
53      selectList.options[selectList.length] = new Option(tube.name, tube.name);
54    }
55  }
56  else
57  {
58    selectList.disabled = true;
59    Main.hide('gonext');   
60    setInputStatus('tubes','No tubes available for partition', 'invalid')
61  } 
62}
63
64function goNext()
65{
66  setInnerHTML('gonext.message', '');
67  if (currentStep == 1)
68  {   
69    gotoStep2();
70  }
71  else if (currentStep == 2)
72  {
73    partitionDateOnBlur();
74    if (step2IsValid()) gotoStep3();
75  }
76}
77
78function step2IsValid()
79{
80  return partitionDateIsValid;
81}
82
83function step3IsValid()
84{
85  for (var i=0; i<spWeightsAreValid.length; i++)
86  {
87    if (spWeightsAreValid[i] == false ||
88        apWeightsAreValid[i] == false ||
89        hisWeightsAreValid[i] == false ||
90        nofPiecesAreValid[i] == false)
91    {
92      return false;
93    }
94  } 
95  return true;
96}
97
98function gotoStep2()
99{
100  var frm = document.forms['reggie'];
101  var selectList = frm.tubesSelect;
102  selectedTubes = new Array();
103  for (var i=0;i<selectList.length; i++)
104  {
105    if (selectList.options[i].selected)
106      selectedTubes.push(specimenTubes[i]);
107  }   
108 
109  if (selectedTubes.length == 0)
110  {
111    setInputStatus('tubes', 'Missing', 'invalid');
112    return;
113  }
114 
115  setInputStatus('tubes', '', 'valid');
116  // Change section
117  frm.tubesSelect.disabled = true;
118 
119  Main.show('partitionSection');
120  Main.show('gocancel');
121  var currentTime = new Date();
122  frm.partitionDate.value = currentTime.getFullYear().toString()+(currentTime.getMonth()+1).toString()+currentTime.getDate().toString();
123  frm.partitionDate.setSelectionRange(0,frm.partitionDate.value.length);
124  frm.partitionDate.focus();
125  currentStep = 2;
126}
127
128function gotoStep3()
129{
130  var frm = document.forms['reggie'];
131  frm.partitionDate.disabled = true; 
132   
133  var inputWeightHtml; 
134  if (selectedTubes.length > 0)
135  {
136    spWeightsAreValid = Array();
137    apWeightsAreValid = Array();
138    hisWeightsAreValid = Array();
139    nofPiecesAreValid = Array();
140       
141    inputWeightHtml = '';
142
143    var spTitle = 'SpWeight<br>';
144    var apTitle = 'ApWeight<br>';
145    var hisTitle = 'HisWeight<br>';
146    var nofTitle = 'NofPieces<br>';
147    var appearanceTitle = 'Appearance<br>';
148    var necrosisTitle = 'Necrosis%<br>';
149    var fatTitle = 'Fat%<br>';
150    var colouredTitle = 'Coloured<br>';
151    var bloodyTitle = 'Bloody<br>';
152   
153    var appearanceOptions = '<option selected></option>'; 
154    appearanceOptions += '<option value=homogenus>Homogenus</option>';
155    appearanceOptions += '<option value=heterogenus>Heterogenus</option>';
156   
157    var necrosisOptions = '<option selected value=0>0</option>';
158    necrosisOptions += '<option value=20>20</option>';
159    necrosisOptions += '<option value=40>40</option>';
160    necrosisOptions += '<option value=60>60</option>';
161    necrosisOptions += '<option value=80>80</option>';
162    necrosisOptions += '<option value=100>100</option>';
163   
164    var fatOptions = '<option selected value=0>0</option>';
165    fatOptions += '<option value=20>20</option>';
166    fatOptions += '<option value=40>40</option>';
167    fatOptions += '<option value=60>60</option>';
168    fatOptions += '<option value=80>80</option>';
169    fatOptions += '<option value=100>100</option>';
170   
171    for (var i=0;i<selectedTubes.length; i++)
172    {
173      var tube = selectedTubes[i];
174      var nextStep = i<(selectedTubes.length-1) ? 'focusOnEnter(event, \'bloody'+(i+1)+'\')' : 'doOnTabOrEnter(event, goCreate)';
175     
176      inputWeightHtml += '<tr>';
177      inputWeightHtml += '<td rowspan=2 class=prompt>'+tube.name;
178      // Only show box information if there is something show.     
179      if (tube.row != null && tube.column != null)
180      {
181        inputWeightHtml += ' ['+tube.box+'&nbsp;'+tube.row+tube.column+']';
182      }
183      inputWeightHtml += '</td>';
184     
185      inputWeightHtml += '<td style="width:400px;">';
186      inputWeightHtml += '<table style="width:100%"><tr>';     
187      inputWeightHtml += '<td>'+bloodyTitle+'<input type=checkbox onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'appearance'+i+'\')" onfocus="messageOnFocus(0,'+i+')" name=bloody'+i+' /></td>';
188      inputWeightHtml += '<td>'+appearanceTitle+'<select name=appearance'+i+' onfocus="messageOnFocus(1,'+i+')" onkeypress="focusOnEnter(event, \'necrosis'+i+'\')">'+appearanceOptions+'</select></td>';
189      inputWeightHtml += '<td>'+necrosisTitle+'<select name=necrosis'+i+' onfocus="messageOnFocus(2,'+i+')" onkeypress="focusOnEnter(event, \'fat'+i+'\')">'+necrosisOptions+'</select></td>'; 
190      inputWeightHtml += '<td>'+fatTitle+'<select name=fat'+i+' onfocus="messageOnFocus(3,'+i+')" onkeypress="focusOnEnter(event, \'coloured'+i+'\')">'+fatOptions+'</select></td>';
191      inputWeightHtml += '<td>'+colouredTitle+'<input type=checkbox name=coloured'+i+' onfocus="messageOnFocus(4,'+i+')" onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'nofPieces'+i+'\')" /></td>'
192      inputWeightHtml += '<td>'+nofTitle+'<input name="nofPieces'+i+'" onfocus="messageOnFocus(5,'+i+')" onchange="nofPiecesOnChange('+i+')" onkeypress="focusOnEnter(event, \'spWeight'+i+'\')" size=2 /></td>';
193      inputWeightHtml += '<td>'+spTitle+'<input name="spWeight'+i+'" onfocus="messageOnFocus(6,'+i+')" onchange="spWeightOnChange('+i+')" onkeypress="focusOnEnter(event, \'hisWeight'+i+'\')" size=2 /></td>';
194      inputWeightHtml += '<td>'+hisTitle+'<input name="hisWeight'+i+'" onfocus="messageOnFocus(7,'+i+')" onchange="hisWeightOnChange('+i+')" onkeypress="focusOnEnter(event, \'apWeight'+i+'\')" size=2 /></td>';
195      inputWeightHtml += '<td>'+apTitle+'<input name="apWeight'+i+'" onfocus="messageOnFocus(8,'+i+')" onchange="apWeightOnChange('+i+')" onkeypress="'+nextStep+'" size=2 /></td>';     
196      inputWeightHtml += '</tr>';
197      inputWeightHtml += '</table>';
198      inputWeightHtml += '</td>';
199      inputWeightHtml += '<td rowspan=2 class="status" id="'+i+'.status"></td>';     
200      inputWeightHtml += '</tr>';
201     
202      inputWeightHtml += '<tr>';
203      inputWeightHtml += '<td style="width:400px;" class="help"><span class="message" id="'+i+'.message"></span><span id="'+i+'.help"></span></td>';     
204      inputWeightHtml += '</tr>';
205     
206      inputWeightHtml += '<tr><td>&nbsp;</td></tr>';
207    }
208    setInnerHTML('weightInputs', inputWeightHtml);
209  }
210  Main.show('weightSection');
211  Main.hide('gonext');
212  Main.show('gocreate');
213  frm.bloody0.focus(); 
214}
215
216function checkOnNumber(event, element)
217{
218  if (event.charCode == 48)
219  {
220    element.checked = false;
221  }
222  else if (event.charCode == 49)
223  {
224    element.checked = true;
225  }
226  return true;
227}
228
229function messageOnFocus(order, tubeIndex)
230{
231  var helpMessage;
232  switch(order)
233  {
234    case 0:
235      helpMessage = 'Check this if the partition is bloody. Unchecked is default.';
236      break;
237    case 1:
238      helpMessage = 'Select appearance. Empty is default';
239      break;
240    case 2:
241      helpMessage = 'Select percentage of necrosis. \'0\' is default.';
242      break;
243    case 3:
244      helpMessage = 'Select percentage of fat. \'0\' is default.';
245      break;
246    case 4:
247      helpMessage = 'Check this if the partition is coloured. Unchecked is default.';
248      break;
249    case 5:
250      helpMessage = 'Number of pieces in this partition.';
251      break;
252    case 6:
253      helpMessage = 'Sp weight in [mg].';
254      break;
255    case 7:
256      helpMessage = 'His weight in [mg].';
257      break;
258    case 8:
259      helpMessage = 'Ap weight in [mg].';
260      break;
261    default:
262      helpMessage='&nbsp;';
263  }
264  for (var i=0;i<selectedTubes.length;i++)
265  {
266    if (i!=tubeIndex) setInnerHTML(i+'.help', '&nbsp;')
267  }
268  setInnerHTML(tubeIndex+'.help', helpMessage); 
269}
270
271function updateInputStatus(tubeIndex)
272{
273  var frm = document.forms['reggie'];
274  if(nofPiecesAreValid[tubeIndex] == false)
275  {
276    setInputStatus(tubeIndex, 'NofPieces is invalid.', 'invalid');
277    frm.elements['nofPieces'+tubeIndex].focus();
278    return ;
279  }
280  if (spWeightsAreValid[tubeIndex] == false)
281  {
282    setInputStatus(tubeIndex, 'SpWeight is invalid.','invalid');
283    return;
284  }
285  if(hisWeightsAreValid[tubeIndex] == false)
286  {
287    setInputStatus(tubeIndex, 'HisWeight is invalid.', 'invalid');
288    return;
289  }
290  if(apWeightsAreValid[tubeIndex] == false)
291  {
292    setInputStatus(tubeIndex, 'APWeight is invalid.', 'invalid');
293    return;
294  }   
295  setInputStatus(tubeIndex, '', 'valid');
296}
297
298function spWeightOnChange(tubeIndex)
299{
300  var inputName = 'spWeight'+tubeIndex;
301  var frm = document.forms['reggie'];
302  var weightInput = frm.elements[inputName].value;
303  if (weightInput != '')
304  {
305    if (weightInput < 0)
306    {
307      spWeightsAreValid[tubeIndex] = false;
308      updateInputStatus(tubeIndex);
309      return;
310    }
311    if (weightInput == '0')
312    {
313      frm.elements[inputName].value = '';
314    }
315  } 
316  spWeightsAreValid[tubeIndex] = true;
317  updateInputStatus(tubeIndex);
318}
319
320function apWeightOnChange(tubeIndex)
321{
322  var inputName = 'apWeight'+tubeIndex;
323  var frm = document.forms['reggie'];
324  var weightInput = frm.elements[inputName].value;
325  if (weightInput != '')
326  {
327    if (weightInput < 0)
328    {
329      apWeightsAreValid[tubeIndex] = false;
330      updateInputStatus(tubeIndex);
331      return;
332    } 
333    if (weightInput == '0')
334    {
335      frm.elements[inputName].value = '';
336    } 
337  }
338  apWeightsAreValid[tubeIndex] = true;
339  updateInputStatus(tubeIndex);
340}
341
342function hisWeightOnChange(tubeIndex)
343{
344  var inputName = 'hisWeight'+tubeIndex;
345  var frm = document.forms['reggie'];
346  var weightInput = frm.elements[inputName].value;
347  if (weightInput != '')
348  {
349    if (weightInput < 0)
350    {
351      hisWeightsAreValid[tubeIndex] = false;
352      updateInputStatus(tubeIndex);
353      return;
354    }
355    if (weightInput == '0')
356    {
357      frm.elements[inputName].value = '';
358    }   
359  } 
360  hisWeightsAreValid[tubeIndex] = true;
361  updateInputStatus(tubeIndex);
362}
363
364function nofPiecesOnChange(tubeIndex)
365{
366  var inputName = 'nofPieces'+tubeIndex;
367  var frm = document.forms['reggie'];
368  var fieldInput = frm.elements[inputName].value;
369  if (fieldInput != '')
370  {
371    if (fieldInput < 0)
372    {
373      nofPiecesAreValid[tubeIndex] = false;
374      updateInputStatus(tubeIndex);
375      return;
376    } 
377    if (fieldInput == '0')
378    {
379      frm.elements[inputName].value = '';
380    } 
381  } 
382  nofPiecesAreValid[tubeIndex] = true;
383  updateInputStatus(tubeIndex);
384}
385
386function partitionDateOnBlur()
387{
388  var frm = document.forms['reggie'];
389  var partitionDate = frm.partitionDate.value;
390  var todaysDate = new Date();
391  partitionDateIsValid = false;
392 
393  setInputStatus('partitionDate', '', '');
394 
395  if (partitionDate != '')
396  {
397    partitionDate = autoFillDate(partitionDate);
398    frm.partitionDate.value = partitionDate;
399   
400    if (!Dates.isDate(partitionDate, 'yyyyMMdd'))
401    {
402      setInputStatus('partitionDate', 'Not a valid date', 'invalid');
403      return;
404    }   
405    if (todaysDate < new Date(partitionDate.substring(0,4), new Number(partitionDate.substring(4,6)-1), partitionDate.substring(6)))
406    {
407      setInputStatus('partitionDate', 'Future dates are not valid','invalid');
408      return;
409    }
410    setInputStatus('partitionDate','','valid');   
411  }
412  else
413  {
414    setInputStatus('partitionDate', 'Missing', 'invalid');
415    return;
416  }
417  partitionDateIsValid = true;
418}
419
420function getSpecimenTubes()
421{
422  var frm = document.forms['reggie']; 
423 
424  var request = Ajax.getXmlHttpRequest();
425  var url = 'PartitionRegistration.servlet?ID=<%=ID%>&cmd=GetSpecimenTubes';   
426  request.open("GET", url, false); 
427  request.send(null);
428
429  if (debug) Main.debug(request.responseText); 
430  var response = JSON.parse(request.responseText); 
431  if (response.status != 'ok')
432  {
433    setFatalError(response.message);
434    return false;
435  } 
436  specimenTubes = response.tubeInfo.specimenTubes;
437}
438
439function goCreate()
440{
441  alert('goCreate');
442  if (!step3IsValid()) return;
443 
444  Main.hide('gocancel');
445  Main.hide('gocreate');
446  var frm = document.forms['reggie'];
447 
448  var specimens = caseInfo.specimen;
449  var nofTubes = specimens.length;
450  var partitionDateValue = frm.elements['partitionDate'].value;
451  //var partitionCommentValue = frm.elements['partitionComment'].value;
452  caseInfo.partitionDate = partitionDateValue;
453//  if (partitionCommentValue != null) caseInfo.otherPartitionComment = partitionCommentValue;
454 
455  for (var i=0; i<nofTubes; i++)
456  {
457    frm.elements['spWeight'+i].disabled = true;
458    frm.elements['apWeight'+i].disabled = true;
459    frm.elements['hisWeight'+i].disabled = true;
460    frm.elements['nofPieces'+i].disabled = true;
461   
462    var specimenTube = specimens[i];
463   
464    var spWeightValue = frm.elements['spWeight'+i].value; 
465    if (spWeightValue != '') specimenTube.spWeight = spWeightValue;
466    var apWeightValue = frm.elements['apWeight'+i].value;
467    if (apWeightValue != '') specimenTube.apWeight = apWeightValue;
468    var hisWeightValue = frm.elements['hisWeight'+i].value;
469    if (hisWeightValue != '') specimenTube.hisWeight = hisWeightValue;
470    var nofPiecesValue = frm.elements['nofPieces'+i].value;
471    if (nofPiecesValue != '') specimenTube.nofPieces = nofPiecesValue;
472   
473    caseInfo.specimen[i] = specimenTube;   
474  } 
475  var submitInfo = new Object();
476  submitInfo.caseInfo = caseInfo;
477 
478  if (debug) Main.debug(JSON.stringify(caseInfo));
479 
480  var request = Ajax.getXmlHttpRequest();
481  var url = 'PartitionRegistration.servlet?ID=<%=ID%>&cmd=CreatePartitions';
482  request.open("POST", url, false);
483  request.setRequestHeader("Content-Type", "application/json");
484  request.send(JSON.stringify(submitInfo));
485
486  if (debug) Main.debug(request.responseText);
487
488  var response = JSON.parse(request.responseText);
489  if (response.status != 'ok')
490  {
491    setFatalError(response.message);
492    return false;
493  }
494
495  var msg = '<ul>';
496  for (var i = 0; i < response.messages.length; i++)
497  {
498    msg += '<li>' + response.messages[i];
499  }
500  msg += '</ul>';
501  setInnerHTML('done', msg);
502 
503 
504  Main.show('done');
505  Main.show('gorestart');
506}
507</script>
508
509
510</base:head>
511<base:body onload="init()">
512<p:path style="margin-top: 20px; margin-bottom: 10px;">
513    <p:pathelement title="Reggie" href="<%="index.jsp?ID="+ID%>" />
514    <p:pathelement title="Partition registration" />
515  </p:path>
516
517  <%
518  if (sc.getActiveProjectId() == 0)
519  {
520    %>
521    <base:note type="warning" style="width: 800px; margin-left: 20px; margin-bottom: 20px; margin-right: 0px; font-weight: bold; color: #cc0000;">
522      No project has been selected. You may proceed with the registration but
523      created items will not be shared.
524    </base:note>
525    <%
526  }
527  %>
528
529  <form name="reggie" onsubmit="return false;">
530 
531  <!-- 1. Case name-->
532  <table border="0" cellspacing="0" cellpadding="0" class="stepform">
533  <tr>
534    <td rowspan="3" class="stepno">1</td>
535    <td class="steptitle">Select specimen tubes</td>
536  </tr>
537  <tr>
538    <td class="stepfields">
539      <table border="0" cellspacing="0" cellpadding="0" width="100%">
540      <tr valign="top">
541        <td class="prompt">Specimen tubes</td>
542        <td class="input"><select style="width:50%" name="tubeSelect" id="tubesSelect" multiple="multiple" size="5" onkeypress='doOnTab(event, goNext)'></select></td>
543        <td class="status" id="tubes.status"></td>
544        <td class="help"><span id="tubes.message" class="message" style="display: none;"></span>Select specimen tubes to include in the partition.</td>
545      </tr>
546      </table>
547    </td>
548  </tr>
549  </table>
550 
551  <!-- 2. General partition information -->
552  <div id="partitionSection" style="display: none;">
553    <p></p>
554    <table border="0" cellspacing="0" cellpadding="0" class="stepform">
555    <tr>
556      <td rowspan="2" class="stepno">2</td>
557      <td class="steptitle">Enter partition information</td>
558    </tr>
559    <tr>
560      <td class="stepfields">
561        <table border="0" cellspacing="0" cellpadding="0" width="100%">
562        <tr valign="top">
563          <td class="prompt">Partition date</td>
564          <td class="input"><input type="text" name="partitionDate" 
565             onkeypress="doOnTabOrEnter(event, goNext)" size="12" maxlength="10" onBlur="partitionDateOnBlur()"></td>
566          <td class="status" id="partitionDate.status"></td>
567          <td class="help"><span id="partitionDate.message" class="message" style="display: none;"></span>The date when the partition was done.</td>
568        </tr>       
569        </table>
570      </td>
571    </tr>
572    </table>
573  </div>
574 
575  <div id="weightSection" style="display:none;">
576    <p></p>
577    <table border="0" cellspacing="0" cellpadding="0" class="stepform">
578    <tr>
579      <td rowspan="2" class="stepno">3</td>
580      <td class="steptitle">Enter weight information</td>   
581    </tr>
582    <tr>
583      <td class="stepfields">
584        <table id="weightInputs" border="0" cellspacing="0" cellpadding="0" width="100%"></table>
585      </td>
586    </tr>
587    </table>
588  </div>
589   
590  <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
591 
592  <div id="done" class="success" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"></div>
593 
594  <table style="margin-left: 20px; margin-top: 10px;" class="navigation">
595    <tr>
596      <td><base:button id="gocancel" title="Cancel" onclick="goRestart(false)" style="display: none;"/></td>
597      <td><base:button id="gonext" title="Next" image="gonext.gif" onclick="goNext(true)"/></td>
598      <td><base:button id="gocreate" title="Create" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
599      <td><base:button id="goupdate" title="Update" image="gonext.gif" onclick="goCreate()" style="display: none;"/></td>
600      <td><base:button id="gorestart" title="Restart" image="goback.gif" onclick="goRestart(true)" style="display: none;"/></td>
601      <td id="gonext.message" class="message"></td>
602    </tr>
603  </table>
604  </form>
605 
606</base:body>
607</base:page>
608<%
609}
610finally
611{
612  if (dc != null) dc.close();
613}
614%>
Note: See TracBrowser for help on using the repository browser.