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

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

References #330 The partition wizard has partly got a new look. Most of the changes are done in the weight section. Background functions are not implemented yet.

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