|
|
@ -4,45 +4,50 @@ define(
|
|
|
|
'handlebars'
|
|
|
|
'handlebars'
|
|
|
|
], function (Handlebars) {
|
|
|
|
], function (Handlebars) {
|
|
|
|
|
|
|
|
|
|
|
|
var formBuilder = function (field) {
|
|
|
|
var _fieldBuilder = function (field) {
|
|
|
|
if (!field.type) {
|
|
|
|
if (!field.type) {
|
|
|
|
return Handlebars.helpers.partial.apply(field,
|
|
|
|
return _templateRenderer.apply(field,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'Form/TextboxTemplate'
|
|
|
|
'Form/TextboxTemplate'
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (field.type === 'password') {
|
|
|
|
if (field.type === 'password') {
|
|
|
|
return Handlebars.helpers.partial.apply(field,
|
|
|
|
return _templateRenderer.apply(field,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'Form/PasswordTemplate'
|
|
|
|
'Form/PasswordTemplate'
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (field.type === 'checkbox') {
|
|
|
|
if (field.type === 'checkbox') {
|
|
|
|
return Handlebars.helpers.partial.apply(field,
|
|
|
|
return _templateRenderer.apply(field,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'Form/CheckboxTemplate'
|
|
|
|
'Form/CheckboxTemplate'
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (field.type === 'select') {
|
|
|
|
if (field.type === 'select') {
|
|
|
|
return Handlebars.helpers.partial.apply(field,
|
|
|
|
return _templateRenderer.apply(field,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'Form/SelectTemplate'
|
|
|
|
'Form/SelectTemplate'
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Handlebars.helpers.partial.apply(field,
|
|
|
|
return _templateRenderer.apply(field,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'Form/TextboxTemplate'
|
|
|
|
'Form/TextboxTemplate'
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _templateRenderer = function (templateName) {
|
|
|
|
|
|
|
|
var templateFunction = Marionette.TemplateCache.get(templateName);
|
|
|
|
|
|
|
|
return new Handlebars.SafeString(templateFunction(this));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Handlebars.registerHelper('formBuilder', function () {
|
|
|
|
Handlebars.registerHelper('formBuilder', function () {
|
|
|
|
var ret = '';
|
|
|
|
var ret = '';
|
|
|
|
_.each(this.fields, function (field) {
|
|
|
|
_.each(this.fields, function (field) {
|
|
|
|
ret += this.FieldBuilder(field);
|
|
|
|
ret += _fieldBuilder(field);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return new Handlebars.SafeString(ret);
|
|
|
|
return new Handlebars.SafeString(ret);
|
|
|
|