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',
|
|
|
|
'Series/SeasonCollection',
|
|
|
|
'Series/Details/SeasonCollectionView',
|
2013-07-12 07:33:26 +00:00
|
|
|
'Series/Edit/EditSeriesView',
|
2013-06-24 23:41:59 +00:00
|
|
|
'Shared/LoadingView',
|
2013-07-12 07:33:26 +00:00
|
|
|
'Commands/CommandController',
|
2013-06-24 23:41:59 +00:00
|
|
|
'backstrech'
|
2013-07-12 07:33:26 +00:00
|
|
|
], function (App, Marionette, EpisodeCollection, SeasonCollection, SeasonCollectionView, EditSeriesView, LoadingView, CommandController) {
|
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: {
|
|
|
|
seasons: '#seasons'
|
|
|
|
},
|
|
|
|
|
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',
|
|
|
|
rename : '.x-rename'
|
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',
|
|
|
|
'click .x-rename' : '_renameSeries'
|
2013-06-07 05:15:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
$('body').addClass('backdrop');
|
2013-07-12 07:33:26 +00:00
|
|
|
|
|
|
|
this.model.on('sync', function () {
|
|
|
|
this._setMonitoredState()
|
|
|
|
}, this);
|
2013-07-18 15:21:21 +00:00
|
|
|
|
|
|
|
this.listenTo(App.vent, App.Events.SeriesDeleted, this._onSeriesDeleted);
|
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-06-01 19:31:39 +00:00
|
|
|
var self = this;
|
|
|
|
|
2013-07-16 23:54:45 +00:00
|
|
|
var fanArt = this._getFanArt();
|
|
|
|
|
|
|
|
if (fanArt) {
|
|
|
|
$.backstretch(fanArt);
|
2013-06-14 00:39:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('body').removeClass('backdrop');
|
|
|
|
}
|
2013-06-07 05:15:07 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
this.seasons.show(new LoadingView());
|
2013-06-01 19:31:39 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
this.seasonCollection = new SeasonCollection();
|
|
|
|
this.episodeCollection = new EpisodeCollection();
|
2013-06-01 19:31:39 +00:00
|
|
|
|
2013-06-24 23:41:59 +00: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 00:35:21 +00:00
|
|
|
episodeCollection: self.episodeCollection,
|
|
|
|
series : self.model
|
2013-06-24 23:41:59 +00:00
|
|
|
}));
|
|
|
|
});
|
2013-07-12 07:33:26 +00:00
|
|
|
|
|
|
|
this._setMonitoredState();
|
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'});
|
|
|
|
|
|
|
|
if(fanArt && fanArt[0]){
|
|
|
|
return fanArt[0].url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
2013-06-01 19:31:39 +00:00
|
|
|
onClose: function () {
|
|
|
|
$('.backstretch').remove();
|
2013-06-07 05:15:07 +00:00
|
|
|
$('body').removeClass('backdrop');
|
2013-07-12 07:33:26 +00: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-16 23:54:45 +00:00
|
|
|
promise.always(function () {
|
2013-07-12 07:33:26 +00:00
|
|
|
self._setMonitoredState();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setMonitoredState: function () {
|
|
|
|
var monitored = this.model.get('monitored');
|
|
|
|
|
2013-07-19 01:49:04 +00:00
|
|
|
this.ui.monitored.removeClass('icon-spin icon-spinner');
|
2013-07-12 07:33:26 +00: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 05:24:18 +00:00
|
|
|
this.ui.refresh.addClass('icon-spin');
|
2013-07-12 07:33:26 +00:00
|
|
|
var promise = CommandController.Execute('refreshseries', { seriesId: this.model.get('id') });
|
|
|
|
|
|
|
|
promise.always(function () {
|
2013-07-14 05:24:18 +00:00
|
|
|
self.ui.refresh.removeClass('icon-spin');
|
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 () {
|
|
|
|
var command = 'renameSeries';
|
|
|
|
|
|
|
|
this.idle = false;
|
|
|
|
|
|
|
|
this.ui.rename.toggleClass('icon-nd-rename icon-nd-spinner');
|
|
|
|
|
|
|
|
var properties = {
|
|
|
|
seriesId : this.model.get('id')
|
|
|
|
};
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var commandPromise = CommandController.Execute(command, properties);
|
|
|
|
|
|
|
|
commandPromise.fail(function (options) {
|
|
|
|
if (options.readyState === 0 || options.status === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Messenger.show({
|
|
|
|
message: 'Season rename failed',
|
|
|
|
type : 'error'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
commandPromise.always(function () {
|
|
|
|
if (!self.isClosed) {
|
|
|
|
self.ui.rename.toggleClass('icon-nd-rename icon-nd-spinner');
|
|
|
|
self.idle = true;
|
|
|
|
}
|
|
|
|
});
|
2013-06-01 19:31:39 +00:00
|
|
|
}
|
|
|
|
});
|
2013-06-24 23:41:59 +00:00
|
|
|
});
|