2013-06-22 06:24:24 +00:00
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
2013-07-12 07:33:26 +00:00
|
|
|
'app',
|
2013-06-24 23:41:59 +00:00
|
|
|
'marionette',
|
|
|
|
'Series/EpisodeCollection',
|
2013-08-22 00:56:25 +00:00
|
|
|
'Series/EpisodeFileCollection',
|
2013-06-24 23:41:59 +00:00
|
|
|
'Series/SeasonCollection',
|
|
|
|
'Series/Details/SeasonCollectionView',
|
2013-08-13 23:42:16 +00:00
|
|
|
'Series/Details/InfoView',
|
2013-09-11 06:33:47 +00:00
|
|
|
'Commands/CommandController',
|
2013-06-24 23:41:59 +00:00
|
|
|
'Shared/LoadingView',
|
2013-08-10 18:38:01 +00:00
|
|
|
'backstrech',
|
|
|
|
'Mixins/backbone.signalr.mixin'
|
2013-09-12 00:42:15 +00:00
|
|
|
], function (App, Marionette, EpisodeCollection, EpisodeFileCollection, SeasonCollection, SeasonCollectionView, InfoView, CommandController, LoadingView) {
|
2013-06-24 23:41:59 +00:00
|
|
|
return Marionette.Layout.extend({
|
2013-06-01 19:31:39 +00:00
|
|
|
|
|
|
|
itemViewContainer: '.x-series-seasons',
|
|
|
|
template : 'Series/Details/SeriesDetailsTemplate',
|
|
|
|
|
|
|
|
regions: {
|
2013-09-11 06:33:47 +00:00
|
|
|
seasons: '#seasons',
|
|
|
|
info : '#info'
|
2013-06-01 19:31:39 +00:00
|
|
|
},
|
|
|
|
|
2013-06-07 05:15:07 +00:00
|
|
|
ui: {
|
2013-07-12 07:33:26 +00:00
|
|
|
header : '.x-header',
|
|
|
|
monitored: '.x-monitored',
|
|
|
|
edit : '.x-edit',
|
2013-07-19 05:23:04 +00:00
|
|
|
refresh : '.x-refresh',
|
2013-07-22 02:52:53 +00:00
|
|
|
rename : '.x-rename',
|
|
|
|
search : '.x-search'
|
2013-07-12 07:33:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .x-monitored': '_toggleMonitored',
|
|
|
|
'click .x-edit' : '_editSeries',
|
2013-07-19 05:23:04 +00:00
|
|
|
'click .x-refresh' : '_refreshSeries',
|
2013-07-22 02:52:53 +00:00
|
|
|
'click .x-rename' : '_renameSeries',
|
|
|
|
'click .x-search' : '_seriesSearch'
|
2013-06-07 05:15:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
2013-09-11 23:42:39 +00:00
|
|
|
this.listenTo(this.model, 'change:monitored', this._setMonitoredState);
|
2013-07-18 15:21:21 +00:00
|
|
|
this.listenTo(App.vent, App.Events.SeriesDeleted, this._onSeriesDeleted);
|
2013-09-03 05:02:47 +00:00
|
|
|
this.listenTo(App.vent, App.Events.SeasonRenamed, this._onSeasonRenamed);
|
2013-06-07 05:15:07 +00:00
|
|
|
},
|
2013-06-01 19:31:39 +00:00
|
|
|
|
2013-06-07 05:15:07 +00:00
|
|
|
onShow: function () {
|
2013-09-22 07:55:44 +00:00
|
|
|
$('body').addClass('backdrop');
|
2013-07-16 23:54:45 +00:00
|
|
|
var fanArt = this._getFanArt();
|
|
|
|
|
|
|
|
if (fanArt) {
|
2013-08-21 19:07:28 +00:00
|
|
|
this._backstrech = $.backstretch(fanArt);
|
2013-06-14 00:39:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('body').removeClass('backdrop');
|
|
|
|
}
|
2013-06-07 05:15:07 +00:00
|
|
|
|
2013-08-04 19:30:04 +00:00
|
|
|
this._showSeasons();
|
2013-07-12 07:33:26 +00:00
|
|
|
this._setMonitoredState();
|
2013-08-13 23:42:16 +00:00
|
|
|
this._showInfo();
|
2013-09-11 06:33:47 +00:00
|
|
|
},
|
|
|
|
|
2013-09-11 23:42:39 +00:00
|
|
|
onRender: function () {
|
2013-09-12 00:42:15 +00:00
|
|
|
CommandController.bindToCommand({
|
2013-09-11 06:33:47 +00:00
|
|
|
element: this.ui.refresh,
|
|
|
|
command: {
|
2013-09-11 23:42:39 +00:00
|
|
|
name: 'refreshSeries'
|
2013-09-11 06:33:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-12 00:42:15 +00:00
|
|
|
CommandController.bindToCommand({
|
2013-09-11 06:33:47 +00:00
|
|
|
element: this.ui.search,
|
|
|
|
command: {
|
2013-09-11 23:42:39 +00:00
|
|
|
name: 'seriesSearch'
|
2013-09-11 06:33:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-12 00:42:15 +00:00
|
|
|
CommandController.bindToCommand({
|
2013-09-11 06:33:47 +00:00
|
|
|
element: this.ui.rename,
|
|
|
|
command: {
|
2013-09-11 23:42:39 +00:00
|
|
|
name: 'renameSeries'
|
2013-09-11 06:33:47 +00:00
|
|
|
}
|
|
|
|
});
|
2013-06-01 19:31:39 +00:00
|
|
|
},
|
|
|
|
|
2013-07-16 23:54:45 +00:00
|
|
|
_getFanArt: function () {
|
|
|
|
var fanArt = _.where(this.model.get('images'), {coverType: 'fanart'});
|
|
|
|
|
2013-07-24 01:15:58 +00:00
|
|
|
if (fanArt && fanArt[0]) {
|
2013-07-16 23:54:45 +00:00
|
|
|
return fanArt[0].url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
2013-06-01 19:31:39 +00:00
|
|
|
onClose: function () {
|
2013-08-21 19:07:28 +00:00
|
|
|
|
|
|
|
if (this._backstrech) {
|
|
|
|
this._backstrech.destroy();
|
|
|
|
delete this._backstrech;
|
|
|
|
}
|
|
|
|
|
2013-06-07 05:15:07 +00:00
|
|
|
$('body').removeClass('backdrop');
|
2013-08-22 00:56:25 +00:00
|
|
|
App.reqres.removeHandler(App.Reqres.GetEpisodeFileById);
|
2013-07-12 07:33:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_toggleMonitored: function () {
|
2013-09-11 23:42:39 +00:00
|
|
|
var savePromise = this.model.save('monitored', !this.model.get('monitored'), {
|
|
|
|
wait: true
|
2013-07-12 07:33:26 +00:00
|
|
|
});
|
2013-09-11 23:42:39 +00:00
|
|
|
|
|
|
|
this.ui.monitored.spinForPromise(savePromise);
|
2013-07-12 07:33:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_setMonitoredState: function () {
|
|
|
|
var monitored = this.model.get('monitored');
|
|
|
|
|
2013-09-11 23:42:39 +00:00
|
|
|
this.ui.monitored.removeAttr('data-idle-icon');
|
2013-07-12 07:33:26 +00:00
|
|
|
|
2013-09-11 23:42:39 +00:00
|
|
|
if (monitored) {
|
2013-09-10 05:22:38 +00:00
|
|
|
this.ui.monitored.addClass('icon-nd-monitored');
|
|
|
|
this.ui.monitored.removeClass('icon-nd-unmonitored');
|
2013-07-12 07:33:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-09-10 05:22:38 +00:00
|
|
|
this.ui.monitored.addClass('icon-nd-unmonitored');
|
|
|
|
this.ui.monitored.removeClass('icon-nd-monitored');
|
2013-07-12 07:33:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_editSeries: function () {
|
2013-07-25 00:41:31 +00:00
|
|
|
App.vent.trigger(App.Commands.EditSeriesCommand, {series: this.model});
|
2013-07-12 07:33:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_refreshSeries: function () {
|
2013-09-11 06:33:47 +00:00
|
|
|
CommandController.Execute('refreshSeries', {
|
|
|
|
name : 'refreshSeries',
|
|
|
|
seriesId: this.model.id
|
2013-07-12 07:33:26 +00:00
|
|
|
});
|
2013-07-18 15:21:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onSeriesDeleted: function (event) {
|
|
|
|
|
|
|
|
if (this.model.get('id') === event.series.get('id')) {
|
|
|
|
App.Router.navigate('/', { trigger: true });
|
|
|
|
}
|
2013-07-19 05:23:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_renameSeries: function () {
|
2013-09-11 06:33:47 +00:00
|
|
|
|
|
|
|
CommandController.Execute('renameSeries', {
|
|
|
|
name : 'renameSeries',
|
|
|
|
seriesId: this.model.id
|
2013-07-19 05:23:04 +00:00
|
|
|
});
|
2013-09-11 06:33:47 +00:00
|
|
|
|
2013-07-22 02:52:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_seriesSearch: function () {
|
2013-09-11 06:33:47 +00:00
|
|
|
CommandController.Execute('seriesSearch', {
|
|
|
|
name : 'seriesSearch',
|
|
|
|
seriesId: this.model.id
|
2013-07-22 02:52:53 +00:00
|
|
|
});
|
2013-08-04 19:30:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_showSeasons: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.seasons.show(new LoadingView());
|
|
|
|
|
2013-09-10 05:22:38 +00:00
|
|
|
this.seasonCollection = new SeasonCollection(this.model.get('seasons'));
|
2013-08-10 18:38:01 +00:00
|
|
|
this.episodeCollection = new EpisodeCollection({ seriesId: this.model.id });
|
2013-08-22 00:56:25 +00:00
|
|
|
this.episodeFileCollection = new EpisodeFileCollection({ seriesId: this.model.id });
|
2013-08-04 19:30:04 +00:00
|
|
|
|
2013-09-10 05:22:38 +00:00
|
|
|
$.when(this.episodeCollection.fetch(), this.episodeFileCollection.fetch()).done(function () {
|
2013-08-10 18:38:01 +00:00
|
|
|
var seasonCollectionView = new SeasonCollectionView({
|
2013-08-04 19:30:04 +00:00
|
|
|
collection : self.seasonCollection,
|
|
|
|
episodeCollection: self.episodeCollection,
|
|
|
|
series : self.model
|
2013-08-10 18:38:01 +00:00
|
|
|
});
|
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
App.reqres.setHandler(App.Reqres.GetEpisodeFileById, function (episodeFileId) {
|
2013-08-22 00:56:25 +00:00
|
|
|
return self.episodeFileCollection.get(episodeFileId);
|
|
|
|
});
|
|
|
|
|
2013-08-10 18:38:01 +00:00
|
|
|
self.seasons.show(seasonCollectionView);
|
2013-08-04 19:30:04 +00:00
|
|
|
});
|
2013-08-13 23:42:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_showInfo: function () {
|
|
|
|
this.info.show(new InfoView({ model: this.model }));
|
2013-08-23 05:37:37 +00:00
|
|
|
},
|
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
_onSeasonRenamed: function (event) {
|
2013-09-03 05:02:47 +00:00
|
|
|
if (this.model.get('id') === event.series.get('id')) {
|
2013-09-12 00:42:15 +00:00
|
|
|
this.episodeFileCollection.fetch();
|
2013-09-03 05:02:47 +00:00
|
|
|
}
|
2013-06-01 19:31:39 +00:00
|
|
|
}
|
|
|
|
});
|
2013-06-24 23:41:59 +00:00
|
|
|
});
|