forked from extern/egroupware
W.I.P vfsSelect Widget:
- Fix upload feature not working
This commit is contained in:
parent
08032dd776
commit
052bef84ce
@ -1055,6 +1055,10 @@ var et2_vfsSelect = (function(){ "use strict"; return et2_inputWidget.extend(
|
||||
resizable: false
|
||||
}, et2_dialog._create_parent('api'));
|
||||
this.dialog.template.uniqueId = 'api.vfsSelectUI';
|
||||
// we need an etemplate_exec_id for better handling serverside parts of
|
||||
// widgets and since we can not have a etemplate_exec_id specifically
|
||||
// for dialog template our best shot is to inherit its parent etemplate_exec_id.
|
||||
this.dialog.template.etemplate_exec_id = this.getInstanceManager().etemplate_exec_id;
|
||||
app.vfsSelectUI.et2 = this.dialog.template.widgetContainer;
|
||||
app.vfsSelectUI.vfsSelectWidget = this;
|
||||
this.dialog.div.on('load', function(e) {
|
||||
|
@ -89,38 +89,35 @@ app.classes.vfsSelectUI = (function(){ "use strict"; return AppJS.extend(
|
||||
},
|
||||
|
||||
/**
|
||||
* Send names of uploaded files (again) to server, to process them: either copy to vfs or ask overwrite/rename
|
||||
* Send names of uploaded files (again) to server,
|
||||
* to process them: either copy to vfs or ask overwrite/rename
|
||||
*
|
||||
* @param {event} _event
|
||||
* @param {number} _file_count
|
||||
* @param {string=} _path where the file is uploaded to, default current directory
|
||||
*/
|
||||
upload: function(_event, _file_count, _path)
|
||||
storeFile: function(_event)
|
||||
{
|
||||
if(typeof _path == 'undefined')
|
||||
{
|
||||
_path = this.get_path();
|
||||
}
|
||||
if (_file_count && !jQuery.isEmptyObject(_event.data.getValue()))
|
||||
var path = this.get_path();
|
||||
|
||||
if (!jQuery.isEmptyObject(_event.data.getValue()))
|
||||
{
|
||||
var widget = _event.data;
|
||||
egw(window).json('filemanager_ui::ajax_action', ['upload', widget.getValue(), _path],
|
||||
this._upload_callback, this, true, this
|
||||
egw(window).json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_vfsSelect_storeFile', [widget.getValue(), path],
|
||||
this._storeFile_callback, this, true, this
|
||||
).sendRequest(true);
|
||||
widget.set_value('');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback for server response to upload request:
|
||||
* Callback for server response to storeFile request:
|
||||
* - display message and refresh list
|
||||
* - ask use to confirm overwritting existing files or rename upload
|
||||
*
|
||||
* @param {object} _data values for attributes msg, files, ...
|
||||
*/
|
||||
_upload_callback: function(_data)
|
||||
_storeFile_callback: function(_data)
|
||||
{
|
||||
if (_data.msg || _data.uploaded) window.egw_refresh(_data.msg, this.appname);
|
||||
if (_data.msg || _data.uploaded) egw(window).message(_data.msg);
|
||||
|
||||
var that = this;
|
||||
for(var file in _data.uploaded)
|
||||
@ -146,8 +143,8 @@ app.classes.vfsSelectUI = (function(){ "use strict"; return 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', [this.my_data.action, uploaded, this.my_data.path, this.my_data.props],
|
||||
that._upload_callback, that, true, that
|
||||
egw.json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_vfsSelect_storeFile', [uploaded, this.my_data.path],
|
||||
that._storeFile_callback, that, true, that
|
||||
).sendRequest();
|
||||
return;
|
||||
case "cancel":
|
||||
@ -164,13 +161,15 @@ app.classes.vfsSelectUI = (function(){ "use strict"; return 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],
|
||||
props: _data.props
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submit();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -295,20 +294,12 @@ app.classes.vfsSelectUI = (function(){ "use strict"; return AppJS.extend(
|
||||
submit: function(_field, _val, _callback)
|
||||
{
|
||||
var arrMgrs = this.et2.getArrayMgrs();
|
||||
arrMgrs.content.data[_field] = _val;
|
||||
jQuery.extend(arrMgrs.content.data, arrMgrs.modifications.data);
|
||||
this.et2.setArrayMgrs(arrMgrs);
|
||||
if (_field && _val)
|
||||
{
|
||||
arrMgrs.content.data[_field] = _val;
|
||||
jQuery.extend(arrMgrs.content.data, arrMgrs.modifications.data);
|
||||
this.et2.setArrayMgrs(arrMgrs);
|
||||
}
|
||||
this.vfsSelectWidget._content(arrMgrs.content.data, _callback);
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {type} _widget
|
||||
* @returns {undefined}
|
||||
* @todo: implementation of upload file
|
||||
*/
|
||||
uploaded: function (_widget)
|
||||
{
|
||||
|
||||
}
|
||||
});}).call(this);
|
||||
|
@ -562,6 +562,79 @@ class Vfs extends File
|
||||
$response->data($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store uploaded temp file into VFS
|
||||
*
|
||||
* @param array $files temp files
|
||||
* @param string $dir vfs path to store the file
|
||||
*/
|
||||
static function ajax_vfsSelect_storeFile ($files, $dir)
|
||||
{
|
||||
$response = Api\Json\Response::get();
|
||||
$result = array (
|
||||
'errs' => 0,
|
||||
'msg' => '',
|
||||
'files' => 0,
|
||||
);
|
||||
$script_error = 0;
|
||||
foreach($files as $tmp_name => &$data)
|
||||
{
|
||||
$path = \EGroupware\Api\Vfs::concat($dir, \EGroupware\Api\Vfs::encodePathComponent($data['name']));
|
||||
|
||||
if(\EGroupware\Api\Vfs::deny_script($path))
|
||||
{
|
||||
if (!isset($script_error))
|
||||
{
|
||||
$result['msg'] .= ($result['msg'] ? "\n" : '').lang('You are NOT allowed to upload a script!');
|
||||
}
|
||||
++$script_error;
|
||||
++$result['errs'];
|
||||
unset($files[$tmp_name]);
|
||||
}
|
||||
elseif (\EGroupware\Api\Vfs::is_dir($path))
|
||||
{
|
||||
$data['confirm'] = 'is_dir';
|
||||
}
|
||||
elseif (!$data['confirmed'] && \EGroupware\Api\Vfs::stat($path))
|
||||
{
|
||||
$data['confirm'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir']))
|
||||
{
|
||||
$tmp_path = $GLOBALS['egw_info']['server']['temp_dir'] . '/' . basename($tmp_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmp_path = ini_get('upload_tmp_dir').'/'.basename($tmp_name);
|
||||
}
|
||||
|
||||
if (\EGroupware\Api\Vfs::copy_uploaded($tmp_path, $path, null, false))
|
||||
{
|
||||
++$result['files'];
|
||||
$uploaded[] = $data['name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
++$result['errs'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($result['errs'] > $script_error)
|
||||
{
|
||||
$result['msg'] .= ($result['msg'] ? "\n" : '').lang('Error uploading file!');
|
||||
}
|
||||
if ($result['files'])
|
||||
{
|
||||
$result['msg'] .= ($result['msg'] ? "\n" : '').lang('%1 successful uploaded.', implode(', ', $uploaded));
|
||||
}
|
||||
$result['uploaded'] = $files;
|
||||
$result['path'] = $dir;
|
||||
|
||||
$response->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list off all apps having an application directory in VFS
|
||||
*
|
||||
|
@ -17,7 +17,7 @@
|
||||
<buttononly statustext="Up" id="up" onclick="app.vfsSelectUI.change_dir('..', widget);" image="goup" background_image="1"/>
|
||||
<select width="175" id="app" empty_label="Applications" no_lang="1" onchange="app.vfsSelectUI.do_action('app', widget)"/>
|
||||
<buttononly statustext="Create directory" id="createdir" class="createDir" onclick="app.vfsSelectUI.createdir" image="button_createdir" ro_image="createdir_disabled" background_image="1"/>
|
||||
<file id='upload_file' progress_dropdownlist = "true" onFinishOne="app.vfsSelectUI.uploadOnOne"/>
|
||||
<file id='upload_file' progress_dropdownlist = "true" multiple="true" onFinish="app.vfsSelectUI.storeFile"/>
|
||||
<vfs-name id="path" class="et2_fullWidth selectPath" align="left" onchange="app.vfsSelectUI.do_action('path', widget)"/>
|
||||
</box>
|
||||
</row>
|
||||
|
Loading…
Reference in New Issue
Block a user