1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-23 02:05:27 +02:00
Sonarr/UI/Series/Details/SeriesDetailsLayout.js

218 lines
7.4 KiB
JavaScript
Raw Normal View History

2013-06-22 09:24:24 +03:00
'use strict';
define(
[
'app',
'marionette',
'Series/EpisodeCollection',
'Series/EpisodeFileCollection',
'Series/SeasonCollection',
'Series/Details/SeasonCollectionView',
'Series/Details/InfoView',
'Shared/LoadingView',
'Shared/Actioneer',
'backstrech',
'Mixins/backbone.signalr.mixin'
2013-08-22 06:43:48 +03:00
], function (App,
Marionette,
EpisodeCollection,
EpisodeFileCollection,
SeasonCollection,
SeasonCollectionView,
InfoView,
LoadingView,
Actioneer) {
return Marionette.Layout.extend({
itemViewContainer: '.x-series-seasons',
template : 'Series/Details/SeriesDetailsTemplate',
regions: {
seasons : '#seasons',
info : '#info'
},
ui: {
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'
},
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'
},
initialize: function () {
$('body').addClass('backdrop');
this.listenTo(this.model, 'sync', function () {
this._setMonitoredState();
this._showInfo();
}, this);
this.listenTo(App.vent, App.Events.SeriesDeleted, this._onSeriesDeleted);
this.listenTo(App.vent, App.Events.SeasonRenamed, this._onSeasonRenamed);
},
onShow: function () {
2013-07-17 02:54:45 +03:00
var fanArt = this._getFanArt();
if (fanArt) {
2013-08-21 22:07:28 +03:00
this._backstrech = $.backstretch(fanArt);
2013-06-14 03:39:53 +03:00
}
else {
$('body').removeClass('backdrop');
}
this._showSeasons();
this._setMonitoredState();
this._showInfo();
},
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;
},
onClose: function () {
2013-08-21 22:07:28 +03:00
if (this._backstrech) {
this._backstrech.destroy();
delete this._backstrech;
}
$('body').removeClass('backdrop');
App.reqres.removeHandler(App.Reqres.GetEpisodeFileById);
},
_toggleMonitored: function () {
var name = 'monitored';
this.model.set(name, !this.model.get(name), { silent: true });
Actioneer.SaveModel({
2013-08-08 10:38:14 +03:00
context: this,
element: this.ui.monitored,
always : this._setMonitoredState()
});
},
_setMonitoredState: function () {
var monitored = this.model.get('monitored');
this.ui.monitored.removeClass('icon-spin icon-spinner');
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});
},
_refreshSeries: function () {
Actioneer.ExecuteCommand({
2013-07-24 04:15:58 +03:00
command : 'refreshSeries',
properties: {
seriesId: this.model.get('id')
},
2013-07-24 04:15:58 +03:00
element : this.ui.refresh,
leaveIcon : true,
2013-08-21 22:07:28 +03:00
context : this,
onSuccess : this._showSeasons
});
},
_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 () {
Actioneer.ExecuteCommand({
command : 'renameSeries',
properties : {
2013-07-24 04:15:58 +03:00
seriesId: this.model.get('id')
},
element : this.ui.rename,
context : this,
onSuccess : this._refetchEpisodeFiles,
errorMessage: '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,
errorMessage: 'Series search failed',
2013-07-22 05:52:53 +03:00
startMessage: 'Search for {0} started'.format(this.model.get('title'))
});
},
_showSeasons: function () {
var self = this;
this.seasons.show(new LoadingView());
this.seasonCollection = new SeasonCollection();
this.episodeCollection = new EpisodeCollection({ seriesId: this.model.id });
this.episodeFileCollection = new EpisodeFileCollection({ seriesId: this.model.id });
$.when(this.episodeCollection.fetch(), this.episodeFileCollection.fetch(), this.seasonCollection.fetch({data: { seriesId: this.model.id }})).done(function () {
var seasonCollectionView = new SeasonCollectionView({
collection : self.seasonCollection,
episodeCollection: self.episodeCollection,
series : self.model
});
App.reqres.setHandler(App.Reqres.GetEpisodeFileById, function(episodeFileId){
return self.episodeFileCollection.get(episodeFileId);
});
2013-08-21 22:07:28 +03:00
/* self.episodeCollection.bindSignalR({
onReceived: seasonCollectionView.onEpisodeGrabbed,
context : seasonCollectionView
2013-08-21 22:07:28 +03:00
});*/
self.seasons.show(seasonCollectionView);
});
},
_showInfo: function () {
this.info.show(new InfoView({ model: this.model }));
},
_refetchEpisodeFiles: function () {
this.episodeFileCollection.fetch();
},
_onSeasonRenamed: function(event) {
if (this.model.get('id') === event.series.get('id')) {
this._refetchEpisodeFiles();
}
}
});
});