Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the before upload event at the elfinder plugin (a file manager plugin)

I am working on the file manager using jquery

here is the code:

 var elfinder = $('#elfinder').elfinder({
            url: '<?= $connector; ?>',
            soundPath: '<?= site_url('assets/plugins/elFinder/sounds/rm.wav'); ?>',
            height: 700,
            lang: 'zh_TW',
            uiOptions: {
                // toolbar configuration
                toolbar: [
                    ['back', 'forward'],
                    ['reload'],
                    ['mkdir', 'upload'],
                    ['copy', 'cut', 'paste', 'rm'],
                    ['rename'],
                    ['view', 'sort']
                ]
            },
            contextmenu: {
                navbar: ['open', '|', 'copy', 'cut', 'paste', 'duplicate', '|', 'rm', '|', 'info'],
                cwd: ['reload', 'back', '|', 'upload', 'mkdir', 'paste', '|', 'info'],
                files: [
                    'open', 'quicklook', 'sharefolder', '|', 'download', '|', 'copy', 'cut', 'paste', 'rm', '|', 'rename', '|', 'info'
                ]
            },
            ui: ['toolbar', 'tree', 'stat'],
            handlers: {
                add: function (e) {
                },
                upload: function (e, instance) {
                    alert("test1");
                    //alert("test2");
                    //return false;
                    //console.log(event.data);
                    //console.log(event.data.selected); // selected files hashes list
                }
            }
        });

The problem are,

1) I would like to have some checking before file upload, if fail then cancel the upload, but in either add / upload event it is fire after upload start , and fire several time

2) Also, it can't capture the on upload complete event as the upload event fire several time

Here is the event list:

https://github.com/Studio-42/elFinder/wiki/Client-event-API

Any suggestion , thanks a lot for helping.

Updated:

Find in Server side, there is a bind options , to override the command e.g. "rm mkdir" etc... however , I would like to get the user id when store, so are there list of event that I can override in client side? Thanks

https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options

like image 584
user782104 Avatar asked Oct 30 '22 03:10

user782104


1 Answers

Please override the function because there is no hook point before command execution.

var elfinderInstance =  $('#elfinder').elfinder({ /* Your options */ }).elfinder('instance');

elfinderInstance.upload = function(files) {
    var hasError;
    elfinderInstance.log(files); // print to browser consol
    if (hasError) {
        elfinderInstance.error('upload error');
        return $.Deferred().reject();
    } else {
        return elfinderInstance.transport.upload(files, elfinderInstance);
    }
};
like image 81
nao-pon Avatar answered Nov 14 '22 10:11

nao-pon