From 30595e85a387a8738bd8568a75fdc8fa44a2289f Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Wed, 10 Apr 2013 18:24:34 -0700 Subject: [PATCH] model should automatically be bound to view. --- UI/AddSeries/RootFolders/RootFolderView.js | 4 --- UI/Calendar/CalendarItemView.js | 4 --- UI/Index.html | 1 + UI/Missing/MissingItemView.js | 4 --- UI/Mixins/AutoComplete.js | 4 ++- UI/Mixins/backbone.ajax.js | 1 + UI/Mixins/backbone.modelbinder.mixin.js | 26 +++++++++++++++++++ UI/Series/Delete/DeleteSeriesView.js | 4 --- UI/Series/Details/EpisodeItemView.js | 3 --- UI/Series/Edit/EditSeriesView.js | 1 - UI/Series/Index/SeriesItemView.js | 4 --- .../DownloadClient/DownloadClientView.js | 2 -- UI/Settings/Indexers/IndexersView.js | 4 --- UI/Settings/Misc/MiscView.js | 1 - UI/Settings/Naming/NamingView.js | 1 - .../Notifications/NotificationsView.js | 4 --- .../Quality/Profile/EditQualityProfileView.js | 1 - .../Quality/Profile/QualityProfileView.js | 7 ----- UI/Settings/Quality/QualityView.js | 4 --- UI/Settings/Quality/Size/QualitySizeView.js | 2 -- UI/Settings/System/SystemView.js | 4 --- UI/Upcoming/UpcomingItemView.js | 8 ++---- 22 files changed, 33 insertions(+), 61 deletions(-) create mode 100644 UI/Mixins/backbone.modelbinder.mixin.js diff --git a/UI/AddSeries/RootFolders/RootFolderView.js b/UI/AddSeries/RootFolders/RootFolderView.js index 08c5b3904..118352c78 100644 --- a/UI/AddSeries/RootFolders/RootFolderView.js +++ b/UI/AddSeries/RootFolders/RootFolderView.js @@ -11,10 +11,6 @@ define(['app', 'AddSeries/RootFolders/RootFolderCollection', 'Mixins/AutoComplet 'click .x-remove': 'removeFolder' }, - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - }, - removeFolder: function () { this.model.destroy({ wait: true }); this.model.collection.remove(this.model); diff --git a/UI/Calendar/CalendarItemView.js b/UI/Calendar/CalendarItemView.js index bba054684..b0da60732 100644 --- a/UI/Calendar/CalendarItemView.js +++ b/UI/Calendar/CalendarItemView.js @@ -8,9 +8,5 @@ define([ NzbDrone.Calendar.CalendarItemView = Backbone.Marionette.ItemView.extend({ template : 'Calendar/CalendarItemTemplate', tagName : 'div', - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - } }); }); \ No newline at end of file diff --git a/UI/Index.html b/UI/Index.html index fac935e11..dfadfedfc 100644 --- a/UI/Index.html +++ b/UI/Index.html @@ -112,6 +112,7 @@ + diff --git a/UI/Missing/MissingItemView.js b/UI/Missing/MissingItemView.js index 0825d384e..8b7c3e45f 100644 --- a/UI/Missing/MissingItemView.js +++ b/UI/Missing/MissingItemView.js @@ -8,9 +8,5 @@ define([ NzbDrone.Missing.MissingItemView = Backbone.Marionette.ItemView.extend({ template: 'Missing/MissingItemTemplate', tagName : 'tr', - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - } }); }); \ No newline at end of file diff --git a/UI/Mixins/AutoComplete.js b/UI/Mixins/AutoComplete.js index 8e5a913a2..f678e2135 100644 --- a/UI/Mixins/AutoComplete.js +++ b/UI/Mixins/AutoComplete.js @@ -1,4 +1,6 @@ -define(['app'], function () { +"use strict"; + +define(['app'], function () { $.fn.autoComplete = function (resource) { $(this).typeahead({ diff --git a/UI/Mixins/backbone.ajax.js b/UI/Mixins/backbone.ajax.js index 7d96a0a76..360f5a8f5 100644 --- a/UI/Mixins/backbone.ajax.js +++ b/UI/Mixins/backbone.ajax.js @@ -1,4 +1,5 @@ //try to add ajax data as query string to DELETE calls. +"use strict"; (function () { var original = Backbone.ajax; diff --git a/UI/Mixins/backbone.modelbinder.mixin.js b/UI/Mixins/backbone.modelbinder.mixin.js new file mode 100644 index 000000000..8d422f91b --- /dev/null +++ b/UI/Mixins/backbone.modelbinder.mixin.js @@ -0,0 +1,26 @@ +'use strict'; + +var oldItemViewRender = Marionette.ItemView.prototype.render; +var oldItemCollectionViewRender = Marionette.CollectionView.prototype.render; + +Marionette.ItemView.prototype.render = function () { + + if (this.model) { + NzbDrone.ModelBinder.bind(this.model, this.el); + } + + console.log("render"); + + return oldItemViewRender.apply(this, arguments); +}; + +Marionette.CollectionView.prototype.render = function () { + + if (this.model) { + NzbDrone.ModelBinder.bind(this.model, this.el); + } + + console.log("render"); + + return oldItemCollectionViewRender.apply(this, arguments); +}; diff --git a/UI/Series/Delete/DeleteSeriesView.js b/UI/Series/Delete/DeleteSeriesView.js index c94c8aa28..95fe9e0eb 100644 --- a/UI/Series/Delete/DeleteSeriesView.js +++ b/UI/Series/Delete/DeleteSeriesView.js @@ -15,10 +15,6 @@ define(['app', 'Series/SeriesModel'], function () { deleteFiles: '.x-delete-files' }, - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - }, - removeSeries: function () { var deleteFiles = this.ui.deleteFiles.prop('checked'); diff --git a/UI/Series/Details/EpisodeItemView.js b/UI/Series/Details/EpisodeItemView.js index 55f216d82..69828b905 100644 --- a/UI/Series/Details/EpisodeItemView.js +++ b/UI/Series/Details/EpisodeItemView.js @@ -12,8 +12,5 @@ define(['app', 'Series/SeasonModel'], function () { events : { }, - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - } }); }); diff --git a/UI/Series/Edit/EditSeriesView.js b/UI/Series/Edit/EditSeriesView.js index dd1897e33..3943cf282 100644 --- a/UI/Series/Edit/EditSeriesView.js +++ b/UI/Series/Edit/EditSeriesView.js @@ -19,7 +19,6 @@ define(['app', 'Series/SeriesModel', 'Series/Delete/DeleteSeriesView', 'Quality/ }, onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); this.ui.switch.bootstrapSwitch(); }, diff --git a/UI/Series/Index/SeriesItemView.js b/UI/Series/Index/SeriesItemView.js index 9593b23ff..ecad2239d 100644 --- a/UI/Series/Index/SeriesItemView.js +++ b/UI/Series/Index/SeriesItemView.js @@ -37,10 +37,6 @@ define([ this.viewStyle = options.viewStyle; }, - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - }, - editSeries: function () { var view = new NzbDrone.Series.Edit.EditSeriesView({ model: this.model}); diff --git a/UI/Settings/DownloadClient/DownloadClientView.js b/UI/Settings/DownloadClient/DownloadClientView.js index 73e9c57d5..23522c1c6 100644 --- a/UI/Settings/DownloadClient/DownloadClientView.js +++ b/UI/Settings/DownloadClient/DownloadClientView.js @@ -25,8 +25,6 @@ define([ }, onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - this.ui.switch.bootstrapSwitch(); this.ui.tooltip.tooltip({ placement: 'right', html: true }); this.ui.pathInput.autoComplete('/directories'); diff --git a/UI/Settings/Indexers/IndexersView.js b/UI/Settings/Indexers/IndexersView.js index 189cef77d..1edeb8ad0 100644 --- a/UI/Settings/Indexers/IndexersView.js +++ b/UI/Settings/Indexers/IndexersView.js @@ -7,9 +7,5 @@ define([ NzbDrone.Settings.Indexers.IndexersView = Backbone.Marionette.ItemView.extend({ template: 'Settings/Indexers/IndexersTemplate', - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - } }); }); diff --git a/UI/Settings/Misc/MiscView.js b/UI/Settings/Misc/MiscView.js index b21de4b03..ad6f47c97 100644 --- a/UI/Settings/Misc/MiscView.js +++ b/UI/Settings/Misc/MiscView.js @@ -15,7 +15,6 @@ define([ }, onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); this.ui.switch.bootstrapSwitch(); this.ui.tooltip.tooltip({ placement: 'right', html: true }); } diff --git a/UI/Settings/Naming/NamingView.js b/UI/Settings/Naming/NamingView.js index f13219494..69bebed35 100644 --- a/UI/Settings/Naming/NamingView.js +++ b/UI/Settings/Naming/NamingView.js @@ -19,7 +19,6 @@ define([ }, onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); this.ui.switch.bootstrapSwitch(); this.ui.tooltip.tooltip({ placement: 'right' }); } diff --git a/UI/Settings/Notifications/NotificationsView.js b/UI/Settings/Notifications/NotificationsView.js index 8b8168e6d..5c893edaa 100644 --- a/UI/Settings/Notifications/NotificationsView.js +++ b/UI/Settings/Notifications/NotificationsView.js @@ -7,9 +7,5 @@ define([ NzbDrone.Settings.Notifications.NotificationsView = Backbone.Marionette.ItemView.extend({ template: 'Settings/Notifications/NotificationsTemplate', - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - } }); }); diff --git a/UI/Settings/Quality/Profile/EditQualityProfileView.js b/UI/Settings/Quality/Profile/EditQualityProfileView.js index eaed084f5..0e88b9702 100644 --- a/UI/Settings/Quality/Profile/EditQualityProfileView.js +++ b/UI/Settings/Quality/Profile/EditQualityProfileView.js @@ -15,7 +15,6 @@ define(['app', 'Quality/QualityProfileModel'], function () { }, onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); this.ui.switch.bootstrapSwitch(); }, diff --git a/UI/Settings/Quality/Profile/QualityProfileView.js b/UI/Settings/Quality/Profile/QualityProfileView.js index c1a176b18..6aa240d02 100644 --- a/UI/Settings/Quality/Profile/QualityProfileView.js +++ b/UI/Settings/Quality/Profile/QualityProfileView.js @@ -20,13 +20,6 @@ define([ 'click .x-remove': 'removeSeries' }, - initialize: function () { - }, - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - }, - editSeries: function () { var view = new NzbDrone.Settings.Quality.Profile.EditQualityProfileView({ model: this.model}); diff --git a/UI/Settings/Quality/QualityView.js b/UI/Settings/Quality/QualityView.js index 2aa9a2a34..103b76be1 100644 --- a/UI/Settings/Quality/QualityView.js +++ b/UI/Settings/Quality/QualityView.js @@ -13,9 +13,5 @@ define([ this.qualityProfileCollection = options.qualityProfiles; this.model.set({ qualityProfiles: this.qualityProfileCollection }); }, - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - } }); }); diff --git a/UI/Settings/Quality/Size/QualitySizeView.js b/UI/Settings/Quality/Size/QualitySizeView.js index 226f99b32..ccce82543 100644 --- a/UI/Settings/Quality/Size/QualitySizeView.js +++ b/UI/Settings/Quality/Size/QualitySizeView.js @@ -25,8 +25,6 @@ define([ }, onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - var self = this; this.ui.slider.slider({ min : 0, diff --git a/UI/Settings/System/SystemView.js b/UI/Settings/System/SystemView.js index 6763199f9..dd6ea6668 100644 --- a/UI/Settings/System/SystemView.js +++ b/UI/Settings/System/SystemView.js @@ -7,9 +7,5 @@ define([ NzbDrone.Settings.System.SystemView = Backbone.Marionette.ItemView.extend({ template: 'Settings/System/SystemTemplate', - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - } }); }); diff --git a/UI/Upcoming/UpcomingItemView.js b/UI/Upcoming/UpcomingItemView.js index c2bc7b1b3..b8830fccb 100644 --- a/UI/Upcoming/UpcomingItemView.js +++ b/UI/Upcoming/UpcomingItemView.js @@ -8,9 +8,5 @@ define([ NzbDrone.Upcoming.UpcomingItemView = Backbone.Marionette.ItemView.extend({ template: 'Upcoming/UpcomingItemTemplate', tagName : 'tr', - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - } - }) -}) \ No newline at end of file + }); +}); \ No newline at end of file