From 8ba29fde949288c7987b1afd123042a08e61a22e Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 14 Feb 2013 10:01:30 -0800 Subject: [PATCH] everything should be moved to require.js --- NzbDrone.Web/NzbDrone.Web.csproj | 22 ++--- ...les-1.10.0-dev.js => jquery.dataTables.js} | 0 NzbDrone.Web/_backboneApp/Routing.js | 4 +- .../{ => Delete}/DeleteSeriesTemplate.html | 0 .../Series/Delete/DeleteSeriesView.js | 29 ++++++ .../_backboneApp/Series/DeleteSeriesView.js | 29 ------ .../Series/{ => Edit}/EditSeriesTemplate.html | 0 .../Series/Edit/EditSeriesView.js | 50 ++++++++++ .../_backboneApp/Series/EditSeriesView.js | 52 ---------- .../_backboneApp/Series/Index/IndexLayout.js | 33 ------- .../Series/Index/SeriesItemView.js | 98 ------------------- .../_backboneApp/Series/SeriesCollection.js | 11 +-- .../{Index => }/SeriesCollectionTemplate.html | 0 .../Series/SeriesCollectionView.js | 57 +++++++++++ .../{Index => }/SeriesItemTemplate.html | 0 .../_backboneApp/Series/SeriesItemView.js | 48 +++++++++ .../_backboneApp/Series/SeriesLayout.js | 33 +++++++ ...emplate.html => SeriesLayoutTemplate.html} | 0 NzbDrone.Web/_backboneApp/app.js | 19 +++- 19 files changed, 253 insertions(+), 232 deletions(-) rename NzbDrone.Web/_backboneApp/JsLibraries/{jquery.dataTables-1.10.0-dev.js => jquery.dataTables.js} (100%) rename NzbDrone.Web/_backboneApp/Series/{ => Delete}/DeleteSeriesTemplate.html (100%) create mode 100644 NzbDrone.Web/_backboneApp/Series/Delete/DeleteSeriesView.js delete mode 100644 NzbDrone.Web/_backboneApp/Series/DeleteSeriesView.js rename NzbDrone.Web/_backboneApp/Series/{ => Edit}/EditSeriesTemplate.html (100%) create mode 100644 NzbDrone.Web/_backboneApp/Series/Edit/EditSeriesView.js delete mode 100644 NzbDrone.Web/_backboneApp/Series/EditSeriesView.js delete mode 100644 NzbDrone.Web/_backboneApp/Series/Index/IndexLayout.js delete mode 100644 NzbDrone.Web/_backboneApp/Series/Index/SeriesItemView.js rename NzbDrone.Web/_backboneApp/Series/{Index => }/SeriesCollectionTemplate.html (100%) create mode 100644 NzbDrone.Web/_backboneApp/Series/SeriesCollectionView.js rename NzbDrone.Web/_backboneApp/Series/{Index => }/SeriesItemTemplate.html (100%) create mode 100644 NzbDrone.Web/_backboneApp/Series/SeriesItemView.js create mode 100644 NzbDrone.Web/_backboneApp/Series/SeriesLayout.js rename NzbDrone.Web/_backboneApp/Series/{Index/IndexLayoutTemplate.html => SeriesLayoutTemplate.html} (100%) diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 1d5bbbae5..683bde29f 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -220,7 +220,7 @@ - + @@ -416,18 +416,19 @@ - - + + + - - - - - - + + + + + + - + @@ -441,7 +442,6 @@ - diff --git a/NzbDrone.Web/_backboneApp/JsLibraries/jquery.dataTables-1.10.0-dev.js b/NzbDrone.Web/_backboneApp/JsLibraries/jquery.dataTables.js similarity index 100% rename from NzbDrone.Web/_backboneApp/JsLibraries/jquery.dataTables-1.10.0-dev.js rename to NzbDrone.Web/_backboneApp/JsLibraries/jquery.dataTables.js diff --git a/NzbDrone.Web/_backboneApp/Routing.js b/NzbDrone.Web/_backboneApp/Routing.js index aba5a79ef..e2c05755f 100644 --- a/NzbDrone.Web/_backboneApp/Routing.js +++ b/NzbDrone.Web/_backboneApp/Routing.js @@ -1,4 +1,4 @@ -require(['app','Shared/NotificationView', 'AddSeries/AddSeriesLayout'], function () { +require(['app','Shared/NotificationView', 'AddSeries/AddSeriesLayout','Series/SeriesLayout'], function () { NzbDrone.Controller = Backbone.Marionette.Controller.extend({ @@ -7,7 +7,7 @@ }, series: function (action, query) { - NzbDrone.mainRegion.show(new NzbDrone.Series.IndexLayout(this, action, query)); + NzbDrone.mainRegion.show(new NzbDrone.Series.SeriesLayout(this, action, query)); }, notFound: function () { diff --git a/NzbDrone.Web/_backboneApp/Series/DeleteSeriesTemplate.html b/NzbDrone.Web/_backboneApp/Series/Delete/DeleteSeriesTemplate.html similarity index 100% rename from NzbDrone.Web/_backboneApp/Series/DeleteSeriesTemplate.html rename to NzbDrone.Web/_backboneApp/Series/Delete/DeleteSeriesTemplate.html diff --git a/NzbDrone.Web/_backboneApp/Series/Delete/DeleteSeriesView.js b/NzbDrone.Web/_backboneApp/Series/Delete/DeleteSeriesView.js new file mode 100644 index 000000000..39cdf6aea --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Series/Delete/DeleteSeriesView.js @@ -0,0 +1,29 @@ +'use strict'; + +define(['app', 'Series/SeriesModel'], function () { + + NzbDrone.Series.DeleteSeriesView = Backbone.Marionette.ItemView.extend({ + template: 'Series/Delete/DeleteSeriesTemplate', + tagName: 'div', + className: "modal", + + ui: { + 'progressbar': '.progress .bar', + }, + + events: { + 'click .x-confirm-delete': 'removeSeries', + }, + + onRender: function () { + NzbDrone.ModelBinder.bind(this.model, this.el); + }, + + removeSeries: function () { + //Todo: why the fuck doesn't destroy send the ID? + this.model.destroy({ wait: true, headers: { id: this.model.get('id'), deleteFiles: $('#delete-from-disk').prop('checked') } }); + this.model.collection.remove(this.model); + this.$el.parent().modal('hide'); + }, + }); +}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Series/DeleteSeriesView.js b/NzbDrone.Web/_backboneApp/Series/DeleteSeriesView.js deleted file mode 100644 index 19dbcdd8a..000000000 --- a/NzbDrone.Web/_backboneApp/Series/DeleteSeriesView.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; -/*global NzbDrone, Backbone*/ - -/// - -NzbDrone.Series.DeleteSeriesView = Backbone.Marionette.ItemView.extend({ - template: 'Series/DeleteSeriesTemplate', - tagName: 'div', - className: "modal", - - ui: { - 'progressbar': '.progress .bar', - }, - - events: { - 'click .x-confirm-delete': 'removeSeries', - }, - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - }, - - removeSeries: function () { - //Todo: why the fuck doesn't destroy send the ID? - this.model.destroy({ wait: true, headers: { id: this.model.get('id'), deleteFiles: $('#delete-from-disk').prop('checked') } }); - this.model.collection.remove(this.model); - this.$el.parent().modal('hide'); - }, -}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Series/EditSeriesTemplate.html b/NzbDrone.Web/_backboneApp/Series/Edit/EditSeriesTemplate.html similarity index 100% rename from NzbDrone.Web/_backboneApp/Series/EditSeriesTemplate.html rename to NzbDrone.Web/_backboneApp/Series/Edit/EditSeriesTemplate.html diff --git a/NzbDrone.Web/_backboneApp/Series/Edit/EditSeriesView.js b/NzbDrone.Web/_backboneApp/Series/Edit/EditSeriesView.js new file mode 100644 index 000000000..52ceb2ebb --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Series/Edit/EditSeriesView.js @@ -0,0 +1,50 @@ +'use strict'; +define(['app', 'Series/SeriesModel', 'Series/Delete/DeleteSeriesView', 'Quality/QualityProfileCollection'], function () { + + NzbDrone.Series.EditSeriesView = Backbone.Marionette.ItemView.extend({ + template: 'Series/Edit/EditSeriesTemplate', + tagName: 'div', + className: "modal", + + ui: { + progressbar: '.progress .bar', + qualityProfile: '.x-quality-profile', + backlogSettings: '.x-backlog-setting', + }, + + events: { + 'click .x-save': 'saveSeries', + 'click .x-remove': 'removeSeries' + }, + + initialize: function (options) { + this.qualityProfileCollection = options.qualityProfiles; + this.model.set('qualityProfiles', this.qualityProfileCollection); + }, + + onRender: function () { + NzbDrone.ModelBinder.bind(this.model, this.el); + }, + + qualityProfileCollection: new NzbDrone.Quality.QualityProfileCollection(), + + saveSeries: function () { + //Todo: Get qualityProfile + backlog setting from UI + var qualityProfile = this.ui.qualityProfile.val(); + var qualityProfileText = this.ui.qualityProfile.children('option:selected').text(); + var backlogSetting = this.ui.backlogSettings.val(); + + this.model.set({ qualityProfileId: qualityProfile, backlogSetting: backlogSetting, qualityProfileName: qualityProfileText }); + + this.model.save(); + this.trigger('saved'); + this.$el.parent().modal('hide'); + }, + + removeSeries: function () { + var view = new NzbDrone.Series.DeleteSeriesView({ model: this.model }); + NzbDrone.modalRegion.show(view); + } + }); + +}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Series/EditSeriesView.js b/NzbDrone.Web/_backboneApp/Series/EditSeriesView.js deleted file mode 100644 index a2df3f929..000000000 --- a/NzbDrone.Web/_backboneApp/Series/EditSeriesView.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; -/*global NzbDrone, Backbone*/ - -/// -/// -/// - -NzbDrone.Series.EditSeriesView = Backbone.Marionette.ItemView.extend({ - template: 'Series/EditSeriesTemplate', - tagName: 'div', - className: "modal", - - ui: { - progressbar: '.progress .bar', - qualityProfile: '.x-quality-profile', - backlogSettings: '.x-backlog-setting', - }, - - events: { - 'click .x-save': 'saveSeries', - 'click .x-remove': 'removeSeries' - }, - - initialize: function (options) { - this.qualityProfileCollection = options.qualityProfiles; - this.model.set('qualityProfiles', this.qualityProfileCollection); - }, - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - }, - - qualityProfileCollection: new NzbDrone.Quality.QualityProfileCollection(), - - saveSeries: function () { - //Todo: Get qualityProfile + backlog setting from UI - var qualityProfile = this.ui.qualityProfile.val(); - var qualityProfileText = this.ui.qualityProfile.children('option:selected').text(); - var backlogSetting = this.ui.backlogSettings.val(); - - this.model.set({ qualityProfileId: qualityProfile, backlogSetting: backlogSetting, qualityProfileName: qualityProfileText }); - - this.model.save(); - this.trigger('saved'); - this.$el.parent().modal('hide'); - }, - - removeSeries: function () { - var view = new NzbDrone.Series.DeleteSeriesView({ model: this.model }); - NzbDrone.modalRegion.show(view); - } -}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Series/Index/IndexLayout.js b/NzbDrone.Web/_backboneApp/Series/Index/IndexLayout.js deleted file mode 100644 index 16999f77e..000000000 --- a/NzbDrone.Web/_backboneApp/Series/Index/IndexLayout.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict;' - -/// -/// -/// - -NzbDrone.Series.IndexLayout = Backbone.Marionette.Layout.extend({ - template: 'Series/Index/IndexLayoutTemplate', - className: "row", - route: 'Series/index', - - ui: { - - }, - - regions: { - seriesRegion: '#series' - }, - - collection: new NzbDrone.Series.SeriesCollection(), - - initialize: function (options) { - - }, - - onRender: function () { - console.log('binding auto complete'); - - this.collection.fetch(); - - this.seriesRegion.show(new NzbDrone.Series.Index.SeriesCollectionView({ collection: this.collection })); - }, -}); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Series/Index/SeriesItemView.js b/NzbDrone.Web/_backboneApp/Series/Index/SeriesItemView.js deleted file mode 100644 index 258f17219..000000000 --- a/NzbDrone.Web/_backboneApp/Series/Index/SeriesItemView.js +++ /dev/null @@ -1,98 +0,0 @@ -'use strict'; -/*global NzbDrone, Backbone*/ - -/// -/// -/// -/// -/// - -NzbDrone.Series.Index.SeriesItemView = Backbone.Marionette.ItemView.extend({ - template: 'Series/Index/SeriesItemTemplate', - tagName: 'tr', - - ui: { - 'progressbar': '.progress .bar', - }, - - events: { - 'click .x-edit': 'editSeries', - 'click .x-remove': 'removeSeries' - }, - - initialize: function(options) { - this.qualityProfileCollection = options.qualityProfiles; - }, - - onRender: function () { - NzbDrone.ModelBinder.bind(this.model, this.el); - }, - - qualityProfileCollection: new NzbDrone.Quality.QualityProfileCollection(), - - editSeries: function () { - var view = new NzbDrone.Series.EditSeriesView({ model: this.model, qualityProfiles: this.qualityProfileCollection }); - view.on('saved', this.render, this); - NzbDrone.modalRegion.show(view); - }, - - removeSeries: function () { - var view = new NzbDrone.Series.DeleteSeriesView({ model: this.model }); - NzbDrone.modalRegion.show(view); - }, - onSave: function() { - alert("saved!"); - } -}); - -NzbDrone.Series.Index.SeriesCollectionView = Backbone.Marionette.CompositeView.extend({ - itemView: NzbDrone.Series.Index.SeriesItemView, - itemViewOptions: {}, - template: 'Series/Index/SeriesCollectionTemplate', - tagName: 'table', - className: 'table table-hover', - qualityProfileCollection: new NzbDrone.Quality.QualityProfileCollection(), - - initialize: function() { - this.qualityProfileCollection.fetch(); - this.itemViewOptions = { qualityProfiles: this.qualityProfileCollection }; - }, - - onRender: function() { - $('.table').dataTable({ - sDom: "<'row'<'span14'l><'span6'f>r>t<'row'<'span14'i><'span6'p>>", - sPaginationType: "bootstrap", - bLengthChange: false, - bPaginate: false, - bFilter: false, - aaSorting: [[1, 'asc']], - bStateSave: true, - iCookieDuration: 60 * 60 * 24 * 365, //1 year - oLanguage: { - sInfo: "_TOTAL_ series", - sEmptyTable: "No series have been added" - }, - aoColumns: [ - { - sType: "title-string", - sWidth: "13px" - }, - null, - null, - null, - null, - { - sType: "best-date" - }, - { - bSortable: false, - sWidth: "125px" - }, - { - bSortable: false, - sWidth: "50px" - } - ] - }); - } -}); diff --git a/NzbDrone.Web/_backboneApp/Series/SeriesCollection.js b/NzbDrone.Web/_backboneApp/Series/SeriesCollection.js index 30dfb1985..1e0af4113 100644 --- a/NzbDrone.Web/_backboneApp/Series/SeriesCollection.js +++ b/NzbDrone.Web/_backboneApp/Series/SeriesCollection.js @@ -1,7 +1,6 @@ - -/// - -NzbDrone.Series.SeriesCollection = Backbone.Collection.extend({ - url: NzbDrone.Constants.ApiRoot + '/series', - model: NzbDrone.Series.SeriesModel, +define(['app', 'Series/SeriesModel'], function () { + NzbDrone.Series.SeriesCollection = Backbone.Collection.extend({ + url: NzbDrone.Constants.ApiRoot + '/series', + model: NzbDrone.Series.SeriesModel, + }); }); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/Series/Index/SeriesCollectionTemplate.html b/NzbDrone.Web/_backboneApp/Series/SeriesCollectionTemplate.html similarity index 100% rename from NzbDrone.Web/_backboneApp/Series/Index/SeriesCollectionTemplate.html rename to NzbDrone.Web/_backboneApp/Series/SeriesCollectionTemplate.html diff --git a/NzbDrone.Web/_backboneApp/Series/SeriesCollectionView.js b/NzbDrone.Web/_backboneApp/Series/SeriesCollectionView.js new file mode 100644 index 000000000..a264d51b1 --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Series/SeriesCollectionView.js @@ -0,0 +1,57 @@ +'use strict'; + +define(['app', 'Series/SeriesItemView', 'Quality/QualityProfileCollection','datatables'], function () { + NzbDrone.Series.SeriesCollectionView = Backbone.Marionette.CompositeView.extend({ + itemView: NzbDrone.Series.SeriesItemView, + itemViewOptions: {}, + template: 'Series/SeriesCollectionTemplate', + tagName: 'table', + className: 'table table-hover', + qualityProfileCollection: new NzbDrone.Quality.QualityProfileCollection(), + + initialize: function () { + this.qualityProfileCollection.fetch(); + this.itemViewOptions = { qualityProfiles: this.qualityProfileCollection }; + }, + + onRender: function () { + $('.table').dataTable({ + sDom: "<'row'<'span14'l><'span6'f>r>t<'row'<'span14'i><'span6'p>>", + sPaginationType: "bootstrap", + bLengthChange: false, + bPaginate: false, + bFilter: true, + aaSorting: [[1, 'asc']], + bStateSave: true, + iCookieDuration: 60 * 60 * 24 * 365, //1 year + oLanguage: { + sInfo: "_TOTAL_ series", + sEmptyTable: "No series have been added" + }, + aoColumns: [ + { + sType: "title-string", + sWidth: "13px" + }, + null, + null, + null, + null, + { + sType: "best-date" + }, + { + bSortable: false, + sWidth: "125px" + }, + { + bSortable: false, + sWidth: "50px" + } + ] + }); + } + }); + +}); + diff --git a/NzbDrone.Web/_backboneApp/Series/Index/SeriesItemTemplate.html b/NzbDrone.Web/_backboneApp/Series/SeriesItemTemplate.html similarity index 100% rename from NzbDrone.Web/_backboneApp/Series/Index/SeriesItemTemplate.html rename to NzbDrone.Web/_backboneApp/Series/SeriesItemTemplate.html diff --git a/NzbDrone.Web/_backboneApp/Series/SeriesItemView.js b/NzbDrone.Web/_backboneApp/Series/SeriesItemView.js new file mode 100644 index 000000000..c678068bc --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Series/SeriesItemView.js @@ -0,0 +1,48 @@ +'use strict'; + +define([ + 'app', + 'Series/SeriesCollection', + 'Series/Edit/EditSeriesView', + 'Series/Delete/DeleteSeriesView', + 'Quality/QualityProfileCollection' +], function () { + + NzbDrone.Series.SeriesItemView = Backbone.Marionette.ItemView.extend({ + template: 'Series/SeriesItemTemplate', + tagName: 'tr', + + ui: { + 'progressbar': '.progress .bar', + }, + + events: { + 'click .x-edit': 'editSeries', + 'click .x-remove': 'removeSeries' + }, + + initialize: function (options) { + this.qualityProfileCollection = options.qualityProfiles; + }, + + onRender: function () { + NzbDrone.ModelBinder.bind(this.model, this.el); + }, + + qualityProfileCollection: new NzbDrone.Quality.QualityProfileCollection(), + + editSeries: function () { + var view = new NzbDrone.Series.EditSeriesView({ model: this.model, qualityProfiles: this.qualityProfileCollection }); + view.on('saved', this.render, this); + NzbDrone.modalRegion.show(view); + }, + + removeSeries: function () { + var view = new NzbDrone.Series.DeleteSeriesView({ model: this.model }); + NzbDrone.modalRegion.show(view); + }, + onSave: function () { + alert("saved!"); + } + }); +}); diff --git a/NzbDrone.Web/_backboneApp/Series/SeriesLayout.js b/NzbDrone.Web/_backboneApp/Series/SeriesLayout.js new file mode 100644 index 000000000..217947b11 --- /dev/null +++ b/NzbDrone.Web/_backboneApp/Series/SeriesLayout.js @@ -0,0 +1,33 @@ +'use strict;' +define(['app', 'Series/SeriesCollection', 'Series/SeriesCollectionView', 'bootstrap'], function () { + + + NzbDrone.Series.SeriesLayout = Backbone.Marionette.Layout.extend({ + template: 'Series/SeriesLayoutTemplate', + className: "row", + route: 'Series/index', + + ui: { + + }, + + regions: { + seriesRegion: '#series' + }, + + collection: new NzbDrone.Series.SeriesCollection(), + + initialize: function (options) { + + }, + + onRender: function () { + console.log('binding auto complete'); + + this.collection.fetch(); + + this.seriesRegion.show(new NzbDrone.Series.SeriesCollectionView({ collection: this.collection })); + }, + }); + +}); diff --git a/NzbDrone.Web/_backboneApp/Series/Index/IndexLayoutTemplate.html b/NzbDrone.Web/_backboneApp/Series/SeriesLayoutTemplate.html similarity index 100% rename from NzbDrone.Web/_backboneApp/Series/Index/IndexLayoutTemplate.html rename to NzbDrone.Web/_backboneApp/Series/SeriesLayoutTemplate.html diff --git a/NzbDrone.Web/_backboneApp/app.js b/NzbDrone.Web/_backboneApp/app.js index 49a73167d..861ce0202 100644 --- a/NzbDrone.Web/_backboneApp/app.js +++ b/NzbDrone.Web/_backboneApp/app.js @@ -6,6 +6,9 @@ 'marionette': 'JsLibraries/backbone.marionette', 'handlebars': 'JsLibraries/handlebars', 'bootstrap': 'JsLibraries/bootstrap', + 'datatablesBase': 'JsLibraries/jquery.dataTables', + 'datatablesExt': 'JsLibraries/jquery.dataTables.extensions', + 'datatables': 'JsLibraries/jquery.dataTables.bootstrap.pagination', }, shim: { @@ -25,7 +28,20 @@ }, handlebars: { exports: "Handlebars" + }, + dataTable: { + deps: ['jquery'] + }, + datatablesBase: { + depts: ['jquery'] + }, + datatablesExt: { + deps: ['datatablesBase'], + }, + datatables: { + deps: ['datatablesExt'] } + } }); @@ -42,7 +58,8 @@ define('app', ['jquery', 'JsLibraries/backbone.modelbinder', 'marionette', 'hand window.NzbDrone = new Backbone.Marionette.Application(); window.NzbDrone.Series = {}; - window.NzbDrone.Series.Index = {}; + window.NzbDrone.Series.Edit = {}; + window.NzbDrone.Series.Delete = {}; window.NzbDrone.AddSeries = {}; window.NzbDrone.AddSeries.New = {}; window.NzbDrone.AddSeries.Existing = {};