Hi Daniil,
I did a JavaScript function that search for my parent node based on node Id and once it finds it it will add the newly created node:
var getTreeNodes = function (tree, nodes, parentId, nodeName, nodeId, isFolder, toAdd) {
try {
var length = nodes.length;
var element = null;
for (var i = 0; i < length; i++) {
element = nodes[i];
// if (console) {
// console.log(nodes[i].attributes.PID);
// }
if (element && element.attributes.PID) {
if (toAdd) {
// if (console) {
// console.log("NODE TO COMPARE: " + parseInt(element.attributes["PID"]) + " WITH : " + parentId);
// }
if (parentId == parseInt(element.attributes.PID, 10)) {
if (nodes[i]) { //add new node under parent
nodes[i].appendChild(new Ext.tree.TreeNode({ text: nodeName, iconCls: isFolder ? "icon-folder" : "icon-page", id: nodeId, leaf: !isFolder, expanded: false, editable: false, "PID": nodeId, allowChildren: false, "sortIndex": nodeName }));
if (console) {
console.log("NODE ADDED: " + nodes[i].attributes.PID);
}
break;
}
}
} else {
if (nodeId == parseInt(element.attributes.PID, 10)) {
if (nodes[i]) { //remove node
tree.removeNode(nodes[i]);
// if (console) {
// console.log("NODE REMOVED: " + nodes[i].attributes.PID);
// }
break;
}
}
}
if (element.childNodes) {
//console.log('element:', element);
getTreeNodes(tree, element.childNodes, parentId, nodeName, nodeId, isFolder, toAdd);
}
}
}
} catch (ex) {
console.error(ex);
}
};
This code is executed from child window when the user is adding a new item and then we try to "inject" this new node in our main window tree which is called using "opener.genericTree"
tree.el.mask('Inserting...', 'x-mask-loading');
Ext.Ajax.request({
scope: this,
method: 'POST',
url: '../Handlers/CreateView.ashx',
params: { "nodeId": parentNode.attributes.PID, "nodeName": dashboardName, "isFolder": 'false', "folderType": folderType, "ViewCode": parentNode.attributes["ViewCode"], "viewAccessibility": parentNode.attributes["viewAccessibility"], "ViewTypeCode": itemTypeCode, "dashboardType": dashboardType },
success: function (response, opts) {
tree.el.unmask();
var responseJson = Ext.decode(response.responseText);
if (responseJson.success === true) {
var newNode = parentNode.appendChild(new Ext.tree.TreeNode({ text: dashboardName, isFolder: false, "folderType": itemTypeCode, iconCls: 'icon-page', leaf: true, expandable: false, editable: false, ViewCode: responseJson.node.ViewCode, PID: responseJson.node.id, id: responseJson.node.id }));
if (newNode != null) {
parentNode.expand();
newNode.select();
btnAddFolder.disable();
btnAdd.disable();
btnAddPage.enable();
if (opener.genericTree) {
getTreeNodes(opener.genericTree, opener.genericTree.root.childNodes, parentNode.attributes.PID, dashboardName, newNode.attributes.PID, false, true);
//if (currentNode) currentNode.appendChild(new Ext.tree.TreeNode({ text: dashboardName, iconCls: "icon-page", id: responseJson.node.id, leaf: true, expandable: false, editable: false }));
} else {
console.log('Tree not found!');
}
pnlSetup.enable();
pnlSetup.load('../View.aspx?page=dashboard&viewFolderId=' + responseJson.node.id);
}
}
else {
Ext.Msg.show({
title: 'Item not created', //<- the dialog's title
msg: responseJson.error.message, //<- the message
buttons: Ext.Msg.OK, //<- OK button
icon: Ext.Msg.ERROR // <- error icon
});
}
}
});
tree.el.unmask();
For some reason it doesn't work on IE it breaks on cascade method inside extjs.
Any help with this would be much appreciated.