UI Cleanup - Updated Rename and SeasonPass subtrees.

This commit is contained in:
Taloth Saldono
2015-02-13 22:52:55 +01:00
parent 860f55996c
commit 1bf433872a
11 changed files with 233 additions and 145 deletions

View File

@@ -7,59 +7,75 @@ var ToolbarLayout = require('../Shared/Toolbar/ToolbarLayout');
require('../Mixins/backbone.signalr.mixin');
module.exports = Marionette.Layout.extend({
template : 'SeasonPass/SeasonPassLayoutTemplate',
regions : {
template : 'SeasonPass/SeasonPassLayoutTemplate',
regions : {
toolbar : '#x-toolbar',
series : '#x-series'
},
initialize : function(){
initialize : function() {
this.seriesCollection = SeriesCollection.clone();
this.seriesCollection.shadowCollection.bindSignalR();
this.listenTo(this.seriesCollection, 'sync', this.render);
this.filteringOptions = {
type : 'radio',
storeState : true,
menuKey : 'seasonpass.filterMode',
defaultAction : 'all',
items : [{
key : 'all',
title : '',
tooltip : 'All',
icon : 'icon-circle-blank',
callback : this._setFilter
}, {
key : 'monitored',
title : '',
tooltip : 'Monitored Only',
icon : 'icon-nd-monitored',
callback : this._setFilter
}, {
key : 'continuing',
title : '',
tooltip : 'Continuing Only',
icon : 'icon-play',
callback : this._setFilter
}, {
key : 'ended',
title : '',
tooltip : 'Ended Only',
icon : 'icon-stop',
callback : this._setFilter
}]
items : [
{
key : 'all',
title : '',
tooltip : 'All',
icon : 'icon-circle-blank',
callback : this._setFilter
},
{
key : 'monitored',
title : '',
tooltip : 'Monitored Only',
icon : 'icon-nd-monitored',
callback : this._setFilter
},
{
key : 'continuing',
title : '',
tooltip : 'Continuing Only',
icon : 'icon-play',
callback : this._setFilter
},
{
key : 'ended',
title : '',
tooltip : 'Ended Only',
icon : 'icon-stop',
callback : this._setFilter
}
]
};
},
onRender : function(){
this.series.show(new SeriesCollectionView({collection : this.seriesCollection}));
onRender : function() {
this.series.show(new SeriesCollectionView({
collection : this.seriesCollection
}));
this._showToolbar();
},
_showToolbar : function(){
_showToolbar : function() {
this.toolbar.show(new ToolbarLayout({
right : [this.filteringOptions],
context : this
}));
},
_setFilter : function(buttonContext){
_setFilter : function(buttonContext) {
var mode = buttonContext.model.get('key');
this.seriesCollection.setFilterMode(mode);
}
});

View File

@@ -1,4 +1,6 @@
var Marionette = require('marionette');
var SeriesLayout = require('./SeriesLayout');
module.exports = Marionette.CollectionView.extend({itemView : SeriesLayout});
module.exports = Marionette.CollectionView.extend({
itemView : SeriesLayout
});

View File

@@ -4,113 +4,149 @@ var Backgrid = require('backgrid');
var SeasonCollection = require('../Series/SeasonCollection');
module.exports = Marionette.Layout.extend({
template : 'SeasonPass/SeriesLayoutTemplate',
ui : {
template : 'SeasonPass/SeriesLayoutTemplate',
ui : {
seasonSelect : '.x-season-select',
expander : '.x-expander',
seasonGrid : '.x-season-grid',
seriesMonitored : '.x-series-monitored'
},
events : {
"change .x-season-select" : '_seasonSelected',
"click .x-expander" : '_expand',
"click .x-latest" : '_latest',
"click .x-all" : '_all',
"click .x-monitored" : '_toggleSeasonMonitored',
"click .x-series-monitored" : '_toggleSeriesMonitored'
events : {
'change .x-season-select' : '_seasonSelected',
'click .x-expander' : '_expand',
'click .x-latest' : '_latest',
'click .x-all' : '_all',
'click .x-monitored' : '_toggleSeasonMonitored',
'click .x-series-monitored' : '_toggleSeriesMonitored'
},
regions : {seasonGrid : '.x-season-grid'},
initialize : function(){
regions : {
seasonGrid : '.x-season-grid'
},
initialize : function() {
this.listenTo(this.model, 'sync', this._setSeriesMonitoredState);
this.seasonCollection = new SeasonCollection(this.model.get('seasons'));
this.expanded = false;
},
onRender : function(){
if(!this.expanded) {
onRender : function() {
if (!this.expanded) {
this.ui.seasonGrid.hide();
}
this._setExpanderIcon();
this._setSeriesMonitoredState();
},
_seasonSelected : function(){
_seasonSelected : function() {
var seasonNumber = parseInt(this.ui.seasonSelect.val(), 10);
if(seasonNumber === -1 || isNaN(seasonNumber)) {
if (seasonNumber === -1 || isNaN(seasonNumber)) {
return;
}
this._setSeasonMonitored(seasonNumber);
},
_expand : function(){
if(this.expanded) {
_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) {
_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');
}
},
_latest : function(){
var season = _.max(this.model.get('seasons'), function(s){
_latest : function() {
var season = _.max(this.model.get('seasons'), function(s) {
return s.seasonNumber;
});
this._setSeasonMonitored(season.seasonNumber);
},
_all : function(){
var minSeasonNotZero = _.min(_.reject(this.model.get('seasons'), {seasonNumber : 0}), 'seasonNumber');
_all : function() {
var minSeasonNotZero = _.min(_.reject(this.model.get('seasons'), { seasonNumber : 0 }), 'seasonNumber');
this._setSeasonMonitored(minSeasonNotZero.seasonNumber);
},
_setSeasonMonitored : function(seasonNumber){
_setSeasonMonitored : function(seasonNumber) {
var self = this;
this.model.setSeasonPass(seasonNumber);
var promise = this.model.save();
promise.done(function(data){
promise.done(function(data) {
self.seasonCollection = new SeasonCollection(data);
self.render();
});
},
_toggleSeasonMonitored : function(e){
_toggleSeasonMonitored : function(e) {
var seasonNumber = 0;
var element;
if(e.target.localName === 'i') {
if (e.target.localName === 'i') {
seasonNumber = parseInt(this.$(e.target).parent('td').attr('data-season-number'), 10);
element = this.$(e.target);
}
else {
seasonNumber = parseInt(this.$(e.target).attr('data-season-number'), 10);
element = this.$(e.target).children('i');
}
this.model.setSeasonMonitored(seasonNumber);
var savePromise = this.model.save().always(this.render.bind(this));
element.spinForPromise(savePromise);
},
_afterToggleSeasonMonitored : function(){
_afterToggleSeasonMonitored : function() {
this.render();
},
_setSeriesMonitoredState : function(){
_setSeriesMonitoredState : function() {
var monitored = this.model.get('monitored');
this.ui.seriesMonitored.removeAttr('data-idle-icon');
if(monitored) {
if (monitored) {
this.ui.seriesMonitored.addClass('icon-nd-monitored');
this.ui.seriesMonitored.removeClass('icon-nd-unmonitored');
}
else {
} else {
this.ui.seriesMonitored.addClass('icon-nd-unmonitored');
this.ui.seriesMonitored.removeClass('icon-nd-monitored');
}
},
_toggleSeriesMonitored : function(){
var savePromise = this.model.save('monitored', !this.model.get('monitored'), {wait : true});
_toggleSeriesMonitored : function() {
var savePromise = this.model.save('monitored', !this.model.get('monitored'), {
wait : true
});
this.ui.seriesMonitored.spinForPromise(savePromise);
}
});
});