diff --git a/src/UI/Navbar/NavbarLayout.js b/src/UI/Navbar/NavbarLayout.js index 89be60482..85fb37330 100644 --- a/src/UI/Navbar/NavbarLayout.js +++ b/src/UI/Navbar/NavbarLayout.js @@ -5,38 +5,55 @@ var QueueView = require('../Activity/Queue/QueueView'); require('./Search'); module.exports = Marionette.Layout.extend({ - template : 'Navbar/NavbarLayoutTemplate', - regions : { + template : 'Navbar/NavbarLayoutTemplate', + + regions : { health : '#x-health', queue : '#x-queue-count' }, - ui : { + + ui : { search : '.x-series-search', collapse : '.x-navbar-collapse' }, - events : {"click a" : 'onClick'}, - onRender : function(){ + + events : { + 'click a' : 'onClick' + }, + + onRender : function() { this.ui.search.bindSearch(); this.health.show(new HealthView()); this.queue.show(new QueueView()); }, - onClick : function(event){ + + onClick : function(event) { + event.preventDefault(); + var target = $(event.target); + + //look down for var href = event.target.getAttribute('href'); - if(!href && target.closest('a') && target.closest('a')[0]) { + + //if couldn't find it look up' + if (!href && target.closest('a') && target.closest('a')[0]) { + var linkElement = target.closest('a')[0]; + href = linkElement.getAttribute('href'); this.setActive(linkElement); - } - else { + } else { this.setActive(event.target); } - if($(window).width() < 768) { + + if ($(window).width() < 768) { this.ui.collapse.collapse('hide'); } }, - setActive : function(element){ + + setActive : function(element) { + //Todo: Set active on first load this.$('a').removeClass('active'); $(element).addClass('active'); } diff --git a/src/UI/Navbar/Search.js b/src/UI/Navbar/Search.js index 1c1f57bef..ec1e14ead 100644 --- a/src/UI/Navbar/Search.js +++ b/src/UI/Navbar/Search.js @@ -5,32 +5,33 @@ var Backbone = require('backbone'); var SeriesCollection = require('../Series/SeriesCollection'); require('typeahead'); -module.exports = (function(){ - vent.on(vent.Hotkeys.NavbarSearch, function(){ - $('.x-series-search').focus(); - }); - $.fn.bindSearch = function(){ - $(this).typeahead({ - hint : true, - highlight : true, - minLength : 1 - }, { - name : 'series', - displayKey : 'title', - source : substringMatcher() - }); - $(this).on('typeahead:selected typeahead:autocompleted', function(e, series){ - this.blur(); - $(this).val(''); - Backbone.history.navigate('/series/{0}'.format(series.titleSlug), {trigger : true}); +vent.on(vent.Hotkeys.NavbarSearch, function() { + $('.x-series-search').focus(); +}); + +var substringMatcher = function() { + return function findMatches (q, cb) { + var matches = _.select(SeriesCollection.toJSON(), function(series) { + return series.title.toLowerCase().indexOf(q.toLowerCase()) > -1; }); + cb(matches); }; - var substringMatcher = function(){ - return function findMatches (q, cb){ - var matches = _.select(SeriesCollection.toJSON(), function(series){ - return series.title.toLowerCase().indexOf(q.toLowerCase()) > -1; - }); - cb(matches); - }; - }; -}).call(this); \ No newline at end of file +}; + +$.fn.bindSearch = function() { + $(this).typeahead({ + hint : true, + highlight : true, + minLength : 1 + }, { + name : 'series', + displayKey : 'title', + source : substringMatcher() + }); + + $(this).on('typeahead:selected typeahead:autocompleted', function(e, series) { + this.blur(); + $(this).val(''); + Backbone.history.navigate('/series/{0}'.format(series.titleSlug), { trigger : true }); + }); +}; \ No newline at end of file diff --git a/src/UI/Profile/ProfileCollection.js b/src/UI/Profile/ProfileCollection.js index bf03bd4e9..838ac3c9c 100644 --- a/src/UI/Profile/ProfileCollection.js +++ b/src/UI/Profile/ProfileCollection.js @@ -1,12 +1,13 @@ var Backbone = require('backbone'); var ProfileModel = require('./ProfileModel'); -module.exports = (function(){ - var ProfileCollection = Backbone.Collection.extend({ - model : ProfileModel, - url : window.NzbDrone.ApiRoot + '/profile' - }); - var profiles = new ProfileCollection(); - profiles.fetch(); - return profiles; -}).call(this); \ No newline at end of file +var ProfileCollection = Backbone.Collection.extend({ + model : ProfileModel, + url : window.NzbDrone.ApiRoot + '/profile' +}); + +var profiles = new ProfileCollection(); + +profiles.fetch(); + +module.exports = profiles; diff --git a/src/UI/Quality/QualityDefinitionModel.js b/src/UI/Quality/QualityDefinitionModel.js index 4f905e231..e5a901b6d 100644 --- a/src/UI/Quality/QualityDefinitionModel.js +++ b/src/UI/Quality/QualityDefinitionModel.js @@ -2,10 +2,13 @@ var ModelBase = require('../Settings/SettingsModelBase'); module.exports = ModelBase.extend({ baseInitialize : ModelBase.prototype.initialize, - initialize : function(){ + + initialize : function() { var name = this.get('quality').name; + this.successMessage = 'Saved ' + name + ' quality settings'; this.errorMessage = 'Couldn\'t save ' + name + ' quality settings'; + this.baseInitialize.call(this); } }); \ No newline at end of file diff --git a/src/UI/Release/AgeCell.js b/src/UI/Release/AgeCell.js index 258859bc0..4d6880425 100644 --- a/src/UI/Release/AgeCell.js +++ b/src/UI/Release/AgeCell.js @@ -5,25 +5,31 @@ require('../Shared/FormatHelpers'); module.exports = Backgrid.Cell.extend({ className : 'age-cell', - render : function(){ + + render : function() { var age = this.model.get('age'); var ageHours = this.model.get('ageHours'); var published = moment(this.model.get('publishDate')); var publishedFormatted = published.format('{0} {1}'.format(UiSettings.get('shortDateFormat'), UiSettings.time(true, true))); var formatted = age; var suffix = this.plural(age, 'day'); - if(age === 0) { + + if (age === 0) { formatted = ageHours.toFixed(1); suffix = this.plural(Math.round(ageHours), 'hour'); } + this.$el.html('
{0} {1}
'.format(formatted, suffix, publishedFormatted)); + this.delegateEvents(); return this; }, - plural : function(input, unit){ - if(input === 1) { + + plural : function(input, unit) { + if (input === 1) { return unit; } + return unit + 's'; } }); \ No newline at end of file diff --git a/src/UI/Release/DownloadReportCell.js b/src/UI/Release/DownloadReportCell.js index 7862b8f08..1d5728f6f 100644 --- a/src/UI/Release/DownloadReportCell.js +++ b/src/UI/Release/DownloadReportCell.js @@ -2,30 +2,40 @@ var Backgrid = require('backgrid'); module.exports = Backgrid.Cell.extend({ className : 'download-report-cell', - events : {click : '_onClick'}, - _onClick : function(){ - if(!this.model.get('downloadAllowed')) { + + events : { + 'click' : '_onClick' + }, + + _onClick : function() { + if (!this.model.get('downloadAllowed')) { return; } + var self = this; + this.$el.html(''); + + //Using success callback instead of promise so it + //gets called before the sync event is triggered this.model.save(null, { - success : function(){ + success : function() { self.model.set('queued', true); } }); }, - render : function(){ + + render : function() { this.$el.empty(); - if(this.model.get('queued')) { + + if (this.model.get('queued')) { this.$el.html(''); - } - else if(this.model.get('downloadAllowed')) { + } else if (this.model.get('downloadAllowed')) { this.$el.html(''); - } - else { + } else { this.className = 'no-download-report-cell'; } + return this; } }); \ No newline at end of file diff --git a/src/UI/Release/PeersCell.js b/src/UI/Release/PeersCell.js index 2be49e5ea..033c69115 100644 --- a/src/UI/Release/PeersCell.js +++ b/src/UI/Release/PeersCell.js @@ -2,23 +2,27 @@ var Backgrid = require('backgrid'); module.exports = Backgrid.Cell.extend({ className : 'peers-cell', - render : function(){ - if(this.model.get('protocol') === 'torrent') { + + render : function() { + if (this.model.get('protocol') === 'torrent') { var seeders = this.model.get('seeders') || 0; var leechers = this.model.get('leechers') || 0; + var level = 'danger'; - if(seeders > 0) { + + if (seeders > 0) { level = 'warning'; - } - if(seeders > 10) { + } else if (seeders > 10) { level = 'info'; - } - if(seeders > 50) { + } else if (seeders > 50) { level = 'primary'; } + this.$el.html('
{0} / {1}
'.format(seeders, leechers, level)); } + this.delegateEvents(); + return this; } }); \ No newline at end of file diff --git a/src/UI/Release/ProtocolCell.js b/src/UI/Release/ProtocolCell.js index 9b208d8da..ede35f9b3 100644 --- a/src/UI/Release/ProtocolCell.js +++ b/src/UI/Release/ProtocolCell.js @@ -2,19 +2,23 @@ var Backgrid = require('backgrid'); module.exports = Backgrid.Cell.extend({ className : 'protocol-cell', - render : function(){ + + render : function() { var protocol = this.model.get('protocol') || 'Unknown'; var label = '??'; - if(protocol) { - if(protocol === 'torrent') { + + if (protocol) { + if (protocol === 'torrent') { label = 'torrent'; - } - else if(protocol === 'usenet') { + } else if (protocol === 'usenet') { label = 'nzb'; } + this.$el.html('
{1}
'.format(protocol, label)); } + this.delegateEvents(); + return this; } }); \ No newline at end of file diff --git a/src/UI/Release/ReleaseCollection.js b/src/UI/Release/ReleaseCollection.js index 975635fc9..a66547f00 100644 --- a/src/UI/Release/ReleaseCollection.js +++ b/src/UI/Release/ReleaseCollection.js @@ -2,42 +2,55 @@ var PagableCollection = require('backbone.pageable'); var ReleaseModel = require('./ReleaseModel'); var AsSortedCollection = require('../Mixins/AsSortedCollection'); -module.exports = (function(){ - var Collection = PagableCollection.extend({ - url : window.NzbDrone.ApiRoot + '/release', - model : ReleaseModel, - state : { - pageSize : 2000, - sortKey : 'download', - order : -1 +var Collection = PagableCollection.extend({ + url : window.NzbDrone.ApiRoot + '/release', + model : ReleaseModel, + + state : { + pageSize : 2000, + sortKey : 'download', + order : -1 + }, + + mode : 'client', + + sortMappings : { + 'quality' : { + sortKey : 'qualityWeight' }, - mode : 'client', - sortMappings : { - quality : {sortKey : 'qualityWeight'}, - rejections : { - sortValue : function(model){ - var rejections = model.get('rejections'); - var releaseWeight = model.get('releaseWeight'); - if(rejections.length !== 0) { - return releaseWeight + 1000000; - } - return releaseWeight; - } - }, - download : {sortKey : 'releaseWeight'}, - seeders : { - sortValue : function(model){ - var seeders = model.get('seeders') || 0; - var leechers = model.get('leechers') || 0; - return seeders * 1000000 + leechers; + 'rejections' : { + sortValue : function(model) { + var rejections = model.get('rejections'); + var releaseWeight = model.get('releaseWeight'); + + if (rejections.length !== 0) { + return releaseWeight + 1000000; } - }, - age : {sortKey : 'ageMinutes'} + + return releaseWeight; + } }, - fetchEpisodeReleases : function(episodeId){ - return this.fetch({data : {episodeId : episodeId}}); + 'download' : { + sortKey : 'releaseWeight' + }, + 'seeders' : { + sortValue : function(model) { + var seeders = model.get('seeders') || 0; + var leechers = model.get('leechers') || 0; + + return seeders * 1000000 + leechers; + } + }, + 'age' : { + sortKey : 'ageMinutes' } - }); - Collection = AsSortedCollection.call(Collection); - return Collection; -}).call(this); \ No newline at end of file + }, + + fetchEpisodeReleases : function(episodeId) { + return this.fetch({ data : { episodeId : episodeId } }); + } +}); + +Collection = AsSortedCollection.call(Collection); + +module.exports = Collection; \ No newline at end of file diff --git a/src/UI/Release/ReleaseLayout.js b/src/UI/Release/ReleaseLayout.js index da495c42e..b17dd01f1 100644 --- a/src/UI/Release/ReleaseLayout.js +++ b/src/UI/Release/ReleaseLayout.js @@ -9,51 +9,63 @@ var ApprovalStatusCell = require('../Cells/ApprovalStatusCell'); var LoadingView = require('../Shared/LoadingView'); module.exports = Marionette.Layout.extend({ - template : 'Release/ReleaseLayoutTemplate', - regions : { + template : 'Release/ReleaseLayoutTemplate', + + regions : { grid : '#x-grid', toolbar : '#x-toolbar' }, - columns : [{ - name : 'indexer', - label : 'Indexer', - sortable : true, - cell : IndexerCell - }, { - name : 'title', - label : 'Title', - sortable : true, - cell : Backgrid.StringCell - }, { - name : 'episodeNumbers', - episodes : 'episodeNumbers', - label : 'season', - cell : EpisodeNumberCell - }, { - name : 'size', - label : 'Size', - sortable : true, - cell : FileSizeCell - }, { - name : 'quality', - label : 'Quality', - sortable : true, - cell : QualityCell - }, { - name : 'rejections', - label : '', - cell : ApprovalStatusCell - }], - initialize : function(){ + + columns : [ + { + name : 'indexer', + label : 'Indexer', + sortable : true, + cell : IndexerCell + }, + { + name : 'title', + label : 'Title', + sortable : true, + cell : Backgrid.StringCell + }, + { + name : 'episodeNumbers', + episodes : 'episodeNumbers', + label : 'season', + cell : EpisodeNumberCell + }, + { + name : 'size', + label : 'Size', + sortable : true, + cell : FileSizeCell + }, + { + name : 'quality', + label : 'Quality', + sortable : true, + cell : QualityCell + }, + { + name : 'rejections', + label : '', + cell : ApprovalStatusCell + } + ], + + initialize : function() { this.collection = new ReleaseCollection(); this.listenTo(this.collection, 'sync', this._showTable); }, - onRender : function(){ + + onRender : function() { this.grid.show(new LoadingView()); this.collection.fetch(); }, - _showTable : function(){ - if(!this.isClosed) { + + _showTable : function() { + if (!this.isClosed) { this.grid.show(new Backgrid.Grid({ row : Backgrid.Row, columns : this.columns,