diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-12-19 03:06:06 +0100 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-12-19 18:33:34 +0100 |
commit | 7760f1652190474d1f62b590b6a57799c8ffd68d (patch) | |
tree | 8e473e460ab02514fe229abb968ad720ccb7fbcc /apps/files/js/fileactions.js | |
parent | b01d20c0d7b76dc04fcbfa027c51b14d740dc67e (diff) | |
download | nextcloud-server-7760f1652190474d1f62b590b6a57799c8ffd68d.tar.gz nextcloud-server-7760f1652190474d1f62b590b6a57799c8ffd68d.zip |
Trigger events before and after a file action is executed
In the same way that other elements can know when a FileAction is
registered or a default action is set this commit makes possible to be
notified before and after a FileAction is executed.
This is achieved by wrapping the registered action handler in a custom
function that notifies the listeners before and after executing the
handler itself. Due to this approach only FileActions registered through
"registerAction" trigger the events, although that is not a problem as
this is how the actions should be added to the FileActions anyway.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/files/js/fileactions.js')
-rw-r--r-- | apps/files/js/fileactions.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 6c031ab06d5..1b94ee15a61 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -142,7 +142,22 @@ var mime = action.mime; var name = action.name; var actionSpec = { - action: action.actionHandler, + action: function(fileName, context) { + // Actions registered in one FileAction may be executed on a + // different one (for example, due to the "merge" function), + // so the listeners have to be updated on the FileActions + // from the context instead of on the one in which it was + // originally registered. + if (context && context.fileActions) { + context.fileActions._notifyUpdateListeners('beforeTriggerAction', {action: actionSpec, fileName: fileName, context: context}); + } + + action.actionHandler(fileName, context); + + if (context && context.fileActions) { + context.fileActions._notifyUpdateListeners('afterTriggerAction', {action: actionSpec, fileName: fileName, context: context}); + } + }, name: name, displayName: action.displayName, mime: mime, |