5

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

user782104
  • 13,233
  • 55
  • 172
  • 312

1 Answers1

2

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);
    }
};
nao-pon
  • 461
  • 2
  • 5
  • really great sample code. Last question, are there any list of event that can override? since I may need to call some php command to log the file whenever , copy , delete , move , create folder etc... thanks – user782104 May 19 '16 at 02:23
  • sorry would you mind briefly explain what are the files object? how to loop through the list to get the file item's name , file size..etc...thanks a lot – user782104 May 19 '16 at 02:53