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