From 7b5c0a952bff52bb1d6c4e945d84e9b7c44c1966 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 13 Feb 2015 22:04:39 +0100 Subject: [PATCH] UI Cleanup - Updated Cells subtree. --- src/UI/Cells/ApprovalStatusCell.js | 11 +++- src/UI/Cells/DeleteEpisodeFileCell.js | 19 ++++-- src/UI/Cells/Edit/QualityCellEditor.js | 36 ++++++++---- src/UI/Cells/EpisodeActionsCell.js | 21 ++++--- src/UI/Cells/EpisodeMonitoredCell.js | 27 +++++++-- src/UI/Cells/EpisodeNumberCell.js | 43 +++++++++----- src/UI/Cells/EpisodeProgressCell.js | 11 +++- src/UI/Cells/EpisodeStatusCell.js | 81 +++++++++++++++++--------- src/UI/Cells/EpisodeTitleCell.js | 17 ++++-- src/UI/Cells/EventTypeCell.js | 9 ++- src/UI/Cells/FileSizeCell.js | 3 +- src/UI/Cells/IndexerCell.js | 3 +- src/UI/Cells/NzbDroneCell.js | 37 ++++++++---- src/UI/Cells/ProfileCell.js | 11 +++- src/UI/Cells/RelativeDateCell.js | 14 +++-- src/UI/Cells/RelativeTimeCell.js | 15 +++-- src/UI/Cells/ReleaseTitleCell.js | 11 ++-- src/UI/Cells/SeasonFolderCell.js | 5 +- src/UI/Cells/SelectAllCell.js | 19 ++++-- src/UI/Cells/SeriesActionsCell.js | 31 ++++++---- src/UI/Cells/SeriesStatusCell.js | 18 ++++-- src/UI/Cells/TemplatedCell.js | 5 +- src/UI/Cells/ToggleCell.js | 30 +++++++--- 23 files changed, 334 insertions(+), 143 deletions(-) diff --git a/src/UI/Cells/ApprovalStatusCell.js b/src/UI/Cells/ApprovalStatusCell.js index 1c467536d..88142394f 100644 --- a/src/UI/Cells/ApprovalStatusCell.js +++ b/src/UI/Cells/ApprovalStatusCell.js @@ -5,14 +5,20 @@ require('bootstrap'); module.exports = Backgrid.Cell.extend({ className : 'approval-status-cell', template : 'Cells/ApprovalStatusCellTemplate', - render : function(){ + + render : function() { + var rejections = this.model.get(this.column.get('name')); - if(rejections.length === 0) { + + if (rejections.length === 0) { return this; } + this.templateFunction = Marionette.TemplateCache.get(this.template); + var html = this.templateFunction(rejections); this.$el.html(''); + this.$el.popover({ content : html, html : true, @@ -21,6 +27,7 @@ module.exports = Backgrid.Cell.extend({ placement : 'left', container : this.$el }); + return this; } }); \ No newline at end of file diff --git a/src/UI/Cells/DeleteEpisodeFileCell.js b/src/UI/Cells/DeleteEpisodeFileCell.js index 140241d40..3ca0a3d96 100644 --- a/src/UI/Cells/DeleteEpisodeFileCell.js +++ b/src/UI/Cells/DeleteEpisodeFileCell.js @@ -3,17 +3,24 @@ var Backgrid = require('backgrid'); module.exports = Backgrid.Cell.extend({ className : 'delete-episode-file-cell', - events : {"click" : '_onClick'}, - render : function(){ + + events : { + 'click' : '_onClick' + }, + + render : function() { this.$el.empty(); this.$el.html(''); + return this; }, - _onClick : function(){ + + _onClick : function() { var self = this; - if(window.confirm('Are you sure you want to delete \'{0}\' from disk?'.format(this.model.get('path')))) { - this.model.destroy().done(function(){ - vent.trigger(vent.Events.EpisodeFileDeleted, {episodeFile : self.model}); + + if (window.confirm('Are you sure you want to delete \'{0}\' from disk?'.format(this.model.get('path')))) { + this.model.destroy().done(function() { + vent.trigger(vent.Events.EpisodeFileDeleted, { episodeFile : self.model }); }); } } diff --git a/src/UI/Cells/Edit/QualityCellEditor.js b/src/UI/Cells/Edit/QualityCellEditor.js index 49a5e77e0..703512be7 100644 --- a/src/UI/Cells/Edit/QualityCellEditor.js +++ b/src/UI/Cells/Edit/QualityCellEditor.js @@ -7,38 +7,49 @@ module.exports = Backgrid.CellEditor.extend({ className : 'quality-cell-editor', template : 'Cells/Edit/QualityCellEditorTemplate', tagName : 'select', - events : { - "change" : 'save', - "blur" : 'close', - "keydown" : 'close' + + events : { + 'change' : 'save', + 'blur' : 'close', + 'keydown' : 'close' }, - render : function(){ + + render : function() { var self = this; + var profileSchemaCollection = new ProfileSchemaCollection(); var promise = profileSchemaCollection.fetch(); - promise.done(function(){ + + promise.done(function() { var templateName = self.template; self.schema = profileSchemaCollection.first(); - var selected = _.find(self.schema.get('items'), function(model){ + + var selected = _.find(self.schema.get('items'), function(model) { return model.quality.id === self.model.get(self.column.get('name')).quality.id; }); - if(selected) { + + if (selected) { selected.quality.selected = true; } + self.templateFunction = Marionette.TemplateCache.get(templateName); var data = self.schema.toJSON(); var html = self.templateFunction(data); self.$el.html(html); }); + return this; }, - save : function(e){ + + save : function(e) { var model = this.model; var column = this.column; var selected = parseInt(this.$el.val(), 10); - var profileItem = _.find(this.schema.get('items'), function(model){ + + var profileItem = _.find(this.schema.get('items'), function(model) { return model.quality.id === selected; }); + var newQuality = { quality : profileItem.quality, revision : { @@ -46,14 +57,17 @@ module.exports = Backgrid.CellEditor.extend({ real : 0 } }; + model.set(column.get('name'), newQuality); model.save(); model.trigger('backgrid:edited', model, column, new Backgrid.Command(e)); }, - close : function(e){ + + close : function(e) { var model = this.model; var column = this.column; var command = new Backgrid.Command(e); + model.trigger('backgrid:edited', model, column, command); } }); \ No newline at end of file diff --git a/src/UI/Cells/EpisodeActionsCell.js b/src/UI/Cells/EpisodeActionsCell.js index 5c4c778b7..e3994e988 100644 --- a/src/UI/Cells/EpisodeActionsCell.js +++ b/src/UI/Cells/EpisodeActionsCell.js @@ -3,14 +3,18 @@ var NzbDroneCell = require('./NzbDroneCell'); var CommandController = require('../Commands/CommandController'); module.exports = NzbDroneCell.extend({ - className : 'episode-actions-cell', - events : { - "click .x-automatic-search" : '_automaticSearch', - "click .x-manual-search" : '_manualSearch' + className : 'episode-actions-cell', + + events : { + 'click .x-automatic-search' : '_automaticSearch', + 'click .x-manual-search' : '_manualSearch' }, - render : function(){ + + render : function() { this.$el.empty(); + this.$el.html('' + ''); + CommandController.bindToCommand({ element : this.$el.find('.x-automatic-search'), command : { @@ -18,16 +22,19 @@ module.exports = NzbDroneCell.extend({ episodeIds : [this.model.get('id')] } }); + this.delegateEvents(); return this; }, - _automaticSearch : function(){ + + _automaticSearch : function() { CommandController.Execute('episodeSearch', { name : 'episodeSearch', episodeIds : [this.model.get('id')] }); }, - _manualSearch : function(){ + + _manualSearch : function() { vent.trigger(vent.Commands.ShowEpisodeDetails, { episode : this.cellValue, hideSeriesLink : true, diff --git a/src/UI/Cells/EpisodeMonitoredCell.js b/src/UI/Cells/EpisodeMonitoredCell.js index 60be30762..b615d2909 100644 --- a/src/UI/Cells/EpisodeMonitoredCell.js +++ b/src/UI/Cells/EpisodeMonitoredCell.js @@ -4,37 +4,52 @@ var SeriesCollection = require('../Series/SeriesCollection'); var Messenger = require('../Shared/Messenger'); module.exports = ToggleCell.extend({ - className : 'toggle-cell episode-monitored', + className : 'toggle-cell episode-monitored', + _originalOnClick : ToggleCell.prototype._onClick, - _onClick : function(e){ + + _onClick : function(e) { + var series = SeriesCollection.get(this.model.get('seriesId')); - if(!series.get('monitored')) { + + if (!series.get('monitored')) { + Messenger.show({ message : 'Unable to change monitored state when series is not monitored', type : 'error' }); + return; } - if(e.shiftKey && this.model.episodeCollection.lastToggled) { + + if (e.shiftKey && this.model.episodeCollection.lastToggled) { this._selectRange(); + return; } + this._originalOnClick.apply(this, arguments); this.model.episodeCollection.lastToggled = this.model; }, - _selectRange : function(){ + + _selectRange : function() { var episodeCollection = this.model.episodeCollection; var lastToggled = episodeCollection.lastToggled; + var currentIndex = episodeCollection.indexOf(this.model); var lastIndex = episodeCollection.indexOf(lastToggled); + var low = Math.min(currentIndex, lastIndex); var high = Math.max(currentIndex, lastIndex); var range = _.range(low + 1, high); - _.each(range, function(index){ + + _.each(range, function(index) { var model = episodeCollection.at(index); + model.set('monitored', lastToggled.get('monitored')); model.save(); }); + this.model.set('monitored', lastToggled.get('monitored')); this.model.save(); this.model.episodeCollection.lastToggled = undefined; diff --git a/src/UI/Cells/EpisodeNumberCell.js b/src/UI/Cells/EpisodeNumberCell.js index 0e38e1477..6d4d804b2 100644 --- a/src/UI/Cells/EpisodeNumberCell.js +++ b/src/UI/Cells/EpisodeNumberCell.js @@ -4,52 +4,65 @@ var _ = require('underscore'); module.exports = NzbDroneCell.extend({ className : 'episode-number-cell', - render : function(){ + + render : function() { + this.$el.empty(); + var airDateField = this.column.get('airDateUtc') || 'airDateUtc'; var seasonField = this.column.get('seasonNumber') || 'seasonNumber'; var episodeField = this.column.get('episodes') || 'episodeNumber'; var absoluteEpisodeField = 'absoluteEpisodeNumber'; - if(this.model) { + + if (this.model) { var result = 'Unknown'; + var airDate = this.model.get(airDateField); var seasonNumber = this.model.get(seasonField); var episodes = this.model.get(episodeField); var absoluteEpisodeNumber = this.model.get(absoluteEpisodeField); - if(this.cellValue) { - if(!seasonNumber) { + + if (this.cellValue) { + if (!seasonNumber) { seasonNumber = this.cellValue.get(seasonField); } - if(!episodes) { + + if (!episodes) { episodes = this.cellValue.get(episodeField); } - if(absoluteEpisodeNumber === undefined) { + + if (absoluteEpisodeNumber === undefined) { absoluteEpisodeNumber = this.cellValue.get(absoluteEpisodeField); } - if(!airDate) { + + if (!airDate) { this.model.get(airDateField); } } - if(episodes) { + + if (episodes) { + var paddedEpisodes; var paddedAbsoluteEpisode; - if(episodes.constructor === Array) { - paddedEpisodes = _.map(episodes, function(episodeNumber){ + + if (episodes.constructor === Array) { + paddedEpisodes = _.map(episodes, function(episodeNumber) { return FormatHelpers.pad(episodeNumber, 2); }).join(); - } - else { + } else { paddedEpisodes = FormatHelpers.pad(episodes, 2); paddedAbsoluteEpisode = FormatHelpers.pad(absoluteEpisodeNumber, 2); } + result = '{0}x{1}'.format(seasonNumber, paddedEpisodes); - if(absoluteEpisodeNumber !== undefined && paddedAbsoluteEpisode) { + + if (absoluteEpisodeNumber !== undefined && paddedAbsoluteEpisode) { result += ' ({0})'.format(paddedAbsoluteEpisode); } - } - else if(airDate) { + } else if (airDate) { result = new Date(airDate).toLocaleDateString(); } + this.$el.html(result); } this.delegateEvents(); diff --git a/src/UI/Cells/EpisodeProgressCell.js b/src/UI/Cells/EpisodeProgressCell.js index c740ad5b9..6208040c4 100644 --- a/src/UI/Cells/EpisodeProgressCell.js +++ b/src/UI/Cells/EpisodeProgressCell.js @@ -4,18 +4,25 @@ var NzbDroneCell = require('./NzbDroneCell'); module.exports = NzbDroneCell.extend({ className : 'episode-progress-cell', template : 'Cells/EpisodeProgressCellTemplate', - render : function(){ + + render : function() { + var episodeCount = this.model.get('episodeCount'); var episodeFileCount = this.model.get('episodeFileCount'); + var percent = 100; - if(episodeCount > 0) { + + if (episodeCount > 0) { percent = episodeFileCount / episodeCount * 100; } + this.model.set('percentOfEpisodes', percent); + this.templateFunction = Marionette.TemplateCache.get(this.template); var data = this.model.toJSON(); var html = this.templateFunction(data); this.$el.html(html); + return this; } }); \ No newline at end of file diff --git a/src/UI/Cells/EpisodeStatusCell.js b/src/UI/Cells/EpisodeStatusCell.js index 68e21fe58..f962e6a2e 100644 --- a/src/UI/Cells/EpisodeStatusCell.js +++ b/src/UI/Cells/EpisodeStatusCell.js @@ -6,93 +6,122 @@ var moment = require('moment'); var FormatHelpers = require('../Shared/FormatHelpers'); module.exports = NzbDroneCell.extend({ - className : 'episode-status-cell', - render : function(){ + className : 'episode-status-cell', + + render : function() { this.listenTo(QueueCollection, 'sync', this._renderCell); + this._renderCell(); + return this; }, - _renderCell : function(){ - if(this.episodeFile) { + + _renderCell : function() { + + if (this.episodeFile) { this.stopListening(this.episodeFile, 'change', this._refresh); } + this.$el.empty(); - if(this.model) { + + if (this.model) { + var icon; var tooltip; + var hasAired = moment(this.model.get('airDateUtc')).isBefore(moment()); this.episodeFile = this._getFile(); - if(this.episodeFile) { + + if (this.episodeFile) { this.listenTo(this.episodeFile, 'change', this._refresh); + var quality = this.episodeFile.get('quality'); var revision = quality.revision; var size = FormatHelpers.bytes(this.episodeFile.get('size')); var title = 'Episode downloaded'; - if(revision.real && revision.real > 0) { + + if (revision.real && revision.real > 0) { title += '[REAL]'; } - if(revision.version && revision.version > 1) { + + if (revision.version && revision.version > 1) { title += ' [PROPER]'; } - if(size !== '') { + + if (size !== '') { title += ' - {0}'.format(size); } - if(this.episodeFile.get('qualityCutoffNotMet')) { + + if (this.episodeFile.get('qualityCutoffNotMet')) { this.$el.html('{1}'.format(title, quality.quality.name)); - } - else { + } else { this.$el.html('{1}'.format(title, quality.quality.name)); } + return; } + else { var model = this.model; var downloading = QueueCollection.findEpisode(model.get('id')); - if(downloading) { - var progress = 100 - downloading.get('sizeleft') / downloading.get('size') * 100; - if(progress === 0) { + + if (downloading) { + var progress = 100 - (downloading.get('sizeleft') / downloading.get('size') * 100); + + if (progress === 0) { icon = 'icon-nd-downloading'; tooltip = 'Episode is downloading'; } + else { - this.$el.html('
'.format(progress.toFixed(1), downloading.get('title')) + '
'.format(progress)); + this.$el.html('
'.format(progress.toFixed(1), downloading.get('title')) + + '
'.format(progress)); return; } } - else if(this.model.get('grabbed')) { + + else if (this.model.get('grabbed')) { icon = 'icon-nd-downloading'; tooltip = 'Episode is downloading'; } - else if(!this.model.get('airDateUtc')) { + + else if (!this.model.get('airDateUtc')) { icon = 'icon-nd-tba'; tooltip = 'TBA'; } - else if(hasAired) { + + else if (hasAired) { icon = 'icon-nd-missing'; tooltip = 'Episode missing from disk'; - } - else { + } else { icon = 'icon-nd-not-aired'; tooltip = 'Episode has not aired'; } } + this.$el.html(''.format(icon, tooltip)); } }, - _getFile : function(){ + + _getFile : function() { var hasFile = this.model.get('hasFile'); - if(hasFile) { + + if (hasFile) { var episodeFile; - if(reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) { + + if (reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) { episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, this.model.get('episodeFileId')); } - else if(this.model.has('episodeFile')) { + + else if (this.model.has('episodeFile')) { episodeFile = new Backbone.Model(this.model.get('episodeFile')); } - if(episodeFile) { + + if (episodeFile) { return episodeFile; } } + return undefined; } }); \ No newline at end of file diff --git a/src/UI/Cells/EpisodeTitleCell.js b/src/UI/Cells/EpisodeTitleCell.js index b9ea593dc..7dce10ede 100644 --- a/src/UI/Cells/EpisodeTitleCell.js +++ b/src/UI/Cells/EpisodeTitleCell.js @@ -2,17 +2,24 @@ var vent = require('vent'); var NzbDroneCell = require('./NzbDroneCell'); module.exports = NzbDroneCell.extend({ - className : 'episode-title-cell', - events : {"click" : '_showDetails'}, - render : function(){ + className : 'episode-title-cell', + + events : { + 'click' : '_showDetails' + }, + + render : function() { var title = this.cellValue.get('title'); - if(!title || title === '') { + + if (!title || title === '') { title = 'TBA'; } + this.$el.html(title); return this; }, - _showDetails : function(){ + + _showDetails : function() { var hideSeriesLink = this.column.get('hideSeriesLink'); vent.trigger(vent.Commands.ShowEpisodeDetails, { episode : this.cellValue, diff --git a/src/UI/Cells/EventTypeCell.js b/src/UI/Cells/EventTypeCell.js index 014c415c5..2f5168240 100644 --- a/src/UI/Cells/EventTypeCell.js +++ b/src/UI/Cells/EventTypeCell.js @@ -2,11 +2,14 @@ var NzbDroneCell = require('./NzbDroneCell'); module.exports = NzbDroneCell.extend({ className : 'history-event-type-cell', - render : function(){ + + render : function() { this.$el.empty(); - if(this.cellValue) { + + if (this.cellValue) { var icon; var toolTip; + switch (this.cellValue.get('eventType')) { case 'grabbed': icon = 'icon-nd-downloading'; @@ -32,8 +35,10 @@ module.exports = NzbDroneCell.extend({ icon = 'icon-question'; toolTip = 'unknown event'; } + this.$el.html(''.format(icon, toolTip)); } + return this; } }); \ No newline at end of file diff --git a/src/UI/Cells/FileSizeCell.js b/src/UI/Cells/FileSizeCell.js index 182d9c7f1..586d5f35c 100644 --- a/src/UI/Cells/FileSizeCell.js +++ b/src/UI/Cells/FileSizeCell.js @@ -3,7 +3,8 @@ var FormatHelpers = require('../Shared/FormatHelpers'); module.exports = Backgrid.Cell.extend({ className : 'file-size-cell', - render : function(){ + + render : function() { var size = this.model.get(this.column.get('name')); this.$el.html(FormatHelpers.bytes(size)); this.delegateEvents(); diff --git a/src/UI/Cells/IndexerCell.js b/src/UI/Cells/IndexerCell.js index 7d7adf968..bbd2e90df 100644 --- a/src/UI/Cells/IndexerCell.js +++ b/src/UI/Cells/IndexerCell.js @@ -2,7 +2,8 @@ var Backgrid = require('backgrid'); module.exports = Backgrid.Cell.extend({ className : 'indexer-cell', - render : function(){ + + render : function() { var indexer = this.model.get(this.column.get('name')); this.$el.html(indexer); return this; diff --git a/src/UI/Cells/NzbDroneCell.js b/src/UI/Cells/NzbDroneCell.js index 5c7f8e6c5..725513828 100644 --- a/src/UI/Cells/NzbDroneCell.js +++ b/src/UI/Cells/NzbDroneCell.js @@ -2,41 +2,56 @@ var Backgrid = require('backgrid'); var Backbone = require('backbone'); module.exports = Backgrid.Cell.extend({ + _originalInit : Backgrid.Cell.prototype.initialize, - initialize : function(){ + + initialize : function() { this._originalInit.apply(this, arguments); this.cellValue = this._getValue(); + this.listenTo(this.model, 'change', this._refresh); - if(this._onEdit) { - this.listenTo(this.model, 'backgrid:edit', function(model, column, cell, editor){ - if(column.get('name') === this.column.get('name')) { + + if (this._onEdit) { + this.listenTo(this.model, 'backgrid:edit', function(model, column, cell, editor) { + if (column.get('name') === this.column.get('name')) { this._onEdit(model, column, cell, editor); } }); } }, - _refresh : function(){ + + _refresh : function() { this.cellValue = this._getValue(); this.render(); }, - _getValue : function(){ + + _getValue : function() { + var cellValue = this.column.get('cellValue'); - if(cellValue) { - if(cellValue === 'this') { + + if (cellValue) { + if (cellValue === 'this') { return this.model; } } + var name = this.column.get('name'); - if(name === 'this') { + + if (name === 'this') { return this.model; } + var value = this.model.get(name); - if(!value) { + + if (!value) { return undefined; } - if(!value.get && typeof value === 'object') { + + //if not a model + if (!value.get && typeof value === 'object') { value = new Backbone.Model(value); } + return value; } }); \ No newline at end of file diff --git a/src/UI/Cells/ProfileCell.js b/src/UI/Cells/ProfileCell.js index aed856471..11da11ee7 100644 --- a/src/UI/Cells/ProfileCell.js +++ b/src/UI/Cells/ProfileCell.js @@ -4,13 +4,18 @@ var _ = require('underscore'); module.exports = Backgrid.Cell.extend({ className : 'profile-cell', - render : function(){ + + render : function() { + this.$el.empty(); var profileId = this.model.get(this.column.get('name')); - var profile = _.findWhere(ProfileCollection.models, {id : profileId}); - if(profile) { + + var profile = _.findWhere(ProfileCollection.models, { id : profileId }); + + if (profile) { this.$el.html(profile.get('name')); } + return this; } }); \ No newline at end of file diff --git a/src/UI/Cells/RelativeDateCell.js b/src/UI/Cells/RelativeDateCell.js index 8dc80c9e6..9dbd5228b 100644 --- a/src/UI/Cells/RelativeDateCell.js +++ b/src/UI/Cells/RelativeDateCell.js @@ -5,19 +5,23 @@ var UiSettings = require('../Shared/UiSettingsModel'); module.exports = NzbDroneCell.extend({ className : 'relative-date-cell', - render : function(){ + + render : function() { + var dateStr = this.model.get(this.column.get('name')); - if(dateStr) { + + if (dateStr) { var date = moment(dateStr); var result = '{1}'; var tooltip = date.format(UiSettings.longDateTime()); var text; - if(UiSettings.get('showRelativeDates')) { + + if (UiSettings.get('showRelativeDates')) { text = FormatHelpers.relativeDate(dateStr); - } - else { + } else { text = date.format(UiSettings.get('shortDateFormat')); } + this.$el.html(result.format(tooltip, text)); } return this; diff --git a/src/UI/Cells/RelativeTimeCell.js b/src/UI/Cells/RelativeTimeCell.js index 8b30341ee..b0d552bfd 100644 --- a/src/UI/Cells/RelativeTimeCell.js +++ b/src/UI/Cells/RelativeTimeCell.js @@ -5,21 +5,26 @@ var UiSettings = require('../Shared/UiSettingsModel'); module.exports = NzbDroneCell.extend({ className : 'relative-time-cell', - render : function(){ + + render : function() { + var dateStr = this.model.get(this.column.get('name')); - if(dateStr) { + + if (dateStr) { var date = moment(dateStr); var result = '{1}'; var tooltip = date.format(UiSettings.longDateTime()); var text; - if(UiSettings.get('showRelativeDates')) { + + if (UiSettings.get('showRelativeDates')) { text = date.fromNow(); - } - else { + } else { text = date.format(UiSettings.shortDateTime()); } + this.$el.html(result.format(tooltip, text)); } + return this; } }); \ No newline at end of file diff --git a/src/UI/Cells/ReleaseTitleCell.js b/src/UI/Cells/ReleaseTitleCell.js index bbf7adbfe..7d3551e41 100644 --- a/src/UI/Cells/ReleaseTitleCell.js +++ b/src/UI/Cells/ReleaseTitleCell.js @@ -2,16 +2,19 @@ var NzbDroneCell = require('./NzbDroneCell'); module.exports = NzbDroneCell.extend({ className : 'release-title-cell', - render : function(){ + + render : function() { this.$el.empty(); + var title = this.model.get('title'); var infoUrl = this.model.get('infoUrl'); - if(infoUrl) { + + if (infoUrl) { this.$el.html('{1}'.format(infoUrl, title)); - } - else { + } else { this.$el.html(title); } + return this; } }); \ No newline at end of file diff --git a/src/UI/Cells/SeasonFolderCell.js b/src/UI/Cells/SeasonFolderCell.js index 3ce72a049..7a9385b84 100644 --- a/src/UI/Cells/SeasonFolderCell.js +++ b/src/UI/Cells/SeasonFolderCell.js @@ -2,10 +2,13 @@ var Backgrid = require('backgrid'); module.exports = Backgrid.Cell.extend({ className : 'season-folder-cell', - render : function(){ + + render : function() { this.$el.empty(); + var seasonFolder = this.model.get(this.column.get('name')); this.$el.html(seasonFolder.toString()); + return this; } }); \ No newline at end of file diff --git a/src/UI/Cells/SelectAllCell.js b/src/UI/Cells/SelectAllCell.js index 4adef8b2e..86282b6c1 100644 --- a/src/UI/Cells/SelectAllCell.js +++ b/src/UI/Cells/SelectAllCell.js @@ -3,32 +3,41 @@ var _ = require('underscore'); var BackgridSelectAll = require('backgrid.selectall'); module.exports = BackgridSelectAll.extend({ - enterEditMode : function(e){ - if(e.shiftKey && this.model.collection.lastToggled) { + enterEditMode : function(e) { + if (e.shiftKey && this.model.collection.lastToggled) { this._selectRange(); } + var checked = $(e.target).prop('checked'); + this.model.collection.lastToggled = this.model; this.model.collection.checked = checked; }, - onChange : function(e){ + + onChange : function(e) { var checked = $(e.target).prop('checked'); this.$el.parent().toggleClass('selected', checked); this.model.trigger('backgrid:selected', this.model, checked); }, - _selectRange : function(){ + + _selectRange : function() { var collection = this.model.collection; var lastToggled = collection.lastToggled; var checked = collection.checked; + var currentIndex = collection.indexOf(this.model); var lastIndex = collection.indexOf(lastToggled); + var low = Math.min(currentIndex, lastIndex); var high = Math.max(currentIndex, lastIndex); var range = _.range(low + 1, high); - _.each(range, function(index){ + + _.each(range, function(index) { var model = collection.at(index); + model.trigger('backgrid:select', model, checked); }); + this.model.collection.lastToggled = undefined; this.model.collection.checked = undefined; } diff --git a/src/UI/Cells/SeriesActionsCell.js b/src/UI/Cells/SeriesActionsCell.js index 49e743068..cf6e7c025 100644 --- a/src/UI/Cells/SeriesActionsCell.js +++ b/src/UI/Cells/SeriesActionsCell.js @@ -3,15 +3,23 @@ var NzbDroneCell = require('./NzbDroneCell'); var CommandController = require('../Commands/CommandController'); module.exports = NzbDroneCell.extend({ - className : 'series-actions-cell', - ui : {refresh : '.x-refresh'}, - events : { - "click .x-edit" : '_editSeries', - "click .x-refresh" : '_refreshSeries' + className : 'series-actions-cell', + + ui : { + refresh : '.x-refresh' }, - render : function(){ + + events : { + 'click .x-edit' : '_editSeries', + 'click .x-refresh' : '_refreshSeries' + }, + + render : function() { this.$el.empty(); - this.$el.html(' ' + ''); + + this.$el.html(' ' + + ''); + CommandController.bindToCommand({ element : this.$el.find('.x-refresh'), command : { @@ -19,13 +27,16 @@ module.exports = NzbDroneCell.extend({ seriesId : this.model.get('id') } }); + this.delegateEvents(); return this; }, - _editSeries : function(){ - vent.trigger(vent.Commands.EditSeriesCommand, {series : this.model}); + + _editSeries : function() { + vent.trigger(vent.Commands.EditSeriesCommand, { series : this.model }); }, - _refreshSeries : function(){ + + _refreshSeries : function() { CommandController.Execute('refreshSeries', { name : 'refreshSeries', seriesId : this.model.id diff --git a/src/UI/Cells/SeriesStatusCell.js b/src/UI/Cells/SeriesStatusCell.js index 2a9eebf92..124d132a8 100644 --- a/src/UI/Cells/SeriesStatusCell.js +++ b/src/UI/Cells/SeriesStatusCell.js @@ -1,26 +1,32 @@ var NzbDroneCell = require('./NzbDroneCell'); module.exports = NzbDroneCell.extend({ - className : 'series-status-cell', - render : function(){ + className : 'series-status-cell', + + render : function() { this.$el.empty(); var monitored = this.model.get('monitored'); var status = this.model.get('status'); - if(status === 'ended') { + + if (status === 'ended') { this.$el.html(''); this._setStatusWeight(3); } - else if(!monitored) { + + else if (!monitored) { this.$el.html(''); this._setStatusWeight(2); } + else { this.$el.html(''); this._setStatusWeight(1); } + return this; }, - _setStatusWeight : function(weight){ - this.model.set('statusWeight', weight, {silent : true}); + + _setStatusWeight : function(weight) { + this.model.set('statusWeight', weight, { silent : true }); } }); \ No newline at end of file diff --git a/src/UI/Cells/TemplatedCell.js b/src/UI/Cells/TemplatedCell.js index 876e29192..5f7525fdd 100644 --- a/src/UI/Cells/TemplatedCell.js +++ b/src/UI/Cells/TemplatedCell.js @@ -2,12 +2,15 @@ var Marionette = require('marionette'); var NzbDroneCell = require('./NzbDroneCell'); module.exports = NzbDroneCell.extend({ - render : function(){ + render : function() { + var templateName = this.column.get('template') || this.template; + this.templateFunction = Marionette.TemplateCache.get(templateName); var data = this.cellValue.toJSON(); var html = this.templateFunction(data); this.$el.html(html); + this.delegateEvents(); return this; } diff --git a/src/UI/Cells/ToggleCell.js b/src/UI/Cells/ToggleCell.js index f7c2a90f8..35900d0b6 100644 --- a/src/UI/Cells/ToggleCell.js +++ b/src/UI/Cells/ToggleCell.js @@ -2,31 +2,45 @@ var Backgrid = require('backgrid'); module.exports = Backgrid.Cell.extend({ className : 'toggle-cell', - events : {"click" : '_onClick'}, - _onClick : function(){ + + events : { + 'click' : '_onClick' + }, + + _onClick : function() { + var self = this; + this.$el.tooltip('hide'); + var name = this.column.get('name'); this.model.set(name, !this.model.get(name)); + this.$('i').addClass('icon-spinner icon-spin'); - this.model.save().always(function(){ + + this.model.save().always(function() { self.render(); }); }, - render : function(){ + + render : function() { this.$el.empty(); this.$el.html(''); + var name = this.column.get('name'); - if(this.model.get(name)) { + + if (this.model.get(name)) { this.$('i').addClass(this.column.get('trueClass')); - } - else { + } else { this.$('i').addClass(this.column.get('falseClass')); } + var tooltip = this.column.get('tooltip'); - if(tooltip) { + + if (tooltip) { this.$('i').attr('title', tooltip); } + return this; } }); \ No newline at end of file