1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/UI/SeasonPass/SeriesLayout.js

126 lines
3.7 KiB
JavaScript
Raw Normal View History

'use strict';
define(
[
'marionette',
'Series/SeasonCollection',
'Shared/Actioneer'
2013-09-10 08:22:38 +03:00
], function (Marionette, SeasonCollection, Actioneer) {
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 09:17:46 +03:00
'click .x-expander' : '_expand',
2013-09-10 08:22:38 +03:00
'click .x-latest' : '_latest',
'click .x-monitored' : '_toggleSeasonMonitored'
},
regions: {
seasonGrid: '.x-season-grid'
},
2013-09-10 08:22:38 +03:00
initialize: function () {
this.seasonCollection = new SeasonCollection(this.model.get('seasons'));
this.expanded = false;
},
onRender: function () {
if (!this.expanded) {
2013-09-10 08:22:38 +03:00
this.ui.seasonGrid.hide();
}
this._setExpanderIcon();
},
_seasonSelected: function () {
var seasonNumber = parseInt(this.ui.seasonSelect.val());
2013-08-06 09:17:46 +03:00
if (seasonNumber == -1 || isNaN(seasonNumber)) {
return;
}
2013-08-06 09:17:46 +03:00
this._setMonitored(seasonNumber)
},
_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 09:17:46 +03:00
},
_latest: function () {
2013-09-10 08:22:38 +03:00
var season = _.max(this.model.get('seasons'), function (s) {
return s.seasonNumber;
2013-08-06 09:17:46 +03:00
});
2013-09-10 08:22:38 +03:00
this._setMonitored(season.seasonNumber);
2013-08-06 09:17:46 +03:00
},
_setMonitored: function (seasonNumber) {
var self = this;
2013-09-10 08:22:38 +03:00
this.model.setSeasonPass(seasonNumber);
var promise = this.model.save();
2013-08-06 09:17:46 +03:00
promise.done(function (data) {
self.seasonCollection = new SeasonCollection(data);
self.render();
});
2013-09-10 08:22:38 +03: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();
}
});
});