2010-01-15 07:48:38 +00:00
|
|
|
// YUI3 File Picker module for moodle
|
|
|
|
// Author: Dongsheng Cai <dongsheng@moodle.com>
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* File Picker UI
|
|
|
|
* =====
|
2012-03-30 10:11:43 +08:00
|
|
|
* this.fpnode, contains reference to filepicker Node, non-empty if and only if rendered
|
2010-01-15 07:48:38 +00:00
|
|
|
* this.api, stores the URL to make ajax request
|
|
|
|
* this.mainui, YUI Panel
|
2012-03-30 10:11:43 +08:00
|
|
|
* this.selectui, YUI Panel for selecting particular file
|
|
|
|
* this.msg_dlg, YUI Panel for error or info message
|
|
|
|
* this.process_dlg, YUI Panel for processing existing filename
|
2010-01-15 07:48:38 +00:00
|
|
|
* this.treeview, YUI Treeview
|
|
|
|
* this.viewmode, store current view mode
|
2012-03-30 10:11:43 +08:00
|
|
|
* this.pathbar, reference to the Node with path bar
|
|
|
|
* this.pathnode, a Node element representing one folder in a path bar (not attached anywhere, just used for template)
|
2010-01-15 07:48:38 +00:00
|
|
|
*
|
|
|
|
* Filepicker options:
|
|
|
|
* =====
|
|
|
|
* this.options.client_id, the instance id
|
|
|
|
* this.options.contextid
|
|
|
|
* this.options.itemid
|
|
|
|
* this.options.repositories, stores all repositories displaied in file picker
|
|
|
|
* this.options.formcallback
|
|
|
|
*
|
|
|
|
* Active repository options
|
|
|
|
* =====
|
|
|
|
* this.active_repo.id
|
|
|
|
* this.active_repo.nosearch
|
|
|
|
* this.active_repo.norefresh
|
|
|
|
* this.active_repo.nologin
|
|
|
|
* this.active_repo.help
|
|
|
|
* this.active_repo.manage
|
2010-09-17 19:46:57 +00:00
|
|
|
*
|
2010-01-15 07:48:38 +00:00
|
|
|
* Server responses
|
|
|
|
* =====
|
|
|
|
* this.filelist, cached filelist
|
|
|
|
* this.pages
|
|
|
|
* this.page
|
|
|
|
* this.filepath, current path
|
|
|
|
* this.logindata, cached login form
|
|
|
|
*/
|
|
|
|
|
2012-05-02 14:59:09 +08:00
|
|
|
YUI.add('moodle-core_filepicker', function(Y) {
|
|
|
|
/** help function to extract width/height style as a number, not as a string */
|
|
|
|
Y.Node.prototype.getStylePx = function(attr) {
|
|
|
|
var style = this.getStyle(attr);
|
|
|
|
if (''+style == '0' || ''+style == '0px') {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
var matches = style.match(/^([\d\.]+)px$/)
|
|
|
|
if (matches && parseFloat(matches[1])) {
|
|
|
|
return parseFloat(matches[1]);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** if condition is met, the class is added to the node, otherwise - removed */
|
|
|
|
Y.Node.prototype.addClassIf = function(className, condition) {
|
|
|
|
if (condition) {
|
|
|
|
this.addClass(className);
|
|
|
|
} else {
|
|
|
|
this.removeClass(className);
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** sets the width(height) of the node considering existing minWidth(minHeight) */
|
|
|
|
Y.Node.prototype.setStyleAdv = function(stylename, value) {
|
|
|
|
var stylenameCap = stylename.substr(0,1).toUpperCase() + stylename.substr(1, stylename.length-1).toLowerCase();
|
|
|
|
this.setStyle(stylename, '' + Math.max(value, this.getStylePx('min'+stylenameCap)) + 'px')
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a list of files (used by filepicker, filemanager) inside the Node
|
|
|
|
*
|
|
|
|
* @param array options
|
|
|
|
* viewmode : 1 - icons, 2 - tree, 3 - table
|
|
|
|
* appendonly : whether fileslist need to be appended instead of replacing the existing content
|
|
|
|
* 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).
|
|
|
|
* 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
|
2012-05-04 16:09:26 +08:00
|
|
|
* 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
|
2012-05-02 14:59:09 +08:00
|
|
|
* @param array fileslist array of files to show, each array element may have attributes:
|
|
|
|
* title or fullname : file name
|
|
|
|
* shorttitle (optional) : display file name
|
|
|
|
* thumbnail : url of image
|
|
|
|
* icon : url of icon image
|
|
|
|
* thumbnail_width : width of thumbnail, default 90
|
|
|
|
* thumbnail_height : height of thumbnail, default 90
|
|
|
|
* thumbnail_alt : TODO not needed!
|
|
|
|
* description or thumbnail_title : alt text
|
|
|
|
* @param array lazyloading : reference to the array with lazy loading images
|
|
|
|
*/
|
|
|
|
Y.Node.prototype.fp_display_filelist = function(options, fileslist, lazyloading) {
|
|
|
|
var viewmodeclassnames = {1:'fp-iconview', 2:'fp-treeview', 3:'fp-tableview'};
|
|
|
|
var classname = viewmodeclassnames[options.viewmode];
|
|
|
|
var scope = this;
|
|
|
|
/** return whether file is a folder (different attributes in FileManager and FilePicker) */
|
|
|
|
var file_is_folder = function(node) {
|
|
|
|
if (node.children) {return true;}
|
|
|
|
if (node.type && node.type == 'folder') {return true;}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
/** return the name of the file (different attributes in FileManager and FilePicker) */
|
|
|
|
var file_get_filename = function(node) {
|
|
|
|
return node.title ? node.title : node.fullname;
|
|
|
|
}
|
|
|
|
/** return display name of the file (different attributes in FileManager and FilePicker) */
|
|
|
|
var file_get_displayname = function(node) {
|
|
|
|
return node.shorttitle ? node.shorttitle : file_get_filename(node);
|
|
|
|
}
|
|
|
|
/** return file description (different attributes in FileManager and FilePicker) */
|
|
|
|
var file_get_description = function(node) {
|
|
|
|
return node.description ? node.description : (node.thumbnail_title ? node.thumbnail_title : file_get_filename(node));
|
|
|
|
}
|
|
|
|
/** help funciton for tree view */
|
|
|
|
var build_tree = function(node, level) {
|
|
|
|
// prepare file name with icon
|
|
|
|
var el = Y.Node.create('<div/>');
|
|
|
|
el.appendChild(options.filenode.cloneNode(true));
|
|
|
|
|
|
|
|
el.one('.fp-filename').setContent(file_get_displayname(node));
|
|
|
|
// TODO add tooltip with node.title or node.thumbnail_title
|
2012-05-04 16:09:26 +08:00
|
|
|
var tmpnodedata = {className:options.classnamecallback(node)};
|
|
|
|
el.get('children').addClass(tmpnodedata.className);
|
2012-05-02 14:59:09 +08:00
|
|
|
if (node.icon) {
|
|
|
|
el.one('.fp-icon').appendChild(Y.Node.create('<img/>').set('src', node.icon));
|
|
|
|
if (node.realicon) {
|
|
|
|
lazyloading[el.one('.fp-icon img').generateID()] = node.realicon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// create node
|
2012-05-03 15:14:59 +08:00
|
|
|
tmpnodedata.html = el.getContent();
|
|
|
|
var tmpNode = new YAHOO.widget.HTMLNode(tmpnodedata, level, false);
|
2012-05-02 14:59:09 +08:00
|
|
|
if (node.dynamicLoadComplete) {
|
|
|
|
tmpNode.dynamicLoadComplete = true;
|
|
|
|
}
|
|
|
|
tmpNode.fileinfo = node;
|
|
|
|
tmpNode.isLeaf = !file_is_folder(node);
|
|
|
|
if (!tmpNode.isLeaf) {
|
|
|
|
if(node.expanded) {
|
|
|
|
tmpNode.expand();
|
|
|
|
}
|
|
|
|
tmpNode.path = node.path ? node.path : (node.filepath ? node.filepath : '');
|
|
|
|
for(var c in node.children) {
|
|
|
|
build_tree(node.children[c], tmpNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/** initialize tree view */
|
|
|
|
var initialize_tree_view = function() {
|
|
|
|
var parentid = scope.one('.'+classname).get('id');
|
2012-05-03 15:14:59 +08:00
|
|
|
// TODO MDL-32736 use YUI3 gallery TreeView
|
2012-05-02 14:59:09 +08:00
|
|
|
scope.treeview = new YAHOO.widget.TreeView(parentid);
|
|
|
|
if (options.dynload) {
|
|
|
|
scope.treeview.setDynamicLoad(Y.bind(options.treeview_dynload, options.callbackcontext), 1);
|
|
|
|
}
|
|
|
|
scope.treeview.singleNodeHighlight = true;
|
|
|
|
if (options.filepath && options.filepath.length) {
|
|
|
|
// we just jumped from icon/details view, we need to show all parents
|
|
|
|
// we extract as much information as possible from filepath and filelist
|
|
|
|
// and send additional requests to retrieve siblings for parent folders
|
|
|
|
var mytree = {};
|
|
|
|
var mytreeel = null;
|
|
|
|
for (var i in options.filepath) {
|
|
|
|
if (mytreeel == null) {
|
|
|
|
mytreeel = mytree;
|
|
|
|
} else {
|
|
|
|
mytreeel.children = [{}];
|
|
|
|
mytreeel = mytreeel.children[0];
|
|
|
|
}
|
|
|
|
var pathelement = options.filepath[i];
|
|
|
|
mytreeel.path = pathelement.path;
|
|
|
|
mytreeel.title = pathelement.name;
|
|
|
|
mytreeel.dynamicLoadComplete = true; // we will call it manually
|
|
|
|
mytreeel.expanded = true;
|
|
|
|
}
|
|
|
|
mytreeel.children = fileslist;
|
|
|
|
build_tree(mytree, scope.treeview.getRoot());
|
|
|
|
// manually call dynload for parent elements in the tree so we can load other siblings
|
|
|
|
if (options.dynload) {
|
|
|
|
var root = scope.treeview.getRoot();
|
|
|
|
while (root && root.children && root.children.length) {
|
|
|
|
root = root.children[0];
|
|
|
|
if (root.path == mytreeel.path) {
|
|
|
|
root.origpath = options.filepath;
|
|
|
|
root.origlist = fileslist;
|
|
|
|
} else if (!root.isLeaf && root.expanded) {
|
|
|
|
Y.bind(options.treeview_dynload, options.callbackcontext)(root, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// there is no path information, just display all elements as a list, without hierarchy
|
|
|
|
for(k in fileslist) {
|
|
|
|
build_tree(fileslist[k], scope.treeview.getRoot());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scope.treeview.subscribe('clickEvent', function(e){
|
|
|
|
e.node.highlight(false);
|
2012-05-03 15:14:59 +08:00
|
|
|
var callback = options.callback;
|
|
|
|
if (options.rightclickcallback && e.event.target &&
|
|
|
|
Y.Node(e.event.target).ancestor('.fp-treeview .fp-contextmenu', true)) {
|
|
|
|
callback = options.rightclickcallback;
|
|
|
|
}
|
|
|
|
Y.bind(callback, options.callbackcontext)(e, e.node.fileinfo);
|
|
|
|
YAHOO.util.Event.stopEvent(e.event)
|
2012-05-02 14:59:09 +08:00
|
|
|
});
|
2012-05-03 15:14:59 +08:00
|
|
|
// TODO MDL-32736 support right click
|
|
|
|
/*if (options.rightclickcallback) {
|
|
|
|
scope.treeview.subscribe('dblClickEvent', function(e){
|
2012-05-02 14:59:09 +08:00
|
|
|
e.node.highlight(false);
|
2012-05-03 15:14:59 +08:00
|
|
|
Y.bind(options.rightclickcallback, options.callbackcontext)(e, e.node.fileinfo);
|
2012-05-02 14:59:09 +08:00
|
|
|
});
|
2012-05-03 15:14:59 +08:00
|
|
|
}*/
|
2012-05-02 14:59:09 +08:00
|
|
|
scope.treeview.draw();
|
|
|
|
};
|
|
|
|
/** formatting function for table view */
|
|
|
|
var formatValue = function (o){
|
|
|
|
if (o.data[''+o.column.key+'_f_s']) {return o.data[''+o.column.key+'_f_s'];}
|
|
|
|
else if (o.data[''+o.column.key+'_f']) {return o.data[''+o.column.key+'_f'];}
|
|
|
|
else if (o.value) {return o.value;}
|
|
|
|
else {return '';}
|
|
|
|
};
|
|
|
|
/** formatting function for table view */
|
|
|
|
var formatTitle = function(o) {
|
|
|
|
var el = Y.Node.create('<div/>');
|
|
|
|
el.appendChild(options.filenode.cloneNode(true)); // TODO not node but string!
|
2012-05-04 16:09:26 +08:00
|
|
|
el.get('children').addClass(o.data['classname']);
|
2012-05-02 14:59:09 +08:00
|
|
|
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']));
|
|
|
|
if (o.data['realicon']) {
|
|
|
|
lazyloading[el.one('.fp-icon img').generateID()] = o.data['realicon'];
|
|
|
|
}
|
|
|
|
}
|
2012-05-03 15:14:59 +08:00
|
|
|
if (options.rightclickcallback) {
|
|
|
|
el.get('children').addClass('fp-hascontextmenu');
|
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
// TODO add tooltip with o.data['title'] (o.value) or o.data['thumbnail_title']
|
|
|
|
return el.getContent();
|
|
|
|
}
|
|
|
|
/** sorting function for table view */
|
|
|
|
var sortFoldersFirst = function(a, b, desc) {
|
|
|
|
if (a.get('isfolder') && !b.get('isfolder')) {return -1;}
|
|
|
|
if (!a.get('isfolder') && b.get('isfolder')) {return 1;}
|
|
|
|
var aa = a.get(this.key), bb = b.get(this.key), dir = desc?-1:1;
|
|
|
|
return (aa > bb) ? dir : ((aa < bb) ? -dir : 0);
|
|
|
|
}
|
|
|
|
/** initialize table view */
|
|
|
|
var initialize_table_view = function() {
|
|
|
|
var parentid = scope.one('.'+classname).get('id');
|
|
|
|
var cols = [
|
|
|
|
{key: "displayname", label: M.str.moodle.name, allowHTML: true, formatter: formatTitle,
|
|
|
|
sortable: true, sortFn: sortFoldersFirst},
|
|
|
|
{key: "datemodified", label: M.str.moodle.lastmodified, allowHTML: true, formatter: formatValue,
|
|
|
|
sortable: true, sortFn: sortFoldersFirst},
|
|
|
|
{key: "size", label: M.str.repository.size, allowHTML: true, formatter: formatValue,
|
|
|
|
sortable: true, sortFn: sortFoldersFirst},
|
|
|
|
{key: "mimetype", label: M.str.repository.type, allowHTML: true,
|
|
|
|
sortable: true, sortFn: sortFoldersFirst}
|
|
|
|
];
|
|
|
|
scope.tableview = new Y.DataTable({columns: cols});
|
|
|
|
scope.tableview.render('#'+parentid);
|
|
|
|
scope.tableview.delegate('click', function (e, tableview) {
|
|
|
|
var record = tableview.getRecord(e.currentTarget.get('id'));
|
2012-05-03 15:14:59 +08:00
|
|
|
if (record) {
|
|
|
|
var callback = options.callback;
|
|
|
|
if (options.rightclickcallback && e.target.ancestor('.fp-tableview .fp-contextmenu', true)) {
|
|
|
|
callback = options.rightclickcallback;
|
|
|
|
}
|
|
|
|
Y.bind(callback, this)(e, record.getAttrs());
|
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
}, 'tr', options.callbackcontext, scope.tableview);
|
|
|
|
if (options.rightclickcallback) {
|
|
|
|
scope.tableview.delegate('contextmenu', function (e, tableview) {
|
|
|
|
var record = tableview.getRecord(e.currentTarget.get('id'));
|
|
|
|
if (record) { Y.bind(options.rightclickcallback, this)(e, record.getAttrs()); }
|
|
|
|
}, 'tr', options.callbackcontext, scope.tableview);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/** append items in table view mode */
|
|
|
|
var append_files_table = function() {
|
|
|
|
for (var k in fileslist) {
|
|
|
|
// to speed up sorting and formatting
|
|
|
|
fileslist[k].displayname = file_get_displayname(fileslist[k]);
|
|
|
|
fileslist[k].isfolder = file_is_folder(fileslist[k]);
|
2012-05-04 16:09:26 +08:00
|
|
|
fileslist[k].classname = options.classnamecallback(fileslist[k]);
|
2012-05-02 14:59:09 +08:00
|
|
|
}
|
|
|
|
scope.tableview.addRows(fileslist);
|
|
|
|
scope.tableview.sortable = options.sortable ? true : false;
|
|
|
|
};
|
|
|
|
/** append items in tree view mode */
|
|
|
|
var append_files_tree = function() {
|
|
|
|
if (options.appendonly) {
|
|
|
|
var parentnode = scope.treeview.getRoot();
|
|
|
|
if (scope.treeview.getHighlightedNode()) {
|
|
|
|
parentnode = scope.treeview.getHighlightedNode();
|
|
|
|
if (parentnode.isLeaf) {parentnode = parentnode.parent;}
|
|
|
|
}
|
|
|
|
for (var k in fileslist) {
|
|
|
|
build_tree(fileslist[k], parentnode);
|
|
|
|
}
|
|
|
|
scope.treeview.draw();
|
|
|
|
} else {
|
|
|
|
// otherwise files were already added in initialize_tree_view()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/** append items in icon view mode */
|
|
|
|
var append_files_icons = function() {
|
|
|
|
parent = scope.one('.'+classname);
|
|
|
|
for (var k in fileslist) {
|
|
|
|
var node = fileslist[k];
|
|
|
|
var element = options.filenode.cloneNode(true);
|
|
|
|
parent.appendChild(element);
|
2012-05-04 16:09:26 +08:00
|
|
|
element.addClass(options.classnamecallback(node));
|
2012-05-02 14:59:09 +08:00
|
|
|
var filenamediv = element.one('.fp-filename');
|
|
|
|
filenamediv.setContent(file_get_displayname(node));
|
|
|
|
var imgdiv = element.one('.fp-thumbnail'), width, height, src;
|
|
|
|
if (node.thumbnail) {
|
|
|
|
width = node.thumbnail_width ? node.thumbnail_width : 90;
|
|
|
|
height = node.thumbnail_height ? node.thumbnail_height : 90;
|
|
|
|
src = node.thumbnail;
|
|
|
|
} else {
|
|
|
|
width = 16;
|
|
|
|
height = 16;
|
|
|
|
src = node.icon;
|
|
|
|
}
|
|
|
|
filenamediv.setStyleAdv('width', width);
|
|
|
|
imgdiv.setStyleAdv('width', width).setStyleAdv('height', height);
|
|
|
|
var img = Y.Node.create('<img/>').setAttrs({
|
|
|
|
src: src,
|
|
|
|
title: file_get_description(node),
|
|
|
|
alt: node.thumbnail_alt ? node.thumbnail_alt : file_get_filename(node)}).
|
|
|
|
setStyle('maxWidth', ''+width+'px').
|
|
|
|
setStyle('maxHeight', ''+height+'px');
|
|
|
|
if (node.realthumbnail) {
|
|
|
|
lazyloading[img.generateID()] = node.realthumbnail;
|
|
|
|
}
|
|
|
|
imgdiv.appendChild(img);
|
2012-05-03 15:14:59 +08:00
|
|
|
element.on('click', function(e, nd) {
|
|
|
|
if (options.rightclickcallback && e.target.ancestor('.fp-iconview .fp-contextmenu', true)) {
|
|
|
|
Y.bind(options.rightclickcallback, this)(e, nd);
|
|
|
|
} else {
|
|
|
|
Y.bind(options.callback, this)(e, nd);
|
|
|
|
}
|
|
|
|
}, options.callbackcontext, node);
|
2012-05-02 14:59:09 +08:00
|
|
|
if (options.rightclickcallback) {
|
|
|
|
element.on('contextmenu', options.rightclickcallback, options.callbackcontext, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize files view
|
|
|
|
if (!options.appendonly) {
|
|
|
|
var parent = Y.Node.create('<div/>').addClass(classname);
|
|
|
|
this.setContent('').appendChild(parent);
|
|
|
|
parent.generateID();
|
|
|
|
if (options.viewmode == 2) {
|
|
|
|
initialize_tree_view();
|
|
|
|
} else if (options.viewmode == 3) {
|
|
|
|
initialize_table_view();
|
|
|
|
} else {
|
|
|
|
// nothing to initialize for icon view
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// append files to the list
|
|
|
|
if (options.viewmode == 2) {
|
|
|
|
append_files_tree();
|
|
|
|
} else if (options.viewmode == 3) {
|
|
|
|
append_files_table();
|
|
|
|
} else {
|
|
|
|
append_files_icons();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}, '@VERSION@', {
|
2012-05-04 16:46:41 +08:00
|
|
|
requires:['base', 'node', 'yui2-treeview', 'panel', 'cookie', 'datatable', 'datatable-sort']
|
2012-05-02 14:59:09 +08:00
|
|
|
});
|
|
|
|
|
2010-02-03 14:36:53 +00:00
|
|
|
M.core_filepicker = M.core_filepicker || {};
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2010-02-03 14:36:53 +00:00
|
|
|
/**
|
|
|
|
* instances of file pickers used on page
|
|
|
|
*/
|
|
|
|
M.core_filepicker.instances = M.core_filepicker.instances || {};
|
2010-03-15 05:19:43 +00:00
|
|
|
M.core_filepicker.active_filepicker = null;
|
2010-02-03 14:36:53 +00:00
|
|
|
|
2012-03-30 10:11:43 +08:00
|
|
|
/**
|
|
|
|
* HTML Templates to use in FilePicker
|
|
|
|
*/
|
|
|
|
M.core_filepicker.templates = M.core_filepicker.templates || {};
|
|
|
|
|
2010-02-03 14:36:53 +00:00
|
|
|
/**
|
|
|
|
* Init and show file picker
|
|
|
|
*/
|
|
|
|
M.core_filepicker.show = function(Y, options) {
|
|
|
|
if (!M.core_filepicker.instances[options.client_id]) {
|
2010-09-17 19:46:57 +00:00
|
|
|
M.core_filepicker.init(Y, options);
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2010-02-03 14:36:53 +00:00
|
|
|
M.core_filepicker.instances[options.client_id].show();
|
|
|
|
};
|
|
|
|
|
2012-04-26 15:28:53 +08:00
|
|
|
M.core_filepicker.set_templates = function(Y, templates) {
|
|
|
|
for (var templid in templates) {
|
|
|
|
M.core_filepicker.templates[templid] = templates[templid];
|
|
|
|
}
|
|
|
|
}
|
2012-04-19 10:40:21 +08:00
|
|
|
|
2010-02-03 14:36:53 +00:00
|
|
|
/**
|
|
|
|
* Add new file picker to current instances
|
|
|
|
*/
|
|
|
|
M.core_filepicker.init = function(Y, options) {
|
|
|
|
var FilePickerHelper = function(options) {
|
|
|
|
FilePickerHelper.superclass.constructor.apply(this, arguments);
|
2010-09-17 19:46:57 +00:00
|
|
|
};
|
2010-02-03 14:36:53 +00:00
|
|
|
|
|
|
|
FilePickerHelper.NAME = "FilePickerHelper";
|
|
|
|
FilePickerHelper.ATTRS = {
|
2010-01-15 07:48:38 +00:00
|
|
|
options: {},
|
|
|
|
lang: {}
|
|
|
|
};
|
2010-02-03 14:36:53 +00:00
|
|
|
|
|
|
|
Y.extend(FilePickerHelper, Y.Base, {
|
2010-01-21 22:19:46 +00:00
|
|
|
api: M.cfg.wwwroot+'/repository/repository_ajax.php',
|
2012-03-07 11:25:18 +08:00
|
|
|
cached_responses: {},
|
2010-02-03 14:36:53 +00:00
|
|
|
|
|
|
|
initializer: function(options) {
|
|
|
|
this.options = options;
|
2010-04-12 03:07:40 +00:00
|
|
|
if (!this.options.savepath) {
|
|
|
|
this.options.savepath = '/';
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
},
|
2010-02-03 14:36:53 +00:00
|
|
|
|
2010-01-15 07:48:38 +00:00
|
|
|
destructor: function() {
|
|
|
|
},
|
2010-02-03 14:36:53 +00:00
|
|
|
|
2010-01-15 07:48:38 +00:00
|
|
|
request: function(args, redraw) {
|
2012-04-11 10:05:25 +08:00
|
|
|
var api = (args.api?args.api:this.api) + '?action='+args.action;
|
2010-01-15 07:48:38 +00:00
|
|
|
var params = {};
|
2012-04-11 10:05:25 +08:00
|
|
|
var scope = args['scope']?args['scope']:this;
|
2010-01-15 07:48:38 +00:00
|
|
|
params['repo_id']=args.repository_id;
|
|
|
|
params['p'] = args.path?args.path:'';
|
|
|
|
params['page'] = args.page?args.page:'';
|
|
|
|
params['env']=this.options.env;
|
|
|
|
// the form element only accept certain file types
|
|
|
|
params['accepted_types']=this.options.accepted_types;
|
2010-07-05 07:27:49 +00:00
|
|
|
params['sesskey'] = M.cfg.sesskey;
|
2010-01-15 07:48:38 +00:00
|
|
|
params['client_id'] = args.client_id;
|
2010-01-18 05:28:42 +00:00
|
|
|
params['itemid'] = this.options.itemid?this.options.itemid:0;
|
2010-03-08 16:49:51 +00:00
|
|
|
params['maxbytes'] = this.options.maxbytes?this.options.maxbytes:-1;
|
2010-07-19 17:44:23 +00:00
|
|
|
if (this.options.context && this.options.context.id) {
|
|
|
|
params['ctx_id'] = this.options.context.id;
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
if (args['params']) {
|
|
|
|
for (i in args['params']) {
|
|
|
|
params[i] = args['params'][i];
|
|
|
|
}
|
|
|
|
}
|
2010-07-26 08:37:48 +00:00
|
|
|
if (args.action == 'upload') {
|
|
|
|
var list = [];
|
|
|
|
for(var k in params) {
|
|
|
|
var value = params[k];
|
|
|
|
if(value instanceof Array) {
|
|
|
|
for(var i in value) {
|
|
|
|
list.push(k+'[]='+value[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
list.push(k+'='+value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
params = list.join('&');
|
|
|
|
} else {
|
|
|
|
params = build_querystring(params);
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
var cfg = {
|
|
|
|
method: 'POST',
|
|
|
|
on: {
|
|
|
|
complete: function(id,o,p) {
|
|
|
|
if (!o) {
|
2012-03-30 10:11:43 +08:00
|
|
|
// TODO
|
2010-01-15 07:48:38 +00:00
|
|
|
alert('IO FATAL');
|
|
|
|
return;
|
|
|
|
}
|
2010-02-03 14:36:53 +00:00
|
|
|
var data = null;
|
|
|
|
try {
|
|
|
|
data = Y.JSON.parse(o.responseText);
|
|
|
|
} catch(e) {
|
2010-05-21 08:13:08 +00:00
|
|
|
scope.print_msg(M.str.repository.invalidjson, 'error');
|
2012-03-30 10:11:43 +08:00
|
|
|
scope.display_error(M.str.repository.invalidjson+'<pre>'+stripHTML(o.responseText)+'</pre>', 'invalidjson')
|
2010-04-28 13:54:36 +00:00
|
|
|
return;
|
2010-02-03 14:36:53 +00:00
|
|
|
}
|
2010-03-29 03:39:08 +00:00
|
|
|
// error checking
|
2010-07-05 07:27:49 +00:00
|
|
|
if (data && data.error) {
|
|
|
|
scope.print_msg(data.error, 'error');
|
2012-03-14 12:24:36 +08:00
|
|
|
if (args.onerror) {
|
|
|
|
args.onerror(id,data,p);
|
|
|
|
} else {
|
2012-04-11 10:05:25 +08:00
|
|
|
this.fpnode.one('.fp-content').setContent('');
|
2012-03-14 12:24:36 +08:00
|
|
|
}
|
2010-03-29 03:39:08 +00:00
|
|
|
return;
|
2011-05-02 10:11:19 +08:00
|
|
|
} else if (data && data.event) {
|
|
|
|
switch (data.event) {
|
|
|
|
case 'fileexists':
|
|
|
|
scope.process_existing_file(data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-03-29 03:39:08 +00:00
|
|
|
} else {
|
2010-05-21 08:13:08 +00:00
|
|
|
if (data.msg) {
|
|
|
|
scope.print_msg(data.msg, 'info');
|
|
|
|
}
|
2012-03-07 11:25:18 +08:00
|
|
|
// cache result if applicable
|
|
|
|
if (args.action != 'upload' && data.allowcaching) {
|
|
|
|
scope.cached_responses[params] = data;
|
|
|
|
}
|
|
|
|
// invoke callback
|
2010-03-29 03:39:08 +00:00
|
|
|
args.callback(id,data,p);
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
arguments: {
|
|
|
|
scope: scope
|
|
|
|
},
|
|
|
|
headers: {
|
2010-07-06 08:28:26 +00:00
|
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
2010-01-15 07:48:38 +00:00
|
|
|
},
|
2010-07-26 08:37:48 +00:00
|
|
|
data: params,
|
2010-02-03 14:36:53 +00:00
|
|
|
context: this
|
2010-01-15 07:48:38 +00:00
|
|
|
};
|
|
|
|
if (args.form) {
|
|
|
|
cfg.form = args.form;
|
|
|
|
}
|
2012-03-07 11:25:18 +08:00
|
|
|
// check if result of the same request has been already cached. If not, request it
|
|
|
|
// (never applicable in case of form submission and/or upload action):
|
|
|
|
if (!args.form && args.action != 'upload' && scope.cached_responses[params]) {
|
|
|
|
args.callback(null, scope.cached_responses[params], {scope: scope})
|
|
|
|
} else {
|
|
|
|
Y.io(api, cfg);
|
|
|
|
if (redraw) {
|
2012-03-30 10:11:43 +08:00
|
|
|
this.wait();
|
2012-03-07 11:25:18 +08:00
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
|
|
|
},
|
2012-03-30 10:11:43 +08:00
|
|
|
/** displays the dialog and processes rename/overwrite if there is a file with the same name in the same filearea*/
|
2011-05-02 10:11:19 +08:00
|
|
|
process_existing_file: function(data) {
|
|
|
|
var scope = this;
|
2012-03-30 10:11:43 +08:00
|
|
|
var handleOverwrite = function(e) {
|
2011-05-02 10:11:19 +08:00
|
|
|
// overwrite
|
2012-03-30 10:11:43 +08:00
|
|
|
e.preventDefault();
|
|
|
|
var data = this.process_dlg.dialogdata;
|
2011-05-02 10:11:19 +08:00
|
|
|
var params = {}
|
|
|
|
params['existingfilename'] = data.existingfile.filename;
|
|
|
|
params['existingfilepath'] = data.existingfile.filepath;
|
|
|
|
params['newfilename'] = data.newfile.filename;
|
|
|
|
params['newfilepath'] = data.newfile.filepath;
|
2012-03-30 10:11:43 +08:00
|
|
|
this.hide_header();
|
|
|
|
this.request({
|
2011-05-02 10:11:19 +08:00
|
|
|
'params': params,
|
2012-03-30 10:11:43 +08:00
|
|
|
'scope': this,
|
2011-05-02 10:11:19 +08:00
|
|
|
'action':'overwrite',
|
|
|
|
'path': '',
|
2012-03-30 10:11:43 +08:00
|
|
|
'client_id': this.options.client_id,
|
|
|
|
'repository_id': this.active_repo.id,
|
2011-05-02 10:11:19 +08:00
|
|
|
'callback': function(id, o, args) {
|
|
|
|
scope.hide();
|
|
|
|
// editor needs to update url
|
|
|
|
// filemanager do nothing
|
2011-05-03 16:27:31 +08:00
|
|
|
if (scope.options.editor_target && scope.options.env == 'editor') {
|
|
|
|
scope.options.editor_target.value = data.existingfile.url;
|
2011-05-02 10:11:19 +08:00
|
|
|
scope.options.editor_target.onchange();
|
2011-09-21 13:15:23 +07:00
|
|
|
} else if (scope.options.env === 'filepicker') {
|
2012-03-30 10:11:43 +08:00
|
|
|
var fileinfo = {'client_id':scope.options.client_id,
|
2011-09-18 13:57:09 +07:00
|
|
|
'url':data.existingfile.url,
|
|
|
|
'file':data.existingfile.filename};
|
|
|
|
scope.options.formcallback.apply(scope, [fileinfo]);
|
2011-05-02 10:11:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
var handleRename = function(e) {
|
|
|
|
// inserts file with the new name
|
|
|
|
e.preventDefault();
|
|
|
|
var scope = this;
|
|
|
|
var data = this.process_dlg.dialogdata;
|
2011-05-03 16:27:31 +08:00
|
|
|
if (scope.options.editor_target && scope.options.env == 'editor') {
|
|
|
|
scope.options.editor_target.value = data.newfile.url;
|
2011-05-02 10:11:19 +08:00
|
|
|
scope.options.editor_target.onchange();
|
|
|
|
}
|
|
|
|
scope.hide();
|
|
|
|
var formcallback_scope = null;
|
|
|
|
if (scope.options.magicscope) {
|
|
|
|
formcallback_scope = scope.options.magicscope;
|
|
|
|
} else {
|
|
|
|
formcallback_scope = scope;
|
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
var fileinfo = {'client_id':scope.options.client_id,
|
2011-09-18 13:22:35 +07:00
|
|
|
'url':data.newfile.url,
|
|
|
|
'file':data.newfile.filename};
|
|
|
|
scope.options.formcallback.apply(formcallback_scope, [fileinfo]);
|
2011-05-02 10:11:19 +08:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
var handleCancel = function(e) {
|
2011-05-02 10:11:19 +08:00
|
|
|
// Delete tmp file
|
2012-03-30 10:11:43 +08:00
|
|
|
e.preventDefault();
|
2011-05-02 10:11:19 +08:00
|
|
|
var params = {};
|
2012-03-30 10:11:43 +08:00
|
|
|
params['newfilename'] = this.process_dlg.dialogdata.newfile.filename;
|
|
|
|
params['newfilepath'] = this.process_dlg.dialogdata.newfile.filepath;
|
|
|
|
this.request({
|
2011-05-02 10:11:19 +08:00
|
|
|
'params': params,
|
2012-03-30 10:11:43 +08:00
|
|
|
'scope': this,
|
2011-05-02 10:11:19 +08:00
|
|
|
'action':'deletetmpfile',
|
|
|
|
'path': '',
|
2012-03-30 10:11:43 +08:00
|
|
|
'client_id': this.options.client_id,
|
|
|
|
'repository_id': this.active_repo.id,
|
2011-05-02 10:11:19 +08:00
|
|
|
'callback': function(id, o, args) {
|
2012-03-30 10:11:43 +08:00
|
|
|
// let it be in background, from user point of view nothing is happenning
|
2011-05-02 10:11:19 +08:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
}, false);
|
|
|
|
this.process_dlg.hide();
|
|
|
|
this.selectui.hide();
|
2011-05-02 10:11:19 +08:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
if (!this.process_dlg) {
|
|
|
|
var node = Y.Node.create(M.core_filepicker.templates.processexistingfile);
|
|
|
|
this.fpnode.appendChild(node);
|
|
|
|
this.process_dlg = new Y.Panel({
|
|
|
|
srcNode : node,
|
|
|
|
headerContent: M.str.repository.fileexistsdialogheader,
|
|
|
|
zIndex : 800000,
|
|
|
|
centered : true,
|
|
|
|
modal : true,
|
|
|
|
visible : false,
|
|
|
|
render : true,
|
|
|
|
buttons : {}
|
|
|
|
});
|
|
|
|
node.one('.fp-dlg-butoverwrite').on('click', handleOverwrite, this);
|
|
|
|
node.one('.fp-dlg-butrename').on('click', handleRename, this);
|
|
|
|
node.one('.fp-dlg-butcancel').on('click', handleCancel, this);
|
|
|
|
if (this.options.env == 'editor') {
|
|
|
|
node.one('.fp-dlg-text').setContent(M.str.repository.fileexistsdialog_editor);
|
|
|
|
} else {
|
|
|
|
node.one('.fp-dlg-text').setContent(M.str.repository.fileexistsdialog_filemanager);
|
|
|
|
}
|
2011-05-02 10:11:19 +08:00
|
|
|
}
|
2012-04-11 10:05:25 +08:00
|
|
|
this.fpnode.one('.fp-select').removeClass('loading');
|
2012-03-30 10:11:43 +08:00
|
|
|
this.process_dlg.dialogdata = data;
|
|
|
|
this.fpnode.one('.fp-dlg .fp-dlg-butrename').setContent(M.util.get_string('renameto', 'repository', data.newfile.filename));
|
|
|
|
this.process_dlg.show();
|
|
|
|
},
|
|
|
|
/** displays error instead of filepicker contents */
|
|
|
|
display_error: function(errortext, errorcode) {
|
|
|
|
this.fpnode.one('.fp-content').setContent(M.core_filepicker.templates.error);
|
|
|
|
this.fpnode.one('.fp-content .fp-error').
|
|
|
|
addClass(errorcode).
|
|
|
|
setContent(errortext);
|
2011-05-02 10:11:19 +08:00
|
|
|
},
|
2012-03-30 10:11:43 +08:00
|
|
|
/** displays message in a popup */
|
2010-05-21 08:13:08 +00:00
|
|
|
print_msg: function(msg, type) {
|
2012-03-30 10:11:43 +08:00
|
|
|
var header = M.str.moodle.error;
|
|
|
|
if (type != 'error') {
|
|
|
|
type = 'info'; // one of only two types excepted
|
|
|
|
header = M.str.moodle.info;
|
2010-05-21 08:13:08 +00:00
|
|
|
}
|
|
|
|
if (!this.msg_dlg) {
|
2012-03-30 10:11:43 +08:00
|
|
|
var node = Y.Node.create(M.core_filepicker.templates.message);
|
|
|
|
this.fpnode.appendChild(node);
|
|
|
|
|
|
|
|
this.msg_dlg = new Y.Panel({
|
|
|
|
srcNode : node,
|
|
|
|
zIndex : 800000,
|
|
|
|
centered : true,
|
|
|
|
modal : true,
|
|
|
|
visible : false,
|
|
|
|
render : true
|
|
|
|
});
|
|
|
|
node.one('.fp-msg-butok').on('click', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.msg_dlg.hide();
|
|
|
|
}, this);
|
2010-05-21 08:13:08 +00:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
|
|
|
|
this.msg_dlg.set('headerContent', header);
|
|
|
|
this.fpnode.one('.fp-msg').removeClass('fp-msg-info').removeClass('fp-msg-error').addClass('fp-msg-'+type)
|
|
|
|
this.fpnode.one('.fp-msg .fp-msg-text').setContent(msg);
|
2010-05-21 08:13:08 +00:00
|
|
|
this.msg_dlg.show();
|
|
|
|
},
|
2012-04-23 14:41:00 +08:00
|
|
|
view_files: function(appenditems) {
|
2012-04-19 10:40:21 +08:00
|
|
|
this.viewbar_set_enabled(true);
|
|
|
|
this.print_path();
|
2012-05-02 14:59:09 +08:00
|
|
|
/*if ((appenditems == null) && (!this.filelist || !this.filelist.length) && !this.active_repo.hasmorepages) {
|
|
|
|
// TODO do it via classes and adjust for each view mode!
|
|
|
|
// If there are no items and no next page, just display status message and quit
|
|
|
|
this.display_error(M.str.repository.nofilesavailable, 'nofilesavailable');
|
|
|
|
return;
|
|
|
|
}*/
|
2012-04-19 10:40:21 +08:00
|
|
|
if (this.viewmode == 2) {
|
2012-04-23 14:41:00 +08:00
|
|
|
this.view_as_list(appenditems);
|
2012-04-19 10:40:21 +08:00
|
|
|
} else if (this.viewmode == 3) {
|
2012-04-23 14:41:00 +08:00
|
|
|
this.view_as_table(appenditems);
|
2010-01-15 07:48:38 +00:00
|
|
|
} else {
|
2012-04-23 14:41:00 +08:00
|
|
|
this.view_as_icons(appenditems);
|
|
|
|
}
|
|
|
|
// display/hide the link for requesting next page
|
|
|
|
if (!appenditems && this.active_repo.hasmorepages) {
|
|
|
|
if (!this.fpnode.one('.fp-content .fp-nextpage')) {
|
|
|
|
this.fpnode.one('.fp-content').append(M.core_filepicker.templates.nextpage);
|
|
|
|
}
|
|
|
|
this.fpnode.one('.fp-content .fp-nextpage').one('a,button').on('click', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.fpnode.one('.fp-content .fp-nextpage').addClass('loading');
|
|
|
|
this.request_next_page();
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
if (!this.active_repo.hasmorepages && this.fpnode.one('.fp-content .fp-nextpage')) {
|
|
|
|
this.fpnode.one('.fp-content .fp-nextpage').remove();
|
|
|
|
}
|
|
|
|
if (this.fpnode.one('.fp-content .fp-nextpage')) {
|
|
|
|
this.fpnode.one('.fp-content .fp-nextpage').removeClass('loading');
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-04-24 11:09:18 +08:00
|
|
|
this.content_scrolled();
|
|
|
|
},
|
|
|
|
content_scrolled: function(e) {
|
|
|
|
setTimeout(Y.bind(function() {
|
|
|
|
if (this.processingimages) {return;}
|
|
|
|
this.processingimages = true;
|
|
|
|
var scope = this,
|
|
|
|
fpcontent = this.fpnode.one('.fp-content'),
|
|
|
|
fpcontenty = fpcontent.getY(),
|
|
|
|
fpcontentheight = fpcontent.getStylePx('height'),
|
|
|
|
nextpage = fpcontent.one('.fp-nextpage'),
|
|
|
|
is_node_visible = function(node) {
|
|
|
|
var offset = node.getY()-fpcontenty;
|
|
|
|
if (offset <= fpcontentheight && (offset >=0 || offset+node.getStylePx('height')>=0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
// automatically load next page when 'more' link becomes visible
|
|
|
|
if (nextpage && !nextpage.hasClass('loading') && is_node_visible(nextpage)) {
|
|
|
|
nextpage.one('a,button').simulate('click');
|
|
|
|
}
|
|
|
|
// replace src for visible images that need to be lazy-loaded
|
|
|
|
if (scope.lazyloading) {
|
|
|
|
fpcontent.all('img').each( function(node) {
|
|
|
|
if (node.get('id') && scope.lazyloading[node.get('id')] && is_node_visible(node)) {
|
|
|
|
node.set('src', scope.lazyloading[node.get('id')]);
|
|
|
|
delete scope.lazyloading[node.get('id')];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.processingimages = false;
|
|
|
|
}, this), 200)
|
2010-01-15 07:48:38 +00:00
|
|
|
},
|
2010-04-29 06:05:03 +00:00
|
|
|
treeview_dynload: function(node, cb) {
|
2012-04-12 15:16:57 +08:00
|
|
|
var retrieved_children = {};
|
|
|
|
if (node.children) {
|
|
|
|
for (var i in node.children) {
|
|
|
|
retrieved_children[node.children[i].path] = node.children[i];
|
|
|
|
}
|
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
this.request({
|
2010-04-29 06:05:03 +00:00
|
|
|
action:'list',
|
2012-05-02 14:59:09 +08:00
|
|
|
client_id: this.options.client_id,
|
|
|
|
repository_id: this.active_repo.id,
|
2010-04-29 06:05:03 +00:00
|
|
|
path:node.path?node.path:'',
|
|
|
|
page:node.page?args.page:'',
|
2012-05-02 14:59:09 +08:00
|
|
|
scope:this,
|
2010-04-29 06:05:03 +00:00
|
|
|
callback: function(id, obj, args) {
|
|
|
|
var list = obj.list;
|
2012-05-02 14:59:09 +08:00
|
|
|
var scope = args.scope;
|
2012-04-12 15:16:57 +08:00
|
|
|
// check that user did not leave the view mode before recieving this response
|
|
|
|
if (!(scope.active_repo.id == obj.repo_id && scope.viewmode == 2 && node && node.getChildrenEl())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cb != null) { // (in manual mode do not update current path)
|
|
|
|
scope.viewbar_set_enabled(true);
|
|
|
|
scope.parse_repository_options(obj);
|
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
node.highlight(false);
|
2012-04-12 15:16:57 +08:00
|
|
|
node.origlist = obj.list?obj.list:null;
|
|
|
|
node.origpath = obj.path?obj.path:null;
|
|
|
|
node.children = [];
|
2010-04-29 06:05:03 +00:00
|
|
|
for(k in list) {
|
2012-04-12 15:16:57 +08:00
|
|
|
if (list[k].children && retrieved_children[list[k].path]) {
|
|
|
|
// if this child is a folder and has already been retrieved
|
|
|
|
node.children[node.children.length] = retrieved_children[list[k].path];
|
|
|
|
} else {
|
2012-05-02 14:59:09 +08:00
|
|
|
// append new file to the list
|
|
|
|
scope.view_as_list([list[k]]);
|
2012-04-12 15:16:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cb == null) {
|
|
|
|
node.refresh();
|
|
|
|
} else {
|
2012-05-02 14:59:09 +08:00
|
|
|
// invoke callback requested by TreeView component
|
2012-04-12 15:16:57 +08:00
|
|
|
cb();
|
2010-04-29 06:05:03 +00:00
|
|
|
}
|
2012-04-24 11:09:18 +08:00
|
|
|
scope.content_scrolled();
|
2010-04-29 06:05:03 +00:00
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
},
|
2012-04-23 14:41:00 +08:00
|
|
|
/** displays list of files in tree (list) view mode. If param appenditems is specified,
|
|
|
|
* appends those items to the end of the list. Otherwise (default behaviour)
|
|
|
|
* clears the contents and displays the items from this.filelist */
|
|
|
|
view_as_list: function(appenditems) {
|
2012-05-02 14:59:09 +08:00
|
|
|
var list = (appenditems != null) ? appenditems : this.filelist;
|
|
|
|
this.viewmode = 2;
|
|
|
|
if (!this.filelist || this.filelist.length==0 && (!this.filepath || !this.filepath.length)) {
|
2012-03-30 10:11:43 +08:00
|
|
|
this.display_error(M.str.repository.nofilesavailable, 'nofilesavailable');
|
2012-03-26 11:19:36 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-05-21 08:13:08 +00:00
|
|
|
|
2012-05-02 14:59:09 +08:00
|
|
|
var element_template = Y.Node.create(M.core_filepicker.templates.listfilename);
|
|
|
|
var options = {
|
|
|
|
viewmode : this.viewmode,
|
|
|
|
appendonly : (appenditems != null),
|
|
|
|
filenode : element_template,
|
|
|
|
callbackcontext : this,
|
|
|
|
callback : function(e, node) {
|
2012-05-03 15:14:59 +08:00
|
|
|
// TODO MDL-32736 e is not an event here but an object with properties 'event' and 'node'
|
2012-05-02 14:59:09 +08:00
|
|
|
if (!node.children) {
|
|
|
|
if (e.node.parent && e.node.parent.origpath) {
|
|
|
|
// set the current path
|
|
|
|
this.filepath = e.node.parent.origpath;
|
|
|
|
this.filelist = e.node.parent.origlist;
|
|
|
|
this.print_path();
|
2012-04-12 15:16:57 +08:00
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
this.select_file(node);
|
|
|
|
} else {
|
|
|
|
// save current path and filelist (in case we want to jump to other viewmode)
|
|
|
|
this.filepath = e.node.origpath;
|
|
|
|
this.filelist = e.node.origlist;
|
|
|
|
this.print_path();
|
|
|
|
this.content_scrolled();
|
2012-04-12 15:16:57 +08:00
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
},
|
2012-05-04 16:09:26 +08:00
|
|
|
classnamecallback : function(node) {
|
|
|
|
return node.children ? 'fp-folder' : '';
|
|
|
|
},
|
2012-05-02 14:59:09 +08:00
|
|
|
dynload : this.active_repo.dynload,
|
|
|
|
filepath : this.filepath,
|
|
|
|
treeview_dynload : this.treeview_dynload
|
|
|
|
};
|
|
|
|
this.fpnode.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
|
2010-01-15 07:48:38 +00:00
|
|
|
},
|
2012-04-23 14:41:00 +08:00
|
|
|
/** displays list of files in icon view mode. If param appenditems is specified,
|
|
|
|
* appends those items to the end of the list. Otherwise (default behaviour)
|
|
|
|
* clears the contents and displays the items from this.filelist */
|
|
|
|
view_as_icons: function(appenditems) {
|
2010-01-15 07:48:38 +00:00
|
|
|
this.viewmode = 1;
|
2012-05-02 14:59:09 +08:00
|
|
|
var list = (appenditems != null) ? appenditems : this.filelist;
|
|
|
|
var element_template = Y.Node.create(M.core_filepicker.templates.iconfilename);
|
|
|
|
if ((appenditems == null) && (!this.filelist || !this.filelist.length)) {
|
|
|
|
this.display_error(M.str.repository.nofilesavailable, 'nofilesavailable');
|
|
|
|
return;
|
2010-05-21 08:13:08 +00:00
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
var options = {
|
|
|
|
viewmode : this.viewmode,
|
|
|
|
appendonly : (appenditems != null),
|
|
|
|
filenode : element_template,
|
|
|
|
callbackcontext : this,
|
|
|
|
callback : function(e, node) {
|
2012-05-03 15:14:59 +08:00
|
|
|
if (e.preventDefault) {e.preventDefault();}
|
2012-05-02 14:59:09 +08:00
|
|
|
if(node.children) {
|
|
|
|
if (this.active_repo.dynload) {
|
|
|
|
this.list({'path':node.path});
|
|
|
|
} else {
|
|
|
|
this.filepath = node.path;
|
|
|
|
this.filelist = node.children;
|
2010-01-15 07:48:38 +00:00
|
|
|
this.view_files();
|
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
} else {
|
|
|
|
this.select_file(node);
|
|
|
|
}
|
2012-05-04 16:09:26 +08:00
|
|
|
},
|
|
|
|
classnamecallback : function(node) {
|
|
|
|
return node.children ? 'fp-folder' : '';
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
};
|
|
|
|
this.fpnode.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
|
2010-01-15 07:48:38 +00:00
|
|
|
},
|
2012-04-23 14:41:00 +08:00
|
|
|
/** displays list of files in table view mode. If param appenditems is specified,
|
|
|
|
* appends those items to the end of the list. Otherwise (default behaviour)
|
|
|
|
* clears the contents and displays the items from this.filelist */
|
|
|
|
view_as_table: function(appenditems) {
|
MDL-14636: Support table view in Filepicker, provide more info about files
- Added table view in Filepicker where for each file we show Name, Last modified, Size and Type. Sortable by column
- Preprocess list of files returned from repositories to include formatted size, dates, type and also add filetype icon
- Make sure that local repositories (coursefiles, filesystem, local, recent, user) return information about file size, datemodified, datecreated, author, license
2012-04-17 14:20:20 +08:00
|
|
|
this.viewmode = 3;
|
2012-05-02 14:59:09 +08:00
|
|
|
var list = (appenditems != null) ? appenditems : this.filelist;
|
|
|
|
if (!appenditems && (!this.filelist || this.filelist.length==0) && !this.active_repo.hasmorepages) {
|
MDL-14636: Support table view in Filepicker, provide more info about files
- Added table view in Filepicker where for each file we show Name, Last modified, Size and Type. Sortable by column
- Preprocess list of files returned from repositories to include formatted size, dates, type and also add filetype icon
- Make sure that local repositories (coursefiles, filesystem, local, recent, user) return information about file size, datemodified, datecreated, author, license
2012-04-17 14:20:20 +08:00
|
|
|
this.display_error(M.str.repository.nofilesavailable, 'nofilesavailable');
|
|
|
|
return;
|
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
var element_template = Y.Node.create(M.core_filepicker.templates.listfilename);
|
|
|
|
var options = {
|
|
|
|
viewmode : this.viewmode,
|
|
|
|
appendonly : (appenditems != null),
|
|
|
|
filenode : element_template,
|
|
|
|
callbackcontext : this,
|
|
|
|
sortable : !this.active_repo.hasmorepages,
|
|
|
|
callback : function(e, node) {
|
2012-05-03 15:14:59 +08:00
|
|
|
if (e.preventDefault) {e.preventDefault();}
|
2012-05-02 14:59:09 +08:00
|
|
|
if (node.children) {
|
2012-04-23 14:41:00 +08:00
|
|
|
if (this.active_repo.dynload) {
|
2012-05-02 14:59:09 +08:00
|
|
|
this.list({'path':node.path});
|
2012-04-23 14:41:00 +08:00
|
|
|
} else {
|
2012-05-02 14:59:09 +08:00
|
|
|
this.filepath = node.path;
|
|
|
|
this.filelist = node.children;
|
2012-04-23 14:41:00 +08:00
|
|
|
this.view_files();
|
MDL-14636: Support table view in Filepicker, provide more info about files
- Added table view in Filepicker where for each file we show Name, Last modified, Size and Type. Sortable by column
- Preprocess list of files returned from repositories to include formatted size, dates, type and also add filetype icon
- Make sure that local repositories (coursefiles, filesystem, local, recent, user) return information about file size, datemodified, datecreated, author, license
2012-04-17 14:20:20 +08:00
|
|
|
}
|
2012-04-23 14:41:00 +08:00
|
|
|
} else {
|
2012-05-02 14:59:09 +08:00
|
|
|
this.select_file(node);
|
MDL-14636: Support table view in Filepicker, provide more info about files
- Added table view in Filepicker where for each file we show Name, Last modified, Size and Type. Sortable by column
- Preprocess list of files returned from repositories to include formatted size, dates, type and also add filetype icon
- Make sure that local repositories (coursefiles, filesystem, local, recent, user) return information about file size, datemodified, datecreated, author, license
2012-04-17 14:20:20 +08:00
|
|
|
}
|
2012-05-04 16:09:26 +08:00
|
|
|
},
|
|
|
|
classnamecallback : function(node) {
|
|
|
|
return node.children ? 'fp-folder' : '';
|
2012-04-23 14:41:00 +08:00
|
|
|
}
|
2012-05-02 14:59:09 +08:00
|
|
|
};
|
|
|
|
this.fpnode.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
|
2012-04-23 14:41:00 +08:00
|
|
|
},
|
|
|
|
/** If more than one page available, requests and displays the files from the next page */
|
|
|
|
request_next_page: function() {
|
|
|
|
if (!this.active_repo.hasmorepages || this.active_repo.nextpagerequested) {
|
|
|
|
// nothing to load
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.active_repo.nextpagerequested = true;
|
|
|
|
var nextpage = this.active_repo.page+1;
|
|
|
|
var args = {page:nextpage, repo_id:this.active_repo.id, path:this.active_repo.path};
|
|
|
|
var action = this.active_repo.issearchresult ? 'search' : 'list';
|
|
|
|
this.request({
|
|
|
|
scope: this,
|
|
|
|
action: action,
|
|
|
|
client_id: this.options.client_id,
|
|
|
|
repository_id: args.repo_id,
|
|
|
|
params: args,
|
|
|
|
callback: function(id, obj, args) {
|
|
|
|
var scope = args.scope;
|
|
|
|
// check that we are still in the same repository and are expecting this page
|
|
|
|
if (scope.active_repo.hasmorepages && obj.list && obj.page &&
|
|
|
|
obj.repo_id == scope.active_repo.id &&
|
|
|
|
obj.page == scope.active_repo.page+1 && obj.path == scope.path) {
|
|
|
|
scope.parse_repository_options(obj, true);
|
|
|
|
scope.view_files(obj.list)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, false);
|
MDL-14636: Support table view in Filepicker, provide more info about files
- Added table view in Filepicker where for each file we show Name, Last modified, Size and Type. Sortable by column
- Preprocess list of files returned from repositories to include formatted size, dates, type and also add filetype icon
- Make sure that local repositories (coursefiles, filesystem, local, recent, user) return information about file size, datemodified, datecreated, author, license
2012-04-17 14:20:20 +08:00
|
|
|
},
|
2010-01-15 07:48:38 +00:00
|
|
|
select_file: function(args) {
|
2012-03-30 10:11:43 +08:00
|
|
|
this.selectui.show();
|
2010-01-15 07:48:38 +00:00
|
|
|
var client_id = this.options.client_id;
|
2012-03-30 10:11:43 +08:00
|
|
|
var selectnode = this.fpnode.one('.fp-select');
|
2012-04-19 10:40:21 +08:00
|
|
|
var return_types = this.options.repositories[this.active_repo.id].return_types;
|
2012-04-11 10:05:25 +08:00
|
|
|
selectnode.removeClass('loading');
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-saveas input').set('value', args.title);
|
|
|
|
selectnode.one('.fp-setauthor input').set('value', this.options.author);
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2012-04-24 11:09:18 +08:00
|
|
|
var imgnode = Y.Node.create('<img/>').
|
|
|
|
set('src', args.realthumbnail ? args.realthumbnail : args.thumbnail).
|
|
|
|
setStyle('maxHeight', ''+(args.thumbnail_height ? args.thumbnail_height : 90)+'px').
|
|
|
|
setStyle('maxWidth', ''+(args.thumbnail_width ? args.thumbnail_width : 90)+'px');
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-thumbnail').setContent('').appendChild(imgnode);
|
2012-03-30 10:11:43 +08:00
|
|
|
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-linkexternal input').set('checked', ''); // default to unchecked
|
|
|
|
if ((this.options.externallink && this.options.env == 'editor' && return_types == 3)) {
|
|
|
|
// support both internal and external links, enable checkbox 'Link external'
|
|
|
|
selectnode.one('.fp-linkexternal input').set('disabled', '');
|
|
|
|
selectnode.all('.fp-linkexternal').removeClass('uneditable')
|
2012-03-30 10:11:43 +08:00
|
|
|
} else {
|
|
|
|
// disable checkbox 'Link external'
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-linkexternal input').set('disabled', 'disabled');
|
|
|
|
selectnode.all('.fp-linkexternal').addClass('uneditable')
|
|
|
|
if (return_types == 1) {
|
2012-03-30 10:11:43 +08:00
|
|
|
// support external links only
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-linkexternal input').set('checked', 'checked');
|
2012-03-30 10:11:43 +08:00
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2010-03-29 03:39:08 +00:00
|
|
|
|
2012-03-30 10:11:43 +08:00
|
|
|
if (args.hasauthor) {
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-setauthor input').set('disabled', 'disabled');
|
|
|
|
selectnode.all('.fp-setauthor').addClass('uneditable')
|
2012-03-30 10:11:43 +08:00
|
|
|
} else {
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-setauthor input').set('disabled', '');
|
|
|
|
selectnode.all('.fp-setauthor').removeClass('uneditable')
|
2010-03-29 03:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!args.haslicense) {
|
|
|
|
// the license of the file
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-setlicense select').set('disabled', '');
|
|
|
|
selectnode.one('.fp-setlicense').removeClass('uneditable');
|
2012-03-30 10:11:43 +08:00
|
|
|
} else {
|
2012-04-19 10:40:21 +08:00
|
|
|
selectnode.one('.fp-setlicense select').set('disabled', 'disabled');
|
|
|
|
selectnode.one('.fp-setlicense').addClass('uneditable');
|
2010-03-29 03:39:08 +00:00
|
|
|
}
|
2012-04-19 10:40:21 +08:00
|
|
|
|
2012-03-30 10:11:43 +08:00
|
|
|
selectnode.one('form #filesource-'+client_id).set('value', args.source);
|
2012-04-19 10:40:21 +08:00
|
|
|
|
|
|
|
// display static information about a file (when known)
|
|
|
|
var attrs = ['datemodified','datecreated','size','license','author','dimensions'];
|
|
|
|
for (var i in attrs) {
|
|
|
|
if (selectnode.one('.fp-'+attrs[i])) {
|
|
|
|
var value = (args[attrs[i]+'_f']) ? args[attrs[i]+'_f'] : (args[attrs[i]] ? args[attrs[i]] : '');
|
|
|
|
selectnode.one('.fp-'+attrs[i]).addClassIf('fp-unknown', ''+value == '')
|
|
|
|
.one('.fp-value').setContent(value);
|
|
|
|
}
|
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
},
|
|
|
|
setup_select_file: function() {
|
|
|
|
var client_id = this.options.client_id;
|
|
|
|
var selectnode = this.fpnode.one('.fp-select');
|
2012-04-19 10:40:21 +08:00
|
|
|
var getfile = selectnode.one('.fp-select-confirm');
|
|
|
|
// bind labels with corresponding inputs
|
|
|
|
selectnode.all('.fp-saveas,.fp-linkexternal,.fp-setauthor,.fp-setlicense').each(function (node) {
|
|
|
|
node.all('label').set('for', node.one('input,select').generateID());
|
|
|
|
});
|
|
|
|
this.populate_licenses_select(selectnode.one('.fp-setlicense select'));
|
|
|
|
// register event on clicking submit button
|
2010-01-15 07:48:38 +00:00
|
|
|
getfile.on('click', function(e) {
|
2012-03-30 10:11:43 +08:00
|
|
|
e.preventDefault();
|
2010-01-15 07:48:38 +00:00
|
|
|
var client_id = this.options.client_id;
|
|
|
|
var scope = this;
|
|
|
|
var repository_id = this.active_repo.id;
|
2012-04-19 10:40:21 +08:00
|
|
|
var title = selectnode.one('.fp-saveas input').get('value');
|
2012-03-30 10:11:43 +08:00
|
|
|
var filesource = selectnode.one('form #filesource-'+client_id).get('value');
|
2010-03-25 07:54:19 +00:00
|
|
|
var params = {'title':title, 'source':filesource, 'savepath': this.options.savepath};
|
2012-04-19 10:40:21 +08:00
|
|
|
var license = selectnode.one('.fp-setlicense select');
|
2010-03-29 03:39:08 +00:00
|
|
|
if (license) {
|
|
|
|
params['license'] = license.get('value');
|
2012-03-30 10:11:43 +08:00
|
|
|
Y.Cookie.set('recentlicense', license.get('value'));
|
2010-03-29 03:39:08 +00:00
|
|
|
}
|
2012-04-19 10:40:21 +08:00
|
|
|
params['author'] = selectnode.one('.fp-setauthor input').get('value');
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2012-03-20 08:56:31 +08:00
|
|
|
if (this.options.externallink && this.options.env == 'editor') {
|
2010-04-12 03:07:40 +00:00
|
|
|
// in editor, images are stored in '/' only
|
|
|
|
params.savepath = '/';
|
2010-07-27 04:06:09 +00:00
|
|
|
// when image or media button is clicked
|
2012-04-19 10:40:21 +08:00
|
|
|
var return_types = this.options.repositories[this.active_repo.id].return_types;
|
|
|
|
if ( return_types != 1 ) {
|
|
|
|
var linkexternal = selectnode.one('.fp-linkexternal input');
|
2012-03-20 08:56:31 +08:00
|
|
|
if (linkexternal && linkexternal.get('checked')) {
|
2010-07-27 04:06:09 +00:00
|
|
|
params['linkexternal'] = 'yes';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// when link button in editor clicked
|
2010-01-15 07:48:38 +00:00
|
|
|
params['linkexternal'] = 'yes';
|
|
|
|
}
|
2010-07-27 04:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.options.env == 'url') {
|
2010-01-15 07:48:38 +00:00
|
|
|
params['linkexternal'] = 'yes';
|
|
|
|
}
|
|
|
|
|
2012-04-11 10:05:25 +08:00
|
|
|
selectnode.addClass('loading');
|
2010-01-15 07:48:38 +00:00
|
|
|
this.request({
|
2010-01-22 03:02:09 +00:00
|
|
|
action:'download',
|
|
|
|
client_id: client_id,
|
|
|
|
repository_id: repository_id,
|
|
|
|
'params': params,
|
2012-03-14 12:24:36 +08:00
|
|
|
onerror: function(id, obj, args) {
|
2012-04-11 10:05:25 +08:00
|
|
|
selectnode.removeClass('loading');
|
2012-03-30 10:11:43 +08:00
|
|
|
scope.selectui.hide();
|
2012-03-14 12:24:36 +08:00
|
|
|
},
|
2010-01-22 03:02:09 +00:00
|
|
|
callback: function(id, obj, args) {
|
2012-04-11 10:05:25 +08:00
|
|
|
selectnode.removeClass('loading');
|
2010-03-08 04:11:32 +00:00
|
|
|
if (scope.options.editor_target && scope.options.env=='editor') {
|
2010-01-22 03:02:09 +00:00
|
|
|
scope.options.editor_target.value=obj.url;
|
|
|
|
scope.options.editor_target.onchange();
|
|
|
|
}
|
|
|
|
scope.hide();
|
|
|
|
obj.client_id = client_id;
|
|
|
|
var formcallback_scope = null;
|
2010-03-02 02:28:11 +00:00
|
|
|
if (args.scope.options.magicscope) {
|
2010-01-22 03:02:09 +00:00
|
|
|
formcallback_scope = args.scope.options.magicscope;
|
|
|
|
} else {
|
|
|
|
formcallback_scope = args.scope;
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2010-01-22 03:02:09 +00:00
|
|
|
scope.options.formcallback.apply(formcallback_scope, [obj]);
|
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
}, false);
|
2010-01-15 07:48:38 +00:00
|
|
|
}, this);
|
2012-03-30 10:11:43 +08:00
|
|
|
var elform = selectnode.one('form');
|
2012-04-11 10:05:25 +08:00
|
|
|
elform.appendChild(Y.Node.create('<input/>').
|
|
|
|
setAttrs({type:'hidden',id:'filesource-'+client_id}));
|
2010-03-08 04:11:32 +00:00
|
|
|
elform.on('keydown', function(e) {
|
|
|
|
if (e.keyCode == 13) {
|
|
|
|
getfile.simulate('click');
|
2010-09-17 19:46:57 +00:00
|
|
|
e.preventDefault();
|
2010-03-08 04:11:32 +00:00
|
|
|
}
|
|
|
|
}, this);
|
2012-04-19 10:40:21 +08:00
|
|
|
var cancel = selectnode.one('.fp-select-cancel');
|
2010-01-15 07:48:38 +00:00
|
|
|
cancel.on('click', function(e) {
|
2012-03-30 10:11:43 +08:00
|
|
|
e.preventDefault();
|
|
|
|
this.selectui.hide();
|
2010-01-15 07:48:38 +00:00
|
|
|
}, this);
|
|
|
|
},
|
2012-03-30 10:11:43 +08:00
|
|
|
wait: function() {
|
|
|
|
this.fpnode.one('.fp-content').setContent(M.core_filepicker.templates.loading);
|
|
|
|
},
|
|
|
|
viewbar_set_enabled: function(mode) {
|
|
|
|
var viewbar = this.fpnode.one('.fp-viewbar')
|
|
|
|
if (viewbar) {
|
|
|
|
if (mode) {
|
|
|
|
viewbar.addClass('enabled').removeClass('disabled')
|
|
|
|
} else {
|
|
|
|
viewbar.removeClass('enabled').addClass('disabled')
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
this.fpnode.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').removeClass('checked')
|
|
|
|
var modes = {1:'icons', 2:'tree', 3:'details'};
|
|
|
|
this.fpnode.all('.fp-vb-'+modes[this.viewmode]).addClass('checked');
|
|
|
|
},
|
|
|
|
viewbar_clicked: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var viewbar = this.fpnode.one('.fp-viewbar')
|
|
|
|
if (!viewbar || !viewbar.hasClass('disabled')) {
|
|
|
|
if (e.currentTarget.hasClass('fp-vb-tree')) {
|
|
|
|
this.viewmode = 2;
|
|
|
|
} else if (e.currentTarget.hasClass('fp-vb-details')) {
|
|
|
|
this.viewmode = 3;
|
|
|
|
} else {
|
|
|
|
this.viewmode = 1;
|
|
|
|
}
|
|
|
|
this.viewbar_set_enabled(true)
|
|
|
|
this.view_files();
|
|
|
|
Y.Cookie.set('recentviewmode', this.viewmode);
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var client_id = this.options.client_id;
|
2012-04-19 10:40:21 +08:00
|
|
|
this.fpnode = Y.Node.create(M.core_filepicker.templates.generallayout).
|
|
|
|
set('id', 'filepicker-'+client_id);
|
|
|
|
var fpselectnode = Y.Node.create(M.core_filepicker.templates.selectlayout);
|
2012-03-30 10:11:43 +08:00
|
|
|
Y.one(document.body).appendChild(this.fpnode);
|
|
|
|
this.mainui = new Y.Panel({
|
|
|
|
srcNode : this.fpnode,
|
|
|
|
headerContent: M.str.repository.filepicker,
|
|
|
|
zIndex : 500000,
|
|
|
|
centered : true,
|
|
|
|
modal : true,
|
|
|
|
visible : false,
|
2012-05-02 15:35:50 +08:00
|
|
|
minWidth : this.fpnode.getStylePx('minWidth'),
|
|
|
|
minHeight : this.fpnode.getStylePx('minHeight'),
|
|
|
|
maxWidth : this.fpnode.getStylePx('maxWidth'),
|
|
|
|
maxHeight : this.fpnode.getStylePx('maxHeight'),
|
2012-04-19 10:40:21 +08:00
|
|
|
render : true
|
2010-01-15 07:48:38 +00:00
|
|
|
});
|
2012-04-19 10:40:21 +08:00
|
|
|
// allow to move the panel dragging it by it's header:
|
|
|
|
this.mainui.plug(Y.Plugin.Drag,{handles:['.yui3-widget-hd']});
|
2012-03-30 10:11:43 +08:00
|
|
|
this.mainui.show();
|
2012-05-04 16:09:26 +08:00
|
|
|
if (this.mainui.get('y')<0) {this.mainui.set('y', 0);}
|
2012-04-19 10:40:21 +08:00
|
|
|
// create panel for selecting a file (initially hidden)
|
2012-05-04 16:09:26 +08:00
|
|
|
this.fpnode.appendChild(fpselectnode);
|
2012-03-30 10:11:43 +08:00
|
|
|
this.selectui = new Y.Panel({
|
|
|
|
srcNode : fpselectnode,
|
|
|
|
zIndex : 600000,
|
|
|
|
centered : true,
|
|
|
|
modal : true,
|
|
|
|
close : true,
|
|
|
|
render : true
|
2010-01-15 07:48:38 +00:00
|
|
|
});
|
2012-03-30 10:11:43 +08:00
|
|
|
this.selectui.hide();
|
2012-04-24 11:09:18 +08:00
|
|
|
// event handler for lazy loading of thumbnails and next page
|
|
|
|
this.fpnode.one('.fp-content').on(['scroll','resize'], this.content_scrolled, this);
|
2012-03-30 10:11:43 +08:00
|
|
|
// save template for one path element and location of path bar
|
|
|
|
if (this.fpnode.one('.fp-path-folder')) {
|
|
|
|
this.pathnode = this.fpnode.one('.fp-path-folder');
|
|
|
|
this.pathbar = this.pathnode.get('parentNode');
|
|
|
|
this.pathbar.removeChild(this.pathnode);
|
|
|
|
}
|
|
|
|
// assign callbacks for view mode switch buttons
|
|
|
|
this.fpnode.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').
|
|
|
|
on('click', this.viewbar_clicked, this);
|
|
|
|
// assign callbacks for toolbar links
|
|
|
|
this.setup_toolbar();
|
|
|
|
this.setup_select_file();
|
2012-04-11 10:05:25 +08:00
|
|
|
this.hide_header();
|
2010-05-03 16:01:45 +00:00
|
|
|
|
2010-01-15 07:48:38 +00:00
|
|
|
// processing repository listing
|
2012-03-30 10:11:43 +08:00
|
|
|
// Resort the repositories by sortorder
|
|
|
|
var sorted_repositories = []
|
|
|
|
for (var i in this.options.repositories) {
|
|
|
|
sorted_repositories[i] = this.options.repositories[i]
|
|
|
|
}
|
|
|
|
sorted_repositories.sort(function(a,b){return a.sortorder-b.sortorder})
|
|
|
|
// extract one repository template and repeat it for all repositories available,
|
|
|
|
// set name and icon and assign callbacks
|
|
|
|
var reponode = this.fpnode.one('.fp-repo');
|
|
|
|
if (reponode) {
|
|
|
|
var list = reponode.get('parentNode');
|
|
|
|
list.removeChild(reponode);
|
|
|
|
for (i in sorted_repositories) {
|
|
|
|
var repository = sorted_repositories[i]
|
|
|
|
var node = reponode.cloneNode(true);
|
|
|
|
list.appendChild(node);
|
|
|
|
node.
|
|
|
|
set('id', 'fp-repo-'+client_id+'-'+repository.id).
|
|
|
|
on('click', function(e, repository_id) {
|
|
|
|
e.preventDefault();
|
|
|
|
Y.Cookie.set('recentrepository', repository_id);
|
|
|
|
this.hide_header();
|
|
|
|
this.list({'repo_id':repository_id});
|
|
|
|
}, this /*handler running scope*/, repository.id/*second argument of handler*/);
|
|
|
|
node.one('.fp-repo-name').setContent(repository.name)
|
|
|
|
node.one('.fp-repo-icon').set('src', repository.icon)
|
|
|
|
if (i==0) {node.addClass('first');}
|
|
|
|
if (i==sorted_repositories.length-1) {node.addClass('last');}
|
|
|
|
if (i%2) {node.addClass('even');} else {node.addClass('odd');}
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
}
|
|
|
|
// display error if no repositories found
|
|
|
|
if (sorted_repositories.length==0) {
|
2012-04-11 10:05:25 +08:00
|
|
|
this.display_error(M.str.repository.norepositoriesavailable, 'norepositoriesavailable')
|
2012-03-30 10:11:43 +08:00
|
|
|
}
|
|
|
|
// display repository that was used last time
|
|
|
|
this.show_recent_repository();
|
2010-01-15 07:48:38 +00:00
|
|
|
},
|
2012-04-23 14:41:00 +08:00
|
|
|
parse_repository_options: function(data, appendtolist) {
|
|
|
|
if (appendtolist) {
|
|
|
|
if (data.list) {
|
|
|
|
if (!this.filelist) { this.filelist = []; }
|
|
|
|
for (var i in data.list) {
|
|
|
|
this.filelist[this.filelist.length] = data.list[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.filelist = data.list?data.list:null;
|
2012-04-24 11:09:18 +08:00
|
|
|
this.lazyloading = {};
|
2012-04-23 14:41:00 +08:00
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
this.filepath = data.path?data.path:null;
|
|
|
|
this.active_repo = {};
|
2012-03-26 11:19:36 +08:00
|
|
|
this.active_repo.issearchresult = data.issearchresult?true:false;
|
2010-03-23 04:08:45 +00:00
|
|
|
this.active_repo.dynload = data.dynload?data.dynload:false;
|
2010-01-15 07:48:38 +00:00
|
|
|
this.active_repo.pages = Number(data.pages?data.pages:null);
|
|
|
|
this.active_repo.page = Number(data.page?data.page:null);
|
2012-04-23 14:41:00 +08:00
|
|
|
this.active_repo.hasmorepages = (this.active_repo.pages && this.active_repo.page && (this.active_repo.page < this.active_repo.pages || this.active_repo.pages == -1))
|
2010-01-15 07:48:38 +00:00
|
|
|
this.active_repo.id = data.repo_id?data.repo_id:null;
|
2012-03-30 10:11:43 +08:00
|
|
|
this.active_repo.nosearch = (data.login || data.nosearch); // this is either login form or 'nosearch' attribute set
|
|
|
|
this.active_repo.norefresh = (data.login || data.norefresh); // this is either login form or 'norefresh' attribute set
|
|
|
|
this.active_repo.nologin = (data.login || data.nologin); // this is either login form or 'nologin' attribute is set
|
2010-08-06 08:49:01 +00:00
|
|
|
this.active_repo.logouttext = data.logouttext?data.logouttext:null;
|
2010-01-15 07:48:38 +00:00
|
|
|
this.active_repo.help = data.help?data.help:null;
|
|
|
|
this.active_repo.manage = data.manage?data.manage:null;
|
2012-03-30 10:11:43 +08:00
|
|
|
this.print_header();
|
2010-01-15 07:48:38 +00:00
|
|
|
},
|
|
|
|
print_login: function(data) {
|
2010-05-11 05:40:14 +00:00
|
|
|
this.parse_repository_options(data);
|
2010-01-15 07:48:38 +00:00
|
|
|
var client_id = this.options.client_id;
|
|
|
|
var repository_id = data.repo_id;
|
|
|
|
var l = this.logindata = data.login;
|
|
|
|
var loginurl = '';
|
2012-04-11 10:05:25 +08:00
|
|
|
var action = data['login_btn_action'] ? data['login_btn_action'] : 'login';
|
2010-01-15 07:48:38 +00:00
|
|
|
var form_id = 'fp-form-'+client_id;
|
|
|
|
|
2012-03-30 14:38:45 +08:00
|
|
|
var loginform_node = Y.Node.create(M.core_filepicker.templates.loginform);
|
|
|
|
loginform_node.one('form').set('id', form_id);
|
|
|
|
this.fpnode.one('.fp-content').setContent('').appendChild(loginform_node);
|
|
|
|
var templates = {
|
|
|
|
'popup' : loginform_node.one('.fp-login-popup'),
|
|
|
|
'textarea' : loginform_node.one('.fp-login-textarea'),
|
|
|
|
'select' : loginform_node.one('.fp-login-select'),
|
|
|
|
'text' : loginform_node.one('.fp-login-text'),
|
2012-04-11 10:05:25 +08:00
|
|
|
'radio' : loginform_node.one('.fp-login-radiogroup'),
|
2012-03-30 14:38:45 +08:00
|
|
|
'checkbox' : loginform_node.one('.fp-login-checkbox'),
|
|
|
|
'input' : loginform_node.one('.fp-login-input')
|
|
|
|
};
|
|
|
|
var container;
|
|
|
|
for (var i in templates) {
|
|
|
|
if (templates[i]) {
|
|
|
|
container = templates[i].get('parentNode');
|
|
|
|
container.removeChild(templates[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var k in l) {
|
|
|
|
if (templates[l[k].type]) {
|
|
|
|
var node = templates[l[k].type].cloneNode(true);
|
|
|
|
} else {
|
|
|
|
node = templates['input'].cloneNode(true);
|
|
|
|
}
|
|
|
|
if (l[k].type == 'popup') {
|
2012-04-11 10:05:25 +08:00
|
|
|
// submit button
|
2012-04-12 15:16:57 +08:00
|
|
|
loginurl = l[k].url;
|
2012-04-11 10:05:25 +08:00
|
|
|
var popupbutton = node.one('button');
|
|
|
|
popupbutton.on('click', function(e){
|
|
|
|
M.core_filepicker.active_filepicker = this;
|
|
|
|
window.open(loginurl, 'repo_auth', 'location=0,status=0,width=500,height=300,scrollbars=yes');
|
|
|
|
e.preventDefault();
|
|
|
|
}, this);
|
|
|
|
loginform_node.one('form').on('keydown', function(e) {
|
|
|
|
if (e.keyCode == 13) {
|
|
|
|
popupbutton.simulate('click');
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}, this);
|
2012-03-30 14:38:45 +08:00
|
|
|
loginform_node.all('.fp-login-submit').remove();
|
|
|
|
action = 'popup';
|
|
|
|
}else if(l[k].type=='textarea') {
|
|
|
|
// textarea element
|
|
|
|
if (node.one('label')) { node.one('label').set('for', l[k].id).setContent(l[k].label) }
|
2012-04-11 10:05:25 +08:00
|
|
|
node.one('textarea').setAttrs({id:l[k].id, name:l[k].name});
|
2012-03-30 14:38:45 +08:00
|
|
|
}else if(l[k].type=='select') {
|
|
|
|
// select element
|
|
|
|
if (node.one('label')) { node.one('label').set('for', l[k].id).setContent(l[k].label) }
|
2012-04-11 10:05:25 +08:00
|
|
|
node.one('select').setAttrs({id:l[k].id, name:l[k].name}).setContent('');
|
2012-03-30 14:38:45 +08:00
|
|
|
for (i in l[k].options) {
|
|
|
|
node.one('select').appendChild(
|
|
|
|
Y.Node.create('<option/>').
|
|
|
|
set('value', l[k].options[i].value).
|
|
|
|
setContent(l[k].options[i].label))
|
|
|
|
}
|
|
|
|
}else if(l[k].type=='radio') {
|
|
|
|
// radio input element
|
2012-04-11 10:05:25 +08:00
|
|
|
node.all('label').setContent(l[k].label);
|
|
|
|
var list = l[k].value.split('|');
|
|
|
|
var labels = l[k].value_label.split('|');
|
|
|
|
var radionode = null;
|
|
|
|
for(var item in list) {
|
|
|
|
if (radionode == null) {
|
|
|
|
radionode = node.one('.fp-login-radio');
|
|
|
|
radionode.one('input').set('checked', 'checked');
|
|
|
|
} else {
|
|
|
|
var x = radionode.cloneNode(true);
|
|
|
|
radionode.insert(x, 'after');
|
|
|
|
radionode = x;
|
|
|
|
radionode.one('input').set('checked', '');
|
|
|
|
}
|
|
|
|
radionode.one('input').setAttrs({id:''+l[k].id+item, name:l[k].name,
|
|
|
|
type:l[k].type, value:list[item]});
|
|
|
|
radionode.all('label').setContent(labels[item]).set('for', ''+l[k].id+item)
|
|
|
|
}
|
|
|
|
if (radionode == null) {
|
|
|
|
node.one('.fp-login-radio').remove();
|
|
|
|
}
|
2012-03-30 14:38:45 +08:00
|
|
|
}else {
|
|
|
|
// input element
|
|
|
|
if (node.one('label')) { node.one('label').set('for', l[k].id).setContent(l[k].label) }
|
|
|
|
node.one('input').
|
|
|
|
set('type', l[k].type).
|
|
|
|
set('id', l[k].id).
|
|
|
|
set('name', l[k].name).
|
|
|
|
set('value', l[k].value?l[k].value:'')
|
|
|
|
}
|
|
|
|
container.appendChild(node);
|
|
|
|
}
|
2012-04-11 10:05:25 +08:00
|
|
|
// custom label text for submit button
|
|
|
|
if (data['login_btn_label']) {
|
|
|
|
loginform_node.all('.fp-login-submit').setContent(data['login_btn_label'])
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-04-11 10:05:25 +08:00
|
|
|
// register button action for login and search
|
|
|
|
if (action == 'login' || action == 'search') {
|
|
|
|
loginform_node.one('.fp-login-submit').on('click', function(e){
|
2012-03-30 14:38:45 +08:00
|
|
|
e.preventDefault();
|
2012-03-30 10:11:43 +08:00
|
|
|
this.hide_header();
|
2010-01-15 07:48:38 +00:00
|
|
|
this.request({
|
2012-04-11 10:05:25 +08:00
|
|
|
'scope': this,
|
|
|
|
'action':(action == 'search') ? 'search' : 'signin',
|
2010-01-15 07:48:38 +00:00
|
|
|
'path': '',
|
|
|
|
'client_id': client_id,
|
|
|
|
'repository_id': repository_id,
|
2012-04-11 10:05:25 +08:00
|
|
|
'form': {id:form_id, upload:false, useDisabled:true},
|
2012-03-26 11:19:36 +08:00
|
|
|
'callback': this.display_response
|
2010-01-15 07:48:38 +00:00
|
|
|
}, true);
|
|
|
|
}, this);
|
|
|
|
}
|
2012-04-11 10:05:25 +08:00
|
|
|
// if 'Enter' is pressed in the form, simulate the button click
|
|
|
|
if (loginform_node.one('.fp-login-submit')) {
|
|
|
|
loginform_node.one('form').on('keydown', function(e) {
|
|
|
|
if (e.keyCode == 13) {
|
|
|
|
loginform_node.one('.fp-login-submit').simulate('click')
|
|
|
|
e.preventDefault();
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
},
|
2012-03-26 11:19:36 +08:00
|
|
|
display_response: function(id, obj, args) {
|
|
|
|
var scope = args.scope
|
|
|
|
// highlight the current repository in repositories list
|
2012-03-30 10:11:43 +08:00
|
|
|
scope.fpnode.all('.fp-repo.active').removeClass('active');
|
|
|
|
scope.fpnode.all('#fp-repo-'+scope.options.client_id+'-'+obj.repo_id).addClass('active')
|
2012-03-30 14:38:45 +08:00
|
|
|
// add class repository_REPTYPE to the filepicker (for repository-specific styles)
|
|
|
|
for (var i in scope.options.repositories) {
|
|
|
|
scope.fpnode.removeClass('repository_'+scope.options.repositories[i].type)
|
|
|
|
}
|
|
|
|
if (obj.repo_id && scope.options.repositories[obj.repo_id]) {
|
|
|
|
scope.fpnode.addClass('repository_'+scope.options.repositories[obj.repo_id].type)
|
|
|
|
}
|
2012-03-26 11:19:36 +08:00
|
|
|
// display response
|
|
|
|
if (obj.login) {
|
2012-03-30 10:11:43 +08:00
|
|
|
scope.viewbar_set_enabled(false);
|
2012-03-26 11:19:36 +08:00
|
|
|
scope.print_login(obj);
|
|
|
|
} else if (obj.upload) {
|
2012-03-30 10:11:43 +08:00
|
|
|
scope.viewbar_set_enabled(false);
|
2012-03-26 11:19:36 +08:00
|
|
|
scope.parse_repository_options(obj);
|
|
|
|
scope.create_upload_form(obj);
|
|
|
|
} else if (obj.iframe) {
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2012-03-26 11:19:36 +08:00
|
|
|
} else if (obj.list) {
|
2012-03-30 10:11:43 +08:00
|
|
|
scope.viewbar_set_enabled(true);
|
2012-03-26 11:19:36 +08:00
|
|
|
scope.parse_repository_options(obj);
|
|
|
|
scope.view_files();
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
list: function(args) {
|
|
|
|
if (!args) {
|
|
|
|
args = {};
|
|
|
|
}
|
|
|
|
if (!args.repo_id) {
|
2012-03-26 11:19:36 +08:00
|
|
|
args.repo_id = this.active_repo.id;
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-03-26 11:19:36 +08:00
|
|
|
this.request({
|
|
|
|
action: 'list',
|
|
|
|
client_id: this.options.client_id,
|
2010-01-15 07:48:38 +00:00
|
|
|
repository_id: args.repo_id,
|
2012-03-26 11:19:36 +08:00
|
|
|
path: args.path,
|
|
|
|
page: args.page,
|
|
|
|
scope: this,
|
|
|
|
callback: this.display_response
|
2010-01-15 07:48:38 +00:00
|
|
|
}, true);
|
|
|
|
},
|
2012-03-30 10:11:43 +08:00
|
|
|
populate_licenses_select: function(node) {
|
|
|
|
if (!node) {
|
|
|
|
return;
|
2010-07-05 07:27:49 +00:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
node.setContent('');
|
2010-03-29 03:39:08 +00:00
|
|
|
var licenses = this.options.licenses;
|
2012-03-30 10:11:43 +08:00
|
|
|
var recentlicense = Y.Cookie.get('recentlicense');
|
2010-05-26 09:43:46 +00:00
|
|
|
if (recentlicense) {
|
|
|
|
this.options.defaultlicense=recentlicense;
|
|
|
|
}
|
2010-03-29 03:39:08 +00:00
|
|
|
for (var i in licenses) {
|
2012-03-30 10:11:43 +08:00
|
|
|
var option = Y.Node.create('<option/>').
|
|
|
|
set('selected', (this.options.defaultlicense==licenses[i].shortname)).
|
|
|
|
set('value', licenses[i].shortname).
|
|
|
|
setContent(licenses[i].fullname);
|
|
|
|
node.appendChild(option)
|
2010-03-29 03:39:08 +00:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
},
|
|
|
|
create_upload_form: function(data) {
|
|
|
|
var client_id = this.options.client_id;
|
|
|
|
var id = data.upload.id+'_'+client_id;
|
2012-04-19 10:40:21 +08:00
|
|
|
var content = this.fpnode.one('.fp-content');
|
|
|
|
content.setContent(M.core_filepicker.templates.uploadform);
|
2012-03-30 10:11:43 +08:00
|
|
|
|
2012-04-19 10:40:21 +08:00
|
|
|
content.all('.fp-file,.fp-saveas,.fp-setauthor,.fp-setlicense').each(function (node) {
|
|
|
|
node.all('label').set('for', node.one('input,select').generateID());
|
|
|
|
});
|
|
|
|
content.one('form').set('id', id);
|
|
|
|
content.one('.fp-file input').set('name', 'repo_upload_file');
|
|
|
|
content.one('.fp-saveas input').set('name', 'title');
|
|
|
|
content.one('.fp-setauthor input').setAttrs({name:'author', value:this.options.author});
|
|
|
|
content.one('.fp-setlicense select').set('name', 'license');
|
|
|
|
this.populate_licenses_select(content.one('.fp-setlicense select'))
|
|
|
|
// append hidden inputs to the upload form
|
|
|
|
content.one('form').appendChild(Y.Node.create('<input/>').
|
2012-04-11 10:05:25 +08:00
|
|
|
setAttrs({type:'hidden',name:'itemid',value:this.options.itemid}));
|
2012-03-30 10:11:43 +08:00
|
|
|
var types = this.options.accepted_types;
|
|
|
|
for (var i in types) {
|
2012-04-19 10:40:21 +08:00
|
|
|
content.one('form').appendChild(Y.Node.create('<input/>').
|
2012-04-11 10:05:25 +08:00
|
|
|
setAttrs({type:'hidden',name:'accepted_types[]',value:types[i]}));
|
2012-03-30 10:11:43 +08:00
|
|
|
}
|
|
|
|
|
2010-01-15 07:48:38 +00:00
|
|
|
var scope = this;
|
2012-04-19 10:40:21 +08:00
|
|
|
content.one('.fp-upload-btn').on('click', function(e) {
|
2010-09-17 19:46:57 +00:00
|
|
|
e.preventDefault();
|
2012-04-19 10:40:21 +08:00
|
|
|
var license = content.one('.fp-setlicense select');
|
2012-03-30 10:11:43 +08:00
|
|
|
Y.Cookie.set('recentlicense', license.get('value'));
|
2012-04-19 10:40:21 +08:00
|
|
|
if (!content.one('.fp-file input').get('value')) {
|
2010-07-24 15:05:08 +00:00
|
|
|
scope.print_msg(M.str.repository.nofilesattached, 'error');
|
2010-07-24 14:49:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
this.hide_header();
|
2011-08-24 15:00:10 +02:00
|
|
|
scope.request({
|
|
|
|
scope: scope,
|
|
|
|
action:'upload',
|
|
|
|
client_id: client_id,
|
|
|
|
params: {'savepath':scope.options.savepath},
|
|
|
|
repository_id: scope.active_repo.id,
|
|
|
|
form: {id: id, upload:true},
|
2012-03-14 12:24:36 +08:00
|
|
|
onerror: function(id, o, args) {
|
|
|
|
scope.create_upload_form(data);
|
|
|
|
},
|
2011-08-24 15:00:10 +02:00
|
|
|
callback: function(id, o, args) {
|
|
|
|
if (scope.options.editor_target&&scope.options.env=='editor') {
|
|
|
|
scope.options.editor_target.value=o.url;
|
|
|
|
scope.options.editor_target.onchange();
|
2010-01-18 05:28:42 +00:00
|
|
|
}
|
2011-08-24 15:00:10 +02:00
|
|
|
scope.hide();
|
|
|
|
o.client_id = client_id;
|
|
|
|
var formcallback_scope = null;
|
|
|
|
if (args.scope.options.magicscope) {
|
|
|
|
formcallback_scope = args.scope.options.magicscope;
|
|
|
|
} else {
|
|
|
|
formcallback_scope = args.scope;
|
|
|
|
}
|
|
|
|
scope.options.formcallback.apply(formcallback_scope, [o]);
|
|
|
|
}
|
|
|
|
}, true);
|
2010-01-15 07:48:38 +00:00
|
|
|
}, this);
|
|
|
|
},
|
2012-03-30 10:11:43 +08:00
|
|
|
/** setting handlers and labels for elements in toolbar. Called once during the initial render of filepicker */
|
|
|
|
setup_toolbar: function() {
|
2010-01-15 07:48:38 +00:00
|
|
|
var client_id = this.options.client_id;
|
2012-04-19 10:40:21 +08:00
|
|
|
var toolbar = this.fpnode.one('.fp-toolbar');
|
|
|
|
toolbar.one('.fp-tb-logout').one('a,button').on('click', function(e) {
|
2012-03-30 10:11:43 +08:00
|
|
|
e.preventDefault();
|
|
|
|
if (!this.active_repo.nologin) {
|
|
|
|
this.hide_header();
|
|
|
|
this.request({
|
|
|
|
action:'logout',
|
|
|
|
client_id: this.options.client_id,
|
|
|
|
repository_id: this.active_repo.id,
|
|
|
|
path:'',
|
|
|
|
callback: this.display_response
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
}, this);
|
2012-04-19 10:40:21 +08:00
|
|
|
toolbar.one('.fp-tb-refresh').one('a,button').on('click', function(e) {
|
2012-03-30 10:11:43 +08:00
|
|
|
e.preventDefault();
|
|
|
|
if (!this.active_repo.norefresh) {
|
|
|
|
this.list();
|
|
|
|
}
|
|
|
|
}, this);
|
2012-04-19 10:40:21 +08:00
|
|
|
toolbar.one('.fp-tb-search form').
|
2012-03-30 10:11:43 +08:00
|
|
|
set('method', 'POST').
|
2012-04-19 10:40:21 +08:00
|
|
|
set('id', 'fp-tb-search-'+client_id).
|
2012-03-30 10:11:43 +08:00
|
|
|
on('submit', function(e) {
|
2012-03-26 11:19:36 +08:00
|
|
|
e.preventDefault();
|
2012-03-30 10:11:43 +08:00
|
|
|
if (!this.active_repo.nosearch) {
|
|
|
|
this.request({
|
|
|
|
scope: this,
|
|
|
|
action:'search',
|
|
|
|
client_id: this.options.client_id,
|
|
|
|
repository_id: this.active_repo.id,
|
|
|
|
form: {id: 'fp-tb-search-'+client_id, upload:false, useDisabled:true},
|
|
|
|
callback: this.display_response
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
}, this);
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2012-04-19 10:40:21 +08:00
|
|
|
// it does not matter what kind of element is .fp-tb-manage, we create a dummy <a>
|
2012-03-30 10:11:43 +08:00
|
|
|
// element and use it to open url on click event
|
2012-04-11 10:05:25 +08:00
|
|
|
var managelnk = Y.Node.create('<a/>').
|
|
|
|
setAttrs({id:'fp-tb-manage-'+client_id+'-link', target:'_blank'}).
|
|
|
|
setStyle('display', 'none');
|
2012-04-19 10:40:21 +08:00
|
|
|
toolbar.append(managelnk);
|
|
|
|
toolbar.one('.fp-tb-manage').one('a,button').
|
|
|
|
on('click', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
managelnk.simulate('click')
|
|
|
|
});
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2012-04-19 10:40:21 +08:00
|
|
|
// same with .fp-tb-help
|
2012-04-11 10:05:25 +08:00
|
|
|
var helplnk = Y.Node.create('<a/>').
|
|
|
|
setAttrs({id:'fp-tb-help-'+client_id+'-link', target:'_blank'}).
|
|
|
|
setStyle('display', 'none');
|
2012-04-19 10:40:21 +08:00
|
|
|
toolbar.append(helplnk);
|
|
|
|
toolbar.one('.fp-tb-manage').one('a,button').
|
|
|
|
on('click', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
helplnk.simulate('click')
|
|
|
|
});
|
2012-03-30 10:11:43 +08:00
|
|
|
},
|
|
|
|
hide_header: function() {
|
2012-04-19 10:40:21 +08:00
|
|
|
if (this.fpnode.one('.fp-toolbar')) {
|
|
|
|
this.fpnode.one('.fp-toolbar').addClass('empty');
|
2012-03-30 10:11:43 +08:00
|
|
|
}
|
2012-04-11 10:05:25 +08:00
|
|
|
if (this.pathbar) {
|
|
|
|
this.pathbar.setContent('').addClass('empty');
|
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
},
|
|
|
|
print_header: function() {
|
|
|
|
var r = this.active_repo;
|
|
|
|
var scope = this;
|
|
|
|
var client_id = this.options.client_id;
|
2012-04-12 15:16:57 +08:00
|
|
|
this.hide_header();
|
2012-04-19 10:40:21 +08:00
|
|
|
this.print_path();
|
|
|
|
var toolbar = this.fpnode.one('.fp-toolbar');
|
|
|
|
if (!toolbar) { return; }
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2012-04-19 10:40:21 +08:00
|
|
|
var enable_tb_control = function(node, enabled) {
|
|
|
|
if (!node) { return; }
|
|
|
|
node.addClassIf('disabled', !enabled).addClassIf('enabled', enabled)
|
|
|
|
if (enabled) {
|
|
|
|
toolbar.removeClass('empty');
|
2012-03-30 10:11:43 +08:00
|
|
|
}
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2012-03-30 10:11:43 +08:00
|
|
|
// TODO 'back' permanently disabled for now. Note, flickr_public uses 'Logout' for it!
|
2012-04-19 10:40:21 +08:00
|
|
|
enable_tb_control(toolbar.one('.fp-tb-back'), false);
|
2010-01-15 07:48:38 +00:00
|
|
|
|
2012-03-30 10:11:43 +08:00
|
|
|
// search form
|
2012-04-19 10:40:21 +08:00
|
|
|
enable_tb_control(toolbar.one('.fp-tb-search'), !r.nosearch);
|
2012-03-30 10:11:43 +08:00
|
|
|
if(!r.nosearch) {
|
2012-04-19 10:40:21 +08:00
|
|
|
var searchform = toolbar.one('.fp-tb-search form');
|
|
|
|
searchform.setContent('');
|
2012-03-30 10:11:43 +08:00
|
|
|
this.request({
|
|
|
|
scope: this,
|
|
|
|
action:'searchform',
|
|
|
|
repository_id: this.active_repo.id,
|
|
|
|
callback: function(id, obj, args) {
|
|
|
|
if (obj.repo_id == scope.active_repo.id && obj.form) {
|
|
|
|
// if we did not jump to another repository meanwhile
|
2012-04-19 10:40:21 +08:00
|
|
|
searchform.setContent(obj.form);
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
}
|
|
|
|
}, false);
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
|
|
|
|
// refresh button
|
2010-01-15 07:48:38 +00:00
|
|
|
// weather we use cache for this instance, this button will reload listing anyway
|
2012-04-19 10:40:21 +08:00
|
|
|
enable_tb_control(toolbar.one('.fp-tb-refresh'), !r.norefresh);
|
2012-03-30 10:11:43 +08:00
|
|
|
|
|
|
|
// login button
|
2012-04-19 10:40:21 +08:00
|
|
|
enable_tb_control(toolbar.one('.fp-tb-logout'), !r.nologin);
|
2010-01-15 07:48:38 +00:00
|
|
|
if(!r.nologin) {
|
2010-08-06 08:49:01 +00:00
|
|
|
var label = r.logouttext?r.logouttext:M.str.repository.logout;
|
2012-04-19 10:40:21 +08:00
|
|
|
toolbar.one('.fp-tb-logout').one('a,button').setContent(label)
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 10:11:43 +08:00
|
|
|
// manage url
|
2012-04-19 10:40:21 +08:00
|
|
|
enable_tb_control(toolbar.one('.fp-tb-manage'), r.manage);
|
2012-03-30 10:11:43 +08:00
|
|
|
Y.one('#fp-tb-manage-'+client_id+'-link').set('href', r.manage);
|
|
|
|
|
|
|
|
// help url
|
2012-04-19 10:40:21 +08:00
|
|
|
enable_tb_control(toolbar.one('.fp-tb-help'), r.help);
|
2012-03-30 10:11:43 +08:00
|
|
|
Y.one('#fp-tb-help-'+client_id+'-link').set('href', r.help);
|
2010-01-15 07:48:38 +00:00
|
|
|
},
|
|
|
|
print_path: function() {
|
2012-03-30 10:11:43 +08:00
|
|
|
if (!this.pathbar) { return; }
|
2012-04-11 10:05:25 +08:00
|
|
|
this.pathbar.setContent('').addClass('empty');
|
2010-01-15 07:48:38 +00:00
|
|
|
var p = this.filepath;
|
2012-04-12 15:16:57 +08:00
|
|
|
if (p && p.length!=0 && this.viewmode != 2) {
|
2010-01-15 07:48:38 +00:00
|
|
|
for(var i = 0; i < p.length; i++) {
|
2012-03-30 10:11:43 +08:00
|
|
|
var el = this.pathnode.cloneNode(true);
|
|
|
|
this.pathbar.appendChild(el);
|
|
|
|
if (i == 0) {el.addClass('first');}
|
|
|
|
if (i == p.length-1) {el.addClass('last');}
|
|
|
|
if (i%2) {el.addClass('even');} else {el.addClass('odd');}
|
|
|
|
el.all('.fp-path-folder-name').setContent(p[i].name);
|
|
|
|
el.on('click',
|
|
|
|
function(e, path) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.list({'path':path});
|
|
|
|
},
|
|
|
|
this, p[i].path);
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
2012-03-30 10:11:43 +08:00
|
|
|
this.pathbar.removeClass('empty');
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
hide: function() {
|
2012-03-30 10:11:43 +08:00
|
|
|
this.selectui.hide();
|
|
|
|
if (this.process_dlg) {
|
|
|
|
this.process_dlg.hide();
|
|
|
|
}
|
|
|
|
if (this.msg_dlg) {
|
|
|
|
this.msg_dlg.hide();
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
this.mainui.hide();
|
|
|
|
},
|
|
|
|
show: function() {
|
2012-03-30 10:11:43 +08:00
|
|
|
if (this.fpnode) {
|
|
|
|
this.hide();
|
2010-01-15 07:48:38 +00:00
|
|
|
this.mainui.show();
|
2010-05-26 09:43:46 +00:00
|
|
|
this.show_recent_repository();
|
2010-01-15 07:48:38 +00:00
|
|
|
} else {
|
|
|
|
this.launch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
launch: function() {
|
2010-01-21 22:04:31 +00:00
|
|
|
this.render();
|
2010-05-26 09:43:46 +00:00
|
|
|
},
|
|
|
|
show_recent_repository: function() {
|
2012-03-30 10:11:43 +08:00
|
|
|
this.hide_header();
|
|
|
|
this.viewbar_set_enabled(false);
|
|
|
|
var repository_id = Y.Cookie.get('recentrepository');
|
|
|
|
this.viewmode = Y.Cookie.get('recentviewmode', Number);
|
MDL-14636: Support table view in Filepicker, provide more info about files
- Added table view in Filepicker where for each file we show Name, Last modified, Size and Type. Sortable by column
- Preprocess list of files returned from repositories to include formatted size, dates, type and also add filetype icon
- Make sure that local repositories (coursefiles, filesystem, local, recent, user) return information about file size, datemodified, datecreated, author, license
2012-04-17 14:20:20 +08:00
|
|
|
if (this.viewmode != 2 && this.viewmode != 3) {
|
2012-03-30 10:11:43 +08:00
|
|
|
this.viewmode = 1;
|
|
|
|
}
|
2010-05-26 09:43:46 +00:00
|
|
|
if (this.options.repositories[repository_id]) {
|
|
|
|
this.list({'repo_id':repository_id});
|
|
|
|
}
|
2010-01-15 07:48:38 +00:00
|
|
|
}
|
|
|
|
});
|
2010-05-24 07:55:57 +00:00
|
|
|
var loading = Y.one('#filepicker-loading-'+options.client_id);
|
|
|
|
if (loading) {
|
|
|
|
loading.setStyle('display', 'none');
|
|
|
|
}
|
2010-02-03 14:36:53 +00:00
|
|
|
M.core_filepicker.instances[options.client_id] = new FilePickerHelper(options);
|
|
|
|
};
|