Ext.namespace('Itransition.RightWayTrader.RightWayTraderData.ux');

Itransition.RightWayTrader.RightWayTraderData.ux.SearchTree = Ext.extend(Ext.tree.TreePanel, {
    tabTitle: '',
    rootNodeTitle: '',
    handlerUrl: '',
    treeOnClickEvent: null,
    parentNodes: [],
    initComponent: function() {
        Ext.apply(this, {
            useArrows: true,
            title: this.tabTitle,
            autoScroll: true,
            animate: true,
            enableDD: false,
            containerScroll: true,
            bodyBorder: false,
            border: false,
            root: {
                nodeType: 'async',
                text: this.rootNodeTitle,
                draggable: false,
                id: '0'
            },
            dataUrl: this.handlerUrl
        });

        this.on('click', function(node, e) {
            categoryId = node.id;

            this.parentNodes = [];
            this.collectParents(node);

            menu.Update(this.parentNodes);
            menu.UpdateGrid();
        } , this);

        Itransition.RightWayTrader.RightWayTraderData.ux.SearchTree.superclass.initComponent.apply(this, arguments);
    },
    collectParents: function(node) {
        this.parentNodes.push({ id: node.id, name: node.text });

        if (node.parentNode != null) {
            this.collectParents(node.parentNode);
        }
    }
});

Ext.reg('SearchTree', Itransition.RightWayTrader.RightWayTraderData.ux.SearchTree);
