1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/UI/Form/FormBuilder.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

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