Created
June 16, 2014 20:57
-
-
Save philstrong/c8a3166304bca0c1e838 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
appendChild : function(node, suppressEvents, commit) { | |
var me = this, | |
i, ln, | |
index, | |
oldParent, | |
previousSibling, | |
childInfo = { | |
isLast: true, | |
parentId: me.getId(), | |
depth: (me.data.depth||0) + 1 | |
}; | |
// if passed an array do them one by one | |
if (Ext.isArray(node)) { | |
// suspend auto syncing while we append all the nodes | |
me.callStore('suspendAutoSync'); | |
for (i = 0, ln = node.length - 1; i < ln; i++) { | |
me.appendChild(node[i], suppressEvents, commit); | |
} | |
// resume auto syncing before we append the last node | |
me.callStore('resumeAutoSync'); | |
me.appendChild(node[ln], suppressEvents, commit); | |
} else { | |
// Make sure it is a record | |
node = me.createNode(node); | |
if (suppressEvents !== true && me.fireEventArgs("beforeappend", [me, node]) === false) { | |
return false; | |
} | |
index = me.childNodes.length; | |
oldParent = node.parentNode; | |
// it's a move, make sure we move it cleanly | |
if (oldParent) { | |
if (suppressEvents !== true && node.fireEventArgs("beforemove", [node, oldParent, me, index]) === false) { | |
return false; | |
} | |
oldParent.removeChild(node, false, false, true); | |
} | |
// Coalesce all layouts caused by node append | |
Ext.suspendLayouts(); | |
index = me.childNodes.length; | |
if (index === 0) { | |
me.setFirstChild(node); | |
} | |
me.childNodes[index] = node; | |
node.parentNode = me; | |
node.nextSibling = null; | |
me.setLastChild(node); | |
previousSibling = me.childNodes[index - 1]; | |
if (previousSibling) { | |
node.previousSibling = previousSibling; | |
previousSibling.nextSibling = node; | |
previousSibling.updateInfo(commit, { | |
isLast: false | |
}); | |
previousSibling.triggerUIUpdate(); | |
} else { | |
node.previousSibling = null; | |
} | |
// Update the new child's info passing in info we already know | |
childInfo.isFirst = index === 0; | |
childInfo.index = index; | |
node.updateInfo(commit, childInfo); | |
// As soon as we append a child to this node, we are loaded | |
if (!me.isLoaded()) { | |
me.set('loaded', true); | |
} else if (me.childNodes.length === 1) { | |
me.triggerUIUpdate(); | |
} | |
// Ensure connectors are correct by updating the UI on all intervening nodes (descendants) between last sibling and new node. | |
if (index && me.childNodes[index - 1].isExpanded()) { | |
me.childNodes[index - 1].cascadeBy(me.triggerUIUpdate); | |
} | |
if(!node.isLeaf() && node.phantom) { | |
node.set('loaded', true); | |
} | |
// Flush layouts caused by updating of the UI | |
Ext.resumeLayouts(true); | |
if (suppressEvents !== true) { | |
me.fireEventArgs("append", [me, node, index]); | |
if (oldParent) { | |
node.fireEventArgs("move", [node, oldParent, me, index]); | |
} | |
} | |
return node; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment