From eb1eed5b8dcba98ea6cd54f2e65e8749de553506 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 13 Mar 2018 17:43:21 +0100 Subject: [PATCH] Implement new feature for vfs-select widget to accept extra buttons action. Additionally, add extra "copy" and "move" actions to link-to vfs dialog. --- api/js/etemplate/et2_widget_link.js | 2 ++ api/js/etemplate/et2_widget_vfs.js | 23 +++++++++++++++++++---- api/src/Etemplate/Widget/Link.php | 23 ++++++++++++++++++++--- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/api/js/etemplate/et2_widget_link.js b/api/js/etemplate/et2_widget_link.js index 16de86eb5f..4f4232ffc7 100644 --- a/api/js/etemplate/et2_widget_link.js +++ b/api/js/etemplate/et2_widget_link.js @@ -185,6 +185,8 @@ var et2_link_to = (function(){ "use strict"; return et2_inputWidget.extend( button_caption: '', readonly: this.options.readonly, dialog_title: egw.lang('Link'), + extra_buttons:[{text: egw.lang("copy"), id:"copy", image: "copy"}, + {text: egw.lang("move"), id:"move", image: "move"}], onchange: function() { var values = true; // If entry not yet saved, store for linking on server diff --git a/api/js/etemplate/et2_widget_vfs.js b/api/js/etemplate/et2_widget_vfs.js index ddffd96af4..0259b5c5f5 100644 --- a/api/js/etemplate/et2_widget_vfs.js +++ b/api/js/etemplate/et2_widget_vfs.js @@ -940,6 +940,11 @@ var et2_vfsSelect = (function(){ "use strict"; return et2_inputWidget.extend( default: "Save as", description: "Title of dialog", translate:true + }, + "extra_buttons": { + name: "extra action buttons", + type: "any", + description: "Extra buttons passed to dialog. It's co-related to method.", } }, @@ -1019,9 +1024,19 @@ var et2_vfsSelect = (function(){ "use strict"; return et2_inputWidget.extend( text: egw.lang(_data.content.label), id:"submit", image:_data.content.mode.match(/saveas|select-dir/) ? "save" : "check" - }, - {text: egw.lang("Close"), id:"close"} + } ]; + if (this.options.extra_buttons && this.options.method) + { + var extra_buttons_action = []; + for (var i=0; i < this.options.extra_buttons.length; i++) + { + buttons.push(this.options.extra_buttons[i]); + extra_buttons_action[this.options.extra_buttons[i]['id']] = this.options.extra_buttons[i]['id']; + } + + } + buttons.push({text: egw.lang("Close"), id:"close"}); var data = jQuery.extend(_data, {'currentapp': egw(window).app_name()}); // define a mini app object for vfs select UI @@ -1031,7 +1046,7 @@ var et2_vfsSelect = (function(){ "use strict"; return et2_inputWidget.extend( { callback: function(_button_id, _value) { - if (_button_id == 'submit' && _value) + if ((_button_id == 'submit' || extra_buttons_action[_button_id]) && _value) { var files = []; switch(_data.content.mode) @@ -1061,7 +1076,7 @@ var et2_vfsSelect = (function(){ "use strict"; return et2_inputWidget.extend( { egw(window).json( self.options.method, - [self.options.method_id, files], + [self.options.method_id, files, _button_id], function(){ jQuery(self.node).change(); } diff --git a/api/src/Etemplate/Widget/Link.php b/api/src/Etemplate/Widget/Link.php index 195386549d..cf0bdf3ce6 100644 --- a/api/src/Etemplate/Widget/Link.php +++ b/api/src/Etemplate/Widget/Link.php @@ -243,11 +243,18 @@ class Link extends Etemplate\Widget $response = Api\Json\Response::get(); $response->data($result !== false); } - + /** - * Symlink an existing file in filemanager + * Symlink/copy/move an existing file in filemanager + * + * @param string $app_id app's id, e.g. infolog:2 + * @param array $files an array of paths + * @param string $action custom action, default is null which + * means link action (actions: copy, move) + * + * @return nothing */ - public static function ajax_link_existing($app_id, $files) + public static function ajax_link_existing($app_id, $files, $action = null) { list($app, $id, $dest_file) = explode(':', $app_id); @@ -261,6 +268,16 @@ class Link extends Etemplate\Widget } if(!is_array($files)) $files = array($files); + + if ($action == "copy") + { + Api\Vfs::copy_files($files, Api\Link::vfs_path($app, $id, '', true)); + } + if ($action == "move") + { + Api\Vfs::move_files($files, Api\Link::vfs_path($app, $id, '', true), $errs = array(), $moved = array()); + } + foreach($files as $target) { Api\Link::link_file($app, $id, $target);