4165 |
21 Oct 16 |
nicklas |
var Register = function() |
4165 |
21 Oct 16 |
nicklas |
2 |
{ |
4165 |
21 Oct 16 |
nicklas |
var register = {}; |
4165 |
21 Oct 16 |
nicklas |
var debug = 0; |
4165 |
21 Oct 16 |
nicklas |
5 |
|
4179 |
27 Oct 16 |
nicklas |
var aliquots; |
4179 |
27 Oct 16 |
nicklas |
var allNames; |
4179 |
27 Oct 16 |
nicklas |
8 |
|
4165 |
21 Oct 16 |
nicklas |
// Page initialization |
4165 |
21 Oct 16 |
nicklas |
register.initPage = function() |
4165 |
21 Oct 16 |
nicklas |
11 |
{ |
4165 |
21 Oct 16 |
nicklas |
// Step 1 |
4165 |
21 Oct 16 |
nicklas |
Events.addEventHandler('step-1', 'wizard-validate', register.validateStep1); |
4165 |
21 Oct 16 |
nicklas |
Events.addEventHandler('workList', 'change', register.worklistOnChange); |
4165 |
21 Oct 16 |
nicklas |
Events.addEventHandler('completedDate', 'change', Wizard.validateDate); |
4165 |
21 Oct 16 |
nicklas |
Events.addEventHandler('outcomeSuccess', 'click', register.outcomeOnChange); |
4165 |
21 Oct 16 |
nicklas |
Events.addEventHandler('outcomeFailed', 'click', register.outcomeOnChange); |
4165 |
21 Oct 16 |
nicklas |
18 |
|
4179 |
27 Oct 16 |
nicklas |
// Step 2 |
4179 |
27 Oct 16 |
nicklas |
Events.addEventHandler('step-2', 'wizard-initialize', register.initializeStep2); |
4179 |
27 Oct 16 |
nicklas |
Events.addEventHandler('except', 'change', register.exceptChange); |
4179 |
27 Oct 16 |
nicklas |
Buttons.addClickHandler('btnBrowseExcept', register.browseExcept); |
4179 |
27 Oct 16 |
nicklas |
Events.addEventHandler('btnBrowseExcept', 'base-selected', register.exceptSelected); |
4179 |
27 Oct 16 |
nicklas |
24 |
|
4165 |
21 Oct 16 |
nicklas |
// Navigation |
4165 |
21 Oct 16 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
4165 |
21 Oct 16 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
4165 |
21 Oct 16 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
4165 |
21 Oct 16 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
4165 |
21 Oct 16 |
nicklas |
30 |
|
4165 |
21 Oct 16 |
nicklas |
// Final registration |
4165 |
21 Oct 16 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', register.submit); |
4165 |
21 Oct 16 |
nicklas |
33 |
|
4165 |
21 Oct 16 |
nicklas |
var url = '../Outtake.servlet?ID='+App.getSessionId(); |
4165 |
21 Oct 16 |
nicklas |
url += '&cmd=GetOuttakeWorklists'; |
4165 |
21 Oct 16 |
nicklas |
Wizard.showLoadingAnimation('Loading outtake work lists...'); |
4165 |
21 Oct 16 |
nicklas |
Wizard.asyncJsonRequest(url, register.initializeStep1); |
4165 |
21 Oct 16 |
nicklas |
38 |
} |
4165 |
21 Oct 16 |
nicklas |
39 |
|
4165 |
21 Oct 16 |
nicklas |
register.initializeStep1 = function(response) |
4165 |
21 Oct 16 |
nicklas |
41 |
{ |
4165 |
21 Oct 16 |
nicklas |
var frm = document.forms['reggie']; |
4165 |
21 Oct 16 |
nicklas |
var workLists = response.workLists; |
4165 |
21 Oct 16 |
nicklas |
44 |
|
4165 |
21 Oct 16 |
nicklas |
var workList = frm.workList; |
4165 |
21 Oct 16 |
nicklas |
if (workLists.length > 0) |
4165 |
21 Oct 16 |
nicklas |
47 |
{ |
4165 |
21 Oct 16 |
nicklas |
for (var i=0; i < workLists.length; i++) |
4165 |
21 Oct 16 |
nicklas |
49 |
{ |
4165 |
21 Oct 16 |
nicklas |
var list = workLists[i]; |
6326 |
14 Jun 21 |
nicklas |
var name = list.name + ' (' + list.size+(list.parentType?' '+list.parentType : '') + ')'; |
4165 |
21 Oct 16 |
nicklas |
var option = new Option(name, list.id); |
4165 |
21 Oct 16 |
nicklas |
option.workList = list; |
4165 |
21 Oct 16 |
nicklas |
workList.options[workList.length] = option; |
4165 |
21 Oct 16 |
nicklas |
55 |
} |
4165 |
21 Oct 16 |
nicklas |
Events.sendChangeEvent(workList); |
4165 |
21 Oct 16 |
nicklas |
57 |
} |
4165 |
21 Oct 16 |
nicklas |
else |
4165 |
21 Oct 16 |
nicklas |
59 |
{ |
4165 |
21 Oct 16 |
nicklas |
Wizard.setFatalError('No outtake works lists available for processing.'); |
4165 |
21 Oct 16 |
nicklas |
return; |
4165 |
21 Oct 16 |
nicklas |
62 |
} |
4165 |
21 Oct 16 |
nicklas |
63 |
|
4165 |
21 Oct 16 |
nicklas |
Doc.show('step-1'); |
4179 |
27 Oct 16 |
nicklas |
Doc.show('goregister'); |
4165 |
21 Oct 16 |
nicklas |
66 |
} |
4165 |
21 Oct 16 |
nicklas |
67 |
|
4165 |
21 Oct 16 |
nicklas |
register.worklistOnChange = function() |
4165 |
21 Oct 16 |
nicklas |
69 |
{ |
4165 |
21 Oct 16 |
nicklas |
var frm = document.forms['reggie']; |
4165 |
21 Oct 16 |
nicklas |
var workList = frm.workList[frm.workList.selectedIndex].workList; |
4165 |
21 Oct 16 |
nicklas |
frm.comments.value = workList.comments; |
4165 |
21 Oct 16 |
nicklas |
73 |
} |
4165 |
21 Oct 16 |
nicklas |
74 |
|
4165 |
21 Oct 16 |
nicklas |
register.validateStep1 = function(event) |
4165 |
21 Oct 16 |
nicklas |
76 |
{ |
4165 |
21 Oct 16 |
nicklas |
var frm = document.forms['reggie']; |
4179 |
27 Oct 16 |
nicklas |
var valid = frm.workList.selectedIndex >= 0; |
4179 |
27 Oct 16 |
nicklas |
valid &= Wizard.isValid('completedDate'); |
4179 |
27 Oct 16 |
nicklas |
80 |
|
4179 |
27 Oct 16 |
nicklas |
if (!valid) |
4165 |
21 Oct 16 |
nicklas |
82 |
{ |
4165 |
21 Oct 16 |
nicklas |
event.preventDefault(); |
4165 |
21 Oct 16 |
nicklas |
84 |
} |
4165 |
21 Oct 16 |
nicklas |
85 |
} |
4165 |
21 Oct 16 |
nicklas |
86 |
|
4165 |
21 Oct 16 |
nicklas |
87 |
|
4179 |
27 Oct 16 |
nicklas |
register.outcomeOnChange = function() |
4179 |
27 Oct 16 |
nicklas |
89 |
{ |
4179 |
27 Oct 16 |
nicklas |
var failed = Doc.element('outcomeFailed').checked |
4179 |
27 Oct 16 |
nicklas |
Doc.showHide('gonext', failed); |
4179 |
27 Oct 16 |
nicklas |
Doc.showHide('goregister', !failed); |
4179 |
27 Oct 16 |
nicklas |
93 |
} |
4179 |
27 Oct 16 |
nicklas |
94 |
|
4165 |
21 Oct 16 |
nicklas |
register.initializeStep2 = function() |
4165 |
21 Oct 16 |
nicklas |
96 |
{ |
4165 |
21 Oct 16 |
nicklas |
var frm = document.forms['reggie']; |
4179 |
27 Oct 16 |
nicklas |
98 |
|
4179 |
27 Oct 16 |
nicklas |
var url = '../Outtake.servlet?ID='+App.getSessionId(); |
4179 |
27 Oct 16 |
nicklas |
url += '&cmd=GetOuttakeInfo'; |
4179 |
27 Oct 16 |
nicklas |
url += '&workListId='+frm.workList.value; |
4179 |
27 Oct 16 |
nicklas |
Wizard.showLoadingAnimation('Loading aliquot information...'); |
4179 |
27 Oct 16 |
nicklas |
Wizard.asyncJsonRequest(url, register.aliquotsLoaded); |
4179 |
27 Oct 16 |
nicklas |
104 |
} |
4179 |
27 Oct 16 |
nicklas |
105 |
|
4179 |
27 Oct 16 |
nicklas |
register.aliquotsLoaded = function(response) |
4179 |
27 Oct 16 |
nicklas |
107 |
{ |
4179 |
27 Oct 16 |
nicklas |
aliquots = response.aliquots; |
4179 |
27 Oct 16 |
nicklas |
allNames = []; |
4179 |
27 Oct 16 |
nicklas |
var aliquots = response.aliquots; |
4165 |
21 Oct 16 |
nicklas |
111 |
|
4179 |
27 Oct 16 |
nicklas |
for (var aliquotNo = 0; aliquotNo < aliquots.length; aliquotNo++) |
4179 |
27 Oct 16 |
nicklas |
113 |
{ |
4179 |
27 Oct 16 |
nicklas |
var a = aliquots[aliquotNo]; |
4179 |
27 Oct 16 |
nicklas |
var p = a.parent; |
4179 |
27 Oct 16 |
nicklas |
allNames[a.name] = a.id; |
4179 |
27 Oct 16 |
nicklas |
allNames[p.name] = a.id; |
4179 |
27 Oct 16 |
nicklas |
118 |
} |
4179 |
27 Oct 16 |
nicklas |
119 |
|
4165 |
21 Oct 16 |
nicklas |
Wizard.setCurrentStep(2); |
4165 |
21 Oct 16 |
nicklas |
Doc.show('goregister'); |
4165 |
21 Oct 16 |
nicklas |
Doc.show('gocancel'); |
4165 |
21 Oct 16 |
nicklas |
123 |
} |
4165 |
21 Oct 16 |
nicklas |
124 |
|
4179 |
27 Oct 16 |
nicklas |
125 |
|
4179 |
27 Oct 16 |
nicklas |
register.exceptChange = function() |
4165 |
21 Oct 16 |
nicklas |
127 |
{ |
4165 |
21 Oct 16 |
nicklas |
var frm = document.forms['reggie']; |
4179 |
27 Oct 16 |
nicklas |
if (frm.except.length > 0) |
4179 |
27 Oct 16 |
nicklas |
130 |
{ |
4179 |
27 Oct 16 |
nicklas |
Wizard.setInputStatus('except', 'valid'); |
4179 |
27 Oct 16 |
nicklas |
132 |
} |
4179 |
27 Oct 16 |
nicklas |
else |
4179 |
27 Oct 16 |
nicklas |
134 |
{ |
4179 |
27 Oct 16 |
nicklas |
Wizard.setInputStatus('except'); |
4179 |
27 Oct 16 |
nicklas |
136 |
} |
4179 |
27 Oct 16 |
nicklas |
137 |
} |
4179 |
27 Oct 16 |
nicklas |
138 |
|
4179 |
27 Oct 16 |
nicklas |
var exceptMessages; |
4179 |
27 Oct 16 |
nicklas |
register.browseExcept = function() |
4179 |
27 Oct 16 |
nicklas |
141 |
{ |
4179 |
27 Oct 16 |
nicklas |
var frm = document.forms['reggie']; |
4179 |
27 Oct 16 |
nicklas |
var workList = frm.workList[frm.workList.selectedIndex].workList; |
4165 |
21 Oct 16 |
nicklas |
144 |
|
4179 |
27 Oct 16 |
nicklas |
var currentExcept = Link.getIdsInList(frm.except, workList.itemType); |
4179 |
27 Oct 16 |
nicklas |
exceptMessages = []; |
4179 |
27 Oct 16 |
nicklas |
Wizard.showFinalMessage(exceptMessages); |
4179 |
27 Oct 16 |
nicklas |
var url = '&resetTemporary=1&exclude='+currentExcept.join(','); |
4179 |
27 Oct 16 |
nicklas |
url += '&tmpfilter:INT:§itemLists='+frm.workList.value; |
4179 |
27 Oct 16 |
nicklas |
Dialogs.selectItem(workList.itemType, 'btnBrowseExcept', 1, url); |
4165 |
21 Oct 16 |
nicklas |
151 |
} |
4165 |
21 Oct 16 |
nicklas |
152 |
|
4179 |
27 Oct 16 |
nicklas |
153 |
|
4179 |
27 Oct 16 |
nicklas |
register.exceptSelected = function(event) |
4165 |
21 Oct 16 |
nicklas |
155 |
{ |
4179 |
27 Oct 16 |
nicklas |
var item = event.detail; |
4179 |
27 Oct 16 |
nicklas |
if (register.checkItemIsAliquot(item)) |
4179 |
27 Oct 16 |
nicklas |
158 |
{ |
4179 |
27 Oct 16 |
nicklas |
Link.addItem('except', item.itemType, item); |
4179 |
27 Oct 16 |
nicklas |
160 |
} |
4179 |
27 Oct 16 |
nicklas |
else |
4179 |
27 Oct 16 |
nicklas |
162 |
{ |
4179 |
27 Oct 16 |
nicklas |
exceptMessages[exceptMessages.length] = '[Warning]'+Strings.encodeTags(item.name) + ' is not in the selected work list'; |
4179 |
27 Oct 16 |
nicklas |
164 |
} |
4179 |
27 Oct 16 |
nicklas |
if (item.remaining == 0) |
4179 |
27 Oct 16 |
nicklas |
166 |
{ |
4179 |
27 Oct 16 |
nicklas |
Events.sendChangeEvent('except'); |
4179 |
27 Oct 16 |
nicklas |
Wizard.showFinalMessage(exceptMessages); |
4179 |
27 Oct 16 |
nicklas |
169 |
} |
4165 |
21 Oct 16 |
nicklas |
170 |
} |
4165 |
21 Oct 16 |
nicklas |
171 |
|
4179 |
27 Oct 16 |
nicklas |
register.checkItemIsAliquot = function(item) |
4179 |
27 Oct 16 |
nicklas |
173 |
{ |
4179 |
27 Oct 16 |
nicklas |
var id = allNames[item.name]; |
4179 |
27 Oct 16 |
nicklas |
if (id) item.id = id; |
4179 |
27 Oct 16 |
nicklas |
return id; |
4179 |
27 Oct 16 |
nicklas |
177 |
} |
4179 |
27 Oct 16 |
nicklas |
178 |
|
4165 |
21 Oct 16 |
nicklas |
register.submit = function() |
4165 |
21 Oct 16 |
nicklas |
180 |
{ |
4165 |
21 Oct 16 |
nicklas |
var frm = document.forms['reggie']; |
4179 |
27 Oct 16 |
nicklas |
var workList = frm.workList[frm.workList.selectedIndex].workList; |
4165 |
21 Oct 16 |
nicklas |
183 |
|
4165 |
21 Oct 16 |
nicklas |
var submitInfo = {}; |
4165 |
21 Oct 16 |
nicklas |
submitInfo.workList = parseInt(frm.workList.value, 10); |
4165 |
21 Oct 16 |
nicklas |
186 |
|
4179 |
27 Oct 16 |
nicklas |
var failed = Doc.element('outcomeFailed').checked; |
4179 |
27 Oct 16 |
nicklas |
submitInfo.failed = failed; |
4179 |
27 Oct 16 |
nicklas |
if (failed) |
4179 |
27 Oct 16 |
nicklas |
190 |
{ |
4179 |
27 Oct 16 |
nicklas |
submitInfo.sampleConsumed = Doc.element('sampleConsumedYes').checked; |
4179 |
27 Oct 16 |
nicklas |
submitInfo.except = Link.getIdsInList(frm.except, workList.itemType); |
4179 |
27 Oct 16 |
nicklas |
193 |
} |
4165 |
21 Oct 16 |
nicklas |
194 |
|
4165 |
21 Oct 16 |
nicklas |
submitInfo.completedDate = frm.completedDate.value; |
4165 |
21 Oct 16 |
nicklas |
submitInfo.comments = frm.comments.value; |
4165 |
21 Oct 16 |
nicklas |
197 |
|
4165 |
21 Oct 16 |
nicklas |
var url = '../Outtake.servlet?ID='+App.getSessionId(); |
4165 |
21 Oct 16 |
nicklas |
url += '&cmd=RegisterOuttakeComplete'; |
4165 |
21 Oct 16 |
nicklas |
Wizard.showLoadingAnimation('Performing registration...'); |
4165 |
21 Oct 16 |
nicklas |
Wizard.asyncJsonRequest(url, register.submissionResults, 'POST', JSON.stringify(submitInfo)); |
4165 |
21 Oct 16 |
nicklas |
202 |
} |
4165 |
21 Oct 16 |
nicklas |
203 |
|
4165 |
21 Oct 16 |
nicklas |
register.submissionResults = function(response) |
4165 |
21 Oct 16 |
nicklas |
205 |
{ |
4165 |
21 Oct 16 |
nicklas |
Wizard.showFinalMessage(response.messages); |
4165 |
21 Oct 16 |
nicklas |
Doc.show('gorestart'); |
4165 |
21 Oct 16 |
nicklas |
208 |
} |
4165 |
21 Oct 16 |
nicklas |
209 |
|
4165 |
21 Oct 16 |
nicklas |
return register; |
4165 |
21 Oct 16 |
nicklas |
211 |
}(); |
4165 |
21 Oct 16 |
nicklas |
212 |
|
4165 |
21 Oct 16 |
nicklas |
Doc.onLoad(Register.initPage); |
4165 |
21 Oct 16 |
nicklas |
214 |
|