UI Cleanup - Updated Shared and Shims subtrees.

This commit is contained in:
Taloth Saldono 2015-02-14 11:17:53 +01:00
parent 019525dd9d
commit d6079a701c
39 changed files with 686 additions and 448 deletions

View file

@ -1,4 +1,4 @@
var _ = require('underscore');
var _ = require('underscore');
var vent = require('vent');
var Marionette = require('marionette');
var Backgrid = require('backgrid');
@ -13,19 +13,25 @@ var LoadingView = require('../LoadingView');
require('../../Mixins/DirectoryAutoComplete');
module.exports = Marionette.Layout.extend({
template : "Shared/FileBrowser/FileBrowserLayoutTemplate",
regions : {browser : "#x-browser"},
ui : {
path : ".x-path",
indicator : ".x-indicator"
template : 'Shared/FileBrowser/FileBrowserLayoutTemplate',
regions : {
browser : '#x-browser'
},
events : {
"typeahead:selected .x-path" : "_pathChanged",
"typeahead:autocompleted .x-path" : "_pathChanged",
"keyup .x-path" : "_inputChanged",
"click .x-ok" : "_selectPath"
ui : {
path : '.x-path',
indicator : '.x-indicator'
},
initialize : function(options){
events : {
'typeahead:selected .x-path' : '_pathChanged',
'typeahead:autocompleted .x-path' : '_pathChanged',
'keyup .x-path' : '_inputChanged',
'click .x-ok' : '_selectPath'
},
initialize : function(options) {
this.collection = new FileBrowserCollection();
this.collection.showFiles = options.showFiles || false;
this.collection.showLastModified = options.showLastModified || false;
@ -34,25 +40,30 @@ module.exports = Marionette.Layout.extend({
this.listenTo(this.collection, "sync", this._showGrid);
this.listenTo(this.collection, "filebrowser:folderselected", this._rowSelected);
},
onRender : function(){
onRender : function() {
this.browser.show(new LoadingView());
this.ui.path.directoryAutoComplete();
this._fetchCollection(this.input.val());
this._updatePath(this.input.val());
},
_setColumns : function(){
this.columns = [{
name : "type",
label : "",
sortable : false,
cell : FileBrowserTypeCell
}, {
name : "name",
label : "Name",
sortable : false,
cell : FileBrowserNameCell
}];
if(this.collection.showLastModified) {
_setColumns : function() {
this.columns = [
{
name : "type",
label : "",
sortable : false,
cell : FileBrowserTypeCell
},
{
name : "name",
label : "Name",
sortable : false,
cell : FileBrowserNameCell
}
];
if (this.collection.showLastModified) {
this.columns.push({
name : "lastModified",
label : "Last Modified",
@ -60,7 +71,7 @@ module.exports = Marionette.Layout.extend({
cell : RelativeDateCell
});
}
if(this.collection.showFiles) {
if (this.collection.showFiles) {
this.columns.push({
name : "size",
label : "Size",
@ -69,17 +80,19 @@ module.exports = Marionette.Layout.extend({
});
}
},
_fetchCollection : function(path){
_fetchCollection : function(path) {
this.ui.indicator.show();
var data = {includeFiles : this.collection.showFiles};
if(path) {
var data = { includeFiles : this.collection.showFiles };
if (path) {
data.path = path;
}
this.collection.fetch({data : data});
this.collection.fetch({ data : data });
},
_showGrid : function(){
_showGrid : function() {
this.ui.indicator.hide();
if(this.collection.models.length === 0) {
if (this.collection.models.length === 0) {
this.browser.show(new EmptyView());
return;
}
@ -91,27 +104,32 @@ module.exports = Marionette.Layout.extend({
});
this.browser.show(grid);
},
_rowSelected : function(model){
_rowSelected : function(model) {
var path = model.get("path");
this._updatePath(path);
this._fetchCollection(path);
},
_pathChanged : function(e, path){
_pathChanged : function(e, path) {
this._fetchCollection(path.value);
this._updatePath(path.value);
},
_inputChanged : function(){
_inputChanged : function() {
var path = this.ui.path.val();
if(path === "" || path.endsWith("\\") || path.endsWith("/")) {
if (path === "" || path.endsWith("\\") || path.endsWith("/")) {
this._fetchCollection(path);
}
},
_updatePath : function(path){
if(path !== undefined || path !== null) {
_updatePath : function(path) {
if (path !== undefined || path !== null) {
this.ui.path.val(path);
}
},
_selectPath : function(){
_selectPath : function() {
this.input.val(this.ui.path.val());
this.input.trigger("change");
vent.trigger(vent.Commands.CloseFileBrowser);