2013-05-22 03:33:35 +00:00
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'handlebars'
|
|
|
|
], function (Handlebars) {
|
2013-05-22 03:33:35 +00:00
|
|
|
|
2013-06-25 15:28:40 +00:00
|
|
|
var _fieldBuilder = function (field) {
|
2013-06-24 23:41:59 +00:00
|
|
|
if (!field.type) {
|
2013-06-25 15:28:40 +00:00
|
|
|
return _templateRenderer.apply(field,
|
2013-06-24 23:41:59 +00:00
|
|
|
[
|
|
|
|
'Form/TextboxTemplate'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (field.type === 'password') {
|
2013-06-25 15:28:40 +00:00
|
|
|
return _templateRenderer.apply(field,
|
2013-06-24 23:41:59 +00:00
|
|
|
[
|
|
|
|
'Form/PasswordTemplate'
|
|
|
|
]);
|
|
|
|
}
|
2013-05-22 03:33:35 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
if (field.type === 'checkbox') {
|
2013-06-25 15:28:40 +00:00
|
|
|
return _templateRenderer.apply(field,
|
2013-06-24 23:41:59 +00:00
|
|
|
[
|
|
|
|
'Form/CheckboxTemplate'
|
|
|
|
]);
|
|
|
|
}
|
2013-05-22 03:33:35 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
if (field.type === 'select') {
|
2013-06-25 15:28:40 +00:00
|
|
|
return _templateRenderer.apply(field,
|
2013-06-24 23:41:59 +00:00
|
|
|
[
|
|
|
|
'Form/SelectTemplate'
|
|
|
|
]);
|
|
|
|
}
|
2013-05-22 03:33:35 +00:00
|
|
|
|
2013-06-25 15:28:40 +00:00
|
|
|
return _templateRenderer.apply(field,
|
2013-06-24 23:41:59 +00:00
|
|
|
[
|
|
|
|
'Form/TextboxTemplate'
|
|
|
|
]);
|
|
|
|
};
|
2013-05-22 03:33:35 +00:00
|
|
|
|
2013-06-25 15:28:40 +00:00
|
|
|
var _templateRenderer = function (templateName) {
|
|
|
|
var templateFunction = Marionette.TemplateCache.get(templateName);
|
|
|
|
return new Handlebars.SafeString(templateFunction(this));
|
|
|
|
};
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
Handlebars.registerHelper('formBuilder', function () {
|
|
|
|
var ret = '';
|
|
|
|
_.each(this.fields, function (field) {
|
2013-06-25 15:28:40 +00:00
|
|
|
ret += _fieldBuilder(field);
|
2013-06-24 23:41:59 +00:00
|
|
|
});
|
2013-06-13 07:20:33 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
return new Handlebars.SafeString(ret);
|
|
|
|
});
|
|
|
|
});
|