MODX Community

Give an confirm on draging files and folders in tree

Hello is it possible to give an alert in the files tree when someone moves a file (drag drop/ sort)
We like to give an alert that it could damage the working of the site when they move files/folders in de file manager or tree.

I have found this: but I have no idea if this is the one that is used there and how to invoke/use this https://docs.modx.com/current/en/extending-modx/custom-manager-pages/modext/modx.tree.tree#custom-events

I believe these events beforeSort and afterSort are only useful if you extend MODx.tree.Tree to create your own Ext.js component.

Furthermore, the tab “Files” seems to use the type MODx.tree.Directory where beforeSort isn’t even fired as far as I can see.

Ok its not the most elegant way I think, but here it is:

$modx->regClientStartupHTMLBlock(
'
<script type="text/javascript">

Ext.onReady(function() {

	const checkExist = setInterval(function() {

		if (Ext.getCmp("modx-file-tree").items === undefined) {

		} else {
			clearInterval(checkExist);
			setTimeout(function() {
					Ext.getCmp("modx-file-tree").items.each(function(item) {
						item.on("beforenodedrop", function(dropEvent) {
							if (!confirm("Are you sure??")) {
								return false;
							}
						});
					});
				}
				, 1000);

		}
	}, 1000);
})

</script>
'
);

I created a plugin on OnManagerPageBeforeRender

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.