Added seasons to top of series details (toggling and jump to)

This commit is contained in:
Mark McDowall 2013-07-31 23:32:36 -07:00
commit 125deb3931
9 changed files with 176 additions and 5 deletions

View file

@ -0,0 +1,31 @@
'use strict';
define(
[
'marionette',
'Series/Details/SeasonMenu/ItemView'
], function (Marionette, ItemView) {
return Marionette.CollectionView.extend({
itemView: ItemView,
initialize: function (options) {
if (!options.episodeCollection) {
throw 'episodeCollection is needed';
}
this.episodeCollection = options.episodeCollection;
},
itemViewOptions: function () {
return {
episodeCollection: this.episodeCollection,
};
},
appendHtml: function(collectionView, itemView, index){
var childrenContainer = $(collectionView.childrenContainer || collectionView.el);
childrenContainer.prepend(itemView.el);
}
});
});

View file

@ -0,0 +1,88 @@
'use strict';
define(
[
'marionette',
'Shared/Actioneer'
], function (Marionette, Actioneer) {
return Marionette.ItemView.extend({
template: 'Series/Details/SeasonMenu/ItemViewTemplate',
tagName : 'span',
ui: {
seasonMonitored: '.x-season-monitored'
},
events: {
'click .x-season-monitored': '_seasonMonitored',
'click .x-text': '_gotoSeason'
},
initialize: function (options) {
if (!options.episodeCollection) {
throw 'episodeCollection is needed';
}
this.episodeCollection = options.episodeCollection.bySeason(this.model.get('seasonNumber'));
var allDownloaded = _.all(this.episodeCollection.models, function (model) {
var hasFile = model.get('hasFile');
return hasFile;
});
this.model.set({
allFilesDownloaded: allDownloaded
});
this.model.on('sync', function () {
this.render();
}, this);
},
onRender: function () {
this._setSeasonMonitoredState();
},
_seasonSearch: function () {
Actioneer.ExecuteCommand({
command : 'seasonSearch',
properties : {
seriesId : this.model.get('seriesId'),
seasonNumber: this.model.get('seasonNumber')
},
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'))
});
},
_seasonMonitored: function (e) {
e.preventDefault();
var name = 'monitored';
this.model.set(name, !this.model.get(name));
Actioneer.SaveModel({
context : this,
element : this.ui.seasonMonitored
});
},
_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');
}
},
_gotoSeason: function () {
window.location.hash = '#season-' + this.model.get('seasonNumber');
}
});
});

View file

@ -0,0 +1,14 @@
{{#if allFilesDownloaded}}
<span class="label label-info season-menu-item">
{{else}}
<span class="label label-white season-menu-item">
{{/if}}
<i class="x-season-monitored clickable" title="Toggle season monitored status"/>
<span class="x-text text" title="Go to season">
{{#if_eq seasonNumber compare=0}}
Specials
{{else}}
S{{Pad2 seasonNumber}}
{{/if_eq}}
</span>
</span>