Changeset 1532
- Timestamp:
- Feb 7, 2012, 2:58:02 PM (11 years ago)
- Location:
- extensions/net.sf.basedb.reggie/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/trunk/resources/partitionform.jsp
r1530 r1532 39 39 var oneOrMoreWeightsAreSet; 40 40 var nofPiecesAreValid; 41 var isRestoringFromLocalStorage = false; // A flag to keep track of what is happening 41 42 42 43 function init() … … 52 53 { 53 54 var tube = specimenTubes[i]; 54 selectList.options[selectList.length] = new Option(tube.name, tube.name); 55 var storeInfo = getStoredInfo(tube.id); 56 selectList.options[selectList.length] = new Option(tube.name + (storeInfo ? ' [*]' : ''), tube.name, storeInfo ? true : false); 55 57 } 56 58 } … … 189 191 } 190 192 191 inputWeightHtml = ' ';193 inputWeightHtml = '<table border="0" cellspacing="0" cellpadding="0" width="100%">'; 192 194 var spTitle = 'SpWeight<br>'; 193 195 var apTitle = 'ApWeight<br>'; … … 226 228 var tube = selectedTubes[i]; 227 229 var nextStep = i<(selectedTubes.length-1) ? 'focusOnEnter(event, \'bloody'+(i+1)+'\')' : ''; 228 230 229 231 inputWeightHtml += '<tr>'; 230 232 inputWeightHtml += '<td rowspan=2 class=prompt>'+tube.name; … … 238 240 inputWeightHtml += '<td style="width:400px;">'; 239 241 inputWeightHtml += '<table style="width:100%"><tr>'; 240 inputWeightHtml += '<td>'+bloodyTitle+'<input type=checkbox onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'appearance'+i+'\')" on focus="messageOnFocus(0,'+i+')" name=bloody'+i+' /></td>';241 inputWeightHtml += '<td>'+appearanceTitle+'<select name=appearance'+i+' onfocus="messageOnFocus(1,'+i+')" on keypress="focusOnEnter(event, \'necrosis'+i+'\')">'+appearanceOptions+'</select></td>';242 inputWeightHtml += '<td>'+necrosisTitle+'<select name=necrosis'+i+' onfocus="messageOnFocus(2,'+i+')" on keypress="focusOnEnter(event, \'fat'+i+'\')">'+necrosisOptions+'</select></td>';243 inputWeightHtml += '<td>'+fatTitle+'<select name=fat'+i+' onfocus="messageOnFocus(3,'+i+')" on keypress="focusOnEnter(event, \'coloured'+i+'\')">'+fatOptions+'</select></td>';244 inputWeightHtml += '<td>'+colouredTitle+'<input type=checkbox name=coloured'+i+' onfocus="messageOnFocus(4,'+i+')" on keypress="checkOnNumber(event, this);focusOnEnter(event, \'nofPieces'+i+'\')" /></td>'242 inputWeightHtml += '<td>'+bloodyTitle+'<input type=checkbox onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'appearance'+i+'\')" onchange="saveToLocalStorage('+i+')" onfocus="messageOnFocus(0,'+i+')" name=bloody'+i+' /></td>'; 243 inputWeightHtml += '<td>'+appearanceTitle+'<select name=appearance'+i+' onfocus="messageOnFocus(1,'+i+')" onchange="saveToLocalStorage('+i+')" onkeypress="focusOnEnter(event, \'necrosis'+i+'\')">'+appearanceOptions+'</select></td>'; 244 inputWeightHtml += '<td>'+necrosisTitle+'<select name=necrosis'+i+' onfocus="messageOnFocus(2,'+i+')" onchange="saveToLocalStorage('+i+')" onkeypress="focusOnEnter(event, \'fat'+i+'\')">'+necrosisOptions+'</select></td>'; 245 inputWeightHtml += '<td>'+fatTitle+'<select name=fat'+i+' onfocus="messageOnFocus(3,'+i+')" onchange="saveToLocalStorage('+i+')" onkeypress="focusOnEnter(event, \'coloured'+i+'\')">'+fatOptions+'</select></td>'; 246 inputWeightHtml += '<td>'+colouredTitle+'<input type=checkbox name=coloured'+i+' onfocus="messageOnFocus(4,'+i+')" onchange="saveToLocalStorage('+i+')" onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'nofPieces'+i+'\')" /></td>' 245 247 inputWeightHtml += '<td>'+nofTitle+'<input name="nofPieces'+i+'" onfocus="messageOnFocus(5,'+i+')" onblur="nofPiecesOnChange('+i+')" onkeypress="focusOnEnter(event, \'spWeight'+i+'\');return isNumberKey(event)" size=2 /></td>'; 246 248 inputWeightHtml += '<td>'+spTitle+'<input name="spWeight'+i+'" onfocus="messageOnFocus(6,'+i+')" onblur="spWeightOnChange('+i+')" onkeypress="focusOnEnter(event, \'hisWeight'+i+'\');return isNumberKey(event)" size=4 /></td>'; … … 250 252 inputWeightHtml += '</table>'; 251 253 inputWeightHtml += '</td>'; 252 inputWeightHtml += '<td rowspan=2 class="status" id="'+i+'.status"></td>'; 254 inputWeightHtml += '<td rowspan=2 class="status" id="'+i+'.status"></td>'; 253 255 inputWeightHtml += '</tr>'; 254 256 … … 258 260 inputWeightHtml += '<tr><td> </td></tr>'; 259 261 } 262 inputWeightHtml += '</table>'; 260 263 setInnerHTML('weightInputs', inputWeightHtml); 261 } 264 265 // Restore saved information 266 isRestoringFromLocalStorage = true; 267 for (var i=0;i<selectedTubes.length; i++) 268 { 269 var tube = selectedTubes[i]; 270 var storeInfo = getStoredInfo(tube.id); 271 if (storeInfo) 272 { 273 frm['bloody'+i].checked = storeInfo.bloody; 274 setSelectedValue(frm['appearance'+i], storeInfo.appearance); 275 setSelectedValue(frm['necrosis'+i], storeInfo.necrosis); 276 setSelectedValue(frm['fat'+i], storeInfo.fat); 277 frm['coloured'+i].checked = storeInfo.coloured; 278 frm['nofPieces'+i].value = storeInfo.nofPieces; 279 frm['spWeight'+i].value = storeInfo.spWeight; 280 frm['hisWeight'+i].value = storeInfo.hisWeight; 281 frm['apWeight'+i].value = storeInfo.apWeight; 282 nofPiecesOnChange(i); 283 spWeightOnChange(i); 284 hisWeightOnChange(i); 285 apWeightOnChange(i); 286 } 287 } 288 isRestoringFromLocalStorage = false; 289 } 290 291 292 262 293 Main.show('weightSection'); 263 294 Main.hide('gonext'); … … 340 371 } 341 372 373 374 375 /** 376 Save as much information as possible about the partitioned 377 specimen tube. The information is stored in the localStorage() 378 under the key 'reggie.specimen.<id>.partitionInfo' where 379 <id> is the ID of the specimen tube. 380 */ 381 function saveToLocalStorage(tubeIndex) 382 { 383 if (window.localStorage && !isRestoringFromLocalStorage) 384 { 385 var tube = selectedTubes[tubeIndex]; 386 var frm = document.forms['reggie']; 387 var storeInfo = new Object(); 388 storeInfo.tubeId = tube.id; 389 storeInfo.bloody = frm['bloody'+tubeIndex].checked; 390 storeInfo.appearance = getSelectedValue(frm['appearance'+tubeIndex]); 391 storeInfo.necrosis = getSelectedValue(frm['necrosis'+tubeIndex]); 392 storeInfo.fat = getSelectedValue(frm['fat'+tubeIndex]); 393 storeInfo.coloured = frm['coloured'+tubeIndex].checked; 394 storeInfo.nofPieces = frm['nofPieces'+tubeIndex].value; 395 storeInfo.spWeight = frm['spWeight'+tubeIndex].value; 396 storeInfo.hisWeight = frm['hisWeight'+tubeIndex].value; 397 storeInfo.apWeight = frm['apWeight'+tubeIndex].value; 398 window.localStorage.setItem('reggie.specimen.' + tube.id + '.partitionInfo', JSON.stringify(storeInfo)); 399 if (debug) 400 { 401 Main.debug(tubeIndex + ': ' + window.localStorage.getItem('reggie.specimen.' + tube.id + '.partitionInfo')); 402 } 403 } 404 } 405 406 function removeFromLocalStorage(tubeId) 407 { 408 if (!window.localStorage) return; 409 if (debug) Main.debug('removeFromLocalStorage:' + tubeId); 410 window.localStorage.removeItem('reggie.specimen.' + tubeId + '.partitionInfo'); 411 } 412 413 function getStoredInfo(tubeId) 414 { 415 if (!window.localStorage) return null; 416 try 417 { 418 var stored = window.localStorage.getItem('reggie.specimen.' + tubeId + '.partitionInfo'); 419 if (debug) Main.debug(stored); 420 return stored ? JSON.parse(stored) : null; 421 } 422 catch (e) 423 { 424 Main.debug('Could not load stored information for tube ' + tubeId + ': ' + e); 425 } 426 } 427 342 428 function updateInputStatus(tubeIndex) 343 429 { 430 saveToLocalStorage(tubeIndex); 344 431 var frm = document.forms['reggie']; 345 432 if(nofPiecesAreValid[tubeIndex] == false) … … 586 673 submitInfo.tubeInfo = tubeInfo; 587 674 588 if (debug) Main.debug(JSON.stringify( caseInfo));675 if (debug) Main.debug(JSON.stringify(submitInfo)); 589 676 var request = Ajax.getXmlHttpRequest(); 590 677 var url = 'PartitionRegistration.servlet?ID=<%=ID%>&cmd=CreatePartitions'; … … 610 697 setInnerHTML('done', msg); 611 698 699 for (var i = 0; i < response.partitioned.length; i++) 700 { 701 removeFromLocalStorage(response.partitioned[i]); 702 } 612 703 613 704 Main.show('done'); … … 664 755 <td class="input"><select style="width:50%" name="tubeSelect" id="tubesSelect" multiple="multiple" size="12" onkeypress='doOnTab(event, goNextAuto)'></select></td> 665 756 <td class="status" id="tubes.status"></td> 666 <td class="help"><span id="tubes.message" class="message" style="display: none;"></span>Select specimen tubes to include in the partition.</td> 757 <td class="help"><span id="tubes.message" class="message" style="display: none;"></span>Select specimen tubes to include in the partition.<br> 758 * = There is unsaved partitioning information for this tube 759 </td> 667 760 </tr> 668 761 </table> … … 711 804 </tr> 712 805 <tr> 713 <td class="stepfields" >714 <table id="weightInputs" border="0" cellspacing="0" cellpadding="0" width="100%"></table>806 <td class="stepfields" id="weightInputs"> 807 715 808 </td> 716 809 </tr> -
extensions/net.sf.basedb.reggie/trunk/resources/reggie.js
r1531 r1532 247 247 return caseName.match(/^\d{7}$/); 248 248 } 249 250 /** 251 Get the selected value from a selection list. 252 */ 253 function getSelectedValue(list) 254 { 255 if (list.selectedIndex < 0) return ''; 256 return list[list.selectedIndex].value; 257 } 258 /** 259 Select the first option in the list that has the given value. 260 */ 261 function setSelectedValue(list, value) 262 { 263 for (var i = 0; i < list.length; i++) 264 { 265 if (list[i].value == value) 266 { 267 list.selectedIndex = i; 268 return; 269 } 270 } 271 } -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PartitionRegistrationServlet.java
r1502 r1532 154 154 JSONObject jsonInfo = (JSONObject)jsonReq.get("tubeInfo"); 155 155 JSONArray jsonSpecimens = (JSONArray)jsonInfo.get("specimens"); 156 JSONArray jsonPartitioned = new JSONArray(); 156 157 157 158 AnnotationType partitionDateType = Reggie.findAnnotationType(dc, new Item[]{Item.EXTRACT, Item.SAMPLE}, Reggie.ANNOTATION_PARTITION_DATE, true); … … 253 254 specimen.setOriginalQuantity(originalQuantity); 254 255 255 jsonMessages.add("Specimen tube " + specimen.getName() + " partitioned successfully"); 256 jsonMessages.add("Specimen tube " + specimen.getName() + " partitioned successfully"); 257 jsonPartitioned.add(specimen.getId()); 256 258 } 257 259 } 258 260 dc.commit(); 261 json.put("partitioned", jsonPartitioned); 259 262 } 260 263 json.put("messages", jsonMessages);
Note: See TracChangeset
for help on using the changeset viewer.