7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2013 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Wizard = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var wizard = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
30 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
32 |
*/ |
7604 |
25 Feb 19 |
nicklas |
wizard.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
34 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId == 'WizardStep1') |
7604 |
25 Feb 19 |
nicklas |
37 |
{ |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnNext', wizard.gotoStep2); |
7604 |
25 Feb 19 |
nicklas |
40 |
|
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('quantity', 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('start_at', 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('pad_length', 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
44 |
|
7604 |
25 Feb 19 |
nicklas |
// Array batch |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('arraybatch_id.select', wizard.selectArrayBatch); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('arraybatch_id', 'base-selected', Items.onItemSelected); |
7604 |
25 Feb 19 |
nicklas |
48 |
|
7604 |
25 Feb 19 |
nicklas |
49 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'WizardStep2') |
7604 |
25 Feb 19 |
nicklas |
51 |
{ |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', wizard.finishWizard); |
7604 |
25 Feb 19 |
nicklas |
54 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('pasteMultipleName', wizard.pasteMultiple); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('clearAllNames', wizard.clearAll); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('pasteMultipleBarcode', wizard.pasteMultiple); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('clearAllBarcodes', wizard.clearAll); |
7604 |
25 Feb 19 |
nicklas |
59 |
|
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['WizardStep2']; |
7604 |
25 Feb 19 |
nicklas |
frm.barcode0.focus(); |
7604 |
25 Feb 19 |
nicklas |
62 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'paste-multiple') |
7604 |
25 Feb 19 |
nicklas |
64 |
{ |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnOk', wizard.saveMultiple); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
wizard.initPasteMultiple(); |
7604 |
25 Feb 19 |
nicklas |
68 |
} |
7604 |
25 Feb 19 |
nicklas |
69 |
} |
7604 |
25 Feb 19 |
nicklas |
70 |
|
7604 |
25 Feb 19 |
nicklas |
wizard.gotoStep2 = function() |
7604 |
25 Feb 19 |
nicklas |
72 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (wizard.validateStep1()) |
7604 |
25 Feb 19 |
nicklas |
74 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['WizardStep1']; |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
77 |
} |
7604 |
25 Feb 19 |
nicklas |
78 |
} |
7604 |
25 Feb 19 |
nicklas |
79 |
|
7604 |
25 Feb 19 |
nicklas |
// Submit and finish the wizard |
7604 |
25 Feb 19 |
nicklas |
wizard.finishWizard = function() |
7604 |
25 Feb 19 |
nicklas |
82 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (wizard.validateStep2()) |
7604 |
25 Feb 19 |
nicklas |
84 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['WizardStep2']; |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
87 |
} |
7604 |
25 Feb 19 |
nicklas |
88 |
} |
7604 |
25 Feb 19 |
nicklas |
89 |
|
7604 |
25 Feb 19 |
nicklas |
wizard.validateStep1 = function() |
7604 |
25 Feb 19 |
nicklas |
91 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['WizardStep1']; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.name.value) == '') |
7604 |
25 Feb 19 |
nicklas |
94 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.name, 'You must enter a name'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
97 |
} |
7604 |
25 Feb 19 |
nicklas |
if (frm.arraybatch_id && !frm.arraybatch_id.value) |
7604 |
25 Feb 19 |
nicklas |
99 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification('arraybatch_id.select', 'You must select an array batch'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
102 |
} |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.quantity.value) == '') |
7604 |
25 Feb 19 |
nicklas |
104 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.quantity, 'You must enter a quantity of slides'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
107 |
} |
7604 |
25 Feb 19 |
nicklas |
if (frm.quantity.value < 1 || frm.quantity.value > 999) |
7604 |
25 Feb 19 |
nicklas |
109 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.quantity, 'The quantity of array slides to be created must be between 1 and 999'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
112 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
114 |
} |
7604 |
25 Feb 19 |
nicklas |
115 |
|
7604 |
25 Feb 19 |
nicklas |
wizard.validateStep2 = function() |
7604 |
25 Feb 19 |
nicklas |
117 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['WizardStep2']; |
7604 |
25 Feb 19 |
nicklas |
var quantity = parseInt(frm.quantity.value); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < quantity; i++) |
7604 |
25 Feb 19 |
nicklas |
121 |
{ |
7604 |
25 Feb 19 |
nicklas |
var name = frm['name'+i]; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(name.value) == '') |
7604 |
25 Feb 19 |
nicklas |
124 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(name, 'You must enter a name for all slides', null, 'pointer-left'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
127 |
} |
7604 |
25 Feb 19 |
nicklas |
128 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
130 |
} |
7604 |
25 Feb 19 |
nicklas |
131 |
|
7604 |
25 Feb 19 |
nicklas |
wizard.selectArrayBatch = function() |
7604 |
25 Feb 19 |
nicklas |
133 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['WizardStep1']; |
7604 |
25 Feb 19 |
nicklas |
var url = ''; |
7604 |
25 Feb 19 |
nicklas |
if (frm.arraybatch_id.length > 0) |
7604 |
25 Feb 19 |
nicklas |
137 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&item_id='+frm.arraybatch_id[0].value; |
7604 |
25 Feb 19 |
nicklas |
139 |
} |
7604 |
25 Feb 19 |
nicklas |
Dialogs.selectItem('ARRAYBATCH', 'arraybatch_id', 0, url); |
7604 |
25 Feb 19 |
nicklas |
141 |
} |
7604 |
25 Feb 19 |
nicklas |
142 |
|
7604 |
25 Feb 19 |
nicklas |
wizard.pasteMultiple = function(event) |
7604 |
25 Feb 19 |
nicklas |
144 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = 'paste_multiple.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&form=WizardStep2&prefix='+Data.get(event.currentTarget, 'form-prefix'); |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'PasteMultiple', 400, 600); |
7604 |
25 Feb 19 |
nicklas |
148 |
} |
7604 |
25 Feb 19 |
nicklas |
149 |
|
7604 |
25 Feb 19 |
nicklas |
wizard.clearAll = function(event) |
7604 |
25 Feb 19 |
nicklas |
151 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['WizardStep2']; |
7604 |
25 Feb 19 |
nicklas |
var i = 0; |
7604 |
25 Feb 19 |
nicklas |
var prefix = Data.get(event.currentTarget, 'form-prefix'); |
7604 |
25 Feb 19 |
nicklas |
var field; |
7604 |
25 Feb 19 |
nicklas |
while(field = frm[prefix+i]) |
7604 |
25 Feb 19 |
nicklas |
157 |
{ |
7604 |
25 Feb 19 |
nicklas |
field.value = ''; |
7604 |
25 Feb 19 |
nicklas |
i++; |
7604 |
25 Feb 19 |
nicklas |
160 |
} |
7604 |
25 Feb 19 |
nicklas |
161 |
} |
7604 |
25 Feb 19 |
nicklas |
162 |
|
7604 |
25 Feb 19 |
nicklas |
wizard.initPasteMultiple = function() |
7604 |
25 Feb 19 |
nicklas |
164 |
{ |
7604 |
25 Feb 19 |
nicklas |
var formName = Data.get('page-data', 'form-name'); |
7604 |
25 Feb 19 |
nicklas |
var prefix = Data.get('page-data', 'form-prefix'); |
7604 |
25 Feb 19 |
nicklas |
var pfrm = window.opener.document.forms[formName]; |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['paste']; |
7604 |
25 Feb 19 |
nicklas |
if (pfrm) |
7604 |
25 Feb 19 |
nicklas |
170 |
{ |
7604 |
25 Feb 19 |
nicklas |
var i = 0; |
7604 |
25 Feb 19 |
nicklas |
var text = ''; |
7604 |
25 Feb 19 |
nicklas |
while (pfrm[prefix+i]) |
7604 |
25 Feb 19 |
nicklas |
174 |
{ |
7604 |
25 Feb 19 |
nicklas |
text += pfrm[prefix+i].value + '\n'; |
7604 |
25 Feb 19 |
nicklas |
i++; |
7604 |
25 Feb 19 |
nicklas |
177 |
} |
7604 |
25 Feb 19 |
nicklas |
frm['text'].value = text; |
7604 |
25 Feb 19 |
nicklas |
179 |
} |
7604 |
25 Feb 19 |
nicklas |
frm['text'].focus(); |
7604 |
25 Feb 19 |
nicklas |
181 |
} |
7604 |
25 Feb 19 |
nicklas |
182 |
|
7604 |
25 Feb 19 |
nicklas |
// Submit the form |
7604 |
25 Feb 19 |
nicklas |
wizard.saveMultiple = function() |
7604 |
25 Feb 19 |
nicklas |
185 |
{ |
7604 |
25 Feb 19 |
nicklas |
var formName = Data.get('page-data', 'form-name'); |
7604 |
25 Feb 19 |
nicklas |
var prefix = Data.get('page-data', 'form-prefix'); |
7604 |
25 Feb 19 |
nicklas |
var pfrm = window.opener.document.forms[formName]; |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['paste']; |
7604 |
25 Feb 19 |
nicklas |
if (pfrm) |
7604 |
25 Feb 19 |
nicklas |
191 |
{ |
7604 |
25 Feb 19 |
nicklas |
var text = frm['text'].value.split('\n'); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < text.length; ++i) |
7604 |
25 Feb 19 |
nicklas |
194 |
{ |
7604 |
25 Feb 19 |
nicklas |
var field = prefix + i; |
7604 |
25 Feb 19 |
nicklas |
if (pfrm[field]) pfrm[field].value = text[i]; |
7604 |
25 Feb 19 |
nicklas |
197 |
} |
7604 |
25 Feb 19 |
nicklas |
// Clear any remaining fields |
7604 |
25 Feb 19 |
nicklas |
while (pfrm[prefix+i]) |
7604 |
25 Feb 19 |
nicklas |
200 |
{ |
7604 |
25 Feb 19 |
nicklas |
pfrm[prefix+i].value = ''; |
7604 |
25 Feb 19 |
nicklas |
i++; |
7604 |
25 Feb 19 |
nicklas |
203 |
} |
7604 |
25 Feb 19 |
nicklas |
204 |
} |
7604 |
25 Feb 19 |
nicklas |
window.close(); |
7604 |
25 Feb 19 |
nicklas |
206 |
} |
7604 |
25 Feb 19 |
nicklas |
207 |
|
7604 |
25 Feb 19 |
nicklas |
208 |
|
7604 |
25 Feb 19 |
nicklas |
return wizard; |
7604 |
25 Feb 19 |
nicklas |
210 |
}(); |
7604 |
25 Feb 19 |
nicklas |
211 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Wizard.initPage); |