2011-03-24 18:06:44 +01:00
|
|
|
/**
|
|
|
|
* eGroupWare egw_action framework - egw action framework
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel <as@stylite.de>
|
|
|
|
* @copyright 2011 by Andreas Stöckel
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package egw_action
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2011-08-03 16:04:30 +02:00
|
|
|
/*egw:uses
|
|
|
|
egw_action;
|
|
|
|
egw_action_common;
|
|
|
|
egw_action_popup;
|
|
|
|
jquery.jquery;
|
|
|
|
jquery.jquery-ui;
|
|
|
|
*/
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the drag and drop handlers
|
|
|
|
*/
|
|
|
|
if (typeof window._egwActionClasses == "undefined")
|
2014-02-25 16:02:49 +01:00
|
|
|
window._egwActionClasses = {};
|
2011-03-24 18:06:44 +01:00
|
|
|
_egwActionClasses["drag"] = {
|
|
|
|
"actionConstructor": egwDragAction,
|
|
|
|
"implementation": getDragImplementation
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
_egwActionClasses["drop"] = {
|
|
|
|
"actionConstructor": egwDropAction,
|
|
|
|
"implementation": getDropImplementation
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The egwDragAction class overwrites the egwAction class and adds the new
|
|
|
|
* "dragType" propery. The "onExecute" event of the drag action will be called
|
|
|
|
* whenever dragging starts. The onExecute JS handler should return the
|
|
|
|
* drag-drop helper object - otherwise an default helper will be generated.
|
2014-02-25 16:02:49 +01:00
|
|
|
*
|
|
|
|
* @param {egwAction} _id
|
|
|
|
* @param {string} _handler
|
|
|
|
* @param {string} _caption
|
|
|
|
* @param {string} _icon
|
|
|
|
* @param {(string|function)} _onExecute
|
|
|
|
* @param {bool} _allowOnMultiple
|
|
|
|
* @returns {egwDragAction}
|
2011-03-24 18:06:44 +01:00
|
|
|
*/
|
|
|
|
function egwDragAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple)
|
|
|
|
{
|
|
|
|
var action = new egwAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple);
|
|
|
|
|
|
|
|
action.type = "drag";
|
|
|
|
action.dragType = "default";
|
|
|
|
action.hideOnDisabled = true;
|
|
|
|
|
|
|
|
action.set_dragType = function(_value) {
|
|
|
|
action.dragType = _value;
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
_dragActionImpl = null;
|
|
|
|
|
|
|
|
function getDragImplementation()
|
|
|
|
{
|
|
|
|
if (!_dragActionImpl)
|
|
|
|
{
|
|
|
|
_dragActionImpl = new egwDragActionImplementation();
|
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
return _dragActionImpl;
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function egwDragActionImplementation()
|
|
|
|
{
|
|
|
|
var ai = new egwActionImplementation();
|
|
|
|
|
|
|
|
ai.type = "drag";
|
|
|
|
|
|
|
|
ai.helper = null;
|
|
|
|
ai.ddTypes = [];
|
|
|
|
ai.selected = [];
|
|
|
|
|
|
|
|
ai.doRegisterAction = function(_aoi, _callback, _context)
|
|
|
|
{
|
|
|
|
var node = _aoi.getDOMNode();
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
2011-03-25 14:12:24 +01:00
|
|
|
// Prevent selection
|
|
|
|
node.onselectstart = function () {
|
|
|
|
return false;
|
|
|
|
};
|
2013-08-29 00:31:14 +02:00
|
|
|
if (!(window.FileReader && 'draggable' in document.createElement('span')) )
|
|
|
|
{
|
|
|
|
// No DnD support
|
|
|
|
return;
|
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
|
2013-08-29 00:31:14 +02:00
|
|
|
// It shouldn't be so hard to get the action...
|
|
|
|
var action = null;
|
|
|
|
var groups = _context.getActionImplementationGroups();
|
|
|
|
if(!groups.drag) return;
|
|
|
|
for(var i = 0; i < groups.drag.length; i++)
|
|
|
|
{
|
|
|
|
// dragType 'file' says it can be dragged as a file
|
|
|
|
if(groups.drag[i].link.actionObj.dragType == 'file')
|
|
|
|
{
|
|
|
|
action = groups.drag[i].link.actionObj;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(action)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* We found an action with dragType 'file', so by holding Ctrl
|
|
|
|
* key & dragging, user can drag from browser to system.
|
|
|
|
* The global data store must provide a full, absolute URL in 'download_url'
|
|
|
|
* and a mime in 'mime'.
|
2014-02-25 16:02:49 +01:00
|
|
|
*
|
2013-08-29 00:31:14 +02:00
|
|
|
* Unfortunately, Native DnD to drag the file conflicts with jQueryUI draggable,
|
|
|
|
* which handles all the other DnD actions. We get around this by:
|
|
|
|
* 1. Require the user indicate a file drag with Ctrl key
|
|
|
|
* 2. Disable jQueryUI draggable, then turn on native draggable attribute
|
2014-02-25 16:02:49 +01:00
|
|
|
* This way we can at least toggle which one is operating, so they
|
2013-08-29 00:31:14 +02:00
|
|
|
* both work alternately if not together.
|
|
|
|
*/
|
|
|
|
// Native DnD - Doesn't play nice with jQueryUI Sortable
|
|
|
|
// Tell jQuery to include this property
|
|
|
|
jQuery.event.props.push('dataTransfer');
|
2014-02-25 16:02:49 +01:00
|
|
|
|
2013-08-29 00:31:14 +02:00
|
|
|
$j(node).off("mousedown")
|
|
|
|
.on("mousedown", function(event) {
|
2013-10-09 11:12:02 +02:00
|
|
|
$j(node).draggable("option","disabled",event.ctrlKey || event.metaKey);
|
2014-02-25 16:02:49 +01:00
|
|
|
$j(this).attr("draggable", event.ctrlKey || event.metaKey ? "true" : "");
|
|
|
|
|
2013-08-29 00:31:14 +02:00
|
|
|
// Disabling draggable adds some UI classes, but we don't care so remove them
|
|
|
|
$j(node).removeClass("ui-draggable-disabled ui-state-disabled");
|
2013-10-09 11:12:02 +02:00
|
|
|
if(!(event.ctrlKey || event.metaKey) || !this.addEventListener) return;
|
2013-08-29 00:31:14 +02:00
|
|
|
})
|
|
|
|
.on("dragstart", function(event) {
|
|
|
|
if(event.dataTransfer == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
event.dataTransfer.effectAllowed="copy";
|
2013-08-29 00:31:14 +02:00
|
|
|
|
|
|
|
// Get all selected
|
|
|
|
// Multiples aren't supported by event.dataTransfer, yet, so
|
|
|
|
// select only the row they clicked on.
|
|
|
|
// var selected = _context.getSelectedLinks('drag');
|
|
|
|
var selected = [_context];
|
|
|
|
_context.parent.setAllSelected(false);
|
|
|
|
_context.setSelected(true);
|
2014-02-25 16:02:49 +01:00
|
|
|
|
2013-08-29 00:31:14 +02:00
|
|
|
// Set file data
|
|
|
|
for(var i = 0; i < selected.length; i++)
|
|
|
|
{
|
|
|
|
var data = egw.dataGetUIDdata(selected[i].id);
|
|
|
|
if(data && data.data.mime && data.data.download_url)
|
|
|
|
{
|
|
|
|
var url = data.data.download_url;
|
2014-02-25 16:02:49 +01:00
|
|
|
|
2013-09-17 17:34:39 +02:00
|
|
|
// NEED an absolute URL
|
|
|
|
if (url[0] == '/') url = egw.link(url);
|
|
|
|
// egw.link adds the webserver, but that might not be an absolute URL - try again
|
|
|
|
if (url[0] == '/') url = window.location.origin+url;
|
2014-02-25 16:02:49 +01:00
|
|
|
|
2013-08-29 00:31:14 +02:00
|
|
|
// Unfortunately, dragging files is currently only supported by Chrome
|
|
|
|
if(navigator && navigator.userAgent.indexOf('Chrome'))
|
|
|
|
{
|
|
|
|
event.dataTransfer.setData("DownloadURL", data.data.mime+':'+data.data.name+':'+url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Include URL as a fallback
|
|
|
|
event.dataTransfer.setData("text/uri-list", url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(event.dataTransfer.types.length == 0)
|
|
|
|
{
|
|
|
|
// No file data? Abort: drag does nothing
|
|
|
|
event.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
|
2013-08-29 00:31:14 +02:00
|
|
|
// Create drag icon
|
|
|
|
_callback.call(_context, _context, ai);
|
|
|
|
// Drag icon must be visible for setDragImage() - we'll remove it on drag
|
|
|
|
$j("body").append(ai.helper);
|
|
|
|
event.dataTransfer.setDragImage(ai.helper[0],-12,-12);
|
|
|
|
})
|
|
|
|
.on("drag", function(e) {
|
|
|
|
// Remove the helper, it has been copied into the dataTransfer object now
|
|
|
|
// Hopefully user didn't notice it...
|
2013-11-07 00:12:32 +01:00
|
|
|
if(e.dataTransfer != null)
|
|
|
|
{
|
|
|
|
ai.helper.remove();
|
|
|
|
}
|
2013-08-29 00:31:14 +02:00
|
|
|
});
|
|
|
|
}
|
2011-07-03 11:00:36 +02:00
|
|
|
$j(node).draggable(
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
|
|
|
"distance": 20,
|
|
|
|
"cursor": "move",
|
|
|
|
"cursorAt": { top: -12, left: -12 },
|
|
|
|
"helper": function(e) {
|
|
|
|
// The helper function is called before the start function
|
|
|
|
// is evoked. Call the given callback function. The callback
|
|
|
|
// function will gather the selected elements and action links
|
|
|
|
// and call the doExecuteImplementation function. This
|
|
|
|
// will call the onExecute function of the first action
|
|
|
|
// in order to obtain the helper object (stored in ai.helper)
|
|
|
|
// and the multiple dragDropTypes (ai.ddTypes)
|
|
|
|
_callback.call(_context, false, ai);
|
|
|
|
|
2011-07-03 11:00:36 +02:00
|
|
|
$j(node).data("ddTypes", ai.ddTypes);
|
|
|
|
$j(node).data("selected", ai.selected);
|
2011-03-24 18:06:44 +01:00
|
|
|
|
2011-03-25 14:12:24 +01:00
|
|
|
if (ai.helper)
|
|
|
|
{
|
|
|
|
// Append the helper object to the body element - this
|
|
|
|
// fixes a bug in IE: If the element isn't inserted into
|
|
|
|
// the DOM-tree jquery appends it to the parent node.
|
|
|
|
// In case this is a table it doesn't work correctly
|
2011-07-03 11:00:36 +02:00
|
|
|
$j("body").append(ai.helper);
|
2011-03-25 14:12:24 +01:00
|
|
|
return ai.helper;
|
|
|
|
}
|
|
|
|
|
2011-03-24 18:06:44 +01:00
|
|
|
// Return an empty div if the helper dom node is not set
|
2011-07-03 11:00:36 +02:00
|
|
|
return $j(document.createElement("div"));
|
2011-03-24 18:06:44 +01:00
|
|
|
},
|
|
|
|
"start": function(e) {
|
|
|
|
return ai.helper != null;
|
|
|
|
},
|
2011-03-25 14:12:24 +01:00
|
|
|
// Solves problem with scroll position changing in the grid
|
2011-03-24 19:17:27 +01:00
|
|
|
// component
|
|
|
|
"refreshPositions": true,
|
2011-03-25 14:12:24 +01:00
|
|
|
"scroll": false,
|
2011-05-28 17:24:31 +02:00
|
|
|
"containment": "document",
|
|
|
|
"iframeFix": true
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
);
|
2014-02-25 16:02:49 +01:00
|
|
|
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
ai.doUnregisterAction = function(_aoi)
|
|
|
|
{
|
2011-06-26 16:57:05 +02:00
|
|
|
var node = _aoi.getDOMNode();
|
|
|
|
|
2013-07-20 15:38:09 +02:00
|
|
|
if (node && $j(node).data("uiDraggable")){
|
2011-07-03 11:00:36 +02:00
|
|
|
$j(node).draggable("destroy");
|
2011-06-26 16:57:05 +02:00
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the context menu and shows it at the given position/DOM-Node.
|
2014-02-25 16:02:49 +01:00
|
|
|
*
|
|
|
|
* @param {string} _context
|
|
|
|
* @param {array} _selected
|
|
|
|
* @param {object} _links
|
2011-03-24 18:06:44 +01:00
|
|
|
*/
|
|
|
|
ai.doExecuteImplementation = function(_context, _selected, _links)
|
|
|
|
{
|
|
|
|
// Reset the helper object of the action implementation
|
|
|
|
this.helper = null;
|
|
|
|
var hasLink = false;
|
|
|
|
|
|
|
|
// Store the drag-drop types
|
|
|
|
this.ddTypes = [];
|
|
|
|
this.selected = _selected;
|
|
|
|
|
|
|
|
// Call the onExecute event of the first actionObject
|
2011-04-23 11:07:31 +02:00
|
|
|
for (var k in _links)
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
|
|
|
if (_links[k].visible)
|
|
|
|
{
|
|
|
|
hasLink = true;
|
|
|
|
|
|
|
|
// Only execute the following code if a JS function is registered
|
|
|
|
// for the action and this is the first action link
|
2011-05-07 13:22:23 +02:00
|
|
|
if (!this.helper && _links[k].actionObj.onExecute.hasHandler())
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
|
|
|
this.helper = _links[k].actionObj.execute(_selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push the dragType of the associated action object onto the
|
|
|
|
// drag type list - this allows an element to support multiple
|
|
|
|
// drag/drop types.
|
2013-04-11 14:53:23 +02:00
|
|
|
var type = $j.isArray(_links[k].actionObj.dragType) ? _links[k].actionObj.dragType : [_links[k].actionObj.dragType];
|
|
|
|
for(var i = 0; i < type.length; i++)
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
2013-04-11 14:53:23 +02:00
|
|
|
if (this.ddTypes.indexOf(type[i]) == -1)
|
|
|
|
{
|
|
|
|
this.ddTypes.push(type[i]);
|
|
|
|
}
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no helper has been defined, create an default one
|
|
|
|
if (!this.helper && hasLink)
|
|
|
|
{
|
2011-07-03 11:00:36 +02:00
|
|
|
this.helper = $j(document.createElement("div"));
|
2011-03-24 18:06:44 +01:00
|
|
|
this.helper.addClass("egw_action_ddHelper");
|
|
|
|
this.helper.text("(" + _selected.length + ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
return ai;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The egwDropAction class overwrites the egwAction class and adds the "acceptedTypes"
|
2014-02-25 16:02:49 +01:00
|
|
|
* property. This array should contain all "dragTypes" the drop action is allowed to
|
|
|
|
*
|
|
|
|
* @param {egwAction} _id
|
|
|
|
* @param {string} _handler
|
|
|
|
* @param {string} _caption
|
|
|
|
* @param {string} _icon
|
|
|
|
* @param {(string|function)} _onExecute
|
|
|
|
* @param {bool} _allowOnMultiple
|
|
|
|
* @returns {egwDropAction}
|
2011-03-24 18:06:44 +01:00
|
|
|
*/
|
|
|
|
function egwDropAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple)
|
|
|
|
{
|
|
|
|
var action = new egwAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple);
|
|
|
|
|
|
|
|
action.type = "drop";
|
|
|
|
action.acceptedTypes = ["default"];
|
|
|
|
action.canHaveChildren = ["drag","popup"];
|
|
|
|
action["default"] = false;
|
|
|
|
action.order = 0;
|
|
|
|
action.group = 0;
|
|
|
|
|
|
|
|
action.set_default = function(_value) {
|
|
|
|
action["default"] = _value;
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
action.set_order = function(_value) {
|
|
|
|
action.order = _value;
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
action.set_group = function(_value) {
|
|
|
|
action.group = _value;
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The acceptType property allows strings as well as arrays - strings are
|
|
|
|
* automatically included in an array.
|
2014-02-25 16:02:49 +01:00
|
|
|
*
|
|
|
|
* @param {(string|array)} _value
|
2011-03-24 18:06:44 +01:00
|
|
|
*/
|
|
|
|
action.set_acceptedTypes = function(_value) {
|
|
|
|
if (_value instanceof Array)
|
|
|
|
{
|
|
|
|
action.acceptedTypes = _value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
action.acceptedTypes = [_value];
|
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
var
|
|
|
|
_dropActionImpl = null;
|
|
|
|
|
|
|
|
function getDropImplementation()
|
|
|
|
{
|
|
|
|
if (!_dropActionImpl)
|
|
|
|
{
|
|
|
|
_dropActionImpl = new egwDropActionImplementation();
|
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
return _dropActionImpl;
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var EGW_AI_DRAG = 0x0100; // Use the first byte as mask for event types - 01 is for events used with drag stuff
|
|
|
|
var EGW_AI_DRAG_OUT = EGW_AI_DRAG | 0x01;
|
|
|
|
var EGW_AI_DRAG_OVER = EGW_AI_DRAG | 0x02;
|
|
|
|
|
|
|
|
function egwDropActionImplementation()
|
|
|
|
{
|
|
|
|
var ai = new egwActionImplementation();
|
|
|
|
|
|
|
|
ai.type = "drop";
|
|
|
|
|
|
|
|
ai.doRegisterAction = function(_aoi, _callback, _context)
|
|
|
|
{
|
|
|
|
var node = _aoi.getDOMNode();
|
2011-06-26 16:57:05 +02:00
|
|
|
var self = this;
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
2011-07-03 11:00:36 +02:00
|
|
|
$j(node).droppable(
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
|
|
|
"accept": function(_draggable) {
|
2011-06-19 13:15:37 +02:00
|
|
|
if (typeof _draggable.data("ddTypes") != "undefined")
|
|
|
|
{
|
2011-06-26 16:57:05 +02:00
|
|
|
var accepted = self._fetchAccepted(
|
|
|
|
_callback.call(_context, "links", self, EGW_AO_EXEC_THIS));
|
2011-03-24 18:06:44 +01:00
|
|
|
|
2011-06-19 13:15:37 +02:00
|
|
|
// Check whether all drag types of the selected objects
|
|
|
|
// are accepted
|
|
|
|
var ddTypes = _draggable.data("ddTypes");
|
2011-03-24 18:06:44 +01:00
|
|
|
|
2011-06-19 13:15:37 +02:00
|
|
|
for (var i = 0; i < ddTypes.length; i++)
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
2013-04-11 14:53:23 +02:00
|
|
|
if (accepted.indexOf(ddTypes[i]) != -1)
|
2011-06-19 13:15:37 +02:00
|
|
|
{
|
2013-04-11 14:53:23 +02:00
|
|
|
return true;
|
2011-06-19 13:15:37 +02:00
|
|
|
}
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
|
2013-04-11 14:53:23 +02:00
|
|
|
return false;
|
2011-06-19 13:15:37 +02:00
|
|
|
}
|
2011-03-24 18:06:44 +01:00
|
|
|
},
|
|
|
|
"drop": function(event, ui) {
|
|
|
|
var draggable = ui.draggable;
|
|
|
|
var ddTypes = draggable.data("ddTypes");
|
|
|
|
var selected = draggable.data("selected");
|
|
|
|
|
2011-06-26 16:57:05 +02:00
|
|
|
var links = _callback.call(_context, "links", self, EGW_AO_EXEC_THIS);
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
// Disable all links which only accept types which are not
|
|
|
|
// inside ddTypes
|
2011-04-23 11:07:31 +02:00
|
|
|
for (var k in links)
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
|
|
|
var accepted = links[k].actionObj.acceptedTypes;
|
|
|
|
|
2014-02-25 16:02:49 +01:00
|
|
|
var enabled = false;
|
2011-03-24 18:06:44 +01:00
|
|
|
for (var i = 0; i < ddTypes.length; i++)
|
|
|
|
{
|
2013-04-11 14:53:23 +02:00
|
|
|
if (accepted.indexOf(ddTypes[i]) != -1)
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
2013-04-11 14:53:23 +02:00
|
|
|
enabled = true;
|
2014-02-25 16:02:49 +01:00
|
|
|
break;
|
2013-04-11 14:53:23 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-29 21:20:36 +02:00
|
|
|
// Check for allowing multiple selected
|
|
|
|
if(!links[k].actionObj.allowOnMultiple && selected.length > 1)
|
|
|
|
{
|
|
|
|
enabled = false;
|
|
|
|
}
|
2013-04-11 14:53:23 +02:00
|
|
|
if(!enabled)
|
|
|
|
{
|
|
|
|
links[k].enabled = false;
|
2014-02-25 16:02:49 +01:00
|
|
|
links[k].visible = !links[k].actionObj.hideOnDisabled;
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether there is only one link
|
|
|
|
var cnt = 0;
|
|
|
|
var lnk = null;
|
2011-04-23 11:07:31 +02:00
|
|
|
for (var k in links)
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
|
|
|
if (links[k].enabled && links[k].visible)
|
|
|
|
{
|
|
|
|
lnk = links[k];
|
|
|
|
cnt += 1 + links[k].actionObj.children.length;
|
2013-05-29 21:20:36 +02:00
|
|
|
|
|
|
|
// Add ui, so you know what happened where
|
|
|
|
lnk.actionObj.ui = ui;
|
|
|
|
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt == 1)
|
|
|
|
{
|
2011-07-21 12:50:33 +02:00
|
|
|
window.setTimeout(function() {
|
|
|
|
lnk.actionObj.execute(selected, _context);
|
|
|
|
},0);
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt > 1)
|
|
|
|
{
|
|
|
|
// More than one drop action link is associated
|
|
|
|
// to the drop event - show those as a popup menu
|
|
|
|
// and let the user decide which one to use.
|
|
|
|
// This is possible as the popup and the popup action
|
|
|
|
// object and the drop action object share same
|
|
|
|
// set of properties.
|
|
|
|
var popup = getPopupImplementation();
|
2012-03-16 13:30:52 +01:00
|
|
|
var pos = popup._getPageXY(event.originalEvent);
|
2011-03-25 14:12:24 +01:00
|
|
|
window.setTimeout(function() {
|
|
|
|
popup.doExecuteImplementation(pos, selected, links,
|
|
|
|
_context);
|
|
|
|
}, 0); // Timeout is needed to have it working in IE
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_aoi.triggerEvent(EGW_AI_DRAG_OUT);
|
|
|
|
},
|
|
|
|
"over": function() {
|
|
|
|
_aoi.triggerEvent(EGW_AI_DRAG_OVER);
|
|
|
|
},
|
|
|
|
"out": function() {
|
|
|
|
_aoi.triggerEvent(EGW_AI_DRAG_OUT);
|
|
|
|
},
|
2013-04-11 14:53:23 +02:00
|
|
|
"tolerance": "pointer",
|
|
|
|
activeClass: "ui-state-hover",
|
2013-05-29 00:09:03 +02:00
|
|
|
hoverClass: "ui-state-active",
|
|
|
|
// Greedy is for nested droppables - children consume the action
|
2014-02-25 16:02:49 +01:00
|
|
|
greedy: true
|
2011-03-24 18:06:44 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
ai.doUnregisterAction = function(_aoi)
|
|
|
|
{
|
2011-06-26 16:57:05 +02:00
|
|
|
var node = _aoi.getDOMNode();
|
|
|
|
|
2013-07-20 15:38:09 +02:00
|
|
|
if (node && $j(node).data("uiDroppable")) {
|
2011-07-03 11:00:36 +02:00
|
|
|
$j(node).droppable("destroy");
|
2011-06-26 16:57:05 +02:00
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
ai._fetchAccepted = function(_links)
|
|
|
|
{
|
|
|
|
// Accumulate the accepted types
|
|
|
|
var accepted = [];
|
2011-04-23 11:07:31 +02:00
|
|
|
for (var k in _links)
|
2011-03-24 18:06:44 +01:00
|
|
|
{
|
|
|
|
for (var i = 0; i < _links[k].actionObj.acceptedTypes.length; i++)
|
|
|
|
{
|
|
|
|
var type = _links[k].actionObj.acceptedTypes[i];
|
|
|
|
|
|
|
|
if (accepted.indexOf(type) == -1)
|
|
|
|
{
|
|
|
|
accepted.push(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return accepted;
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the context menu and shows it at the given position/DOM-Node.
|
2014-02-25 16:02:49 +01:00
|
|
|
*
|
|
|
|
* @param {string} _context
|
|
|
|
* @param {array} _selected
|
|
|
|
* @param {object} _links
|
2011-03-24 18:06:44 +01:00
|
|
|
*/
|
|
|
|
ai.doExecuteImplementation = function(_context, _selected, _links)
|
|
|
|
{
|
|
|
|
if (_context == "links")
|
|
|
|
{
|
|
|
|
return _links;
|
|
|
|
}
|
2014-02-25 16:02:49 +01:00
|
|
|
};
|
2011-03-24 18:06:44 +01:00
|
|
|
|
|
|
|
return ai;
|
|
|
|
}
|