2024-02-08 21:17:55 +01:00
|
|
|
/**
|
|
|
|
* EGroupware egw_dragdrop_shoelaceTree - egw action framework
|
|
|
|
*
|
|
|
|
* @link https://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
|
|
|
|
*/
|
|
|
|
import {egwActionObjectInterface} from "./egw_action";
|
|
|
|
import {Et2Tree} from "../etemplate/Et2Tree/Et2Tree";
|
2024-07-31 17:52:24 +02:00
|
|
|
import {EGW_AI_DRAG_ENTER, EGW_AI_DRAG_OUT, EGW_AO_STATE_FOCUSED, EGW_AO_STATE_SELECTED} from "./egw_action_constants";
|
2024-02-08 21:17:55 +01:00
|
|
|
import {egwBitIsSet} from "./egw_action_common";
|
2024-07-25 14:24:57 +02:00
|
|
|
import {SlTreeItem} from "@shoelace-style/shoelace";
|
2024-07-31 17:52:24 +02:00
|
|
|
import {EgwActionObject} from "./EgwActionObject";
|
2024-02-08 21:17:55 +01:00
|
|
|
|
2024-02-21 09:36:56 +01:00
|
|
|
|
2024-02-21 16:13:51 +01:00
|
|
|
export const EXPAND_FOLDER_ON_DRAG_DROP_TIMEOUT = 1000
|
2024-02-21 09:36:56 +01:00
|
|
|
|
2024-07-25 14:24:57 +02:00
|
|
|
export class EgwDragDropShoelaceTree extends egwActionObjectInterface{
|
|
|
|
node: SlTreeItem;
|
|
|
|
id: string;
|
|
|
|
tree: Et2Tree;
|
2024-07-31 17:52:24 +02:00
|
|
|
|
|
|
|
// Reference to the widget that's handling actions for us
|
|
|
|
public findActionTargetHandler : EgwActionObject;
|
2024-07-25 14:24:57 +02:00
|
|
|
constructor(_tree:Et2Tree, _itemId: string) {
|
2024-02-08 21:17:55 +01:00
|
|
|
|
2024-07-25 14:24:57 +02:00
|
|
|
super();
|
|
|
|
this.node = _tree.getDomNode(_itemId);
|
|
|
|
this.id = _itemId
|
|
|
|
this.tree = _tree
|
2024-07-31 17:52:24 +02:00
|
|
|
this.findActionTargetHandler = _tree.widget_object;
|
2024-07-25 14:24:57 +02:00
|
|
|
this.doGetDOMNode = function () {
|
|
|
|
return this.node;
|
2024-02-08 21:17:55 +01:00
|
|
|
}
|
2024-06-27 17:05:12 +02:00
|
|
|
let timeout: NodeJS.Timeout;
|
2024-02-08 21:17:55 +01:00
|
|
|
|
2024-07-25 14:24:57 +02:00
|
|
|
this.doTriggerEvent = function (_event) {
|
2024-06-27 17:05:12 +02:00
|
|
|
if (_event == EGW_AI_DRAG_ENTER)
|
2024-02-08 21:17:55 +01:00
|
|
|
{
|
2024-06-27 17:05:12 +02:00
|
|
|
|
2024-07-31 17:52:24 +02:00
|
|
|
this.node.classList.add("draggedOver", "drop-hover");
|
2024-06-27 17:05:12 +02:00
|
|
|
timeout = setTimeout(() => {
|
2024-02-21 09:36:56 +01:00
|
|
|
if (this.node.classList.contains("draggedOver"))
|
|
|
|
{
|
|
|
|
this.node.expanded = true
|
|
|
|
}
|
|
|
|
}, EXPAND_FOLDER_ON_DRAG_DROP_TIMEOUT)
|
2024-02-08 21:17:55 +01:00
|
|
|
}
|
|
|
|
if (_event == EGW_AI_DRAG_OUT)
|
|
|
|
{
|
2024-07-31 17:52:24 +02:00
|
|
|
(this.node).classList.remove("draggedOver", "drop-hover");
|
2024-06-27 17:05:12 +02:00
|
|
|
clearTimeout(timeout)
|
2024-02-08 21:17:55 +01:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-07-25 14:24:57 +02:00
|
|
|
this.doSetState = function (_state) {
|
2024-02-08 21:17:55 +01:00
|
|
|
if (!_tree || !_tree.focusItem) return;
|
|
|
|
|
|
|
|
// Update the "focused" flag
|
|
|
|
if (egwBitIsSet(_state, EGW_AO_STATE_FOCUSED))
|
|
|
|
{
|
|
|
|
_tree.focusItem(this.id);
|
|
|
|
}
|
|
|
|
if (egwBitIsSet(_state, EGW_AO_STATE_SELECTED))
|
|
|
|
{
|
|
|
|
// _tree.selectItem(this.id, false); // false = do not trigger onSelect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|