From 29d9e3dadfb7f77ef49e72a9cbcb143ba4d1e46a Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 13 Feb 2015 22:06:34 +0100 Subject: [PATCH] UI Cleanup - Updated root tree. --- src/UI/AppLayout.js | 32 ++++++++--------- src/UI/Config.js | 85 ++++++++++++++++++++++---------------------- src/UI/Controller.js | 36 +++++++++++-------- src/UI/LifeCycle.js | 8 ++--- src/UI/Router.js | 2 +- src/UI/app.js | 61 +++++++++++++++++-------------- src/UI/main.js | 21 +++++++---- src/UI/polyfills.js | 33 ++++++++--------- src/UI/reqres.js | 1 + src/UI/vendor.js | 1 - src/UI/vent.js | 67 +++++++++++++++++----------------- 11 files changed, 181 insertions(+), 166 deletions(-) diff --git a/src/UI/AppLayout.js b/src/UI/AppLayout.js index 335615937..613cbcd06 100644 --- a/src/UI/AppLayout.js +++ b/src/UI/AppLayout.js @@ -3,20 +3,18 @@ var ModalRegion = require('./Shared/Modal/ModalRegion'); var FileBrowserModalRegion = require('./Shared/FileBrowser/FileBrowserModalRegion'); var ControlPanelRegion = require('./Shared/ControlPanel/ControlPanelRegion'); -module.exports = (function(){ - 'use strict'; - var Layout = Marionette.Layout.extend({ - regions : { - navbarRegion : '#nav-region', - mainRegion : '#main-region' - }, - initialize : function(){ - this.addRegions({ - modalRegion : ModalRegion, - fileBrowserModalRegion : FileBrowserModalRegion, - controlPanelRegion : ControlPanelRegion - }); - } - }); - return new Layout({el : 'body'}); -}).call(this); \ No newline at end of file +var Layout = Marionette.Layout.extend({ + regions : { + navbarRegion : '#nav-region', + mainRegion : '#main-region' + }, + + initialize : function() { + this.addRegions({ + modalRegion : ModalRegion, + fileBrowserModalRegion : FileBrowserModalRegion, + controlPanelRegion : ControlPanelRegion + }); + } +}); +module.exports = new Layout({ el : 'body' }); \ No newline at end of file diff --git a/src/UI/Config.js b/src/UI/Config.js index 7563a189b..6ea02dbe8 100644 --- a/src/UI/Config.js +++ b/src/UI/Config.js @@ -1,53 +1,52 @@ -'use strict'; -define( - [ - 'vent' - ], function (vent) { - return { - Events: { - ConfigUpdatedEvent: 'ConfigUpdatedEvent' - }, +var vent = require('./vent'); - Keys : { - DefaultProfileId : 'DefaultProfileId', - DefaultRootFolderId : 'DefaultRootFolderId', - UseSeasonFolder : 'UseSeasonFolder', - DefaultSeriesType : 'DefaultSeriesType', - MonitorEpisodes : 'MonitorEpisodes', - AdvancedSettings : 'advancedSettings' - }, +module.exports = { + Events : { + ConfigUpdatedEvent : 'ConfigUpdatedEvent' + }, - getValueBoolean: function (key, defaultValue) { - defaultValue = defaultValue || false; + Keys : { + DefaultProfileId : 'DefaultProfileId', + DefaultRootFolderId : 'DefaultRootFolderId', + UseSeasonFolder : 'UseSeasonFolder', + DefaultSeriesType : 'DefaultSeriesType', + MonitorEpisodes : 'MonitorEpisodes', + AdvancedSettings : 'advancedSettings' + }, - return this.getValue(key, defaultValue.toString()) === 'true'; - }, + getValueBoolean : function(key, defaultValue) { + defaultValue = defaultValue || false; - getValue: function (key, defaultValue) { - var storeValue = window.localStorage.getItem(key); + return this.getValue(key, defaultValue.toString()) === 'true'; + }, - if (!storeValue) { - return defaultValue; - } + getValue : function(key, defaultValue) { + var storeValue = window.localStorage.getItem(key); - return storeValue.toString(); - }, + if (!storeValue) { + return defaultValue; + } - setValue: function (key, value) { + return storeValue.toString(); + }, - console.log('Config: [{0}] => [{1}]'.format(key, value)); + setValue : function(key, value) { - if (this.getValue(key) === value.toString()) { - return; - } + console.log('Config: [{0}] => [{1}]'.format(key, value)); - try { - window.localStorage.setItem(key, value); - vent.trigger(this.Events.ConfigUpdatedEvent, {key: key, value: value}); - } - catch (error) { - console.error('Unable to save config: [{0}] => [{1}]'.format(key, value)); - } - } - }; - }); + if (this.getValue(key) === value.toString()) { + return; + } + + try { + window.localStorage.setItem(key, value); + vent.trigger(this.Events.ConfigUpdatedEvent, { + key : key, + value : value + }); + } + catch (error) { + console.error('Unable to save config: [{0}] => [{1}]'.format(key, value)); + } + } +}; diff --git a/src/UI/Controller.js b/src/UI/Controller.js index cd7e9128b..f1e4032ab 100644 --- a/src/UI/Controller.js +++ b/src/UI/Controller.js @@ -12,39 +12,47 @@ var SeasonPassLayout = require('./SeasonPass/SeasonPassLayout'); var SeriesEditorLayout = require('./Series/Editor/SeriesEditorLayout'); module.exports = NzbDroneController.extend({ - addSeries : function(action){ + addSeries : function(action) { this.setTitle('Add Series'); - this.showMainRegion(new AddSeriesLayout({action : action})); + this.showMainRegion(new AddSeriesLayout({ action : action })); }, - calendar : function(){ + + calendar : function() { this.setTitle('Calendar'); this.showMainRegion(new CalendarLayout()); }, - settings : function(action){ + + settings : function(action) { this.setTitle('Settings'); - this.showMainRegion(new SettingsLayout({action : action})); + this.showMainRegion(new SettingsLayout({ action : action })); }, - wanted : function(action){ + + wanted : function(action) { this.setTitle('Wanted'); - this.showMainRegion(new WantedLayout({action : action})); + this.showMainRegion(new WantedLayout({ action : action })); }, - activity : function(action){ + + activity : function(action) { this.setTitle('Activity'); - this.showMainRegion(new ActivityLayout({action : action})); + this.showMainRegion(new ActivityLayout({ action : action })); }, - rss : function(){ + + rss : function() { this.setTitle('RSS'); this.showMainRegion(new ReleaseLayout()); }, - system : function(action){ + + system : function(action) { this.setTitle('System'); - this.showMainRegion(new SystemLayout({action : action})); + this.showMainRegion(new SystemLayout({ action : action })); }, - seasonPass : function(){ + + seasonPass : function() { this.setTitle('Season Pass'); this.showMainRegion(new SeasonPassLayout()); }, - seriesEditor : function(){ + + seriesEditor : function() { this.setTitle('Series Editor'); this.showMainRegion(new SeriesEditorLayout()); } diff --git a/src/UI/LifeCycle.js b/src/UI/LifeCycle.js index 0b8789933..59a237340 100644 --- a/src/UI/LifeCycle.js +++ b/src/UI/LifeCycle.js @@ -1,5 +1,3 @@ -module.exports = (function(){ - window.onbeforeunload = function(){ - window.NzbDrone.unloading = true; - }; -}).call(this); \ No newline at end of file +window.onbeforeunload = function() { + window.NzbDrone.unloading = true; +}; \ No newline at end of file diff --git a/src/UI/Router.js b/src/UI/Router.js index 93d8bd9a9..91b42a074 100644 --- a/src/UI/Router.js +++ b/src/UI/Router.js @@ -19,7 +19,7 @@ module.exports = Marionette.AppRouter.extend({ 'system' : 'system', 'system/:action' : 'system', 'seasonpass' : 'seasonPass', - 'serieseditor' : 'seriesEditor', + 'serieseditor' : 'seriesEditor', ':whatever' : 'showNotFound' } }); \ No newline at end of file diff --git a/src/UI/app.js b/src/UI/app.js index b9d42be4f..3ebfafdb0 100644 --- a/src/UI/app.js +++ b/src/UI/app.js @@ -34,18 +34,16 @@ require.config({ }, shim : { - - api : { + api : { deps : ['jquery'] }, - jquery : { exports : '$' }, messenger : { deps : ['jquery'], exports : 'Messenger', - init : function(){ + init : function() { window.Messenger.options = { theme : 'flat' }; @@ -58,7 +56,10 @@ require.config({ deps : ['jquery'] }, 'bootstrap.tagsinput' : { - deps : ['bootstrap', 'typeahead'] + deps : [ + 'bootstrap', + 'typeahead' + ] }, backstrech : { deps : ['jquery'] @@ -68,18 +69,25 @@ require.config({ exports : '_' }, backbone : { - deps : ['jquery', 'Instrumentation/ErrorHandler', 'underscore', 'Mixins/jquery.ajax', 'jQuery/ToTheTop'], - + deps : [ + 'jquery', + 'Instrumentation/ErrorHandler', + 'underscore', + 'Mixins/jquery.ajax', + 'jQuery/ToTheTop' + ], exports : 'Backbone' }, marionette : { - deps : ['backbone', 'Handlebars/backbone.marionette.templates', 'Mixins/AsNamedView'], - + deps : [ + 'backbone', + 'Handlebars/backbone.marionette.templates', + 'Mixins/AsNamedView' + ], exports : 'Marionette', - init : function(Backbone, TemplateMixin, AsNamedView){ + init : function(Backbone, TemplateMixin, AsNamedView) { TemplateMixin.call(window.Marionette.TemplateCache); AsNamedView.call(window.Marionette.ItemView.prototype); - } }, 'typeahead' : { @@ -101,7 +109,10 @@ require.config({ deps : ['backbone'] }, 'backbone.deepmodel' : { - deps : ['backbone', 'underscore'] + deps : [ + 'backbone', + 'underscore' + ] }, 'backbone.validation' : { deps : ['backbone'], @@ -111,17 +122,17 @@ require.config({ deps : ['backbone'] }, 'backbone.collectionview' : { - deps : ['backbone', 'jquery-ui'], + deps : [ + 'backbone', + 'jquery-ui' + ], exports : 'Backbone.CollectionView' }, backgrid : { - deps : ['backbone'], - + deps : ['backbone'], exports : 'Backgrid', - - init : function(){ - require(['Shared/Grid/HeaderCell'], function(){ - + init : function() { + require(['Shared/Grid/HeaderCell'], function() { window.Backgrid.Column.prototype.defaults = { name : undefined, label : undefined, @@ -137,16 +148,12 @@ require.config({ } }, 'backgrid.paginator' : { - - exports : 'Backgrid.Extension.Paginator', - - deps : ['backgrid'] + deps : ['backgrid'], + exports : 'Backgrid.Extension.Paginator' }, 'backgrid.selectall' : { - - exports : 'Backgrid.Extension.SelectRowCell', - - deps : ['backgrid'] + deps : ['backgrid'], + exports : 'Backgrid.Extension.SelectRowCell' } } }); \ No newline at end of file diff --git a/src/UI/main.js b/src/UI/main.js index 1748c6110..55a8e9eff 100644 --- a/src/UI/main.js +++ b/src/UI/main.js @@ -1,4 +1,4 @@ -var $ = require('jquery'); +var $ = require('jquery'); var Backbone = require('backbone'); var Marionette = require('marionette'); var RouteBinder = require('./jQuery/RouteBinder'); @@ -23,13 +23,18 @@ new SeriesController(); new ModalController(); new ControlPanelController(); new Router(); + var app = new Marionette.Application(); -app.addInitializer(function(){ + +app.addInitializer(function() { console.log('starting application'); }); -app.addInitializer(SignalRBroadcaster.appInitializer, {app : app}); -app.addInitializer(Tooltip.appInitializer, {app : app}); -app.addInitializer(function(){ + +app.addInitializer(SignalRBroadcaster.appInitializer, { app : app }); + +app.addInitializer(Tooltip.appInitializer, { app : app }); + +app.addInitializer(function() { Backbone.history.start({ pushState : true, root : serverStatusModel.get('urlBase') @@ -38,13 +43,15 @@ app.addInitializer(function(){ AppLayout.navbarRegion.show(new NavbarLayout()); $('body').addClass('started'); }); -app.addInitializer(function(){ + +app.addInitializer(function() { var footerText = serverStatusModel.get('version'); - if(serverStatusModel.get('branch') !== 'master') { + if (serverStatusModel.get('branch') !== 'master') { footerText += '
' + serverStatusModel.get('branch'); } $('#footer-region .version').html(footerText); }); + app.start(); module.exports = app; diff --git a/src/UI/polyfills.js b/src/UI/polyfills.js index 08bea2e83..fef657524 100644 --- a/src/UI/polyfills.js +++ b/src/UI/polyfills.js @@ -1,33 +1,29 @@ window.console = window.console || {}; -window.console.log = window.console.log || function(){ -}; -window.console.group = window.console.group || function(){ -}; -window.console.groupEnd = window.console.groupEnd || function(){ -}; -window.console.debug = window.console.debug || function(){ -}; -window.console.warn = window.console.warn || function(){ -}; -window.console.assert = window.console.assert || function(){ -}; -if(!String.prototype.startsWith) { +window.console.log = window.console.log || function() {}; +window.console.group = window.console.group || function() {}; +window.console.groupEnd = window.console.groupEnd || function() {}; +window.console.debug = window.console.debug || function() {}; +window.console.warn = window.console.warn || function() {}; +window.console.assert = window.console.assert || function() {}; + +if (!String.prototype.startsWith) { Object.defineProperty(String.prototype, 'startsWith', { enumerable : false, configurable : false, writable : false, - value : function(searchString, position){ + value : function(searchString, position) { position = position || 0; return this.indexOf(searchString, position) === position; } }); } -if(!String.prototype.endsWith) { + +if (!String.prototype.endsWith) { Object.defineProperty(String.prototype, 'endsWith', { enumerable : false, configurable : false, writable : false, - value : function(searchString, position){ + value : function(searchString, position) { position = position || this.length; position = position - searchString.length; var lastIndex = this.lastIndexOf(searchString); @@ -35,8 +31,9 @@ if(!String.prototype.endsWith) { } }); } -if(!('contains' in String.prototype)) { - String.prototype.contains = function(str, startIndex){ + +if (!('contains' in String.prototype)) { + String.prototype.contains = function(str, startIndex) { return -1 !== String.prototype.indexOf.call(this, str, startIndex); }; } \ No newline at end of file diff --git a/src/UI/reqres.js b/src/UI/reqres.js index a39b792ed..2d4351657 100644 --- a/src/UI/reqres.js +++ b/src/UI/reqres.js @@ -1,6 +1,7 @@ var Wreqr = require('./JsLibraries/backbone.wreqr'); var reqres = new Wreqr.RequestResponse(); + reqres.Requests = { GetEpisodeFileById : 'GetEpisodeFileById', GetAlternateNameBySeasonNumber : 'GetAlternateNameBySeasonNumber' diff --git a/src/UI/vendor.js b/src/UI/vendor.js index 97a4e32c9..dc343bb35 100644 --- a/src/UI/vendor.js +++ b/src/UI/vendor.js @@ -17,7 +17,6 @@ require('zero.clipboard'); require('bootstrap'); require('bootstrap.tagsinput'); - /*Backbone*/ require('backbone'); require('backbone.deepmodel'); diff --git a/src/UI/vent.js b/src/UI/vent.js index 1b0d285b0..04163b2d8 100644 --- a/src/UI/vent.js +++ b/src/UI/vent.js @@ -1,35 +1,36 @@ var Wreqr = require('./JsLibraries/backbone.wreqr'); -module.exports = (function(){ - 'use strict'; - var vent = new Wreqr.EventAggregator(); - vent.Events = { - SeriesAdded : 'series:added', - SeriesDeleted : 'series:deleted', - CommandComplete : 'command:complete', - ServerUpdated : 'server:updated', - EpisodeFileDeleted : 'episodefile:deleted' - }; - vent.Commands = { - EditSeriesCommand : 'EditSeriesCommand', - DeleteSeriesCommand : 'DeleteSeriesCommand', - OpenModalCommand : 'OpenModalCommand', - CloseModalCommand : 'CloseModalCommand', - ShowEpisodeDetails : 'ShowEpisodeDetails', - ShowHistoryDetails : 'ShowHistoryDetails', - ShowLogDetails : 'ShowLogDetails', - SaveSettings : 'saveSettings', - ShowLogFile : 'showLogFile', - ShowRenamePreview : 'showRenamePreview', - ShowFileBrowser : 'showFileBrowser', - CloseFileBrowser : 'closeFileBrowser', - OpenControlPanelCommand : 'OpenControlPanelCommand', - CloseControlPanelCommand : 'CloseControlPanelCommand' - }; - vent.Hotkeys = { - NavbarSearch : 'navbar:search', - SaveSettings : 'settings:save', - ShowHotkeys : 'hotkeys:show' - }; - return vent; -}).call(this); \ No newline at end of file +var vent = new Wreqr.EventAggregator(); + +vent.Events = { + SeriesAdded : 'series:added', + SeriesDeleted : 'series:deleted', + CommandComplete : 'command:complete', + ServerUpdated : 'server:updated', + EpisodeFileDeleted : 'episodefile:deleted' +}; + +vent.Commands = { + EditSeriesCommand : 'EditSeriesCommand', + DeleteSeriesCommand : 'DeleteSeriesCommand', + OpenModalCommand : 'OpenModalCommand', + CloseModalCommand : 'CloseModalCommand', + ShowEpisodeDetails : 'ShowEpisodeDetails', + ShowHistoryDetails : 'ShowHistoryDetails', + ShowLogDetails : 'ShowLogDetails', + SaveSettings : 'saveSettings', + ShowLogFile : 'showLogFile', + ShowRenamePreview : 'showRenamePreview', + ShowFileBrowser : 'showFileBrowser', + CloseFileBrowser : 'closeFileBrowser', + OpenControlPanelCommand : 'OpenControlPanelCommand', + CloseControlPanelCommand : 'CloseControlPanelCommand' +}; + +vent.Hotkeys = { + NavbarSearch : 'navbar:search', + SaveSettings : 'settings:save', + ShowHotkeys : 'hotkeys:show' +}; + +module.exports = vent; \ No newline at end of file