Changeset 2128
- Timestamp:
- Nov 11, 2013, 10:48:59 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/branches/ticket-489/resources/sampleproc/histology_score.jsp
r2125 r2128 40 40 var heGlass; 41 41 42 var disableModificationCheck = false; 43 42 44 var SCORES = ['ScoreInvasiveCancer', 'ScoreInsituCancer', 'ScoreLymphocytes', 'ScoreNormal', 'ScoreStroma', 'ScoreFat']; 43 45 var FIELDS = ['score_invasive_cancer', 'score_insitu_cancer', 'score_lymphocytes', 'score_normal', 'score_stroma', 'score_fat']; … … 72 74 73 75 saveOriginalProperties(sample); 76 restoreFromLocalStorage(sample); 74 77 75 78 // Save ID of HE glass since we need that later … … 105 108 Main.show('gocreate'); 106 109 window.addEventListener('beforeunload', confirmIfModified); 107 110 111 keepSessionAlive('<%=ID%>', debug && false, '../'); 108 112 } 109 113 else … … 143 147 o.GoodStain = sample.GoodStain; 144 148 o.ScoreComplete = sample.ScoreComplete; 149 o.comments = sample.comments; 145 150 sample.o = o; 146 151 sample.isModified = false; … … 152 157 function isModified(sample, useCache) 153 158 { 154 if (useCache) 155 { 156 return sample.isModified; 157 } 158 var o = sample.o; 159 for (var p in o) 160 { 161 if (o[p] != sample[p]) return true; 162 } 163 return false; 159 if (!useCache) 160 { 161 var o = sample.o; 162 sample.isModified = false; 163 for (var p in o) 164 { 165 if (o[p] != sample[p]) 166 { 167 sample.isModified = true; 168 break; 169 } 170 } 171 } 172 return sample.isModified; 164 173 } 165 174 … … 170 179 { 171 180 glassName = frm.findGlassName.value; 181 if (!glassName) return; 182 172 183 if (glassName.match(/^\d+$/)) 173 184 { … … 185 196 } 186 197 187 location. href = url;198 location.replace(url); 188 199 } 189 200 190 201 function selectHeGlass() 191 202 { 203 if (!confirmIfModified()) return; 204 192 205 var url = getRoot() + 'biomaterials/bioplates/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone'; 193 206 url += '&resetTemporary=1'; … … 199 212 function setSelectedHeGlass(id, name) 200 213 { 214 disableModificationCheck = true; 201 215 findHeGlass(name); 202 216 } … … 352 366 353 367 // Comments 354 frm.comments.value = sample.comments ;368 frm.comments.value = sample.comments || ''; 355 369 356 370 // Class name of selected table cell … … 416 430 frm.score_complete.disabled = true; 417 431 frm.score_complete.checked = false; 418 419 if (selectedSample.ScoreTotal != null) 420 { 421 selectedSample.ScoreComplete = false; 422 setInputStatus('score_total', 'Not 100%', 'warning'); 423 } 424 else 425 { 426 selectedSample.ScoreComplete = null; 427 setInputStatus('score_total', '', ''); 428 } 432 433 setInputStatus('score_total', 'Not 100%', 'warning'); 434 selectedSample.ScoreComplete = selectedSample.ScoreTotal == null ? null : false; 429 435 } 430 436 431 437 setSampleClassName(selectedSample); 438 saveToLocalStorage(selectedSample); 432 439 } 433 440 … … 464 471 selectedSample.ScoreComplete = frm.score_complete.checked; 465 472 setSampleClassName(selectedSample); 473 saveToLocalStorage(selectedSample); 466 474 } 467 475 … … 482 490 sample.GoodStain = null; 483 491 setSampleClassName(sample); 492 saveToLocalStorage(sample); 484 493 } 485 494 } … … 489 498 frm.good_stain.disabled = true; 490 499 setSampleClassName(selectedSample); 500 saveToLocalStorage(selectedSample); 491 501 } 492 502 … … 495 505 var frm = document.forms['reggie']; 496 506 selectedSample.comments = frm.comments.value; 507 setSampleClassName(selectedSample); 508 saveToLocalStorage(selectedSample); 497 509 } 498 510 … … 564 576 function confirmIfModified(event) 565 577 { 578 if (disableModificationCheck) return; 579 566 580 var numModified = 0; 567 581 for (var glassNo = 0; glassNo < heGlass.length; glassNo++) … … 578 592 } 579 593 580 var okToContinue = true; 581 if (numModified > 0) 582 { 583 if (event) 594 if (event) 595 { 596 if (numModified > 0) 584 597 { 585 598 event.returnValue = 'There are unsaved modifications. Continue?'; 586 } 587 else 588 { 589 if (!confirm('There are unsaved modifications. Continue?')) 590 { 591 okToContinue = false; 592 } 593 } 594 } 595 596 return okToContinue; 599 return event.returnValue; 600 } 601 } 602 else 603 { 604 return confirm('There are unsaved modifications. Continue?'); 605 } 606 597 607 } 598 608 … … 667 677 } 668 678 679 // Reset changed properties and remove saved info 680 for (var sampleNo = 0; sampleNo < samples.length; sampleNo++) 681 { 682 var sample = samples[sampleNo]; 683 saveOriginalProperties(sample); 684 setSampleClassName(sample); 685 removeFromLocalStorage(sample); 686 } 687 688 669 689 var msg = '<ul>'; 670 690 for (var i = 0; i < response.messages.length; i++) … … 679 699 Main.hide('gocreate'); 680 700 701 } 702 703 704 /** 705 Save score information to the local storage. 706 */ 707 function saveToLocalStorage(sample) 708 { 709 if (window.localStorage && isModified(sample, true)) 710 { 711 var storeKey = getStoreKey(sample); 712 window.localStorage.setItem(storeKey, JSON.stringify(sample)); 713 if (debug) 714 { 715 Main.debug('saveToLocalStorage: ' + sample.name + '=' + window.localStorage.getItem(storeKey)); 716 } 717 } 718 } 719 720 function removeFromLocalStorage(sample) 721 { 722 if (!window.localStorage) return; 723 if (debug) Main.debug('removeFromLocalStorage:' + sample.name); 724 window.localStorage.removeItem(getStoreKey(sample)); 725 } 726 727 function restoreFromLocalStorage(sample) 728 { 729 if (!window.localStorage) return; 730 try 731 { 732 var stored = window.localStorage.getItem(getStoreKey(sample)); 733 if (!stored) return; 734 735 if (debug) Main.debug(stored); 736 var tmp = JSON.parse(stored); 737 if (!tmp) return; 738 739 // Check that all original scores are the same, or someone has modified 740 // this sample from another computer 741 for (var p in sample.o) 742 { 743 if (sample.o[p] != tmp.o[p]) 744 { 745 return; 746 } 747 } 748 749 // Ok, copy stored info to the current sample 750 for (var i = 0; i < SCORES.length; i++) 751 { 752 sample[SCORES[i]] = tmp[SCORES[i]]; 753 } 754 sample.ScoreComplete = tmp.ScoreComplete; 755 sample.GoodStain = tmp.GoodStain; 756 sample.comments = tmp.comments; 757 } 758 catch (e) 759 { 760 Main.debug('Could not load stored information for sample ' + sample.name + ': ' + e); 761 } 762 } 763 764 function getStoreKey(sample) 765 { 766 return 'reggie.histology.' + sample.id + '.scoreInfo'; 681 767 } 682 768
Note: See TracChangeset
for help on using the changeset viewer.