/*
描述:框架树
编写:CoolHu
日期:2012-11-25
修改:
*/
SysTree = function (config) {
};
Ext.define('SysTree', {
extend: 'Ext.tree.Panel',
defaults: {
id: "mySysTree",
title: "Ext.tree.Panel",
iconCls: "application_view_columns",
region: "west",
width: 240,
height: 100,
rootVisible: true,
border: true,
autoScroll: true,
expanded: true,//自定义属性,是否展开
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop'//允许拖拽
}
},
root: {
id: "0",
text: "树列表",
expanded: false,
draggable: false // 根节点不容许拖动
},
tools: [{
id: "expand",
type: 'expand',
tooltip: '展开',
handler: function (event, target, owner, tool) {
Ext.getCmp(this.ownerCt.ownerCt.id).expandAll();
}
},
{
id: "collapse",
type: 'collapse',
tooltip: '折叠',
handler: function (event, target, owner, tool) {
Ext.getCmp(this.ownerCt.ownerCt.id).collapseAll();
}
}]
},
constructor: function (config) {
var me = this;
Ext.apply(me, config || {}, me.defaults);
me.callParent([config]);
//处理是否展开配置
if (!me.root.expanded) {
if (me.expanded) {
me.expandAll();
}
}
},
GetTitle: function () {
return this.title;
},
changeChildChecked: function (node, checked) {
if (Ext.isArray(node)) {
for (var i = node.length - 1; i >= 0; i--) {
this.changeChildChecked(node[i], checked);
}
} else {
//if (node.data.checked != null && checked == false) {
if (node.data.checked != null) {
node.set("checked", checked);
}
if (node.childNodes.length > 0) {
this.changeChildChecked(node.childNodes, checked);
}
}
},
changeParentChecked: function (node, checked) {
if (Ext.isArray(node)) {
for (var i = node.length - 1; i >= 0; i--) {
this.changeParentChecked(node[i], checked);
}
} else {
if (node.data.checked != null && checked == true) {
node.set("checked", checked);
}
if (node.parentNode != null) {
this.changeParentChecked(node.parentNode, checked);
}
}
},
listeners: {
checkchange: function (node, checked) {
if (node.childNodes.length > 0) {
this.changeChildChecked(node.childNodes, checked);
}
if (node.parentNode != null) {
this.changeParentChecked(node.parentNode, checked);
}
}
}
});