UI Cleanup - Updated Rename and SeasonPass subtrees.

This commit is contained in:
Taloth Saldono 2015-02-13 22:52:55 +01:00
parent 860f55996c
commit 1bf433872a
11 changed files with 233 additions and 145 deletions

View File

@ -4,24 +4,31 @@ var RenamePreviewModel = require('./RenamePreviewModel');
module.exports = Backbone.Collection.extend({ module.exports = Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/rename', url : window.NzbDrone.ApiRoot + '/rename',
model : RenamePreviewModel, model : RenamePreviewModel,
originalFetch : Backbone.Collection.prototype.fetch, originalFetch : Backbone.Collection.prototype.fetch,
initialize : function(options) { initialize : function(options) {
if (!options.seriesId) { if (!options.seriesId) {
throw 'seriesId is required'; throw 'seriesId is required';
} }
this.seriesId = options.seriesId; this.seriesId = options.seriesId;
this.seasonNumber = options.seasonNumber; this.seasonNumber = options.seasonNumber;
}, },
fetch : function(options) { fetch : function(options) {
if (!this.seriesId) { if (!this.seriesId) {
throw 'seriesId is required'; throw 'seriesId is required';
} }
options = options || {}; options = options || {};
options.data = {}; options.data = {};
options.data.seriesId = this.seriesId; options.data.seriesId = this.seriesId;
if (this.seasonNumber) { if (this.seasonNumber) {
options.data.seasonNumber = this.seasonNumber; options.data.seasonNumber = this.seasonNumber;
} }
return this.originalFetch.call(this, options); return this.originalFetch.call(this, options);
} }
}); });

View File

@ -1,4 +1,6 @@
var Marionette = require('marionette'); var Marionette = require('marionette');
var RenamePreviewItemView = require('./RenamePreviewItemView'); var RenamePreviewItemView = require('./RenamePreviewItemView');
module.exports = Marionette.CollectionView.extend({itemView : RenamePreviewItemView}); module.exports = Marionette.CollectionView.extend({
itemView : RenamePreviewItemView
});

View File

@ -1,4 +1,6 @@
var vent = require('vent'); var vent = require('vent');
var Marionette = require('marionette'); var Marionette = require('marionette');
module.exports = Marionette.ItemView.extend({template : 'Rename/RenamePreviewEmptyCollectionViewTemplate'}); module.exports = Marionette.ItemView.extend({
template : 'Rename/RenamePreviewEmptyCollectionViewTemplate'
});

View File

