1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-29 02:57:15 +02:00
Sonarr/UI/Series/Details/SeasonLayout.js

155 lines
5.2 KiB
JavaScript
Raw Normal View History

2013-06-25 07:43:16 +03:00
'use strict';
define(
[
'marionette',
'backgrid',
'Cells/ToggleCell',
'Cells/EpisodeTitleCell',
'Cells/AirDateCell',
'Cells/EpisodeStatusCell',
'Commands/CommandController',
'Shared/Messenger'
], function ( Marionette, Backgrid, ToggleCell, EpisodeTitleCell, AirDateCell, EpisodeStatusCell, CommandController, Messenger) {
return Marionette.Layout.extend({
template: 'Series/Details/SeasonLayoutTemplate',
2013-04-23 05:07:21 +03:00
2013-06-24 07:37:55 +03:00
ui: {
2013-07-10 05:11:00 +03:00
seasonSearch : '.x-season-search',
seasonMonitored: '.x-season-monitored'
2013-06-24 07:37:55 +03:00
},
events: {
2013-07-10 05:11:00 +03:00
'click .x-season-search' : '_seasonSearch',
'click .x-season-monitored': '_seasonMonitored'
2013-06-24 07:37:55 +03:00
},
regions: {
episodeGrid: '#x-episode-grid'
},
2013-04-23 05:07:21 +03:00
columns:
[
{
name : 'monitored',
label : '',
cell : ToggleCell,
trueClass : 'icon-bookmark',
falseClass: 'icon-bookmark-empty',
tooltip : 'Toggle monitored status'
},
{
name : 'episodeNumber',
label: '#',
cell : Backgrid.IntegerCell.extend({
className: 'episode-number-cell'
})
},
{
name : 'this',
label: 'Title',
cell : EpisodeTitleCell
},
{
name : 'airDate',
label: 'Air Date',
cell : AirDateCell
} ,
{
name : 'status',
label: 'Status',
cell : EpisodeStatusCell
}
],
2013-04-23 05:07:21 +03:00
initialize: function (options) {
if (!options.episodeCollection) {
throw 'episodeCollection is needed';
}
this.episodeCollection = options.episodeCollection.bySeason(this.model.get('seasonNumber'));
_.each(this.episodeCollection.models, function (episode) {
episode.set({ hideSeriesLink: true, series: options.series });
});
},
2013-04-23 05:07:21 +03:00
2013-07-10 05:11:00 +03:00
onRender: function () {
this.episodeGrid.show(new Backgrid.Grid({
columns : this.columns,
collection: this.episodeCollection,
className : 'table table-hover season-grid'
}));
2013-07-10 05:11:00 +03:00
this._setSeasonMonitoredState();
2013-06-24 07:37:55 +03:00
},
_seasonSearch: function () {
var command = 'seasonSearch';
this.idle = false;
this.ui.seasonSearch.addClass('icon-spinner icon-spin');
var properties = {
seriesId : this.model.get('seriesId'),
2013-06-24 07:37:55 +03:00
seasonNumber: this.model.get('seasonNumber')
};
var self = this;
var commandPromise = CommandController.Execute(command, properties);
2013-06-24 07:37:55 +03:00
commandPromise.fail(function (options) {
if (options.readyState === 0 || options.status === 0) {
return;
}
Messenger.show({
message: 'Season search failed',
type : 'error'
});
});
commandPromise.always(function () {
if (!self.isClosed) {
self.ui.seasonSearch.removeClass('icon-spinner icon-spin');
self.idle = true;
}
});
2013-07-10 05:11:00 +03:00
},
_seasonMonitored: function () {
var self = this;
var name = 'monitored';
this.model.set(name, !this.model.get(name));
this.ui.seasonMonitored.addClass('icon-spinner icon-spin');
var promise = this.model.save();
promise.always(function (){
_.each(self.episodeCollection.models, function (episode) {
episode.set({ monitored: !episode.get('monitored') });
});
self.render();
});
},
_setSeasonMonitoredState: function () {
var monitored = this.model.get('monitored');
this.ui.seasonMonitored.removeClass('icon-spinner icon-spin');
if (this.model.get('monitored')) {
this.ui.seasonMonitored.addClass('icon-bookmark');
this.ui.seasonMonitored.removeClass('icon-bookmark-empty');
}
else {
this.ui.seasonMonitored.addClass('icon-bookmark-empty');
this.ui.seasonMonitored.removeClass('icon-bookmark');
}
}
});
2013-04-23 05:07:21 +03:00
});