From 467c88f71126681f39f84394253130278cacda1d Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 20 Jun 2013 22:35:56 -0700 Subject: [PATCH] moved mixins to require.js --- .../backbone.marionette.templates.js | 0 UI/History/Row.js | 14 --- UI/Missing/MissingLayout.js | 89 +++++++++---------- UI/Missing/Row.js | 24 ++--- UI/Mixins/backbone.ajax.js | 29 +++--- UI/app.js | 14 +-- 6 files changed, 81 insertions(+), 89 deletions(-) rename UI/{Mixins => Handlebars}/backbone.marionette.templates.js (100%) delete mode 100644 UI/History/Row.js diff --git a/UI/Mixins/backbone.marionette.templates.js b/UI/Handlebars/backbone.marionette.templates.js similarity index 100% rename from UI/Mixins/backbone.marionette.templates.js rename to UI/Handlebars/backbone.marionette.templates.js diff --git a/UI/History/Row.js b/UI/History/Row.js deleted file mode 100644 index e6aae27c1..000000000 --- a/UI/History/Row.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -define(['app','backgrid'], function () { - NzbDrone.Missing.Row = Backgrid.Row.extend({ - events: { - 'click .x-search': 'search' - }, - - search: function () { - window.alert('Episode Search'); - } - }); - - return NzbDrone.Missing.Row; -}); diff --git a/UI/Missing/MissingLayout.js b/UI/Missing/MissingLayout.js index 29c0f06e1..e972d588e 100644 --- a/UI/Missing/MissingLayout.js +++ b/UI/Missing/MissingLayout.js @@ -1,19 +1,19 @@ "use strict"; -define([ - 'app', - 'Missing/Collection', - 'Missing/Row', - 'Cells/AirDateCell', - 'Series/Index/Table/SeriesStatusCell', - 'Shared/Toolbar/ToolbarLayout', - 'Cells/SeriesTitleCell', - 'Cells/EpisodeNumberCell', - 'Cells/EpisodeTitleCell', - 'Cells/AirDateCell', - 'Shared/Grid/Pager', - 'Shared/LoadingView' -], - function () { +define( + [ + 'app', + 'Missing/Row', + 'Missing/Collection', + 'Cells/AirDateCell', + 'Series/Index/Table/SeriesStatusCell', + 'Shared/Toolbar/ToolbarLayout', + 'Cells/SeriesTitleCell', + 'Cells/EpisodeNumberCell', + 'Cells/EpisodeTitleCell', + 'Cells/AirDateCell', + 'Shared/Grid/Pager', + 'Shared/LoadingView' + ], function (App, MissingRow) { NzbDrone.Missing.MissingLayout = Backbone.Marionette.Layout.extend({ template: 'Missing/MissingLayoutTemplate', @@ -23,36 +23,36 @@ define([ pager : '#x-pager' }, - columns: [ - { - name : 'series', - label : 'Series Title', - sortable: false, - cell : NzbDrone.Cells.SeriesTitleCell - }, - { - name : 'this', - label : 'Episode', - sortable: false, - cell : NzbDrone.Cells.EpisodeNumberCell - }, - { - name : 'this', - label : 'Episode Title', - sortable: false, - cell : NzbDrone.Cells.EpisodeTitleCell - }, - { - name : 'airDate', - label: 'Air Date', - cell : NzbDrone.Cells.AirDateCell - } - ], + columns: + [ + { + name : 'series', + label : 'Series Title', + sortable: false, + cell : NzbDrone.Cells.SeriesTitleCell + }, + { + name : 'this', + label : 'Episode', + sortable: false, + cell : NzbDrone.Cells.EpisodeNumberCell + }, + { + name : 'this', + label : 'Episode Title', + sortable: false, + cell : NzbDrone.Cells.EpisodeTitleCell + }, + { + name : 'airDate', + label: 'Air Date', + cell : NzbDrone.Cells.AirDateCell + } + ], _showTable: function () { - this.missing.show(new Backgrid.Grid( - { - row : NzbDrone.Missing.Row, + this.missing.show(new Backgrid.Grid({ + row : MissingRow, columns : this.columns, collection: this.missingCollection, className : 'table table-hover' @@ -70,8 +70,7 @@ define([ this.missing.show(new NzbDrone.Shared.LoadingView()); this.missingCollection = new NzbDrone.Missing.Collection(); - this.missingCollection.fetch() - .done(function () { + this.missingCollection.fetch().done(function () { self._showTable(); }); } diff --git a/UI/Missing/Row.js b/UI/Missing/Row.js index dc3d998b5..30af3d97a 100644 --- a/UI/Missing/Row.js +++ b/UI/Missing/Row.js @@ -1,16 +1,16 @@ "use strict"; -define(['app','backgrid'], function () { +define( + [ + 'backgrid' + ], function (Backgrid) { - NzbDrone.Missing.Row = Backgrid.Row.extend({ - events: { - 'click .x-search': 'search' - }, - - search: function () { - window.alert('Episode Search'); - } + return Backgrid.Row.extend({ + events: { + 'click .x-search': 'search' + }, + search: function () { + window.alert('Episode Search'); + } + }); }); - return NzbDrone.Mixins.Row; - -}); diff --git a/UI/Mixins/backbone.ajax.js b/UI/Mixins/backbone.ajax.js index 139b4c0c4..e56c5e89c 100644 --- a/UI/Mixins/backbone.ajax.js +++ b/UI/Mixins/backbone.ajax.js @@ -1,23 +1,26 @@ //try to add ajax data as query string to DELETE calls. "use strict"; -define(['jquery'], function () { +define(function () { - var original = Backbone.ajax; + return function () { - Backbone.ajax = function () { + var original = this.ajax; + this.ajax = function () { - var xhr = arguments[0]; + var xhr = arguments[0]; - //check if ajax call was made with data option - if (xhr && xhr.data && xhr.type === 'DELETE') { - if (xhr.url.indexOf('?') === -1) { - xhr.url = xhr.url + '?' + $.param(xhr.data); + //check if ajax call was made with data option + if (xhr && xhr.data && xhr.type === 'DELETE') { + if (xhr.url.indexOf('?') === -1) { + xhr.url = xhr.url + '?' + $.param(xhr.data); + } + else { + xhr.url = xhr.url + '&' + $.param(xhr.data); + } } - else { - xhr.url = xhr.url + '&' + $.param(xhr.data); - } - } - return original.apply(this, arguments); + return original.apply(this, arguments); + }; }; + }); diff --git a/UI/app.js b/UI/app.js index 3c76d590e..393c91112 100644 --- a/UI/app.js +++ b/UI/app.js @@ -68,10 +68,14 @@ require.config({ backbone: { deps : [ + 'mixins/backbone.ajax', 'underscore', '$' ], - exports: 'Backbone' + exports: 'Backbone', + init : function (AjaxMixin) { + AjaxMixin.apply(Backbone); + } }, @@ -87,7 +91,7 @@ require.config({ [ 'backbone', 'handlebars', - 'mixins/backbone.marionette.templates', + 'Handlebars/backbone.marionette.templates', 'mixins/AsNamedView', 'Handlebars/Helpers/DateTime' @@ -122,6 +126,9 @@ require.config({ [ 'backbone' ], + + exports: 'Backgrid', + init: function () { Backgrid.Column.prototype.defaults = { name : undefined, @@ -199,7 +206,6 @@ define( window.NzbDrone.History = {}; window.NzbDrone.Logs = {}; window.NzbDrone.Release = {}; - window.NzbDrone.Mixins = {}; window.NzbDrone.Events = { SeriesAdded: 'seriesAdded' @@ -214,9 +220,7 @@ define( }; window.NzbDrone.addInitializer(function () { - console.log('starting application'); - }); NzbDrone.addRegions({