Hope anyone will suggest me a good solution for my problem.
I need to handle some restrictions with my jstree drag-and-drop functionality, to avoid placing a node (which is of 'file' type) under another node (which also of 'file' type).
I have 2 types of nodes i) 'default' (which i'm considering as 'files' type) and ii) 'folder'
$("div#newtreecontainer").jstree({
"core": {
"multiple": false,
'check_callback' : true,
"themes": {
"dots": true,
"icons": false
}
},
"plugins": ['dnd', 'search', 'types', 'themes', 'contextmenu'],
"types": {
"max_depth": -1,
"max_children": -1,
"valid_children": ["folder"],
"types": {
"folder": {
"valid_children": ["default", "folder"],
"check_node": false,
"uncheck_node": false
},
"default": {
"valid_children": "none"
}
}
},
"contextmenu": {
items: function(node) {
var nodeType = node.li_attr.rel;
var obj = {};
if (nodeType == 'folder') {
obj['create_header'] = {
"label" : "Add Header",
"separator_before" : false,
"separator_after" : true,
"action" : function(data) {
var inst = $.jstree.reference(data.reference),
obj = inst.get_node(data.reference);
inst.create_node(obj, {"rel" : "folder" }, "last", function(newNode) {
setTimeout(function() { inst.edit(newNode); }, 0);
});
}
}
obj['create'] = {
"label": screen,
"separator_before" : false,
"separator_after" : true,
"action" : function(data) {
var inst = $.jstree.reference(data.reference),
obj = inst.get_node(data.reference);
inst.create_node(obj, {"rel" : "default" }, "last", function(newNode) {
setTimeout(function() { inst.edit(newNode); }, 0);
});
}
}
}
return obj;
}
}
});