From bd1a9db0ef3e5b772e71df427736d9ff4af1c45c Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 29 Sep 2013 01:48:47 -0700 Subject: [PATCH] refresh series details after rename/refresh Fixed: Refresh series details after series refresh and rename --- UI/Commands/CommandController.js | 68 ++++++++++++++---------- UI/Commands/CommandModel.js | 14 +++-- UI/Series/Details/SeriesDetailsLayout.js | 12 +++++ UI/app.js | 8 +-- 4 files changed, 64 insertions(+), 38 deletions(-) diff --git a/UI/Commands/CommandController.js b/UI/Commands/CommandController.js index f859e2c51..8e14512cf 100644 --- a/UI/Commands/CommandController.js +++ b/UI/Commands/CommandController.js @@ -1,56 +1,66 @@ 'use strict'; define( [ + 'app', 'Commands/CommandModel', 'Commands/CommandCollection', 'underscore', 'jQuery/jquery.spin' - ], function (CommandModel, CommandCollection, _) { + ], function (App, CommandModel, CommandCollection, _) { - return{ + var singleton = function () { - Execute: function (name, properties) { + return { - var attr = _.extend({name: name.toLocaleLowerCase()}, properties); + Execute: function (name, properties) { - var commandModel = new CommandModel(attr); + var attr = _.extend({name: name.toLocaleLowerCase()}, properties); - return commandModel.save().success(function () { - CommandCollection.add(commandModel); - }); - }, + var commandModel = new CommandModel(attr); - bindToCommand: function (options) { + return commandModel.save().success(function () { + CommandCollection.add(commandModel); + }); + }, - var self = this; + bindToCommand: function (options) { - var existingCommand = CommandCollection.findCommand(options.command); + var self = this; - if (existingCommand) { - this._bindToCommandModel.call(this, existingCommand, options); - } + var existingCommand = CommandCollection.findCommand(options.command); - CommandCollection.bind('add sync', function (model) { - if (model.isSameCommand(options.command)) { - self._bindToCommandModel.call(self, model, options); + if (existingCommand) { + this._bindToCommandModel.call(this, existingCommand, options); } - }); - }, - _bindToCommandModel: function bindToCommand(model, options) { + CommandCollection.bind('add sync', function (model) { + if (model.isSameCommand(options.command)) { + self._bindToCommandModel.call(self, model, options); + } + }); + }, - if (!model.isActive()) { - options.element.stopSpin(); - return; - } + _bindToCommandModel: function bindToCommand(model, options) { - model.bind('change:state', function (model) { if (!model.isActive()) { options.element.stopSpin(); + return; } - }); - options.element.startSpin(); - } + model.bind('change:state', function (model) { + if (!model.isActive()) { + options.element.stopSpin(); + + if (model.isComplete()) { + App.vent.trigger(App.Events.CommandComplete, { command: model, model: options.model }); + } + } + }); + + options.element.startSpin(); + } + }; }; + + return singleton(); }); diff --git a/UI/Commands/CommandModel.js b/UI/Commands/CommandModel.js index fcb08dd6d..cdb492ca6 100644 --- a/UI/Commands/CommandModel.js +++ b/UI/Commands/CommandModel.js @@ -11,13 +11,9 @@ define( return response; }, - isActive: function () { - return this.get('state') !== 'completed' && this.get('state') !== 'failed'; - }, - isSameCommand: function (command) { - if (command.name.toLocaleLowerCase() != this.get('name').toLocaleLowerCase()) { + if (command.name.toLocaleLowerCase() !== this.get('name').toLocaleLowerCase()) { return false; } @@ -28,6 +24,14 @@ define( } return true; + }, + + isActive: function () { + return this.get('state') !== 'completed' && this.get('state') !== 'failed'; + }, + + isComplete: function () { + return this.get('state') === 'completed'; } }); }); diff --git a/UI/Series/Details/SeriesDetailsLayout.js b/UI/Series/Details/SeriesDetailsLayout.js index 238ffb00c..d08abac58 100644 --- a/UI/Series/Details/SeriesDetailsLayout.js +++ b/UI/Series/Details/SeriesDetailsLayout.js @@ -44,6 +44,8 @@ define( this.listenTo(this.model, 'change:monitored', this._setMonitoredState); this.listenTo(App.vent, App.Events.SeriesDeleted, this._onSeriesDeleted); this.listenTo(App.vent, App.Events.SeasonRenamed, this._onSeasonRenamed); + + App.vent.on(App.Events.CommandComplete, this._commandComplete, this); }, onShow: function () { @@ -195,6 +197,16 @@ define( if (this.model.get('id') === event.series.get('id')) { this.episodeFileCollection.fetch(); } + }, + + _commandComplete: function (options) { + if (options.command.get('name') === 'refreshseries' || options.command.get('name') === 'renameseries') { + if (options.command.get('seriesId') === this.model.get('id')) { + this._showSeasons(); + this._setMonitoredState(); + this._showInfo(); + } + } } }); }); diff --git a/UI/app.js b/UI/app.js index 8f64f4790..1834d9163 100644 --- a/UI/app.js +++ b/UI/app.js @@ -25,7 +25,6 @@ require.config({ 'jquery.knob' : 'JsLibraries/jquery.knob', 'jquery.dotdotdot' : 'JsLibraries/jquery.dotdotdot', 'libs' : 'JsLibraries/' - }, shim: { @@ -191,9 +190,10 @@ define( var app = new Marionette.Application(); app.Events = { - SeriesAdded : 'series:added', - SeriesDeleted: 'series:deleted', - SeasonRenamed: 'season:renamed' + SeriesAdded : 'series:added', + SeriesDeleted : 'series:deleted', + SeasonRenamed : 'season:renamed', + CommandComplete: 'command:complete' }; app.Commands = {