"MDL-21170, apply maxfiles limit to filemanager"
This commit is contained in:
@@ -155,18 +155,18 @@ case 'downloaddir':
|
||||
$zipper = new zip_packer();
|
||||
$fs = get_file_storage();
|
||||
|
||||
$file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, '.');
|
||||
if ($file->get_parent_directory()) {
|
||||
$parent_path = $file->get_parent_directory()->get_filepath();
|
||||
$filename = trim($filepath, '/').'.zip';
|
||||
} else {
|
||||
$stored_file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, '.');
|
||||
if ($filepath === '/') {
|
||||
$parent_path = '/';
|
||||
$filename = get_string('files').'.zip';
|
||||
} else {
|
||||
$parent_path = $stored_file->get_parent_directory()->get_filepath();
|
||||
$filename = trim($filepath, '/').'.zip';
|
||||
}
|
||||
|
||||
// archive compressed file to an unused draft area
|
||||
$newdraftitemid = file_get_unused_draft_itemid();
|
||||
if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user_draft', $newdraftitemid, '/', $filename, $USER->id)) {
|
||||
if ($newfile = $zipper->archive_to_storage(array($stored_file), $user_context->id, 'user_draft', $newdraftitemid, '/', $filename, $USER->id)) {
|
||||
$return = new stdclass;
|
||||
$return->fileurl = $CFG->wwwroot . '/draftfile.php/' . $user_context->id .'/user_draft/'.$newdraftitemid.'/'.$filename;
|
||||
$return->filepath = $parent_path;
|
||||
|
||||
+42
-28
@@ -23,14 +23,17 @@
|
||||
* this.mkdir_dialog
|
||||
* this.rename_dialog
|
||||
* this.client_id
|
||||
* this.filecount, how many files in this filemanager
|
||||
* this.maxfiles
|
||||
* this.maxbytes
|
||||
*
|
||||
* FileManager options:
|
||||
* =====
|
||||
* this.options.currentpath
|
||||
* this.options.itemid
|
||||
*/
|
||||
var filemanagers = {};
|
||||
var fm_filepickers = {};
|
||||
M.filemanagers = M.filemanagers||{};
|
||||
M.fm_filepickers = M.fm_filepickers || {};
|
||||
|
||||
M.core_filemanager = (function(){
|
||||
function core_filemanager (args) {
|
||||
@@ -49,9 +52,16 @@ M.core_filemanager = (function(){
|
||||
this.currentpath = '/';
|
||||
this.filepicker_options = args.filepicker;
|
||||
this.client_id = '';
|
||||
this.maxfiles = args.maxfiles;
|
||||
this.maxbytes = args.maxbytes;
|
||||
if (args.client_id) {
|
||||
this.client_id = args.client_id;
|
||||
}
|
||||
if (args.filecount) {
|
||||
this.filecount = args.filecount;
|
||||
} else {
|
||||
this.filecount = 0;
|
||||
}
|
||||
this.setup_buttons();
|
||||
this.render();
|
||||
},
|
||||
@@ -98,7 +108,11 @@ M.core_filemanager = (function(){
|
||||
Y.io(api, cfg);
|
||||
},
|
||||
filepicker_callback: function(obj) {
|
||||
//console.warn(obj);
|
||||
var button_addfile = Y.one("#btnadd-"+this.client_id);
|
||||
this.filecount++;
|
||||
if (this.filecount >= this.maxfiles && this.maxfiles!=-1) {
|
||||
button_addfile.setStyle('display', 'none');
|
||||
}
|
||||
this.refresh(this.currentpath);
|
||||
},
|
||||
refresh: function(filepath) {
|
||||
@@ -123,34 +137,29 @@ M.core_filemanager = (function(){
|
||||
var button_download = Y.one("#btndwn-"+client_id);
|
||||
var button_create = Y.one("#btncrt-"+client_id);
|
||||
var button_addfile = Y.one("#btnadd-"+client_id);
|
||||
button_addfile.on('click', function(e) {
|
||||
var options = this.filepicker_options;
|
||||
var scope = this;
|
||||
var client_id = this.client_id;
|
||||
Y.use('core_filepicker', function (Y) {
|
||||
options.formcallback = scope.filepicker_callback;
|
||||
// XXX: magic here, to let filepicker use filemanager scope
|
||||
options.magicscope = scope;
|
||||
options.savepath = scope.currentpath;
|
||||
if (!fm_filepickers[client_id]) {
|
||||
fm_filepickers[client_id] = new M.core_filepicker(options);
|
||||
}
|
||||
fm_filepickers[client_id].show();
|
||||
});
|
||||
}, this);
|
||||
|
||||
// setup 'add file' button
|
||||
// if maxfiles == -1, the no limit
|
||||
//if (fm_cfg[client_id].filecount >= fm_cfg[client_id].maxfiles
|
||||
//&& fm_cfg[client_id].maxfiles!=-1) {
|
||||
//button_addfile.style.display = 'none';
|
||||
//} else {
|
||||
//button_addfile.onclick = function(e) {
|
||||
//this.options.savepath = this.options.currentpath;
|
||||
//fm_launch_filepicker(this.options.target, this.options);
|
||||
//}
|
||||
//button_addfile.options = fm_cfg[client_id];
|
||||
//}
|
||||
if (this.filecount >= this.maxfiles
|
||||
&& this.maxfiles!=-1) {
|
||||
button_addfile.setStyle('display', 'none');
|
||||
} else {
|
||||
button_addfile.on('click', function(e) {
|
||||
var options = this.filepicker_options;
|
||||
var scope = this;
|
||||
var client_id = this.client_id;
|
||||
Y.use('core_filepicker', function (Y) {
|
||||
options.formcallback = scope.filepicker_callback;
|
||||
// XXX: magic here, to let filepicker use filemanager scope
|
||||
options.magicscope = scope;
|
||||
options.savepath = scope.currentpath;
|
||||
if (!M.fm_filepickers[client_id]) {
|
||||
M.fm_filepickers[client_id] = new M.core_filepicker(options);
|
||||
}
|
||||
M.fm_filepickers[client_id].show();
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
|
||||
// setup 'make a folder' button
|
||||
if (this.options.subdirs) {
|
||||
@@ -470,7 +479,12 @@ M.core_filemanager = (function(){
|
||||
scope: scope,
|
||||
params: params,
|
||||
callback: function(id, obj, args) {
|
||||
scope.filecount--;
|
||||
scope.refresh(obj.filepath);
|
||||
if (scope.filecount < scope.maxfiles && scope.maxfiles!=-1) {
|
||||
var button_addfile = Y.one("#btnadd-"+scope.client_id);
|
||||
button_addfile.setStyle('display', 'inline');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -216,9 +216,9 @@ FMHTML;
|
||||
<div id="filemanager-wrapper-{$client_id}" style="display:none">
|
||||
<div class="fm-breadcrumb" id="fm-path-{$client_id}"></div>
|
||||
<div class="filemanager-toolbar">
|
||||
<a href="###" id="btnadd-{$client_id}">{$straddfile}</a>
|
||||
<a href="###" id="btncrt-{$client_id}">{$strmakedir}</a>
|
||||
<a href="###" id="btndwn-{$client_id}">{$strdownload}</a>
|
||||
<button id="btnadd-{$client_id}" onclick="return false">{$straddfile}</button>
|
||||
<button id="btncrt-{$client_id}" onclick="return false">{$strmakedir}</button>
|
||||
<button id="btndwn-{$client_id}" onclick="return false">{$strdownload}</button>
|
||||
</div>
|
||||
<div class="filemanager-container" id="filemanager-{$client_id}">
|
||||
<ul id="draftfiles-{$client_id}">
|
||||
|
||||
Reference in New Issue
Block a user