hat-trick 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -5
- data/app/assets/javascripts/hat-trick.js.coffee +254 -120
- data/app/views/hat_trick/_wizard_meta.html.erb +1 -1
- data/hat-trick.gemspec +3 -3
- data/lib/hat-trick.rb +1 -1
- data/lib/hat_trick/config.rb +17 -0
- data/lib/hat_trick/controller_helpers.rb +64 -0
- data/lib/hat_trick/controller_hooks.rb +20 -64
- data/lib/hat_trick/dsl.rb +86 -62
- data/lib/hat_trick/{rails_engine.rb → engine.rb} +1 -1
- data/lib/hat_trick/form_helper.rb +0 -4
- data/lib/hat_trick/model_methods.rb +30 -8
- data/lib/hat_trick/step_definition.rb +12 -12
- data/lib/hat_trick/version.rb +1 -1
- data/lib/hat_trick/wizard.rb +44 -27
- data/lib/hat_trick/wizard_definition.rb +2 -0
- data/lib/hat_trick/wizard_steps.rb +5 -2
- data/spec/lib/hat_trick/dsl_spec.rb +26 -0
- data/spec/lib/hat_trick/wizard_spec.rb +21 -19
- data/spec/spec_helper.rb +1 -9
- data/vendor/assets/javascripts/jquery.form.wizard.js +499 -438
- data/vendor/assets/javascripts/jquery.history.js +1 -0
- metadata +15 -12
- data/spec/lib/hat_trick/step_spec.rb +0 -9
- data/vendor/assets/javascripts/jquery.ba-bbq.js +0 -1137
@@ -13,444 +13,505 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
(function($){
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
16
|
+
$.widget("ui.formwizard", {
|
17
|
+
|
18
|
+
_init: function() {
|
19
|
+
|
20
|
+
var wizard = this;
|
21
|
+
var formOptionsSuccess = this.options.formOptions.success;
|
22
|
+
var formOptionsComplete = this.options.formOptions.complete;
|
23
|
+
var formOptionsBeforeSend = this.options.formOptions.beforeSend;
|
24
|
+
var formOptionsBeforeSubmit = this.options.formOptions.beforeSubmit;
|
25
|
+
var formOptionsBeforeSerialize = this.options.formOptions.beforeSerialize;
|
26
|
+
this.options.formOptions = $.extend(this.options.formOptions,{
|
27
|
+
success : function(responseText, textStatus, xhr){
|
28
|
+
if(formOptionsSuccess){
|
29
|
+
formOptionsSuccess(responseText, textStatus, xhr);
|
30
|
+
}
|
31
|
+
if(wizard.options.formOptions && wizard.options.formOptions.resetForm || !wizard.options.formOptions){
|
32
|
+
wizard._reset();
|
33
|
+
}
|
34
|
+
},
|
35
|
+
complete : function(xhr, textStatus){
|
36
|
+
if(formOptionsComplete){
|
37
|
+
formOptionsComplete(xhr, textStatus);
|
38
|
+
}
|
39
|
+
wizard._enableNavigation();
|
40
|
+
},
|
41
|
+
beforeSubmit : function(arr, theForm, options) {
|
42
|
+
if(formOptionsBeforeSubmit){
|
43
|
+
var shouldSubmit = formOptionsBeforeSubmit(arr, theForm, options);
|
44
|
+
if(!shouldSubmit)
|
45
|
+
wizard._enableNavigation();
|
46
|
+
return shouldSubmit;
|
47
|
+
}
|
48
|
+
},
|
49
|
+
beforeSend : function(xhr) {
|
50
|
+
if(formOptionsBeforeSend){
|
51
|
+
var shouldSubmit = formOptionsBeforeSend(xhr);
|
52
|
+
if(!shouldSubmit)
|
53
|
+
wizard._enableNavigation();
|
54
|
+
return shouldSubmit;
|
55
|
+
}
|
56
|
+
},
|
57
|
+
beforeSerialize: function(form, options) {
|
58
|
+
if(formOptionsBeforeSerialize){
|
59
|
+
var shouldSubmit = formOptionsBeforeSerialize(form, options);
|
60
|
+
if(!shouldSubmit)
|
61
|
+
wizard._enableNavigation();
|
62
|
+
return shouldSubmit;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
});
|
66
|
+
|
67
|
+
this.steps = this.element.find(".step").hide();
|
68
|
+
|
69
|
+
this.firstStep = this.options.firstStep || this.steps.eq(0).attr("id");
|
70
|
+
this.activatedSteps = [];
|
71
|
+
this.isLastStep = false;
|
72
|
+
this.previousStep = undefined;
|
73
|
+
this.currentStep = this.firstStep;
|
74
|
+
|
75
|
+
this._updateButtons();
|
76
|
+
|
77
|
+
if(this.options.validationEnabled && jQuery().validate == undefined){
|
78
|
+
this.options.validationEnabled = false;
|
79
|
+
if( (window['console'] !== undefined) ){
|
80
|
+
console.log("%s", "validationEnabled option set, but the validation plugin is not included");
|
81
|
+
}
|
82
|
+
}else if(this.options.validationEnabled){
|
83
|
+
this.element.validate(this.options.validationOptions);
|
84
|
+
}
|
85
|
+
if(this.options.formPluginEnabled && jQuery().ajaxSubmit == undefined){
|
86
|
+
this.options.formPluginEnabled = false;
|
87
|
+
if( (window['console'] !== undefined) ){
|
88
|
+
console.log("%s", "formPluginEnabled option set but the form plugin is not included");
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
if(this.options.disableInputFields == true){
|
93
|
+
$(this.steps).find(":input:not('.wizard-ignore')").attr("disabled","disabled");
|
94
|
+
}
|
95
|
+
|
96
|
+
if(this.options.historyEnabled){
|
97
|
+
History.Adapter.bind(window, 'statechange', function() {
|
98
|
+
var state;
|
99
|
+
var step;
|
100
|
+
state = History.getState();
|
101
|
+
step = state.data.step;
|
102
|
+
if(step !== wizard.currentStep){
|
103
|
+
if(wizard.options.validationEnabled && step === wizard._navigate(wizard.currentStep)){
|
104
|
+
if(!wizard.element.valid()){
|
105
|
+
wizard._updateHistory(wizard.currentStep);
|
106
|
+
wizard.element.validate().focusInvalid();
|
107
|
+
|
108
|
+
return false;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
if(step !== wizard.currentStep)
|
112
|
+
wizard._show(step);
|
113
|
+
}
|
114
|
+
});
|
115
|
+
}
|
116
|
+
|
117
|
+
this.element.addClass("ui-formwizard");
|
118
|
+
this.element.find(":input").addClass("ui-wizard-content");
|
119
|
+
this.steps.addClass("ui-formwizard-content");
|
120
|
+
this.backButton.addClass("ui-formwizard-button ui-wizard-content");
|
121
|
+
this.nextButton.addClass("ui-formwizard-button ui-wizard-content");
|
122
|
+
|
123
|
+
if(!this.options.disableUIStyles){
|
124
|
+
this.element.addClass("ui-helper-reset ui-widget ui-widget-content ui-helper-reset ui-corner-all");
|
125
|
+
this.element.find(":input").addClass("ui-helper-reset ui-state-default");
|
126
|
+
this.steps.addClass("ui-helper-reset ui-corner-all");
|
127
|
+
this.backButton.addClass("ui-helper-reset ui-state-default");
|
128
|
+
this.nextButton.addClass("ui-helper-reset ui-state-default");
|
129
|
+
}
|
130
|
+
this._show(undefined);
|
131
|
+
return $(this);
|
132
|
+
},
|
133
|
+
|
134
|
+
_updateButtons : function(){
|
135
|
+
var wizard = this;
|
136
|
+
|
137
|
+
this.nextButton = this.element.find(this.options.next);
|
138
|
+
this.nextButton.each(function() {
|
139
|
+
var events = $(this).data("events");
|
140
|
+
if (typeof events === "undefined" ||
|
141
|
+
typeof events['click'] === "undefined" ||
|
142
|
+
events['click'].length === 0) {
|
143
|
+
$(this).click(function() {
|
144
|
+
var nextClickCallbackData = {
|
145
|
+
"currentStep": wizard.currentStep,
|
146
|
+
"button": $(this).attr("id")
|
147
|
+
};
|
148
|
+
$(wizard.element).trigger('next_click', nextClickCallbackData);
|
149
|
+
return wizard._next();
|
150
|
+
});
|
151
|
+
}
|
152
|
+
});
|
153
|
+
|
154
|
+
this.nextButtonInitinalValue = this.nextButton.val();
|
155
|
+
this.nextButton.val(this.options.textNext);
|
156
|
+
|
157
|
+
this.backButton = this.element.find(this.options.back);
|
158
|
+
this.backButton.each(function() {
|
159
|
+
var events = $(this).data('events');
|
160
|
+
if (typeof events === "undefined" ||
|
161
|
+
typeof events['click'] === "undefined" ||
|
162
|
+
events['click'].length === 0) {
|
163
|
+
$(this).click(function() {
|
164
|
+
var backClickCallbackData = {
|
165
|
+
"currentStep": wizard.currentStep,
|
166
|
+
"button": $(this).attr("id")
|
167
|
+
};
|
168
|
+
$(wizard.element).trigger('back_click', backClickCallbackData);
|
169
|
+
wizard._back();
|
170
|
+
return false;
|
171
|
+
});
|
172
|
+
}
|
173
|
+
});
|
174
|
+
|
175
|
+
this.backButtonInitinalValue = this.backButton.val();
|
176
|
+
this.backButton.val(this.options.textBack);
|
177
|
+
},
|
178
|
+
|
179
|
+
_next : function(){
|
180
|
+
if(this.options.validationEnabled){
|
181
|
+
if(!this.element.valid()){
|
182
|
+
this.element.validate().focusInvalid();
|
183
|
+
return false;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
if(this.options.remoteAjax != undefined){
|
188
|
+
var options = this.options.remoteAjax[this.currentStep];
|
189
|
+
var wizard = this;
|
190
|
+
if(options !== undefined){
|
191
|
+
var success = options.success;
|
192
|
+
var beforeSend = options.beforeSend;
|
193
|
+
var complete = options.complete;
|
194
|
+
|
195
|
+
options = $.extend({},options,{
|
196
|
+
beforeSend : function(xhr){
|
197
|
+
wizard._disableNavigation();
|
198
|
+
if(beforeSend !== undefined)
|
199
|
+
beforeSend(xhr);
|
200
|
+
$(wizard.element).trigger('before_remote_ajax', {
|
201
|
+
"xhr": xhr,
|
202
|
+
"currentStep" : wizard.currentStep
|
203
|
+
});
|
204
|
+
},
|
205
|
+
complete : function(xhr, statusText){
|
206
|
+
if(complete !== undefined)
|
207
|
+
complete(xhr, statusText);
|
208
|
+
$(wizard.element).trigger('after_remote_ajax', {
|
209
|
+
"xhr": xhr,
|
210
|
+
"statusText": statusText,
|
211
|
+
"currentStep" : wizard.currentStep
|
212
|
+
});
|
213
|
+
|
214
|
+
if (statusText === "success") {
|
215
|
+
wizard._continueToNextStep();
|
216
|
+
}
|
217
|
+
|
218
|
+
wizard._enableNavigation();
|
219
|
+
}
|
220
|
+
});
|
221
|
+
this.element.ajaxSubmit(options);
|
222
|
+
return false;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
return this._continueToNextStep();
|
227
|
+
},
|
228
|
+
|
229
|
+
_back : function(){
|
230
|
+
if(this.activatedSteps.length > 0){
|
231
|
+
if(this.options.historyEnabled){
|
232
|
+
this._updateHistory(this.activatedSteps[this.activatedSteps.length - 2]);
|
233
|
+
}else{
|
234
|
+
this._show(this.activatedSteps[this.activatedSteps.length - 2], true);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
return false;
|
238
|
+
},
|
239
|
+
|
240
|
+
_continueToNextStep : function(){
|
241
|
+
if(this.isLastStep){
|
242
|
+
for(var i = 0; i < this.activatedSteps.length; i++){
|
243
|
+
this.steps.filter("#" + this.activatedSteps[i]).find(":input").not(".wizard-ignore").removeAttr("disabled");
|
244
|
+
}
|
245
|
+
if(!this.options.formPluginEnabled){
|
246
|
+
return true;
|
247
|
+
}else{
|
248
|
+
this._disableNavigation();
|
249
|
+
this.element.ajaxSubmit(this.options.formOptions);
|
250
|
+
return false;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
var step = this._navigate(this.currentStep);
|
255
|
+
if(step == this.currentStep){
|
256
|
+
return false;
|
257
|
+
}
|
258
|
+
if(this.options.historyEnabled){
|
259
|
+
this._updateHistory(step);
|
260
|
+
}else{
|
261
|
+
this._show(step, true);
|
262
|
+
}
|
263
|
+
return false;
|
264
|
+
},
|
265
|
+
|
266
|
+
_updateHistory : function(step) {
|
267
|
+
var state = {};
|
268
|
+
var title = $("title").text();
|
269
|
+
state["step"] = step;
|
270
|
+
History.pushState(state, title, step);
|
271
|
+
},
|
272
|
+
|
273
|
+
_disableNavigation : function(){
|
274
|
+
this.nextButton.attr("disabled","disabled");
|
275
|
+
this.backButton.attr("disabled","disabled");
|
276
|
+
if(!this.options.disableUIStyles){
|
277
|
+
this.nextButton.removeClass("ui-state-active").addClass("ui-state-disabled");
|
278
|
+
this.backButton.removeClass("ui-state-active").addClass("ui-state-disabled");
|
279
|
+
}
|
280
|
+
},
|
281
|
+
|
282
|
+
_setNavButtonValues : function(){
|
283
|
+
if(this.isLastStep){
|
284
|
+
this.nextButton.val(this.options.textSubmit);
|
285
|
+
}else{
|
286
|
+
this.nextButton.val(this.options.textNext);
|
287
|
+
}
|
288
|
+
},
|
289
|
+
|
290
|
+
_enableNavigation : function(){
|
291
|
+
if(this.nextButton.val() === ""){
|
292
|
+
this._setNavButtonValues();
|
293
|
+
}
|
294
|
+
|
295
|
+
if($.trim(this.currentStep) !== this.steps.eq(0).attr("id")){
|
296
|
+
this.backButton.removeAttr("disabled");
|
297
|
+
if(!this.options.disableUIStyles){
|
298
|
+
this.backButton.removeClass("ui-state-disabled").addClass("ui-state-active");
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
this.nextButton.removeAttr("disabled");
|
303
|
+
if(!this.options.disableUIStyles){
|
304
|
+
this.nextButton.removeClass("ui-state-disabled").addClass("ui-state-active");
|
305
|
+
}
|
306
|
+
},
|
307
|
+
|
308
|
+
_animate : function(oldStep, newStep, stepShownCallback){
|
309
|
+
this._disableNavigation();
|
310
|
+
var old = this.steps.filter("#" + oldStep);
|
311
|
+
var current = this.steps.filter("#" + newStep);
|
312
|
+
old.find(":input").not(".wizard-ignore").attr("disabled","disabled");
|
313
|
+
current.find(":input").not(".wizard-ignore").removeAttr("disabled");
|
314
|
+
var wizard = this;
|
315
|
+
old.animate(wizard.options.outAnimation, wizard.options.outDuration, wizard.options.easing, function(){
|
316
|
+
current.animate(wizard.options.inAnimation, wizard.options.inDuration, wizard.options.easing, function(){
|
317
|
+
if(wizard.options.focusFirstInput)
|
318
|
+
current.find(":input:first").focus();
|
319
|
+
wizard._enableNavigation();
|
320
|
+
|
321
|
+
stepShownCallback.apply(wizard);
|
322
|
+
});
|
323
|
+
return;
|
324
|
+
});
|
325
|
+
},
|
326
|
+
|
327
|
+
_checkIflastStep : function(step){
|
328
|
+
this.isLastStep = false;
|
329
|
+
if($("#" + step).hasClass(this.options.submitStepClass) || this.steps.filter(":last").attr("id") == step){
|
330
|
+
this.isLastStep = true;
|
331
|
+
}
|
332
|
+
},
|
333
|
+
|
334
|
+
_getLink : function(step){
|
335
|
+
var link = undefined;
|
336
|
+
var links = this.steps.filter("#" + step).find(this.options.linkClass);
|
337
|
+
|
338
|
+
if(links != undefined){
|
339
|
+
if(links.filter(":radio,:checkbox").size() > 0){
|
340
|
+
link = links.filter(this.options.linkClass + ":checked").val();
|
341
|
+
}else{
|
342
|
+
link = $(links).val();
|
343
|
+
}
|
344
|
+
}
|
345
|
+
return link;
|
346
|
+
},
|
347
|
+
|
348
|
+
_navigate : function(step){
|
349
|
+
var link = this._getLink(step);
|
350
|
+
if(link != undefined){
|
351
|
+
if((link != "" && link != null && link != undefined) && this.steps.filter("#" + link).attr("id") != undefined){
|
352
|
+
return link;
|
353
|
+
}
|
354
|
+
return this.currentStep;
|
355
|
+
}else if(link == undefined && !this.isLastStep){
|
356
|
+
var step1 = this.steps.filter("#" + step).next().attr("id");
|
357
|
+
return step1;
|
358
|
+
}
|
359
|
+
},
|
360
|
+
|
361
|
+
_stepFromPath : function() {
|
362
|
+
var path = window.location.pathname;
|
363
|
+
var pathComponents = path.split('/');
|
364
|
+
for (var i = pathComponents.length; i >= 0; i--) {
|
365
|
+
if (pathComponents[i] !== "") {
|
366
|
+
return pathComponents[i];
|
367
|
+
}
|
368
|
+
}
|
369
|
+
},
|
370
|
+
|
371
|
+
_show : function(step){
|
372
|
+
var backwards = false;
|
373
|
+
var triggerStepShown = step !== undefined;
|
374
|
+
var fragment;
|
375
|
+
if(step == undefined || step == ""){
|
376
|
+
step = this._stepFromPath() || this.firstStep;
|
377
|
+
this.activatedSteps.pop();
|
378
|
+
this.activatedSteps.push(step);
|
379
|
+
}else{
|
380
|
+
if($.inArray(step, this.activatedSteps) > -1){
|
381
|
+
backwards = true;
|
382
|
+
this.activatedSteps.pop();
|
383
|
+
}else {
|
384
|
+
this.activatedSteps.push(step);
|
385
|
+
}
|
386
|
+
}
|
387
|
+
|
388
|
+
if(this.currentStep !== step || step === this.firstStep){
|
389
|
+
this.previousStep = this.currentStep;
|
390
|
+
this._checkIflastStep(step);
|
391
|
+
this.currentStep = step;
|
392
|
+
var stepShownCallback = function(){if(triggerStepShown)$(this.element).trigger('step_shown', $.extend({"isBackNavigation" : backwards},this._state()));};
|
393
|
+
this._animate(this.previousStep, step, stepShownCallback);
|
394
|
+
};
|
395
|
+
|
396
|
+
|
397
|
+
},
|
398
|
+
|
399
|
+
_reset : function(){
|
400
|
+
this.element.resetForm()
|
401
|
+
$("label,:input,textarea",this).removeClass("error");
|
402
|
+
for(var i = 0; i < this.activatedSteps.length; i++){
|
403
|
+
this.steps.filter("#" + this.activatedSteps[i]).hide().find(":input").attr("disabled","disabled");
|
404
|
+
}
|
405
|
+
this.activatedSteps = new Array();
|
406
|
+
this.previousStep = undefined;
|
407
|
+
this.isLastStep = false;
|
408
|
+
if(this.options.historyEnabled){
|
409
|
+
this._updateHistory(this.firstStep);
|
410
|
+
}else{
|
411
|
+
this._show(this.firstStep);
|
412
|
+
}
|
413
|
+
|
414
|
+
},
|
415
|
+
|
416
|
+
_state : function(state){
|
417
|
+
var currentState = { "settings" : this.options,
|
418
|
+
"activatedSteps" : this.activatedSteps,
|
419
|
+
"isLastStep" : this.isLastStep,
|
420
|
+
"isFirstStep" : this.currentStep === this.firstStep,
|
421
|
+
"previousStep" : this.previousStep,
|
422
|
+
"currentStep" : this.currentStep,
|
423
|
+
"backButton" : this.backButton,
|
424
|
+
"nextButton" : this.nextButton,
|
425
|
+
"steps" : this.steps,
|
426
|
+
"firstStep" : this.firstStep
|
427
|
+
}
|
428
|
+
|
429
|
+
if(state !== undefined)
|
430
|
+
return currentState[state];
|
431
|
+
|
432
|
+
return currentState;
|
433
|
+
},
|
434
|
+
|
435
|
+
/*Methods*/
|
436
|
+
|
437
|
+
show : function(step){
|
438
|
+
if(this.options.historyEnabled){
|
439
|
+
this._updateHistory(step);
|
440
|
+
}else{
|
441
|
+
this._show(step);
|
442
|
+
}
|
443
|
+
},
|
444
|
+
|
445
|
+
state : function(state){
|
446
|
+
return this._state(state);
|
447
|
+
},
|
448
|
+
|
449
|
+
reset : function(){
|
450
|
+
this._reset();
|
451
|
+
},
|
452
|
+
|
453
|
+
next : function(){
|
454
|
+
this._next();
|
455
|
+
},
|
456
|
+
|
457
|
+
back : function(){
|
458
|
+
this._back();
|
459
|
+
},
|
460
|
+
|
461
|
+
destroy: function() {
|
462
|
+
this.element.find("*").removeAttr("disabled").show();
|
463
|
+
this.nextButton.unbind("click").val(this.nextButtonInitinalValue).removeClass("ui-state-disabled").addClass("ui-state-active");
|
464
|
+
this.backButton.unbind("click").val(this.backButtonInitinalValue).removeClass("ui-state-disabled").addClass("ui-state-active");
|
465
|
+
this.backButtonInitinalValue = undefined;
|
466
|
+
this.nextButtonInitinalValue = undefined;
|
467
|
+
this.activatedSteps = undefined;
|
468
|
+
this.previousStep = undefined;
|
469
|
+
this.currentStep = undefined;
|
470
|
+
this.isLastStep = undefined;
|
471
|
+
this.options = undefined;
|
472
|
+
this.nextButton = undefined;
|
473
|
+
this.backButton = undefined;
|
474
|
+
this.formwizard = undefined;
|
475
|
+
this.element = undefined;
|
476
|
+
this.steps = undefined;
|
477
|
+
this.firstStep = undefined;
|
478
|
+
},
|
479
|
+
|
480
|
+
update_steps : function(){
|
481
|
+
this.steps = this.element.find(".step").addClass("ui-formwizard-content");
|
482
|
+
this.steps.not("#" + this.currentStep).hide().find(":input").addClass("ui-wizard-content").attr("disabled","disabled");
|
483
|
+
this._updateButtons();
|
484
|
+
this._checkIflastStep(this.currentStep);
|
485
|
+
this._enableNavigation();
|
486
|
+
if(!this.options.disableUIStyles){
|
487
|
+
this.steps.addClass("ui-helper-reset ui-corner-all");
|
488
|
+
this.steps.find(":input").addClass("ui-helper-reset ui-state-default");
|
489
|
+
}
|
490
|
+
},
|
491
|
+
|
492
|
+
options: {
|
493
|
+
historyEnabled : false,
|
494
|
+
validationEnabled : false,
|
495
|
+
validationOptions : undefined,
|
496
|
+
formPluginEnabled : false,
|
497
|
+
linkClass : ".link",
|
498
|
+
submitStepClass : "submit_step",
|
499
|
+
back : ":reset",
|
500
|
+
next : ":submit",
|
501
|
+
textSubmit : 'Submit',
|
502
|
+
textNext : 'Next',
|
503
|
+
textBack : 'Back',
|
504
|
+
remoteAjax : undefined,
|
505
|
+
inAnimation : {opacity: 'show'},
|
506
|
+
outAnimation: {opacity: 'hide'},
|
507
|
+
inDuration : 400,
|
508
|
+
outDuration: 400,
|
509
|
+
easing: 'swing',
|
510
|
+
focusFirstInput : false,
|
511
|
+
disableInputFields : true,
|
512
|
+
formOptions : { reset: true, success: function(data) { if( (window['console'] !== undefined) ){console.log("%s", "form submit successful");}},
|
513
|
+
disableUIStyles : false
|
514
|
+
}
|
454
515
|
}
|
455
516
|
});
|
456
517
|
})(jQuery);
|