2013-04-09 18:20:06 +02:00
|
|
|
/**
|
2013-04-13 14:44:50 +02:00
|
|
|
* EGroupware - Filemanager - Javascript UI
|
2013-04-09 18:20:06 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package filemanager
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2014-01-22 09:42:42 +01:00
|
|
|
* @copyright (c) 2008-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2013-04-09 18:20:06 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2013-04-13 14:44:50 +02:00
|
|
|
/**
|
|
|
|
* UI for filemanager
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-13 14:44:50 +02:00
|
|
|
* @augments AppJS
|
|
|
|
*/
|
2013-11-04 21:54:23 +01:00
|
|
|
app.classes.filemanager = AppJS.extend(
|
2013-04-09 18:20:06 +02:00
|
|
|
{
|
|
|
|
appname: 'filemanager',
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
2014-12-05 20:34:12 +01:00
|
|
|
* path widget, by template
|
2013-04-10 19:11:32 +02:00
|
|
|
*/
|
2014-12-05 20:34:12 +01:00
|
|
|
path_widget: {},
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Are files cut into clipboard - need to be deleted at source on paste
|
|
|
|
*/
|
|
|
|
clipboard_is_cut: false,
|
2013-04-09 18:20:06 +02:00
|
|
|
|
|
|
|
/**
|
2013-04-10 19:11:32 +02:00
|
|
|
* Constructor
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-13 14:44:50 +02:00
|
|
|
* @memberOf app.filemanager
|
2013-04-09 18:20:06 +02:00
|
|
|
*/
|
2013-11-04 21:54:23 +01:00
|
|
|
init: function()
|
2013-04-09 18:20:06 +02:00
|
|
|
{
|
2013-04-10 19:11:32 +02:00
|
|
|
// call parent
|
|
|
|
this._super.apply(this, arguments);
|
2014-12-08 17:04:20 +01:00
|
|
|
|
2014-12-05 20:34:12 +01:00
|
|
|
// Loading filemanager in its tab and home causes us problems with
|
|
|
|
// unwanted destruction, so we check for already existing path widgets
|
|
|
|
var lists = etemplate2.getByApplication('home');
|
|
|
|
for(var i = 0; i < lists.length; i++)
|
|
|
|
{
|
|
|
|
if(lists[i].app == 'filemanager' && lists[i].widgetContainer.getWidgetById('path'))
|
|
|
|
{
|
|
|
|
this.path_widget[lists[i].uniqueId] = lists[i].widgetContainer.getWidgetById('path');
|
|
|
|
}
|
|
|
|
}
|
2013-04-10 12:04:18 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
destroy: function()
|
|
|
|
{
|
2014-12-08 17:04:20 +01:00
|
|
|
delete this.et2;
|
2013-04-10 19:11:32 +02:00
|
|
|
// call parent
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* This function is called when the etemplate2 object is loaded
|
|
|
|
* and ready. If you must store a reference to the et2 object,
|
|
|
|
* make sure to clean it up in destroy().
|
|
|
|
*
|
|
|
|
* @param et2 etemplate2 Newly ready object
|
2014-12-08 17:04:20 +01:00
|
|
|
* @param {string} name template name
|
2013-04-10 19:11:32 +02:00
|
|
|
*/
|
2014-12-05 20:34:12 +01:00
|
|
|
et2_ready: function(et2,name)
|
2013-04-10 19:11:32 +02:00
|
|
|
{
|
|
|
|
// call parent
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2016-02-02 11:42:21 +01:00
|
|
|
var path_widget = this.et2.getWidgetById('path');
|
|
|
|
if(path_widget) // do NOT set not found path-widgets, as uploads works on first one only!
|
2015-01-13 22:56:54 +01:00
|
|
|
{
|
2016-02-02 11:42:21 +01:00
|
|
|
this.path_widget[et2.DOMContainer.id] = path_widget;
|
2015-01-13 22:56:54 +01:00
|
|
|
// Bind to removal to remove from list
|
|
|
|
$j(et2.DOMContainer).on('clear', function(e) {
|
2015-01-15 17:01:41 +01:00
|
|
|
if (app.filemanager && app.filemanager.path_widget) delete app.filemanager.path_widget[e.target.id];
|
2015-01-13 22:56:54 +01:00
|
|
|
});
|
|
|
|
}
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2014-09-09 01:02:46 +02:00
|
|
|
if(this.et2.getWidgetById('nm'))
|
|
|
|
{
|
|
|
|
// Legacy JS only supports 2 arguments (event and widget), so set
|
|
|
|
// to the actual function here
|
|
|
|
this.et2.getWidgetById('nm').set_onfiledrop(jQuery.proxy(this.filedrop, this));
|
|
|
|
}
|
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
// get clipboard from browser localstore and update button tooltips
|
|
|
|
this.clipboard_tooltips();
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2014-12-10 11:32:47 +01:00
|
|
|
// calling set_readonly for initial path
|
|
|
|
if (this.et2.getArrayMgr('content').getEntry('initial_path_readonly'))
|
|
|
|
{
|
|
|
|
this.readonly = [this.et2.getArrayMgr('content').getEntry('nm[path]'), true];
|
|
|
|
}
|
2013-10-07 18:53:13 +02:00
|
|
|
if (typeof this.readonly != 'undefined')
|
|
|
|
{
|
|
|
|
this.set_readonly.apply(this, this.readonly);
|
|
|
|
delete this.readonly;
|
|
|
|
}
|
2013-04-10 19:11:32 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2015-01-13 22:56:54 +01:00
|
|
|
/**
|
|
|
|
* Set the application's state to the given state.
|
|
|
|
*
|
|
|
|
* Extended from parent to also handle view
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {{name: string, state: object}|string} state Object (or JSON string) for a state.
|
|
|
|
* Only state is required, and its contents are application specific.
|
|
|
|
*
|
|
|
|
* @return {boolean} false - Returns false to stop event propagation
|
|
|
|
*/
|
|
|
|
setState: function(state)
|
|
|
|
{
|
|
|
|
// State should be an object, not a string, but we'll parse
|
|
|
|
if(typeof state == "string")
|
|
|
|
{
|
|
|
|
if(state.indexOf('{') != -1 || state =='null')
|
|
|
|
{
|
|
|
|
state = JSON.parse(state);
|
|
|
|
}
|
|
|
|
}
|
2015-01-30 17:59:31 +01:00
|
|
|
var result = this._super.call(this, state, 'filemanager.index');
|
2015-01-15 17:01:41 +01:00
|
|
|
|
2015-01-14 21:55:03 +01:00
|
|
|
// This has to happen after the parent, changing to tile recreates
|
|
|
|
// nm controller
|
2015-01-13 22:56:54 +01:00
|
|
|
if(typeof state == "object" && state.state && state.state.view)
|
|
|
|
{
|
|
|
|
var et2 = etemplate2.getById('filemanager-index');
|
|
|
|
if(et2)
|
|
|
|
{
|
2015-01-14 21:55:03 +01:00
|
|
|
this.et2 = et2.widgetContainer;
|
|
|
|
this.change_view(state.state.view);
|
2015-01-13 22:56:54 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-14 21:55:03 +01:00
|
|
|
return result;
|
2015-01-13 22:56:54 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the current state of the application for future restoration
|
|
|
|
*
|
|
|
|
* Extended from parent to also set view
|
|
|
|
*
|
|
|
|
* @return {object} Application specific map representing the current state
|
|
|
|
*/
|
|
|
|
getState: function()
|
|
|
|
{
|
|
|
|
var state = this._super.apply(this);
|
|
|
|
|
|
|
|
var et2 = etemplate2.getById('filemanager-index');
|
|
|
|
if(et2)
|
|
|
|
{
|
|
|
|
var nm = et2.widgetContainer.getWidgetById('nm');
|
|
|
|
state.view = nm.view;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
},
|
|
|
|
|
2013-04-13 14:44:50 +02:00
|
|
|
/**
|
|
|
|
* Regexp to convert id to a path, use this.id2path(_id)
|
|
|
|
*/
|
|
|
|
remove_prefix: /^filemanager::/,
|
|
|
|
/**
|
|
|
|
* Convert id to path (remove "filemanager::" prefix)
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-01-22 09:42:42 +01:00
|
|
|
* @param {string} _id
|
2013-04-13 14:44:50 +02:00
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
id2path: function(_id)
|
|
|
|
{
|
|
|
|
return _id.replace(this.remove_prefix, '');
|
|
|
|
},
|
|
|
|
|
2013-04-11 12:46:39 +02:00
|
|
|
/**
|
|
|
|
* Convert array of elems to array of paths
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-11-24 17:13:14 +01:00
|
|
|
* @param {egwActionObject[]} _elems selected items from actions
|
2013-04-11 12:46:39 +02:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
_elems2paths: function(_elems)
|
|
|
|
{
|
|
|
|
var paths = [];
|
|
|
|
for (var i = 0; i < _elems.length; i++)
|
|
|
|
{
|
2014-11-24 17:13:14 +01:00
|
|
|
// If selected has no id, try parent. This happens for the placeholder row
|
|
|
|
// in empty directories.
|
|
|
|
paths.push(_elems[i].id? this.id2path(_elems[i].id) : _elems[i]._context._parentId);
|
2013-04-11 12:46:39 +02:00
|
|
|
}
|
|
|
|
return paths;
|
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 12:04:18 +02:00
|
|
|
/**
|
2013-04-13 14:44:50 +02:00
|
|
|
* Get directory of a path
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-01-22 09:42:42 +01:00
|
|
|
* @param {string} _path
|
2013-04-13 14:44:50 +02:00
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
dirname: function(_path)
|
|
|
|
{
|
|
|
|
var parts = _path.split('/');
|
|
|
|
parts.pop();
|
|
|
|
return parts.join('/') || '/';
|
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-13 14:44:50 +02:00
|
|
|
/**
|
|
|
|
* Get name of a path
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-01-22 09:42:42 +01:00
|
|
|
* @param {string} _path
|
2013-04-13 14:44:50 +02:00
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
basename: function(_path)
|
|
|
|
{
|
|
|
|
return _path.split('/').pop();
|
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-13 14:44:50 +02:00
|
|
|
/**
|
|
|
|
* Get current working directory
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-12-08 17:04:20 +01:00
|
|
|
* @param {string} etemplate_name
|
2013-04-13 14:44:50 +02:00
|
|
|
* @return string
|
2013-04-10 12:04:18 +02:00
|
|
|
*/
|
2014-12-05 20:34:12 +01:00
|
|
|
get_path: function(etemplate_name)
|
2013-04-10 12:04:18 +02:00
|
|
|
{
|
2014-12-09 16:09:29 +01:00
|
|
|
if(!etemplate_name || typeof this.path_widget[etemplate_name] == 'undefined')
|
2014-12-05 20:34:12 +01:00
|
|
|
{
|
2014-12-09 16:09:29 +01:00
|
|
|
for(etemplate_name in this.path_widget) break;
|
2014-12-05 20:34:12 +01:00
|
|
|
}
|
|
|
|
return this.path_widget[etemplate_name] ? this.path_widget[etemplate_name].get_value() : null;
|
2013-04-13 14:44:50 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Open compose with already attached files
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-01-22 09:42:42 +01:00
|
|
|
* @param {(string|string[])} attachments path(s)
|
2014-12-03 17:25:10 +01:00
|
|
|
* @param {object} params
|
2013-04-10 19:11:32 +02:00
|
|
|
*/
|
2014-12-03 17:25:10 +01:00
|
|
|
open_mail: function(attachments, params)
|
2013-04-09 18:20:06 +02:00
|
|
|
{
|
2014-11-18 00:57:15 +01:00
|
|
|
if (typeof attachments == 'undefined') attachments = this.get_clipboard_files();
|
2014-12-03 17:25:10 +01:00
|
|
|
if (!params || typeof params != 'object') params = {};
|
2013-04-09 18:20:06 +02:00
|
|
|
if (!(attachments instanceof Array)) attachments = [ attachments ];
|
|
|
|
for(var i=0; i < attachments.length; i++)
|
|
|
|
{
|
2013-04-11 12:46:39 +02:00
|
|
|
params['preset[file]['+i+']'] = 'vfs://default'+attachments[i];
|
2013-04-09 18:20:06 +02:00
|
|
|
}
|
2014-01-15 16:13:02 +01:00
|
|
|
egw.open('', 'mail', 'add', params);
|
2013-04-09 18:20:06 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Mail files action: open compose with already attached files
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-10 19:11:32 +02:00
|
|
|
* @param _action
|
|
|
|
* @param _elems
|
|
|
|
*/
|
2013-04-09 18:20:06 +02:00
|
|
|
mail: function(_action, _elems)
|
|
|
|
{
|
2014-12-03 17:25:10 +01:00
|
|
|
this.open_mail(this._elems2paths(_elems), {
|
|
|
|
'preset[filemode]': _action.id.substr(5)
|
|
|
|
});
|
2013-04-09 18:20:06 +02:00
|
|
|
},
|
2015-01-15 17:01:41 +01:00
|
|
|
|
2015-01-14 10:06:32 +01:00
|
|
|
/**
|
|
|
|
* Trigger Upload after each file is uploaded
|
|
|
|
* @param {type} _event
|
|
|
|
*/
|
|
|
|
uploadOnOne: function (_event)
|
|
|
|
{
|
|
|
|
this.upload(_event,1);
|
|
|
|
},
|
2015-01-15 17:01:41 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
2013-04-20 21:23:36 +02:00
|
|
|
* Send names of uploaded files (again) to server, to process them: either copy to vfs or ask overwrite/rename
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-01-22 09:42:42 +01:00
|
|
|
* @param {event} _event
|
|
|
|
* @param {number} _file_count
|
|
|
|
* @param {string=} _path where the file is uploaded to, default current directory
|
2013-04-10 19:11:32 +02:00
|
|
|
*/
|
2013-08-27 22:40:15 +02:00
|
|
|
upload: function(_event, _file_count, _path)
|
2013-04-09 18:20:06 +02:00
|
|
|
{
|
2013-08-27 22:40:15 +02:00
|
|
|
if(typeof _path == 'undefined')
|
|
|
|
{
|
|
|
|
_path = this.get_path();
|
|
|
|
}
|
2013-08-10 01:34:42 +02:00
|
|
|
if (_file_count && !jQuery.isEmptyObject(_event.data.getValue()))
|
2013-04-09 18:20:06 +02:00
|
|
|
{
|
2013-04-20 21:23:36 +02:00
|
|
|
var widget = _event.data;
|
2013-11-04 21:54:23 +01:00
|
|
|
var request = egw.json('filemanager_ui::ajax_action', ['upload', widget.getValue(), _path],
|
2013-09-10 21:54:19 +02:00
|
|
|
this._upload_callback, this, true, this
|
|
|
|
).sendRequest();
|
2013-04-20 21:23:36 +02:00
|
|
|
widget.set_value('');
|
|
|
|
}
|
|
|
|
},
|
2013-11-14 22:38:45 +01:00
|
|
|
|
2013-11-08 00:30:50 +01:00
|
|
|
/**
|
|
|
|
* Finish callback for file a file dialog, to get the overwrite / rename prompt
|
2014-01-22 09:42:42 +01:00
|
|
|
*
|
|
|
|
* @param {event} _event
|
|
|
|
* @param {number} _file_count
|
2013-11-08 00:30:50 +01:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2013-11-14 22:38:45 +01:00
|
|
|
|
2013-11-08 00:30:50 +01:00
|
|
|
var props = widget.getInstanceManager().getValues(widget.getRoot());
|
2013-11-14 22:38:45 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 17:59:30 +01:00
|
|
|
opener.egw_refresh('','filemanager',null,null,'filemanager');
|
2013-11-14 22:38:45 +01:00
|
|
|
}, app.filemanager, true, this
|
|
|
|
).sendRequest(true);
|
2013-11-08 00:30:50 +01:00
|
|
|
return true;
|
|
|
|
},
|
2013-11-14 22:38:45 +01:00
|
|
|
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-20 21:23:36 +02:00
|
|
|
/**
|
|
|
|
* Callback for server response to upload request:
|
|
|
|
* - display message and refresh list
|
|
|
|
* - ask use to confirm overwritting existing files or rename upload
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-01-22 09:42:42 +01:00
|
|
|
* @param {object} _data values for attributes msg, files, ...
|
2013-04-20 21:23:36 +02:00
|
|
|
*/
|
|
|
|
_upload_callback: function(_data)
|
|
|
|
{
|
2014-04-03 17:39:23 +02:00
|
|
|
if (_data.msg || _data.uploaded) window.egw_refresh(_data.msg, this.appname);
|
2013-04-20 21:23:36 +02:00
|
|
|
|
2013-04-22 21:57:03 +02:00
|
|
|
var that = this;
|
2013-04-20 21:23:36 +02:00
|
|
|
for(var file in _data.uploaded)
|
|
|
|
{
|
|
|
|
if (_data.uploaded[file].confirm && !_data.uploaded[file].confirmed)
|
2013-04-09 18:20:06 +02:00
|
|
|
{
|
2013-04-23 18:52:39 +02:00
|
|
|
var buttons = [
|
2013-10-07 18:53:13 +02:00
|
|
|
{text: this.egw.lang("Yes"), id: "overwrite", class: "ui-priority-primary", "default": true},
|
|
|
|
{text: this.egw.lang("Rename"), id:"rename"},
|
2014-01-22 09:42:42 +01:00
|
|
|
{text: this.egw.lang("Cancel"), id:"cancel"}
|
2013-04-23 18:52:39 +02:00
|
|
|
];
|
|
|
|
if (_data.uploaded[file].confirm === "is_dir")
|
|
|
|
buttons.shift();
|
|
|
|
var dialog = et2_dialog.show_prompt(function(_button_id, _value) {
|
|
|
|
var uploaded = {};
|
|
|
|
uploaded[this.my_data.file] = this.my_data.data;
|
|
|
|
switch (_button_id)
|
|
|
|
{
|
|
|
|
case "overwrite":
|
|
|
|
uploaded[this.my_data.file].confirmed = true;
|
|
|
|
// fall through
|
|
|
|
case "rename":
|
|
|
|
uploaded[this.my_data.file].name = _value;
|
|
|
|
delete uploaded[this.my_data.file].confirm;
|
|
|
|
// send overwrite-confirmation and/or rename request to server
|
2013-11-14 22:38:45 +01:00
|
|
|
egw.json('filemanager_ui::ajax_action', [this.my_data.action, uploaded, this.my_data.path, this.my_data.props],
|
2013-09-10 21:54:19 +02:00
|
|
|
that._upload_callback, that, true, that
|
|
|
|
).sendRequest();
|
2013-04-23 18:52:39 +02:00
|
|
|
return;
|
2013-11-08 00:30:50 +01:00
|
|
|
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);
|
2013-04-23 18:52:39 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
_data.uploaded[file].confirm === "is_dir" ?
|
2013-10-07 18:53:13 +02:00
|
|
|
this.egw.lang("There's already a directory with that name!") :
|
|
|
|
this.egw.lang('Do you want to overwrite existing file %1 in directory %2?', _data.uploaded[file].name, _data.path),
|
|
|
|
this.egw.lang('File %1 already exists', _data.uploaded[file].name),
|
2013-04-23 18:52:39 +02:00
|
|
|
_data.uploaded[file].name, buttons, file);
|
|
|
|
// setting required data for callback in as my_data
|
|
|
|
dialog.my_data = {
|
2013-11-14 22:38:45 +01:00
|
|
|
action: _data.action,
|
2013-04-23 18:52:39 +02:00
|
|
|
file: file,
|
|
|
|
path: _data.path,
|
2013-11-08 00:30:50 +01:00
|
|
|
data: _data.uploaded[file],
|
|
|
|
props: _data.props
|
2013-04-23 18:52:39 +02:00
|
|
|
};
|
2013-04-20 21:23:36 +02:00
|
|
|
}
|
2013-04-09 18:20:06 +02:00
|
|
|
}
|
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2014-11-18 00:57:15 +01:00
|
|
|
/**
|
|
|
|
* Get any files that are in the system clipboard
|
|
|
|
*
|
|
|
|
* @return {string[]} Paths
|
|
|
|
*/
|
|
|
|
get_clipboard_files: function()
|
|
|
|
{
|
|
|
|
var clipboard_files = [];
|
|
|
|
if (typeof window.localStorage != 'undefined' && typeof egw.getSessionItem('phpgwapi', 'egw_clipboard') != 'undefined')
|
|
|
|
{
|
|
|
|
var clipboard = JSON.parse(egw.getSessionItem('phpgwapi', 'egw_clipboard')) || {
|
|
|
|
type:[],
|
|
|
|
selected:[]
|
|
|
|
};
|
|
|
|
if(clipboard.type.indexOf('file') >= 0)
|
|
|
|
{
|
|
|
|
for(var i = 0; i < clipboard.selected.length; i++)
|
|
|
|
{
|
|
|
|
var split = clipboard.selected[i].id.split('::');
|
|
|
|
if(split[0] == 'filemanager')
|
|
|
|
{
|
|
|
|
clipboard_files.push(this.id2path(clipboard.selected[i].id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return clipboard_files;
|
|
|
|
},
|
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
2013-04-12 12:30:52 +02:00
|
|
|
* Update clickboard tooltips in buttons
|
2013-04-10 19:11:32 +02:00
|
|
|
*/
|
|
|
|
clipboard_tooltips: function()
|
2013-04-09 18:20:06 +02:00
|
|
|
{
|
2013-04-10 19:11:32 +02:00
|
|
|
var paste_buttons = ['button[paste]', 'button[linkpaste]', 'button[mailpaste]'];
|
|
|
|
for(var i=0; i < paste_buttons.length; ++i)
|
|
|
|
{
|
|
|
|
var button = this.et2.getWidgetById(paste_buttons[i]);
|
2014-11-18 00:57:15 +01:00
|
|
|
if (button) button.set_statustext(this.get_clipboard_files().join(",\n"));
|
2013-04-10 19:11:32 +02:00
|
|
|
}
|
2013-04-09 18:20:06 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Clip files into clipboard
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-10 19:11:32 +02:00
|
|
|
* @param _action
|
|
|
|
* @param _elems
|
|
|
|
*/
|
2013-04-09 18:20:06 +02:00
|
|
|
clipboard: function(_action, _elems)
|
|
|
|
{
|
2013-04-10 19:11:32 +02:00
|
|
|
this.clipboard_is_cut = _action.id == "cut";
|
2014-11-18 00:57:15 +01:00
|
|
|
var clipboard = JSON.parse(egw.getSessionItem('phpgwapi', 'egw_clipboard')) || {
|
|
|
|
type:[],
|
|
|
|
selected:[]
|
|
|
|
};
|
|
|
|
if(_action.id != "add")
|
|
|
|
{
|
|
|
|
clipboard = {
|
|
|
|
type:[],
|
|
|
|
selected:[]
|
2014-12-03 17:25:10 +01:00
|
|
|
};
|
2014-11-18 00:57:15 +01:00
|
|
|
};
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2014-11-18 00:57:15 +01:00
|
|
|
// When pasting we need to know the type of data - pull from actions
|
|
|
|
var drag = _elems[0].getSelectedLinks('drag').links;
|
|
|
|
for(var k in drag)
|
2013-04-09 18:20:06 +02:00
|
|
|
{
|
2014-11-18 00:57:15 +01:00
|
|
|
if(drag[k].enabled && drag[k].actionObj.dragType.length > 0)
|
|
|
|
{
|
|
|
|
clipboard.type = clipboard.type.concat(drag[k].actionObj.dragType);
|
|
|
|
}
|
2013-04-10 19:11:32 +02:00
|
|
|
}
|
2014-11-18 00:57:15 +01:00
|
|
|
clipboard.type = jQuery.unique(clipboard.type);
|
|
|
|
// egwAction is a circular structure and can't be stringified so just take what we want
|
|
|
|
// Hopefully that's enough for the action handlers
|
|
|
|
for(var k in _elems)
|
2013-04-10 19:11:32 +02:00
|
|
|
{
|
2014-11-18 00:57:15 +01:00
|
|
|
if(_elems[k].id) clipboard.selected.push({id:_elems[k].id, data:_elems[k].data});
|
2013-04-10 19:11:32 +02:00
|
|
|
}
|
2014-11-18 00:57:15 +01:00
|
|
|
|
|
|
|
// Save it in session
|
|
|
|
egw.setSessionItem('phpgwapi', 'egw_clipboard', JSON.stringify(clipboard));
|
|
|
|
|
|
|
|
this.clipboard_tooltips();
|
2013-04-10 19:11:32 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Paste files into current directory or mail them
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-10 19:11:32 +02:00
|
|
|
* @param _type 'paste', 'linkpaste', 'mailpaste'
|
|
|
|
*/
|
|
|
|
paste: function(_type)
|
|
|
|
{
|
2014-11-18 00:57:15 +01:00
|
|
|
var clipboard_files = this.get_clipboard_files();
|
|
|
|
if (clipboard_files.length == 0)
|
2013-04-11 12:46:39 +02:00
|
|
|
{
|
2013-10-07 18:53:13 +02:00
|
|
|
alert(this.egw.lang('Clipboard is empty!'));
|
2013-04-11 12:46:39 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-04-10 19:11:32 +02:00
|
|
|
switch(_type)
|
|
|
|
{
|
|
|
|
case 'mailpaste':
|
2014-11-18 00:57:15 +01:00
|
|
|
this.open_mail(clipboard_files);
|
2013-04-10 19:11:32 +02:00
|
|
|
break;
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
case 'paste':
|
2014-11-18 00:57:15 +01:00
|
|
|
this._do_action(this.clipboard_is_cut ? 'move' : 'copy', clipboard_files);
|
2013-04-11 12:46:39 +02:00
|
|
|
|
|
|
|
if (this.clipboard_is_cut)
|
|
|
|
{
|
|
|
|
this.clipboard_is_cut = false;
|
2014-11-18 00:57:15 +01:00
|
|
|
clipboard_files = [];
|
2013-04-11 12:46:39 +02:00
|
|
|
this.clipboard_tooltips();
|
|
|
|
}
|
|
|
|
break;
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-11 12:46:39 +02:00
|
|
|
case 'linkpaste':
|
2014-11-18 00:57:15 +01:00
|
|
|
this._do_action('symlink', clipboard_files);
|
2013-04-11 12:46:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass action to server
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-11 12:46:39 +02:00
|
|
|
* @param _action
|
|
|
|
* @param _elems
|
|
|
|
*/
|
|
|
|
action: function(_action, _elems)
|
|
|
|
{
|
2013-04-23 18:52:39 +02:00
|
|
|
var paths = this._elems2paths(_elems);
|
2014-12-05 20:34:12 +01:00
|
|
|
var path = this.get_path(_action && _action.parent.data.nextmatch.getInstanceManager().uniqueId || false);
|
|
|
|
this._do_action(_action.id, paths,true, path);
|
2013-04-09 18:20:06 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-11 12:46:39 +02:00
|
|
|
/**
|
|
|
|
* Prompt user for directory to create
|
2014-11-19 18:58:02 +01:00
|
|
|
*
|
2014-12-12 10:47:56 +01:00
|
|
|
* @param {egwAction|undefined|jQuery.Event} action Action, event or undefined if called directly
|
2014-11-19 18:58:02 +01:00
|
|
|
* @param {egwActionObject[] | undefined} selected Selected row, or undefined if called directly
|
2013-04-11 12:46:39 +02:00
|
|
|
*/
|
2014-11-19 18:58:02 +01:00
|
|
|
createdir: function(action, selected)
|
2013-04-11 12:46:39 +02:00
|
|
|
{
|
2015-11-05 13:05:46 +01:00
|
|
|
var self = this;
|
|
|
|
et2_dialog.show_prompt(function(button, dir){
|
|
|
|
if (button && dir)
|
2014-11-19 18:58:02 +01:00
|
|
|
{
|
2015-11-05 13:05:46 +01:00
|
|
|
var path = self.get_path(action && action.parent ? action.parent.data.nextmatch.getInstanceManager().uniqueId : false);
|
|
|
|
if(action && action instanceof egwAction)
|
2014-11-24 20:47:48 +01:00
|
|
|
{
|
2015-11-05 13:05:46 +01:00
|
|
|
var paths = self._elems2paths(selected);
|
|
|
|
if(paths[0]) path = paths[0];
|
|
|
|
// check if target is a file --> use it's directory instead
|
|
|
|
if(selected[0].id || path)
|
2014-11-24 20:47:48 +01:00
|
|
|
{
|
2015-11-05 13:05:46 +01:00
|
|
|
var data = egw.dataGetUIDdata(selected[0].id || 'filemanager::'+path );
|
|
|
|
if (data && data.data.mime != 'httpd/unix-directory')
|
|
|
|
{
|
|
|
|
path = self.dirname(path);
|
|
|
|
}
|
2014-11-24 20:47:48 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-05 13:05:46 +01:00
|
|
|
self._do_action('createdir', dir, true, path); // true=synchronous request
|
|
|
|
self.change_dir((path == '/' ? '' : path)+'/'+ dir);
|
2014-11-19 18:58:02 +01:00
|
|
|
}
|
2015-11-05 13:05:46 +01:00
|
|
|
},this.egw.lang('New directory'),this.egw.lang('Create directroy'));
|
2013-04-11 12:46:39 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-11 12:46:39 +02:00
|
|
|
/**
|
|
|
|
* Prompt user for directory to create
|
|
|
|
*/
|
|
|
|
symlink: function()
|
|
|
|
{
|
2015-11-05 13:05:46 +01:00
|
|
|
var self = this;
|
|
|
|
et2_dialog.show_prompt(function (button, target) {
|
|
|
|
if (button && target)
|
|
|
|
{
|
|
|
|
self._do_action('symlink', target);
|
|
|
|
}
|
|
|
|
},this.egw.lang('Link target'), this.egw.lang('Create link'));
|
2013-04-11 12:46:39 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-11 12:46:39 +02:00
|
|
|
/**
|
|
|
|
* Run a serverside action via an ajax call
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-11 12:46:39 +02:00
|
|
|
* @param _type 'move_file', 'copy_file', ...
|
|
|
|
* @param _selected selected paths
|
|
|
|
* @param _sync send a synchronous ajax request
|
2013-04-12 10:56:28 +02:00
|
|
|
* @param _path defaults to current path
|
2013-04-11 12:46:39 +02:00
|
|
|
*/
|
2013-04-12 10:56:28 +02:00
|
|
|
_do_action: function(_type, _selected, _sync, _path)
|
2013-04-11 12:46:39 +02:00
|
|
|
{
|
2013-04-13 14:44:50 +02:00
|
|
|
if (typeof _path == 'undefined') _path = this.get_path();
|
2013-09-10 21:56:22 +02:00
|
|
|
var request = egw.json('filemanager_ui::ajax_action', [_type, _selected, _path],
|
|
|
|
this._do_action_callback, this, !_sync, this
|
|
|
|
).sendRequest();
|
2013-04-11 12:46:39 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-11 12:46:39 +02:00
|
|
|
/**
|
|
|
|
* Callback for _do_action ajax call
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-11 12:46:39 +02:00
|
|
|
* @param _data
|
|
|
|
*/
|
|
|
|
_do_action_callback: function(_data)
|
|
|
|
{
|
|
|
|
window.egw_refresh(_data.msg, this.appname);
|
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Force download of a file by appending '?download' to it's download url
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-10 19:11:32 +02:00
|
|
|
* @param _action
|
|
|
|
* @param _senders
|
|
|
|
*/
|
2013-04-09 18:20:06 +02:00
|
|
|
force_download: function(_action, _senders)
|
|
|
|
{
|
2014-06-23 23:58:27 +02:00
|
|
|
for(var i = 0; i < _senders.length; i++)
|
|
|
|
{
|
|
|
|
var data = egw.dataGetUIDdata(_senders[i].id);
|
|
|
|
var url = data ? data.data.download_url : '/webdav.php'+this.id2path(_senders[i].id);
|
|
|
|
if (url[0] == '/') url = egw.link(url);
|
2014-10-13 19:23:33 +02:00
|
|
|
|
2014-06-23 23:58:27 +02:00
|
|
|
var a = document.createElement('a');
|
|
|
|
if(typeof a.download == "undefined")
|
|
|
|
{
|
|
|
|
window.location = url+"?download";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Multiple file download for those that support it
|
|
|
|
a = $j(a)
|
|
|
|
.prop('href', url)
|
|
|
|
.prop('download', data ? data.data.name : "")
|
|
|
|
.appendTo(this.et2.getDOMNode());
|
|
|
|
|
|
|
|
var evt = document.createEvent('MouseEvent');
|
|
|
|
evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
|
|
a[0].dispatchEvent(evt);
|
|
|
|
a.remove();
|
|
|
|
}
|
|
|
|
return false;
|
2013-04-10 19:11:32 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2014-06-24 00:41:34 +02:00
|
|
|
/**
|
|
|
|
* Check to see if the browser supports downloading multiple files
|
|
|
|
* (using a tag download attribute) to enable/disable the context menu
|
|
|
|
*
|
|
|
|
* @param {egwAction} action
|
|
|
|
* @param {egwActionObject[]} selected
|
|
|
|
*/
|
|
|
|
is_multiple_allowed: function(action, selected)
|
|
|
|
{
|
|
|
|
var allowed = typeof document.createElement('a').download != "undefined";
|
2014-10-13 19:23:33 +02:00
|
|
|
|
2014-06-24 00:41:34 +02:00
|
|
|
if(typeof action == "undefined") return allowed;
|
|
|
|
|
|
|
|
return (allowed || selected.length <= 1) && action.not_disableClass.apply(action, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Change directory
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-12-08 17:04:20 +01:00
|
|
|
* @param {string} _dir directory to change to incl. '..' for one up
|
|
|
|
* @param {et2_widget} widget
|
2013-04-10 19:11:32 +02:00
|
|
|
*/
|
2014-12-05 20:34:12 +01:00
|
|
|
change_dir: function(_dir, widget)
|
2013-04-10 19:11:32 +02:00
|
|
|
{
|
2014-12-09 16:09:29 +01:00
|
|
|
for(var etemplate_name in this.path_widget) break;
|
|
|
|
if (widget) etemplate_name = widget.getInstanceManager().uniqueId;
|
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
switch (_dir)
|
|
|
|
{
|
|
|
|
case '..':
|
2014-12-05 20:34:12 +01:00
|
|
|
_dir = this.dirname(this.get_path(etemplate_name));
|
2013-04-10 19:11:32 +02:00
|
|
|
break;
|
|
|
|
case '~':
|
|
|
|
_dir = this.et2.getWidgetById('nm').options.settings.home_dir;
|
|
|
|
break;
|
|
|
|
}
|
2014-12-05 20:34:12 +01:00
|
|
|
|
|
|
|
this.path_widget[etemplate_name].set_value(_dir);
|
2013-04-10 19:11:32 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2014-12-31 18:55:06 +01:00
|
|
|
/**
|
|
|
|
* Toggle view between tiles and rows
|
2015-01-15 17:01:41 +01:00
|
|
|
*
|
2015-01-13 22:56:54 +01:00
|
|
|
* @param {string|Event} [view] - Specify what to change the view to. Either 'tile' or 'row'.
|
|
|
|
* Or, if this is used as a callback view is actually the event, and we need to find the view.
|
2014-12-31 18:55:06 +01:00
|
|
|
* @param {et2_widget} [button_widget] - The widget that's calling
|
|
|
|
*/
|
|
|
|
change_view: function(view, button_widget)
|
|
|
|
{
|
2015-01-14 21:55:03 +01:00
|
|
|
var et2 = etemplate2.getById('filemanager-index');
|
|
|
|
var nm = false;
|
|
|
|
if(et2 && et2.widgetContainer.getWidgetById('nm'))
|
|
|
|
{
|
|
|
|
nm = et2.widgetContainer.getWidgetById('nm');
|
|
|
|
}
|
2014-12-31 18:55:06 +01:00
|
|
|
if(!nm)
|
|
|
|
{
|
|
|
|
egw.debug('warn', 'Could not find nextmatch to change view');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-13 22:56:54 +01:00
|
|
|
if(!button_widget)
|
|
|
|
{
|
|
|
|
button_widget = nm.getWidgetById('button[change_view]');
|
|
|
|
}
|
2014-12-31 18:55:06 +01:00
|
|
|
if(button_widget && button_widget.instanceOf(et2_button))
|
|
|
|
{
|
|
|
|
// Switch view based on button icon, since controller can get re-created
|
|
|
|
if(typeof view != 'string')
|
|
|
|
{
|
|
|
|
view = button_widget.options.image.replace('list_','');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle button icon to the other view
|
|
|
|
button_widget.set_image("list_"+(view == nm.controller.VIEW_ROW ? nm.controller.VIEW_TILE : nm.controller.VIEW_ROW));
|
|
|
|
|
2016-02-24 11:41:18 +01:00
|
|
|
button_widget.set_statustext(view == nm.controller.VIEW_ROW ? this.egw.lang("Tile view") : this.egw.lang('List view'));
|
2014-12-31 18:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nm.set_view(view);
|
2015-01-13 22:56:54 +01:00
|
|
|
// Put it into active filters (but don't refresh)
|
|
|
|
nm.activeFilters.view = view;
|
2014-12-31 18:55:06 +01:00
|
|
|
|
|
|
|
// Change template to match
|
2015-09-21 19:14:39 +02:00
|
|
|
var template = view == nm.controller.VIEW_ROW ? 'filemanager.index.rows' : 'filemanager.tile';
|
|
|
|
nm.set_template(template);
|
|
|
|
|
|
|
|
// Wait for template to load, then refresh
|
|
|
|
template = nm.getWidgetById(template);
|
|
|
|
if(template && template.loading)
|
|
|
|
{
|
|
|
|
template.loading.done(function() {
|
|
|
|
nm.applyFilters({view: view});
|
2016-02-24 11:41:18 +01:00
|
|
|
});
|
2015-09-21 19:14:39 +02:00
|
|
|
}
|
2014-12-31 18:55:06 +01:00
|
|
|
},
|
|
|
|
|
2013-04-10 19:11:32 +02:00
|
|
|
/**
|
|
|
|
* Open/active an item
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-10 19:11:32 +02:00
|
|
|
* @param _action
|
|
|
|
* @param _senders
|
|
|
|
*/
|
|
|
|
open: function(_action, _senders)
|
|
|
|
{
|
|
|
|
var data = egw.dataGetUIDdata(_senders[0].id);
|
2013-04-13 14:44:50 +02:00
|
|
|
var path = this.id2path(_senders[0].id);
|
2015-04-07 14:32:57 +02:00
|
|
|
var mime = this.et2._inst.widgetContainer.getWidgetById('$row');
|
|
|
|
// try to get mime widget DOM node out of the row DOM
|
|
|
|
var mime_dom = jQuery(_senders[0].iface.getDOMNode()).find("span#filemanager-index_\\$row");
|
2015-05-01 12:52:24 +02:00
|
|
|
|
2013-10-14 11:01:03 +02:00
|
|
|
// symlinks dont have mime 'http/unix-directory', but server marks all directories with class 'isDir'
|
|
|
|
if (data.data.mime == 'httpd/unix-directory' || data.data['class'] && data.data['class'].split(/ +/).indexOf('isDir') != -1)
|
2013-04-10 19:11:32 +02:00
|
|
|
{
|
2014-12-05 20:34:12 +01:00
|
|
|
this.change_dir(path,_action.parent.data.nextmatch || this.et2);
|
2013-04-10 19:11:32 +02:00
|
|
|
}
|
2015-04-07 14:32:57 +02:00
|
|
|
else if(mime && data.data.mime.match(mime.mime_regexp) && mime_dom.length>0)
|
|
|
|
{
|
|
|
|
mime_dom.click();
|
|
|
|
}
|
2013-04-10 19:11:32 +02:00
|
|
|
else
|
|
|
|
{
|
2015-05-01 12:52:24 +02:00
|
|
|
egw.open({path: path, type: data.data.mime, download_url: data.data.download_url}, 'file','view',null,'_browser');
|
2013-04-10 19:11:32 +02:00
|
|
|
}
|
2014-12-05 20:34:12 +01:00
|
|
|
return false;
|
2013-04-11 12:46:39 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-12 12:30:52 +02:00
|
|
|
/**
|
|
|
|
* Edit prefs of current directory
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-08-20 15:12:18 +02:00
|
|
|
* @param _action
|
|
|
|
* @param _senders
|
2013-04-12 12:30:52 +02:00
|
|
|
*/
|
2013-08-20 15:12:18 +02:00
|
|
|
editprefs: function(_action, _senders)
|
2013-04-12 12:30:52 +02:00
|
|
|
{
|
2014-12-05 20:34:12 +01:00
|
|
|
var path = typeof _senders != 'undefined' ? this.id2path(_senders[0].id) : this.get_path(_action && _action.parent.data.nextmatch.getInstanceManager().uniqueId || false);
|
2013-04-12 12:30:52 +02:00
|
|
|
|
|
|
|
egw().open_link(egw.link('/index.php', {
|
|
|
|
menuaction: 'filemanager.filemanager_ui.file',
|
2014-01-22 09:42:42 +01:00
|
|
|
path: path
|
2015-01-09 16:42:43 +01:00
|
|
|
}), 'fileprefs', '510x425');
|
2013-04-12 12:30:52 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-11 12:46:39 +02:00
|
|
|
/**
|
|
|
|
* File(s) droped
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-04-11 12:46:39 +02:00
|
|
|
* @param _action
|
|
|
|
* @param _elems
|
|
|
|
* @param _target
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
drop: function(_action, _elems, _target)
|
|
|
|
{
|
|
|
|
var src = this._elems2paths(_elems);
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2014-11-19 18:58:02 +01:00
|
|
|
|
|
|
|
// Target will be missing ID if directory is empty
|
|
|
|
// so start with the current directory
|
2015-08-25 17:17:54 +02:00
|
|
|
var nm_dst = this.get_path(_action.parent.data.nextmatch.getInstanceManager().uniqueId || false);
|
2014-11-19 18:58:02 +01:00
|
|
|
|
|
|
|
// File(s) were dropped on a row, they want them inside
|
2014-11-24 17:25:05 +01:00
|
|
|
if(_target)
|
2013-04-13 14:44:50 +02:00
|
|
|
{
|
2014-12-03 17:25:10 +01:00
|
|
|
var dst = '';
|
2014-11-24 17:25:05 +01:00
|
|
|
var paths = this._elems2paths([_target]);
|
|
|
|
if(paths[0]) dst = paths[0];
|
2014-11-19 18:58:02 +01:00
|
|
|
|
|
|
|
// check if target is a file --> use it's directory instead
|
2014-11-24 17:25:05 +01:00
|
|
|
if(_target.id)
|
2014-11-19 18:58:02 +01:00
|
|
|
{
|
2014-11-24 17:25:05 +01:00
|
|
|
var data = egw.dataGetUIDdata(_target.id);
|
|
|
|
if (!data || data.data.mime != 'httpd/unix-directory')
|
|
|
|
{
|
|
|
|
dst = this.dirname(dst);
|
|
|
|
}
|
2014-11-19 18:58:02 +01:00
|
|
|
}
|
2013-04-13 14:44:50 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 17:17:54 +02:00
|
|
|
this._do_action(_action.id.replace("file_drop_",''), src, false, dst || nm_dst);
|
2013-04-11 12:46:39 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-08-27 22:40:15 +02:00
|
|
|
/**
|
|
|
|
* Handle a native / HTML5 file drop from system
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-08-27 22:40:15 +02:00
|
|
|
* This is a callback from nextmatch to prevent the default link action, and just upload instead.
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2013-08-27 22:40:15 +02:00
|
|
|
* @param {string} row_uid UID of the row the files were dropped on
|
2014-09-09 01:02:46 +02:00
|
|
|
* @param {Files[]} files
|
2013-08-27 22:40:15 +02:00
|
|
|
*/
|
2014-09-09 01:02:46 +02:00
|
|
|
filedrop: function(row_uid, files)
|
2013-08-27 22:40:15 +02:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
var data = egw.dataGetUIDdata(row_uid);
|
2013-11-12 23:41:52 +01:00
|
|
|
files = files || window.event.dataTransfer.files;
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-11-13 18:20:13 +01:00
|
|
|
var path = typeof data != 'undefined' && data.data.mime == "httpd/unix-directory" ? data.data.path : this.get_path();
|
2013-08-27 22:40:15 +02:00
|
|
|
var widget = this.et2.getWidgetById('upload');
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-08-27 22:40:15 +02:00
|
|
|
// Override finish to specify a potentially different path
|
2015-05-11 21:33:57 +02:00
|
|
|
var old_onfinishone = widget.options.onFinishOne;
|
|
|
|
var old_onfinish = widget.options.onFinish;
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2015-02-23 18:42:21 +01:00
|
|
|
widget.options.onFinishOne = function(_event, _file_count) {
|
2013-08-27 22:40:15 +02:00
|
|
|
self.upload(_event, _file_count, path);
|
2014-01-22 09:42:42 +01:00
|
|
|
};
|
2015-05-11 21:33:57 +02:00
|
|
|
|
|
|
|
widget.options.onFinish = function() {
|
|
|
|
widget.options.onFinish = old_onfinish;
|
|
|
|
widget.options.onFinishOne = old_onfinishone;
|
2016-02-24 11:41:18 +01:00
|
|
|
};
|
2013-08-27 22:40:15 +02:00
|
|
|
// This triggers the upload
|
|
|
|
widget.set_value(files);
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-08-27 22:40:15 +02:00
|
|
|
// Return false to prevent the link
|
|
|
|
return false;
|
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-04-12 19:57:12 +02:00
|
|
|
/**
|
|
|
|
* Change readonly state for given directory
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-01-22 09:42:42 +01:00
|
|
|
* Get call/transported with each get_rows call, but should only by applied to UI if matching curent dir
|
2013-11-04 21:54:23 +01:00
|
|
|
*
|
2014-01-22 09:42:42 +01:00
|
|
|
* @param {string} _path
|
|
|
|
* @param {boolean} _ro
|
2013-04-12 19:57:12 +02:00
|
|
|
*/
|
|
|
|
set_readonly: function(_path, _ro)
|
|
|
|
{
|
|
|
|
//alert('set_readonly("'+_path+'", '+_ro+')');
|
2013-10-07 18:53:13 +02:00
|
|
|
if (!this.path_widget) // widget not yet ready, try later
|
|
|
|
{
|
|
|
|
this.readonly = [_path, _ro];
|
|
|
|
return;
|
|
|
|
}
|
2015-01-13 22:56:54 +01:00
|
|
|
for(var id in this.path_widget)
|
2013-04-12 19:57:12 +02:00
|
|
|
{
|
2015-01-13 22:56:54 +01:00
|
|
|
var path = this.get_path(id);
|
|
|
|
|
|
|
|
if (_path == path)
|
2013-04-12 19:57:12 +02:00
|
|
|
{
|
2015-01-13 22:56:54 +01:00
|
|
|
var ids = ['button[linkpaste]', 'button[paste]', 'button[createdir]', 'button[symlink]', 'upload'];
|
|
|
|
for(var i=0; i < ids.length; ++i)
|
2013-04-12 19:57:12 +02:00
|
|
|
{
|
2015-01-13 22:56:54 +01:00
|
|
|
var widget = etemplate2.getById(id).widgetContainer.getWidgetById(ids[i]);
|
|
|
|
if (widget)
|
2013-04-12 19:57:12 +02:00
|
|
|
{
|
2016-04-18 12:37:08 +02:00
|
|
|
widget.set_readonly(_ro);
|
2013-04-12 19:57:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-01 17:40:14 +02:00
|
|
|
},
|
2013-11-04 21:54:23 +01:00
|
|
|
|
2013-10-01 17:40:14 +02:00
|
|
|
/**
|
2014-02-10 19:37:51 +01:00
|
|
|
* Row or filename in select-file dialog clicked
|
2014-01-22 09:42:42 +01:00
|
|
|
*
|
2014-02-10 19:37:51 +01:00
|
|
|
* @param {jQuery.event} event
|
2014-01-22 09:42:42 +01:00
|
|
|
* @param {et2_widget} widget
|
2013-10-01 17:40:14 +02:00
|
|
|
*/
|
2014-02-10 19:37:51 +01:00
|
|
|
select_clicked: function(event, widget)
|
2013-10-01 17:40:14 +02:00
|
|
|
{
|
2014-02-10 19:37:51 +01:00
|
|
|
if (!widget || typeof widget.value != 'object')
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-12-18 14:46:44 +01:00
|
|
|
else if (widget.value.is_dir) // true for "httpd/unix-directory" and "egw/*"
|
2013-10-01 17:40:14 +02:00
|
|
|
{
|
|
|
|
var path = null;
|
|
|
|
// Cannot do this, there are multiple widgets named path
|
|
|
|
// widget.getRoot().getWidgetById("path");
|
|
|
|
widget.getRoot().iterateOver(function(widget) {
|
|
|
|
if(widget.id == "path") path = widget;
|
|
|
|
},null, et2_textbox);
|
|
|
|
if(path)
|
|
|
|
{
|
2014-02-10 19:37:51 +01:00
|
|
|
path.set_value(widget.value.path);
|
2013-10-01 17:40:14 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 19:37:51 +01:00
|
|
|
else if (this.et2 && this.et2.getArrayMgr('content').getEntry('mode') != 'open-multiple')
|
2013-10-04 11:28:10 +02:00
|
|
|
{
|
2014-02-10 19:37:51 +01:00
|
|
|
var editfield = this.et2.getWidgetById('name');
|
|
|
|
if(editfield)
|
|
|
|
{
|
|
|
|
editfield.set_value(widget.value.name);
|
|
|
|
}
|
2013-10-04 11:28:10 +02:00
|
|
|
}
|
2014-02-10 19:37:51 +01:00
|
|
|
else
|
2014-01-22 09:42:42 +01:00
|
|
|
{
|
2014-02-10 19:37:51 +01:00
|
|
|
var file = widget.value.name;
|
|
|
|
widget.getParent().iterateOver(function(widget)
|
2014-01-22 09:42:42 +01:00
|
|
|
{
|
2014-02-10 19:37:51 +01:00
|
|
|
if(widget.options.selected_value == file)
|
|
|
|
{
|
|
|
|
widget.set_value(widget.get_value() == file ? widget.options.unselected_value : file);
|
|
|
|
}
|
|
|
|
}, null, et2_checkbox);
|
2013-11-13 00:51:05 +01:00
|
|
|
|
2014-02-10 19:37:51 +01:00
|
|
|
}
|
2013-11-13 00:51:05 +01:00
|
|
|
// Stop event or it will toggle back off
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
return false;
|
2014-07-31 19:45:57 +02:00
|
|
|
},
|
2014-10-13 19:23:33 +02:00
|
|
|
|
2014-07-31 19:45:57 +02:00
|
|
|
/**
|
|
|
|
* Set Sudo button's label and change its onclick handler according to its action
|
2014-10-13 19:23:33 +02:00
|
|
|
*
|
2014-07-31 19:45:57 +02:00
|
|
|
* @param {widget object} _widget sudo buttononly
|
|
|
|
* @param {string} _action string of action type {login|logout}
|
|
|
|
*/
|
|
|
|
set_sudoButton: function (_widget, _action)
|
|
|
|
{
|
|
|
|
var widget = _widget || this.et2.getWidgetById('sudouser');
|
|
|
|
if (widget)
|
|
|
|
{
|
|
|
|
switch (_action)
|
|
|
|
{
|
|
|
|
case 'login':
|
|
|
|
widget.set_label('Logout');
|
|
|
|
this.et2._inst.submit(widget);
|
|
|
|
break;
|
2014-10-13 19:23:33 +02:00
|
|
|
|
2014-07-31 19:45:57 +02:00
|
|
|
default:
|
|
|
|
widget.set_label('Superuser');
|
|
|
|
widget.onclick = function(){
|
|
|
|
jQuery('.superuser').css('display','inline');
|
2014-12-03 17:25:10 +01:00
|
|
|
};
|
2014-07-31 19:45:57 +02:00
|
|
|
}
|
|
|
|
}
|
2013-04-12 10:56:28 +02:00
|
|
|
}
|
2013-04-23 01:00:29 +02:00
|
|
|
});
|