sonarr-repo-only/UI/Series/Details/SeasonLayout.js

157 lines
5.6 KiB
JavaScript
Raw Normal View History

2013-06-25 04:43:16 +00:00
'use strict';
define(
[
'marionette',
'backgrid',
'Cells/ToggleCell',
'Cells/EpisodeTitleCell',
'Cells/RelativeDateCell',
'Cells/EpisodeStatusCell',
'Commands/CommandController',
'Shared/Actioneer'
], function ( Marionette, Backgrid, ToggleCell, EpisodeTitleCell, RelativeDateCell, EpisodeStatusCell, CommandController, Actioneer) {
return Marionette.Layout.extend({
template: 'Series/Details/SeasonLayoutTemplate',
2013-04-23 02:07:21 +00:00
2013-06-24 04:37:55 +00:00
ui: {
2013-07-10 02:11:00 +00:00
seasonSearch : '.x-season-search',
2013-07-19 05:23:04 +00:00
seasonMonitored: '.x-season-monitored',
seasonRename : '.x-season-rename'
2013-06-24 04:37:55 +00:00
},
events: {
2013-07-10 02:11:00 +00:00
'click .x-season-search' : '_seasonSearch',
2013-07-19 05:23:04 +00:00
'click .x-season-monitored': '_seasonMonitored',
'click .x-season-rename' : '_seasonRename'
2013-06-24 04:37:55 +00:00
},
regions: {
episodeGrid: '#x-episode-grid'
},
2013-04-23 02:07:21 +00:00
columns:
[
{
name : 'monitored',
label : '',
cell : ToggleCell,
trueClass : 'icon-bookmark',
falseClass: 'icon-bookmark-empty',
2013-07-21 23:46:45 +00:00
tooltip : 'Toggle monitored status',
sortable : false
},
{
name : 'episodeNumber',
label: '#',
cell : Backgrid.IntegerCell.extend({
className: 'episode-number-cell'
})
},
{
2013-07-21 23:46:45 +00:00
name : 'this',
label : 'Title',
2013-08-21 21:47:39 +00:00
hideSeriesLink : true,
2013-07-21 23:46:45 +00:00
cell : EpisodeTitleCell,
sortable: false
},
{
2013-07-24 05:28:06 +00:00
name : 'airDateUtc',
label: 'Air Date',
cell : RelativeDateCell
} ,
{
2013-07-21 23:46:45 +00:00
name : 'status',
label : 'Status',
cell : EpisodeStatusCell,
sortable: false
}
],
2013-04-23 02:07:21 +00:00
initialize: function (options) {
if (!options.episodeCollection) {
throw 'episodeCollection is needed';
}
this.episodeCollection = options.episodeCollection.bySeason(this.model.get('seasonNumber'));
2013-08-19 15:12:35 +00:00
this.listenTo(this.model, 'sync', function () {
this._afterSeasonMonitored();
}, this);
2013-08-19 15:12:35 +00:00
this.listenTo(this.episodeCollection, 'sync', function () {
this.render();
}, this);
},
2013-04-23 02:07:21 +00:00
2013-07-10 02:11:00 +00:00
onRender: function () {
this.episodeGrid.show(new Backgrid.Grid({
columns : this.columns,
collection: this.episodeCollection,
className : 'table table-hover season-grid'
}));
2013-07-10 02:11:00 +00:00
this._setSeasonMonitoredState();
2013-06-24 04:37:55 +00:00
},
_seasonSearch: function () {
Actioneer.ExecuteCommand({
2013-07-22 02:52:53 +00:00
command : 'seasonSearch',
properties : {
seriesId : this.model.get('seriesId'),
seasonNumber: this.model.get('seasonNumber')
},
2013-07-22 02:52:53 +00:00
element : this.ui.seasonSearch,
failMessage : 'Search for season {0} failed'.format(this.model.get('seasonNumber')),
startMessage: 'Search for season {0} started'.format(this.model.get('seasonNumber'))
2013-06-24 04:37:55 +00:00
});
2013-07-10 02:11:00 +00:00
},
_seasonMonitored: function () {
var name = 'monitored';
this.model.set(name, !this.model.get(name));
Actioneer.SaveModel({
2013-08-08 07:38:14 +00:00
context: this,
element: this.ui.seasonMonitored,
always : this._afterSeasonMonitored
});
},
2013-07-10 02:11:00 +00:00
_afterSeasonMonitored: function () {
var self = this;
2013-07-10 02:11:00 +00:00
_.each(this.episodeCollection.models, function (episode) {
episode.set({ monitored: self.model.get('monitored') });
2013-07-10 02:11:00 +00:00
});
this.render();
2013-07-10 02:11:00 +00:00
},
_setSeasonMonitoredState: function () {
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-07-19 05:23:04 +00:00
},
_seasonRename: function () {
Actioneer.ExecuteCommand({
command : 'renameSeason',
properties : {
seriesId : this.model.get('seriesId'),
seasonNumber: this.model.get('seasonNumber')
},
element : this.ui.seasonRename,
failMessage: 'Season rename failed'
2013-07-19 05:23:04 +00:00
});
}
});
2013-04-23 02:07:21 +00:00
});