-
Notifications
You must be signed in to change notification settings - Fork 22
/
ionic.js
244 lines (227 loc) · 6.1 KB
/
ionic.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
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
/*
* Template helpers for "ionic" template
*/
Template['quickForm_ionic'].helpers({
submitButtonAtts: function bsQuickFormSubmitButtonAtts() {
var qfAtts = this.atts;
var atts = {};
if (typeof qfAtts.buttonClasses === "string") {
atts['class'] = qfAtts.buttonClasses;
} else {
atts['class'] = 'button button-positive button-block';
}
return atts;
}
});
Template['afFormGroup_ionic'].helpers({
skipLabel: function bsFormGroupSkipLabel() {
var self = this;
var skipLabelTypes = [
"checkbox", "checkbox-group", "boolean-checkbox", "select-checkbox",
"select-radio", "select-radio-group", "select-radio-group-inline", "boolean-radio", "boolean-radio-group",
"select", "boolean-select", "select-multiple",
"toggle"
];
var type = AutoForm.getInputType(self.afFieldInputAtts);
return (self.skipLabel || _.contains(skipLabelTypes, type));
},
ionicFieldLabelAtts: function ionicFieldLabelAtts() {
var atts = _.clone(this.afFieldLabelAtts);
var classes = ['item', 'item-input'];
if (atts.type === 'placeholder') {
atts.placeholderOnly = true;
} else if (atts.type === 'stacked') {
classes.push('item-stacked-label');
}
else if (atts.type === 'floating') {
classes.push('item-floating-label');
}
atts = AutoForm.Utility.addClass(atts, classes.join(' '));
return atts;
}
});
_.each([
"afSelect_ionic",
"afBooleanSelect_ionic",
"afSelectMultiple_ionic",
"afTextarea_ionic",
"afInputText_ionic",
"afInputPassword_ionic",
"afInputDateTime_ionic",
"afInputDateTimeLocal_ionic",
"afInputDate_ionic",
"afInputMonth_ionic",
"afInputTime_ionic",
"afInputWeek_ionic",
"afInputNumber_ionic",
"afInputEmail_ionic",
"afInputUrl_ionic",
"afInputSearch_ionic",
"afInputTel_ionic",
"afInputColor_ionic"
], function (tmplName) {
Template[tmplName].helpers({
atts: function addFormControlAtts() {
var atts = _.clone(this.atts);
return atts;
}
});
});
_.each([
"afInputButton_ionic",
"afInputSubmit_ionic",
"afInputReset_ionic",
], function (tmplName) {
Template[tmplName].helpers({
atts: function addFormControlAtts() {
var atts = _.clone(this.atts);
// Add bootstrap class
atts = AutoForm.Utility.addClass(atts, "button");
return atts;
}
});
});
Template["afRadio_ionic"].helpers({
atts: function selectedAttsAdjust() {
var atts = _.clone(this.atts);
if (this.selected) {
atts.checked = "";
}
return atts;
}
});
_.each([
"afCheckboxGroup_ionic",
"afRadioGroup_ionic",
"afCheckboxGroupInline_ionic",
"afRadioGroupInline_ionic"
], function (tmplName) {
Template[tmplName].helpers({
atts: function selectedAttsAdjust() {
var atts = _.clone(this.atts);
if (this.selected) {
atts.checked = "";
}
// remove data-schema-key attribute because we put it
// on the entire group
delete atts["data-schema-key"];
return atts;
},
dsk: function dsk() {
return {
"data-schema-key": this.atts["data-schema-key"]
}
}
});
});
var selectHelpers = {
optionAtts: function afSelectOptionAtts() {
var item = this;
var atts = {
value: item.value
};
if (item.selected) {
atts.selected = "";
}
return atts;
}
};
Template["afSelect_ionic"].helpers(selectHelpers);
Template["afSelectMultiple_ionic"].helpers(selectHelpers);
Template["afBooleanSelect_ionic"].helpers(selectHelpers);
Template["afBooleanRadioGroup_ionic"].helpers({
falseAtts: function falseAtts() {
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'data-schema-key');
if (this.value === false) {
atts.checked = "";
}
return atts;
},
trueAtts: function trueAtts() {
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'data-schema-key');
if (this.value === true) {
atts.checked = "";
}
return atts;
},
dsk: function () {
return {'data-schema-key': this.atts['data-schema-key']};
}
});
// Custom Ionic input types:
AutoForm.addInputType("toggle", {
template: "afToggle",
valueOut: function () {
return !!this.is(":checked");
},
valueConverters: {
"boolean": function (val) {
if (val === "true") {
return true;
} else if (val === "false") {
return false;
}
return val;
},
"string": function (val) {
if (val === true) {
return "TRUE";
} else if (val === false) {
return "FALSE";
}
return val;
},
"stringArray": function (val) {
if (val === true) {
return ["TRUE"];
} else if (val === false) {
return ["FALSE"];
}
return val;
},
"number": function (val) {
if (val === true) {
return 1;
} else if (val === false) {
return 0;
}
return val;
},
"numberArray": function (val) {
if (val === true) {
return [1];
} else if (val === false) {
return [0];
}
return val;
}
},
contextAdjust: function (context) {
if (context.value === true) {
context.atts.checked = "";
}
//don't add required attribute to checkboxes because some browsers assume that to mean that it must be checked, which is not what we mean by "required"
delete context.atts.required;
return context;
}
});
// Floating Labels: http://ionicframework.com/docs/components/#forms-floating-labels
// 'label-type': 'floating'
Template.afFormGroup_ionic.rendered = function () {
var template = this;
var isFloating = template.$('.item-floating-label').length;
if (isFloating) {
template.$('input, textarea').on('keyup.item-floating-label', function (event) {
if ($(this).val() !== '') {
template.$('.item-floating-label .input-label').addClass('has-input');
} else {
template.$('.item-floating-label .input-label').removeClass('has-input');
}
});
template.$('input').trigger('keydown.item-floating-label');
}
};
Template.afFormGroup_ionic.destroyed = function () {
var template = this;
template.$('input').off('keyup.item-floating-label');
};