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
+48 -30
View File
@@ -9,66 +9,79 @@ var LoadingView = require('../Shared/LoadingView');
var CommandController = require('../Commands/CommandController');
module.exports = Marionette.Layout.extend({
className : 'modal-lg',
template : 'Rename/RenamePreviewLayoutTemplate',
regions : {
className : 'modal-lg',
template : 'Rename/RenamePreviewLayoutTemplate',
regions : {
renamePreviews : '#rename-previews',
formatRegion : '.x-format-region'
},
ui : {
ui : {
pathInfo : '.x-path-info',
renameAll : '.x-rename-all',
checkboxIcon : '.x-rename-all-button i'
},
events : {
"click .x-organize" : '_organizeFiles',
"change .x-rename-all" : '_toggleAll'
events : {
'click .x-organize' : '_organizeFiles',
'change .x-rename-all' : '_toggleAll'
},
initialize : function(options){
initialize : function(options) {
this.model = options.series;
this.seasonNumber = options.seasonNumber;
var viewOptions = {};
viewOptions.seriesId = this.model.id;
viewOptions.seasonNumber = this.seasonNumber;
this.collection = new RenamePreviewCollection(viewOptions);
this.listenTo(this.collection, 'sync', this._showPreviews);
this.listenTo(this.collection, 'rename:select', this._itemRenameChanged);
this.collection.fetch();
},
onRender : function(){
onRender : function() {
this.renamePreviews.show(new LoadingView());
this.formatRegion.show(new RenamePreviewFormatView({model : this.model}));
this.formatRegion.show(new RenamePreviewFormatView({ model : this.model }));
},
_showPreviews : function(){
if(this.collection.length === 0) {
_showPreviews : function() {
if (this.collection.length === 0) {
this.ui.pathInfo.hide();
this.renamePreviews.show(new EmptyCollectionView());
return;
}
this.ui.pathInfo.show();
this.collection.invoke('set', {rename : true});
this.renamePreviews.show(new RenamePreviewCollectionView({collection : this.collection}));
this.collection.invoke('set', { rename : true });
this.renamePreviews.show(new RenamePreviewCollectionView({ collection : this.collection }));
},
_organizeFiles : function(){
if(this.collection.length === 0) {
_organizeFiles : function() {
if (this.collection.length === 0) {
vent.trigger(vent.Commands.CloseModalCommand);
}
var files = _.map(this.collection.where({rename : true}), function(model){
var files = _.map(this.collection.where({ rename : true }), function(model) {
return model.get('episodeFileId');
});
if(files.length === 0) {
if (files.length === 0) {
vent.trigger(vent.Commands.CloseModalCommand);
return;
}
if(this.seasonNumber) {
if (this.seasonNumber) {
CommandController.Execute('renameFiles', {
name : 'renameFiles',
seriesId : this.model.id,
seasonNumber : this.seasonNumber,
files : files
});
}
else {
} else {
CommandController.Execute('renameFiles', {
name : 'renameFiles',
seriesId : this.model.id,
@@ -76,30 +89,35 @@ module.exports = Marionette.Layout.extend({
files : files
});
}
vent.trigger(vent.Commands.CloseModalCommand);
},
_setCheckedState : function(checked){
if(checked) {
_setCheckedState : function(checked) {
if (checked) {
this.ui.checkboxIcon.addClass('icon-check');
this.ui.checkboxIcon.removeClass('icon-check-empty');
}
else {
} else {
this.ui.checkboxIcon.addClass('icon-check-empty');
this.ui.checkboxIcon.removeClass('icon-check');
}
},
_toggleAll : function(){
_toggleAll : function() {
var checked = this.ui.renameAll.prop('checked');
this._setCheckedState(checked);
this.collection.each(function(model){
this.collection.each(function(model) {
model.trigger('rename:select', model, checked);
});
},
_itemRenameChanged : function(model, checked){
var allChecked = this.collection.all(function(m){
_itemRenameChanged : function(model, checked) {
var allChecked = this.collection.all(function(m) {
return m.get('rename');
});
if(!checked || allChecked) {
if (!checked || allChecked) {
this._setCheckedState(checked);
}
}