2933 |
14 Nov 14 |
olle |
1 |
|
2933 |
14 Nov 14 |
olle |
var Meludi = function() |
2933 |
14 Nov 14 |
olle |
3 |
{ |
2933 |
14 Nov 14 |
olle |
var meludi = {}; |
2933 |
14 Nov 14 |
olle |
var internal = {}; |
2933 |
14 Nov 14 |
olle |
6 |
|
3210 |
26 Mar 15 |
olle |
meludi.TITLE = 'MeLuDI'; |
6805 |
24 Aug 22 |
olle |
meludi.VERSION = '1.6.0'; |
2933 |
14 Nov 14 |
olle |
9 |
|
2933 |
14 Nov 14 |
olle |
var WELL_ALPHA = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; |
2933 |
14 Nov 14 |
olle |
11 |
|
2933 |
14 Nov 14 |
olle |
var GENERIC_STRATAGENE_NAME = 'Stratagene.r'; |
2933 |
14 Nov 14 |
olle |
var EXTERNAL_RNA_NAME = 'External.r'; |
2933 |
14 Nov 14 |
olle |
14 |
|
2933 |
14 Nov 14 |
olle |
var CASENAME_WITH_SUFFIX = /^\d{7}(C|D)?$/; |
2933 |
14 Nov 14 |
olle |
var CASENAME = /^\d{7}$/; |
2933 |
14 Nov 14 |
olle |
17 |
|
2933 |
14 Nov 14 |
olle |
var RCCID_WITH_SUFFIX = /^\d{10}(B|C|D){1}$/; |
2933 |
14 Nov 14 |
olle |
19 |
|
2933 |
14 Nov 14 |
olle |
var currentDirectory; |
2933 |
14 Nov 14 |
olle |
21 |
|
2933 |
14 Nov 14 |
olle |
22 |
/* |
4215 |
08 Nov 16 |
olle |
Verify that the 'case' name equals itemNamePrefix + itemNumDigits digits |
4215 |
08 Nov 16 |
olle |
24 |
*/ |
4215 |
08 Nov 16 |
olle |
meludi.isValidCaseName2 = function isValidCaseName(caseName, itemNamePrefix, itemNumDigits) |
4215 |
08 Nov 16 |
olle |
26 |
{ |
4215 |
08 Nov 16 |
olle |
27 |
/* |
4215 |
08 Nov 16 |
olle |
var regex = /^ML\d{5}$/; |
4215 |
08 Nov 16 |
olle |
29 |
*/ |
4215 |
08 Nov 16 |
olle |
var regex = new RegExp('^' + itemNamePrefix + '\\d{' + itemNumDigits + '}$', ''); |
4215 |
08 Nov 16 |
olle |
return caseName.match(regex); |
4215 |
08 Nov 16 |
olle |
32 |
} |
4215 |
08 Nov 16 |
olle |
33 |
|
4215 |
08 Nov 16 |
olle |
34 |
/* |
4142 |
30 Sep 16 |
olle |
Verify that the 'case' name equals itemNamePrefix + 5 digits |
2933 |
14 Nov 14 |
olle |
36 |
*/ |
4142 |
30 Sep 16 |
olle |
meludi.isValidCaseName = function isValidCaseName(caseName, itemNamePrefix) |
2933 |
14 Nov 14 |
olle |
38 |
{ |
4142 |
30 Sep 16 |
olle |
39 |
/* |
2933 |
14 Nov 14 |
olle |
var regex = /^ML\d{5}$/; |
4142 |
30 Sep 16 |
olle |
41 |
*/ |
4142 |
30 Sep 16 |
olle |
var regex = new RegExp('^' + itemNamePrefix + '\\d{5}$', ''); |
2933 |
14 Nov 14 |
olle |
return caseName.match(regex); |
2933 |
14 Nov 14 |
olle |
44 |
} |
2933 |
14 Nov 14 |
olle |
45 |
|
2933 |
14 Nov 14 |
olle |
46 |
/* |
2933 |
14 Nov 14 |
olle |
Verify that the 'case' name is a 7-digit value + optional C/D suffix |
2933 |
14 Nov 14 |
olle |
48 |
*/ |
2933 |
14 Nov 14 |
olle |
49 |
/* |
2933 |
14 Nov 14 |
olle |
meludi.isValidCaseName = function isValidCaseName(caseName, allowSuffix) |
2933 |
14 Nov 14 |
olle |
51 |
{ |
2933 |
14 Nov 14 |
olle |
return caseName.match(allowSuffix ? CASENAME_WITH_SUFFIX : CASENAME); |
2933 |
14 Nov 14 |
olle |
53 |
} |
2933 |
14 Nov 14 |
olle |
54 |
*/ |
2933 |
14 Nov 14 |
olle |
55 |
|
2933 |
14 Nov 14 |
olle |
56 |
/* |
2933 |
14 Nov 14 |
olle |
Verify that the RCCID number is a 10-digit value + 'B', 'C', or 'D' suffix |
2933 |
14 Nov 14 |
olle |
58 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.isValidRccidNumber = function(rccidNumber) |
2933 |
14 Nov 14 |
olle |
60 |
{ |
2933 |
14 Nov 14 |
olle |
return rccidNumber.match(RCCID_WITH_SUFFIX); |
2933 |
14 Nov 14 |
olle |
62 |
} |
2933 |
14 Nov 14 |
olle |
63 |
|
2933 |
14 Nov 14 |
olle |
64 |
/** |
2933 |
14 Nov 14 |
olle |
Check the control digit of the given personal number. |
2933 |
14 Nov 14 |
olle |
@pnr The 10-digit personal number in the form YYMMDDXXXX |
2933 |
14 Nov 14 |
olle |
67 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.personalNumberControlDigitCheck = function(pnr) |
2933 |
14 Nov 14 |
olle |
69 |
{ |
2933 |
14 Nov 14 |
olle |
var sum = 0; |
2933 |
14 Nov 14 |
olle |
var factor = 2; |
2933 |
14 Nov 14 |
olle |
for (var i = 0; i < 9; i++) |
2933 |
14 Nov 14 |
olle |
73 |
{ |
2933 |
14 Nov 14 |
olle |
var digit = parseInt(pnr.substr(i, 1), 10); |
2933 |
14 Nov 14 |
olle |
var tmp = factor * digit; |
2933 |
14 Nov 14 |
olle |
sum += tmp >= 10 ? tmp - 9: tmp; |
2933 |
14 Nov 14 |
olle |
factor = factor == 2 ? 1 : 2; |
2933 |
14 Nov 14 |
olle |
78 |
} |
2933 |
14 Nov 14 |
olle |
79 |
|
2933 |
14 Nov 14 |
olle |
var control = 10 - (sum % 10); |
2933 |
14 Nov 14 |
olle |
if (control == 10) control = 0; |
2933 |
14 Nov 14 |
olle |
return (control == parseInt(pnr.substr(9, 1), 10)) |
2933 |
14 Nov 14 |
olle |
83 |
} |
2933 |
14 Nov 14 |
olle |
84 |
|
2933 |
14 Nov 14 |
olle |
85 |
/** |
2933 |
14 Nov 14 |
olle |
Autofill a date-string. |
2933 |
14 Nov 14 |
olle |
The supplemented date-string will have the format yyyyMMdd when it's returned. |
2933 |
14 Nov 14 |
olle |
If the short-date in format MMdd is larger the current date, the year before will be used. |
2933 |
14 Nov 14 |
olle |
89 |
|
2933 |
14 Nov 14 |
olle |
@param shortDate Date in format 'MMdd' or in 'yyMMdd' |
2933 |
14 Nov 14 |
olle |
@param allowSixDigitDates Boolean Flag indicating if 6-digit dates should be auto-filled (default = false). |
2933 |
14 Nov 14 |
olle |
92 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.autoFillDate = function(shortDate, allowSixDigitDates) |
2933 |
14 Nov 14 |
olle |
94 |
{ |
2933 |
14 Nov 14 |
olle |
shortDate = shortDate.replace("-",""); |
2933 |
14 Nov 14 |
olle |
var fullDate = shortDate; |
2933 |
14 Nov 14 |
olle |
97 |
|
2933 |
14 Nov 14 |
olle |
var currentDate = new Date(); |
2933 |
14 Nov 14 |
olle |
var currentYear = currentDate.getFullYear(); |
2933 |
14 Nov 14 |
olle |
var currentMonth = currentDate.getMonth()+1; |
2933 |
14 Nov 14 |
olle |
101 |
|
2933 |
14 Nov 14 |
olle |
if (shortDate.length == 4 && Dates.isDate(shortDate, 'MMdd')) |
2933 |
14 Nov 14 |
olle |
103 |
{ |
2933 |
14 Nov 14 |
olle |
var month = parseInt(shortDate.substring(0, 2), 10); |
2933 |
14 Nov 14 |
olle |
var day = parseInt(shortDate.substring(2), 10); |
2933 |
14 Nov 14 |
olle |
if ((month > currentMonth) || (month == currentMonth && day > currentDate.getDate())) |
2933 |
14 Nov 14 |
olle |
107 |
{ |
2933 |
14 Nov 14 |
olle |
currentYear--; |
2933 |
14 Nov 14 |
olle |
109 |
} |
2933 |
14 Nov 14 |
olle |
fullDate = currentYear+shortDate; |
2933 |
14 Nov 14 |
olle |
111 |
} |
2933 |
14 Nov 14 |
olle |
else if (allowSixDigitDates && shortDate.length == 6 && Dates.isDate(shortDate, 'yyMMdd')) |
2933 |
14 Nov 14 |
olle |
113 |
{ |
2933 |
14 Nov 14 |
olle |
var year = parseInt(shortDate.substring(0,2), 10); |
2933 |
14 Nov 14 |
olle |
fullDate = ((2000+year) > currentYear ? "19" : "20") + fullDate; |
2933 |
14 Nov 14 |
olle |
116 |
} |
2933 |
14 Nov 14 |
olle |
return fullDate; |
2933 |
14 Nov 14 |
olle |
118 |
} |
2933 |
14 Nov 14 |
olle |
119 |
|
2933 |
14 Nov 14 |
olle |
meludi.autoFillTime = function(shortTime) |
2933 |
14 Nov 14 |
olle |
121 |
{ |
2933 |
14 Nov 14 |
olle |
var fullTimeString = shortTime; |
2933 |
14 Nov 14 |
olle |
if (shortTime.length==3) |
2933 |
14 Nov 14 |
olle |
124 |
{ |
2933 |
14 Nov 14 |
olle |
fullTimeString = "0"+shortTime; |
2933 |
14 Nov 14 |
olle |
126 |
} |
2933 |
14 Nov 14 |
olle |
return fullTimeString; |
2933 |
14 Nov 14 |
olle |
128 |
} |
2933 |
14 Nov 14 |
olle |
129 |
|
2933 |
14 Nov 14 |
olle |
130 |
/** |
2933 |
14 Nov 14 |
olle |
Convert a 2-digit year to a 4-digit year. Assuming |
2933 |
14 Nov 14 |
olle |
that the short year is between 1 and 100 years old. |
2933 |
14 Nov 14 |
olle |
133 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.fullYear = function(shortYear) |
2933 |
14 Nov 14 |
olle |
135 |
{ |
2933 |
14 Nov 14 |
olle |
var thisYear = new Date().getFullYear(); |
2933 |
14 Nov 14 |
olle |
var fullYear = shortYear + 100*Math.floor((thisYear - shortYear - 1) / 100); |
2933 |
14 Nov 14 |
olle |
return fullYear; |
2933 |
14 Nov 14 |
olle |
139 |
} |
2933 |
14 Nov 14 |
olle |
140 |
|
2933 |
14 Nov 14 |
olle |
meludi.formatNumber = function(number, unit, baseDecimals) |
2933 |
14 Nov 14 |
olle |
142 |
{ |
2933 |
14 Nov 14 |
olle |
if (number == null) return ''; |
2933 |
14 Nov 14 |
olle |
144 |
|
2933 |
14 Nov 14 |
olle |
var numDecimals; |
2933 |
14 Nov 14 |
olle |
if (!baseDecimals) baseDecimals = 3; |
2933 |
14 Nov 14 |
olle |
if (number < 10) |
2933 |
14 Nov 14 |
olle |
148 |
{ |
2933 |
14 Nov 14 |
olle |
numDecimals = baseDecimals; |
2933 |
14 Nov 14 |
olle |
150 |
} |
2933 |
14 Nov 14 |
olle |
else if (number < 100) |
2933 |
14 Nov 14 |
olle |
152 |
{ |
2933 |
14 Nov 14 |
olle |
numDecimals = baseDecimals-1; |
2933 |
14 Nov 14 |
olle |
154 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
156 |
{ |
2933 |
14 Nov 14 |
olle |
numDecimals = baseDecimals-2; |
2933 |
14 Nov 14 |
olle |
158 |
} |
2933 |
14 Nov 14 |
olle |
159 |
|
2933 |
14 Nov 14 |
olle |
var result = number.toFixed(numDecimals); |
2933 |
14 Nov 14 |
olle |
if (unit) result += unit; |
2933 |
14 Nov 14 |
olle |
return result; |
2933 |
14 Nov 14 |
olle |
163 |
} |
2933 |
14 Nov 14 |
olle |
164 |
|
2933 |
14 Nov 14 |
olle |
165 |
/** |
2933 |
14 Nov 14 |
olle |
Reformat a date string in YYYYMMDD or YYYYMMDD HHMM format |
2933 |
14 Nov 14 |
olle |
to YYYY-MM-DD HH:MM |
2933 |
14 Nov 14 |
olle |
168 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.reformatDate = function(value, defaultValue) |
2933 |
14 Nov 14 |
olle |
170 |
{ |
2933 |
14 Nov 14 |
olle |
if (!value) return defaultValue || ''; |
2933 |
14 Nov 14 |
olle |
if (value.length == 8) |
2933 |
14 Nov 14 |
olle |
173 |
{ |
2933 |
14 Nov 14 |
olle |
// YYYYMMDD |
2933 |
14 Nov 14 |
olle |
value = value.substr(0, 4) + '-' + value.substr(4, 2) + '-' + value.substr(6, 2); |
2933 |
14 Nov 14 |
olle |
176 |
} |
2933 |
14 Nov 14 |
olle |
else if (value.length == 13) |
2933 |
14 Nov 14 |
olle |
178 |
{ |
2933 |
14 Nov 14 |
olle |
// YYYYMMDD HHMM |
2933 |
14 Nov 14 |
olle |
value = value.substr(0, 4) + '-' + value.substr(4, 2) + '-' + value.substr(6, 2) + ' ' + value.substr(9, 2) + ':' + value.substr(11, 2); |
2933 |
14 Nov 14 |
olle |
181 |
} |
2933 |
14 Nov 14 |
olle |
return value; |
2933 |
14 Nov 14 |
olle |
183 |
} |
2933 |
14 Nov 14 |
olle |
184 |
|
2933 |
14 Nov 14 |
olle |
185 |
|
2933 |
14 Nov 14 |
olle |
186 |
/** |
2933 |
14 Nov 14 |
olle |
Get subtype information. |
2933 |
14 Nov 14 |
olle |
188 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.getSubtypeInfo = function(subtype) |
2933 |
14 Nov 14 |
olle |
190 |
{ |
2933 |
14 Nov 14 |
olle |
var url = '../Subtype.servlet?ID='+App.getSessionId(); |
2933 |
14 Nov 14 |
olle |
url += '&cmd=GetSubtypeInfo&name='+subtype; |
2933 |
14 Nov 14 |
olle |
var response = Wizard.syncJsonRequest(url); |
2933 |
14 Nov 14 |
olle |
return response ? response.subtype : null; |
2933 |
14 Nov 14 |
olle |
195 |
} |
2933 |
14 Nov 14 |
olle |
196 |
|
2933 |
14 Nov 14 |
olle |
meludi.setCurrentDirectory = function(path) |
2933 |
14 Nov 14 |
olle |
198 |
{ |
2933 |
14 Nov 14 |
olle |
if (path == currentDirectory) return; |
2933 |
14 Nov 14 |
olle |
var url = '../Session.servlet?ID='+App.getSessionId(); |
2933 |
14 Nov 14 |
olle |
url += '&cmd=SetCurrentDirectory&path='+encodeURIComponent(path); |
2933 |
14 Nov 14 |
olle |
Wizard.syncJsonRequest(url); |
2933 |
14 Nov 14 |
olle |
currentDirectory = path; |
2933 |
14 Nov 14 |
olle |
204 |
} |
2933 |
14 Nov 14 |
olle |
205 |
|
2933 |
14 Nov 14 |
olle |
206 |
/** |
2933 |
14 Nov 14 |
olle |
Load protocols of the given subtype and add them |
2933 |
14 Nov 14 |
olle |
to a selection list. This method submits an |
2933 |
14 Nov 14 |
olle |
async request to the server and then returns |
2933 |
14 Nov 14 |
olle |
immediately. |
2933 |
14 Nov 14 |
olle |
211 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.loadProtocols = function(subtype, list, annotations) |
2933 |
14 Nov 14 |
olle |
213 |
{ |
2933 |
14 Nov 14 |
olle |
list = Doc.element(list); |
2933 |
14 Nov 14 |
olle |
list.length=0; |
2933 |
14 Nov 14 |
olle |
list[0] = new Option('loading...', ''); |
2933 |
14 Nov 14 |
olle |
Doc.addClass(list, 'list-loading'); |
2933 |
14 Nov 14 |
olle |
var url = '../Protocol.servlet?ID='+App.getSessionId(); |
2933 |
14 Nov 14 |
olle |
url += '&cmd=GetProtocols&subtype='+subtype; |
2933 |
14 Nov 14 |
olle |
Wizard.asyncJsonRequest(url, |
2933 |
14 Nov 14 |
olle |
function(response) |
2933 |
14 Nov 14 |
olle |
222 |
{ |
2933 |
14 Nov 14 |
olle |
internal.fillList(response.protocols, list, true); |
2933 |
14 Nov 14 |
olle |
224 |
} |
2933 |
14 Nov 14 |
olle |
225 |
); |
2933 |
14 Nov 14 |
olle |
226 |
} |
2933 |
14 Nov 14 |
olle |
227 |
|
2933 |
14 Nov 14 |
olle |
228 |
/** |
2933 |
14 Nov 14 |
olle |
Load software of the given subtype and add them |
2933 |
14 Nov 14 |
olle |
to a selection list. This method submits an |
2933 |
14 Nov 14 |
olle |
async request to the server and then returns |
2933 |
14 Nov 14 |
olle |
immediately. |
2933 |
14 Nov 14 |
olle |
233 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.loadSoftware = function(subtype, list) |
2933 |
14 Nov 14 |
olle |
235 |
{ |
2933 |
14 Nov 14 |
olle |
list = Doc.element(list); |
2933 |
14 Nov 14 |
olle |
list.length=0; |
2933 |
14 Nov 14 |
olle |
list[0] = new Option('loading...', ''); |
2933 |
14 Nov 14 |
olle |
Doc.addClass(list, 'list-loading'); |
2933 |
14 Nov 14 |
olle |
var url = '../Software.servlet?ID='+App.getSessionId(); |
2933 |
14 Nov 14 |
olle |
url += '&cmd=GetSoftware&subtype='+subtype; |
2933 |
14 Nov 14 |
olle |
Wizard.asyncJsonRequest(url, |
2933 |
14 Nov 14 |
olle |
function(response) |
2933 |
14 Nov 14 |
olle |
244 |
{ |
2933 |
14 Nov 14 |
olle |
internal.fillList(response.software, list, true); |
2933 |
14 Nov 14 |
olle |
246 |
} |
2933 |
14 Nov 14 |
olle |
247 |
); |
2933 |
14 Nov 14 |
olle |
248 |
} |
2933 |
14 Nov 14 |
olle |
249 |
|
2933 |
14 Nov 14 |
olle |
250 |
/** |
2933 |
14 Nov 14 |
olle |
Load hardware of the given subtype and add them |
2933 |
14 Nov 14 |
olle |
to a selection list. This method submits an |
2933 |
14 Nov 14 |
olle |
async request to the server and then returns |
2933 |
14 Nov 14 |
olle |
immediately. |
2933 |
14 Nov 14 |
olle |
255 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.loadHardware = function(subtype, list, annotations) |
2933 |
14 Nov 14 |
olle |
257 |
{ |
2933 |
14 Nov 14 |
olle |
list = Doc.element(list); |
2933 |
14 Nov 14 |
olle |
list.length=0; |
2933 |
14 Nov 14 |
olle |
list[0] = new Option('loading...', ''); |
2933 |
14 Nov 14 |
olle |
Doc.addClass(list, 'list-loading'); |
2933 |
14 Nov 14 |
olle |
var url = '../Hardware.servlet?ID='+App.getSessionId(); |
2933 |
14 Nov 14 |
olle |
url += '&cmd=GetHardware&subtype='+subtype; |
2933 |
14 Nov 14 |
olle |
if (annotations) |
2933 |
14 Nov 14 |
olle |
265 |
{ |
2933 |
14 Nov 14 |
olle |
url += '&annotations='+annotations; |
2933 |
14 Nov 14 |
olle |
267 |
} |
2933 |
14 Nov 14 |
olle |
Wizard.asyncJsonRequest(url, |
2933 |
14 Nov 14 |
olle |
function(response) |
2933 |
14 Nov 14 |
olle |
270 |
{ |
2933 |
14 Nov 14 |
olle |
internal.fillList(response.hardware, list, true); |
2933 |
14 Nov 14 |
olle |
272 |
} |
2933 |
14 Nov 14 |
olle |
273 |
); |
2933 |
14 Nov 14 |
olle |
274 |
} |
2933 |
14 Nov 14 |
olle |
275 |
|
2933 |
14 Nov 14 |
olle |
// Fills a selection list with items |
2933 |
14 Nov 14 |
olle |
internal.fillList = function(items, list, addNoneOption) |
2933 |
14 Nov 14 |
olle |
278 |
{ |
2933 |
14 Nov 14 |
olle |
Doc.removeClass(list, 'list-loading'); |
2933 |
14 Nov 14 |
olle |
list.length = 0; |
2933 |
14 Nov 14 |
olle |
for (var i = 0; i < items.length; i++) |
2933 |
14 Nov 14 |
olle |
282 |
{ |
2933 |
14 Nov 14 |
olle |
var item = items[i]; |
2933 |
14 Nov 14 |
olle |
var option = new Option(item.name, item.id, item.isDefault); |
2933 |
14 Nov 14 |
olle |
option.item = item; |
2933 |
14 Nov 14 |
olle |
list[list.length] = option; |
2933 |
14 Nov 14 |
olle |
287 |
} |
2933 |
14 Nov 14 |
olle |
if (list.length > 0) Wizard.setInputStatus(list.id, 'valid'); |
2933 |
14 Nov 14 |
olle |
if (addNoneOption) |
2933 |
14 Nov 14 |
olle |
290 |
{ |
2933 |
14 Nov 14 |
olle |
list[list.length] = new Option('- none -', ''); |
2933 |
14 Nov 14 |
olle |
292 |
} |
2933 |
14 Nov 14 |
olle |
293 |
} |
2933 |
14 Nov 14 |
olle |
294 |
|
2933 |
14 Nov 14 |
olle |
meludi.isStratagene = function(sampleName) |
2933 |
14 Nov 14 |
olle |
296 |
{ |
2933 |
14 Nov 14 |
olle |
return sampleName.indexOf(GENERIC_STRATAGENE_NAME) == 0; |
2933 |
14 Nov 14 |
olle |
298 |
} |
2933 |
14 Nov 14 |
olle |
299 |
|
2933 |
14 Nov 14 |
olle |
meludi.isExternal = function(sampleName) |
2933 |
14 Nov 14 |
olle |
301 |
{ |
2933 |
14 Nov 14 |
olle |
return sampleName.indexOf(EXTERNAL_RNA_NAME) == 0; |
2933 |
14 Nov 14 |
olle |
303 |
} |
2933 |
14 Nov 14 |
olle |
304 |
|
2933 |
14 Nov 14 |
olle |
meludi.wellToAlpha = function(wellNo) |
2933 |
14 Nov 14 |
olle |
306 |
{ |
2933 |
14 Nov 14 |
olle |
return wellNo >=0 && wellNo < WELL_ALPHA.length ? WELL_ALPHA[wellNo] : '?'; |
2933 |
14 Nov 14 |
olle |
308 |
} |
2933 |
14 Nov 14 |
olle |
309 |
|
2933 |
14 Nov 14 |
olle |
meludi.alphaToWell = function(wellAlpha) |
2933 |
14 Nov 14 |
olle |
311 |
{ |
2933 |
14 Nov 14 |
olle |
return WELL_ALPHA.indexOf(wellAlpha.toUpperCase()); |
2933 |
14 Nov 14 |
olle |
313 |
} |
2933 |
14 Nov 14 |
olle |
314 |
|
2933 |
14 Nov 14 |
olle |
315 |
/** |
2933 |
14 Nov 14 |
olle |
Open a popup window and copy a part of the current window to the popup |
2933 |
14 Nov 14 |
olle |
and make it suitable for printin. |
2933 |
14 Nov 14 |
olle |
318 |
|
2933 |
14 Nov 14 |
olle |
@param printElementId The id of a html tag in the current page that should |
2933 |
14 Nov 14 |
olle |
be copied to the print window |
2933 |
14 Nov 14 |
olle |
@param pageTitle The title of the print window |
2933 |
14 Nov 14 |
olle |
@param pageOrientation 'landscape' or 'portrait' (default) |
2933 |
14 Nov 14 |
olle |
@param printNote Optional note intended to include instructions how to configure |
2933 |
14 Nov 14 |
olle |
the browser for optimal printing (eg. set to landscape and scale to 75%) |
2933 |
14 Nov 14 |
olle |
325 |
*/ |
2933 |
14 Nov 14 |
olle |
meludi.openPrintWindow = function(printElementId, pageTitle, pageOrientation, printNote, meludiRoot, extraStyles) |
2933 |
14 Nov 14 |
olle |
327 |
{ |
2933 |
14 Nov 14 |
olle |
// Default width/height is for 'portrait' orientation |
2933 |
14 Nov 14 |
olle |
var width = 900; |
2933 |
14 Nov 14 |
olle |
var height = 900; |
2933 |
14 Nov 14 |
olle |
if (pageOrientation == 'landscape') |
2933 |
14 Nov 14 |
olle |
332 |
{ |
2933 |
14 Nov 14 |
olle |
width = 1300; |
2933 |
14 Nov 14 |
olle |
height = 700; |
2933 |
14 Nov 14 |
olle |
335 |
} |
2933 |
14 Nov 14 |
olle |
336 |
|
2933 |
14 Nov 14 |
olle |
var url = 'print_template.jsp?ID='+App.getSessionId(); |
2933 |
14 Nov 14 |
olle |
if (extraStyles) url += '&extraStyles='+extraStyles; |
2933 |
14 Nov 14 |
olle |
if (meludiRoot) url = meludiRoot+url; |
2933 |
14 Nov 14 |
olle |
// Open the print-window |
2933 |
14 Nov 14 |
olle |
internal.printOptions = { |
2933 |
14 Nov 14 |
olle |
'printElementId': printElementId, |
2933 |
14 Nov 14 |
olle |
'pageTitle': pageTitle, |
2933 |
14 Nov 14 |
olle |
'pageOrientation': pageOrientation, |
2933 |
14 Nov 14 |
olle |
'printNote': printNote |
2933 |
14 Nov 14 |
olle |
346 |
}; |
2933 |
14 Nov 14 |
olle |
var printWin = window.open(url, 'PrintWindow', 'width='+width+',height='+height+',toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes'); |
2933 |
14 Nov 14 |
olle |
348 |
} |
2933 |
14 Nov 14 |
olle |
349 |
|
2933 |
14 Nov 14 |
olle |
meludi.finalizePrint = function(printWin) |
2933 |
14 Nov 14 |
olle |
351 |
{ |
2933 |
14 Nov 14 |
olle |
// Set page title... |
2933 |
14 Nov 14 |
olle |
if (internal.printOptions.pageTitle) |
2933 |
14 Nov 14 |
olle |
354 |
{ |
2933 |
14 Nov 14 |
olle |
printWin.document.title = internal.printOptions.pageTitle; |
2933 |
14 Nov 14 |
olle |
356 |
} |
2933 |
14 Nov 14 |
olle |
357 |
|
2933 |
14 Nov 14 |
olle |
// ...orientation... |
2933 |
14 Nov 14 |
olle |
if (internal.printOptions.pageOrientation) |
2933 |
14 Nov 14 |
olle |
360 |
{ |
2933 |
14 Nov 14 |
olle |
var paper = printWin.document.getElementById('paper'); |
2933 |
14 Nov 14 |
olle |
paper.className += ' ' + internal.printOptions.pageOrientation; |
2933 |
14 Nov 14 |
olle |
363 |
} |
2933 |
14 Nov 14 |
olle |
364 |
|
2933 |
14 Nov 14 |
olle |
// ... and print note |
2933 |
14 Nov 14 |
olle |
if (internal.printOptions.printNote) |
2933 |
14 Nov 14 |
olle |
367 |
{ |
2933 |
14 Nov 14 |
olle |
var note = printWin.document.getElementById('printNote'); |
2933 |
14 Nov 14 |
olle |
note.innerHTML = internal.printOptions.printNote; |
2933 |
14 Nov 14 |
olle |
370 |
} |
2933 |
14 Nov 14 |
olle |
371 |
|
2933 |
14 Nov 14 |
olle |
// Get the HTML from the <div> tag to be printed |
2933 |
14 Nov 14 |
olle |
var printElement = Doc.element(internal.printOptions.printElementId); |
2933 |
14 Nov 14 |
olle |
var printHtml = printElement.innerHTML; |
2933 |
14 Nov 14 |
olle |
// Replace all <canvas> elements with <img> |
2933 |
14 Nov 14 |
olle |
// since that seems the only way to make things work in IE |
2933 |
14 Nov 14 |
olle |
printHtml = printHtml.replace(/\<canvas.*?\<\/canvas\>/g, '<img class="canvas-copy">'); |
2933 |
14 Nov 14 |
olle |
378 |
|
2933 |
14 Nov 14 |
olle |
// Copy the HTML to the print-area in the print-window |
2933 |
14 Nov 14 |
olle |
var printArea = printWin.document.getElementById('printarea'); |
2933 |
14 Nov 14 |
olle |
printArea.innerHTML = printHtml; |
2933 |
14 Nov 14 |
olle |
382 |
|
2933 |
14 Nov 14 |
olle |
// Copy the <canvas> elements as images to the <img> elements |
2933 |
14 Nov 14 |
olle |
// using toDataURL() |
2933 |
14 Nov 14 |
olle |
var srcCanvas = printElement.getElementsByTagName('canvas'); |
2933 |
14 Nov 14 |
olle |
var printImg = printArea.getElementsByClassName('canvas-copy'); |
2933 |
14 Nov 14 |
olle |
for (var i = 0; i < srcCanvas.length; i++) |
2933 |
14 Nov 14 |
olle |
388 |
{ |
2933 |
14 Nov 14 |
olle |
printImg[i].src = srcCanvas[i].toDataURL(); |
2933 |
14 Nov 14 |
olle |
390 |
} |
2933 |
14 Nov 14 |
olle |
391 |
|
2933 |
14 Nov 14 |
olle |
392 |
} |
2933 |
14 Nov 14 |
olle |
393 |
|
2933 |
14 Nov 14 |
olle |
return meludi; |
2933 |
14 Nov 14 |
olle |
395 |
}(); |
2933 |
14 Nov 14 |
olle |
396 |
|
2933 |
14 Nov 14 |
olle |
397 |
|
2933 |
14 Nov 14 |
olle |
398 |
|
2933 |
14 Nov 14 |
olle |
399 |
|
2933 |
14 Nov 14 |
olle |
var Wizard = function() |
2933 |
14 Nov 14 |
olle |
401 |
{ |
2933 |
14 Nov 14 |
olle |
var wizard = {}; |
2933 |
14 Nov 14 |
olle |
var internal = {}; |
3185 |
18 Mar 15 |
olle |
var debug = 0; |
2933 |
14 Nov 14 |
olle |
405 |
|
2933 |
14 Nov 14 |
olle |
var currentStep = 1; |
2933 |
14 Nov 14 |
olle |
var numLiveAsyncRequests = 0; |
2933 |
14 Nov 14 |
olle |
var hasSentRegistration = false; |
2933 |
14 Nov 14 |
olle |
var forceConfirm = false; |
2933 |
14 Nov 14 |
olle |
var noConfirmOnFirstStep = true; |
2933 |
14 Nov 14 |
olle |
var hasFatalError = false; |
2933 |
14 Nov 14 |
olle |
412 |
|
2933 |
14 Nov 14 |
olle |
413 |
/** |
2933 |
14 Nov 14 |
olle |
Validate the 'date'-input field that is the target of this event |
2933 |
14 Nov 14 |
olle |
The date is optional unless 'required' is part if it's className. |
2933 |
14 Nov 14 |
olle |
Dates should be either 4 or 8 digits with month+day or year+month+day. |
2933 |
14 Nov 14 |
olle |
If 'data-allow-six-digits' is set on the target element, the year |
2933 |
14 Nov 14 |
olle |
is allowed to be only 2 digits. |
2933 |
14 Nov 14 |
olle |
419 |
|
2933 |
14 Nov 14 |
olle |
4-digit (and 6-digit) dates auto-padded to 8 digits. |
2933 |
14 Nov 14 |
olle |
421 |
|
2933 |
14 Nov 14 |
olle |
The 'data-valid' attribute is set to 1 or 0 depending on the outcome, |
2933 |
14 Nov 14 |
olle |
and 'data-warning' is set if the date is missing on non-required fields. |
2933 |
14 Nov 14 |
olle |
424 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.validateDate = function(event) |
2933 |
14 Nov 14 |
olle |
426 |
{ |
2933 |
14 Nov 14 |
olle |
var target = event.currentTarget; |
2933 |
14 Nov 14 |
olle |
var isValid = false; |
2933 |
14 Nov 14 |
olle |
var isWarning = false; |
2933 |
14 Nov 14 |
olle |
430 |
|
2933 |
14 Nov 14 |
olle |
// Reset current status |
2933 |
14 Nov 14 |
olle |
wizard.setInputStatus(target); |
2933 |
14 Nov 14 |
olle |
433 |
|
2933 |
14 Nov 14 |
olle |
var date = target.value; |
2933 |
14 Nov 14 |
olle |
if (date == '') |
2933 |
14 Nov 14 |
olle |
436 |
{ |
2933 |
14 Nov 14 |
olle |
// No date, is this an error or a warning? |
2933 |
14 Nov 14 |
olle |
var optional = target.className.indexOf('required') == -1; |
2933 |
14 Nov 14 |
olle |
wizard.setInputStatus(target, optional ? 'warning' : 'invalid', 'Missing'); |
2933 |
14 Nov 14 |
olle |
isValid = optional; |
2933 |
14 Nov 14 |
olle |
isWarning = optional; |
2933 |
14 Nov 14 |
olle |
442 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
444 |
{ |
2933 |
14 Nov 14 |
olle |
var allowSixDigits = Data.int(target, 'allow-six-digits'); |
2933 |
14 Nov 14 |
olle |
date = Meludi.autoFillDate(date, allowSixDigits); |
2933 |
14 Nov 14 |
olle |
target.value = date; |
2933 |
14 Nov 14 |
olle |
448 |
|
2933 |
14 Nov 14 |
olle |
var d = Dates.parseString(date, 'yyyyMMdd'); |
2933 |
14 Nov 14 |
olle |
if (d == null) |
2933 |
14 Nov 14 |
olle |
451 |
{ |
2933 |
14 Nov 14 |
olle |
Wizard.setInputStatus(target, 'invalid', 'Not a valid date'); |
2933 |
14 Nov 14 |
olle |
453 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
455 |
{ |
2933 |
14 Nov 14 |
olle |
var disallowFutureDate = Data.int(target, 'disallow-future-date'); |
2933 |
14 Nov 14 |
olle |
var today = new Date(); |
2933 |
14 Nov 14 |
olle |
if (disallowFutureDate && (d.getTime() > today.getTime())) |
2933 |
14 Nov 14 |
olle |
459 |
{ |
2933 |
14 Nov 14 |
olle |
Wizard.setInputStatus(target, 'invalid', 'Future dates are not valid'); |
2933 |
14 Nov 14 |
olle |
461 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
463 |
{ |
2933 |
14 Nov 14 |
olle |
Wizard.setInputStatus(target, 'valid'); |
2933 |
14 Nov 14 |
olle |
isValid = true; |
2933 |
14 Nov 14 |
olle |
466 |
} |
2933 |
14 Nov 14 |
olle |
467 |
} |
2933 |
14 Nov 14 |
olle |
468 |
} |
2933 |
14 Nov 14 |
olle |
469 |
|
2933 |
14 Nov 14 |
olle |
Data.set(target, 'valid', isValid ? 1 : 0); |
2933 |
14 Nov 14 |
olle |
Data.set(target, 'warning', isWarning ? 1 : 0); |
2933 |
14 Nov 14 |
olle |
472 |
|
2933 |
14 Nov 14 |
olle |
if (!isValid && target.focus) target.focus(); |
2933 |
14 Nov 14 |
olle |
return isValid; |
2933 |
14 Nov 14 |
olle |
475 |
} |
2933 |
14 Nov 14 |
olle |
476 |
|
2933 |
14 Nov 14 |
olle |
477 |
|
2933 |
14 Nov 14 |
olle |
wizard.isValid = function(element) |
2933 |
14 Nov 14 |
olle |
479 |
{ |
2933 |
14 Nov 14 |
olle |
return Data.int(element, 'valid', 1); |
2933 |
14 Nov 14 |
olle |
481 |
} |
2933 |
14 Nov 14 |
olle |
482 |
|
2933 |
14 Nov 14 |
olle |
483 |
|
2933 |
14 Nov 14 |
olle |
wizard.initFileSelectionField = function(element) |
2933 |
14 Nov 14 |
olle |
485 |
{ |
2933 |
14 Nov 14 |
olle |
element = Doc.element(element); |
2933 |
14 Nov 14 |
olle |
487 |
|
2933 |
14 Nov 14 |
olle |
var subtype = Data.get(element, 'subtype'); |
2933 |
14 Nov 14 |
olle |
if (subtype) |
2933 |
14 Nov 14 |
olle |
490 |
{ |
5149 |
28 Nov 18 |
olle |
element.subtype = Meludi.getSubtypeInfo(subtype); |
2933 |
14 Nov 14 |
olle |
492 |
} |
2933 |
14 Nov 14 |
olle |
493 |
|
2933 |
14 Nov 14 |
olle |
Buttons.addClickHandler(element.id + '.btn', wizard.browseOnClick, { 'file-field': element.id }); |
2933 |
14 Nov 14 |
olle |
Events.doOnEnter(element, wizard.browseOnClick); |
2933 |
14 Nov 14 |
olle |
496 |
|
2933 |
14 Nov 14 |
olle |
Events.addEventHandler(element, 'base-selected', wizard.fileSelected); |
2933 |
14 Nov 14 |
olle |
Events.addEventHandler(element, 'change', wizard.fileChanged); |
2933 |
14 Nov 14 |
olle |
Events.sendChangeEvent(element); |
2933 |
14 Nov 14 |
olle |
500 |
} |
2933 |
14 Nov 14 |
olle |
501 |
|
2933 |
14 Nov 14 |
olle |
wizard.browseOnClick = function(event) |
2933 |
14 Nov 14 |
olle |
503 |
{ |
2933 |
14 Nov 14 |
olle |
var fileField = Doc.element(Data.get(event.currentTarget, 'file-field', event.currentTarget.id)); |
2933 |
14 Nov 14 |
olle |
505 |
|
2933 |
14 Nov 14 |
olle |
var url = '&resetTemporary=1'; |
2933 |
14 Nov 14 |
olle |
var nameFilter = Data.get(fileField, 'name-filter'); |
2933 |
14 Nov 14 |
olle |
if (nameFilter) |
2933 |
14 Nov 14 |
olle |
509 |
{ |
2933 |
14 Nov 14 |
olle |
url += '&tmpfilter:STRING:name='+encodeURIComponent(nameFilter); |
2933 |
14 Nov 14 |
olle |
511 |
} |
2933 |
14 Nov 14 |
olle |
512 |
|
2933 |
14 Nov 14 |
olle |
var subtype = fileField.subtype; |
2933 |
14 Nov 14 |
olle |
if (subtype) |
2933 |
14 Nov 14 |
olle |
515 |
{ |
2933 |
14 Nov 14 |
olle |
url += '&tmpfilter:INT:itemSubtype='+subtype.id; |
2933 |
14 Nov 14 |
olle |
517 |
} |
2933 |
14 Nov 14 |
olle |
518 |
|
2933 |
14 Nov 14 |
olle |
var directory = Data.get(fileField, 'directory'); |
2933 |
14 Nov 14 |
olle |
if (directory && !Data.get(fileField, 'has-browsed')) |
2933 |
14 Nov 14 |
olle |
521 |
{ |
2933 |
14 Nov 14 |
olle |
Meludi.setCurrentDirectory(directory); |
2933 |
14 Nov 14 |
olle |
Data.set(fileField, 'has-browsed', 1); |
2933 |
14 Nov 14 |
olle |
524 |
} |
2933 |
14 Nov 14 |
olle |
525 |
|
2933 |
14 Nov 14 |
olle |
Dialogs.selectItem('FILE', fileField, 0, url); |
2933 |
14 Nov 14 |
olle |
527 |
} |
2933 |
14 Nov 14 |
olle |
528 |
|
2933 |
14 Nov 14 |
olle |
wizard.fileSelected = function(event) |
2933 |
14 Nov 14 |
olle |
530 |
{ |
2933 |
14 Nov 14 |
olle |
event.currentTarget.value = event.detail.name; |
2933 |
14 Nov 14 |
olle |
Events.sendChangeEvent(event.currentTarget); |
2933 |
14 Nov 14 |
olle |
533 |
} |
2933 |
14 Nov 14 |
olle |
534 |
|
2933 |
14 Nov 14 |
olle |
wizard.fileChanged = function(event) |
2933 |
14 Nov 14 |
olle |
536 |
{ |
2933 |
14 Nov 14 |
olle |
var target = event.currentTarget; |
2933 |
14 Nov 14 |
olle |
538 |
|
2933 |
14 Nov 14 |
olle |
var isValid = false; |
2933 |
14 Nov 14 |
olle |
var isWarning = false; |
2933 |
14 Nov 14 |
olle |
541 |
|
2933 |
14 Nov 14 |
olle |
// Reset current status |
2933 |
14 Nov 14 |
olle |
wizard.setInputStatus(target); |
2933 |
14 Nov 14 |
olle |
544 |
|
2933 |
14 Nov 14 |
olle |
var path = target.value; |
2933 |
14 Nov 14 |
olle |
if (path == '') |
2933 |
14 Nov 14 |
olle |
547 |
{ |
2933 |
14 Nov 14 |
olle |
// No file, is this an error or a warning? |
2933 |
14 Nov 14 |
olle |
var optional = target.className.indexOf('required') == -1; |
2933 |
14 Nov 14 |
olle |
wizard.setInputStatus(target, optional ? 'warning' : 'invalid', 'Missing'); |
2933 |
14 Nov 14 |
olle |
isValid = optional; |
2933 |
14 Nov 14 |
olle |
isWarning = optional; |
2933 |
14 Nov 14 |
olle |
553 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
555 |
{ |
2933 |
14 Nov 14 |
olle |
Wizard.setInputStatus(target, 'valid'); |
2933 |
14 Nov 14 |
olle |
isValid = true; |
2933 |
14 Nov 14 |
olle |
558 |
} |
2933 |
14 Nov 14 |
olle |
559 |
|
2933 |
14 Nov 14 |
olle |
Data.set(target, 'valid', isValid ? 1 : 0); |
2933 |
14 Nov 14 |
olle |
Data.set(target, 'warning', isWarning ? 1 : 0); |
2933 |
14 Nov 14 |
olle |
562 |
|
2933 |
14 Nov 14 |
olle |
if (!isValid && target.focus) target.focus(); |
2933 |
14 Nov 14 |
olle |
564 |
} |
2933 |
14 Nov 14 |
olle |
565 |
|
2933 |
14 Nov 14 |
olle |
566 |
|
2933 |
14 Nov 14 |
olle |
567 |
/** |
5149 |
28 Nov 18 |
olle |
Get subtype information. |
5149 |
28 Nov 18 |
olle |
569 |
*/ |
5149 |
28 Nov 18 |
olle |
wizard.getSubtypeInfo = function(subtype) |
5149 |
28 Nov 18 |
olle |
571 |
{ |
5149 |
28 Nov 18 |
olle |
var url = '../Subtype.servlet?ID='+App.getSessionId(); |
5149 |
28 Nov 18 |
olle |
url += '&cmd=GetSubtypeInfo&name='+subtype; |
5149 |
28 Nov 18 |
olle |
var response = Wizard.syncJsonRequest(url); |
5149 |
28 Nov 18 |
olle |
return response ? response.subtype : null; |
5149 |
28 Nov 18 |
olle |
576 |
} |
5149 |
28 Nov 18 |
olle |
577 |
|
5149 |
28 Nov 18 |
olle |
578 |
/** |
5149 |
28 Nov 18 |
olle |
Get data file type information. |
5149 |
28 Nov 18 |
olle |
580 |
*/ |
5149 |
28 Nov 18 |
olle |
wizard.getDataFileTypeInfo = function(filetype) |
5149 |
28 Nov 18 |
olle |
582 |
{ |
5149 |
28 Nov 18 |
olle |
var url = '../Subtype.servlet?ID='+App.getSessionId(); |
5149 |
28 Nov 18 |
olle |
url += '&cmd=GetDataFileTypeInfo&name='+filetype; |
5149 |
28 Nov 18 |
olle |
var response = Wizard.syncJsonRequest(url); |
5149 |
28 Nov 18 |
olle |
return response ? response.fileType : null; |
5149 |
28 Nov 18 |
olle |
587 |
} |
5149 |
28 Nov 18 |
olle |
588 |
|
5149 |
28 Nov 18 |
olle |
wizard.setCurrentDirectory = function(path) |
5149 |
28 Nov 18 |
olle |
590 |
{ |
5149 |
28 Nov 18 |
olle |
if (path == currentDirectory) return; |
5149 |
28 Nov 18 |
olle |
var url = '../Session.servlet?ID='+App.getSessionId(); |
5149 |
28 Nov 18 |
olle |
url += '&cmd=SetCurrentDirectory&path='+encodeURIComponent(path); |
5149 |
28 Nov 18 |
olle |
Wizard.syncJsonRequest(url); |
5149 |
28 Nov 18 |
olle |
currentDirectory = path; |
5149 |
28 Nov 18 |
olle |
596 |
} |
5149 |
28 Nov 18 |
olle |
597 |
|
5149 |
28 Nov 18 |
olle |
598 |
/** |
2933 |
14 Nov 14 |
olle |
Change display status for an input field. |
2933 |
14 Nov 14 |
olle |
@param prefix ID prefix to locate tags |
2933 |
14 Nov 14 |
olle |
@param clazz The message clazz (valid, invalid, warning) or empty |
2933 |
14 Nov 14 |
olle |
@param message The message (may be empty) |
2933 |
14 Nov 14 |
olle |
603 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.setInputStatus = function(prefix, clazz, message) |
2933 |
14 Nov 14 |
olle |
605 |
{ |
2933 |
14 Nov 14 |
olle |
if (prefix.id) prefix = prefix.id; |
2933 |
14 Nov 14 |
olle |
607 |
|
2933 |
14 Nov 14 |
olle |
var statusTag = Doc.element(prefix + '.status'); |
2933 |
14 Nov 14 |
olle |
statusTag.className = 'status ' + (clazz || ''); |
2933 |
14 Nov 14 |
olle |
610 |
|
2933 |
14 Nov 14 |
olle |
var trTag = statusTag.parentNode; |
2933 |
14 Nov 14 |
olle |
var trClass = Data.get(trTag, 'original-class'); |
2933 |
14 Nov 14 |
olle |
if (!trClass) |
2933 |
14 Nov 14 |
olle |
614 |
{ |
2933 |
14 Nov 14 |
olle |
trClass = trTag.className || 'foo'; |
2933 |
14 Nov 14 |
olle |
Data.set(trTag, 'original-class', trClass); |
2933 |
14 Nov 14 |
olle |
617 |
} |
2933 |
14 Nov 14 |
olle |
trTag.className = trClass + ' ' + (clazz || ''); |
2933 |
14 Nov 14 |
olle |
619 |
|
2933 |
14 Nov 14 |
olle |
var msgTag = Doc.element(prefix + '.message'); |
2933 |
14 Nov 14 |
olle |
if (msgTag) |
2933 |
14 Nov 14 |
olle |
622 |
{ |
2933 |
14 Nov 14 |
olle |
if (message) |
2933 |
14 Nov 14 |
olle |
624 |
{ |
2933 |
14 Nov 14 |
olle |
msgTag.innerHTML = message; |
2933 |
14 Nov 14 |
olle |
Doc.show(msgTag, Data.get(msgTag, 'display', 'inline')); |
2933 |
14 Nov 14 |
olle |
627 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
629 |
{ |
2933 |
14 Nov 14 |
olle |
msgTag.innerHTML = message; |
2933 |
14 Nov 14 |
olle |
Doc.hide(msgTag); |
2933 |
14 Nov 14 |
olle |
632 |
} |
2933 |
14 Nov 14 |
olle |
633 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
635 |
{ |
2933 |
14 Nov 14 |
olle |
statusTag.title = message || ''; |
2933 |
14 Nov 14 |
olle |
637 |
} |
2933 |
14 Nov 14 |
olle |
638 |
} |
2933 |
14 Nov 14 |
olle |
639 |
|
2933 |
14 Nov 14 |
olle |
640 |
|
2933 |
14 Nov 14 |
olle |
641 |
/** |
2933 |
14 Nov 14 |
olle |
Event handler for input fields, that go to the |
2933 |
14 Nov 14 |
olle |
next wizard step if TAB or ENTER key is pressed. |
2933 |
14 Nov 14 |
olle |
A short delay is used to allow other event handler |
2933 |
14 Nov 14 |
olle |
to run first (eg. for validation). |
2933 |
14 Nov 14 |
olle |
646 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.goNextOnTabOrEnter = function(event) |
2933 |
14 Nov 14 |
olle |
648 |
{ |
2933 |
14 Nov 14 |
olle |
if (event.keyCode == 9 || event.keyCode == 13) |
2933 |
14 Nov 14 |
olle |
650 |
{ |
2933 |
14 Nov 14 |
olle |
setTimeout(function() { wizard.goNext(true) }, 200); |
2933 |
14 Nov 14 |
olle |
652 |
} |
2933 |
14 Nov 14 |
olle |
653 |
} |
2933 |
14 Nov 14 |
olle |
654 |
|
2933 |
14 Nov 14 |
olle |
655 |
/** |
2933 |
14 Nov 14 |
olle |
Event handler for input fields, that go to the |
2933 |
14 Nov 14 |
olle |
next wizard step if TAB key is pressed. |
2933 |
14 Nov 14 |
olle |
A short delay is used to allow other event handler |
2933 |
14 Nov 14 |
olle |
to run first (eg. for validation). |
2933 |
14 Nov 14 |
olle |
660 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.goNextOnTab = function(event) |
2933 |
14 Nov 14 |
olle |
662 |
{ |
2933 |
14 Nov 14 |
olle |
if (event.keyCode == 9) |
2933 |
14 Nov 14 |
olle |
664 |
{ |
2933 |
14 Nov 14 |
olle |
setTimeout(function() { wizard.goNext(true) }, 200); |
2933 |
14 Nov 14 |
olle |
666 |
} |
2933 |
14 Nov 14 |
olle |
667 |
} |
2933 |
14 Nov 14 |
olle |
668 |
|
2933 |
14 Nov 14 |
olle |
669 |
/** |
2933 |
14 Nov 14 |
olle |
Event handler for input fields, that changes |
2933 |
14 Nov 14 |
olle |
focus to the next element. The next element |
2933 |
14 Nov 14 |
olle |
should be defined by 'data-next-focus' attribute. |
2933 |
14 Nov 14 |
olle |
It is recommended that this is consisistent with TAB. |
2933 |
14 Nov 14 |
olle |
674 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.focusOnEnter = function(event) |
2933 |
14 Nov 14 |
olle |
676 |
{ |
2933 |
14 Nov 14 |
olle |
if (event.keyCode == 13) |
2933 |
14 Nov 14 |
olle |
678 |
{ |
2933 |
14 Nov 14 |
olle |
var nextFocus = Doc.element(Data.get(event.currentTarget, 'next-focus')); |
2933 |
14 Nov 14 |
olle |
if (nextFocus && nextFocus.focus) nextFocus.focus(); |
2933 |
14 Nov 14 |
olle |
681 |
} |
2933 |
14 Nov 14 |
olle |
682 |
} |
2933 |
14 Nov 14 |
olle |
683 |
|
2933 |
14 Nov 14 |
olle |
// Event handler for the 'Next' navigation button |
2933 |
14 Nov 14 |
olle |
wizard.goNextOnClick = function(event) |
2933 |
14 Nov 14 |
olle |
686 |
{ |
2933 |
14 Nov 14 |
olle |
wizard.goNext(false); |
2933 |
14 Nov 14 |
olle |
688 |
} |
2933 |
14 Nov 14 |
olle |
689 |
|
2933 |
14 Nov 14 |
olle |
690 |
/** |
2933 |
14 Nov 14 |
olle |
Go to the next step in the wizard. This method will first |
2933 |
14 Nov 14 |
olle |
submit 'wizard-validate' event to the current step. If at |
2933 |
14 Nov 14 |
olle |
least one event handler calls 'Event.preventDefault()' the |
2933 |
14 Nov 14 |
olle |
processing is aborted. |
2933 |
14 Nov 14 |
olle |
695 |
|
2933 |
14 Nov 14 |
olle |
Otherwise, the current step is disabled and the 'wizard-initialize' |
2933 |
14 Nov 14 |
olle |
event is sent to the next step. The event handler is responsible |
2933 |
14 Nov 14 |
olle |
for calling 'Wizard.setCurrentStep' to display the next step. |
2933 |
14 Nov 14 |
olle |
699 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.goNext = function(auto) |
2933 |
14 Nov 14 |
olle |
701 |
{ |
2933 |
14 Nov 14 |
olle |
var verify = Doc.element('verifyGoNext'); |
2933 |
14 Nov 14 |
olle |
if (verify && !verify.checked) return; |
2933 |
14 Nov 14 |
olle |
704 |
|
2933 |
14 Nov 14 |
olle |
var details = { 'auto': auto }; |
2933 |
14 Nov 14 |
olle |
706 |
|
2933 |
14 Nov 14 |
olle |
// Send 'wizard-validate' event to current step |
2933 |
14 Nov 14 |
olle |
var step = Doc.element('step-'+currentStep); |
2933 |
14 Nov 14 |
olle |
var evt = document.createEvent('CustomEvent'); |
2933 |
14 Nov 14 |
olle |
evt.initCustomEvent('wizard-validate', true, true, details); |
2933 |
14 Nov 14 |
olle |
if (!step.dispatchEvent(evt)) |
2933 |
14 Nov 14 |
olle |
712 |
{ |
2933 |
14 Nov 14 |
olle |
wizard.notifyError(); |
2933 |
14 Nov 14 |
olle |
return; |
2933 |
14 Nov 14 |
olle |
715 |
} |
2933 |
14 Nov 14 |
olle |
716 |
|
2933 |
14 Nov 14 |
olle |
// Hide all navigation buttons and disable form controls in current step |
2933 |
14 Nov 14 |
olle |
internal.hideButtons('navigation'); |
2933 |
14 Nov 14 |
olle |
internal.disableStep(step); |
2933 |
14 Nov 14 |
olle |
720 |
|
2933 |
14 Nov 14 |
olle |
// Send 'wizard-initialize' to the next step |
2933 |
14 Nov 14 |
olle |
var nextStep = Doc.element('step-'+(currentStep+1)); |
2933 |
14 Nov 14 |
olle |
var evt = document.createEvent('CustomEvent'); |
2933 |
14 Nov 14 |
olle |
evt.initCustomEvent('wizard-initialize', true, true, details); |
2933 |
14 Nov 14 |
olle |
nextStep.dispatchEvent(evt); |
2933 |
14 Nov 14 |
olle |
726 |
} |
2933 |
14 Nov 14 |
olle |
727 |
|
2933 |
14 Nov 14 |
olle |
wizard.notifyError = function() |
2933 |
14 Nov 14 |
olle |
729 |
{ |
2933 |
14 Nov 14 |
olle |
Doc.addClass('wizard', 'flash-error'); |
2933 |
14 Nov 14 |
olle |
setTimeout(internal.stopFlashing, 2000); |
2933 |
14 Nov 14 |
olle |
732 |
} |
2933 |
14 Nov 14 |
olle |
733 |
|
2933 |
14 Nov 14 |
olle |
internal.stopFlashing = function() |
2933 |
14 Nov 14 |
olle |
735 |
{ |
2933 |
14 Nov 14 |
olle |
Doc.removeClass('wizard', 'flash-error'); |
2933 |
14 Nov 14 |
olle |
737 |
} |
2933 |
14 Nov 14 |
olle |
738 |
|
2933 |
14 Nov 14 |
olle |
739 |
/** |
2933 |
14 Nov 14 |
olle |
Finalize the registration of the wizard. This method will |
2933 |
14 Nov 14 |
olle |
first submit 'wizard-validate' to the current step. If at |
2933 |
14 Nov 14 |
olle |
least one event handler calls 'Event.preventDefault()' the |
2933 |
14 Nov 14 |
olle |
processing is aborted. |
2933 |
14 Nov 14 |
olle |
744 |
|
2933 |
14 Nov 14 |
olle |
Otherwise, the current step is disabled and the 'wizard-submit' |
2933 |
14 Nov 14 |
olle |
event is sent to the 'wizard'. The event handler is responsible |
2933 |
14 Nov 14 |
olle |
for finalizing the registration and displaying a proper |
2933 |
14 Nov 14 |
olle |
message, for example, by calling Wizard.showFinalMessage() |
2933 |
14 Nov 14 |
olle |
749 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.goRegister = function() |
2933 |
14 Nov 14 |
olle |
751 |
{ |
2933 |
14 Nov 14 |
olle |
// Check if verification is enabled |
2933 |
14 Nov 14 |
olle |
var verify = Doc.element('verifyGoNext'); |
2933 |
14 Nov 14 |
olle |
if (verify && !verify.checked) return; |
2933 |
14 Nov 14 |
olle |
755 |
|
2933 |
14 Nov 14 |
olle |
// Send 'wizard-validate' event to current step |
2933 |
14 Nov 14 |
olle |
var step = Doc.element('step-'+currentStep); |
2933 |
14 Nov 14 |
olle |
var evt = document.createEvent('Event'); |
2933 |
14 Nov 14 |
olle |
evt.initEvent('wizard-validate', false, true); |
2933 |
14 Nov 14 |
olle |
if (!step.dispatchEvent(evt)) |
2933 |
14 Nov 14 |
olle |
761 |
{ |
2933 |
14 Nov 14 |
olle |
wizard.notifyError(); |
2933 |
14 Nov 14 |
olle |
return; |
2933 |
14 Nov 14 |
olle |
764 |
} |
2933 |
14 Nov 14 |
olle |
765 |
|
2933 |
14 Nov 14 |
olle |
internal.hideButtons('navigation'); |
2933 |
14 Nov 14 |
olle |
internal.disableStep(step); |
2933 |
14 Nov 14 |
olle |
768 |
|
2933 |
14 Nov 14 |
olle |
// Send 'wizard-submit' to the next step |
2933 |
14 Nov 14 |
olle |
var wiz = Doc.element('wizard'); |
2933 |
14 Nov 14 |
olle |
hasSentRegistration = true; |
2933 |
14 Nov 14 |
olle |
var evt = document.createEvent('Event'); |
2933 |
14 Nov 14 |
olle |
evt.initEvent('wizard-submit', false, true); |
2933 |
14 Nov 14 |
olle |
wiz.dispatchEvent(evt); |
2933 |
14 Nov 14 |
olle |
775 |
} |
2933 |
14 Nov 14 |
olle |
776 |
|
2933 |
14 Nov 14 |
olle |
wizard.setNoConfirmOnFirstStep = function(cf) |
2933 |
14 Nov 14 |
olle |
778 |
{ |
2933 |
14 Nov 14 |
olle |
noConfirmOnFirstStep = cf; |
2933 |
14 Nov 14 |
olle |
780 |
} |
2933 |
14 Nov 14 |
olle |
781 |
|
2933 |
14 Nov 14 |
olle |
// Ask the user for confirmation and then restart the wizard |
2933 |
14 Nov 14 |
olle |
wizard.cancelWizard = function() |
2933 |
14 Nov 14 |
olle |
784 |
{ |
2933 |
14 Nov 14 |
olle |
forceConfirm = true; |
2933 |
14 Nov 14 |
olle |
wizard.restartWizard(); |
2933 |
14 Nov 14 |
olle |
787 |
} |
2933 |
14 Nov 14 |
olle |
788 |
|
2933 |
14 Nov 14 |
olle |
// Restart the wizard without asking the user for confirmation |
2933 |
14 Nov 14 |
olle |
wizard.restartWizard = function() |
2933 |
14 Nov 14 |
olle |
791 |
{ |
2933 |
14 Nov 14 |
olle |
var url = location.href; |
2933 |
14 Nov 14 |
olle |
if (url.indexOf('&restart=1') == -1) url += '&restart=1'; |
2933 |
14 Nov 14 |
olle |
location.href = url; |
2933 |
14 Nov 14 |
olle |
795 |
} |
2933 |
14 Nov 14 |
olle |
796 |
|
2933 |
14 Nov 14 |
olle |
wizard.goPrint = function() |
2933 |
14 Nov 14 |
olle |
798 |
{ |
2933 |
14 Nov 14 |
olle |
window.print(); |
2933 |
14 Nov 14 |
olle |
800 |
} |
2933 |
14 Nov 14 |
olle |
801 |
|
2933 |
14 Nov 14 |
olle |
wizard.setCurrentStep = function(stepNo) |
2933 |
14 Nov 14 |
olle |
803 |
{ |
2933 |
14 Nov 14 |
olle |
currentStep = stepNo; |
2933 |
14 Nov 14 |
olle |
internal.enableStep(Doc.element('step-'+currentStep)); |
2933 |
14 Nov 14 |
olle |
806 |
} |
2933 |
14 Nov 14 |
olle |
807 |
|
2933 |
14 Nov 14 |
olle |
internal.disableStep = function(step) |
2933 |
14 Nov 14 |
olle |
809 |
{ |
2933 |
14 Nov 14 |
olle |
step = Doc.element(step); |
2933 |
14 Nov 14 |
olle |
internal.disableAllFormElements(step); |
2933 |
14 Nov 14 |
olle |
Doc.addClass(step, 'disabled'); |
2933 |
14 Nov 14 |
olle |
Doc.hide('gonext-message'); |
2933 |
14 Nov 14 |
olle |
var stepNo = step.getElementsByClassName('step-no')[0]; |
2933 |
14 Nov 14 |
olle |
Events.addEventHandler(stepNo, 'click', internal.togglePastStep, {'step-id': step.id}); |
2933 |
14 Nov 14 |
olle |
stepNo.title = 'Show/hide this section'; |
2933 |
14 Nov 14 |
olle |
817 |
} |
2933 |
14 Nov 14 |
olle |
818 |
|
2933 |
14 Nov 14 |
olle |
internal.enableStep = function(step) |
2933 |
14 Nov 14 |
olle |
820 |
{ |
2933 |
14 Nov 14 |
olle |
step = Doc.element(step); |
2933 |
14 Nov 14 |
olle |
Doc.removeClass(step, 'disabled'); |
2933 |
14 Nov 14 |
olle |
Doc.show(step); |
2933 |
14 Nov 14 |
olle |
824 |
} |
2933 |
14 Nov 14 |
olle |
825 |
|
2933 |
14 Nov 14 |
olle |
// Toggle visibility of a past step |
2933 |
14 Nov 14 |
olle |
// The step is hidden if the 'auto-hide' class is present |
2933 |
14 Nov 14 |
olle |
internal.togglePastStep = function(event) |
2933 |
14 Nov 14 |
olle |
829 |
{ |
2933 |
14 Nov 14 |
olle |
var step = Data.get(event.currentTarget, 'step-id'); |
2933 |
14 Nov 14 |
olle |
Doc.addOrRemoveClass(step, 'auto-hide'); |
2933 |
14 Nov 14 |
olle |
832 |
} |
2933 |
14 Nov 14 |
olle |
833 |
|
2933 |
14 Nov 14 |
olle |
wizard.syncJsonRequest = function(url, method, postdata) |
2933 |
14 Nov 14 |
olle |
835 |
{ |
2933 |
14 Nov 14 |
olle |
if (debug) |
2933 |
14 Nov 14 |
olle |
837 |
{ |
2933 |
14 Nov 14 |
olle |
App.debug((method || 'GET') + ': ' + url); |
2933 |
14 Nov 14 |
olle |
if (postdata) App.debug(postdata); |
2933 |
14 Nov 14 |
olle |
840 |
} |
2933 |
14 Nov 14 |
olle |
var request = Ajax.getXmlHttpRequest(); |
2933 |
14 Nov 14 |
olle |
request.open(method || 'GET', url, false); |
2933 |
14 Nov 14 |
olle |
if (postdata) |
2933 |
14 Nov 14 |
olle |
844 |
{ |
2933 |
14 Nov 14 |
olle |
request.setRequestHeader("Content-Type", "application/json"); |
2933 |
14 Nov 14 |
olle |
846 |
} |
2933 |
14 Nov 14 |
olle |
request.send(postdata || null); |
2933 |
14 Nov 14 |
olle |
848 |
|
2933 |
14 Nov 14 |
olle |
if (debug) App.debug(request.responseText); |
2933 |
14 Nov 14 |
olle |
if (!hasFatalError) Wizard.hideWizardStatus(); |
2933 |
14 Nov 14 |
olle |
851 |
|
2933 |
14 Nov 14 |
olle |
var response = null; |
2933 |
14 Nov 14 |
olle |
var errorMsg = null; |
2933 |
14 Nov 14 |
olle |
try |
2933 |
14 Nov 14 |
olle |
855 |
{ |
2933 |
14 Nov 14 |
olle |
response = JSON.parse(request.responseText); |
2933 |
14 Nov 14 |
olle |
if (response.status != 'ok') |
2933 |
14 Nov 14 |
olle |
858 |
{ |
2933 |
14 Nov 14 |
olle |
errorMsg = response.message; |
2933 |
14 Nov 14 |
olle |
860 |
} |
2933 |
14 Nov 14 |
olle |
861 |
} |
2933 |
14 Nov 14 |
olle |
catch (err) |
2933 |
14 Nov 14 |
olle |
863 |
{ |
2933 |
14 Nov 14 |
olle |
errorMsg = err.toString ? err.toString() : err; |
2933 |
14 Nov 14 |
olle |
865 |
} |
2933 |
14 Nov 14 |
olle |
866 |
|
2933 |
14 Nov 14 |
olle |
if (errorMsg) |
2933 |
14 Nov 14 |
olle |
868 |
{ |
2933 |
14 Nov 14 |
olle |
Wizard.setFatalError(errorMsg); |
2933 |
14 Nov 14 |
olle |
return null; |
2933 |
14 Nov 14 |
olle |
871 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
873 |
{ |
2933 |
14 Nov 14 |
olle |
return response; |
2933 |
14 Nov 14 |
olle |
875 |
} |
2933 |
14 Nov 14 |
olle |
876 |
} |
2933 |
14 Nov 14 |
olle |
877 |
|
2933 |
14 Nov 14 |
olle |
878 |
/** |
2933 |
14 Nov 14 |
olle |
Submit an ansynchronous request for JSON data. 'GET' method |
2933 |
14 Nov 14 |
olle |
is used if 'method' parameter is not set. |
2933 |
14 Nov 14 |
olle |
The 'callback' should be a method accepting a single |
2933 |
14 Nov 14 |
olle |
JSON parameter object. If the 'status' of the response |
2933 |
14 Nov 14 |
olle |
is not 'ok' this method will call setFatalError and |
2933 |
14 Nov 14 |
olle |
without calling the callback method. |
2933 |
14 Nov 14 |
olle |
885 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.asyncJsonRequest = function(url, callback, method, postdata) |
2933 |
14 Nov 14 |
olle |
887 |
{ |
2933 |
14 Nov 14 |
olle |
if (debug) |
2933 |
14 Nov 14 |
olle |
889 |
{ |
2933 |
14 Nov 14 |
olle |
App.debug((method || 'GET') + ': ' + url); |
2933 |
14 Nov 14 |
olle |
if (postdata) App.debug(postdata); |
2933 |
14 Nov 14 |
olle |
892 |
} |
2933 |
14 Nov 14 |
olle |
var request = Ajax.getXmlHttpRequest(); |
2933 |
14 Nov 14 |
olle |
request.jsonCallback = callback; |
2933 |
14 Nov 14 |
olle |
request.open(method || 'GET', url, true); |
2933 |
14 Nov 14 |
olle |
if (postdata) |
2933 |
14 Nov 14 |
olle |
897 |
{ |
2933 |
14 Nov 14 |
olle |
request.setRequestHeader("Content-Type", "application/json"); |
2933 |
14 Nov 14 |
olle |
899 |
} |
2933 |
14 Nov 14 |
olle |
Ajax.setReadyStateHandler(request, internal.asyncCallbackWrapper, internal.asyncCallbackWrapper); |
2933 |
14 Nov 14 |
olle |
numLiveAsyncRequests++; |
2933 |
14 Nov 14 |
olle |
request.send(postdata || null); |
2933 |
14 Nov 14 |
olle |
903 |
} |
2933 |
14 Nov 14 |
olle |
904 |
|
2933 |
14 Nov 14 |
olle |
905 |
/** |
2933 |
14 Nov 14 |
olle |
Callback wrapper for ansynchronous requests. |
2933 |
14 Nov 14 |
olle |
907 |
*/ |
2933 |
14 Nov 14 |
olle |
internal.asyncCallbackWrapper = function(request) |
2933 |
14 Nov 14 |
olle |
909 |
{ |
2933 |
14 Nov 14 |
olle |
numLiveAsyncRequests--; |
2933 |
14 Nov 14 |
olle |
if (debug) App.debug(request.responseText); |
2933 |
14 Nov 14 |
olle |
if (!hasFatalError) Wizard.hideWizardStatus(); |
2933 |
14 Nov 14 |
olle |
913 |
|
2933 |
14 Nov 14 |
olle |
var response = null; |
2933 |
14 Nov 14 |
olle |
var messages = null; |
2933 |
14 Nov 14 |
olle |
try |
2933 |
14 Nov 14 |
olle |
917 |
{ |
2933 |
14 Nov 14 |
olle |
if (request.status != 200) |
2933 |
14 Nov 14 |
olle |
919 |
{ |
2933 |
14 Nov 14 |
olle |
throw new Error(request.responseText); |
2933 |
14 Nov 14 |
olle |
921 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
923 |
{ |
2933 |
14 Nov 14 |
olle |
if (request.getResponseHeader('Content-Type').indexOf('json') != -1) |
2933 |
14 Nov 14 |
olle |
925 |
{ |
2933 |
14 Nov 14 |
olle |
response = JSON.parse(request.responseText); |
2933 |
14 Nov 14 |
olle |
messages = response.messages; |
2933 |
14 Nov 14 |
olle |
if (response.status != 'ok') |
2933 |
14 Nov 14 |
olle |
929 |
{ |
2933 |
14 Nov 14 |
olle |
throw new Error(response.message || response.stacktrace); |
2933 |
14 Nov 14 |
olle |
931 |
} |
2933 |
14 Nov 14 |
olle |
932 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
934 |
{ |
2933 |
14 Nov 14 |
olle |
response = request.responseText; |
2933 |
14 Nov 14 |
olle |
936 |
} |
2933 |
14 Nov 14 |
olle |
if (request.jsonCallback && request.jsonCallback.call) |
2933 |
14 Nov 14 |
olle |
938 |
{ |
2933 |
14 Nov 14 |
olle |
request.jsonCallback.call(null, response); |
2933 |
14 Nov 14 |
olle |
940 |
} |
2933 |
14 Nov 14 |
olle |
941 |
} |
2933 |
14 Nov 14 |
olle |
942 |
} |
2933 |
14 Nov 14 |
olle |
catch (err) |
2933 |
14 Nov 14 |
olle |
944 |
{ |
2933 |
14 Nov 14 |
olle |
Wizard.setFatalError(err, messages); |
2933 |
14 Nov 14 |
olle |
946 |
} |
2933 |
14 Nov 14 |
olle |
947 |
} |
2933 |
14 Nov 14 |
olle |
948 |
|
2933 |
14 Nov 14 |
olle |
949 |
|
2933 |
14 Nov 14 |
olle |
950 |
/** |
2933 |
14 Nov 14 |
olle |
A fatal error has occurred and the wizard will not be able to continue. |
2933 |
14 Nov 14 |
olle |
This method will display the error message, disable all form input fields |
2933 |
14 Nov 14 |
olle |
and buttons (except the 'Restart' button). |
2933 |
14 Nov 14 |
olle |
954 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.setFatalError = function(err, messages) |
2933 |
14 Nov 14 |
olle |
956 |
{ |
2933 |
14 Nov 14 |
olle |
hasFatalError = true; |
2933 |
14 Nov 14 |
olle |
var msg = err; |
2933 |
14 Nov 14 |
olle |
if (err.toString) |
2933 |
14 Nov 14 |
olle |
960 |
{ |
2933 |
14 Nov 14 |
olle |
App.debug(err.toString()); |
2933 |
14 Nov 14 |
olle |
msg = Strings.encodeTags(err.toString()); |
2933 |
14 Nov 14 |
olle |
if (err.stack && !messages) |
2933 |
14 Nov 14 |
olle |
964 |
{ |
2933 |
14 Nov 14 |
olle |
App.debug(err.stack); |
2933 |
14 Nov 14 |
olle |
msg += '<br><pre>'+Strings.encodeTags(err.stack)+'</pre>'; |
2933 |
14 Nov 14 |
olle |
967 |
} |
2933 |
14 Nov 14 |
olle |
968 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
970 |
{ |
2933 |
14 Nov 14 |
olle |
App.debug(msg); |
2933 |
14 Nov 14 |
olle |
972 |
} |
2933 |
14 Nov 14 |
olle |
973 |
|
2933 |
14 Nov 14 |
olle |
if (messages) |
2933 |
14 Nov 14 |
olle |
975 |
{ |
2933 |
14 Nov 14 |
olle |
msg = '<div class="messagecontainer error">'+msg+'</div>'+internal.generateMessageList(messages).html; |
2933 |
14 Nov 14 |
olle |
wizard.setWizardStatus('success', msg); |
2933 |
14 Nov 14 |
olle |
978 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
980 |
{ |
2933 |
14 Nov 14 |
olle |
wizard.setWizardStatus('messagecontainer error', msg || 'Unexpected failure!'); |
2933 |
14 Nov 14 |
olle |
982 |
} |
2933 |
14 Nov 14 |
olle |
983 |
|
2933 |
14 Nov 14 |
olle |
Doc.addClass('wizard', 'disabled'); |
2933 |
14 Nov 14 |
olle |
internal.disableAllFormElements('wizard', true); |
2933 |
14 Nov 14 |
olle |
Doc.show('gorestart'); |
2933 |
14 Nov 14 |
olle |
987 |
} |
2933 |
14 Nov 14 |
olle |
988 |
|
2933 |
14 Nov 14 |
olle |
989 |
|
2933 |
14 Nov 14 |
olle |
990 |
/** |
2933 |
14 Nov 14 |
olle |
Display a 'loading' global wizard-status message. |
2933 |
14 Nov 14 |
olle |
992 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.showLoadingAnimation = function(msg) |
2933 |
14 Nov 14 |
olle |
994 |
{ |
2933 |
14 Nov 14 |
olle |
wizard.setWizardStatus('loading', msg || 'Working, please wait...'); |
2933 |
14 Nov 14 |
olle |
996 |
} |
2933 |
14 Nov 14 |
olle |
997 |
|
2933 |
14 Nov 14 |
olle |
wizard.showStatusMessage = function(msg) |
2933 |
14 Nov 14 |
olle |
999 |
{ |
2933 |
14 Nov 14 |
olle |
App.debug(msg); |
2933 |
14 Nov 14 |
olle |
wizard.setWizardStatus('messagecontainer note', msg); |
2933 |
14 Nov 14 |
olle |
1002 |
} |
2933 |
14 Nov 14 |
olle |
1003 |
|
2933 |
14 Nov 14 |
olle |
wizard.showGoNextConfirmation = function(verify, msg) |
2933 |
14 Nov 14 |
olle |
1005 |
{ |
2933 |
14 Nov 14 |
olle |
var check = ''; |
2933 |
14 Nov 14 |
olle |
if (verify) |
2933 |
14 Nov 14 |
olle |
1008 |
{ |
2933 |
14 Nov 14 |
olle |
check = '<input type="checkbox" name="verifyGoNext" id="verifyGoNext">'; |
2933 |
14 Nov 14 |
olle |
Doc.addClass('gonext', 'disabled'); |
2933 |
14 Nov 14 |
olle |
Doc.addClass('goregister', 'disabled'); |
2933 |
14 Nov 14 |
olle |
1012 |
} |
2933 |
14 Nov 14 |
olle |
1013 |
|
2933 |
14 Nov 14 |
olle |
var gonext = Doc.element('gonext-message'); |
2933 |
14 Nov 14 |
olle |
gonext.innerHTML = check + msg; |
2933 |
14 Nov 14 |
olle |
Doc.show(gonext); |
2933 |
14 Nov 14 |
olle |
1017 |
|
2933 |
14 Nov 14 |
olle |
if (verify) |
2933 |
14 Nov 14 |
olle |
1019 |
{ |
2933 |
14 Nov 14 |
olle |
Events.addEventHandler('verifyGoNext', 'click', internal.verifyInternalOnClick); |
2933 |
14 Nov 14 |
olle |
1021 |
} |
2933 |
14 Nov 14 |
olle |
1022 |
} |
2933 |
14 Nov 14 |
olle |
1023 |
|
2933 |
14 Nov 14 |
olle |
wizard.hideGoNextConfirmation = function() |
2933 |
14 Nov 14 |
olle |
1025 |
{ |
2933 |
14 Nov 14 |
olle |
var gonext = Doc.element('gonext-message'); |
2933 |
14 Nov 14 |
olle |
gonext.innerHTML = ''; |
2933 |
14 Nov 14 |
olle |
Doc.hide(gonext); |
2933 |
14 Nov 14 |
olle |
Doc.removeClass('gonext', 'disabled'); |
2933 |
14 Nov 14 |
olle |
Doc.removeClass('goregister', 'disabled'); |
2933 |
14 Nov 14 |
olle |
1031 |
} |
2933 |
14 Nov 14 |
olle |
1032 |
|
2933 |
14 Nov 14 |
olle |
internal.verifyInternalOnClick = function(event) |
2933 |
14 Nov 14 |
olle |
1034 |
{ |
2933 |
14 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2933 |
14 Nov 14 |
olle |
var checked = event.currentTarget.checked; |
2933 |
14 Nov 14 |
olle |
Doc.addOrRemoveClass('goregister', 'disabled', !checked); |
2933 |
14 Nov 14 |
olle |
Doc.addOrRemoveClass('gonext', 'disabled', !checked); |
2933 |
14 Nov 14 |
olle |
1039 |
} |
2933 |
14 Nov 14 |
olle |
1040 |
|
2933 |
14 Nov 14 |
olle |
1041 |
/** |
2933 |
14 Nov 14 |
olle |
Show final registration messages in a list. |
2933 |
14 Nov 14 |
olle |
1043 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.showFinalMessage = function(messages) |
2933 |
14 Nov 14 |
olle |
1045 |
{ |
2933 |
14 Nov 14 |
olle |
var msg = internal.generateMessageList(messages); |
2933 |
14 Nov 14 |
olle |
wizard.setWizardStatus('success', msg.html); |
2933 |
14 Nov 14 |
olle |
return { 'errors': msg.errors, 'warnings': msg.warnings }; |
2933 |
14 Nov 14 |
olle |
1049 |
} |
2933 |
14 Nov 14 |
olle |
1050 |
|
2933 |
14 Nov 14 |
olle |
1051 |
|
2933 |
14 Nov 14 |
olle |
1052 |
/* |
2933 |
14 Nov 14 |
olle |
Call this method once to start a repeating timer that will submit |
2933 |
14 Nov 14 |
olle |
an Ajax request at regular intervals in order to keep the current login |
2933 |
14 Nov 14 |
olle |
session alive. Once started there is no way to stop the timer except |
2933 |
14 Nov 14 |
olle |
navigating away from the page. |
2933 |
14 Nov 14 |
olle |
@param meludiRoot Optional relative path to the root of the MeLuDi installation (for pages in a subdirectory) |
2933 |
14 Nov 14 |
olle |
1058 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.keepSessionAlive = function() |
2933 |
14 Nov 14 |
olle |
1060 |
{ |
2933 |
14 Nov 14 |
olle |
if (debug) |
2933 |
14 Nov 14 |
olle |
1062 |
{ |
2933 |
14 Nov 14 |
olle |
// Create a 'simulate timeout' checkbox |
2933 |
14 Nov 14 |
olle |
var div = document.createElement('div'); |
2933 |
14 Nov 14 |
olle |
div.id = 'simulateTimeoutDiv'; |
2933 |
14 Nov 14 |
olle |
div.style.textAlign = 'center'; |
2933 |
14 Nov 14 |
olle |
div.innerHTML = '<label><input type="checkbox" id="simulateTimeout">Simulate session timeout</label>'; |
2933 |
14 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2933 |
14 Nov 14 |
olle |
frm.appendChild(div); |
2933 |
14 Nov 14 |
olle |
1070 |
} |
2933 |
14 Nov 14 |
olle |
1071 |
|
2933 |
14 Nov 14 |
olle |
internal.scheduleKeepAlive(); |
2933 |
14 Nov 14 |
olle |
1073 |
} |
2933 |
14 Nov 14 |
olle |
1074 |
|
2933 |
14 Nov 14 |
olle |
// Schedule a keep-alive request |
2933 |
14 Nov 14 |
olle |
internal.scheduleKeepAlive = function() |
2933 |
14 Nov 14 |
olle |
1077 |
{ |
2933 |
14 Nov 14 |
olle |
setTimeout(internal.sendKeepAlive, debug ? 5000 : 30000); |
2933 |
14 Nov 14 |
olle |
1079 |
} |
2933 |
14 Nov 14 |
olle |
1080 |
|
2933 |
14 Nov 14 |
olle |
// Send a keep-alive request |
2933 |
14 Nov 14 |
olle |
internal.sendKeepAlive = function() |
2933 |
14 Nov 14 |
olle |
1083 |
{ |
2933 |
14 Nov 14 |
olle |
if (hasSentRegistration || hasFatalError) |
2933 |
14 Nov 14 |
olle |
1085 |
{ |
2933 |
14 Nov 14 |
olle |
if (debug) Doc.hide('simulateTimeoutDiv'); |
2933 |
14 Nov 14 |
olle |
return; |
2933 |
14 Nov 14 |
olle |
1088 |
} |
2933 |
14 Nov 14 |
olle |
var simulateTimeout = false; |
2933 |
14 Nov 14 |
olle |
if (debug) |
2933 |
14 Nov 14 |
olle |
1091 |
{ |
2933 |
14 Nov 14 |
olle |
var msg = 'Checking if session '+App.getSessionId() + ' is alive'; |
2933 |
14 Nov 14 |
olle |
var timeoutDiv = Doc.element('simulateTimeout'); |
2933 |
14 Nov 14 |
olle |
if (timeoutDiv && timeoutDiv.checked) |
2933 |
14 Nov 14 |
olle |
1095 |
{ |
2933 |
14 Nov 14 |
olle |
simulateTimeout = true; |
2933 |
14 Nov 14 |
olle |
timeoutDiv.checked = false; |
2933 |
14 Nov 14 |
olle |
msg += ' (simulating a session timeout)' |
2933 |
14 Nov 14 |
olle |
1099 |
} |
2933 |
14 Nov 14 |
olle |
App.debug(msg); |
2933 |
14 Nov 14 |
olle |
1101 |
} |
2933 |
14 Nov 14 |
olle |
1102 |
|
2933 |
14 Nov 14 |
olle |
var url = '../Session.servlet?ID='+App.getSessionId(); |
2933 |
14 Nov 14 |
olle |
url += '&cmd=CheckSession'; |
2933 |
14 Nov 14 |
olle |
if (simulateTimeout) url += '&simulateTimeout=1'; |
2933 |
14 Nov 14 |
olle |
1106 |
|
2933 |
14 Nov 14 |
olle |
wizard.asyncJsonRequest(url, internal.onKeepAliveResponse); |
2933 |
14 Nov 14 |
olle |
1108 |
} |
2933 |
14 Nov 14 |
olle |
1109 |
|
2933 |
14 Nov 14 |
olle |
1110 |
|
2933 |
14 Nov 14 |
olle |
internal.onKeepAliveResponse = function(response) |
2933 |
14 Nov 14 |
olle |
1112 |
{ |
2933 |
14 Nov 14 |
olle |
if (!response.session) |
2933 |
14 Nov 14 |
olle |
1114 |
{ |
2933 |
14 Nov 14 |
olle |
// Hide navigation buttons |
2933 |
14 Nov 14 |
olle |
Doc.hide('navigation'); |
2933 |
14 Nov 14 |
olle |
Doc.addClass('wizard', 'disabled'); |
2933 |
14 Nov 14 |
olle |
1118 |
|
2933 |
14 Nov 14 |
olle |
// Show message |
2933 |
14 Nov 14 |
olle |
var div = Doc.element('timeoutMessage'); |
2933 |
14 Nov 14 |
olle |
if (!div) |
2933 |
14 Nov 14 |
olle |
1122 |
{ |
2933 |
14 Nov 14 |
olle |
div = document.createElement('div'); |
2933 |
14 Nov 14 |
olle |
div.id = 'timeoutMessage'; |
2933 |
14 Nov 14 |
olle |
div.className = 'messagecontainer error link'; |
2933 |
14 Nov 14 |
olle |
div.innerHTML = 'You have been logged out due to inactivity or unstable internet connection. Click HERE to login again!'; |
2933 |
14 Nov 14 |
olle |
div.addEventListener('click', internal.openLoginWindow, false); |
2933 |
14 Nov 14 |
olle |
div.addEventListener('logged-in', internal.loggedInAgain, false); |
2933 |
14 Nov 14 |
olle |
var frm = document.forms['meludi']; |
2933 |
14 Nov 14 |
olle |
frm.appendChild(div); |
2933 |
14 Nov 14 |
olle |
1131 |
} |
2933 |
14 Nov 14 |
olle |
Doc.show(div); |
2933 |
14 Nov 14 |
olle |
1133 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
1135 |
{ |
2933 |
14 Nov 14 |
olle |
internal.scheduleKeepAlive(); |
2933 |
14 Nov 14 |
olle |
1137 |
} |
2933 |
14 Nov 14 |
olle |
1138 |
} |
2933 |
14 Nov 14 |
olle |
1139 |
|
2933 |
14 Nov 14 |
olle |
// Open popup window for logging in again |
2933 |
14 Nov 14 |
olle |
internal.openLoginWindow = function() |
2933 |
14 Nov 14 |
olle |
1142 |
{ |
2933 |
14 Nov 14 |
olle |
if (debug) App.debug('Need to login again!'); |
2933 |
14 Nov 14 |
olle |
var url = '../keep_session_alive.jsp?ID='+App.getSessionId(); |
2933 |
14 Nov 14 |
olle |
Dialogs.openPopup(url, 'KeepSessionAlive', 800, 600); |
2933 |
14 Nov 14 |
olle |
1146 |
} |
2933 |
14 Nov 14 |
olle |
1147 |
|
2933 |
14 Nov 14 |
olle |
// Callback when the user has been successfully logged in |
2933 |
14 Nov 14 |
olle |
internal.loggedInAgain = function() |
2933 |
14 Nov 14 |
olle |
1150 |
{ |
2933 |
14 Nov 14 |
olle |
if (debug) App.debug('Logged in again!'); |
2933 |
14 Nov 14 |
olle |
Doc.removeClass('wizard', 'disabled'); |
2933 |
14 Nov 14 |
olle |
Doc.hide('timeoutMessage'); |
2933 |
14 Nov 14 |
olle |
Doc.show('navigation'); |
2933 |
14 Nov 14 |
olle |
internal.scheduleKeepAlive(); |
2933 |
14 Nov 14 |
olle |
1156 |
} |
2933 |
14 Nov 14 |
olle |
1157 |
|
2933 |
14 Nov 14 |
olle |
internal.generateMessageList = function(messages) |
2933 |
14 Nov 14 |
olle |
1159 |
{ |
2933 |
14 Nov 14 |
olle |
var msg = '<ul>'; |
2933 |
14 Nov 14 |
olle |
var numWarnings = 0; |
2933 |
14 Nov 14 |
olle |
var numErrors = 0; |
2933 |
14 Nov 14 |
olle |
for (var i = 0; i < messages.length; i++) |
2933 |
14 Nov 14 |
olle |
1164 |
{ |
2933 |
14 Nov 14 |
olle |
var msgLine = messages[i]; |
2933 |
14 Nov 14 |
olle |
if (msgLine.indexOf('[Warning]') >= 0) |
2933 |
14 Nov 14 |
olle |
1167 |
{ |
2933 |
14 Nov 14 |
olle |
msg += '<li class="warning">' + Strings.encodeTags(msgLine.replace('[Warning]', '')); |
2933 |
14 Nov 14 |
olle |
numWarnings++; |
2933 |
14 Nov 14 |
olle |
1170 |
} |
2933 |
14 Nov 14 |
olle |
else if (msgLine.indexOf('[Error]') >= 0) |
2933 |
14 Nov 14 |
olle |
1172 |
{ |
2933 |
14 Nov 14 |
olle |
msg += '<li class="error">' + Strings.encodeTags(msgLine.replace('[Error]', '')); |
2933 |
14 Nov 14 |
olle |
numErrors++; |
2933 |
14 Nov 14 |
olle |
1175 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
1177 |
{ |
2933 |
14 Nov 14 |
olle |
msg += '<li class="ok">' + Strings.encodeTags(msgLine); |
2933 |
14 Nov 14 |
olle |
1179 |
} |
2933 |
14 Nov 14 |
olle |
1180 |
} |
2933 |
14 Nov 14 |
olle |
msg += '</ul>'; |
2933 |
14 Nov 14 |
olle |
return { 'html': msg, 'errors': numErrors, 'warnings': numWarnings }; |
2933 |
14 Nov 14 |
olle |
1183 |
} |
2933 |
14 Nov 14 |
olle |
1184 |
|
2933 |
14 Nov 14 |
olle |
1185 |
/** |
2933 |
14 Nov 14 |
olle |
Hide the current global wizard-status message. |
2933 |
14 Nov 14 |
olle |
1187 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.hideWizardStatus = function() |
2933 |
14 Nov 14 |
olle |
1189 |
{ |
2933 |
14 Nov 14 |
olle |
Doc.hide('wizard-status'); |
2933 |
14 Nov 14 |
olle |
1191 |
} |
2933 |
14 Nov 14 |
olle |
1192 |
|
2933 |
14 Nov 14 |
olle |
1193 |
/** |
2933 |
14 Nov 14 |
olle |
Initialize the wizard: |
2933 |
14 Nov 14 |
olle |
1195 |
|
2933 |
14 Nov 14 |
olle |
* Check that a project is active |
2933 |
14 Nov 14 |
olle |
1197 |
*/ |
2933 |
14 Nov 14 |
olle |
internal.initWizard = function() |
2933 |
14 Nov 14 |
olle |
1199 |
{ |
2933 |
14 Nov 14 |
olle |
// Check if project is enabled |
2933 |
14 Nov 14 |
olle |
var wiz = Doc.element('wizard'); |
2933 |
14 Nov 14 |
olle |
if (wiz) |
2933 |
14 Nov 14 |
olle |
1203 |
{ |
2933 |
14 Nov 14 |
olle |
if (!App.getActiveProjectId()) |
2933 |
14 Nov 14 |
olle |
1205 |
{ |
2933 |
14 Nov 14 |
olle |
wizard.setFatalError('No project has been selected.'); |
2933 |
14 Nov 14 |
olle |
1207 |
} |
2933 |
14 Nov 14 |
olle |
window.addEventListener('beforeunload', internal.confirmLeaveWizard); |
2933 |
14 Nov 14 |
olle |
1209 |
} |
2933 |
14 Nov 14 |
olle |
1210 |
|
2933 |
14 Nov 14 |
olle |
var path = document.getElementsByClassName('pathelement'); |
2933 |
14 Nov 14 |
olle |
if (path && path.length) |
2933 |
14 Nov 14 |
olle |
1213 |
{ |
2933 |
14 Nov 14 |
olle |
// Set program title |
4159 |
17 Oct 16 |
olle |
var simpleElement = false; |
2933 |
14 Nov 14 |
olle |
if (path[0].firstChild) |
2933 |
14 Nov 14 |
olle |
1217 |
{ |
2933 |
14 Nov 14 |
olle |
// Set program title for link (anchor tag) |
2933 |
14 Nov 14 |
olle |
path[0].firstChild.innerHTML = Meludi.TITLE; |
2933 |
14 Nov 14 |
olle |
1220 |
} |
2933 |
14 Nov 14 |
olle |
else |
2933 |
14 Nov 14 |
olle |
1222 |
{ |
2933 |
14 Nov 14 |
olle |
// Set program title for simple element (used for index.jsp page title) |
2933 |
14 Nov 14 |
olle |
path[0].innerHTML += '<span id="meludi-title">'+Meludi.TITLE+'</span>'; |
4159 |
17 Oct 16 |
olle |
simpleElement = true; |
2933 |
14 Nov 14 |
olle |
1226 |
} |
4159 |
17 Oct 16 |
olle |
// Set project name |
4159 |
17 Oct 16 |
olle |
var projectName = internal.getActiveProjectName(simpleElement); |
4159 |
17 Oct 16 |
olle |
path[path.length-1].innerHTML += '<span id="meludi-project">'+projectName+'</span>'; |
2933 |
14 Nov 14 |
olle |
// Set program title plus version |
2933 |
14 Nov 14 |
olle |
path[path.length-1].innerHTML += '<span id="meludi-version">['+Meludi.TITLE+' '+Meludi.VERSION+']</span>'; |
2933 |
14 Nov 14 |
olle |
1232 |
} |
2933 |
14 Nov 14 |
olle |
1233 |
|
2933 |
14 Nov 14 |
olle |
var programTitle = document.getElementById('programtitle'); |
2933 |
14 Nov 14 |
olle |
if (programTitle) |
2933 |
14 Nov 14 |
olle |
1236 |
{ |
2933 |
14 Nov 14 |
olle |
programTitle.innerHTML = Meludi.TITLE; |
2933 |
14 Nov 14 |
olle |
1238 |
} |
2933 |
14 Nov 14 |
olle |
1239 |
} |
4159 |
17 Oct 16 |
olle |
1240 |
|
4159 |
17 Oct 16 |
olle |
1241 |
/** |
4159 |
17 Oct 16 |
olle |
Get name of active project. |
4159 |
17 Oct 16 |
olle |
1243 |
*/ |
4159 |
17 Oct 16 |
olle |
internal.getActiveProjectName = function(simpleElement) |
4159 |
17 Oct 16 |
olle |
1245 |
{ |
4159 |
17 Oct 16 |
olle |
// Url for link (anchor tag) |
4159 |
17 Oct 16 |
olle |
var url = '../Session.servlet?ID='+App.getSessionId(); |
4159 |
17 Oct 16 |
olle |
if (simpleElement) |
4159 |
17 Oct 16 |
olle |
1249 |
{ |
4159 |
17 Oct 16 |
olle |
// Url for simple element (used for index.jsp page title) |
4159 |
17 Oct 16 |
olle |
url = './Session.servlet?ID='+App.getSessionId(); |
4159 |
17 Oct 16 |
olle |
1252 |
} |
4159 |
17 Oct 16 |
olle |
url += '&cmd=GetActiveProjectName'; |
4159 |
17 Oct 16 |
olle |
var response = Wizard.syncJsonRequest(url); |
4159 |
17 Oct 16 |
olle |
return response ? response.projectname : null; |
4159 |
17 Oct 16 |
olle |
1256 |
} |
2933 |
14 Nov 14 |
olle |
1257 |
|
2933 |
14 Nov 14 |
olle |
internal.confirmLeaveWizard = function(event) |
2933 |
14 Nov 14 |
olle |
1259 |
{ |
2933 |
14 Nov 14 |
olle |
if (hasFatalError) return; |
2933 |
14 Nov 14 |
olle |
if (!forceConfirm) |
2933 |
14 Nov 14 |
olle |
1262 |
{ |
2933 |
14 Nov 14 |
olle |
if (currentStep == 1 && noConfirmOnFirstStep) return; |
2933 |
14 Nov 14 |
olle |
if (hasSentRegistration && numLiveAsyncRequests == 0) return; |
2933 |
14 Nov 14 |
olle |
1265 |
} |
2933 |
14 Nov 14 |
olle |
forceConfirm = false; |
2933 |
14 Nov 14 |
olle |
event.preventDefault(); |
2933 |
14 Nov 14 |
olle |
1268 |
} |
2933 |
14 Nov 14 |
olle |
1269 |
|
2933 |
14 Nov 14 |
olle |
// Initialize some event handlers |
2933 |
14 Nov 14 |
olle |
internal.initElements = function(element, autoInit) |
2933 |
14 Nov 14 |
olle |
1272 |
{ |
2933 |
14 Nov 14 |
olle |
if (autoInit == 'focus-on-enter') |
2933 |
14 Nov 14 |
olle |
1274 |
{ |
2933 |
14 Nov 14 |
olle |
Events.addEventHandler(element, 'keypress', wizard.focusOnEnter); |
2933 |
14 Nov 14 |
olle |
1276 |
} |
2933 |
14 Nov 14 |
olle |
1277 |
} |
2933 |
14 Nov 14 |
olle |
1278 |
|
2933 |
14 Nov 14 |
olle |
1279 |
/** |
2933 |
14 Nov 14 |
olle |
Display a global wizard-status message. This may for example be |
2933 |
14 Nov 14 |
olle |
an error message, a work-in-progress indicator, etc. |
2933 |
14 Nov 14 |
olle |
1282 |
*/ |
2933 |
14 Nov 14 |
olle |
wizard.setWizardStatus = function(className, msg) |
2933 |
14 Nov 14 |
olle |
1284 |
{ |
2933 |
14 Nov 14 |
olle |
var status = Doc.element('wizard-status'); |
2933 |
14 Nov 14 |
olle |
status.className = className; |
2933 |
14 Nov 14 |
olle |
status.innerHTML = msg; |
2933 |
14 Nov 14 |
olle |
Doc.show(status); |
2933 |
14 Nov 14 |
olle |
1289 |
} |
2933 |
14 Nov 14 |
olle |
1290 |
|
2933 |
14 Nov 14 |
olle |
// Disable all form elements inside the given container |
2933 |
14 Nov 14 |
olle |
internal.disableAllFormElements = function(container, hideButtons) |
2933 |
14 Nov 14 |
olle |
1293 |
{ |
2933 |
14 Nov 14 |
olle |
container = Doc.element(container); |
2933 |
14 Nov 14 |
olle |
var input = container.getElementsByTagName('input'); |
2933 |
14 Nov 14 |
olle |
for (var i = 0; i < input.length; i++) |
2933 |
14 Nov 14 |
olle |
1297 |
{ |
2933 |
14 Nov 14 |
olle |
input[i].disabled = true; |
2933 |
14 Nov 14 |
olle |
1299 |
} |
2933 |
14 Nov 14 |
olle |
var select = container.getElementsByTagName('select'); |
2933 |
14 Nov 14 |
olle |
for (var i = 0; i < select.length; i++) |
2933 |
14 Nov 14 |
olle |
1302 |
{ |
2933 |
14 Nov 14 |
olle |
select[i].disabled = true; |
2933 |
14 Nov 14 |
olle |
1304 |
} |
2933 |
14 Nov 14 |
olle |
var text = container.getElementsByTagName('textarea'); |
2933 |
14 Nov 14 |
olle |
for (var i = 0; i < text.length; i++) |
2933 |
14 Nov 14 |
olle |
1307 |
{ |
2933 |
14 Nov 14 |
olle |
text[i].disabled = true; |
2933 |
14 Nov 14 |
olle |
1309 |
} |
2933 |
14 Nov 14 |
olle |
if (hideButtons) |
2933 |
14 Nov 14 |
olle |
1311 |
{ |
2933 |
14 Nov 14 |
olle |
internal.hideButtons(container); |
2933 |
14 Nov 14 |
olle |
1313 |
} |
2933 |
14 Nov 14 |
olle |
1314 |
} |
2933 |
14 Nov 14 |
olle |
1315 |
|
2933 |
14 Nov 14 |
olle |
// Hide all 'basicbuttons':s in the given container |
2933 |
14 Nov 14 |
olle |
internal.hideButtons = function(container) |
2933 |
14 Nov 14 |
olle |
1318 |
{ |
2933 |
14 Nov 14 |
olle |
container = Doc.element(container); |
2933 |
14 Nov 14 |
olle |
var buttons = container.getElementsByClassName('basicbutton'); |
2933 |
14 Nov 14 |
olle |
for (var i = 0; i < buttons.length; i++) |
2933 |
14 Nov 14 |
olle |
1322 |
{ |
2933 |
14 Nov 14 |
olle |
Doc.hide(buttons[i]); |
2933 |
14 Nov 14 |
olle |
1324 |
} |
2933 |
14 Nov 14 |
olle |
1325 |
} |
2933 |
14 Nov 14 |
olle |
1326 |
|
2933 |
14 Nov 14 |
olle |
Doc.addFinalizer(internal.initWizard); |
2933 |
14 Nov 14 |
olle |
Doc.addElementInitializer(internal.initElements); |
2933 |
14 Nov 14 |
olle |
return wizard; |
2933 |
14 Nov 14 |
olle |
1330 |
}(); |
2933 |
14 Nov 14 |
olle |
1331 |
|