2013-08-05 09:09:41 +00:00
|
|
|
|
'use strict';
|
|
|
|
|
define(
|
|
|
|
|
[
|
|
|
|
|
'marionette',
|
|
|
|
|
'Series/SeasonCollection',
|
2013-09-11 06:33:47 +00:00
|
|
|
|
'Cells/ToggleCell'
|
|
|
|
|
], function (Marionette, Backgrid, SeasonCollection, ToggleCell) {
|
2013-08-05 09:09:41 +00:00
|
|
|
|
return Marionette.Layout.extend({
|
|
|
|
|
template: 'SeasonPass/SeriesLayoutTemplate',
|
|
|
|
|
|
|
|
|
|
ui: {
|
|
|
|
|
seasonSelect: '.x-season-select',
|
|
|
|
|
expander : '.x-expander',
|
|
|
|
|
seasonGrid : '.x-season-grid'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
events: {
|
|
|
|
|
'change .x-season-select': '_seasonSelected',
|
2013-08-06 06:17:46 +00:00
|
|
|
|
'click .x-expander' : '_expand',
|
2013-09-10 05:22:38 +00:00
|
|
|
|
'click .x-latest' : '_latest',
|
|
|
|
|
'click .x-monitored' : '_toggleSeasonMonitored'
|
2013-08-05 09:09:41 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
regions: {
|
|
|
|
|
seasonGrid: '.x-season-grid'
|
|
|
|
|
},
|
|
|
|
|
|
2013-09-10 05:22:38 +00:00
|
|
|
|
initialize: function () {
|
|
|
|
|
this.seasonCollection = new SeasonCollection(this.model.get('seasons'));
|
2013-08-05 09:09:41 +00:00
|
|
|
|
this.expanded = false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onRender: function () {
|
|
|
|
|
if (!this.expanded) {
|
2013-09-10 05:22:38 +00:00
|
|
|
|
this.ui.seasonGrid.hide();
|
2013-08-05 09:09:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._setExpanderIcon();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_seasonSelected: function () {
|
|
|
|
|
var seasonNumber = parseInt(this.ui.seasonSelect.val());
|
|
|
|
|
|
2013-08-06 06:17:46 +00:00
|
|
|
|
if (seasonNumber == -1 || isNaN(seasonNumber)) {
|
2013-08-05 09:09:41 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-06 06:17:46 +00:00
|
|
|
|
this._setMonitored(seasonNumber)
|
2013-08-05 09:09:41 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_expand: function () {
|
|
|
|
|
if (this.expanded) {
|
|
|
|
|
this.ui.seasonGrid.slideUp();
|
|
|
|
|
this.expanded = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
this.ui.seasonGrid.slideDown();
|
|
|
|
|
this.expanded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._setExpanderIcon();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_setExpanderIcon: function () {
|
|
|
|
|
if (this.expanded) {
|
|
|
|
|
this.ui.expander.removeClass('icon-chevron-right');
|
|
|
|
|
this.ui.expander.addClass('icon-chevron-down');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
this.ui.expander.removeClass('icon-chevron-down');
|
|
|
|
|
this.ui.expander.addClass('icon-chevron-right');
|
|
|
|
|
}
|
2013-08-06 06:17:46 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_latest: function () {
|
2013-09-10 05:22:38 +00:00
|
|
|
|
var season = _.max(this.model.get('seasons'), function (s) {
|
|
|
|
|
return s.seasonNumber;
|
2013-08-06 06:17:46 +00:00
|
|
|
|
});
|
|
|
|
|
|
2013-09-10 05:22:38 +00:00
|
|
|
|
this._setMonitored(season.seasonNumber);
|
2013-08-06 06:17:46 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_setMonitored: function (seasonNumber) {
|
|
|
|
|
var self = this;
|
|
|
|
|
|
2013-09-10 05:22:38 +00:00
|
|
|
|
this.model.setSeasonPass(seasonNumber);
|
|
|
|
|
|
|
|
|
|
var promise = this.model.save();
|
2013-08-06 06:17:46 +00:00
|
|
|
|
|
|
|
|
|
promise.done(function (data) {
|
|
|
|
|
self.seasonCollection = new SeasonCollection(data);
|
|
|
|
|
self.render();
|
|
|
|
|
});
|
2013-09-10 05:22:38 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_toggleSeasonMonitored: function (e) {
|
|
|
|
|
var seasonNumber = 0;
|
|
|
|
|
var element;
|
|
|
|
|
|
|
|
|
|
if (e.target.localName === 'i') {
|
|
|
|
|
seasonNumber = parseInt($(e.target).parent('td').attr('data-season-number'));
|
|
|
|
|
element = $(e.target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
seasonNumber = parseInt($(e.target).attr('data-season-number'));
|
|
|
|
|
element = $(e.target).children('i');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.model.setSeasonMonitored(seasonNumber);
|
|
|
|
|
|
|
|
|
|
Actioneer.SaveModel({
|
|
|
|
|
element: element,
|
|
|
|
|
context: this,
|
|
|
|
|
always : this._afterToggleSeasonMonitored
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_afterToggleSeasonMonitored: function () {
|
|
|
|
|
this.render();
|
2013-08-05 09:09:41 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|