diff --git a/src/UI/Settings/MediaManagement/MediaManagementLayout.js b/src/UI/Settings/MediaManagement/MediaManagementLayout.js index 47d670a40..eb31dcb77 100644 --- a/src/UI/Settings/MediaManagement/MediaManagementLayout.js +++ b/src/UI/Settings/MediaManagement/MediaManagementLayout.js @@ -3,7 +3,7 @@ define( [ 'marionette', - 'Settings/MediaManagement/Naming/View', + 'Settings/MediaManagement/Naming/NamingView', 'Settings/MediaManagement/Sorting/View', 'Settings/MediaManagement/FileManagement/FileManagementView' ], function (Marionette, NamingView, SortingView, FileManagementView) { diff --git a/src/UI/Settings/MediaManagement/Naming/NamingSampleModel.js b/src/UI/Settings/MediaManagement/Naming/NamingSampleModel.js new file mode 100644 index 000000000..fd833e32f --- /dev/null +++ b/src/UI/Settings/MediaManagement/Naming/NamingSampleModel.js @@ -0,0 +1,10 @@ +'use strict'; +define( + [ + 'backbone' + ], function (Backbone) { + return Backbone.Model.extend({ + url: window.NzbDrone.ApiRoot + '/config/naming/samples' + }); + + }); diff --git a/src/UI/Settings/MediaManagement/Naming/View.js b/src/UI/Settings/MediaManagement/Naming/NamingView.js similarity index 60% rename from src/UI/Settings/MediaManagement/Naming/View.js rename to src/UI/Settings/MediaManagement/Naming/NamingView.js index 1623285fb..3acadee56 100644 --- a/src/UI/Settings/MediaManagement/Naming/View.js +++ b/src/UI/Settings/MediaManagement/Naming/NamingView.js @@ -2,11 +2,12 @@ define( [ 'marionette', + 'Settings/MediaManagement/Naming/NamingSampleModel', 'Mixins/AsModelBoundView' - ], function (Marionette, AsModelBoundView) { + ], function (Marionette, NamingSampleModel, AsModelBoundView) { var view = Marionette.ItemView.extend({ - template: 'Settings/MediaManagement/Naming/ViewTemplate', + template: 'Settings/MediaManagement/Naming/NamingViewTemplate', ui: { namingOptions : '.x-naming-options', @@ -24,8 +25,11 @@ define( this.ui.namingOptions.hide(); } - this.listenTo(this.model, 'change', this._updateExamples); - this._updateExamples(); + this.namingSampleModel = new NamingSampleModel(); + + this.listenTo(this.model, 'change', this._updateSamples); + this.listenTo(this.namingSampleModel, 'sync', this._showSamples); + this._updateSamples(); }, _setNamingOptionsVisibility: function () { @@ -39,20 +43,13 @@ define( } }, - _updateExamples: function () { - //TODO: make this use events/listeners - var self = this; - - var promise = $.ajax({ - type: 'GET', - url : window.NzbDrone.ApiRoot + '/config/naming/samples', - data: this.model.toJSON() - }); + _updateSamples: function () { + this.namingSampleModel.fetch({ data: this.model.toJSON() }); + }, - promise.done(function (result) { - self.ui.singleEpisodeExample.html(result.singleEpisodeExample); - self.ui.multiEpisodeExample.html(result.multiEpisodeExample); - }); + _showSamples: function () { + this.ui.singleEpisodeExample.html(this.namingSampleModel.get('singleEpisodeExample')); + this.ui.multiEpisodeExample.html(this.namingSampleModel.get('multiEpisodeExample')); } }); diff --git a/src/UI/Settings/MediaManagement/Naming/ViewTemplate.html b/src/UI/Settings/MediaManagement/Naming/NamingViewTemplate.html similarity index 100% rename from src/UI/Settings/MediaManagement/Naming/ViewTemplate.html rename to src/UI/Settings/MediaManagement/Naming/NamingViewTemplate.html