Question

I need to edit content and inform the user about various things if a file is deleted or renamed inside CKFinder. I thought I could create a JavaScript solution and then offload the logic into the backend with some simple AJAX, with something like this:

CKFinder.on('successfulFileRename', function(event, oldpath, newpath) {
    // Contact backend, see where file was used, inform user etc etc
});

But alas, I could not find any event system. How would I implement this functionality for CKFinder? Events I need are File/Folder - Rename/Delete/Move. It doesn't have to be a frontend solution, but I would prefer it for simplicity. My backend is ASP.net MVC3.

(Alternatives for CKF are welcome as comments, but they need about the same functionality as it has.)

Was it helpful?

Solution

Going through the documentation I was also not able to find any event like extension points.

However looking through some of the source I've found the sendCommandPost method on the CKFinder.dataTypes.Connector which gets invoked every time when somethings needs to be send to the server. So on every important event like File/Folder - Rename/Delete/Move.

So you can easily create a custom plugin where you can access the CKFinderAPI instance and from there you can override the sendCommandPost and add you custom logic

CKFinder.addPlugin( 'myplugin', function( api ) {
    var orginalsendCommandPost = api.connector.sendCommandPost;
    api.connector.sendCommandPost = function() {

      // call the original function
      var result = orginalsendCommandPost.apply(this, arguments);

      // commandname as string: 'CreateFolder', 'MoveFiles', 'RenameFile', etc
      console.log(arguments[0]); 
      // arguments as object
      console.log(JSON.stringify(arguments[1]));

      return result;
    }
} );

And registering the plugin:

config.extraPlugins = "myplugin";
var ckfinder = new CKFinder( config );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top