From 6209c42dc4bf861ddfe0ad3fb5725d78e2444ff4 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 7 Nov 2013 23:30:50 +0000 Subject: [PATCH] - Add props parameter for upload - If user cancels rename/overwrite, remove file from file widget --- filemanager/inc/class.filemanager_ui.inc.php | 5 +-- filemanager/js/app.js | 33 ++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index 440878e273..4fc70ad333 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -1227,7 +1227,7 @@ class filemanager_ui * @param string $dir=null current directory * @see self::action() */ - public static function ajax_action($action, $selected, $dir=null) + public static function ajax_action($action, $selected, $dir=null, $props=null) { $response = egw_json_response::get(); @@ -1277,7 +1277,7 @@ class filemanager_ui $tmp_path = ini_get('upload_tmp_dir').'/'.basename($tmp_name); } - if (egw_vfs::copy_uploaded($tmp_path, $path, null, false)) + if (egw_vfs::copy_uploaded($tmp_path, $path, $props, false)) { ++$arr['files']; $uploaded[] = $data['name']; @@ -1298,6 +1298,7 @@ class filemanager_ui } $arr['uploaded'] = $selected; $arr['path'] = $dir; + $arr['props'] = $props; break; default: diff --git a/filemanager/js/app.js b/filemanager/js/app.js index fd2ed0fb80..f1972dbaba 100644 --- a/filemanager/js/app.js +++ b/filemanager/js/app.js @@ -198,6 +198,29 @@ app.classes.filemanager = AppJS.extend( widget.set_value(''); } }, + + /** + * Finish callback for file a file dialog, to get the overwrite / rename prompt + */ + file_a_file_upload: function(_event, _file_count) + { + var widget = _event.data; + var value = widget.getValue(); + var path = widget.getRoot().getWidgetById("path").getValue(); + var action = widget.getRoot().getWidgetById("action").getValue(); + var link = widget.getRoot().getWidgetById("entry").getValue(); + if(action == 'save_as' && link.app && link.id) + { + path = "/apps/"+link.app+"/"+link.id; + } + + var props = widget.getInstanceManager().getValues(widget.getRoot()); + egw.json('filemanager_ui::ajax_action', ['upload', widget.getValue(), path, props], + app.filemanager._upload_callback, app.filemanager, true, this + ).sendRequest(true); + return true; + }, + /** * Callback for server response to upload request: @@ -234,10 +257,15 @@ app.classes.filemanager = AppJS.extend( uploaded[this.my_data.file].name = _value; delete uploaded[this.my_data.file].confirm; // send overwrite-confirmation and/or rename request to server - egw.json('filemanager_ui::ajax_action', ['upload', uploaded, this.my_data.path], + egw.json('filemanager_ui::ajax_action', ['upload', uploaded, this.my_data.path, this.my_data.props], that._upload_callback, that, true, that ).sendRequest(); return; + case "cancel": + // Remove that file from every file widget... + that.et2.iterateOver(function(_widget) { + _widget.remove_file(this.my_data.data.name); + }, this, et2_file); } }, _data.uploaded[file].confirm === "is_dir" ? @@ -249,7 +277,8 @@ app.classes.filemanager = AppJS.extend( dialog.my_data = { file: file, path: _data.path, - data: _data.uploaded[file] + data: _data.uploaded[file], + props: _data.props }; } }