diff --git a/UI/Controller.js b/UI/Controller.js index e86e42d3c..aa546a243 100644 --- a/UI/Controller.js +++ b/UI/Controller.js @@ -1,10 +1,16 @@ "use strict"; -define(['app', 'AddSeries/AddSeriesLayout', +define(['app', + 'Form/FormBuilder', + 'AddSeries/AddSeriesLayout', 'Series/Index/SeriesIndexLayout', - 'Calendar/CalendarCollectionView', 'Shared/NotificationView', - 'Shared/NotFoundView', 'MainMenuView', - 'Series/Details/SeriesDetailsView', 'Series/EpisodeCollection', - 'Settings/SettingsLayout', 'Missing/MissingLayout', + 'Calendar/CalendarCollectionView', + 'Shared/NotificationView', + 'Shared/NotFoundView', + 'MainMenuView', + 'Series/Details/SeriesDetailsView', + 'Series/EpisodeCollection', + 'Settings/SettingsLayout', + 'Missing/MissingLayout', 'History/HistoryLayout'], function () { var controller = Backbone.Marionette.Controller.extend({ diff --git a/UI/Form/FormBuilder.js b/UI/Form/FormBuilder.js new file mode 100644 index 000000000..512b5b9de --- /dev/null +++ b/UI/Form/FormBuilder.js @@ -0,0 +1,27 @@ +'use strict'; +define(['app'], function () { + Handlebars.registerHelper('formBuilder', function (){ + var ret = ""; + _.each(this.fields, function(field){ + ret += NzbDrone.Form.FieldBuilder(field); + }); + + return new Handlebars.SafeString(ret); + }); + + NzbDrone.Form.FieldBuilder = function(field) { + if (!field.type) { + return Handlebars.helpers.partial.apply(field, ['Form/TextboxTemplate']); + } + + if (field.type === 'password') { + return Handlebars.helpers.partial.apply(field, ['Form/PasswordTemplate']); + } + + if (field.type === 'checkbox') { + return Handlebars.helpers.partial.apply(field, ['Form/CheckboxTemplate']); + } + + return Handlebars.helpers.partial.apply(field, ['Form/TextboxTemplate']); + }; +}); diff --git a/UI/Mixins/handlebars.mixin.js b/UI/Mixins/handlebars.mixin.js index cb0b7b14c..dcbfd488a 100644 --- a/UI/Mixins/handlebars.mixin.js +++ b/UI/Mixins/handlebars.mixin.js @@ -7,22 +7,6 @@ Handlebars.registerHelper('partial', function (templateName) { return new Handlebars.SafeString(templateFunction(this)); }); -Handlebars.registerHelper('formField', function () { - if (!this.type) { - return Handlebars.helpers.partial.apply(this, ['Form/TextboxTemplate']); - } - - if (this.type === 'password') { - return Handlebars.helpers.partial.apply(this, ['Form/PasswordTemplate']); - } - - if (this.type === 'checkbox') { - return Handlebars.helpers.partial.apply(this, ['Form/CheckboxTemplate']); - } - - return Handlebars.helpers.partial.apply(this, ['Form/TextboxTemplate']); -}); - Handlebars.registerHelper("debug", function(optionalValue) { console.log("Current Context"); console.log("===================="); diff --git a/UI/Settings/Notifications/EditTemplate.html b/UI/Settings/Notifications/EditTemplate.html index f31574abd..c2aa4abac 100644 --- a/UI/Settings/Notifications/EditTemplate.html +++ b/UI/Settings/Notifications/EditTemplate.html @@ -52,9 +52,7 @@ - {{#each fields}} - {{formField}} - {{/each}} + {{formBuilder}}