forked from fanruan/fineui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.1 KiB
136 lines
4.1 KiB
8 years ago
|
/**
|
||
|
* guy
|
||
|
* 二级树
|
||
|
* @class BI.MultiLayerSingleLevelTree
|
||
|
* @extends BI.Single
|
||
|
*/
|
||
|
BI.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, {
|
||
|
_defaultConfig: function () {
|
||
|
return BI.extend(BI.MultiLayerSingleLevelTree.superclass._defaultConfig.apply(this, arguments), {
|
||
|
baseCls: "bi-multilayer-single-level-tree",
|
||
|
isDefaultInit: false,
|
||
|
items: [],
|
||
|
itemsCreator: BI.emptyFn
|
||
|
})
|
||
|
},
|
||
|
|
||
|
_init: function () {
|
||
|
BI.MultiLayerSingleLevelTree.superclass._init.apply(this, arguments);
|
||
|
|
||
|
this.initTree(this.options.items);
|
||
|
},
|
||
|
|
||
|
_formatItems: function (nodes, layer) {
|
||
|
var self = this;
|
||
|
BI.each(nodes, function (i, node) {
|
||
|
var extend = {};
|
||
|
node.layer = layer;
|
||
|
if (!BI.isKey(node.id)) {
|
||
|
node.id = BI.UUID();
|
||
|
}
|
||
|
if (node.isParent === true || BI.isNotEmptyArray(node.children)) {
|
||
|
switch (i) {
|
||
|
case 0 :
|
||
|
extend.type = "bi.multilayer_single_tree_first_plus_group_node";
|
||
|
break;
|
||
|
case nodes.length - 1 :
|
||
|
extend.type = "bi.multilayer_single_tree_last_plus_group_node";
|
||
|
break;
|
||
|
default :
|
||
|
extend.type = "bi.multilayer_single_tree_mid_plus_group_node";
|
||
|
break;
|
||
|
}
|
||
|
BI.defaults(node, extend);
|
||
|
|
||
|
self._formatItems(node.children, layer + 1);
|
||
|
} else {
|
||
|
switch (i) {
|
||
|
case nodes.length - 1:
|
||
|
extend.type = "bi.multilayer_single_tree_last_tree_leaf_item";
|
||
|
break;
|
||
|
default :
|
||
|
extend.type = "bi.multilayer_single_tree_mid_tree_leaf_item";
|
||
|
}
|
||
|
BI.defaults(node, extend);
|
||
|
}
|
||
|
});
|
||
|
return nodes;
|
||
|
},
|
||
|
|
||
|
_assertId: function (sNodes) {
|
||
|
BI.each(sNodes, function (i, node) {
|
||
|
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: {
|
||
|
isDefaultInit: o.isDefaultInit,
|
||
|
el: {},
|
||
|
popup: {
|
||
|
type: "bi.custom_tree"
|
||
|
}
|
||
|
},
|
||
|
|
||
|
items: this._formatItems(BI.Tree.transformToTreeFormat(nodes), 0),
|
||
|
itemsCreator: function (op, callback) {
|
||
|
o.itemsCreator(op, function (items) {
|
||
|
callback(BI.Tree.transformToTreeFormat(items), 0)
|
||
|
})
|
||
|
},
|
||
|
|
||
|
el: {
|
||
|
type: "bi.button_tree",
|
||
|
chooseType: BI.Selection.Single,
|
||
|
layouts: [{
|
||
|
type: "bi.vertical"
|
||
|
}]
|
||
|
}
|
||
|
});
|
||
|
this.tree.on(BI.Controller.EVENT_CHANGE, function (type) {
|
||
|
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
|
||
|
if (type === BI.Events.CLICK) {
|
||
|
self.fireEvent(BI.MultiLayerSingleLevelTree.EVENT_CHANGE, arguments);
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
|
||
|
populate: function (nodes) {
|
||
|
this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(nodes), 0));
|
||
|
},
|
||
|
|
||
|
doBehavior: function () {
|
||
|
this.tree.doBehavior.apply(this.tree, arguments);
|
||
|
},
|
||
|
|
||
|
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.MultiLayerSingleLevelTree.EVENT_CHANGE = "EVENT_CHANGE";
|
||
|
|
||
|
$.shortcut("bi.multilayer_single_level_tree", BI.MultiLayerSingleLevelTree);
|