@ -4,6 +4,7 @@ var NamingModel = require('../Settings/MediaManagement/Naming/NamingModel');
module.exports = Marionette.ItemView.extend({ module.exports = Marionette.ItemView.extend({
template : 'Rename/RenamePreviewFormatViewTemplate', template : 'Rename/RenamePreviewFormatViewTemplate',
templateHelpers : function() { templateHelpers : function() {
var type = this.model.get('seriesType'); var type = this.model.get('seriesType');
return { return {
@ -11,6 +12,7 @@ module.exports = Marionette.ItemView.extend({
format : this.naming.get(type + 'EpisodeFormat') format : this.naming.get(type + 'EpisodeFormat')
}; };
}, },
initialize : function() { initialize : function() {
this.naming = new NamingModel(); this.naming = new NamingModel();
this.naming.fetch(); this.naming.fetch();

View File

@ -1,3 +1,3 @@
{{#if rename}} {{#if rename}}
Naming pattern: {{format}} Naming pattern: {{format}}
{{/if}} {{/if}}

View File

@ -1,36 +1,39 @@
var vent = require('vent'); var vent = require('vent');
var Marionette = require('marionette'); var Marionette = require('marionette');
var AsModelBoundView = require('../Mixins/AsModelBoundView'); var AsModelBoundView = require('../Mixins/AsModelBoundView');
module.exports = (function(){
var view = Marionette.ItemView.extend({ var view = Marionette.ItemView.extend({
template : 'Rename/RenamePreviewItemViewTemplate', template : 'Rename/RenamePreviewItemViewTemplate',
ui : { ui : {
itemDiv : '.rename-preview-item', itemDiv : '.rename-preview-item',
checkboxIcon : '.rename-checkbox i' checkboxIcon : '.rename-checkbox i'
}, },
onRender : function() { onRender : function() {
this._setItemState(); this._setItemState();
this.listenTo(this.model, 'change', this._setItemState); this.listenTo(this.model, 'change', this._setItemState);
this.listenTo(this.model, 'rename:select', this._onRenameAll); this.listenTo(this.model, 'rename:select', this._onRenameAll);
}, },
_setItemState : function() { _setItemState : function() {
var checked = this.model.get('rename'); var checked = this.model.get('rename');
this.model.trigger('rename:select', this.model, checked); this.model.trigger('rename:select', this.model, checked);
if (checked) { if (checked) {
this.ui.itemDiv.removeClass('do-not-rename'); this.ui.itemDiv.removeClass('do-not-rename');
this.ui.checkboxIcon.addClass('icon-check'); this.ui.checkboxIcon.addClass('icon-check');
this.ui.checkboxIcon.removeClass('icon-check-empty'); this.ui.checkboxIcon.removeClass('icon-check-empty');
} } else {
else {
this.ui.itemDiv.addClass('do-not-rename'); this.ui.itemDiv.addClass('do-not-rename');
this.ui.checkboxIcon.addClass('icon-check-empty'); this.ui.checkboxIcon.addClass('icon-check-empty');
this.ui.checkboxIcon.removeClass('icon-check'); this.ui.checkboxIcon.removeClass('icon-check');
} }
}, },
_onRenameAll : function(model, checked) { _onRenameAll : function(model, checked) {
this.model.set('rename', checked); this.model.set('rename', checked);
} }
}); });
return AsModelBoundView.apply(view);
}).call(this); module.exports = AsModelBoundView.apply(view);

View File

@ -11,55 +11,69 @@ var CommandController = require('../Commands/CommandController');
module.exports = Marionette.Layout.extend({ module.exports = Marionette.Layout.extend({
className : 'modal-lg', className : 'modal-lg',
template : 'Rename/RenamePreviewLayoutTemplate', template : 'Rename/RenamePreviewLayoutTemplate',
regions : { regions : {
renamePreviews : '#rename-previews', renamePreviews : '#rename-previews',
formatRegion : '.x-format-region' formatRegion : '.x-format-region'
}, },
ui : { ui : {
pathInfo : '.x-path-info', pathInfo : '.x-path-info',
renameAll : '.x-rename-all', renameAll : '.x-rename-all',
checkboxIcon : '.x-rename-all-button i' checkboxIcon : '.x-rename-all-button i'
}, },
events : { events : {
"click .x-organize" : '_organizeFiles', 'click .x-organize' : '_organizeFiles',
"change .x-rename-all" : '_toggleAll' 'change .x-rename-all' : '_toggleAll'
}, },
initialize : function(options) { initialize : function(options) {
this.model = options.series; this.model = options.series;
this.seasonNumber = options.seasonNumber; this.seasonNumber = options.seasonNumber;
var viewOptions = {}; var viewOptions = {};
viewOptions.seriesId = this.model.id; viewOptions.seriesId = this.model.id;
viewOptions.seasonNumber = this.seasonNumber; viewOptions.seasonNumber = this.seasonNumber;
this.collection = new RenamePreviewCollection(viewOptions); this.collection = new RenamePreviewCollection(viewOptions);
this.listenTo(this.collection, 'sync', this._showPreviews); this.listenTo(this.collection, 'sync', this._showPreviews);
this.listenTo(this.collection, 'rename:select', this._itemRenameChanged); this.listenTo(this.collection, 'rename:select', this._itemRenameChanged);
this.collection.fetch(); this.collection.fetch();
}, },
onRender : function() { onRender : function() {
this.renamePreviews.show(new LoadingView()); this.renamePreviews.show(new LoadingView());
this.formatRegion.show(new RenamePreviewFormatView({ model : this.model })); this.formatRegion.show(new RenamePreviewFormatView({ model : this.model }));
}, },
_showPreviews : function() { _showPreviews : function() {
if (this.collection.length === 0) { if (this.collection.length === 0) {
this.ui.pathInfo.hide(); this.ui.pathInfo.hide();
this.renamePreviews.show(new EmptyCollectionView()); this.renamePreviews.show(new EmptyCollectionView());
return; return;
} }
this.ui.pathInfo.show(); this.ui.pathInfo.show();
this.collection.invoke('set', { rename : true }); this.collection.invoke('set', { rename : true });
this.renamePreviews.show(new RenamePreviewCollectionView({ collection : this.collection })); this.renamePreviews.show(new RenamePreviewCollectionView({ collection : this.collection }));
}, },
_organizeFiles : function() { _organizeFiles : function() {
if (this.collection.length === 0) { if (this.collection.length === 0) {
vent.trigger(vent.Commands.CloseModalCommand); vent.trigger(vent.Commands.CloseModalCommand);
} }
var files = _.map(this.collection.where({ rename : true }), function(model) { var files = _.map(this.collection.where({ rename : true }), function(model) {
return model.get('episodeFileId'); return model.get('episodeFileId');
}); });
if (files.length === 0) { if (files.length === 0) {
vent.trigger(vent.Commands.CloseModalCommand); vent.trigger(vent.Commands.CloseModalCommand);
return; return;
} }
if (this.seasonNumber) { if (this.seasonNumber) {
CommandController.Execute('renameFiles', { CommandController.Execute('renameFiles', {
name : 'renameFiles', name : 'renameFiles',
@ -67,8 +81,7 @@ module.exports = Marionette.Layout.extend({
seasonNumber : this.seasonNumber, seasonNumber : this.seasonNumber,
files : files files : files
}); });
} } else {
else {
CommandController.Execute('renameFiles', { CommandController.Execute('renameFiles', {
name : 'renameFiles', name : 'renameFiles',
seriesId : this.model.id, seriesId : this.model.id,
@ -76,29 +89,34 @@ module.exports = Marionette.Layout.extend({
files : files files : files
}); });
} }
vent.trigger(vent.Commands.CloseModalCommand); vent.trigger(vent.Commands.CloseModalCommand);
}, },
_setCheckedState : function(checked) { _setCheckedState : function(checked) {
if (checked) { if (checked) {
this.ui.checkboxIcon.addClass('icon-check'); this.ui.checkboxIcon.addClass('icon-check');
this.ui.checkboxIcon.removeClass('icon-check-empty'); this.ui.checkboxIcon.removeClass('icon-check-empty');
} } else {
else {
this.ui.checkboxIcon.addClass('icon-check-empty'); this.ui.checkboxIcon.addClass('icon-check-empty');
this.ui.checkboxIcon.removeClass('icon-check'); this.ui.checkboxIcon.removeClass('icon-check');
} }
}, },
_toggleAll : function() { _toggleAll : function() {
var checked = this.ui.renameAll.prop('checked'); var checked = this.ui.renameAll.prop('checked');
this._setCheckedState(checked); this._setCheckedState(checked);
this.collection.each(function(model) { this.collection.each(function(model) {
model.trigger('rename:select', model, checked); model.trigger('rename:select', model, checked);
}); });
}, },
_itemRenameChanged : function(model, checked) { _itemRenameChanged : function(model, checked) {
var allChecked = this.collection.all(function(m) { var allChecked = this.collection.all(function(m) {
return m.get('rename'); return m.get('rename');
}); });
if (!checked || allChecked) { if (!checked || allChecked) {
this._setCheckedState(checked); this._setCheckedState(checked);
} }

View File

@ -1,4 +1,4 @@
<div class="modal-content"> <div class="modal-content">
<div class="rename-preview-modal"> <div class="rename-preview-modal">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

View File

@ -8,58 +8,74 @@ require('../Mixins/backbone.signalr.mixin');
module.exports = Marionette.Layout.extend({ module.exports = Marionette.Layout.extend({
template : 'SeasonPass/SeasonPassLayoutTemplate', template : 'SeasonPass/SeasonPassLayoutTemplate',
regions : { regions : {
toolbar : '#x-toolbar', toolbar : '#x-toolbar',
series : '#x-series' series : '#x-series'
}, },
initialize : function() { initialize : function() {
this.seriesCollection = SeriesCollection.clone(); this.seriesCollection = SeriesCollection.clone();
this.seriesCollection.shadowCollection.bindSignalR(); this.seriesCollection.shadowCollection.bindSignalR();
this.listenTo(this.seriesCollection, 'sync', this.render); this.listenTo(this.seriesCollection, 'sync', this.render);
this.filteringOptions = { this.filteringOptions = {
type : 'radio', type : 'radio',
storeState : true, storeState : true,
menuKey : 'seasonpass.filterMode', menuKey : 'seasonpass.filterMode',
defaultAction : 'all', defaultAction : 'all',
items : [{ items : [
{
key : 'all', key : 'all',
title : '', title : '',
tooltip : 'All', tooltip : 'All',
icon : 'icon-circle-blank', icon : 'icon-circle-blank',
callback : this._setFilter callback : this._setFilter
}, { },
{
key : 'monitored', key : 'monitored',
title : '', title : '',
tooltip : 'Monitored Only', tooltip : 'Monitored Only',
icon : 'icon-nd-monitored', icon : 'icon-nd-monitored',
callback : this._setFilter callback : this._setFilter
}, { },
{
key : 'continuing', key : 'continuing',
title : '', title : '',
tooltip : 'Continuing Only', tooltip : 'Continuing Only',
icon : 'icon-play', icon : 'icon-play',
callback : this._setFilter callback : this._setFilter
}, { },
{
key : 'ended', key : 'ended',
title : '', title : '',
tooltip : 'Ended Only', tooltip : 'Ended Only',
icon : 'icon-stop', icon : 'icon-stop',
callback : this._setFilter callback : this._setFilter
}] }
]
}; };
}, },
onRender : function() { onRender : function() {
this.series.show(new SeriesCollectionView({collection : this.seriesCollection})); this.series.show(new SeriesCollectionView({
collection : this.seriesCollection
}));
this._showToolbar(); this._showToolbar();
}, },
_showToolbar : function() { _showToolbar : function() {
this.toolbar.show(new ToolbarLayout({ this.toolbar.show(new ToolbarLayout({
right : [this.filteringOptions], right : [this.filteringOptions],
context : this context : this
})); }));
}, },
_setFilter : function(buttonContext) { _setFilter : function(buttonContext) {
var mode = buttonContext.model.get('key'); var mode = buttonContext.model.get('key');
this.seriesCollection.setFilterMode(mode); this.seriesCollection.setFilterMode(mode);
} }
}); });

View File

@ -1,4 +1,6 @@
var Marionette = require('marionette'); var Marionette = require('marionette');
var SeriesLayout = require('./SeriesLayout'); var SeriesLayout = require('./SeriesLayout');
module.exports = Marionette.CollectionView.extend({itemView : SeriesLayout}); module.exports = Marionette.CollectionView.extend({
itemView : SeriesLayout
});

View File

@ -5,112 +5,148 @@ var SeasonCollection = require('../Series/SeasonCollection');
module.exports = Marionette.Layout.extend({ module.exports = Marionette.Layout.extend({
template : 'SeasonPass/SeriesLayoutTemplate', template : 'SeasonPass/SeriesLayoutTemplate',
ui : { ui : {
seasonSelect : '.x-season-select', seasonSelect : '.x-season-select',
expander : '.x-expander', expander : '.x-expander',
seasonGrid : '.x-season-grid', seasonGrid : '.x-season-grid',
seriesMonitored : '.x-series-monitored' seriesMonitored : '.x-series-monitored'
}, },
events : { events : {
"change .x-season-select" : '_seasonSelected', 'change .x-season-select' : '_seasonSelected',
"click .x-expander" : '_expand', 'click .x-expander' : '_expand',
"click .x-latest" : '_latest', 'click .x-latest' : '_latest',
"click .x-all" : '_all', 'click .x-all' : '_all',
"click .x-monitored" : '_toggleSeasonMonitored', 'click .x-monitored' : '_toggleSeasonMonitored',
"click .x-series-monitored" : '_toggleSeriesMonitored' 'click .x-series-monitored' : '_toggleSeriesMonitored'
}, },
regions : {seasonGrid : '.x-season-grid'},
regions : {
seasonGrid : '.x-season-grid'
},
initialize : function() { initialize : function() {
this.listenTo(this.model, 'sync', this._setSeriesMonitoredState); this.listenTo(this.model, 'sync', this._setSeriesMonitoredState);
this.seasonCollection = new SeasonCollection(this.model.get('seasons')); this.seasonCollection = new SeasonCollection(this.model.get('seasons'));
this.expanded = false; this.expanded = false;
}, },
onRender : function() { onRender : function() {
if (!this.expanded) { if (!this.expanded) {
this.ui.seasonGrid.hide(); this.ui.seasonGrid.hide();
} }
this._setExpanderIcon(); this._setExpanderIcon();
this._setSeriesMonitoredState(); this._setSeriesMonitoredState();
}, },
_seasonSelected : function() { _seasonSelected : function() {
var seasonNumber = parseInt(this.ui.seasonSelect.val(), 10); var seasonNumber = parseInt(this.ui.seasonSelect.val(), 10);
if (seasonNumber === -1 || isNaN(seasonNumber)) { if (seasonNumber === -1 || isNaN(seasonNumber)) {
return; return;
} }
this._setSeasonMonitored(seasonNumber); this._setSeasonMonitored(seasonNumber);
}, },
_expand : function() { _expand : function() {
if (this.expanded) { if (this.expanded) {
this.ui.seasonGrid.slideUp(); this.ui.seasonGrid.slideUp();
this.expanded = false; this.expanded = false;
} }
else { else {
this.ui.seasonGrid.slideDown(); this.ui.seasonGrid.slideDown();
this.expanded = true; this.expanded = true;
} }
this._setExpanderIcon(); this._setExpanderIcon();
}, },
_setExpanderIcon : function() { _setExpanderIcon : function() {
if (this.expanded) { if (this.expanded) {
this.ui.expander.removeClass('icon-chevron-right'); this.ui.expander.removeClass('icon-chevron-right');
this.ui.expander.addClass('icon-chevron-down'); this.ui.expander.addClass('icon-chevron-down');
} }
else { else {
this.ui.expander.removeClass('icon-chevron-down'); this.ui.expander.removeClass('icon-chevron-down');
this.ui.expander.addClass('icon-chevron-right'); this.ui.expander.addClass('icon-chevron-right');
} }
}, },
_latest : function() { _latest : function() {
var season = _.max(this.model.get('seasons'), function(s) { var season = _.max(this.model.get('seasons'), function(s) {
return s.seasonNumber; return s.seasonNumber;
}); });
this._setSeasonMonitored(season.seasonNumber); this._setSeasonMonitored(season.seasonNumber);
}, },
_all : function() { _all : function() {
var minSeasonNotZero = _.min(_.reject(this.model.get('seasons'), { seasonNumber : 0 }), 'seasonNumber'); var minSeasonNotZero = _.min(_.reject(this.model.get('seasons'), { seasonNumber : 0 }), 'seasonNumber');
this._setSeasonMonitored(minSeasonNotZero.seasonNumber); this._setSeasonMonitored(minSeasonNotZero.seasonNumber);
}, },
_setSeasonMonitored : function(seasonNumber) { _setSeasonMonitored : function(seasonNumber) {
var self = this; var self = this;
this.model.setSeasonPass(seasonNumber); this.model.setSeasonPass(seasonNumber);
var promise = this.model.save(); var promise = this.model.save();
promise.done(function(data) { promise.done(function(data) {
self.seasonCollection = new SeasonCollection(data); self.seasonCollection = new SeasonCollection(data);
self.render(); self.render();
}); });
}, },
_toggleSeasonMonitored : function(e) { _toggleSeasonMonitored : function(e) {
var seasonNumber = 0; var seasonNumber = 0;
var element; var element;
if (e.target.localName === 'i') { if (e.target.localName === 'i') {
seasonNumber = parseInt(this.$(e.target).parent('td').attr('data-season-number'), 10); seasonNumber = parseInt(this.$(e.target).parent('td').attr('data-season-number'), 10);
element = this.$(e.target); element = this.$(e.target);
} }
else { else {
seasonNumber = parseInt(this.$(e.target).attr('data-season-number'), 10); seasonNumber = parseInt(this.$(e.target).attr('data-season-number'), 10);
element = this.$(e.target).children('i'); element = this.$(e.target).children('i');
} }
this.model.setSeasonMonitored(seasonNumber); this.model.setSeasonMonitored(seasonNumber);
var savePromise = this.model.save().always(this.render.bind(this)); var savePromise = this.model.save().always(this.render.bind(this));
element.spinForPromise(savePromise); element.spinForPromise(savePromise);
}, },
_afterToggleSeasonMonitored : function() { _afterToggleSeasonMonitored : function() {
this.render(); this.render();
}, },
_setSeriesMonitoredState : function() { _setSeriesMonitoredState : function() {
var monitored = this.model.get('monitored'); var monitored = this.model.get('monitored');
this.ui.seriesMonitored.removeAttr('data-idle-icon'); this.ui.seriesMonitored.removeAttr('data-idle-icon');
if (monitored) { if (monitored) {
this.ui.seriesMonitored.addClass('icon-nd-monitored'); this.ui.seriesMonitored.addClass('icon-nd-monitored');
this.ui.seriesMonitored.removeClass('icon-nd-unmonitored'); this.ui.seriesMonitored.removeClass('icon-nd-unmonitored');
} } else {
else {
this.ui.seriesMonitored.addClass('icon-nd-unmonitored'); this.ui.seriesMonitored.addClass('icon-nd-unmonitored');
this.ui.seriesMonitored.removeClass('icon-nd-monitored'); this.ui.seriesMonitored.removeClass('icon-nd-monitored');
} }
}, },
_toggleSeriesMonitored : function() { _toggleSeriesMonitored : function() {
var savePromise = this.model.save('monitored', !this.model.get('monitored'), {wait : true}); var savePromise = this.model.save('monitored', !this.model.get('monitored'), {
wait : true
});
this.ui.seriesMonitored.spinForPromise(savePromise); this.ui.seriesMonitored.spinForPromise(savePromise);
} }
}); });