Topic: Problem with code which stop working

Hi Moro, I have a problem with code, when i click to "save order" button Firebug shows that:              tree.serialize is not a function
    [Break on this error] var theDump = tree.serialize();

when clik to rename button, display field to rename, click OK and then:(Firebug)
tree.reload is not a function
[Break on this error] url: 'menuorder/data.php?json=yesplease&l=pl'

Everything was ok earlier, I added checkboxes and now everything stop working:(
Could you look at this code?

Thank you and Regards
Paul


        <script type="text/javascript">
        window.addEvent('domready',function(){
            tree = new Mif.Tree({
                container: $('tree_container'),
                forest: true,
                
                types: {
                    folder:{
                        openIcon: 'mif-tree-open-icon',
                        closeIcon: 'mif-tree-close-icon'
                    },
                    loader:{
                        openIcon: 'mif-tree-loader-open-icon',
                        closeIcon: 'mif-tree-loader-close-icon',
                        dropDenied: ['inside','after']
                    },
                    disabled:{
                        openIcon: 'mif-tree-open-icon',
                        closeIcon: 'mif-tree-close-icon',
                        dragDisabled: true,
                        cls: 'disabled'
                    },
                },


                
            serialize: function(items){
                var serial = [];
                if (!items) items = this.root.getChildren();
                items.each(function(el, i){
                    serial[i] = {
                        id: el.id,
                        children: (el.getChildren()) ? tree.serialize(el.getChildren()) : []
                    };
                });
                return serial;
            },
                
                onRename: function(node, newName, oldName)
                {
                            var req = new Request({
                                    method: 'post',                
                                    url: "menuorder/save.php<? echo "?l=".$_GET['l'];?>", 
                                    onComplete: function() {
                                        tree.reload({
                                            url: 'menuorder/data.php?json=yesplease<? echo "&l=".$_GET['l'];?>'
                                        });
                                    }
                            }).send('old='+oldName+'&new='+newName);                
                },
                        
                initialize: function(){
                        this.initCheckbox('simple');
                        new Mif.Tree.Drag(this);
                    },

                dfltType:'folder',
                height: 18,
                onCheck: function(node)
                {
                    var req = new Request({
                                    method: 'post',                
                                    url: "menuorder/save.php<? echo "?l=".$_GET['l'];?>" 
                                    
                            }).send('sid='+node.id+'&action=show');
                    
                    
                    //$('log').adopt(new Element('li').set('html', node.name+' checked'));
                },
                onUnCheck: function(node)
                {
                    var req = new Request({
                                    method: 'post',                
                                    url: "menuorder/save.php<? echo "?l=".$_GET['l'];?>" 
                                    
                            }).send('sid='+node.id+'&action=hide');
                    
                    //$('log').adopt(new Element('li').set('html', node.id+' unchecked'));
                },

                onCopy: function(from, to, where, copy)
                {
                    if(from.parent==copy.parent)
                    {
                        copy.set(
                        {
                            property: 
                            {
                                name: 'copy '+from.name
                            }
                        });
                    }
                }
            });
            
            $('rename').addEvent('click', function(){
                var node=tree.selected;
                if(!node) return;
                node.rename();
            });
            
            tree.options.beforeRename=function(node, oldName, newName){
                if(confirm('Jesteś pewnien, że chceszzmienić nazwę kategorii?')){
                    this.renameComplete();
                }else{
                    this.renameCancel();
                }
            };

            
            tree.load({
                url: 'menuorder/data.php?json=yesplease<? echo "&l=".$_GET['l'];?>'
            });
            
            var request = function(e) {
                new Event(e).stop();

                var theDump = tree.serialize();
                var req = new Request({
                        method: 'post',                
                        url: "menuorder/save.php<? echo "&l=".$_GET['l'];?>", 
                        onComplete: function() {
                            tree.reload({
                                url: 'menuorder/data.php?json=yesplease<? echo "&l=".$_GET['l'];?>'
                            });
                        }
                }).send('m='+JSON.encode(theDump));
            };
            $('save').addEvent('click', request);
        

        
        });
        </script>

Re: Problem with code which stop working

try implement serialize function:

Mif.Tree.implement({

    serialize: function(items){
        var serial = [];
        if (!items) items = this.root.getChildren();
        items.each(function(el, i){
            serial[i] = {
                id: el.id,
                children: (el.getChildren()) ? this.serialize(el.getChildren()) : []
            };
        }, this);
        return serial;
    }
    
});

Re: Problem with code which stop working

reload method not exists. You should implement it before.

Re: Problem with code which stop working

Ok works fine:) thanks a lot