2013-06-22 08:24:24 +02:00
|
|
|
'use strict';
|
2013-06-25 01:41:59 +02:00
|
|
|
define(
|
|
|
|
[
|
2013-07-12 09:33:26 +02:00
|
|
|
'app',
|
2013-06-25 01:41:59 +02:00
|
|
|
'marionette',
|
|
|
|
'Series/EpisodeCollection',
|
|
|
|
'Series/SeasonCollection',
|
|
|
|
'Series/Details/SeasonCollectionView',
|
2013-07-12 09:33:26 +02:00
|
|
|
'Series/Edit/EditSeriesView',
|
2013-06-25 01:41:59 +02:00
|
|
|
'Shared/LoadingView',
|
2013-07-12 09:33:26 +02:00
|
|
|
'Commands/CommandController',
|
2013-06-25 01:41:59 +02:00
|
|
|
'backstrech'
|
2013-07-12 09:33:26 +02:00
|
|
|
], function (App, Marionette, EpisodeCollection, SeasonCollection, SeasonCollectionView, EditSeriesView, LoadingView, CommandController) {
|
2013-06-25 01:41:59 +02:00
|
|
|
return Marionette.Layout.extend({
|
2013-06-01 21:31:39 +02:00
|
|
|
|
|
|
|
itemViewContainer: '.x-series-seasons',
|
|
|
|
template : 'Series/Details/SeriesDetailsTemplate',
|
|
|
|
|
|
|
|
regions: {
|
|
|
|
seasons: '#seasons'
|
|
|
|
},
|
|
|
|
|
2013-06-07 07:15:07 +02:00
|
|
|
ui: {
|
2013-07-12 09:33:26 +02:00
|
|
|
header : '.x-header',
|
|
|
|
monitored: '.x-monitored',
|
|
|
|
edit : '.x-edit',
|
|
|
|
refresh : '.x-refresh'
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .x-monitored': '_toggleMonitored',
|
|
|
|
'click .x-edit' : '_editSeries',
|
|
|
|
'click .x-refresh' : '_refreshSeries'
|
2013-06-07 07:15:07 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
$('body').addClass('backdrop');
|
2013-07-12 09:33:26 +02:00
|
|
|
|
|
|
|
this.model.on('sync', function () {
|
|
|
|
this._setMonitoredState()
|
|
|
|
}, this);
|
2013-07-18 17:21:21 +02:00
|
|
|
|
|
|
|
this.listenTo(App.vent, App.Events.SeriesDeleted, this._onSeriesDeleted);
|
2013-06-07 07:15:07 +02:00
|
|
|
},
|
2013-06-01 21:31:39 +02:00
|
|
|
|
2013-06-07 07:15:07 +02:00
|
|
|
onShow: function () {
|
2013-06-01 21:31:39 +02:00
|
|
|
var self = this;
|
|
|
|
|
2013-07-17 01:54:45 +02:00
|
|
|
var fanArt = this._getFanArt();
|
|
|
|
|
|
|
|
if (fanArt) {
|
|
|
|
$.backstretch(fanArt);
|
2013-06-14 02:39:53 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('body').removeClass('backdrop');
|
|
|
|
}
|
2013-06-07 07:15:07 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
this.seasons.show(new LoadingView());
|
2013-06-01 21:31:39 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
this.seasonCollection = new SeasonCollection();
|
|
|
|
this.episodeCollection = new EpisodeCollection();
|
2013-06-01 21:31:39 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
$.when(this.episodeCollection.fetch({data: { seriesId: this.model.id }}), this.seasonCollection.fetch({data: { seriesId: this.model.id }})).done(function () {
|
|
|
|
self.seasons.show(new SeasonCollectionView({
|
|
|
|
collection : self.seasonCollection,
|
2013-06-29 02:35:21 +02:00
|
|
|
episodeCollection: self.episodeCollection,
|
|
|
|
series : self.model
|
2013-06-25 01:41:59 +02:00
|
|
|
}));
|
|
|
|
});
|
2013-07-12 09:33:26 +02:00
|
|
|
|
|
|
|
this._setMonitoredState();
|
2013-06-01 21:31:39 +02:00
|
|
|
},
|
|
|
|
|
2013-07-17 01:54:45 +02:00
|
|
|
_getFanArt: function () {
|
|
|
|
var fanArt = _.where(this.model.get('images'), {coverType: 'fanart'});
|
|
|
|
|
|
|
|
if(fanArt && fanArt[0]){
|
|
|
|
return fanArt[0].url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
2013-06-01 21:31:39 +02:00
|
|
|
onClose: function () {
|
|
|
|
$('.backstretch').remove();
|
2013-06-07 07:15:07 +02:00
|
|
|
$('body').removeClass('backdrop');
|
2013-07-12 09:33:26 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_toggleMonitored: function () {
|
|
|
|
var self = this;
|
|
|
|
var name = 'monitored';
|
|
|
|
this.model.set(name, !this.model.get(name), { silent: true });
|
|
|
|
|
|
|
|
this.ui.monitored.addClass('icon-spinner icon-spin');
|
|
|
|
|
|
|
|
var promise = this.model.save();
|
|
|
|
|
2013-07-17 01:54:45 +02:00
|
|
|
promise.always(function () {
|
2013-07-12 09:33:26 +02:00
|
|
|
self._setMonitoredState();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setMonitoredState: function () {
|
|
|
|
var monitored = this.model.get('monitored');
|
|
|
|
|
2013-07-19 03:49:04 +02:00
|
|
|
this.ui.monitored.removeClass('icon-spin icon-spinner');
|
2013-07-12 09:33:26 +02:00
|
|
|
|
|
|
|
if (this.model.get('monitored')) {
|
|
|
|
this.ui.monitored.addClass('icon-bookmark');
|
|
|
|
this.ui.monitored.removeClass('icon-bookmark-empty');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.ui.monitored.addClass('icon-bookmark-empty');
|
|
|
|
this.ui.monitored.removeClass('icon-bookmark');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_editSeries: function () {
|
|
|
|
var view = new EditSeriesView({ model: this.model });
|
|
|
|
App.modalRegion.show(view);
|
|
|
|
},
|
|
|
|
|
|
|
|
_refreshSeries: function () {
|
|
|
|
var self = this;
|
|
|
|
|
2013-07-14 07:24:18 +02:00
|
|
|
this.ui.refresh.addClass('icon-spin');
|
2013-07-12 09:33:26 +02:00
|
|
|
var promise = CommandController.Execute('refreshseries', { seriesId: this.model.get('id') });
|
|
|
|
|
|
|
|
promise.always(function () {
|
2013-07-14 07:24:18 +02:00
|
|
|
self.ui.refresh.removeClass('icon-spin');
|
2013-07-12 09:33:26 +02:00
|
|
|
});
|
2013-07-18 17:21:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_onSeriesDeleted: function (event) {
|
|
|
|
|
|
|
|
if (this.model.get('id') === event.series.get('id')) {
|
|
|
|
App.Router.navigate('/', { trigger: true });
|
|
|
|
}
|
2013-06-01 21:31:39 +02:00
|
|
|
}
|
|
|
|
});
|
2013-06-25 01:41:59 +02:00
|
|
|
});
|