|
|
|
/**
|
|
|
|
* guy
|
|
|
|
* 二级树
|
|
|
|
* @class BI.LevelTree
|
|
|
|
* @extends BI.Single
|
|
|
|
*/
|
|
|
|
BI.LevelTree = BI.inherit(BI.Widget, {
|
|
|
|
_defaultConfig: function () {
|
|
|
|
return BI.extend(BI.LevelTree.superclass._defaultConfig.apply(this, arguments), {
|
|
|
|
baseCls: "bi-level-tree",
|
|
|
|
el: {
|
|
|
|
chooseType: 0
|
|
|
|
},
|
|
|
|
expander: {},
|
|
|
|
items: [],
|
|
|
|
value: ""
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_init: function () {
|
|
|
|
BI.LevelTree.superclass._init.apply(this, arguments);
|
|
|
|
|
|
|
|
this.initTree(this.options.items);
|
|
|
|
},
|
|
|
|
|
|
|
|
_formatItems: function (nodes, layer, pNode) {
|
|
|
|
var self = this;
|
|
|
|
BI.each(nodes, function (i, node) {
|
|
|
|
var extend = {layer: layer};
|
|
|
|
if (!BI.isKey(node.id)) {
|
|
|
|
node.id = BI.UUID();
|
|
|
|
}
|
|
|
|
extend.pNode = pNode;
|
|
|
|
if (node.isParent === true || node.parent === true || BI.isNotEmptyArray(node.children)) {
|
|
|
|
extend.type = "bi.mid_plus_group_node";
|
|
|
|
if (i === nodes.length - 1) {
|
|
|
|
extend.type = "bi.last_plus_group_node";
|
|
|
|
extend.isLastNode = true;
|
|
|
|
}
|
|
|
|
if (i === 0 && !pNode) {
|
|
|
|
extend.type = "bi.first_plus_group_node"
|
|
|
|
}
|
|
|
|
if (i === 0 && i === nodes.length - 1) { // 根
|
|
|
|
extend.type = "bi.plus_group_node";
|
|
|
|
}
|
|
|
|
BI.defaults(node, extend);
|
|
|
|
self._formatItems(node.children, layer + 1, node);
|
|
|
|
} else {
|
|
|
|
extend.type = "bi.mid_tree_leaf_item";
|
|
|
|
if (i === 0 && !pNode) {
|
|
|
|
extend.type = "bi.first_tree_leaf_item"
|
|
|
|
}
|
|
|
|
if (i === nodes.length - 1) {
|
|
|
|
extend.type = "bi.last_tree_leaf_item";
|
|
|
|
}
|
|
|
|
BI.defaults(node, extend);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return nodes;
|
|
|
|
},
|
|
|
|
|
|
|
|
_assertId: function (sNodes) {
|
|
|
|
BI.each(sNodes, function (i, node) {
|
|
|
|
if (!BI.isKey(node.id)) {
|
|
|
|
node.id = BI.UUID();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// 构造树结构,
|
|
|
|
initTree: function (nodes) {
|
|
|
|
var self = this, o = this.options;
|
|
|
|
this.empty();
|
|
|
|
this._assertId(nodes);
|
|
|
|
this.tree = BI.createWidget({
|
|
|
|
type: "bi.custom_tree",
|
|
|
|
element: this,
|
|
|
|
expander: BI.extend({
|
|
|
|
el: {},
|
|
|
|
popup: {
|
|
|
|
type: "bi.custom_tree"
|
|
|
|
}
|
|
|
|
}, o.expander),
|
|
|
|
|
|
|
|
items: this._formatItems(BI.Tree.transformToTreeFormat(nodes), 0),
|
|
|
|
value: o.value,
|
|
|
|
|
|
|
|
el: BI.extend({
|
|
|
|
type: "bi.button_tree",
|
|
|
|
chooseType: 0,
|
|
|
|
layouts: [{
|
|
|
|
type: "bi.vertical"
|
|
|
|
}]
|
|
|
|
}, o.el)
|
|
|
|
});
|
|
|
|
this.tree.on(BI.Controller.EVENT_CHANGE, function (type, value, ob) {
|
|
|
|
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
|
|
|
|
if (type === BI.Events.CLICK) {
|
|
|
|
self.fireEvent(BI.LevelTree.EVENT_CHANGE, value, ob);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// 生成树方法
|
|
|
|
stroke: function (nodes) {
|
|
|
|
this.tree.stroke.apply(this.tree, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
populate: function (items, keyword) {
|
|
|
|
items = this._formatItems(BI.Tree.transformToTreeFormat(items), 0);
|
|
|
|
this.tree.populate(items, keyword);
|
|
|
|
},
|
|
|
|
|
|
|
|
setValue: function (v) {
|
|
|
|
this.tree.setValue(v);
|
|
|
|
},
|
|
|
|
|
|
|
|
getValue: function () {
|
|
|
|
return this.tree.getValue();
|
|
|
|
},
|
|
|
|
|
|
|
|
getAllLeaves: function () {
|
|
|
|
return this.tree.getAllLeaves();
|
|
|
|
},
|
|
|
|
|
|
|
|
getNodeById: function (id) {
|
|
|
|
return this.tree.getNodeById(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
getNodeByValue: function (id) {
|
|
|
|
return this.tree.getNodeByValue(id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
BI.LevelTree.EVENT_CHANGE = "EVENT_CHANGE";
|
|
|
|
|
|
|
|
BI.shortcut("bi.level_tree", BI.LevelTree);
|