forked from forwarder/meteor-wizard-example
-
Notifications
You must be signed in to change notification settings - Fork 1
/
autoform-wizard-example.js
128 lines (112 loc) · 2.79 KB
/
autoform-wizard-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
Orders = new Meteor.Collection('orders');
Schema = {};
Schema.contactInformation = new SimpleSchema({
name: {
type: String,
label: 'Name'
},
address: {
type: String,
label: 'Address'
},
zipcode: {
type: String,
label: 'Zipcode'
},
city: {
type: String,
label: 'City',
optional: true
}
});
Schema.paymentInformation = new SimpleSchema({
paymentMethod: {
type: String,
label: 'Payment method',
allowedValues: ['credit-card', 'bank-transfer'],
autoform: {
options: [{
label: 'Credit card',
value: 'credit-card'
}, {
label: 'Bank transfer',
value: 'bank-transfer'
}]
}
},
acceptTerms: {
type: Boolean,
label: 'I accept the terms and conditions.',
autoform: {
label: false
},
autoValue: function () {
if (this.isSet && this.value !== true) {
this.unset();
}
}
}
});
Schema.Orders = new SimpleSchema({
contactInformation: {
type: Schema.contactInformation
},
paymentInformation: {
type: Schema.paymentInformation
}
});
Orders.attachSchema(Schema.Orders);
if (Meteor.isClient) {
Meteor.startup(function () {
AutoForm.setDefaultTemplate("semanticUI");
Template.afCheckbox_semanticUI.onRendered(function () {
$(this.firstNode).checkbox();
});
});
Template.registerHelper('Schema', function () {
return Schema;
});
Template.steps.helpers({
stepClass: function (id) {
var activeStep = this.wizard.activeStep();
var step = this.wizard.getStep(id);
if (activeStep && activeStep.id === id) {
return 'active';
}
if (step.data()) {
return 'completed';
}
return 'disabled';
}
});
AutoForm.addHooks(['newOrderWizard', 'editOrderWizard'], {
onSuccess: function (formType, result) {
console.log("SUCCESS:", result);
Router.go('viewOrder', {_id: result});
},
onError: function (formType, error) {
console.log("ERROR:", error);
}
});
}
Router.configure({
layoutTemplate: 'layout'
});
Router.route('/', function () {
this.redirect('newOrder');
});
Router.route('/order/new/:step?', {
name: 'newOrder'
});
Router.route('/order/:_id', {
name: 'viewOrder',
data: function () {
return Orders.findOne(this.params._id);
}
});
Router.route('/order/:_id/edit/:step?', {
name: 'editOrder',
data: function () {
return Orders.findOne(this.params._id);
}
});