3735 |
10 Feb 16 |
olle |
1 |
|
3735 |
10 Feb 16 |
olle |
var LabEnv = function() |
3735 |
10 Feb 16 |
olle |
3 |
{ |
3735 |
10 Feb 16 |
olle |
var labenv = {}; |
3735 |
10 Feb 16 |
olle |
var internal = {}; |
3735 |
10 Feb 16 |
olle |
6 |
|
5572 |
15 Aug 19 |
nicklas |
labenv.VERSION = '1.8-dev'; |
3735 |
10 Feb 16 |
olle |
8 |
|
3735 |
10 Feb 16 |
olle |
9 |
/** |
3735 |
10 Feb 16 |
olle |
Autofill a date-string. |
3735 |
10 Feb 16 |
olle |
The supplemented date-string will have the format yyyyMMdd when it's returned. |
3735 |
10 Feb 16 |
olle |
If the short-date in format MMdd is larger the current date, the year before will be used. |
3735 |
10 Feb 16 |
olle |
13 |
|
3735 |
10 Feb 16 |
olle |
@param shortDate Date in format 'MMdd' or in 'yyMMdd' |
3735 |
10 Feb 16 |
olle |
@param allowSixDigitDates Boolean Flag indicating if 6-digit dates should be auto-filled (default = false). |
3735 |
10 Feb 16 |
olle |
16 |
*/ |
3735 |
10 Feb 16 |
olle |
labenv.autoFillDate = function(shortDate, allowSixDigitDates) |
3735 |
10 Feb 16 |
olle |
18 |
{ |
3735 |
10 Feb 16 |
olle |
shortDate = shortDate.replace("-",""); |
3735 |
10 Feb 16 |
olle |
var fullDate = shortDate; |
3735 |
10 Feb 16 |
olle |
21 |
|
3735 |
10 Feb 16 |
olle |
var currentDate = new Date(); |
3735 |
10 Feb 16 |
olle |
var currentYear = currentDate.getFullYear(); |
3735 |
10 Feb 16 |
olle |
var currentMonth = currentDate.getMonth()+1; |
3735 |
10 Feb 16 |
olle |
25 |
|
3735 |
10 Feb 16 |
olle |
if (shortDate.length == 4 && Dates.isDate(shortDate, 'MMdd')) |
3735 |
10 Feb 16 |
olle |
27 |
{ |
3735 |
10 Feb 16 |
olle |
var month = parseInt(shortDate.substring(0, 2), 10); |
3735 |
10 Feb 16 |
olle |
var day = parseInt(shortDate.substring(2), 10); |
3735 |
10 Feb 16 |
olle |
if ((month > currentMonth) || (month == currentMonth && day > currentDate.getDate())) |
3735 |
10 Feb 16 |
olle |
31 |
{ |
3735 |
10 Feb 16 |
olle |
currentYear--; |
3735 |
10 Feb 16 |
olle |
33 |
} |
3735 |
10 Feb 16 |
olle |
fullDate = currentYear+shortDate; |
3735 |
10 Feb 16 |
olle |
35 |
} |
3735 |
10 Feb 16 |
olle |
else if (allowSixDigitDates && shortDate.length == 6 && Dates.isDate(shortDate, 'yyMMdd')) |
3735 |
10 Feb 16 |
olle |
37 |
{ |
3735 |
10 Feb 16 |
olle |
var year = parseInt(shortDate.substring(0,2), 10); |
3735 |
10 Feb 16 |
olle |
fullDate = ((2000+year) > currentYear ? "19" : "20") + fullDate; |
3735 |
10 Feb 16 |
olle |
40 |
} |
3735 |
10 Feb 16 |
olle |
return fullDate; |
3735 |
10 Feb 16 |
olle |
42 |
} |
3735 |
10 Feb 16 |
olle |
43 |
|
3735 |
10 Feb 16 |
olle |
labenv.autoFillTime = function(shortTime) |
3735 |
10 Feb 16 |
olle |
45 |
{ |
3735 |
10 Feb 16 |
olle |
var fullTimeString = shortTime; |
3735 |
10 Feb 16 |
olle |
if (shortTime.length==3) |
3735 |
10 Feb 16 |
olle |
48 |
{ |
3735 |
10 Feb 16 |
olle |
fullTimeString = "0"+shortTime; |
3735 |
10 Feb 16 |
olle |
50 |
} |
3735 |
10 Feb 16 |
olle |
return fullTimeString; |
3735 |
10 Feb 16 |
olle |
52 |
} |
3735 |
10 Feb 16 |
olle |
53 |
|
3735 |
10 Feb 16 |
olle |
54 |
/** |
3735 |
10 Feb 16 |
olle |
Convert a 2-digit year to a 4-digit year. Assuming |
3735 |
10 Feb 16 |
olle |
that the short year is between 1 and 100 years old. |
3735 |
10 Feb 16 |
olle |
57 |
*/ |
3735 |
10 Feb 16 |
olle |
labenv.fullYear = function(shortYear) |
3735 |
10 Feb 16 |
olle |
59 |
{ |
3735 |
10 Feb 16 |
olle |
var thisYear = new Date().getFullYear(); |
3735 |
10 Feb 16 |
olle |
var fullYear = shortYear + 100*Math.floor((thisYear - shortYear - 1) / 100); |
3735 |
10 Feb 16 |
olle |
return fullYear; |
3735 |
10 Feb 16 |
olle |
63 |
} |
3735 |
10 Feb 16 |
olle |
64 |
|
3735 |
10 Feb 16 |
olle |
labenv.formatNumber = function(number, unit, baseDecimals) |
3735 |
10 Feb 16 |
olle |
66 |
{ |
3735 |
10 Feb 16 |
olle |
if (number == null) return ''; |
3735 |
10 Feb 16 |
olle |
68 |
|
3735 |
10 Feb 16 |
olle |
var numDecimals; |
3735 |
10 Feb 16 |
olle |
if (!baseDecimals) baseDecimals = 3; |
3735 |
10 Feb 16 |
olle |
if (number < 10) |
3735 |
10 Feb 16 |
olle |
72 |
{ |
3735 |
10 Feb 16 |
olle |
numDecimals = baseDecimals; |
3735 |
10 Feb 16 |
olle |
74 |
} |
3735 |
10 Feb 16 |
olle |
else if (number < 100) |
3735 |
10 Feb 16 |
olle |
76 |
{ |
3735 |
10 Feb 16 |
olle |
numDecimals = baseDecimals-1; |
3735 |
10 Feb 16 |
olle |
78 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
80 |
{ |
3735 |
10 Feb 16 |
olle |
numDecimals = baseDecimals-2; |
3735 |
10 Feb 16 |
olle |
82 |
} |
3735 |
10 Feb 16 |
olle |
83 |
|
3735 |
10 Feb 16 |
olle |
var result = number.toFixed(numDecimals); |
3735 |
10 Feb 16 |
olle |
if (unit) result += unit; |
3735 |
10 Feb 16 |
olle |
return result; |
3735 |
10 Feb 16 |
olle |
87 |
} |
3735 |
10 Feb 16 |
olle |
88 |
|
3735 |
10 Feb 16 |
olle |
89 |
/** |
3735 |
10 Feb 16 |
olle |
Reformat a date string in YYYYMMDD or YYYYMMDD HHMM format |
3735 |
10 Feb 16 |
olle |
to YYYY-MM-DD HH:MM |
3735 |
10 Feb 16 |
olle |
92 |
*/ |
3735 |
10 Feb 16 |
olle |
labenv.reformatDate = function(value, defaultValue) |
3735 |
10 Feb 16 |
olle |
94 |
{ |
3735 |
10 Feb 16 |
olle |
if (!value) return defaultValue || ''; |
3735 |
10 Feb 16 |
olle |
if (value.length == 8) |
3735 |
10 Feb 16 |
olle |
97 |
{ |
3735 |
10 Feb 16 |
olle |
// YYYYMMDD |
3735 |
10 Feb 16 |
olle |
value = value.substr(0, 4) + '-' + value.substr(4, 2) + '-' + value.substr(6, 2); |
3735 |
10 Feb 16 |
olle |
100 |
} |
3735 |
10 Feb 16 |
olle |
else if (value.length == 13) |
3735 |
10 Feb 16 |
olle |
102 |
{ |
3735 |
10 Feb 16 |
olle |
// YYYYMMDD HHMM |
3735 |
10 Feb 16 |
olle |
value = value.substr(0, 4) + '-' + value.substr(4, 2) + '-' + value.substr(6, 2) + ' ' + value.substr(9, 2) + ':' + value.substr(11, 2); |
3735 |
10 Feb 16 |
olle |
105 |
} |
3735 |
10 Feb 16 |
olle |
return value; |
3735 |
10 Feb 16 |
olle |
107 |
} |
3735 |
10 Feb 16 |
olle |
108 |
|
3735 |
10 Feb 16 |
olle |
109 |
/** |
3735 |
10 Feb 16 |
olle |
Open a popup window and copy a part of the current window to the popup |
3735 |
10 Feb 16 |
olle |
and make it suitable for printin. |
3735 |
10 Feb 16 |
olle |
112 |
|
3735 |
10 Feb 16 |
olle |
@param printElementId The id of a html tag in the current page that should |
3735 |
10 Feb 16 |
olle |
be copied to the print window |
3735 |
10 Feb 16 |
olle |
@param pageTitle The title of the print window |
3735 |
10 Feb 16 |
olle |
@param pageOrientation 'landscape' or 'portrait' (default) |
3735 |
10 Feb 16 |
olle |
@param printNote Optional note intended to include instructions how to configure |
3735 |
10 Feb 16 |
olle |
the browser for optimal printing (eg. set to landscape and scale to 75%) |
3735 |
10 Feb 16 |
olle |
119 |
*/ |
3735 |
10 Feb 16 |
olle |
labenv.openPrintWindow = function(printElementId, pageTitle, pageOrientation, printNote, labenvRoot, extraStyles) |
3735 |
10 Feb 16 |
olle |
121 |
{ |
3735 |
10 Feb 16 |
olle |
// Default width/height is for 'portrait' orientation |
3735 |
10 Feb 16 |
olle |
var width = 900; |
3735 |
10 Feb 16 |
olle |
var height = 900; |
3735 |
10 Feb 16 |
olle |
if (pageOrientation == 'landscape') |
3735 |
10 Feb 16 |
olle |
126 |
{ |
3735 |
10 Feb 16 |
olle |
width = 1300; |
3735 |
10 Feb 16 |
olle |
height = 700; |
3735 |
10 Feb 16 |
olle |
129 |
} |
3735 |
10 Feb 16 |
olle |
130 |
|
3735 |
10 Feb 16 |
olle |
var url = 'print_template.jsp?ID='+App.getSessionId(); |
3735 |
10 Feb 16 |
olle |
if (extraStyles) url += '&extraStyles='+extraStyles; |
3735 |
10 Feb 16 |
olle |
if (labenvRoot) url = labenvRoot+url; |
3735 |
10 Feb 16 |
olle |
// Open the print-window |
3735 |
10 Feb 16 |
olle |
internal.printOptions = { |
3735 |
10 Feb 16 |
olle |
'printElementId': printElementId, |
3735 |
10 Feb 16 |
olle |
'pageTitle': pageTitle, |
3735 |
10 Feb 16 |
olle |
'pageOrientation': pageOrientation, |
3735 |
10 Feb 16 |
olle |
'printNote': printNote |
3735 |
10 Feb 16 |
olle |
140 |
}; |
3735 |
10 Feb 16 |
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'); |
3735 |
10 Feb 16 |
olle |
142 |
} |
3735 |
10 Feb 16 |
olle |
143 |
|
3735 |
10 Feb 16 |
olle |
labenv.finalizePrint = function(printWin) |
3735 |
10 Feb 16 |
olle |
145 |
{ |
3735 |
10 Feb 16 |
olle |
// Set page title... |
3735 |
10 Feb 16 |
olle |
if (internal.printOptions.pageTitle) |
3735 |
10 Feb 16 |
olle |
148 |
{ |
3735 |
10 Feb 16 |
olle |
printWin.document.title = internal.printOptions.pageTitle; |
3735 |
10 Feb 16 |
olle |
150 |
} |
3735 |
10 Feb 16 |
olle |
151 |
|
3735 |
10 Feb 16 |
olle |
// ...orientation... |
3735 |
10 Feb 16 |
olle |
if (internal.printOptions.pageOrientation) |
3735 |
10 Feb 16 |
olle |
154 |
{ |
3735 |
10 Feb 16 |
olle |
var paper = printWin.document.getElementById('paper'); |
3735 |
10 Feb 16 |
olle |
paper.className += ' ' + internal.printOptions.pageOrientation; |
3735 |
10 Feb 16 |
olle |
157 |
} |
3735 |
10 Feb 16 |
olle |
158 |
|
3735 |
10 Feb 16 |
olle |
// ... and print note |
3735 |
10 Feb 16 |
olle |
if (internal.printOptions.printNote) |
3735 |
10 Feb 16 |
olle |
161 |
{ |
3735 |
10 Feb 16 |
olle |
var note = printWin.document.getElementById('printNote'); |
3735 |
10 Feb 16 |
olle |
note.innerHTML = internal.printOptions.printNote; |
3735 |
10 Feb 16 |
olle |
164 |
} |
3735 |
10 Feb 16 |
olle |
165 |
|
3735 |
10 Feb 16 |
olle |
// Get the HTML from the <div> tag to be printed |
3735 |
10 Feb 16 |
olle |
var printElement = Doc.element(internal.printOptions.printElementId); |
3735 |
10 Feb 16 |
olle |
var printHtml = printElement.innerHTML; |
3735 |
10 Feb 16 |
olle |
// Replace all <canvas> elements with <img> |
3735 |
10 Feb 16 |
olle |
// since that seems the only way to make things work in IE |
3735 |
10 Feb 16 |
olle |
printHtml = printHtml.replace(/\<canvas.*?\<\/canvas\>/g, '<img class="canvas-copy">'); |
3735 |
10 Feb 16 |
olle |
172 |
|
3735 |
10 Feb 16 |
olle |
// Copy the HTML to the print-area in the print-window |
3735 |
10 Feb 16 |
olle |
var printArea = printWin.document.getElementById('printarea'); |
3735 |
10 Feb 16 |
olle |
printArea.innerHTML = printHtml; |
3735 |
10 Feb 16 |
olle |
176 |
|
3735 |
10 Feb 16 |
olle |
// Copy the <canvas> elements as images to the <img> elements |
3735 |
10 Feb 16 |
olle |
// using toDataURL() |
3735 |
10 Feb 16 |
olle |
var srcCanvas = printElement.getElementsByTagName('canvas'); |
3735 |
10 Feb 16 |
olle |
var printImg = printArea.getElementsByClassName('canvas-copy'); |
3735 |
10 Feb 16 |
olle |
for (var i = 0; i < srcCanvas.length; i++) |
3735 |
10 Feb 16 |
olle |
182 |
{ |
4525 |
15 Jun 17 |
nicklas |
var canvas = srcCanvas[i]; |
4525 |
15 Jun 17 |
nicklas |
var img = printImg[i]; |
4525 |
15 Jun 17 |
nicklas |
if (canvas.style.width) img.style.width = canvas.style.width; |
4525 |
15 Jun 17 |
nicklas |
if (canvas.style.height) img.style.height = canvas.style.height; |
4525 |
15 Jun 17 |
nicklas |
img.src = canvas.toDataURL(); |
3735 |
10 Feb 16 |
olle |
188 |
} |
3735 |
10 Feb 16 |
olle |
189 |
} |
3735 |
10 Feb 16 |
olle |
190 |
|
3735 |
10 Feb 16 |
olle |
return labenv; |
3735 |
10 Feb 16 |
olle |
192 |
}(); |
3735 |
10 Feb 16 |
olle |
193 |
|
3735 |
10 Feb 16 |
olle |
194 |
|
3735 |
10 Feb 16 |
olle |
195 |
|
3735 |
10 Feb 16 |
olle |
196 |
|
3735 |
10 Feb 16 |
olle |
var Wizard = function() |
3735 |
10 Feb 16 |
olle |
198 |
{ |
3735 |
10 Feb 16 |
olle |
var wizard = {}; |
3735 |
10 Feb 16 |
olle |
var internal = {}; |
3735 |
10 Feb 16 |
olle |
var debug = 0; |
3735 |
10 Feb 16 |
olle |
202 |
|
3735 |
10 Feb 16 |
olle |
var currentStep = 1; |
3735 |
10 Feb 16 |
olle |
var numLiveAsyncRequests = 0; |
3735 |
10 Feb 16 |
olle |
var hasSentRegistration = false; |
3735 |
10 Feb 16 |
olle |
var forceConfirm = false; |
3735 |
10 Feb 16 |
olle |
var noConfirmOnFirstStep = true; |
3735 |
10 Feb 16 |
olle |
var hasFatalError = false; |
3735 |
10 Feb 16 |
olle |
209 |
|
3735 |
10 Feb 16 |
olle |
210 |
/** |
3735 |
10 Feb 16 |
olle |
Validate the 'date'-input field that is the target of this event |
3735 |
10 Feb 16 |
olle |
The date is optional unless 'required' is part if it's className. |
3735 |
10 Feb 16 |
olle |
Dates should be either 4 or 8 digits with month+day or year+month+day. |
3735 |
10 Feb 16 |
olle |
If 'data-allow-six-digits' is set on the target element, the year |
3735 |
10 Feb 16 |
olle |
is allowed to be only 2 digits. |
3735 |
10 Feb 16 |
olle |
216 |
|
3735 |
10 Feb 16 |
olle |
4-digit (and 6-digit) dates auto-padded to 8 digits. |
3735 |
10 Feb 16 |
olle |
218 |
|
3735 |
10 Feb 16 |
olle |
The 'data-valid' attribute is set to 1 or 0 depending on the outcome, |
3735 |
10 Feb 16 |
olle |
and 'data-warning' is set if the date is missing on non-required fields. |
3735 |
10 Feb 16 |
olle |
221 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.validateDate = function(event) |
3735 |
10 Feb 16 |
olle |
223 |
{ |
3735 |
10 Feb 16 |
olle |
var target = event.currentTarget; |
3735 |
10 Feb 16 |
olle |
var isValid = false; |
3735 |
10 Feb 16 |
olle |
var isWarning = false; |
3735 |
10 Feb 16 |
olle |
227 |
|
3735 |
10 Feb 16 |
olle |
// Reset current status |
3735 |
10 Feb 16 |
olle |
wizard.setInputStatus(target); |
3735 |
10 Feb 16 |
olle |
230 |
|
3735 |
10 Feb 16 |
olle |
var date = target.value; |
3735 |
10 Feb 16 |
olle |
if (date == '') |
3735 |
10 Feb 16 |
olle |
233 |
{ |
3735 |
10 Feb 16 |
olle |
// No date, is this an error or a warning? |
3735 |
10 Feb 16 |
olle |
var optional = target.className.indexOf('required') == -1; |
3735 |
10 Feb 16 |
olle |
wizard.setInputStatus(target, optional ? 'warning' : 'invalid', 'Missing'); |
3735 |
10 Feb 16 |
olle |
isValid = optional; |
3735 |
10 Feb 16 |
olle |
isWarning = optional; |
3735 |
10 Feb 16 |
olle |
239 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
241 |
{ |
3735 |
10 Feb 16 |
olle |
var allowSixDigits = Data.int(target, 'allow-six-digits'); |
3735 |
10 Feb 16 |
olle |
date = LabEnv.autoFillDate(date, allowSixDigits); |
3735 |
10 Feb 16 |
olle |
target.value = date; |
3735 |
10 Feb 16 |
olle |
245 |
|
3735 |
10 Feb 16 |
olle |
var d = Dates.parseString(date, 'yyyyMMdd'); |
3735 |
10 Feb 16 |
olle |
if (d == null) |
3735 |
10 Feb 16 |
olle |
248 |
{ |
3735 |
10 Feb 16 |
olle |
Wizard.setInputStatus(target, 'invalid', 'Not a valid date'); |
3735 |
10 Feb 16 |
olle |
250 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
252 |
{ |
3735 |
10 Feb 16 |
olle |
var disallowFutureDate = Data.int(target, 'disallow-future-date'); |
3735 |
10 Feb 16 |
olle |
var today = new Date(); |
3735 |
10 Feb 16 |
olle |
if (disallowFutureDate && (d.getTime() > today.getTime())) |
3735 |
10 Feb 16 |
olle |
256 |
{ |
3735 |
10 Feb 16 |
olle |
Wizard.setInputStatus(target, 'invalid', 'Future dates are not valid'); |
3735 |
10 Feb 16 |
olle |
258 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
260 |
{ |
3735 |
10 Feb 16 |
olle |
Wizard.setInputStatus(target, 'valid'); |
3735 |
10 Feb 16 |
olle |
isValid = true; |
3735 |
10 Feb 16 |
olle |
263 |
} |
3735 |
10 Feb 16 |
olle |
264 |
} |
3735 |
10 Feb 16 |
olle |
265 |
} |
3735 |
10 Feb 16 |
olle |
266 |
|
3735 |
10 Feb 16 |
olle |
Data.set(target, 'valid', isValid ? 1 : 0); |
3735 |
10 Feb 16 |
olle |
Data.set(target, 'warning', isWarning ? 1 : 0); |
3735 |
10 Feb 16 |
olle |
269 |
|
3735 |
10 Feb 16 |
olle |
if (!isValid && target.focus) target.focus(); |
3735 |
10 Feb 16 |
olle |
return isValid; |
3735 |
10 Feb 16 |
olle |
272 |
} |
3735 |
10 Feb 16 |
olle |
273 |
|
3735 |
10 Feb 16 |
olle |
274 |
|
3735 |
10 Feb 16 |
olle |
wizard.isValid = function(element) |
3735 |
10 Feb 16 |
olle |
276 |
{ |
3735 |
10 Feb 16 |
olle |
return Data.int(element, 'valid', 1); |
3735 |
10 Feb 16 |
olle |
278 |
} |
3735 |
10 Feb 16 |
olle |
279 |
|
3735 |
10 Feb 16 |
olle |
280 |
|
3735 |
10 Feb 16 |
olle |
281 |
/** |
3735 |
10 Feb 16 |
olle |
Change display status for an input field. |
3735 |
10 Feb 16 |
olle |
@param prefix ID prefix to locate tags |
3735 |
10 Feb 16 |
olle |
@param clazz The message clazz (valid, invalid, warning) or empty |
3735 |
10 Feb 16 |
olle |
@param message The message (may be empty) |
3735 |
10 Feb 16 |
olle |
286 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.setInputStatus = function(prefix, clazz, message) |
3735 |
10 Feb 16 |
olle |
288 |
{ |
3735 |
10 Feb 16 |
olle |
if (prefix.id) prefix = prefix.id; |
3735 |
10 Feb 16 |
olle |
290 |
|
3735 |
10 Feb 16 |
olle |
var statusTag = Doc.element(prefix + '.status'); |
3735 |
10 Feb 16 |
olle |
statusTag.className = 'status ' + (clazz || ''); |
3735 |
10 Feb 16 |
olle |
293 |
|
3735 |
10 Feb 16 |
olle |
var trTag = statusTag.parentNode; |
3735 |
10 Feb 16 |
olle |
var trClass = Data.get(trTag, 'original-class'); |
3735 |
10 Feb 16 |
olle |
if (!trClass) |
3735 |
10 Feb 16 |
olle |
297 |
{ |
3735 |
10 Feb 16 |
olle |
trClass = trTag.className || 'foo'; |
3735 |
10 Feb 16 |
olle |
Data.set(trTag, 'original-class', trClass); |
3735 |
10 Feb 16 |
olle |
300 |
} |
3735 |
10 Feb 16 |
olle |
trTag.className = trClass + ' ' + (clazz || ''); |
3735 |
10 Feb 16 |
olle |
302 |
|
3735 |
10 Feb 16 |
olle |
var msgTag = Doc.element(prefix + '.message'); |
3735 |
10 Feb 16 |
olle |
if (msgTag) |
3735 |
10 Feb 16 |
olle |
305 |
{ |
3735 |
10 Feb 16 |
olle |
if (message) |
3735 |
10 Feb 16 |
olle |
307 |
{ |
3735 |
10 Feb 16 |
olle |
msgTag.innerHTML = message; |
3735 |
10 Feb 16 |
olle |
Doc.show(msgTag, Data.get(msgTag, 'display', 'inline')); |
3735 |
10 Feb 16 |
olle |
310 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
312 |
{ |
3735 |
10 Feb 16 |
olle |
msgTag.innerHTML = message; |
3735 |
10 Feb 16 |
olle |
Doc.hide(msgTag); |
3735 |
10 Feb 16 |
olle |
315 |
} |
3735 |
10 Feb 16 |
olle |
316 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
318 |
{ |
3735 |
10 Feb 16 |
olle |
statusTag.title = message || ''; |
3735 |
10 Feb 16 |
olle |
320 |
} |
3735 |
10 Feb 16 |
olle |
321 |
} |
3735 |
10 Feb 16 |
olle |
322 |
|
3735 |
10 Feb 16 |
olle |
323 |
|
3735 |
10 Feb 16 |
olle |
324 |
/** |
3735 |
10 Feb 16 |
olle |
Event handler for input fields, that go to the |
3735 |
10 Feb 16 |
olle |
next wizard step if TAB or ENTER key is pressed. |
3735 |
10 Feb 16 |
olle |
A short delay is used to allow other event handler |
3735 |
10 Feb 16 |
olle |
to run first (eg. for validation). |
3735 |
10 Feb 16 |
olle |
329 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.goNextOnTabOrEnter = function(event) |
3735 |
10 Feb 16 |
olle |
331 |
{ |
3735 |
10 Feb 16 |
olle |
if (event.keyCode == 9 || event.keyCode == 13) |
3735 |
10 Feb 16 |
olle |
333 |
{ |
3735 |
10 Feb 16 |
olle |
setTimeout(function() { wizard.goNext(true) }, 200); |
3735 |
10 Feb 16 |
olle |
335 |
} |
3735 |
10 Feb 16 |
olle |
336 |
} |
3735 |
10 Feb 16 |
olle |
337 |
|
3735 |
10 Feb 16 |
olle |
338 |
/** |
3735 |
10 Feb 16 |
olle |
Event handler for input fields, that go to the |
3735 |
10 Feb 16 |
olle |
next wizard step if TAB key is pressed. |
3735 |
10 Feb 16 |
olle |
A short delay is used to allow other event handler |
3735 |
10 Feb 16 |
olle |
to run first (eg. for validation). |
3735 |
10 Feb 16 |
olle |
343 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.goNextOnTab = function(event) |
3735 |
10 Feb 16 |
olle |
345 |
{ |
3735 |
10 Feb 16 |
olle |
if (event.keyCode == 9) |
3735 |
10 Feb 16 |
olle |
347 |
{ |
3735 |
10 Feb 16 |
olle |
setTimeout(function() { wizard.goNext(true) }, 200); |
3735 |
10 Feb 16 |
olle |
349 |
} |
3735 |
10 Feb 16 |
olle |
350 |
} |
3735 |
10 Feb 16 |
olle |
351 |
|
3735 |
10 Feb 16 |
olle |
352 |
/** |
3735 |
10 Feb 16 |
olle |
Event handler for input fields, that changes |
3735 |
10 Feb 16 |
olle |
focus to the next element. The next element |
3735 |
10 Feb 16 |
olle |
should be defined by 'data-next-focus' attribute. |
3735 |
10 Feb 16 |
olle |
It is recommended that this is consisistent with TAB. |
3735 |
10 Feb 16 |
olle |
357 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.focusOnEnter = function(event) |
3735 |
10 Feb 16 |
olle |
359 |
{ |
3735 |
10 Feb 16 |
olle |
if (event.keyCode == 13) |
3735 |
10 Feb 16 |
olle |
361 |
{ |
3735 |
10 Feb 16 |
olle |
var nextFocus = Doc.element(Data.get(event.currentTarget, 'next-focus')); |
3735 |
10 Feb 16 |
olle |
if (nextFocus && nextFocus.focus) nextFocus.focus(); |
3735 |
10 Feb 16 |
olle |
364 |
} |
3735 |
10 Feb 16 |
olle |
365 |
} |
3735 |
10 Feb 16 |
olle |
366 |
|
3735 |
10 Feb 16 |
olle |
// Event handler for the 'Next' navigation button |
3735 |
10 Feb 16 |
olle |
wizard.goNextOnClick = function(event) |
3735 |
10 Feb 16 |
olle |
369 |
{ |
3735 |
10 Feb 16 |
olle |
wizard.goNext(false); |
3735 |
10 Feb 16 |
olle |
371 |
} |
3735 |
10 Feb 16 |
olle |
372 |
|
3735 |
10 Feb 16 |
olle |
373 |
/** |
3735 |
10 Feb 16 |
olle |
Go to the next step in the wizard. This method will first |
3735 |
10 Feb 16 |
olle |
submit 'wizard-validate' event to the current step. If at |
3735 |
10 Feb 16 |
olle |
least one event handler calls 'Event.preventDefault()' the |
3735 |
10 Feb 16 |
olle |
processing is aborted. |
3735 |
10 Feb 16 |
olle |
378 |
|
3735 |
10 Feb 16 |
olle |
Otherwise, the current step is disabled and the 'wizard-initialize' |
3735 |
10 Feb 16 |
olle |
event is sent to the next step. The event handler is responsible |
3735 |
10 Feb 16 |
olle |
for calling 'Wizard.setCurrentStep' to display the next step. |
3735 |
10 Feb 16 |
olle |
382 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.goNext = function(auto) |
3735 |
10 Feb 16 |
olle |
384 |
{ |
3735 |
10 Feb 16 |
olle |
var verify = Doc.element('verifyGoNext'); |
3735 |
10 Feb 16 |
olle |
if (verify && !verify.checked) return; |
3735 |
10 Feb 16 |
olle |
387 |
|
3735 |
10 Feb 16 |
olle |
var details = { 'auto': auto }; |
3735 |
10 Feb 16 |
olle |
389 |
|
3735 |
10 Feb 16 |
olle |
// Send 'wizard-validate' event to current step |
3735 |
10 Feb 16 |
olle |
var step = Doc.element('step-'+currentStep); |
3735 |
10 Feb 16 |
olle |
var evt = document.createEvent('CustomEvent'); |
3735 |
10 Feb 16 |
olle |
evt.initCustomEvent('wizard-validate', true, true, details); |
3735 |
10 Feb 16 |
olle |
if (!step.dispatchEvent(evt)) |
3735 |
10 Feb 16 |
olle |
395 |
{ |
3735 |
10 Feb 16 |
olle |
wizard.notifyError(); |
3735 |
10 Feb 16 |
olle |
return; |
3735 |
10 Feb 16 |
olle |
398 |
} |
3735 |
10 Feb 16 |
olle |
399 |
|
3735 |
10 Feb 16 |
olle |
// Hide all navigation buttons and disable form controls in current step |
3735 |
10 Feb 16 |
olle |
internal.hideButtons('navigation'); |
3735 |
10 Feb 16 |
olle |
internal.disableStep(step); |
3735 |
10 Feb 16 |
olle |
403 |
|
3735 |
10 Feb 16 |
olle |
// Send 'wizard-initialize' to the next step |
3735 |
10 Feb 16 |
olle |
var nextStep = Doc.element('step-'+(currentStep+1)); |
3735 |
10 Feb 16 |
olle |
var evt = document.createEvent('CustomEvent'); |
3735 |
10 Feb 16 |
olle |
evt.initCustomEvent('wizard-initialize', true, true, details); |
3735 |
10 Feb 16 |
olle |
nextStep.dispatchEvent(evt); |
3735 |
10 Feb 16 |
olle |
409 |
} |
3735 |
10 Feb 16 |
olle |
410 |
|
3735 |
10 Feb 16 |
olle |
wizard.notifyError = function() |
3735 |
10 Feb 16 |
olle |
412 |
{ |
3735 |
10 Feb 16 |
olle |
Doc.addClass('wizard', 'flash-error'); |
3735 |
10 Feb 16 |
olle |
setTimeout(internal.stopFlashing, 2000); |
3735 |
10 Feb 16 |
olle |
415 |
} |
3735 |
10 Feb 16 |
olle |
416 |
|
3735 |
10 Feb 16 |
olle |
internal.stopFlashing = function() |
3735 |
10 Feb 16 |
olle |
418 |
{ |
3735 |
10 Feb 16 |
olle |
Doc.removeClass('wizard', 'flash-error'); |
3735 |
10 Feb 16 |
olle |
420 |
} |
3735 |
10 Feb 16 |
olle |
421 |
|
3735 |
10 Feb 16 |
olle |
422 |
/** |
3735 |
10 Feb 16 |
olle |
Finalize the registration of the wizard. This method will |
3735 |
10 Feb 16 |
olle |
first submit 'wizard-validate' to the current step. If at |
3735 |
10 Feb 16 |
olle |
least one event handler calls 'Event.preventDefault()' the |
3735 |
10 Feb 16 |
olle |
processing is aborted. |
3735 |
10 Feb 16 |
olle |
427 |
|
3735 |
10 Feb 16 |
olle |
Otherwise, the current step is disabled and the 'wizard-submit' |
3735 |
10 Feb 16 |
olle |
event is sent to the 'wizard'. The event handler is responsible |
3735 |
10 Feb 16 |
olle |
for finalizing the registration and displaying a proper |
3735 |
10 Feb 16 |
olle |
message, for example, by calling Wizard.showFinalMessage() |
3735 |
10 Feb 16 |
olle |
432 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.goRegister = function() |
3735 |
10 Feb 16 |
olle |
434 |
{ |
3735 |
10 Feb 16 |
olle |
// Check if verification is enabled |
3735 |
10 Feb 16 |
olle |
var verify = Doc.element('verifyGoNext'); |
3735 |
10 Feb 16 |
olle |
if (verify && !verify.checked) return; |
3735 |
10 Feb 16 |
olle |
438 |
|
3735 |
10 Feb 16 |
olle |
// Send 'wizard-validate' event to current step |
3735 |
10 Feb 16 |
olle |
var step = Doc.element('step-'+currentStep); |
4527 |
20 Jun 17 |
nicklas |
if (step) |
3735 |
10 Feb 16 |
olle |
442 |
{ |
4527 |
20 Jun 17 |
nicklas |
var evt = document.createEvent('Event'); |
4527 |
20 Jun 17 |
nicklas |
evt.initEvent('wizard-validate', false, true); |
4527 |
20 Jun 17 |
nicklas |
if (!step.dispatchEvent(evt)) |
4527 |
20 Jun 17 |
nicklas |
446 |
{ |
4527 |
20 Jun 17 |
nicklas |
wizard.notifyError(); |
4527 |
20 Jun 17 |
nicklas |
return; |
4527 |
20 Jun 17 |
nicklas |
449 |
} |
4527 |
20 Jun 17 |
nicklas |
internal.disableStep(step); |
3735 |
10 Feb 16 |
olle |
451 |
} |
3735 |
10 Feb 16 |
olle |
452 |
|
3735 |
10 Feb 16 |
olle |
internal.hideButtons('navigation'); |
3735 |
10 Feb 16 |
olle |
454 |
|
3735 |
10 Feb 16 |
olle |
// Send 'wizard-submit' to the next step |
3735 |
10 Feb 16 |
olle |
var wiz = Doc.element('wizard'); |
3735 |
10 Feb 16 |
olle |
hasSentRegistration = true; |
3735 |
10 Feb 16 |
olle |
var evt = document.createEvent('Event'); |
3735 |
10 Feb 16 |
olle |
evt.initEvent('wizard-submit', false, true); |
3735 |
10 Feb 16 |
olle |
wiz.dispatchEvent(evt); |
3735 |
10 Feb 16 |
olle |
461 |
} |
3735 |
10 Feb 16 |
olle |
462 |
|
3735 |
10 Feb 16 |
olle |
wizard.setNoConfirmOnFirstStep = function(cf) |
3735 |
10 Feb 16 |
olle |
464 |
{ |
3735 |
10 Feb 16 |
olle |
noConfirmOnFirstStep = cf; |
3735 |
10 Feb 16 |
olle |
466 |
} |
3735 |
10 Feb 16 |
olle |
467 |
|
3735 |
10 Feb 16 |
olle |
// Ask the user for confirmation and then restart the wizard |
3735 |
10 Feb 16 |
olle |
wizard.cancelWizard = function() |
3735 |
10 Feb 16 |
olle |
470 |
{ |
3735 |
10 Feb 16 |
olle |
forceConfirm = true; |
3735 |
10 Feb 16 |
olle |
wizard.restartWizard(); |
3735 |
10 Feb 16 |
olle |
473 |
} |
3735 |
10 Feb 16 |
olle |
474 |
|
3735 |
10 Feb 16 |
olle |
// Restart the wizard without asking the user for confirmation |
3735 |
10 Feb 16 |
olle |
wizard.restartWizard = function() |
3735 |
10 Feb 16 |
olle |
477 |
{ |
3735 |
10 Feb 16 |
olle |
var url = location.href; |
3735 |
10 Feb 16 |
olle |
if (url.indexOf('&restart=1') == -1) url += '&restart=1'; |
3735 |
10 Feb 16 |
olle |
location.href = url; |
3735 |
10 Feb 16 |
olle |
481 |
} |
3735 |
10 Feb 16 |
olle |
482 |
|
3735 |
10 Feb 16 |
olle |
wizard.goPrint = function() |
3735 |
10 Feb 16 |
olle |
484 |
{ |
3735 |
10 Feb 16 |
olle |
window.print(); |
3735 |
10 Feb 16 |
olle |
486 |
} |
3735 |
10 Feb 16 |
olle |
487 |
|
3735 |
10 Feb 16 |
olle |
wizard.setCurrentStep = function(stepNo) |
3735 |
10 Feb 16 |
olle |
489 |
{ |
3735 |
10 Feb 16 |
olle |
currentStep = stepNo; |
3735 |
10 Feb 16 |
olle |
internal.enableStep(Doc.element('step-'+currentStep)); |
3735 |
10 Feb 16 |
olle |
492 |
} |
3735 |
10 Feb 16 |
olle |
493 |
|
3735 |
10 Feb 16 |
olle |
internal.disableStep = function(step) |
3735 |
10 Feb 16 |
olle |
495 |
{ |
3735 |
10 Feb 16 |
olle |
step = Doc.element(step); |
3735 |
10 Feb 16 |
olle |
internal.disableAllFormElements(step); |
3735 |
10 Feb 16 |
olle |
Doc.addClass(step, 'disabled'); |
3735 |
10 Feb 16 |
olle |
Doc.hide('gonext-message'); |
3735 |
10 Feb 16 |
olle |
var stepNo = step.getElementsByClassName('step-no')[0]; |
3735 |
10 Feb 16 |
olle |
Events.addEventHandler(stepNo, 'click', internal.togglePastStep, {'step-id': step.id}); |
3735 |
10 Feb 16 |
olle |
stepNo.title = 'Show/hide this section'; |
3735 |
10 Feb 16 |
olle |
503 |
} |
3735 |
10 Feb 16 |
olle |
504 |
|
3735 |
10 Feb 16 |
olle |
internal.enableStep = function(step) |
3735 |
10 Feb 16 |
olle |
506 |
{ |
3735 |
10 Feb 16 |
olle |
step = Doc.element(step); |
3735 |
10 Feb 16 |
olle |
Doc.removeClass(step, 'disabled'); |
3735 |
10 Feb 16 |
olle |
Doc.show(step); |
3735 |
10 Feb 16 |
olle |
510 |
} |
3735 |
10 Feb 16 |
olle |
511 |
|
3735 |
10 Feb 16 |
olle |
// Toggle visibility of a past step |
3735 |
10 Feb 16 |
olle |
// The step is hidden if the 'auto-hide' class is present |
3735 |
10 Feb 16 |
olle |
internal.togglePastStep = function(event) |
3735 |
10 Feb 16 |
olle |
515 |
{ |
3735 |
10 Feb 16 |
olle |
var step = Data.get(event.currentTarget, 'step-id'); |
3735 |
10 Feb 16 |
olle |
Doc.addOrRemoveClass(step, 'auto-hide'); |
3735 |
10 Feb 16 |
olle |
518 |
} |
3735 |
10 Feb 16 |
olle |
519 |
|
3735 |
10 Feb 16 |
olle |
520 |
/** |
3735 |
10 Feb 16 |
olle |
Submit an ansynchronous request for JSON data. 'GET' method |
3735 |
10 Feb 16 |
olle |
is used if 'method' parameter is not set. |
3735 |
10 Feb 16 |
olle |
The 'callback' should be a method accepting a single |
3735 |
10 Feb 16 |
olle |
JSON parameter object. If the 'status' of the response |
3735 |
10 Feb 16 |
olle |
is not 'ok' this method will call setFatalError and |
3735 |
10 Feb 16 |
olle |
without calling the callback method. |
3735 |
10 Feb 16 |
olle |
527 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.asyncJsonRequest = function(url, callback, method, postdata) |
3735 |
10 Feb 16 |
olle |
529 |
{ |
3735 |
10 Feb 16 |
olle |
if (debug) |
3735 |
10 Feb 16 |
olle |
531 |
{ |
3735 |
10 Feb 16 |
olle |
App.debug((method || 'GET') + ': ' + url); |
3735 |
10 Feb 16 |
olle |
if (postdata) App.debug(postdata); |
3735 |
10 Feb 16 |
olle |
534 |
} |
3735 |
10 Feb 16 |
olle |
var request = Ajax.getXmlHttpRequest(); |
3735 |
10 Feb 16 |
olle |
request.jsonCallback = callback; |
3735 |
10 Feb 16 |
olle |
request.open(method || 'GET', url, true); |
3735 |
10 Feb 16 |
olle |
if (postdata) |
3735 |
10 Feb 16 |
olle |
539 |
{ |
3735 |
10 Feb 16 |
olle |
request.setRequestHeader("Content-Type", "application/json"); |
3735 |
10 Feb 16 |
olle |
541 |
} |
3735 |
10 Feb 16 |
olle |
Ajax.setReadyStateHandler(request, internal.asyncCallbackWrapper, internal.asyncCallbackWrapper); |
3735 |
10 Feb 16 |
olle |
numLiveAsyncRequests++; |
3735 |
10 Feb 16 |
olle |
request.send(postdata || null); |
3735 |
10 Feb 16 |
olle |
545 |
} |
3735 |
10 Feb 16 |
olle |
546 |
|
3735 |
10 Feb 16 |
olle |
547 |
/** |
3735 |
10 Feb 16 |
olle |
Callback wrapper for ansynchronous requests. |
3735 |
10 Feb 16 |
olle |
549 |
*/ |
3735 |
10 Feb 16 |
olle |
internal.asyncCallbackWrapper = function(request) |
3735 |
10 Feb 16 |
olle |
551 |
{ |
3735 |
10 Feb 16 |
olle |
numLiveAsyncRequests--; |
3735 |
10 Feb 16 |
olle |
if (debug) App.debug(request.responseText); |
3735 |
10 Feb 16 |
olle |
if (!hasFatalError) Wizard.hideWizardStatus(); |
3735 |
10 Feb 16 |
olle |
555 |
|
3735 |
10 Feb 16 |
olle |
var response = null; |
3735 |
10 Feb 16 |
olle |
var messages = null; |
3735 |
10 Feb 16 |
olle |
try |
3735 |
10 Feb 16 |
olle |
559 |
{ |
3735 |
10 Feb 16 |
olle |
if (request.status != 200) |
3735 |
10 Feb 16 |
olle |
561 |
{ |
3735 |
10 Feb 16 |
olle |
throw new Error(request.responseText); |
3735 |
10 Feb 16 |
olle |
563 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
565 |
{ |
3735 |
10 Feb 16 |
olle |
if (request.getResponseHeader('Content-Type').indexOf('json') != -1) |
3735 |
10 Feb 16 |
olle |
567 |
{ |
3735 |
10 Feb 16 |
olle |
response = JSON.parse(request.responseText); |
3735 |
10 Feb 16 |
olle |
messages = response.messages; |
3735 |
10 Feb 16 |
olle |
if (response.status != 'ok') |
3735 |
10 Feb 16 |
olle |
571 |
{ |
3735 |
10 Feb 16 |
olle |
throw new Error(response.message || response.stacktrace); |
3735 |
10 Feb 16 |
olle |
573 |
} |
3735 |
10 Feb 16 |
olle |
574 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
576 |
{ |
3735 |
10 Feb 16 |
olle |
response = request.responseText; |
3735 |
10 Feb 16 |
olle |
578 |
} |
3735 |
10 Feb 16 |
olle |
if (request.jsonCallback && request.jsonCallback.call) |
3735 |
10 Feb 16 |
olle |
580 |
{ |
3735 |
10 Feb 16 |
olle |
request.jsonCallback.call(null, response); |
3735 |
10 Feb 16 |
olle |
582 |
} |
3735 |
10 Feb 16 |
olle |
583 |
} |
3735 |
10 Feb 16 |
olle |
584 |
} |
3735 |
10 Feb 16 |
olle |
catch (err) |
3735 |
10 Feb 16 |
olle |
586 |
{ |
3735 |
10 Feb 16 |
olle |
Wizard.setFatalError(err, messages); |
3735 |
10 Feb 16 |
olle |
588 |
} |
3735 |
10 Feb 16 |
olle |
589 |
} |
3735 |
10 Feb 16 |
olle |
590 |
|
3735 |
10 Feb 16 |
olle |
591 |
|
3735 |
10 Feb 16 |
olle |
592 |
/** |
3735 |
10 Feb 16 |
olle |
A fatal error has occurred and the wizard will not be able to continue. |
3735 |
10 Feb 16 |
olle |
This method will display the error message, disable all form input fields |
3735 |
10 Feb 16 |
olle |
and buttons (except the 'Restart' button). |
3735 |
10 Feb 16 |
olle |
596 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.setFatalError = function(err, messages) |
3735 |
10 Feb 16 |
olle |
598 |
{ |
3735 |
10 Feb 16 |
olle |
hasFatalError = true; |
3735 |
10 Feb 16 |
olle |
var msg = err; |
3735 |
10 Feb 16 |
olle |
if (err.toString) |
3735 |
10 Feb 16 |
olle |
602 |
{ |
3735 |
10 Feb 16 |
olle |
App.debug(err.toString()); |
3735 |
10 Feb 16 |
olle |
msg = Strings.encodeTags(err.toString()); |
3735 |
10 Feb 16 |
olle |
if (err.stack && !messages) |
3735 |
10 Feb 16 |
olle |
606 |
{ |
3735 |
10 Feb 16 |
olle |
App.debug(err.stack); |
3735 |
10 Feb 16 |
olle |
msg += '<br><pre>'+Strings.encodeTags(err.stack)+'</pre>'; |
3735 |
10 Feb 16 |
olle |
609 |
} |
3735 |
10 Feb 16 |
olle |
610 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
612 |
{ |
3735 |
10 Feb 16 |
olle |
App.debug(msg); |
3735 |
10 Feb 16 |
olle |
614 |
} |
3735 |
10 Feb 16 |
olle |
615 |
|
3735 |
10 Feb 16 |
olle |
if (messages) |
3735 |
10 Feb 16 |
olle |
617 |
{ |
3735 |
10 Feb 16 |
olle |
msg = '<div class="messagecontainer error">'+msg+'</div>'+internal.generateMessageList(messages).html; |
3735 |
10 Feb 16 |
olle |
wizard.setWizardStatus('success', msg); |
3735 |
10 Feb 16 |
olle |
620 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
622 |
{ |
3735 |
10 Feb 16 |
olle |
wizard.setWizardStatus('messagecontainer error', msg || 'Unexpected failure!'); |
3735 |
10 Feb 16 |
olle |
624 |
} |
3735 |
10 Feb 16 |
olle |
625 |
|
3735 |
10 Feb 16 |
olle |
Doc.addClass('wizard', 'disabled'); |
3735 |
10 Feb 16 |
olle |
internal.disableAllFormElements('wizard', true); |
3735 |
10 Feb 16 |
olle |
Doc.show('gorestart'); |
3735 |
10 Feb 16 |
olle |
629 |
} |
3735 |
10 Feb 16 |
olle |
630 |
|
3735 |
10 Feb 16 |
olle |
631 |
|
3735 |
10 Feb 16 |
olle |
632 |
/** |
3735 |
10 Feb 16 |
olle |
Display a 'loading' global wizard-status message. |
3735 |
10 Feb 16 |
olle |
634 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.showLoadingAnimation = function(msg) |
3735 |
10 Feb 16 |
olle |
636 |
{ |
3735 |
10 Feb 16 |
olle |
wizard.setWizardStatus('loading', msg || 'Working, please wait...'); |
3735 |
10 Feb 16 |
olle |
638 |
} |
3735 |
10 Feb 16 |
olle |
639 |
|
3735 |
10 Feb 16 |
olle |
wizard.showStatusMessage = function(msg) |
3735 |
10 Feb 16 |
olle |
641 |
{ |
3735 |
10 Feb 16 |
olle |
App.debug(msg); |
3735 |
10 Feb 16 |
olle |
wizard.setWizardStatus('messagecontainer note', msg); |
3735 |
10 Feb 16 |
olle |
644 |
} |
3735 |
10 Feb 16 |
olle |
645 |
|
3735 |
10 Feb 16 |
olle |
internal.verifyInternalOnClick = function(event) |
3735 |
10 Feb 16 |
olle |
647 |
{ |
3735 |
10 Feb 16 |
olle |
var frm = document.forms['labenv']; |
3735 |
10 Feb 16 |
olle |
var checked = event.currentTarget.checked; |
3735 |
10 Feb 16 |
olle |
Doc.addOrRemoveClass('goregister', 'disabled', !checked); |
3735 |
10 Feb 16 |
olle |
Doc.addOrRemoveClass('gonext', 'disabled', !checked); |
3735 |
10 Feb 16 |
olle |
652 |
} |
3735 |
10 Feb 16 |
olle |
653 |
|
3735 |
10 Feb 16 |
olle |
654 |
/** |
3735 |
10 Feb 16 |
olle |
Show final registration messages in a list. |
3735 |
10 Feb 16 |
olle |
656 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.showFinalMessage = function(messages) |
3735 |
10 Feb 16 |
olle |
658 |
{ |
3735 |
10 Feb 16 |
olle |
var msg = internal.generateMessageList(messages); |
3735 |
10 Feb 16 |
olle |
wizard.setWizardStatus('success', msg.html); |
3735 |
10 Feb 16 |
olle |
return { 'errors': msg.errors, 'warnings': msg.warnings }; |
3735 |
10 Feb 16 |
olle |
662 |
} |
3735 |
10 Feb 16 |
olle |
663 |
|
3735 |
10 Feb 16 |
olle |
664 |
|
3735 |
10 Feb 16 |
olle |
internal.generateMessageList = function(messages) |
3735 |
10 Feb 16 |
olle |
666 |
{ |
3735 |
10 Feb 16 |
olle |
var msg = '<ul>'; |
3735 |
10 Feb 16 |
olle |
var numWarnings = 0; |
3735 |
10 Feb 16 |
olle |
var numErrors = 0; |
3735 |
10 Feb 16 |
olle |
for (var i = 0; i < messages.length; i++) |
3735 |
10 Feb 16 |
olle |
671 |
{ |
3735 |
10 Feb 16 |
olle |
var msgLine = messages[i]; |
3735 |
10 Feb 16 |
olle |
if (msgLine.indexOf('[Warning]') >= 0) |
3735 |
10 Feb 16 |
olle |
674 |
{ |
3735 |
10 Feb 16 |
olle |
msg += '<li class="warning">' + Strings.encodeTags(msgLine.replace('[Warning]', '')); |
3735 |
10 Feb 16 |
olle |
numWarnings++; |
3735 |
10 Feb 16 |
olle |
677 |
} |
3735 |
10 Feb 16 |
olle |
else if (msgLine.indexOf('[Error]') >= 0) |
3735 |
10 Feb 16 |
olle |
679 |
{ |
3735 |
10 Feb 16 |
olle |
msg += '<li class="error">' + Strings.encodeTags(msgLine.replace('[Error]', '')); |
3735 |
10 Feb 16 |
olle |
numErrors++; |
3735 |
10 Feb 16 |
olle |
682 |
} |
3735 |
10 Feb 16 |
olle |
else |
3735 |
10 Feb 16 |
olle |
684 |
{ |
3735 |
10 Feb 16 |
olle |
msg += '<li class="ok">' + Strings.encodeTags(msgLine); |
3735 |
10 Feb 16 |
olle |
686 |
} |
3735 |
10 Feb 16 |
olle |
687 |
} |
3735 |
10 Feb 16 |
olle |
msg += '</ul>'; |
3735 |
10 Feb 16 |
olle |
return { 'html': msg, 'errors': numErrors, 'warnings': numWarnings }; |
3735 |
10 Feb 16 |
olle |
690 |
} |
3735 |
10 Feb 16 |
olle |
691 |
|
3735 |
10 Feb 16 |
olle |
692 |
/** |
3735 |
10 Feb 16 |
olle |
Hide the current global wizard-status message. |
3735 |
10 Feb 16 |
olle |
694 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.hideWizardStatus = function() |
3735 |
10 Feb 16 |
olle |
696 |
{ |
3735 |
10 Feb 16 |
olle |
Doc.hide('wizard-status'); |
3735 |
10 Feb 16 |
olle |
698 |
} |
3735 |
10 Feb 16 |
olle |
699 |
|
3735 |
10 Feb 16 |
olle |
700 |
/** |
3735 |
10 Feb 16 |
olle |
Initialize the wizard: |
3735 |
10 Feb 16 |
olle |
702 |
|
3735 |
10 Feb 16 |
olle |
* Check that a project is active |
3735 |
10 Feb 16 |
olle |
704 |
*/ |
3735 |
10 Feb 16 |
olle |
internal.initWizard = function() |
3735 |
10 Feb 16 |
olle |
706 |
{ |
3735 |
10 Feb 16 |
olle |
// Check if project is enabled |
3735 |
10 Feb 16 |
olle |
var wiz = Doc.element('wizard'); |
3735 |
10 Feb 16 |
olle |
if (wiz) |
3735 |
10 Feb 16 |
olle |
710 |
{ |
3735 |
10 Feb 16 |
olle |
window.addEventListener('beforeunload', internal.confirmLeaveWizard); |
3735 |
10 Feb 16 |
olle |
712 |
} |
3735 |
10 Feb 16 |
olle |
713 |
|
3735 |
10 Feb 16 |
olle |
var path = document.getElementsByClassName('pathelement'); |
3735 |
10 Feb 16 |
olle |
if (path && path.length) |
3735 |
10 Feb 16 |
olle |
716 |
{ |
3735 |
10 Feb 16 |
olle |
path[path.length-1].innerHTML += '<span id="labenv-version">[LabEnv '+LabEnv.VERSION+']</span>'; |
3735 |
10 Feb 16 |
olle |
718 |
} |
3735 |
10 Feb 16 |
olle |
719 |
} |
3735 |
10 Feb 16 |
olle |
720 |
|
3735 |
10 Feb 16 |
olle |
internal.confirmLeaveWizard = function(event) |
3735 |
10 Feb 16 |
olle |
722 |
{ |
3735 |
10 Feb 16 |
olle |
if (hasFatalError) return; |
3735 |
10 Feb 16 |
olle |
if (!forceConfirm) |
3735 |
10 Feb 16 |
olle |
725 |
{ |
3735 |
10 Feb 16 |
olle |
if (currentStep == 1 && noConfirmOnFirstStep) return; |
3735 |
10 Feb 16 |
olle |
if (hasSentRegistration && numLiveAsyncRequests == 0) return; |
3735 |
10 Feb 16 |
olle |
728 |
} |
3735 |
10 Feb 16 |
olle |
forceConfirm = false; |
3735 |
10 Feb 16 |
olle |
event.preventDefault(); |
3735 |
10 Feb 16 |
olle |
731 |
} |
3735 |
10 Feb 16 |
olle |
732 |
|
3735 |
10 Feb 16 |
olle |
// Initialize some event handlers |
3735 |
10 Feb 16 |
olle |
internal.initElements = function(element, autoInit) |
3735 |
10 Feb 16 |
olle |
735 |
{ |
3735 |
10 Feb 16 |
olle |
if (autoInit == 'focus-on-enter') |
3735 |
10 Feb 16 |
olle |
737 |
{ |
3735 |
10 Feb 16 |
olle |
Events.addEventHandler(element, 'keypress', wizard.focusOnEnter); |
3735 |
10 Feb 16 |
olle |
739 |
} |
3735 |
10 Feb 16 |
olle |
740 |
} |
3735 |
10 Feb 16 |
olle |
741 |
|
3735 |
10 Feb 16 |
olle |
742 |
/** |
3735 |
10 Feb 16 |
olle |
Display a global wizard-status message. This may for example be |
3735 |
10 Feb 16 |
olle |
an error message, a work-in-progress indicator, etc. |
3735 |
10 Feb 16 |
olle |
745 |
*/ |
3735 |
10 Feb 16 |
olle |
wizard.setWizardStatus = function(className, msg) |
3735 |
10 Feb 16 |
olle |
747 |
{ |
3735 |
10 Feb 16 |
olle |
var status = Doc.element('wizard-status'); |
3735 |
10 Feb 16 |
olle |
status.className = className; |
3735 |
10 Feb 16 |
olle |
status.innerHTML = msg; |
3735 |
10 Feb 16 |
olle |
Doc.show(status); |
3735 |
10 Feb 16 |
olle |
752 |
} |
3735 |
10 Feb 16 |
olle |
753 |
|
3735 |
10 Feb 16 |
olle |
// Disable all form elements inside the given container |
3735 |
10 Feb 16 |
olle |
internal.disableAllFormElements = function(container, hideButtons) |
3735 |
10 Feb 16 |
olle |
756 |
{ |
3735 |
10 Feb 16 |
olle |
container = Doc.element(container); |
3735 |
10 Feb 16 |
olle |
var input = container.getElementsByTagName('input'); |
3735 |
10 Feb 16 |
olle |
for (var i = 0; i < input.length; i++) |
3735 |
10 Feb 16 |
olle |
760 |
{ |
3735 |
10 Feb 16 |
olle |
input[i].disabled = true; |
3735 |
10 Feb 16 |
olle |
762 |
} |
3735 |
10 Feb 16 |
olle |
var select = container.getElementsByTagName('select'); |
3735 |
10 Feb 16 |
olle |
for (var i = 0; i < select.length; i++) |
3735 |
10 Feb 16 |
olle |
765 |
{ |
3735 |
10 Feb 16 |
olle |
select[i].disabled = true; |
3735 |
10 Feb 16 |
olle |
767 |
} |
3735 |
10 Feb 16 |
olle |
var text = container.getElementsByTagName('textarea'); |
3735 |
10 Feb 16 |
olle |
for (var i = 0; i < text.length; i++) |
3735 |
10 Feb 16 |
olle |
770 |
{ |
3735 |
10 Feb 16 |
olle |
text[i].disabled = true; |
3735 |
10 Feb 16 |
olle |
772 |
} |
3735 |
10 Feb 16 |
olle |
if (hideButtons) |
3735 |
10 Feb 16 |
olle |
774 |
{ |
3735 |
10 Feb 16 |
olle |
internal.hideButtons(container); |
3735 |
10 Feb 16 |
olle |
776 |
} |
3735 |
10 Feb 16 |
olle |
777 |
} |
3735 |
10 Feb 16 |
olle |
778 |
|
3735 |
10 Feb 16 |
olle |
// Hide all 'basicbuttons':s in the given container |
3735 |
10 Feb 16 |
olle |
internal.hideButtons = function(container) |
3735 |
10 Feb 16 |
olle |
781 |
{ |
3735 |
10 Feb 16 |
olle |
container = Doc.element(container); |
3735 |
10 Feb 16 |
olle |
var buttons = container.getElementsByClassName('basicbutton'); |
3735 |
10 Feb 16 |
olle |
for (var i = 0; i < buttons.length; i++) |
3735 |
10 Feb 16 |
olle |
785 |
{ |
3735 |
10 Feb 16 |
olle |
Doc.hide(buttons[i]); |
3735 |
10 Feb 16 |
olle |
787 |
} |
3735 |
10 Feb 16 |
olle |
788 |
} |
3735 |
10 Feb 16 |
olle |
789 |
|
3735 |
10 Feb 16 |
olle |
Doc.addFinalizer(internal.initWizard); |
3735 |
10 Feb 16 |
olle |
Doc.addElementInitializer(internal.initElements); |
3735 |
10 Feb 16 |
olle |
return wizard; |
3735 |
10 Feb 16 |
olle |
793 |
}(); |
3735 |
10 Feb 16 |
olle |
794 |
|