2782 |
10 Oct 14 |
nicklas |
var Block = function() |
2782 |
10 Oct 14 |
nicklas |
2 |
{ |
2782 |
10 Oct 14 |
nicklas |
var block = {}; |
2853 |
23 Oct 14 |
nicklas |
var debug = 0; |
2782 |
10 Oct 14 |
nicklas |
5 |
|
2782 |
10 Oct 14 |
nicklas |
var workList; |
2782 |
10 Oct 14 |
nicklas |
7 |
|
2782 |
10 Oct 14 |
nicklas |
// Page initialization |
2782 |
10 Oct 14 |
nicklas |
block.initPage = function() |
2782 |
10 Oct 14 |
nicklas |
10 |
{ |
2782 |
10 Oct 14 |
nicklas |
// Step 1 |
2782 |
10 Oct 14 |
nicklas |
Events.addEventHandler('step-1', 'wizard-validate', block.validateStep1); |
2782 |
10 Oct 14 |
nicklas |
Events.addEventHandler('embedDate', 'blur', Wizard.validateDate); |
2782 |
10 Oct 14 |
nicklas |
14 |
|
2782 |
10 Oct 14 |
nicklas |
// Step 2 |
2782 |
10 Oct 14 |
nicklas |
Events.addEventHandler('step-2', 'wizard-initialize', block.initializeStep2); |
2782 |
10 Oct 14 |
nicklas |
Events.addEventHandler('step-2', 'wizard-validate', block.validateStep2); |
2782 |
10 Oct 14 |
nicklas |
18 |
|
2782 |
10 Oct 14 |
nicklas |
// Navigation |
2782 |
10 Oct 14 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
2782 |
10 Oct 14 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
2782 |
10 Oct 14 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
2782 |
10 Oct 14 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
2782 |
10 Oct 14 |
nicklas |
24 |
|
2782 |
10 Oct 14 |
nicklas |
// Final registration |
2782 |
10 Oct 14 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', block.submit); |
2782 |
10 Oct 14 |
nicklas |
27 |
|
2782 |
10 Oct 14 |
nicklas |
Reggie.loadProtocols('HISTOLOGY_PROTOCOL', 'histologyProtocol'); |
2782 |
10 Oct 14 |
nicklas |
29 |
|
2782 |
10 Oct 14 |
nicklas |
var url = '../Histology.servlet?ID='+App.getSessionId(); |
2782 |
10 Oct 14 |
nicklas |
url += '&cmd=GetHistologyWorkLists'; |
2782 |
10 Oct 14 |
nicklas |
Wizard.showLoadingAnimation('Loading histology work lists...'); |
2782 |
10 Oct 14 |
nicklas |
Wizard.asyncJsonRequest(url, block.histologyListsLoaded); |
2782 |
10 Oct 14 |
nicklas |
34 |
} |
2782 |
10 Oct 14 |
nicklas |
35 |
|
2782 |
10 Oct 14 |
nicklas |
block.histologyListsLoaded = function(response) |
2782 |
10 Oct 14 |
nicklas |
37 |
{ |
2782 |
10 Oct 14 |
nicklas |
var frm = document.forms['reggie']; |
2782 |
10 Oct 14 |
nicklas |
var workLists = response.workLists; |
2782 |
10 Oct 14 |
nicklas |
40 |
|
2782 |
10 Oct 14 |
nicklas |
if (workLists.length > 0) |
2782 |
10 Oct 14 |
nicklas |
42 |
{ |
2782 |
10 Oct 14 |
nicklas |
for (var i=0; i < workLists.length; i++) |
2782 |
10 Oct 14 |
nicklas |
44 |
{ |
2782 |
10 Oct 14 |
nicklas |
var list = workLists[i]; |
2782 |
10 Oct 14 |
nicklas |
var name = list.name + ' (' + list.size + ')'; |
2782 |
10 Oct 14 |
nicklas |
var option = new Option(name, list.id); |
2782 |
10 Oct 14 |
nicklas |
frm.workList[frm.workList.length] = option; |
2782 |
10 Oct 14 |
nicklas |
49 |
} |
2782 |
10 Oct 14 |
nicklas |
50 |
|
2782 |
10 Oct 14 |
nicklas |
Wizard.setInputStatus('workList', 'valid'); |
2782 |
10 Oct 14 |
nicklas |
52 |
} |
2782 |
10 Oct 14 |
nicklas |
else |
2782 |
10 Oct 14 |
nicklas |
54 |
{ |
2782 |
10 Oct 14 |
nicklas |
Wizard.setFatalError('No Histology work lists available for processing.'); |
2782 |
10 Oct 14 |
nicklas |
return; |
2782 |
10 Oct 14 |
nicklas |
57 |
} |
2782 |
10 Oct 14 |
nicklas |
58 |
|
2782 |
10 Oct 14 |
nicklas |
Doc.show('step-1'); |
2782 |
10 Oct 14 |
nicklas |
Doc.show('gonext'); |
2782 |
10 Oct 14 |
nicklas |
frm.embedDate.focus(); |
2782 |
10 Oct 14 |
nicklas |
62 |
} |
2782 |
10 Oct 14 |
nicklas |
63 |
|
2782 |
10 Oct 14 |
nicklas |
block.validateStep1 = function(event) |
2782 |
10 Oct 14 |
nicklas |
65 |
{ |
2782 |
10 Oct 14 |
nicklas |
var valid = Wizard.isValid('embedDate'); |
2782 |
10 Oct 14 |
nicklas |
if (!valid) event.preventDefault(); |
2782 |
10 Oct 14 |
nicklas |
68 |
} |
2782 |
10 Oct 14 |
nicklas |
69 |
|
2782 |
10 Oct 14 |
nicklas |
70 |
|
2782 |
10 Oct 14 |
nicklas |
block.initializeStep2 = function() |
2782 |
10 Oct 14 |
nicklas |
72 |
{ |
2782 |
10 Oct 14 |
nicklas |
var frm = document.forms['reggie']; |
2782 |
10 Oct 14 |
nicklas |
var url = '../Histology.servlet?ID='+App.getSessionId(); |
2782 |
10 Oct 14 |
nicklas |
url += '&cmd=GetHistologyWorkListInfo&workListId='+frm.workList.value; |
2782 |
10 Oct 14 |
nicklas |
Wizard.showLoadingAnimation('Loading histology work list information...'); |
2782 |
10 Oct 14 |
nicklas |
Wizard.asyncJsonRequest(url, block.workListInfoLoaded); |
2782 |
10 Oct 14 |
nicklas |
78 |
} |
2782 |
10 Oct 14 |
nicklas |
79 |
|
2782 |
10 Oct 14 |
nicklas |
block.workListInfoLoaded = function(response) |
2782 |
10 Oct 14 |
nicklas |
81 |
{ |
2782 |
10 Oct 14 |
nicklas |
var frm = document.forms['reggie']; |
2782 |
10 Oct 14 |
nicklas |
83 |
|
2782 |
10 Oct 14 |
nicklas |
workList = response.workList; |
2782 |
10 Oct 14 |
nicklas |
var lastBlockBox = Data.get('page-data', 'last-block-box', ''); |
2782 |
10 Oct 14 |
nicklas |
86 |
|
2782 |
10 Oct 14 |
nicklas |
var html = '<table id="blockTable">'; |
2782 |
10 Oct 14 |
nicklas |
html += '<thead>'; |
2782 |
10 Oct 14 |
nicklas |
// First header row |
2782 |
10 Oct 14 |
nicklas |
html += '<tr>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<th style="width: 8em;">Paraffin block</th>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<th style="width: 8em;">Storage box</th>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<th style="width: 25em;">Comment</th>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<th style="width: 20px;"></th>'; |
2782 |
10 Oct 14 |
nicklas |
html += '</tr>'; |
2782 |
10 Oct 14 |
nicklas |
html += '</thead>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<tbody>'; |
2782 |
10 Oct 14 |
nicklas |
98 |
|
2782 |
10 Oct 14 |
nicklas |
for (var blockNo = 0; blockNo < workList.blocks.length; blockNo++) |
2782 |
10 Oct 14 |
nicklas |
100 |
{ |
2782 |
10 Oct 14 |
nicklas |
var pb = workList.blocks[blockNo]; |
2782 |
10 Oct 14 |
nicklas |
102 |
|
2782 |
10 Oct 14 |
nicklas |
html += '<tr>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<td>' + Strings.encodeTags(pb.name) + '</td>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<td><input type="text" name="blockBox.'+blockNo+'" id="blockBox.'+blockNo+'" value="'+lastBlockBox+'" style="width: 8em;"></td>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<td><input type="text" name="blockComment.'+blockNo+'" id="blockComment.'+blockNo+'" style="width: 25em;"></td>'; |
2782 |
10 Oct 14 |
nicklas |
html += '<td class="status" id="blockBox.'+blockNo+'.status"></td>'; |
2782 |
10 Oct 14 |
nicklas |
html += '</tr>'; |
2782 |
10 Oct 14 |
nicklas |
109 |
} |
2782 |
10 Oct 14 |
nicklas |
html += '</tbody>'; |
2782 |
10 Oct 14 |
nicklas |
html += '</table>'; |
2782 |
10 Oct 14 |
nicklas |
Doc.element('blockBoxInput').innerHTML = html; |
2782 |
10 Oct 14 |
nicklas |
113 |
|
2782 |
10 Oct 14 |
nicklas |
for (var blockNo = 0; blockNo < workList.blocks.length; blockNo++) |
2782 |
10 Oct 14 |
nicklas |
115 |
{ |
2782 |
10 Oct 14 |
nicklas |
Events.addEventHandler('blockBox.'+blockNo, 'keypress', Wizard.focusOnEnter, { 'next-focus': 'blockBox.'+(blockNo+1) }); |
2782 |
10 Oct 14 |
nicklas |
Events.addEventHandler('blockBox.'+blockNo, 'change', block.blockBoxOnChange); |
2782 |
10 Oct 14 |
nicklas |
118 |
} |
2782 |
10 Oct 14 |
nicklas |
119 |
|
2782 |
10 Oct 14 |
nicklas |
Wizard.setCurrentStep(2); |
2782 |
10 Oct 14 |
nicklas |
Doc.show('goregister'); |
2782 |
10 Oct 14 |
nicklas |
Doc.show('gocancel'); |
2782 |
10 Oct 14 |
nicklas |
frm['blockBox.0'].focus(); |
2782 |
10 Oct 14 |
nicklas |
124 |
} |
2782 |
10 Oct 14 |
nicklas |
125 |
|
2782 |
10 Oct 14 |
nicklas |
126 |
/** |
2782 |
10 Oct 14 |
nicklas |
Propagate changes to downward blocks. |
2782 |
10 Oct 14 |
nicklas |
128 |
*/ |
2782 |
10 Oct 14 |
nicklas |
block.blockBoxOnChange = function(event) |
2782 |
10 Oct 14 |
nicklas |
130 |
{ |
2782 |
10 Oct 14 |
nicklas |
var frm = document.forms['reggie']; |
2782 |
10 Oct 14 |
nicklas |
var blockName = event.currentTarget.value; |
2782 |
10 Oct 14 |
nicklas |
133 |
|
2782 |
10 Oct 14 |
nicklas |
var isDownwards = false; |
2782 |
10 Oct 14 |
nicklas |
for (var blockNo = 0; blockNo < workList.blocks.length; blockNo++) |
2782 |
10 Oct 14 |
nicklas |
136 |
{ |
2782 |
10 Oct 14 |
nicklas |
var bb = frm['blockBox.'+blockNo]; |
2782 |
10 Oct 14 |
nicklas |
if (isDownwards) |
2782 |
10 Oct 14 |
nicklas |
139 |
{ |
2782 |
10 Oct 14 |
nicklas |
bb.value = blockName; |
2782 |
10 Oct 14 |
nicklas |
141 |
} |
2782 |
10 Oct 14 |
nicklas |
else if (bb == event.currentTarget) |
2782 |
10 Oct 14 |
nicklas |
143 |
{ |
2782 |
10 Oct 14 |
nicklas |
isDownwards = true; |
2782 |
10 Oct 14 |
nicklas |
145 |
} |
2782 |
10 Oct 14 |
nicklas |
146 |
} |
2782 |
10 Oct 14 |
nicklas |
147 |
} |
2782 |
10 Oct 14 |
nicklas |
148 |
|
2782 |
10 Oct 14 |
nicklas |
block.validateStep2 = function(event) |
2782 |
10 Oct 14 |
nicklas |
150 |
{ |
2782 |
10 Oct 14 |
nicklas |
var frm = document.forms['reggie']; |
2782 |
10 Oct 14 |
nicklas |
var valid = true; |
2782 |
10 Oct 14 |
nicklas |
Wizard.setInputStatus('blockBox'); |
2782 |
10 Oct 14 |
nicklas |
154 |
|
2782 |
10 Oct 14 |
nicklas |
for (var blockNo = 0; blockNo < workList.blocks.length; blockNo++) |
2782 |
10 Oct 14 |
nicklas |
156 |
{ |
2782 |
10 Oct 14 |
nicklas |
if (frm['blockBox.'+blockNo].value == '') |
2782 |
10 Oct 14 |
nicklas |
158 |
{ |
2782 |
10 Oct 14 |
nicklas |
Wizard.setInputStatus('blockBox.'+blockNo, 'invalid', 'A storage box must be specified for all blocks.'); |
2782 |
10 Oct 14 |
nicklas |
valid = false; |
2782 |
10 Oct 14 |
nicklas |
161 |
} |
2782 |
10 Oct 14 |
nicklas |
else |
2782 |
10 Oct 14 |
nicklas |
163 |
{ |
2782 |
10 Oct 14 |
nicklas |
Wizard.setInputStatus('blockBox.'+blockNo, 'valid'); |
2782 |
10 Oct 14 |
nicklas |
165 |
} |
2782 |
10 Oct 14 |
nicklas |
166 |
} |
2782 |
10 Oct 14 |
nicklas |
if (!valid) |
2782 |
10 Oct 14 |
nicklas |
168 |
{ |
2782 |
10 Oct 14 |
nicklas |
Wizard.setInputStatus('blockBox', '', 'A storage box must be specified for all blocks.'); |
2782 |
10 Oct 14 |
nicklas |
event.preventDefault(); |
2782 |
10 Oct 14 |
nicklas |
171 |
} |
2782 |
10 Oct 14 |
nicklas |
172 |
} |
2782 |
10 Oct 14 |
nicklas |
173 |
|
2782 |
10 Oct 14 |
nicklas |
174 |
|
2782 |
10 Oct 14 |
nicklas |
block.submit = function() |
2782 |
10 Oct 14 |
nicklas |
176 |
{ |
2782 |
10 Oct 14 |
nicklas |
var frm = document.forms['reggie']; |
2782 |
10 Oct 14 |
nicklas |
178 |
|
2782 |
10 Oct 14 |
nicklas |
workList.embedDate = frm.embedDate.value; |
2782 |
10 Oct 14 |
nicklas |
workList.protocolId = parseInt(frm.histologyProtocol.value, 10); |
2782 |
10 Oct 14 |
nicklas |
181 |
|
2782 |
10 Oct 14 |
nicklas |
for (var blockNo = 0; blockNo < workList.blocks.length; blockNo++) |
2782 |
10 Oct 14 |
nicklas |
183 |
{ |
2782 |
10 Oct 14 |
nicklas |
var pb = workList.blocks[blockNo]; |
2782 |
10 Oct 14 |
nicklas |
pb.storageBox = frm['blockBox.'+blockNo].value; |
2782 |
10 Oct 14 |
nicklas |
pb.comment = frm['blockComment.'+blockNo].value; |
2782 |
10 Oct 14 |
nicklas |
187 |
} |
2782 |
10 Oct 14 |
nicklas |
188 |
|
2782 |
10 Oct 14 |
nicklas |
var url = '../Histology.servlet?ID='+App.getSessionId(); |
2782 |
10 Oct 14 |
nicklas |
url += '&cmd=MoveHistologySamplesToParaffinBlocks'; |
2782 |
10 Oct 14 |
nicklas |
Wizard.showLoadingAnimation('Performing registration...'); |
2782 |
10 Oct 14 |
nicklas |
Wizard.asyncJsonRequest(url, block.submissionResults, 'POST', JSON.stringify(workList)); |
2782 |
10 Oct 14 |
nicklas |
193 |
|
2782 |
10 Oct 14 |
nicklas |
194 |
} |
2782 |
10 Oct 14 |
nicklas |
195 |
|
2782 |
10 Oct 14 |
nicklas |
block.submissionResults = function(response) |
2782 |
10 Oct 14 |
nicklas |
197 |
{ |
2782 |
10 Oct 14 |
nicklas |
Wizard.showFinalMessage(response.messages); |
2782 |
10 Oct 14 |
nicklas |
Doc.show('gorestart'); |
2782 |
10 Oct 14 |
nicklas |
200 |
} |
2782 |
10 Oct 14 |
nicklas |
201 |
|
2782 |
10 Oct 14 |
nicklas |
return block; |
2782 |
10 Oct 14 |
nicklas |
203 |
}(); |
2782 |
10 Oct 14 |
nicklas |
204 |
|
2782 |
10 Oct 14 |
nicklas |
Doc.onLoad(Block.initPage); |
2782 |
10 Oct 14 |
nicklas |
206 |
|