2013-06-25 04:43:16 +00:00
|
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
|
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({
|
2013-06-09 20:51:32 +00:00
|
|
|
|
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
|
|
|
|
},
|
|
|
|
|
|
2013-06-09 20:51:32 +00:00
|
|
|
|
regions: {
|
|
|
|
|
episodeGrid: '#x-episode-grid'
|
|
|
|
|
},
|
2013-04-23 02:07:21 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
columns:
|
|
|
|
|
[
|
|
|
|
|
{
|
2013-07-09 15:41:42 +00:00
|
|
|
|
name : 'monitored',
|
2013-06-24 23:41:59 +00:00
|
|
|
|
label : '',
|
|
|
|
|
cell : ToggleCell,
|
2013-07-09 15:41:42 +00:00
|
|
|
|
trueClass : 'icon-bookmark',
|
|
|
|
|
falseClass: 'icon-bookmark-empty',
|
2013-07-21 23:46:45 +00:00
|
|
|
|
tooltip : 'Toggle monitored status',
|
|
|
|
|
sortable : false
|
2013-06-24 23:41:59 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name : 'episodeNumber',
|
|
|
|
|
label: '#',
|
|
|
|
|
cell : Backgrid.IntegerCell.extend({
|
|
|
|
|
className: 'episode-number-cell'
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
{
|
2013-07-21 23:46:45 +00:00
|
|
|
|
name : 'this',
|
|
|
|
|
label : 'Title',
|
|
|
|
|
cell : EpisodeTitleCell,
|
|
|
|
|
sortable: false
|
2013-06-24 23:41:59 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name : 'airDate',
|
|
|
|
|
label: 'Air Date',
|
|
|
|
|
cell : AirDateCell
|
|
|
|
|
} ,
|
|
|
|
|
{
|
2013-07-21 23:46:45 +00:00
|
|
|
|
name : 'status',
|
|
|
|
|
label : 'Status',
|
|
|
|
|
cell : EpisodeStatusCell,
|
|
|
|
|
sortable: false
|
2013-06-24 23:41:59 +00:00
|
|
|
|
}
|
|
|
|
|
],
|
2013-04-23 02:07:21 +00:00
|
|
|
|
|
2013-06-09 20:51:32 +00:00
|
|
|
|
initialize: function (options) {
|
2013-06-01 19:31:39 +00:00
|
|
|
|
|
2013-06-09 20:51:32 +00:00
|
|
|
|
if (!options.episodeCollection) {
|
|
|
|
|
throw 'episodeCollection is needed';
|
|
|
|
|
}
|
2013-06-01 19:31:39 +00:00
|
|
|
|
|
2013-06-09 20:51:32 +00:00
|
|
|
|
this.episodeCollection = options.episodeCollection.bySeason(this.model.get('seasonNumber'));
|
2013-06-28 22:12:57 +00:00
|
|
|
|
|
|
|
|
|
_.each(this.episodeCollection.models, function (episode) {
|
2013-06-29 00:35:21 +00:00
|
|
|
|
episode.set({ hideSeriesLink: true, series: options.series });
|
2013-06-28 22:12:57 +00:00
|
|
|
|
});
|
2013-07-19 01:49:04 +00:00
|
|
|
|
|
|
|
|
|
this.episodeCollection.on('sync', function () {
|
|
|
|
|
this.render();
|
|
|
|
|
}, this);
|
2013-06-09 20:51:32 +00:00
|
|
|
|
},
|
2013-04-23 02:07:21 +00:00
|
|
|
|
|
2013-07-10 02:11:00 +00:00
|
|
|
|
onRender: function () {
|
2013-06-24 23:41:59 +00:00
|
|
|
|
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 () {
|
|
|
|
|
var command = 'seasonSearch';
|
|
|
|
|
|
|
|
|
|
this.idle = false;
|
|
|
|
|
|
|
|
|
|
this.ui.seasonSearch.addClass('icon-spinner icon-spin');
|
|
|
|
|
|
|
|
|
|
var properties = {
|
2013-06-24 23:41:59 +00:00
|
|
|
|
seriesId : this.model.get('seriesId'),
|
2013-06-24 04:37:55 +00:00
|
|
|
|
seasonNumber: this.model.get('seasonNumber')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var self = this;
|
2013-06-24 23:41:59 +00:00
|
|
|
|
var commandPromise = CommandController.Execute(command, properties);
|
2013-06-24 04:37:55 +00: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 02:11:00 +00: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) {
|
2013-07-19 06:54:38 +00:00
|
|
|
|
episode.set({ monitored: self.model.get('monitored') });
|
2013-07-10 02:11:00 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.render();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_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 () {
|
|
|
|
|
var command = 'renameSeason';
|
|
|
|
|
|
|
|
|
|
this.idle = false;
|
|
|
|
|
|
|
|
|
|
this.ui.seasonRename.toggleClass('icon-nd-rename icon-nd-spinner');
|
|
|
|
|
|
|
|
|
|
var properties = {
|
|
|
|
|
seriesId : this.model.get('seriesId'),
|
|
|
|
|
seasonNumber: this.model.get('seasonNumber')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
var commandPromise = CommandController.Execute(command, properties);
|
|
|
|
|
|
|
|
|
|
commandPromise.fail(function (options) {
|
|
|
|
|
if (options.readyState === 0 || options.status === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Messenger.show({
|
|
|
|
|
message: 'Season rename failed',
|
|
|
|
|
type : 'error'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
commandPromise.always(function () {
|
|
|
|
|
if (!self.isClosed) {
|
|
|
|
|
self.ui.seasonRename.toggleClass('icon-nd-rename icon-nd-spinner');
|
|
|
|
|
self.idle = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-06-09 20:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2013-04-23 02:07:21 +00:00
|
|
|
|
});
|