4354 |
13 Feb 17 |
nicklas |
1 |
|
4354 |
13 Feb 17 |
nicklas |
var Relax = function() |
4354 |
13 Feb 17 |
nicklas |
3 |
{ |
4354 |
13 Feb 17 |
nicklas |
var relax = {}; |
4354 |
13 Feb 17 |
nicklas |
5 |
|
5979 |
24 Jun 20 |
nicklas |
relax.VERSION = '1.7-dev'; |
4354 |
13 Feb 17 |
nicklas |
7 |
|
4632 |
22 Nov 17 |
nicklas |
8 |
|
4632 |
22 Nov 17 |
nicklas |
relax.checkIsAdmin = function(message, callback, servletDir) |
4632 |
22 Nov 17 |
nicklas |
10 |
{ |
4632 |
22 Nov 17 |
nicklas |
var url = (servletDir || '../') + 'Session.servlet?ID='+App.getSessionId(); |
4632 |
22 Nov 17 |
nicklas |
url += '&cmd=CheckIsAdmin'; |
4632 |
22 Nov 17 |
nicklas |
if (message) url += '&message='+encodeURIComponent(message); |
4632 |
22 Nov 17 |
nicklas |
if (!callback) callback = function() {}; |
4632 |
22 Nov 17 |
nicklas |
Wizard.asyncJsonRequest(url, callback); |
4632 |
22 Nov 17 |
nicklas |
16 |
} |
4632 |
22 Nov 17 |
nicklas |
17 |
|
4354 |
13 Feb 17 |
nicklas |
return relax; |
4354 |
13 Feb 17 |
nicklas |
19 |
}(); |
4354 |
13 Feb 17 |
nicklas |
20 |
|
4354 |
13 Feb 17 |
nicklas |
21 |
|
4354 |
13 Feb 17 |
nicklas |
var Wizard = function() |
4354 |
13 Feb 17 |
nicklas |
23 |
{ |
4354 |
13 Feb 17 |
nicklas |
var wizard = {}; |
4354 |
13 Feb 17 |
nicklas |
var internal = {}; |
5284 |
06 Feb 19 |
nicklas |
var debug = 0; |
4354 |
13 Feb 17 |
nicklas |
27 |
|
4354 |
13 Feb 17 |
nicklas |
var numLiveAsyncRequests = 0; |
4354 |
13 Feb 17 |
nicklas |
var hasFatalError = false; |
4631 |
21 Nov 17 |
nicklas |
var currentStep = 1; |
4631 |
21 Nov 17 |
nicklas |
var hasSentRegistration = false; |
4631 |
21 Nov 17 |
nicklas |
var forceConfirm = false; |
4631 |
21 Nov 17 |
nicklas |
var noConfirmOnFirstStep = true; |
5078 |
08 Nov 18 |
nicklas |
var progressTimer = 0; |
4354 |
13 Feb 17 |
nicklas |
35 |
|
4354 |
13 Feb 17 |
nicklas |
36 |
/** |
4354 |
13 Feb 17 |
nicklas |
Submit an ansynchronous request for JSON data. 'GET' method |
4354 |
13 Feb 17 |
nicklas |
is used if 'method' parameter is not set. |
4354 |
13 Feb 17 |
nicklas |
The 'callback' should be a method accepting a single |
4354 |
13 Feb 17 |
nicklas |
JSON parameter object. If the 'status' of the response |
4354 |
13 Feb 17 |
nicklas |
is not 'ok' this method will call setFatalError and |
4354 |
13 Feb 17 |
nicklas |
without calling the callback method. |
4354 |
13 Feb 17 |
nicklas |
43 |
|
4354 |
13 Feb 17 |
nicklas |
The 'errorCallback' is an optional function parameter that should |
4354 |
13 Feb 17 |
nicklas |
take two parameters. The first is an Error object and the second is |
4354 |
13 Feb 17 |
nicklas |
the JSON response. The seconds parameter only has a value if the error |
4354 |
13 Feb 17 |
nicklas |
happens after parsing the response and is null otherwise. |
4354 |
13 Feb 17 |
nicklas |
48 |
*/ |
4354 |
13 Feb 17 |
nicklas |
wizard.asyncJsonRequest = function(url, callback, method, postdata, errorCallback) |
4354 |
13 Feb 17 |
nicklas |
50 |
{ |
4354 |
13 Feb 17 |
nicklas |
if (debug) |
4354 |
13 Feb 17 |
nicklas |
52 |
{ |
4354 |
13 Feb 17 |
nicklas |
App.debug((method || 'GET') + ': ' + url); |
4354 |
13 Feb 17 |
nicklas |
if (postdata) App.debug(postdata); |
4354 |
13 Feb 17 |
nicklas |
55 |
} |
4354 |
13 Feb 17 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
4354 |
13 Feb 17 |
nicklas |
request.jsonCallback = callback; |
4354 |
13 Feb 17 |
nicklas |
request.errorCallback = errorCallback; |
4354 |
13 Feb 17 |
nicklas |
request.open(method || 'GET', url, true); |
4354 |
13 Feb 17 |
nicklas |
// Firefox only adds request header with needed "boundary" info, if request header is not set explicitly |
4354 |
13 Feb 17 |
nicklas |
if (postdata && !(postdata instanceof FormData)) |
4354 |
13 Feb 17 |
nicklas |
62 |
{ |
4354 |
13 Feb 17 |
nicklas |
request.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); |
4354 |
13 Feb 17 |
nicklas |
64 |
} |
4354 |
13 Feb 17 |
nicklas |
Ajax.setReadyStateHandler(request, internal.asyncCallbackWrapper, internal.asyncCallbackWrapper); |
4354 |
13 Feb 17 |
nicklas |
numLiveAsyncRequests++; |
4354 |
13 Feb 17 |
nicklas |
request.send(postdata || null); |
4354 |
13 Feb 17 |
nicklas |
68 |
} |
4354 |
13 Feb 17 |
nicklas |
69 |
|
4354 |
13 Feb 17 |
nicklas |
70 |
/** |
4354 |
13 Feb 17 |
nicklas |
Callback wrapper for ansynchronous requests. |
4354 |
13 Feb 17 |
nicklas |
72 |
*/ |
4354 |
13 Feb 17 |
nicklas |
internal.asyncCallbackWrapper = function(request) |
4354 |
13 Feb 17 |
nicklas |
74 |
{ |
4354 |
13 Feb 17 |
nicklas |
numLiveAsyncRequests--; |
4354 |
13 Feb 17 |
nicklas |
if (debug) App.debug(request.responseText); |
4354 |
13 Feb 17 |
nicklas |
if (!hasFatalError) Wizard.hideWizardStatus(); |
4354 |
13 Feb 17 |
nicklas |
78 |
|
4354 |
13 Feb 17 |
nicklas |
var response = null; |
4354 |
13 Feb 17 |
nicklas |
var messages = null; |
4354 |
13 Feb 17 |
nicklas |
try |
4354 |
13 Feb 17 |
nicklas |
82 |
{ |
4354 |
13 Feb 17 |
nicklas |
if (request.status != 200) |
4354 |
13 Feb 17 |
nicklas |
84 |
{ |
4354 |
13 Feb 17 |
nicklas |
throw new Error(request.responseText); |
4354 |
13 Feb 17 |
nicklas |
86 |
} |
4354 |
13 Feb 17 |
nicklas |
else |
4354 |
13 Feb 17 |
nicklas |
88 |
{ |
4354 |
13 Feb 17 |
nicklas |
if (request.getResponseHeader('Content-Type').indexOf('json') != -1) |
4354 |
13 Feb 17 |
nicklas |
90 |
{ |
4354 |
13 Feb 17 |
nicklas |
response = JSON.parse(request.responseText); |
4354 |
13 Feb 17 |
nicklas |
messages = response.messages; |
4354 |
13 Feb 17 |
nicklas |
if (response.status != 'ok') |
4354 |
13 Feb 17 |
nicklas |
94 |
{ |
4354 |
13 Feb 17 |
nicklas |
throw new Error(response.message || response.stacktrace); |
4354 |
13 Feb 17 |
nicklas |
96 |
} |
4354 |
13 Feb 17 |
nicklas |
97 |
} |
4354 |
13 Feb 17 |
nicklas |
else |
4354 |
13 Feb 17 |
nicklas |
99 |
{ |
4354 |
13 Feb 17 |
nicklas |
response = request.responseText; |
4354 |
13 Feb 17 |
nicklas |
101 |
} |
4354 |
13 Feb 17 |
nicklas |
if (request.jsonCallback && request.jsonCallback.call) |
4354 |
13 Feb 17 |
nicklas |
103 |
{ |
4354 |
13 Feb 17 |
nicklas |
request.jsonCallback.call(null, response); |
4354 |
13 Feb 17 |
nicklas |
105 |
} |
4354 |
13 Feb 17 |
nicklas |
106 |
} |
4354 |
13 Feb 17 |
nicklas |
107 |
} |
4354 |
13 Feb 17 |
nicklas |
catch (err) |
4354 |
13 Feb 17 |
nicklas |
109 |
{ |
4354 |
13 Feb 17 |
nicklas |
if (request.errorCallback && request.errorCallback.call) |
4354 |
13 Feb 17 |
nicklas |
111 |
{ |
4354 |
13 Feb 17 |
nicklas |
request.errorCallback.call(null, err, response); |
4354 |
13 Feb 17 |
nicklas |
113 |
} |
4354 |
13 Feb 17 |
nicklas |
else |
4354 |
13 Feb 17 |
nicklas |
115 |
{ |
4354 |
13 Feb 17 |
nicklas |
Wizard.setFatalError(err, messages); |
4354 |
13 Feb 17 |
nicklas |
117 |
} |
4354 |
13 Feb 17 |
nicklas |
118 |
} |
4354 |
13 Feb 17 |
nicklas |
119 |
} |
4631 |
21 Nov 17 |
nicklas |
120 |
|
4631 |
21 Nov 17 |
nicklas |
wizard.isValid = function(element) |
4631 |
21 Nov 17 |
nicklas |
122 |
{ |
4631 |
21 Nov 17 |
nicklas |
return Data.int(element, 'valid', 1); |
4631 |
21 Nov 17 |
nicklas |
124 |
} |
4354 |
13 Feb 17 |
nicklas |
125 |
|
4631 |
21 Nov 17 |
nicklas |
wizard.initFileSelectionField = function(element) |
4631 |
21 Nov 17 |
nicklas |
127 |
{ |
4631 |
21 Nov 17 |
nicklas |
element = Doc.element(element); |
4631 |
21 Nov 17 |
nicklas |
Events.addEventHandler(element, 'change', wizard.fileChanged); |
4631 |
21 Nov 17 |
nicklas |
Events.sendChangeEvent(element); |
4631 |
21 Nov 17 |
nicklas |
131 |
} |
4354 |
13 Feb 17 |
nicklas |
132 |
|
4631 |
21 Nov 17 |
nicklas |
wizard.fileChanged = function(event) |
4631 |
21 Nov 17 |
nicklas |
134 |
{ |
4631 |
21 Nov 17 |
nicklas |
var target = event.currentTarget; |
4631 |
21 Nov 17 |
nicklas |
136 |
|
4631 |
21 Nov 17 |
nicklas |
var isValid = false; |
4631 |
21 Nov 17 |
nicklas |
var isWarning = false; |
4631 |
21 Nov 17 |
nicklas |
139 |
|
4631 |
21 Nov 17 |
nicklas |
// Reset current status |
4631 |
21 Nov 17 |
nicklas |
wizard.setInputStatus(target); |
4631 |
21 Nov 17 |
nicklas |
142 |
|
4631 |
21 Nov 17 |
nicklas |
var path = target.value; |
4631 |
21 Nov 17 |
nicklas |
if (path == '') |
4631 |
21 Nov 17 |
nicklas |
145 |
{ |
4631 |
21 Nov 17 |
nicklas |
// No file, is this an error or a warning? |
4631 |
21 Nov 17 |
nicklas |
var optional = target.className.indexOf('required') == -1; |
4631 |
21 Nov 17 |
nicklas |
wizard.setInputStatus(target, optional ? 'warning' : 'invalid', 'Missing'); |
4631 |
21 Nov 17 |
nicklas |
isValid = optional; |
4631 |
21 Nov 17 |
nicklas |
isWarning = optional; |
4631 |
21 Nov 17 |
nicklas |
151 |
} |
4631 |
21 Nov 17 |
nicklas |
else |
4631 |
21 Nov 17 |
nicklas |
153 |
{ |
4631 |
21 Nov 17 |
nicklas |
Wizard.setInputStatus(target, 'valid'); |
4631 |
21 Nov 17 |
nicklas |
isValid = true; |
4631 |
21 Nov 17 |
nicklas |
156 |
} |
4631 |
21 Nov 17 |
nicklas |
157 |
|
4631 |
21 Nov 17 |
nicklas |
Data.set(target, 'valid', isValid ? 1 : 0); |
4631 |
21 Nov 17 |
nicklas |
Data.set(target, 'warning', isWarning ? 1 : 0); |
4631 |
21 Nov 17 |
nicklas |
160 |
|
4631 |
21 Nov 17 |
nicklas |
if (!isValid && target.focus) target.focus(); |
4631 |
21 Nov 17 |
nicklas |
162 |
} |
4631 |
21 Nov 17 |
nicklas |
163 |
|
4354 |
13 Feb 17 |
nicklas |
164 |
/** |
4631 |
21 Nov 17 |
nicklas |
Change display status for an input field. |
4631 |
21 Nov 17 |
nicklas |
@param prefix ID prefix to locate tags |
4631 |
21 Nov 17 |
nicklas |
@param clazz The message clazz (valid, invalid, warning) or empty |
4631 |
21 Nov 17 |
nicklas |
@param message The message (may be empty) |
4631 |
21 Nov 17 |
nicklas |
169 |
*/ |
4631 |
21 Nov 17 |
nicklas |
wizard.setInputStatus = function(prefix, clazz, message) |
4631 |
21 Nov 17 |
nicklas |
171 |
{ |
4631 |
21 Nov 17 |
nicklas |
if (prefix.id) prefix = prefix.id; |
4631 |
21 Nov 17 |
nicklas |
173 |
|
4631 |
21 Nov 17 |
nicklas |
var statusTag = Doc.element(prefix + '.status'); |
4631 |
21 Nov 17 |
nicklas |
175 |
|
4631 |
21 Nov 17 |
nicklas |
if (statusTag) |
4631 |
21 Nov 17 |
nicklas |
177 |
{ |
4631 |
21 Nov 17 |
nicklas |
statusTag.className = 'status ' + (clazz || ''); |
4631 |
21 Nov 17 |
nicklas |
var trTag = statusTag.parentNode; |
4631 |
21 Nov 17 |
nicklas |
var trClass = Data.get(trTag, 'original-class'); |
4631 |
21 Nov 17 |
nicklas |
if (!trClass) |
4631 |
21 Nov 17 |
nicklas |
182 |
{ |
4631 |
21 Nov 17 |
nicklas |
trClass = trTag.className || 'foo'; |
4631 |
21 Nov 17 |
nicklas |
Data.set(trTag, 'original-class', trClass); |
4631 |
21 Nov 17 |
nicklas |
185 |
} |
4631 |
21 Nov 17 |
nicklas |
trTag.className = trClass + ' ' + (clazz || ''); |
4631 |
21 Nov 17 |
nicklas |
187 |
} |
4631 |
21 Nov 17 |
nicklas |
188 |
|
4631 |
21 Nov 17 |
nicklas |
var msgTag = Doc.element(prefix + '.message'); |
4631 |
21 Nov 17 |
nicklas |
if (msgTag) |
4631 |
21 Nov 17 |
nicklas |
191 |
{ |
4631 |
21 Nov 17 |
nicklas |
if (message) |
4631 |
21 Nov 17 |
nicklas |
193 |
{ |
4631 |
21 Nov 17 |
nicklas |
msgTag.innerHTML = message; |
4631 |
21 Nov 17 |
nicklas |
Doc.show(msgTag, Data.get(msgTag, 'display', 'inline')); |
4631 |
21 Nov 17 |
nicklas |
196 |
} |
4631 |
21 Nov 17 |
nicklas |
else |
4631 |
21 Nov 17 |
nicklas |
198 |
{ |
4631 |
21 Nov 17 |
nicklas |
msgTag.innerHTML = message; |
4631 |
21 Nov 17 |
nicklas |
Doc.hide(msgTag); |
4631 |
21 Nov 17 |
nicklas |
201 |
} |
4631 |
21 Nov 17 |
nicklas |
202 |
} |
4631 |
21 Nov 17 |
nicklas |
else if (statusTag) |
4631 |
21 Nov 17 |
nicklas |
204 |
{ |
4631 |
21 Nov 17 |
nicklas |
statusTag.title = message || ''; |
4631 |
21 Nov 17 |
nicklas |
206 |
} |
4631 |
21 Nov 17 |
nicklas |
207 |
} |
4631 |
21 Nov 17 |
nicklas |
208 |
|
4631 |
21 Nov 17 |
nicklas |
209 |
/** |
4631 |
21 Nov 17 |
nicklas |
Event handler for input fields, that go to the |
4631 |
21 Nov 17 |
nicklas |
next wizard step if TAB or ENTER key is pressed. |
4631 |
21 Nov 17 |
nicklas |
A short delay is used to allow other event handler |
4631 |
21 Nov 17 |
nicklas |
to run first (eg. for validation). |
4631 |
21 Nov 17 |
nicklas |
214 |
*/ |
4631 |
21 Nov 17 |
nicklas |
wizard.goNextOnTabOrEnter = function(event) |
4631 |
21 Nov 17 |
nicklas |
216 |
{ |
4631 |
21 Nov 17 |
nicklas |
if (event.keyCode == 9 || event.keyCode == 13) |
4631 |
21 Nov 17 |
nicklas |
218 |
{ |
4631 |
21 Nov 17 |
nicklas |
setTimeout(function() { wizard.goNext(true) }, 200); |
4631 |
21 Nov 17 |
nicklas |
220 |
} |
4631 |
21 Nov 17 |
nicklas |
221 |
} |
4631 |
21 Nov 17 |
nicklas |
222 |
|
4631 |
21 Nov 17 |
nicklas |
223 |
/** |
4631 |
21 Nov 17 |
nicklas |
Event handler for input fields, that go to the |
4631 |
21 Nov 17 |
nicklas |
next wizard step if TAB key is pressed. |
4631 |
21 Nov 17 |
nicklas |
A short delay is used to allow other event handler |
4631 |
21 Nov 17 |
nicklas |
to run first (eg. for validation). |
4631 |
21 Nov 17 |
nicklas |
228 |
*/ |
4631 |
21 Nov 17 |
nicklas |
wizard.goNextOnTab = function(event) |
4631 |
21 Nov 17 |
nicklas |
230 |
{ |
4631 |
21 Nov 17 |
nicklas |
if (event.keyCode == 9) |
4631 |
21 Nov 17 |
nicklas |
232 |
{ |
4631 |
21 Nov 17 |
nicklas |
setTimeout(function() { wizard.goNext(true) }, 200); |
4631 |
21 Nov 17 |
nicklas |
234 |
} |
4631 |
21 Nov 17 |
nicklas |
235 |
} |
4631 |
21 Nov 17 |
nicklas |
236 |
|
4631 |
21 Nov 17 |
nicklas |
237 |
/** |
4631 |
21 Nov 17 |
nicklas |
Event handler for input fields, that changes |
4631 |
21 Nov 17 |
nicklas |
focus to the next element. The next element |
4631 |
21 Nov 17 |
nicklas |
should be defined by 'data-next-focus' attribute. |
4631 |
21 Nov 17 |
nicklas |
It is recommended that this is consisistent with TAB. |
4631 |
21 Nov 17 |
nicklas |
242 |
*/ |
4631 |
21 Nov 17 |
nicklas |
wizard.focusOnEnter = function(event) |
4631 |
21 Nov 17 |
nicklas |
244 |
{ |
4631 |
21 Nov 17 |
nicklas |
if (event.keyCode == 13) |
4631 |
21 Nov 17 |
nicklas |
246 |
{ |
4631 |
21 Nov 17 |
nicklas |
var nextFocus = Doc.element(Data.get(event.currentTarget, 'next-focus')); |
4631 |
21 Nov 17 |
nicklas |
if (nextFocus && nextFocus.focus) nextFocus.focus(); |
4631 |
21 Nov 17 |
nicklas |
249 |
} |
4631 |
21 Nov 17 |
nicklas |
250 |
} |
4631 |
21 Nov 17 |
nicklas |
251 |
|
4631 |
21 Nov 17 |
nicklas |
// Event handler for the 'Next' navigation button |
4631 |
21 Nov 17 |
nicklas |
wizard.goNextOnClick = function(event) |
4631 |
21 Nov 17 |
nicklas |
254 |
{ |
4631 |
21 Nov 17 |
nicklas |
wizard.goNext(false); |
4631 |
21 Nov 17 |
nicklas |
256 |
} |
4631 |
21 Nov 17 |
nicklas |
257 |
|
4631 |
21 Nov 17 |
nicklas |
258 |
/** |
4631 |
21 Nov 17 |
nicklas |
Go to the next step in the wizard. This method will first |
4631 |
21 Nov 17 |
nicklas |
submit 'wizard-validate' event to the current step. If at |
4631 |
21 Nov 17 |
nicklas |
least one event handler calls 'Event.preventDefault()' the |
4631 |
21 Nov 17 |
nicklas |
processing is aborted. |
4631 |
21 Nov 17 |
nicklas |
263 |
|
4631 |
21 Nov 17 |
nicklas |
Otherwise, the current step is disabled and the 'wizard-initialize' |
4631 |
21 Nov 17 |
nicklas |
event is sent to the next step. The event handler is responsible |
4631 |
21 Nov 17 |
nicklas |
for calling 'Wizard.setCurrentStep' to display the next step. |
4631 |
21 Nov 17 |
nicklas |
267 |
*/ |
4631 |
21 Nov 17 |
nicklas |
wizard.goNext = function(auto) |
4631 |
21 Nov 17 |
nicklas |
269 |
{ |
4631 |
21 Nov 17 |
nicklas |
var verify = Doc.element('verifyGoNext'); |
4631 |
21 Nov 17 |
nicklas |
if (verify && !verify.checked) return; |
4631 |
21 Nov 17 |
nicklas |
272 |
|
4631 |
21 Nov 17 |
nicklas |
var details = { 'auto': auto }; |
4631 |
21 Nov 17 |
nicklas |
274 |
|
4631 |
21 Nov 17 |
nicklas |
// Send 'wizard-validate' event to current step |
4631 |
21 Nov 17 |
nicklas |
var step = Doc.element('step-'+currentStep); |
4631 |
21 Nov 17 |
nicklas |
var evt = document.createEvent('CustomEvent'); |
4631 |
21 Nov 17 |
nicklas |
evt.initCustomEvent('wizard-validate', true, true, details); |
4631 |
21 Nov 17 |
nicklas |
if (!step.dispatchEvent(evt)) |
4631 |
21 Nov 17 |
nicklas |
280 |
{ |
4631 |
21 Nov 17 |
nicklas |
wizard.notifyError(); |
4631 |
21 Nov 17 |
nicklas |
return; |
4631 |
21 Nov 17 |
nicklas |
283 |
} |
4631 |
21 Nov 17 |
nicklas |
284 |
|
4631 |
21 Nov 17 |
nicklas |
// Hide all navigation buttons and disable form controls in current step |
4631 |
21 Nov 17 |
nicklas |
internal.hideButtons('navigation'); |
4631 |
21 Nov 17 |
nicklas |
internal.disableStep(step); |
4631 |
21 Nov 17 |
nicklas |
288 |
|
4631 |
21 Nov 17 |
nicklas |
// Send 'wizard-initialize' to the next step |
4631 |
21 Nov 17 |
nicklas |
var nextStep = Doc.element('step-'+(currentStep+1)); |
4631 |
21 Nov 17 |
nicklas |
var evt = document.createEvent('CustomEvent'); |
4631 |
21 Nov 17 |
nicklas |
evt.initCustomEvent('wizard-initialize', true, true, details); |
4631 |
21 Nov 17 |
nicklas |
nextStep.dispatchEvent(evt); |
4631 |
21 Nov 17 |
nicklas |
294 |
} |
4631 |
21 Nov 17 |
nicklas |
295 |
|
4631 |
21 Nov 17 |
nicklas |
wizard.notifyError = function() |
4631 |
21 Nov 17 |
nicklas |
297 |
{ |
4631 |
21 Nov 17 |
nicklas |
Doc.addClass('wizard', 'flash-error'); |
4631 |
21 Nov 17 |
nicklas |
setTimeout(internal.stopFlashing, 2000); |
4631 |
21 Nov 17 |
nicklas |
300 |
} |
4631 |
21 Nov 17 |
nicklas |
301 |
|
4631 |
21 Nov 17 |
nicklas |
internal.stopFlashing = function() |
4631 |
21 Nov 17 |
nicklas |
303 |
{ |
4631 |
21 Nov 17 |
nicklas |
Doc.removeClass('wizard', 'flash-error'); |
4631 |
21 Nov 17 |
nicklas |
305 |
} |
4631 |
21 Nov 17 |
nicklas |
306 |
|
4631 |
21 Nov 17 |
nicklas |
307 |
/** |
4631 |
21 Nov 17 |
nicklas |
Finalize the registration of the wizard. This method will |
4631 |
21 Nov 17 |
nicklas |
first submit 'wizard-validate' to the current step. If at |
4631 |
21 Nov 17 |
nicklas |
least one event handler calls 'Event.preventDefault()' the |
4631 |
21 Nov 17 |
nicklas |
processing is aborted. |
4631 |
21 Nov 17 |
nicklas |
312 |
|
4631 |
21 Nov 17 |
nicklas |
Otherwise, the current step is disabled and the 'wizard-submit' |
4631 |
21 Nov 17 |
nicklas |
event is sent to the 'wizard'. The event handler is responsible |
4631 |
21 Nov 17 |
nicklas |
for finalizing the registration and displaying a proper |
4631 |
21 Nov 17 |
nicklas |
message, for example, by calling Wizard.showFinalMessage() |
4631 |
21 Nov 17 |
nicklas |
317 |
|
4631 |
21 Nov 17 |
nicklas |
The 'data' is passed on to the 'wizard-validate' and |
4631 |
21 Nov 17 |
nicklas |
'wizard-submit' events as the Event.details object. |
4631 |
21 Nov 17 |
nicklas |
320 |
*/ |
4631 |
21 Nov 17 |
nicklas |
wizard.goRegister = function(data) |
4631 |
21 Nov 17 |
nicklas |
322 |
{ |
4631 |
21 Nov 17 |
nicklas |
// Check if verification is enabled |
4631 |
21 Nov 17 |
nicklas |
var verify = Doc.element('verifyGoNext'); |
4631 |
21 Nov 17 |
nicklas |
if (verify && !verify.checked) return; |
4631 |
21 Nov 17 |
nicklas |
326 |
|
4631 |
21 Nov 17 |
nicklas |
// Send 'wizard-validate' event to current step |
4631 |
21 Nov 17 |
nicklas |
var step = Doc.element('step-'+currentStep); |
4631 |
21 Nov 17 |
nicklas |
var evt = document.createEvent('CustomEvent'); |
4631 |
21 Nov 17 |
nicklas |
evt.initCustomEvent('wizard-validate', true, true, data); |
4631 |
21 Nov 17 |
nicklas |
if (!step.dispatchEvent(evt)) |
4631 |
21 Nov 17 |
nicklas |
332 |
{ |
4631 |
21 Nov 17 |
nicklas |
wizard.notifyError(); |
4631 |
21 Nov 17 |
nicklas |
return; |
4631 |
21 Nov 17 |
nicklas |
335 |
} |
4631 |
21 Nov 17 |
nicklas |
336 |
|
4631 |
21 Nov 17 |
nicklas |
internal.hideButtons('navigation'); |
4631 |
21 Nov 17 |
nicklas |
internal.disableStep(step); |
4631 |
21 Nov 17 |
nicklas |
339 |
|
4631 |
21 Nov 17 |
nicklas |
// Send 'wizard-submit' to the next step |
4631 |
21 Nov 17 |
nicklas |
var wiz = Doc.element('wizard'); |
4631 |
21 Nov 17 |
nicklas |
hasSentRegistration = true; |
4631 |
21 Nov 17 |
nicklas |
var evt = document.createEvent('CustomEvent'); |
4631 |
21 Nov 17 |
nicklas |
evt.initCustomEvent('wizard-submit', true, true, data); |
4631 |
21 Nov 17 |
nicklas |
wiz.dispatchEvent(evt); |
4631 |
21 Nov 17 |
nicklas |
346 |
} |
4631 |
21 Nov 17 |
nicklas |
347 |
|
4631 |
21 Nov 17 |
nicklas |
wizard.setNoConfirmOnFirstStep = function(cf) |
4631 |
21 Nov 17 |
nicklas |
349 |
{ |
4631 |
21 Nov 17 |
nicklas |
noConfirmOnFirstStep = cf; |
4631 |
21 Nov 17 |
nicklas |
351 |
} |
4631 |
21 Nov 17 |
nicklas |
352 |
|
4631 |
21 Nov 17 |
nicklas |
// Ask the user for confirmation and then restart the wizard |
4631 |
21 Nov 17 |
nicklas |
wizard.cancelWizard = function() |
4631 |
21 Nov 17 |
nicklas |
355 |
{ |
4631 |
21 Nov 17 |
nicklas |
forceConfirm = true; |
4631 |
21 Nov 17 |
nicklas |
wizard.restartWizard(); |
4631 |
21 Nov 17 |
nicklas |
358 |
} |
4631 |
21 Nov 17 |
nicklas |
359 |
|
4631 |
21 Nov 17 |
nicklas |
// Restart the wizard without asking the user for confirmation |
4631 |
21 Nov 17 |
nicklas |
wizard.restartWizard = function() |
4631 |
21 Nov 17 |
nicklas |
362 |
{ |
4631 |
21 Nov 17 |
nicklas |
var url = location.href; |
4631 |
21 Nov 17 |
nicklas |
if (url.indexOf('&restart=1') == -1) url += '&restart=1'; |
4631 |
21 Nov 17 |
nicklas |
location.href = url; |
4631 |
21 Nov 17 |
nicklas |
366 |
} |
4631 |
21 Nov 17 |
nicklas |
367 |
|
4631 |
21 Nov 17 |
nicklas |
wizard.setCurrentStep = function(stepNo) |
4631 |
21 Nov 17 |
nicklas |
369 |
{ |
4631 |
21 Nov 17 |
nicklas |
currentStep = stepNo; |
4631 |
21 Nov 17 |
nicklas |
internal.enableStep(Doc.element('step-'+currentStep)); |
4631 |
21 Nov 17 |
nicklas |
372 |
} |
4631 |
21 Nov 17 |
nicklas |
373 |
|
4631 |
21 Nov 17 |
nicklas |
internal.disableStep = function(step) |
4631 |
21 Nov 17 |
nicklas |
375 |
{ |
4631 |
21 Nov 17 |
nicklas |
step = Doc.element(step); |
4631 |
21 Nov 17 |
nicklas |
internal.disableAllFormElements(step); |
4631 |
21 Nov 17 |
nicklas |
Doc.addClass(step, 'disabled'); |
4631 |
21 Nov 17 |
nicklas |
Doc.hide('gonext-message'); |
4631 |
21 Nov 17 |
nicklas |
var stepNo = step.getElementsByClassName('step-no')[0]; |
4631 |
21 Nov 17 |
nicklas |
Events.addEventHandler(stepNo, 'click', internal.togglePastStep, {'step-id': step.id}); |
4631 |
21 Nov 17 |
nicklas |
stepNo.title = 'Show/hide this section'; |
4631 |
21 Nov 17 |
nicklas |
383 |
} |
4631 |
21 Nov 17 |
nicklas |
384 |
|
4631 |
21 Nov 17 |
nicklas |
internal.enableStep = function(step) |
4631 |
21 Nov 17 |
nicklas |
386 |
{ |
4631 |
21 Nov 17 |
nicklas |
step = Doc.element(step); |
4631 |
21 Nov 17 |
nicklas |
Doc.removeClass(step, 'disabled'); |
4631 |
21 Nov 17 |
nicklas |
Doc.show(step); |
4631 |
21 Nov 17 |
nicklas |
390 |
} |
4631 |
21 Nov 17 |
nicklas |
391 |
|
4631 |
21 Nov 17 |
nicklas |
// Toggle visibility of a past step |
4631 |
21 Nov 17 |
nicklas |
// The step is hidden if the 'auto-hide' class is present |
4631 |
21 Nov 17 |
nicklas |
internal.togglePastStep = function(event) |
4631 |
21 Nov 17 |
nicklas |
395 |
{ |
4631 |
21 Nov 17 |
nicklas |
var step = Data.get(event.currentTarget, 'step-id'); |
4631 |
21 Nov 17 |
nicklas |
Doc.addOrRemoveClass(step, 'auto-hide'); |
4631 |
21 Nov 17 |
nicklas |
398 |
} |
4631 |
21 Nov 17 |
nicklas |
399 |
|
4631 |
21 Nov 17 |
nicklas |
400 |
|
4631 |
21 Nov 17 |
nicklas |
401 |
/** |
4354 |
13 Feb 17 |
nicklas |
A fatal error has occurred and the wizard will not be able to continue. |
4354 |
13 Feb 17 |
nicklas |
This method will display the error message, disable all form input fields |
4354 |
13 Feb 17 |
nicklas |
and buttons (except the 'Restart' button). |
4354 |
13 Feb 17 |
nicklas |
405 |
*/ |
4354 |
13 Feb 17 |
nicklas |
wizard.setFatalError = function(err, messages) |
4354 |
13 Feb 17 |
nicklas |
407 |
{ |
4354 |
13 Feb 17 |
nicklas |
hasFatalError = true; |
4354 |
13 Feb 17 |
nicklas |
var msg = err; |
4354 |
13 Feb 17 |
nicklas |
if (err.toString) |
4354 |
13 Feb 17 |
nicklas |
411 |
{ |
4354 |
13 Feb 17 |
nicklas |
App.debug(err.toString()); |
4354 |
13 Feb 17 |
nicklas |
msg = Strings.encodeTags(err.toString()); |
4354 |
13 Feb 17 |
nicklas |
if (err.stack && !messages) |
4354 |
13 Feb 17 |
nicklas |
415 |
{ |
4354 |
13 Feb 17 |
nicklas |
App.debug(err.stack); |
4354 |
13 Feb 17 |
nicklas |
msg += '<br><pre>'+Strings.encodeTags(err.stack)+'</pre>'; |
4354 |
13 Feb 17 |
nicklas |
418 |
} |
4354 |
13 Feb 17 |
nicklas |
419 |
} |
4354 |
13 Feb 17 |
nicklas |
else |
4354 |
13 Feb 17 |
nicklas |
421 |
{ |
4354 |
13 Feb 17 |
nicklas |
App.debug(msg); |
4354 |
13 Feb 17 |
nicklas |
423 |
} |
4354 |
13 Feb 17 |
nicklas |
424 |
|
4354 |
13 Feb 17 |
nicklas |
if (messages) |
4354 |
13 Feb 17 |
nicklas |
426 |
{ |
4354 |
13 Feb 17 |
nicklas |
msg = '<div class="messagecontainer error">'+msg+'</div>'+internal.generateMessageList(messages).html; |
4354 |
13 Feb 17 |
nicklas |
wizard.setWizardStatus('success', msg); |
4354 |
13 Feb 17 |
nicklas |
429 |
} |
4354 |
13 Feb 17 |
nicklas |
else |
4354 |
13 Feb 17 |
nicklas |
431 |
{ |
4354 |
13 Feb 17 |
nicklas |
wizard.setWizardStatus('messagecontainer error', msg || 'Unexpected failure!'); |
4354 |
13 Feb 17 |
nicklas |
433 |
} |
4354 |
13 Feb 17 |
nicklas |
434 |
|
4354 |
13 Feb 17 |
nicklas |
Doc.addClass('wizard', 'disabled'); |
4354 |
13 Feb 17 |
nicklas |
internal.disableAllFormElements('wizard', true); |
4354 |
13 Feb 17 |
nicklas |
Doc.show('gorestart'); |
4354 |
13 Feb 17 |
nicklas |
438 |
} |
4354 |
13 Feb 17 |
nicklas |
439 |
|
4354 |
13 Feb 17 |
nicklas |
440 |
|
4354 |
13 Feb 17 |
nicklas |
441 |
/** |
4354 |
13 Feb 17 |
nicklas |
Display a 'loading' global wizard-status message. |
4354 |
13 Feb 17 |
nicklas |
The 'progress' parameter is optional. If given, |
4354 |
13 Feb 17 |
nicklas |
it should be the name of a progress reporter. |
4354 |
13 Feb 17 |
nicklas |
This activates the display of a progress bar which |
4476 |
28 Apr 17 |
nicklas |
Relax will update at regular intervals in the background. |
4354 |
13 Feb 17 |
nicklas |
See SessionServlet (cmd=GetProgress) for more information. |
4354 |
13 Feb 17 |
nicklas |
448 |
*/ |
4354 |
13 Feb 17 |
nicklas |
wizard.showLoadingAnimation = function(msg, progress) |
4354 |
13 Feb 17 |
nicklas |
450 |
{ |
4354 |
13 Feb 17 |
nicklas |
wizard.setWizardStatus('loading', msg || 'Working, please wait...'); |
4631 |
21 Nov 17 |
nicklas |
if (progress) |
4631 |
21 Nov 17 |
nicklas |
453 |
{ |
4631 |
21 Nov 17 |
nicklas |
var progressBar = Doc.element('wizard-progress'); |
4631 |
21 Nov 17 |
nicklas |
progressBar.classList.add('progress-bar'); |
4631 |
21 Nov 17 |
nicklas |
456 |
|
4631 |
21 Nov 17 |
nicklas |
// Get/create child elements |
4631 |
21 Nov 17 |
nicklas |
var done = Doc.element('wizard-progress-done'); |
4631 |
21 Nov 17 |
nicklas |
if (!done) |
4631 |
21 Nov 17 |
nicklas |
460 |
{ |
4631 |
21 Nov 17 |
nicklas |
done = document.createElement('span'); |
4631 |
21 Nov 17 |
nicklas |
done.id = 'wizard-progress-done'; |
4631 |
21 Nov 17 |
nicklas |
done.className = 'progress-bar-done bg-filled-100 topborder bottomborder leftborder'; |
4631 |
21 Nov 17 |
nicklas |
progressBar.appendChild(done); |
4631 |
21 Nov 17 |
nicklas |
465 |
} |
4631 |
21 Nov 17 |
nicklas |
var remain = Doc.element('wizard-progress-remain'); |
4631 |
21 Nov 17 |
nicklas |
if (!remain) |
4631 |
21 Nov 17 |
nicklas |
468 |
{ |
4631 |
21 Nov 17 |
nicklas |
remain = document.createElement('span'); |
4631 |
21 Nov 17 |
nicklas |
remain.id = 'wizard-progress-remain'; |
4631 |
21 Nov 17 |
nicklas |
remain.className = 'progress-bar-remain topborder bottomborder rightborder'; |
4631 |
21 Nov 17 |
nicklas |
progressBar.appendChild(remain); |
4631 |
21 Nov 17 |
nicklas |
473 |
} |
4631 |
21 Nov 17 |
nicklas |
474 |
|
4631 |
21 Nov 17 |
nicklas |
progressBar.setAttribute('value', '0%'); |
4631 |
21 Nov 17 |
nicklas |
done.style.width = '0%'; |
4631 |
21 Nov 17 |
nicklas |
remain.style.width = '100%'; |
4631 |
21 Nov 17 |
nicklas |
Doc.show(progressBar); |
4631 |
21 Nov 17 |
nicklas |
479 |
|
4631 |
21 Nov 17 |
nicklas |
// Initial request for updating the progress bar |
4631 |
21 Nov 17 |
nicklas |
progressTimer = setTimeout(internal.requestProgressUpdate, 1500, progress); |
4631 |
21 Nov 17 |
nicklas |
482 |
} |
4354 |
13 Feb 17 |
nicklas |
483 |
} |
4354 |
13 Feb 17 |
nicklas |
484 |
|
4631 |
21 Nov 17 |
nicklas |
485 |
/** |
4631 |
21 Nov 17 |
nicklas |
Make a request for the progress information. The 'progress' |
4631 |
21 Nov 17 |
nicklas |
parameter is the name of a progress bar. |
4631 |
21 Nov 17 |
nicklas |
488 |
*/ |
4631 |
21 Nov 17 |
nicklas |
internal.requestProgressUpdate = function(progress) |
4631 |
21 Nov 17 |
nicklas |
490 |
{ |
4631 |
21 Nov 17 |
nicklas |
if (hasFatalError) return; |
4631 |
21 Nov 17 |
nicklas |
var url = '../Session.servlet?ID='+App.getSessionId(); |
4631 |
21 Nov 17 |
nicklas |
url += '&cmd=GetProgress'; |
4631 |
21 Nov 17 |
nicklas |
url += '&name='+encodeURIComponent(progress); |
4631 |
21 Nov 17 |
nicklas |
495 |
|
4631 |
21 Nov 17 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
4631 |
21 Nov 17 |
nicklas |
request.open("GET", url, true); |
4631 |
21 Nov 17 |
nicklas |
Ajax.setReadyStateHandler(request, internal.onProgressReport, internal.onProgressReport); |
4631 |
21 Nov 17 |
nicklas |
request.send(null); |
4631 |
21 Nov 17 |
nicklas |
500 |
} |
4631 |
21 Nov 17 |
nicklas |
501 |
|
4631 |
21 Nov 17 |
nicklas |
502 |
/** |
4631 |
21 Nov 17 |
nicklas |
Callback when receiving a progress update. |
4631 |
21 Nov 17 |
nicklas |
504 |
*/ |
4631 |
21 Nov 17 |
nicklas |
internal.onProgressReport = function(request) |
4631 |
21 Nov 17 |
nicklas |
506 |
{ |
4631 |
21 Nov 17 |
nicklas |
if (hasFatalError) return; |
4631 |
21 Nov 17 |
nicklas |
if (debug) App.debug(Strings.encodeTags(request.responseText)); |
4631 |
21 Nov 17 |
nicklas |
var response; |
4631 |
21 Nov 17 |
nicklas |
var error = false; |
4631 |
21 Nov 17 |
nicklas |
try |
4631 |
21 Nov 17 |
nicklas |
512 |
{ |
4631 |
21 Nov 17 |
nicklas |
response = JSON.parse(request.responseText); |
4631 |
21 Nov 17 |
nicklas |
if (response.status != 'ok') |
4631 |
21 Nov 17 |
nicklas |
515 |
{ |
4631 |
21 Nov 17 |
nicklas |
error = response.message || response.stacktrace || 'Unexpected error'; |
4631 |
21 Nov 17 |
nicklas |
517 |
} |
4631 |
21 Nov 17 |
nicklas |
518 |
} |
4631 |
21 Nov 17 |
nicklas |
catch (ex) |
4631 |
21 Nov 17 |
nicklas |
520 |
{ |
4631 |
21 Nov 17 |
nicklas |
error = ex; |
4631 |
21 Nov 17 |
nicklas |
522 |
} |
4631 |
21 Nov 17 |
nicklas |
523 |
|
4631 |
21 Nov 17 |
nicklas |
if (error) |
4631 |
21 Nov 17 |
nicklas |
525 |
{ |
4631 |
21 Nov 17 |
nicklas |
return; |
4631 |
21 Nov 17 |
nicklas |
527 |
} |
4631 |
21 Nov 17 |
nicklas |
528 |
|
4631 |
21 Nov 17 |
nicklas |
var progress = response.progress; |
4631 |
21 Nov 17 |
nicklas |
var progressBar = Doc.element('wizard-progress'); |
4631 |
21 Nov 17 |
nicklas |
531 |
|
4631 |
21 Nov 17 |
nicklas |
if (!progress) |
4631 |
21 Nov 17 |
nicklas |
533 |
{ |
4631 |
21 Nov 17 |
nicklas |
// Give up if no progress information |
4631 |
21 Nov 17 |
nicklas |
Doc.hide(progressBar); |
4631 |
21 Nov 17 |
nicklas |
return; |
4631 |
21 Nov 17 |
nicklas |
537 |
} |
4631 |
21 Nov 17 |
nicklas |
538 |
|
4631 |
21 Nov 17 |
nicklas |
var done = Doc.element('wizard-progress-done'); |
4631 |
21 Nov 17 |
nicklas |
var remain = Doc.element('wizard-progress-remain'); |
4631 |
21 Nov 17 |
nicklas |
541 |
|
4631 |
21 Nov 17 |
nicklas |
progressBar.setAttribute('value', progress.percent+'%'); |
4631 |
21 Nov 17 |
nicklas |
done.style.width = progress.percent+'%'; |
4631 |
21 Nov 17 |
nicklas |
remain.style.width = (100-progress.percent)+'%'; |
4631 |
21 Nov 17 |
nicklas |
545 |
|
4631 |
21 Nov 17 |
nicklas |
if (progress.message) |
4631 |
21 Nov 17 |
nicklas |
547 |
{ |
4631 |
21 Nov 17 |
nicklas |
Doc.element('wizard-status').innerHTML = Strings.encodeTags(progress.message); |
4631 |
21 Nov 17 |
nicklas |
549 |
} |
4631 |
21 Nov 17 |
nicklas |
550 |
|
4631 |
21 Nov 17 |
nicklas |
if (progress.percent < 100) |
4631 |
21 Nov 17 |
nicklas |
552 |
{ |
4631 |
21 Nov 17 |
nicklas |
// Continue to request updates until we 100% has been reached |
4631 |
21 Nov 17 |
nicklas |
progressTimer = setTimeout(internal.requestProgressUpdate, 1500, progress.name); |
4631 |
21 Nov 17 |
nicklas |
555 |
} |
4631 |
21 Nov 17 |
nicklas |
else |
4631 |
21 Nov 17 |
nicklas |
557 |
{ |
4631 |
21 Nov 17 |
nicklas |
progressTimer = null; |
4631 |
21 Nov 17 |
nicklas |
Doc.hide(progressBar); |
4631 |
21 Nov 17 |
nicklas |
560 |
} |
4631 |
21 Nov 17 |
nicklas |
561 |
} |
4631 |
21 Nov 17 |
nicklas |
562 |
|
4631 |
21 Nov 17 |
nicklas |
563 |
|
4354 |
13 Feb 17 |
nicklas |
wizard.showStatusMessage = function(msg) |
4354 |
13 Feb 17 |
nicklas |
565 |
{ |
4354 |
13 Feb 17 |
nicklas |
wizard.setWizardStatus('messagecontainer note', msg); |
4354 |
13 Feb 17 |
nicklas |
567 |
} |
4354 |
13 Feb 17 |
nicklas |
568 |
|
4354 |
13 Feb 17 |
nicklas |
569 |
/** |
4354 |
13 Feb 17 |
nicklas |
Hide the current global wizard-status message. |
4354 |
13 Feb 17 |
nicklas |
571 |
*/ |
4354 |
13 Feb 17 |
nicklas |
wizard.hideWizardStatus = function() |
4354 |
13 Feb 17 |
nicklas |
573 |
{ |
4354 |
13 Feb 17 |
nicklas |
Doc.hide('wizard-status'); |
4354 |
13 Feb 17 |
nicklas |
Doc.hide('wizard-progress'); |
4354 |
13 Feb 17 |
nicklas |
576 |
} |
4631 |
21 Nov 17 |
nicklas |
577 |
|
4631 |
21 Nov 17 |
nicklas |
wizard.showGoNextConfirmation = function(verify, msg) |
4631 |
21 Nov 17 |
nicklas |
579 |
{ |
4631 |
21 Nov 17 |
nicklas |
var check = ''; |
4631 |
21 Nov 17 |
nicklas |
if (verify) |
4631 |
21 Nov 17 |
nicklas |
582 |
{ |
4631 |
21 Nov 17 |
nicklas |
check = '<input type="checkbox" name="verifyGoNext" id="verifyGoNext">'; |
4631 |
21 Nov 17 |
nicklas |
Doc.addClass('gonext', 'disabled'); |
4631 |
21 Nov 17 |
nicklas |
Doc.addClass('goregister', 'disabled'); |
4631 |
21 Nov 17 |
nicklas |
586 |
} |
4354 |
13 Feb 17 |
nicklas |
587 |
|
4631 |
21 Nov 17 |
nicklas |
var gonext = Doc.element('gonext-message'); |
4631 |
21 Nov 17 |
nicklas |
gonext.innerHTML = check + msg; |
4631 |
21 Nov 17 |
nicklas |
Doc.show(gonext); |
4631 |
21 Nov 17 |
nicklas |
591 |
|
4631 |
21 Nov 17 |
nicklas |
if (verify) |
4631 |
21 Nov 17 |
nicklas |
593 |
{ |
4631 |
21 Nov 17 |
nicklas |
Events.addEventHandler('verifyGoNext', 'click', internal.verifyInternalOnClick); |
4631 |
21 Nov 17 |
nicklas |
595 |
} |
4631 |
21 Nov 17 |
nicklas |
596 |
} |
4631 |
21 Nov 17 |
nicklas |
597 |
|
4631 |
21 Nov 17 |
nicklas |
wizard.hideGoNextConfirmation = function() |
4631 |
21 Nov 17 |
nicklas |
599 |
{ |
4631 |
21 Nov 17 |
nicklas |
var gonext = Doc.element('gonext-message'); |
4631 |
21 Nov 17 |
nicklas |
gonext.innerHTML = ''; |
4631 |
21 Nov 17 |
nicklas |
Doc.hide(gonext); |
4631 |
21 Nov 17 |
nicklas |
Doc.removeClass('gonext', 'disabled'); |
4631 |
21 Nov 17 |
nicklas |
Doc.removeClass('goregister', 'disabled'); |
4631 |
21 Nov 17 |
nicklas |
605 |
} |
4631 |
21 Nov 17 |
nicklas |
606 |
|
4631 |
21 Nov 17 |
nicklas |
internal.verifyInternalOnClick = function(event) |
4631 |
21 Nov 17 |
nicklas |
608 |
{ |
4631 |
21 Nov 17 |
nicklas |
var frm = document.forms['reggie']; |
4631 |
21 Nov 17 |
nicklas |
var checked = event.currentTarget.checked; |
4631 |
21 Nov 17 |
nicklas |
Doc.addOrRemoveClass('goregister', 'disabled', !checked); |
4631 |
21 Nov 17 |
nicklas |
Doc.addOrRemoveClass('gonext', 'disabled', !checked); |
4631 |
21 Nov 17 |
nicklas |
613 |
} |
4631 |
21 Nov 17 |
nicklas |
614 |
|
4354 |
13 Feb 17 |
nicklas |
615 |
/** |
4631 |
21 Nov 17 |
nicklas |
Show final registration messages in a list. |
4631 |
21 Nov 17 |
nicklas |
617 |
*/ |
4631 |
21 Nov 17 |
nicklas |
wizard.showFinalMessage = function(messages) |
4631 |
21 Nov 17 |
nicklas |
619 |
{ |
4631 |
21 Nov 17 |
nicklas |
var msg = internal.generateMessageList(messages); |
5078 |
08 Nov 18 |
nicklas |
621 |
|
5078 |
08 Nov 18 |
nicklas |
var status = Doc.element('wizard-messages') || Doc.element('wizard-status'); |
5078 |
08 Nov 18 |
nicklas |
status.className = 'success'; |
5078 |
08 Nov 18 |
nicklas |
status.innerHTML = msg.html; |
5078 |
08 Nov 18 |
nicklas |
Doc.show(status); |
5078 |
08 Nov 18 |
nicklas |
626 |
|
4631 |
21 Nov 17 |
nicklas |
if (progressTimer) clearTimeout(progressTimer); |
4631 |
21 Nov 17 |
nicklas |
return { 'errors': msg.errors, 'warnings': msg.warnings }; |
4631 |
21 Nov 17 |
nicklas |
629 |
} |
4631 |
21 Nov 17 |
nicklas |
630 |
|
4631 |
21 Nov 17 |
nicklas |
internal.generateMessageList = function(messages) |
4631 |
21 Nov 17 |
nicklas |
632 |
{ |
4631 |
21 Nov 17 |
nicklas |
var msg = '<ul>'; |
4631 |
21 Nov 17 |
nicklas |
var numWarnings = 0; |
4631 |
21 Nov 17 |
nicklas |
var numErrors = 0; |
4631 |
21 Nov 17 |
nicklas |
for (var i = 0; i < messages.length; i++) |
4631 |
21 Nov 17 |
nicklas |
637 |
{ |
4631 |
21 Nov 17 |
nicklas |
var msgLine = messages[i]; |
4631 |
21 Nov 17 |
nicklas |
if (msgLine.indexOf('[Warning]') >= 0) |
4631 |
21 Nov 17 |
nicklas |
640 |
{ |
4631 |
21 Nov 17 |
nicklas |
msg += '<li class="warning">' + Strings.encodeTags(msgLine.replace('[Warning]', '')); |
4631 |
21 Nov 17 |
nicklas |
numWarnings++; |
4631 |
21 Nov 17 |
nicklas |
643 |
} |
4631 |
21 Nov 17 |
nicklas |
else if (msgLine.indexOf('[Error]') >= 0) |
4631 |
21 Nov 17 |
nicklas |
645 |
{ |
4631 |
21 Nov 17 |
nicklas |
msg += '<li class="error">' + Strings.encodeTags(msgLine.replace('[Error]', '')); |
4631 |
21 Nov 17 |
nicklas |
numErrors++; |
4631 |
21 Nov 17 |
nicklas |
648 |
} |
4631 |
21 Nov 17 |
nicklas |
else |
4631 |
21 Nov 17 |
nicklas |
650 |
{ |
4631 |
21 Nov 17 |
nicklas |
msg += '<li class="ok">' + Strings.encodeTags(msgLine); |
4631 |
21 Nov 17 |
nicklas |
652 |
} |
4631 |
21 Nov 17 |
nicklas |
653 |
} |
4631 |
21 Nov 17 |
nicklas |
msg += '</ul>'; |
4631 |
21 Nov 17 |
nicklas |
return { 'html': msg, 'errors': numErrors, 'warnings': numWarnings }; |
4631 |
21 Nov 17 |
nicklas |
656 |
} |
4631 |
21 Nov 17 |
nicklas |
657 |
|
4631 |
21 Nov 17 |
nicklas |
658 |
/** |
4354 |
13 Feb 17 |
nicklas |
Initialize the wizard: |
4354 |
13 Feb 17 |
nicklas |
660 |
|
4354 |
13 Feb 17 |
nicklas |
* Check that a project is active |
4354 |
13 Feb 17 |
nicklas |
662 |
*/ |
4354 |
13 Feb 17 |
nicklas |
internal.initWizard = function() |
4354 |
13 Feb 17 |
nicklas |
664 |
{ |
4354 |
13 Feb 17 |
nicklas |
var path = document.getElementsByClassName('path'); |
4354 |
13 Feb 17 |
nicklas |
if (path && path.length) |
4354 |
13 Feb 17 |
nicklas |
667 |
{ |
4354 |
13 Feb 17 |
nicklas |
var relaxVersion = document.createElement('span'); |
4354 |
13 Feb 17 |
nicklas |
relaxVersion.id = 'relax-version'; |
4354 |
13 Feb 17 |
nicklas |
relaxVersion.innerHTML = '[Relax '+Relax.VERSION+']'; |
4354 |
13 Feb 17 |
nicklas |
path[0].appendChild(relaxVersion); |
4354 |
13 Feb 17 |
nicklas |
672 |
} |
4354 |
13 Feb 17 |
nicklas |
673 |
} |
4354 |
13 Feb 17 |
nicklas |
674 |
|
4354 |
13 Feb 17 |
nicklas |
675 |
/** |
4354 |
13 Feb 17 |
nicklas |
Display a global wizard-status message. This may for example be |
4354 |
13 Feb 17 |
nicklas |
an error message, a work-in-progress indicator, etc. |
4354 |
13 Feb 17 |
nicklas |
678 |
*/ |
4354 |
13 Feb 17 |
nicklas |
wizard.setWizardStatus = function(className, msg) |
4354 |
13 Feb 17 |
nicklas |
680 |
{ |
4354 |
13 Feb 17 |
nicklas |
var status = Doc.element('wizard-status'); |
4354 |
13 Feb 17 |
nicklas |
status.className = className; |
4354 |
13 Feb 17 |
nicklas |
status.innerHTML = msg; |
4354 |
13 Feb 17 |
nicklas |
Doc.show(status); |
4354 |
13 Feb 17 |
nicklas |
685 |
} |
4354 |
13 Feb 17 |
nicklas |
686 |
|
4354 |
13 Feb 17 |
nicklas |
// Disable all form elements inside the given container |
4354 |
13 Feb 17 |
nicklas |
internal.disableAllFormElements = function(container, hideButtons) |
4354 |
13 Feb 17 |
nicklas |
689 |
{ |
4354 |
13 Feb 17 |
nicklas |
container = Doc.element(container); |
4632 |
22 Nov 17 |
nicklas |
if (!container) return; |
4354 |
13 Feb 17 |
nicklas |
var input = container.getElementsByTagName('input'); |
4354 |
13 Feb 17 |
nicklas |
for (var i = 0; i < input.length; i++) |
4354 |
13 Feb 17 |
nicklas |
694 |
{ |
4354 |
13 Feb 17 |
nicklas |
input[i].disabled = true; |
4354 |
13 Feb 17 |
nicklas |
696 |
} |
4354 |
13 Feb 17 |
nicklas |
var select = container.getElementsByTagName('select'); |
4354 |
13 Feb 17 |
nicklas |
for (var i = 0; i < select.length; i++) |
4354 |
13 Feb 17 |
nicklas |
699 |
{ |
4354 |
13 Feb 17 |
nicklas |
select[i].disabled = true; |
4354 |
13 Feb 17 |
nicklas |
701 |
} |
4354 |
13 Feb 17 |
nicklas |
var text = container.getElementsByTagName('textarea'); |
4354 |
13 Feb 17 |
nicklas |
for (var i = 0; i < text.length; i++) |
4354 |
13 Feb 17 |
nicklas |
704 |
{ |
4354 |
13 Feb 17 |
nicklas |
text[i].disabled = true; |
4354 |
13 Feb 17 |
nicklas |
706 |
} |
4354 |
13 Feb 17 |
nicklas |
if (hideButtons) |
4354 |
13 Feb 17 |
nicklas |
708 |
{ |
4354 |
13 Feb 17 |
nicklas |
internal.hideButtons(container); |
4354 |
13 Feb 17 |
nicklas |
710 |
} |
4354 |
13 Feb 17 |
nicklas |
711 |
} |
4354 |
13 Feb 17 |
nicklas |
712 |
|
4354 |
13 Feb 17 |
nicklas |
// Hide all 'basicbuttons':s in the given container |
4354 |
13 Feb 17 |
nicklas |
internal.hideButtons = function(container) |
4354 |
13 Feb 17 |
nicklas |
715 |
{ |
4354 |
13 Feb 17 |
nicklas |
container = Doc.element(container); |
4354 |
13 Feb 17 |
nicklas |
var buttons = container.getElementsByClassName('basicbutton'); |
4354 |
13 Feb 17 |
nicklas |
for (var i = 0; i < buttons.length; i++) |
4354 |
13 Feb 17 |
nicklas |
719 |
{ |
4354 |
13 Feb 17 |
nicklas |
Doc.hide(buttons[i]); |
4354 |
13 Feb 17 |
nicklas |
721 |
} |
4354 |
13 Feb 17 |
nicklas |
722 |
} |
4354 |
13 Feb 17 |
nicklas |
723 |
|
4354 |
13 Feb 17 |
nicklas |
Doc.addFinalizer(internal.initWizard); |
4354 |
13 Feb 17 |
nicklas |
return wizard; |
4354 |
13 Feb 17 |
nicklas |
726 |
}(); |
4354 |
13 Feb 17 |
nicklas |
727 |
|
4360 |
15 Feb 17 |
nicklas |
728 |
/** |
4360 |
15 Feb 17 |
nicklas |
Holds one or more filter criterias. Use the 'add*' methods |
4360 |
15 Feb 17 |
nicklas |
to add criterias to the filter, and the 'check(item)' method |
4360 |
15 Feb 17 |
nicklas |
to evaluate all criterias against a single item. |
4360 |
15 Feb 17 |
nicklas |
732 |
*/ |
4360 |
15 Feb 17 |
nicklas |
var Filter = function() |
4360 |
15 Feb 17 |
nicklas |
734 |
{ |
4360 |
15 Feb 17 |
nicklas |
this.criterias = []; |
4360 |
15 Feb 17 |
nicklas |
736 |
} |
4360 |
15 Feb 17 |
nicklas |
737 |
|
4360 |
15 Feb 17 |
nicklas |
738 |
/** |
4360 |
15 Feb 17 |
nicklas |
Adds a text criteria comparing the given item property to |
4360 |
15 Feb 17 |
nicklas |
a static value (f2). |
4360 |
15 Feb 17 |
nicklas |
741 |
*/ |
4360 |
15 Feb 17 |
nicklas |
Filter.prototype.addTextCriteria = function(itemProp, f2) |
4360 |
15 Feb 17 |
nicklas |
743 |
{ |
4360 |
15 Feb 17 |
nicklas |
if (f2 != '') |
4360 |
15 Feb 17 |
nicklas |
745 |
{ |
4360 |
15 Feb 17 |
nicklas |
var cmp; |
4360 |
15 Feb 17 |
nicklas |
if (f2 == '=') |
4360 |
15 Feb 17 |
nicklas |
748 |
{ |
4360 |
15 Feb 17 |
nicklas |
cmp = Comparator.eq; |
4360 |
15 Feb 17 |
nicklas |
f2 = null; |
4360 |
15 Feb 17 |
nicklas |
751 |
} |
4360 |
15 Feb 17 |
nicklas |
else if (f2 == '<>') |
4360 |
15 Feb 17 |
nicklas |
753 |
{ |
4360 |
15 Feb 17 |
nicklas |
cmp = Comparator.neq; |
4360 |
15 Feb 17 |
nicklas |
f2 = null; |
4360 |
15 Feb 17 |
nicklas |
756 |
} |
4360 |
15 Feb 17 |
nicklas |
else |
4360 |
15 Feb 17 |
nicklas |
758 |
{ |
4360 |
15 Feb 17 |
nicklas |
cmp = Comparator.eq; |
4360 |
15 Feb 17 |
nicklas |
760 |
} |
4360 |
15 Feb 17 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
4360 |
15 Feb 17 |
nicklas |
762 |
} |
4360 |
15 Feb 17 |
nicklas |
763 |
} |
4360 |
15 Feb 17 |
nicklas |
764 |
|
4360 |
15 Feb 17 |
nicklas |
765 |
/** |
4360 |
15 Feb 17 |
nicklas |
Adds a text criteria checking if the given item property to |
4360 |
15 Feb 17 |
nicklas |
contains a static value (f2). |
4360 |
15 Feb 17 |
nicklas |
768 |
*/ |
4360 |
15 Feb 17 |
nicklas |
Filter.prototype.addContainsCriteria = function(itemProp, f2) |
4360 |
15 Feb 17 |
nicklas |
770 |
{ |
4360 |
15 Feb 17 |
nicklas |
if (f2 != '') |
4360 |
15 Feb 17 |
nicklas |
772 |
{ |
4360 |
15 Feb 17 |
nicklas |
var cmp; |
4360 |
15 Feb 17 |
nicklas |
if (f2 == '=') |
4360 |
15 Feb 17 |
nicklas |
775 |
{ |
4360 |
15 Feb 17 |
nicklas |
cmp = Comparator.eq; |
4360 |
15 Feb 17 |
nicklas |
f2 = null; |
4360 |
15 Feb 17 |
nicklas |
778 |
} |
4360 |
15 Feb 17 |
nicklas |
else if (f2 == '<>') |
4360 |
15 Feb 17 |
nicklas |
780 |
{ |
4360 |
15 Feb 17 |
nicklas |
cmp = Comparator.neq; |
4360 |
15 Feb 17 |
nicklas |
f2 = null; |
4360 |
15 Feb 17 |
nicklas |
783 |
} |
4360 |
15 Feb 17 |
nicklas |
else |
4360 |
15 Feb 17 |
nicklas |
785 |
{ |
4360 |
15 Feb 17 |
nicklas |
cmp = Comparator.contains; |
4360 |
15 Feb 17 |
nicklas |
787 |
} |
4360 |
15 Feb 17 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
4360 |
15 Feb 17 |
nicklas |
789 |
} |
4360 |
15 Feb 17 |
nicklas |
790 |
} |
4360 |
15 Feb 17 |
nicklas |
791 |
|
4360 |
15 Feb 17 |
nicklas |
792 |
/** |
4360 |
15 Feb 17 |
nicklas |
Evaluate all criterias. Return true if all pass, false otherwise. |
4360 |
15 Feb 17 |
nicklas |
794 |
*/ |
4360 |
15 Feb 17 |
nicklas |
Filter.prototype.check = function(item) |
4360 |
15 Feb 17 |
nicklas |
796 |
{ |
4360 |
15 Feb 17 |
nicklas |
for (var i = 0; i < this.criterias.length; i++) |
4360 |
15 Feb 17 |
nicklas |
798 |
{ |
4360 |
15 Feb 17 |
nicklas |
if (!this.criterias[i](item)) return false; |
4360 |
15 Feb 17 |
nicklas |
800 |
} |
4360 |
15 Feb 17 |
nicklas |
return true; |
4360 |
15 Feb 17 |
nicklas |
802 |
} |
4360 |
15 Feb 17 |
nicklas |
803 |
|
4360 |
15 Feb 17 |
nicklas |
804 |
|
4360 |
15 Feb 17 |
nicklas |
var Comparator = function() |
4360 |
15 Feb 17 |
nicklas |
806 |
{ |
4360 |
15 Feb 17 |
nicklas |
var cmp = {}; |
4360 |
15 Feb 17 |
nicklas |
808 |
|
4360 |
15 Feb 17 |
nicklas |
809 |
/** |
4360 |
15 Feb 17 |
nicklas |
Return a comparator based on the symbol |
4360 |
15 Feb 17 |
nicklas |
which can be either '>' or '<' to return |
4360 |
15 Feb 17 |
nicklas |
Comparator.gt or Comparator.lt. Otherwise |
4360 |
15 Feb 17 |
nicklas |
the given default or Comparator.eq is returned. |
4360 |
15 Feb 17 |
nicklas |
814 |
*/ |
4360 |
15 Feb 17 |
nicklas |
cmp.get = function(symbol, defaultCmp) |
4360 |
15 Feb 17 |
nicklas |
816 |
{ |
4360 |
15 Feb 17 |
nicklas |
var c; |
4360 |
15 Feb 17 |
nicklas |
if (symbol == '<') |
4360 |
15 Feb 17 |
nicklas |
819 |
{ |
4360 |
15 Feb 17 |
nicklas |
c = cmp.lt; |
4360 |
15 Feb 17 |
nicklas |
821 |
} |
4360 |
15 Feb 17 |
nicklas |
else if (symbol == '>') |
4360 |
15 Feb 17 |
nicklas |
823 |
{ |
4360 |
15 Feb 17 |
nicklas |
c = cmp.gt; |
4360 |
15 Feb 17 |
nicklas |
825 |
} |
4360 |
15 Feb 17 |
nicklas |
else |
4360 |
15 Feb 17 |
nicklas |
827 |
{ |
4360 |
15 Feb 17 |
nicklas |
c = defaultCmp || cmp.eq; |
4360 |
15 Feb 17 |
nicklas |
829 |
} |
4360 |
15 Feb 17 |
nicklas |
return c; |
4360 |
15 Feb 17 |
nicklas |
831 |
} |
4360 |
15 Feb 17 |
nicklas |
832 |
|
4360 |
15 Feb 17 |
nicklas |
// Compare if two values are equal |
4360 |
15 Feb 17 |
nicklas |
cmp.eq = function(v1, v2) |
4360 |
15 Feb 17 |
nicklas |
835 |
{ |
4360 |
15 Feb 17 |
nicklas |
return v1 == v2; |
4360 |
15 Feb 17 |
nicklas |
837 |
} |
4360 |
15 Feb 17 |
nicklas |
838 |
|
4360 |
15 Feb 17 |
nicklas |
// Compare if two values are different |
4360 |
15 Feb 17 |
nicklas |
cmp.neq = function(v1, v2) |
4360 |
15 Feb 17 |
nicklas |
841 |
{ |
4360 |
15 Feb 17 |
nicklas |
return v1 != v2; |
4360 |
15 Feb 17 |
nicklas |
843 |
} |
4360 |
15 Feb 17 |
nicklas |
844 |
|
4360 |
15 Feb 17 |
nicklas |
// Check if v2 is contained in v1 |
4360 |
15 Feb 17 |
nicklas |
cmp.contains = function(v1, v2) |
4360 |
15 Feb 17 |
nicklas |
847 |
{ |
4360 |
15 Feb 17 |
nicklas |
return v1 != null && v2 != null && v1.indexOf(v2) >= 0; |
4360 |
15 Feb 17 |
nicklas |
849 |
} |
4360 |
15 Feb 17 |
nicklas |
850 |
|
4360 |
15 Feb 17 |
nicklas |
// Compare if two values are appoximately equals (difference is not more than 0.05) |
4360 |
15 Feb 17 |
nicklas |
cmp.approx = function(v1, v2) |
4360 |
15 Feb 17 |
nicklas |
853 |
{ |
4360 |
15 Feb 17 |
nicklas |
return Math.abs(v2 - v1) < 0.05; |
4360 |
15 Feb 17 |
nicklas |
855 |
} |
4360 |
15 Feb 17 |
nicklas |
856 |
|
4360 |
15 Feb 17 |
nicklas |
// Compare if v1 starts with the same string as v2 |
4360 |
15 Feb 17 |
nicklas |
cmp.startsWith = function(v1, v2) |
4360 |
15 Feb 17 |
nicklas |
859 |
{ |
4360 |
15 Feb 17 |
nicklas |
return v1 != null && v1.indexOf(v2) == 0; |
4360 |
15 Feb 17 |
nicklas |
861 |
} |
4360 |
15 Feb 17 |
nicklas |
862 |
|
4360 |
15 Feb 17 |
nicklas |
// Compare if v1 is greater than or equal to v2 |
4360 |
15 Feb 17 |
nicklas |
cmp.gt = function(v1, v2) |
4360 |
15 Feb 17 |
nicklas |
865 |
{ |
4360 |
15 Feb 17 |
nicklas |
return v1 != null && v2 != null && v1 >= v2; |
4360 |
15 Feb 17 |
nicklas |
867 |
} |
4360 |
15 Feb 17 |
nicklas |
868 |
|
4360 |
15 Feb 17 |
nicklas |
// Compare if v1 is less than or equal to v2 |
4360 |
15 Feb 17 |
nicklas |
cmp.lt = function(v1, v2) |
4360 |
15 Feb 17 |
nicklas |
871 |
{ |
4360 |
15 Feb 17 |
nicklas |
return v1 != null && v2 != null && v1 <= v2; |
4360 |
15 Feb 17 |
nicklas |
873 |
} |
4360 |
15 Feb 17 |
nicklas |
874 |
|
4360 |
15 Feb 17 |
nicklas |
return cmp; |
4360 |
15 Feb 17 |
nicklas |
876 |
}(); |
4360 |
15 Feb 17 |
nicklas |
877 |
|
4360 |
15 Feb 17 |
nicklas |
878 |
|
4360 |
15 Feb 17 |
nicklas |
879 |
|