2013-06-22 09:24:24 +03:00
|
|
|
'use strict';
|
2013-06-25 02:41:59 +03:00
|
|
|
define(
|
|
|
|
[
|
2013-07-12 10:33:26 +03:00
|
|
|
'app',
|
2013-06-25 02:41:59 +03:00
|
|
|
'marionette',
|
|
|
|
'Series/EpisodeCollection',
|
|
|
|
'Series/SeasonCollection',
|
|
|
|
'Series/Details/SeasonCollectionView',
|
|
|
|
'Shared/LoadingView',
|
2013-07-22 05:23:17 +03:00
|
|
|
'Shared/Actioneer',
|
2013-06-25 02:41:59 +03:00
|
|
|
'backstrech'
|
2013-07-24 04:15:58 +03:00
|
|
|
], function (App, Marionette, EpisodeCollection, SeasonCollection, SeasonCollectionView, LoadingView, Actioneer) {
|
2013-06-25 02:41:59 +03:00
|
|
|
return Marionette.Layout.extend({
|
2013-06-01 22:31:39 +03:00
|
|
|
|
|
|
|
itemViewContainer: '.x-series-seasons',
|
|
|
|
template : 'Series/Details/SeriesDetailsTemplate',
|
|
|
|
|
|
|
|
regions: {
|
|
|
|
seasons: '#seasons'
|
|
|
|
},
|
|
|
|
|
2013-06-07 08:15:07 +03:00
|
|
|
ui: {
|
2013-07-12 10:33:26 +03:00
|
|
|
header : '.x-header',
|
|
|
|
monitored: '.x-monitored',
|
|
|
|
edit : '.x-edit',
|
2013-07-19 08:23:04 +03:00
|
|
|
refresh : '.x-refresh',
|
2013-07-22 05:52:53 +03:00
|
|
|
rename : '.x-rename',
|
|
|
|
search : '.x-search'
|
2013-07-12 10:33:26 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .x-monitored': '_toggleMonitored',
|
|
|
|
'click .x-edit' : '_editSeries',
|
2013-07-19 08:23:04 +03:00
|
|
|
'click .x-refresh' : '_refreshSeries',
|
2013-07-22 05:52:53 +03:00
|
|
|
'click .x-rename' : '_renameSeries',
|
|
|
|
'click .x-search' : '_seriesSearch'
|
2013-06-07 08:15:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
$('body').addClass('backdrop');
|
2013-07-12 10:33:26 +03:00
|
|
|
|
|
|
|
this.model.on('sync', function () {
|
|
|
|
this._setMonitoredState()
|
|
|
|
}, this);
|
2013-07-18 18:21:21 +03:00
|
|
|
|
|
|
|
this.listenTo(App.vent, App.Events.SeriesDeleted, this._onSeriesDeleted);
|
2013-06-07 08:15:07 +03:00
|
|
|
},
|
2013-06-01 22:31:39 +03:00
|
|
|
|
2013-06-07 08:15:07 +03:00
|
|
|
onShow: function () {
|
2013-06-01 22:31:39 +03:00
|
|
|
var self = this;
|
|
|
|
|
2013-07-17 02:54:45 +03:00
|
|
|
var fanArt = this._getFanArt();
|
|
|
|
|
|
|
|
if (fanArt) {
|
|
|
|
$.backstretch(fanArt);
|
2013-06-14 03:39:53 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('body').removeClass('backdrop');
|
|
|
|
}
|
2013-06-07 08:15:07 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
this.seasons.show(new LoadingView());
|
2013-06-01 22:31:39 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
this.seasonCollection = new SeasonCollection();
|
|
|
|
this.episodeCollection = new EpisodeCollection();
|
2013-06-01 22:31:39 +03:00
|
|
|
|
2013-06-25 02:41:59 +03: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 03:35:21 +03:00
|
|
|
episodeCollection: self.episodeCollection,
|
|
|
|
series : self.model
|
2013-06-25 02:41:59 +03:00
|
|
|
}));
|
|
|
|
});
|
2013-07-12 10:33:26 +03:00
|
|
|
|
|
|
|
this._setMonitoredState();
|
2013-06-01 22:31:39 +03:00
|
|
|
},
|
|
|
|
|
2013-07-17 02:54:45 +03:00
|
|
|
_getFanArt: function () {
|
|
|
|
var fanArt = _.where(this.model.get('images'), {coverType: 'fanart'});
|
|
|
|
|
2013-07-24 04:15:58 +03:00
|
|
|
if (fanArt && fanArt[0]) {
|
2013-07-17 02:54:45 +03:00
|
|
|
return fanArt[0].url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
2013-06-01 22:31:39 +03:00
|
|
|
onClose: function () {
|
|
|
|
$('.backstretch').remove();
|
2013-06-07 08:15:07 +03:00
|
|
|
$('body').removeClass('backdrop');
|
2013-07-12 10:33:26 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_toggleMonitored: function () {
|
|
|
|
var name = 'monitored';
|
|
|
|
this.model.set(name, !this.model.get(name), { silent: true });
|
|
|
|
|
2013-07-22 05:23:17 +03:00
|
|
|
Actioneer.SaveModel({
|
|
|
|
context : this,
|
|
|
|
element : this.ui.monitored,
|
|
|
|
alwaysCallback: this._setMonitoredState()
|
2013-07-12 10:33:26 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setMonitoredState: function () {
|
|
|
|
var monitored = this.model.get('monitored');
|
|
|
|
|
2013-07-19 04:49:04 +03:00
|
|
|
this.ui.monitored.removeClass('icon-spin icon-spinner');
|
2013-07-12 10:33:26 +03: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 () {
|
2013-07-25 03:41:31 +03:00
|
|
|
App.vent.trigger(App.Commands.EditSeriesCommand, {series: this.model});
|
2013-07-12 10:33:26 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_refreshSeries: function () {
|
2013-07-22 05:23:17 +03:00
|
|
|
Actioneer.ExecuteCommand({
|
2013-07-24 04:15:58 +03:00
|
|
|
command : 'refreshSeries',
|
|
|
|
properties: {
|
|
|
|
seriesId: this.model.get('id')
|
2013-07-22 05:23:17 +03:00
|
|
|
},
|
2013-07-24 04:15:58 +03:00
|
|
|
element : this.ui.refresh,
|
|
|
|
leaveIcon : true
|
2013-07-12 10:33:26 +03:00
|
|
|
});
|
2013-07-18 18:21:21 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_onSeriesDeleted: function (event) {
|
|
|
|
|
|
|
|
if (this.model.get('id') === event.series.get('id')) {
|
|
|
|
App.Router.navigate('/', { trigger: true });
|
|
|
|
}
|
2013-07-19 08:23:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_renameSeries: function () {
|
2013-07-22 05:23:17 +03:00
|
|
|
Actioneer.ExecuteCommand({
|
|
|
|
command : 'renameSeries',
|
|
|
|
properties : {
|
2013-07-24 04:15:58 +03:00
|
|
|
seriesId: this.model.get('id')
|
2013-07-22 05:23:17 +03:00
|
|
|
},
|
|
|
|
element : this.ui.rename,
|
|
|
|
failMessage: 'Series search failed'
|
2013-07-19 08:23:04 +03:00
|
|
|
});
|
2013-07-22 05:52:53 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_seriesSearch: function () {
|
|
|
|
Actioneer.ExecuteCommand({
|
|
|
|
command : 'seriesSearch',
|
|
|
|
properties : {
|
2013-07-24 04:15:58 +03:00
|
|
|
seriesId: this.model.get('id')
|
2013-07-22 05:52:53 +03:00
|
|
|
},
|
|
|
|
element : this.ui.search,
|
|
|
|
failMessage : 'Series search failed',
|
|
|
|
startMessage: 'Search for {0} started'.format(this.model.get('title'))
|
|
|
|
});
|
2013-06-01 22:31:39 +03:00
|
|
|
}
|
|
|
|
});
|
2013-06-25 02:41:59 +03:00
|
|
|
});
|