RedoX
15 Oct 2007, 12:57 PM
Hey guys,
I think I'm seeing something over its head.. So annoying.. I know the awnser must be really easy and I'm almost ashamed that I'm posting this..
Ok, so I got my tree working.. I can move around with stuff.. and it saves the right positions.. Except the order where they are in listed.. So i'm able to save the parents and stuff but the order is where I get stuck.. I know it must be really easy..
Here is some of my code..
Tree
<script type="text/javascript">
Ext.onReady(function(){
// shorthand
var Tree = Ext.tree;
var tree = new Tree.TreePanel('tree-div', {
autoScroll:true,
animate:true,
enableDD:true,
containerScroll: true,
});
// set the root node
var root = new Tree.AsyncTreeNode({
text: 'Category Structure',
draggable:false,
id:'source'
});
tree.setRootNode(root);
bildCategoryTree(root, <?php echo $node; ?>);
// render the tree
tree.addListener('beforenodedrop', categoryMove.createDelegate(this));
tree.render();
root.expand();
tree.expandAll();
});
function bildCategoryTree(parent, config){
if (!config) return null;
if (parent && config && config.length){
for (var i = 0; i < config.length; i++){
var node = new Ext.tree.TreeNode(config[i]);
parent.appendChild(node);
if(config[i].children){
bildCategoryTree(node, config[i].children);
}
}
}
}
categoryMove = function(obj){
var data = {id: obj.dropNode.id}
data.point = obj.point;
switch (obj.point) {
case 'above' :
data.pid = obj.target.parentNode.id;
if (obj.target.previousSibling) {
data.aid = obj.target.previousSibling.id;
} else {
data.aid = 0;
}
break;
case 'below' :
data.pid = obj.target.parentNode.id;
data.aid = obj.target.id;
break;
case 'append' :
data.pid = obj.target.id;
if (obj.target.lastChild) {
data.aid = obj.target.lastChild.id;
} else {
data.aid = 0;
}
break;
default :
obj.cancel = true;
return obj;
}
var success = function(o) {
try {
if(o.responseText){
alert(o.responseText);
}
}
catch(e) {
}
};
var failure = function(o) {
Ext.dump(o.statusText);
};
var pd = [];
for(var key in data) {
pd.push(encodeURIComponent(key), "=", encodeURIComponent(data[key]), "&");
}
pd.splice(pd.length-1,1);
var con = new Ext.lib.Ajax.request(
'POST',
'http://localhost/backoffice/categories/move/',
{success:success,failure:failure, scope:obj, loaderArea:'tree-div'},
pd.join(""));
}
</script>
<h1>Drag and Drop ordering in a TreePanel</h1>
<div id="tree-div" style="overflow:auto; height:300px;width:400px;border:1px solid #c3daf9;"></div>
I got a part of the CategoryMove code from a friend so I didn't write it myself..
Called by Ajax
$update = "UPDATE categories SET parent = '".$_POST['pid']."' WHERE id = '".$_POST['id']."'";
$this->Category->query($update);
$this->layout = 'ajax';
Ok, I hope you guys can lead me to the light..
I'm also experiencing some problems with IE.. It doesn't render in IE.. but it does in Safari and Firefox.. I'm stuck with that too.. I'm using the original CSS.. And another small thing.. the loading icon by the Root Node doesn't disappear.. It just stays there.. what am I doing wrong?
Thanks in advance and keep up the good work!
RedoX
The Netherlands
I think I'm seeing something over its head.. So annoying.. I know the awnser must be really easy and I'm almost ashamed that I'm posting this..
Ok, so I got my tree working.. I can move around with stuff.. and it saves the right positions.. Except the order where they are in listed.. So i'm able to save the parents and stuff but the order is where I get stuck.. I know it must be really easy..
Here is some of my code..
Tree
<script type="text/javascript">
Ext.onReady(function(){
// shorthand
var Tree = Ext.tree;
var tree = new Tree.TreePanel('tree-div', {
autoScroll:true,
animate:true,
enableDD:true,
containerScroll: true,
});
// set the root node
var root = new Tree.AsyncTreeNode({
text: 'Category Structure',
draggable:false,
id:'source'
});
tree.setRootNode(root);
bildCategoryTree(root, <?php echo $node; ?>);
// render the tree
tree.addListener('beforenodedrop', categoryMove.createDelegate(this));
tree.render();
root.expand();
tree.expandAll();
});
function bildCategoryTree(parent, config){
if (!config) return null;
if (parent && config && config.length){
for (var i = 0; i < config.length; i++){
var node = new Ext.tree.TreeNode(config[i]);
parent.appendChild(node);
if(config[i].children){
bildCategoryTree(node, config[i].children);
}
}
}
}
categoryMove = function(obj){
var data = {id: obj.dropNode.id}
data.point = obj.point;
switch (obj.point) {
case 'above' :
data.pid = obj.target.parentNode.id;
if (obj.target.previousSibling) {
data.aid = obj.target.previousSibling.id;
} else {
data.aid = 0;
}
break;
case 'below' :
data.pid = obj.target.parentNode.id;
data.aid = obj.target.id;
break;
case 'append' :
data.pid = obj.target.id;
if (obj.target.lastChild) {
data.aid = obj.target.lastChild.id;
} else {
data.aid = 0;
}
break;
default :
obj.cancel = true;
return obj;
}
var success = function(o) {
try {
if(o.responseText){
alert(o.responseText);
}
}
catch(e) {
}
};
var failure = function(o) {
Ext.dump(o.statusText);
};
var pd = [];
for(var key in data) {
pd.push(encodeURIComponent(key), "=", encodeURIComponent(data[key]), "&");
}
pd.splice(pd.length-1,1);
var con = new Ext.lib.Ajax.request(
'POST',
'http://localhost/backoffice/categories/move/',
{success:success,failure:failure, scope:obj, loaderArea:'tree-div'},
pd.join(""));
}
</script>
<h1>Drag and Drop ordering in a TreePanel</h1>
<div id="tree-div" style="overflow:auto; height:300px;width:400px;border:1px solid #c3daf9;"></div>
I got a part of the CategoryMove code from a friend so I didn't write it myself..
Called by Ajax
$update = "UPDATE categories SET parent = '".$_POST['pid']."' WHERE id = '".$_POST['id']."'";
$this->Category->query($update);
$this->layout = 'ajax';
Ok, I hope you guys can lead me to the light..
I'm also experiencing some problems with IE.. It doesn't render in IE.. but it does in Safari and Firefox.. I'm stuck with that too.. I'm using the original CSS.. And another small thing.. the loading icon by the Root Node doesn't disappear.. It just stays there.. what am I doing wrong?
Thanks in advance and keep up the good work!
RedoX
The Netherlands