File a file link via ajax

This commit is contained in:
Nathan Gray 2013-11-14 21:38:45 +00:00
parent 727cdc83b3
commit 4cc524dedd
2 changed files with 42 additions and 7 deletions

View File

@ -1233,6 +1233,7 @@ class filemanager_ui
$arr = array(
'msg' => '',
'action' => $action,
'errs' => 0,
'dirs' => 0,
'files' => 0,
@ -1301,11 +1302,31 @@ class filemanager_ui
$arr['props'] = $props;
break;
// Upload, then link
case 'link':
// First upload
$arr = self::ajax_action('upload', $selected, $dir, $props);
$app_dir = egw_link::vfs_path($props['entry']['app'],$props['entry']['id'],'',true);
foreach($arr['uploaded'] as $file)
{
$target=egw_vfs::concat($dir,egw_vfs::encodePathComponent($file['name']));
if (egw_vfs::file_exists($target) && $app_dir)
{
if (!egw_vfs::file_exists($app_dir)) egw_vfs::mkdir($app_dir);
error_log("Symlinking $target to $app_dir");
egw_vfs::symlink($target, egw_vfs::concat($app_dir,egw_vfs::encodePathComponent($file['name'])));
}
}
// Must return to avoid adding to $response again
return;
default:
$arr['msg'] = self::action($action, $selected, $dir, $arr['errs'], $arr['dirs'], $arr['files']);
}
$response->data($arr);
//error_log(__METHOD__."('$action',".array2string($selected).') returning '.array2string($arr));
return $arr;
}
/**

View File

@ -215,8 +215,21 @@ app.classes.filemanager = AppJS.extend(
}
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
egw.json('filemanager_ui::ajax_action', [action == 'save_as' ? 'upload' : 'link', widget.getValue(), path, props],
function(_data)
{
app.filemanager._upload_callback(_data);
// Remove successful after a delay
for(var file in _data.uploaded)
{
if(!_data.uploaded[file].confirm || _data.uploaded[file].confirmed)
{
// Remove that file from file widget...
widget.remove_file(_data.uploaded[file].name);
}
}
}, app.filemanager, true, this
).sendRequest(true);
return true;
},
@ -257,7 +270,7 @@ 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, this.my_data.props],
egw.json('filemanager_ui::ajax_action', [this.my_data.action, uploaded, this.my_data.path, this.my_data.props],
that._upload_callback, that, true, that
).sendRequest();
return;
@ -275,6 +288,7 @@ app.classes.filemanager = AppJS.extend(
_data.uploaded[file].name, buttons, file);
// setting required data for callback in as my_data
dialog.my_data = {
action: _data.action,
file: file,
path: _data.path,
data: _data.uploaded[file],