I have a tree consisting of folders and files representing images (instead of documents).
I am trying to prevent image deletion by allowing me to add, rename, move and delete folders.
Using jsTree types, I can prevent images from being deleted, but not if the images are inside a folder.
If the same images are in the folder, the folder will be deleted with all the images.
Any suggestions on how to prevent deleting a folder that is not empty - does it have images in it?
I tried to put the function inside the "types" "delete_node", but I have a terrible time identifying the folder to be deleted. I'm out of luck using $ (this).
Here is my last attempt. Trying to check images before sending delete_node -
.bind("before.jstree", function (e, data) { if(data.func === "delete_node") { if ($(e.currentTarget).find("[rel='imgIR']")){ // rel='imgIR' identifies images alert("Folder must be empty to delete it."); e.stopImmediatePropagation(); return false; } else { return true; } } })
And it works in the sense that it does not allow you to remove it. But it stops deleting every time with or without images.
When I send (e.currentTarget) .html () to the console log, the whole tree is included, not just the folder to be deleted. And I can not find a way to select a specific folder.
The plugins I use are:
"plugins" : [ "html_data", "types", "themes", "ui", "crrm", "contextmenu", "dnd" ]
Any help would be greatly appreciated. Thanks!
* Well, I had some progress, but a new setback.
Using Array.prototype.slice.call (arguments, 1), I was finally able to find that data.args [0] [0] gives me a specific node. But now I get the error message from the jquery.jstree.js 234 line I'm stuck on.
Error: Uncaught TypeError: Function.prototype.apply: the argument list is of the wrong type
This is what my code looks like now. The error occurs in the internal if statement.
.bind("before.jstree", function (e, data) { if(data.func === "delete_node") { var node = data.args[0][0]; if ($(node).children('li[rel="imgIR"]').length != 0){ // rel='imgIR' identifies images alert("Folder must be empty to delete it."); e.stopImmediatePropagation(); return false; } else { return true; } } })