Skip to content

Commit

Permalink
MDL-31901: Highlighting main file in FileManager
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed May 21, 2012
1 parent c092681 commit 6c2367c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
27 changes: 24 additions & 3 deletions lib/form/filemanager.js
Expand Up @@ -468,6 +468,13 @@ M.form_filemanager.init = function(Y, options) {
rightclickcallback : function(e, node) {
if (e.preventDefault) { e.preventDefault(); }
this.select_file(node);
},
classnamecallback : function(node) {
var classname = '';
if (node.type == 'folder') { classname = classname + ' fp-folder';}
if (node.filepath) { classname = classname + ' fp-hascontextmenu';}
if (node.sortorder == 1) { classname = classname + ' fp-mainfile';}
return Y.Lang.trim(classname);
}
};
if (this.viewmode == 2) {
Expand Down Expand Up @@ -606,7 +613,9 @@ M.form_filemanager.init = function(Y, options) {
}, this);
selectnode.one('.fp-file-download').on('click', function(e) {
e.preventDefault();
window.open(this.selectui.fileinfo.url, 'fm-download-file');
if (this.selectui.fileinfo.type != 'folder') {
window.open(this.selectui.fileinfo.url, 'fm-download-file');
}
}, this);
selectnode.one('.fp-file-delete').on('click', function(e) {
e.preventDefault();
Expand Down Expand Up @@ -644,6 +653,10 @@ M.form_filemanager.init = function(Y, options) {
e.preventDefault();
var params = {};
var fileinfo = this.selectui.fileinfo;
if (fileinfo.type != 'folder') {
// this button should not even be shown
return;
}
params['filepath'] = fileinfo.filepath;
params['filename'] = '.';
selectnode.addClass('loading');
Expand All @@ -661,6 +674,10 @@ M.form_filemanager.init = function(Y, options) {
e.preventDefault();
var params = {};
var fileinfo = this.selectui.fileinfo;
if (fileinfo.type != 'zip') {
// this button should not even be shown
return;
}
params['filepath'] = fileinfo.filepath;
params['filename'] = fileinfo.fullname;
selectnode.addClass('loading');
Expand All @@ -678,6 +695,10 @@ M.form_filemanager.init = function(Y, options) {
e.preventDefault();
var params = {};
var fileinfo = this.selectui.fileinfo;
if (fileinfo.type == 'folder') {
// this button should not even be shown for folders
return;
}
params['filepath'] = fileinfo.filepath;
params['filename'] = fileinfo.fullname;
selectnode.addClass('loading');
Expand All @@ -687,7 +708,7 @@ M.form_filemanager.init = function(Y, options) {
params: params,
callback: function(id, obj, args) {
args.scope.selectui.hide();
args.scope.refresh(obj.filepath);
args.scope.refresh(fileinfo.filepath);
}
});
}, this);
Expand All @@ -710,7 +731,7 @@ M.form_filemanager.init = function(Y, options) {
removeClass('fp-file').removeClass('fp-zip').removeClass('fp-cansetmain');
if (node.type == 'folder' || node.type == 'zip') {selectnode.addClass('fp-'+node.type);}
else {selectnode.addClass('fp-file');}
if (this.enablemainfile && (node.sortorder != 1)) {
if (this.enablemainfile && (node.sortorder != 1) && node.type == 'file') {
selectnode.addClass('fp-cansetmain');
}
this.selectui.fileinfo = node;
Expand Down
41 changes: 18 additions & 23 deletions repository/filepicker.js
Expand Up @@ -82,12 +82,12 @@ YUI.add('moodle-core_filepicker', function(Y) {
* filenode : Node element that contains template for displaying one file
* callback : On click callback. The element of the fileslist array will be passed as argument
* rightclickcallback : On right click callback (optional).
* norootrightclick : No right click for top element in the tree
* callbackcontext : context where callbacks are executed
* sortable : whether content may be sortable (in table mode)
* dynload : allow dynamic load for tree view
* filepath : for pre-building of tree view - the path to the current directory in filepicker format
* treeview_dynload : callback to ...
* treeview_dynload : callback to function to dynamically load the folder in tree view
* classnamecallback : callback to function that returns the class name for an element
* @param array fileslist array of files to show, each array element may have attributes:
* title or fullname : file name
* shorttitle (optional) : display file name
Expand Down Expand Up @@ -129,14 +129,8 @@ YUI.add('moodle-core_filepicker', function(Y) {

el.one('.fp-filename').setContent(file_get_displayname(node));
// TODO add tooltip with node.title or node.thumbnail_title
var tmpnodedata = {className:''};
if (file_is_folder(node)) {
el.get('children').addClass('fp-folder');
tmpnodedata.className = tmpnodedata.className + ' fp-folder';
}
if (options.rightclickcallback && !node.nocontextmenu) {
tmpnodedata.className = tmpnodedata.className + ' fp-hascontextmenu';
}
var tmpnodedata = {className:options.classnamecallback(node)};
el.get('children').addClass(tmpnodedata.className);
if (node.icon) {
el.one('.fp-icon').appendChild(Y.Node.create('<img/>').set('src', node.icon));
if (node.realicon) {
Expand Down Expand Up @@ -179,9 +173,6 @@ YUI.add('moodle-core_filepicker', function(Y) {
for (var i in options.filepath) {
if (mytreeel == null) {
mytreeel = mytree;
if (options.norootrightclick) {
mytreeel.nocontextmenu = true;
}
} else {
mytreeel.children = [{}];
mytreeel = mytreeel.children[0];
Expand Down Expand Up @@ -243,9 +234,7 @@ YUI.add('moodle-core_filepicker', function(Y) {
var formatTitle = function(o) {
var el = Y.Node.create('<div/>');
el.appendChild(options.filenode.cloneNode(true)); // TODO not node but string!
if (o.data['isfolder']) {
el.get('children').addClass('fp-folder');
}
el.get('children').addClass(o.data['classname']);
el.one('.fp-filename').setContent(o.value);
if (o.data['icon']) {
el.one('.fp-icon').appendChild(Y.Node.create('<img/>').set('src', o.data['icon']));
Expand Down Expand Up @@ -304,6 +293,7 @@ YUI.add('moodle-core_filepicker', function(Y) {
// to speed up sorting and formatting
fileslist[k].displayname = file_get_displayname(fileslist[k]);
fileslist[k].isfolder = file_is_folder(fileslist[k]);
fileslist[k].classname = options.classnamecallback(fileslist[k]);
}
scope.tableview.addRows(fileslist);
scope.tableview.sortable = options.sortable ? true : false;
Expand Down Expand Up @@ -331,12 +321,7 @@ YUI.add('moodle-core_filepicker', function(Y) {
var node = fileslist[k];
var element = options.filenode.cloneNode(true);
parent.appendChild(element);
if (file_is_folder(node)) {
element.addClass('fp-folder');
}
if (options.rightclickcallback) {
element.addClass('fp-hascontextmenu');
}
element.addClass(options.classnamecallback(node));
var filenamediv = element.one('.fp-filename');
filenamediv.setContent(file_get_displayname(node));
var imgdiv = element.one('.fp-thumbnail'), width, height, src;
Expand Down Expand Up @@ -858,6 +843,9 @@ M.core_filepicker.init = function(Y, options) {
this.content_scrolled();
}
},
classnamecallback : function(node) {
return node.children ? 'fp-folder' : '';
},
dynload : this.active_repo.dynload,
filepath : this.filepath,
treeview_dynload : this.treeview_dynload
Expand Down Expand Up @@ -893,6 +881,9 @@ M.core_filepicker.init = function(Y, options) {
} else {
this.select_file(node);
}
},
classnamecallback : function(node) {
return node.children ? 'fp-folder' : '';
}
};
this.fpnode.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
Expand Down Expand Up @@ -927,6 +918,9 @@ M.core_filepicker.init = function(Y, options) {
} else {
this.select_file(node);
}
},
classnamecallback : function(node) {
return node.children ? 'fp-folder' : '';
}
};
this.fpnode.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
Expand Down Expand Up @@ -1144,7 +1138,6 @@ M.core_filepicker.init = function(Y, options) {
set('id', 'filepicker-'+client_id);
var fpselectnode = Y.Node.create(M.core_filepicker.templates.selectlayout);
Y.one(document.body).appendChild(this.fpnode);
this.fpnode.appendChild(fpselectnode);
this.mainui = new Y.Panel({
srcNode : this.fpnode,
headerContent: M.str.repository.filepicker,
Expand All @@ -1161,7 +1154,9 @@ M.core_filepicker.init = function(Y, options) {
// allow to move the panel dragging it by it's header:
this.mainui.plug(Y.Plugin.Drag,{handles:['.yui3-widget-hd']});
this.mainui.show();
if (this.mainui.get('y')<0) {this.mainui.set('y', 0);}
// create panel for selecting a file (initially hidden)
this.fpnode.appendChild(fpselectnode);
this.selectui = new Y.Panel({
srcNode : fpselectnode,
zIndex : 600000,
Expand Down
1 change: 1 addition & 0 deletions theme/base/style/filemanager.css
Expand Up @@ -237,6 +237,7 @@ background: #CCC!important;filter: progid:DXImageTransform.Microsoft.gradient(st
.filemanager .fp-iconview .fp-file {float:left;text-align:center;}
.filemanager .fp-iconview .fp-file div {overflow: hidden;}
.filemanager .fp-iconview .fp-file .fp-filename {height:48px;text-align:center;min-width:50px;}
.filemanager .fp-mainfile .fp-filename {font-weight:bold;}

.filemanager .fp-contextmenu {display:none;}
.filemanager .fp-iconview .fp-folder.fp-hascontextmenu .fp-contextmenu {display:block;position:absolute;right:0px;top:0px;}
Expand Down

0 comments on commit 6c2367c

Please sign in to comment.