1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 16:32:56 +01:00
Sonarr/UI/Series/Details/SeriesDetailsLayout.js

133 lines
4.3 KiB
JavaScript
Raw Normal View History

2013-06-22 08:24:24 +02:00
'use strict';
define(
[
'app',
'marionette',
'Series/EpisodeCollection',
'Series/SeasonCollection',
'Series/Details/SeasonCollectionView',
'Series/Edit/EditSeriesView',
'Shared/LoadingView',
'Commands/CommandController',
'backstrech'
], function (App, Marionette, EpisodeCollection, SeasonCollection, SeasonCollectionView, EditSeriesView, LoadingView, CommandController) {
return Marionette.Layout.extend({
itemViewContainer: '.x-series-seasons',
template : 'Series/Details/SeriesDetailsTemplate',
regions: {
seasons: '#seasons'
},
ui: {
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'
},
initialize: function () {
$('body').addClass('backdrop');
this.model.on('sync', function () {
this._setMonitoredState()
}, this);
},
onShow: function () {
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');
}
this.seasons.show(new LoadingView());
this.seasonCollection = new SeasonCollection();
this.episodeCollection = new EpisodeCollection();
$.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,
episodeCollection: self.episodeCollection,
series : self.model
}));
});
this._setMonitoredState();
},
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;
},
onClose: function () {
$('.backstretch').remove();
$('body').removeClass('backdrop');
},
_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 () {
self._setMonitoredState();
});
},
_setMonitoredState: function () {
var monitored = this.model.get('monitored');
2013-07-14 07:24:18 +02:00
this.ui.monitored.removeClass('icon-spin');
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');
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');
});
}
});
});