如何为CKFinder创建重命名后或删除后事件挂钩?

时间:2013-10-23 10:31:48

标签: javascript asp.net-mvc ckfinder

如果在CKFinder中删除或重命名文件,我需要编辑内容并告知用户各种事情。我以为我可以创建一个JavaScript解决方案然后使用一些简单的AJAX将逻辑卸载到后端,如下所示:

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

但是,我找不到任何活动系统。我如何为CKFinder实现此功能?我需要的事件是文件/文件夹 - 重命名/删除/移动。它不一定是前端解决方案,但我更喜欢它的简单性。我的后端是ASP.net MVC3。

(CKF的替代品欢迎作为评论,但它们需要与其相同的功能。)

1 个答案:

答案 0 :(得分:3)

通过documentation我也无法找到任何类似扩展点的活动。

然而,通过查看某些来源,我发现CKFinder.dataTypes.Connector上的sendCommandPost metho d,每当需要将某些事情发送到服务器时就会调用它。所以在每个重要的事件,如文件/文件夹 - 重命名/删除/移动。

因此,您可以轻松创建自定义插件,您可以在其中访问CKFinderAPI实例,然后您可以覆盖sendCommandPost并添加自定义逻辑

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;
    }
} );

注册插件:

config.extraPlugins = "myplugin";
var ckfinder = new CKFinder( config );