drag helper and added dir to ajax_action method, now calling do_action for all actions

This commit is contained in:
Ralf Becker 2013-04-11 13:16:40 +00:00
parent 927dd9e5dc
commit 3db8d01007
2 changed files with 59 additions and 95 deletions

View File

@ -174,7 +174,7 @@ class filemanager_ui
'file_drag' => array( 'file_drag' => array(
'dragType' => 'file', 'dragType' => 'file',
'type' => 'drag', 'type' => 'drag',
'onExecute' => 'javaScript:add.filemanager.drag' 'onExecute' => 'javaScript:app.filemanager.drag'
), ),
'file_drop_move' => array( 'file_drop_move' => array(
'icon' => 'stylite/move', 'icon' => 'stylite/move',
@ -614,7 +614,7 @@ class filemanager_ui
case 'delete': case 'delete':
return self::do_delete($selected,$errs,$files,$dirs); return self::do_delete($selected,$errs,$files,$dirs);
/* done on clientside now
case 'add': case 'add':
$files = egw_session::appsession('clipboard_files','filemanager'); $files = egw_session::appsession('clipboard_files','filemanager');
egw_session::appsession('clipboard_files','filemanager',$files ? array_unique(array_merge($files,$selected)) : $selected); egw_session::appsession('clipboard_files','filemanager',$files ? array_unique(array_merge($files,$selected)) : $selected);
@ -626,7 +626,7 @@ class filemanager_ui
egw_session::appsession('clipboard_files','filemanager',$selected); egw_session::appsession('clipboard_files','filemanager',$selected);
egw_session::appsession('clipboard_type','filemanager',$action); egw_session::appsession('clipboard_type','filemanager',$action);
return lang('%1 URLs %2 to clipboard.',count($selected),$action=='copy'?lang('copied'):lang('cut')); return lang('%1 URLs %2 to clipboard.',count($selected),$action=='copy'?lang('copied'):lang('cut'));
*/
case 'copy_paste': case 'copy_paste':
foreach($selected as $path) foreach($selected as $path)
{ {
@ -716,6 +716,33 @@ class filemanager_ui
$ret = lang('%1 errors linking (%2)!',$errs,$ret); $ret = lang('%1 errors linking (%2)!',$errs,$ret);
} }
return $ret." egw_vfs::symlink('$to','$path')"; return $ret." egw_vfs::symlink('$to','$path')";
case 'createdir':
$dst = egw_vfs::concat($dir, $selected[0]);
if (egw_vfs::mkdir($dst, null, STREAM_MKDIR_RECURSIVE))
{
$arr['msg'] = lang("Directory successfully created.");
}
else
{
$arr['msg'] = lang("Error while creating directory.");
}
break;
case 'symlink': // symlink given file into current dir
$target = $selected[0];
$link = egw_vfs::concat($dir, egw_vfs::basename($target));
$abs_target = $target[0] == '/' ? $target : egw_vfs::concat($dir, $target);
if (!egw_vfs::stat($abs_target))
{
$arr['msg'] = lang('Link target %1 not found!', egw_vfs::decodePath($abs_target));
break;
}
$arr['msg'] = egw_vfs::symlink($target,$link) ?
lang('Symlink to %1 created.',$target) :
lang('Error creating symlink to target %1!',egw_vfs::decodePath($target));
break;
default: default:
list($action, $settings) = explode('_', $action, 2); list($action, $settings) = explode('_', $action, 2);
switch($action) switch($action)
@ -1381,10 +1408,11 @@ class filemanager_ui
* Run given action on given path(es) and return array/object with values for keys 'msg', 'errs', 'dirs', 'files' * Run given action on given path(es) and return array/object with values for keys 'msg', 'errs', 'dirs', 'files'
* *
* @param string $action eg. 'delete', ... * @param string $action eg. 'delete', ...
* @param string $path * @param array $selected selected path(s)
* @param string $dir=null current directory
* @see self::action() * @see self::action()
*/ */
public static function ajax_action($action,$path) public static function ajax_action($action, $selected, $dir=null)
{ {
$response = egw_json_response::get(); $response = egw_json_response::get();
@ -1395,78 +1423,9 @@ class filemanager_ui
'files' => 0, 'files' => 0,
); );
$selected = func_get_args(); if (!isset($dir)) $dir = array_pop($selected);
$action = array_shift($selected);
switch ($action)
{
case "copy_files":
$dst = array_pop($selected);
$src = $selected;
$copied = array();
if (egw_vfs::copy_files($src, $dst, $arr['errs'], $copied)) $arr['msg'] = self::action($action, $selected, $dir, $arr['errs'], $arr['dirs'], $arr['files']);
{
$arr['msg'] = sprintf(lang("%d files successfully copied."), count($copied));
}
else
{
$arr['msg'] = sprintf(lang("%d errors while copying, %d files successfully copied."),
$arr['errs'], count($copied));
}
break;
case "move_files":
$dst = array_pop($selected);
$src = $selected;
$moved = array();
if (egw_vfs::move_files($src, $dst, $arr['errs'], $moved))
{
$arr['msg'] = sprintf(lang("%d files successfully moved."), count($moved));
}
else
{
$arr['msg'] = sprintf(lang("%d errors while moving, %d files successfully moved."),
$arr['errs'], count($moved));
}
break;
case "createdir":
$curdir = $selected[0];
$newdir = $selected[1];
$dst = egw_vfs::concat($curdir, $newdir);
if (egw_vfs::mkdir($dst, null, STREAM_MKDIR_RECURSIVE))
{
$arr['msg'] = lang("Directory successfully created.");
}
else
{
$arr['msg'] = lang("Error while creating directory.");
}
break;
case "symlink":
$curdir = $selected[0];
$target = $selected[1];
$link = egw_vfs::concat($curdir, egw_vfs::basename($target));
$abs_target = $target[0] == '/' ? $target : egw_vfs::concat($target, $target);
if (!egw_vfs::stat($abs_target))
{
$arr['msg'] = lang('Link target %1 not found!', egw_vfs::decodePath($abs_target));
break;
}
$arr['msg'] = egw_vfs::symlink($target,$link) ?
lang('Symlink to %1 created.',$target) : lang('Error creating symlink to target %1!',egw_vfs::decodePath($target));
break;
default:
$arr['msg'] = self::action($action,$selected,null,$arr['errs'],$arr['dirs'],$arr['files']);
break;
}
$response->data($arr); $response->data($arr);
//error_log(__METHOD__."('$action',".array2string($selected).') returning '.array2string($arr)); //error_log(__METHOD__."('$action',".array2string($selected).') returning '.array2string($arr));

View File

@ -228,8 +228,7 @@ app.filemanager = AppJS.extend(
break; break;
case 'paste': case 'paste':
this._do_action(this.clipboard_is_cut ? 'move_files' : 'copy_files', this._do_action(this.clipboard_is_cut ? 'cut_paste' : 'copy_paste', this.clipboard_files);
this.clipboard_files.concat([this.path_widget.getValue()]));
if (this.clipboard_is_cut) if (this.clipboard_is_cut)
{ {
@ -240,7 +239,7 @@ app.filemanager = AppJS.extend(
break; break;
case 'linkpaste': case 'linkpaste':
this._do_action('symlink', this.clipboard_files.concat([this.path_widget.getValue()])); this._do_action('link_paste', this.clipboard_files);
break; break;
} }
}, },
@ -269,7 +268,7 @@ app.filemanager = AppJS.extend(
if (dir) if (dir)
{ {
var path = this.path_widget.get_value(); var path = this.path_widget.get_value();
this._do_action('createdir', [ path, dir ], true); // true=synchronous request this._do_action('createdir', dir, true); // true=synchronous request
this.change_dir(path+'/'+dir); this.change_dir(path+'/'+dir);
} }
}, },
@ -283,8 +282,7 @@ app.filemanager = AppJS.extend(
if (target) if (target)
{ {
var path = this.path_widget.get_value(); this._do_action('symlink', target);
this._do_action('symlink', [ path, target ]);
} }
}, },
@ -297,9 +295,8 @@ app.filemanager = AppJS.extend(
*/ */
_do_action: function(_type, _selected, _sync) _do_action: function(_type, _selected, _sync)
{ {
var params = [_type]; var path = this.path_widget.get_value();
params = params.concat(_selected); var request = new egw_json_request('filemanager_ui::ajax_action', [_type, _selected, path], this);
var request = new egw_json_request('filemanager_ui::ajax_action', params, this);
request.sendRequest(!_sync, this._do_action_callback, this); request.sendRequest(!_sync, this._do_action_callback, this);
}, },
@ -411,13 +408,16 @@ app.filemanager = AppJS.extend(
var icons = []; var icons = [];
for (var i = 0; i < _elems.length; i++) for (var i = 0; i < _elems.length; i++)
{ {
var data = egw.dataGetUIDdata(_elems[i].id);
var src = egw.mime_icon(data.data.mime, data.data.path);
if (_elems[i].getFocused()) if (_elems[i].getFocused())
{ {
icons.unshift(_elems[i].data.iconUrl); icons.unshift(src);
} }
else else
{ {
icons.push(_elems[i].data.iconUrl); icons.push(src);
} }
} }
@ -436,14 +436,15 @@ app.filemanager = AppJS.extend(
lastIcon = icons[i]; lastIcon = icons[i];
// Create a stack of images // Create a stack of images
var img = $j(document.createElement("img")); var img = $j(document.createElement('img'));
img.css("position", "absolute"); img.css({
img.css("z-index", 10000-i); position: 'absolute',
img.css("top", idx * 3); 'z-index': 10000-i,
img.css("left", idx * 3); top: idx*5,
img.css("opacity", (maxCnt - idx) / maxCnt); left: idx*5,
opacity: (maxCnt - idx) / maxCnt
img.attr("src", icons[i]); });
img.attr('src', icons[i]);
div.append(img); div.append(img);
idx++; idx++;
@ -453,6 +454,10 @@ app.filemanager = AppJS.extend(
} }
} }
} }
var text = $j(document.createElement('div')).css({left: '30px', position: 'absolute'});
// add filename or number of files for multiple files
text.text(_elems.length > 1 ? _elems.length+' '+egw.lang('files') : _elems[0].id.split('/').pop());
div.append(text);
return div; return div;
}, },