按钮弹出 checkbox tree

 

//载入tree数据
ResourceClassLoader=new Ext.tree.TreeLoader({
    dataUrl: '../ResourcesClassTree.action',
    listeners:{
        "beforeload":function(treeloader,node){
            treeloader.baseParams={
                treegrid_id:node.id,
                isAsc:'true',
                attr:'orderNo',
                resourceNo:resourceNo //此处测试时为指定的值,生产时由主程序传参数
            };
        }
    } ,
    processResponse : function(response, node, callback) {
        var json = response.responseText;
        try {
            var json = eval("(" + json + ")");
            node.beginUpdate();
            // 从json中获得json数组,这里的key与Struts2返回的json对象中的key对应
            var o = json["tree"];
            for (var i = 0, len = o.length; i < len; i++) {
                var n = this.createNode(o[i]);
                if (n) {
                    node.appendChild(n);
                }
            }
            node.endUpdate();
            if (typeof callback == "function") {
                callback(this, node);
            }
        } catch (e) {
            this.handleFailure(response);
        }
    }
});

 

//定义树组件,也没特别的,还就是树

com.gwtjs.ClassSelectTree = Ext.extend(Ext.tree.TreePanel,{
    constructor:function(_cfg){
        _cfg = Ext.apply({
            rootVisible: false,
            checkModel: 'single',//对树的级联多选
            //onlyLeafCheckable: false,//对树所有结点都可选
            animate: false,
            loader:{
                requestMethod:"post",
                baseAttrs: {
                    uiProvider: Ext.ux.TreeCheckNodeUI
                }, //添加 uiProvider 属性
                baseParams:{
                    attr:'orderNo',
                    resourceNo:resourceNo //此处测试时为指定的值,生产时由主程序传参数
                },
                nodeParameter:"id"
            },
            listeners:{
                load:function(node){
                    var rootNode = this.getRootNode();
                    rootNode.eachChild(function(child){
                        child.on("checkchange",function(node,checked){
                            if(child!=child&&child.attributes.checked){
                                child.attributes.checked=!checked;
                                child.ui.checkbox.checked=!checked;
                            }
                        });
                    });               
                },
                'checkchange': function(node, checked){
                    //console.warn(checked,node);
                    if(checked){
                        node.getUI().addClass('complete');
                        //取上级tbar的部件
                        //1.定位到tbar
                        var pan = this.ownerCt.ownerCt.ownerCt.ownerCt;
                        //1.定位到textfield
                        var text = pan.items.items[1].findByType('textfield')[0];
                        text.setValue(node.text);
                    }else{
                        node.getUI().removeClass('complete');
                    }
                }

            },
            root:new Ext.tree.AsyncTreeNode({
                id:'0',
                loader:ResourceClassLoader
            })
        });
        com.gwtjs.ClassSelectTree.superclass.constructor.call(this, _cfg);
    }
});


//定义一个按钮,用自己的template渲染。

 

com.gwtjs.ClassSelectButton = Ext.extend(Ext.Button,{
    classTree : null,
    constructor:function(_cfg){
        this.classTree = new com.gwtjs.ClassSelectTree();
        _cfg = Ext.apply({
            text:"分类选择",
            template:ClassTextFieldBTN,
            menu:{
                autoHeight:true,
                autoWidth:true,
                items:this.classTree
            }
        });
       
        com.gwtjs.ClassSelectButton.superclass.constructor.call(this, _cfg);
    }
});

 

//定义一个tbar   供grid调用
com.gwtjs.ResourceSearchForm = Ext.extend(Ext.form.FormPanel,{
    classCombo:null,
    classBtn : null,
    constructor:function(_cfg){
        if(!_cfg)_cfg={};
       
        Ext.apply(this,_cfg);
        this.classBtn = new com.gwtjs.ClassSelectButton();
        this.classCombo = new com.gwtjs.ClassCombo({
            emptyText:'可选择分类,可使用"?"、"*",并且在任意位置',
            lock:true,
            label:"分类"
        });
        _cfg=Ext.apply({
            layout:"hbox",
            anchor:'100%',
            border:true,
            defaults:{
                labelAlign:'right',
                labelWidth:58,
                layout:'form',
                anchor:"100%"
            },
            items:[{
                xtype:"label",
                width:56,
                margins:"4",
                anchor:"100%",
                style: 'font-weight:bold;text-align:right;',
                text:"数据检索:"
            },{
                layout:"column",
                width:808,
                defaults:{
                    layout:"form"
                },
                items:[{
                    columnWidth:.3,
                    labelWidth:52,
                    items:{
                        xtype:"textfield",
                        anchor:"100%",
                        name:"keyword",//?,*
                        allowBlank:false,
                        labelStyle: 'font-weight:bold;color:#F90;',
                        emptyText:'查询关键字,可使用"?"、"*",并且在任意位置',
                        fieldLabel:"关键字"
                    }
                },{
                    columnWidth:.2,
                    labelWidth:36,
                    items:{
                        xtype:"textfield",
                        anchor:"100%",
                        readOnly:true,
                        name:"classId"
                    }
                },{
                    columnWidth:.1,
                    labelWidth:36,
                    items:this.classBtn
                },{
                    columnWidth:.2,
                    labelWidth:36,
                    items:{
                        xtype:"combo",
                        anchor:"100%",
                        labelStyle: 'font-weight:bold;color:#F00;',
                        editable:false,
                        transform :"querySelect",
                        //store : ResourceSimple,
                        hiddenName:"queryOpetion",
                        mode : "local",
                        triggerAction : "all",
                        fieldLabel:"选项"
                    }
                },{
                    columnWidth:.2,
                    labelWidth:78,
                    items:{
                        xtype:"datefield",
                        anchor:"100%",
                        format:"Y-m-d",
                        labelStyle: 'font-weight:bold;color:#090;',
                        labelSeparator:'&gt;',
                        fieldLabel:"采集时间",
                        name:"collectTime"
                    }
                }]
            },{
                xtype:"button",
                anchor:"100%",
                margins:"0 5",
                iconCls:"search-trigger",
                bodyStyle:"color:green;",
                text:"Search",
                handler:function(){
                    //do is form success console.dir(this.form);
                    //success  console.dir(this.ownerCt.grid);
                    //console.dir(this.ownerCt.grid.store);
                    console.warn("success ","Test get Grid Store");
                    console.dir(this.ownerCt.grid.store);
                },
                scope:this
            }]
        });
        com.gwtjs.ResourceSearchForm.superclass.constructor.call(this, _cfg);
    }
});

你可能感兴趣的:(按钮弹出 checkbox tree)