|
|
|
/**
|
|
|
|
* @class BI.SelectTreePopup
|
|
|
|
* @extends BI.Pane
|
|
|
|
*/
|
|
|
|
|
|
|
|
BI.SelectTreePopup = BI.inherit(BI.Pane, {
|
|
|
|
|
|
|
|
_defaultConfig: function () {
|
|
|
|
return BI.extend(BI.SelectTreePopup.superclass._defaultConfig.apply(this, arguments), {
|
|
|
|
baseCls: "bi-select-level-tree",
|
|
|
|
tipText: BI.i18nText("BI-No_Selected_Item"),
|
|
|
|
items: [],
|
|
|
|
value: ""
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_formatItems: function (nodes, layer, pNode) {
|
|
|
|
var self = this;
|
|
|
|
BI.each(nodes, function (i, node) {
|
|
|
|
var extend = {
|
|
|
|
layer: layer,
|
|
|
|
isFirstNode: i === 0,
|
|
|
|
isLastNode: i === nodes.length - 1,
|
|
|
|
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
|
|
|
|
pNode: pNode,
|
|
|
|
};
|
|
|
|
node.id = node.id || BI.UUID();
|
|
|
|
|
|
|
|
if (node.isParent === true || node.parent === true || BI.isNotEmptyArray(node.children)) {
|
|
|
|
|
|
|
|
extend.type = "bi.tree_node";
|
|
|
|
extend.selectable = true;
|
|
|
|
BI.defaults(node, extend);
|
|
|
|
self._formatItems(node.children, layer + 1, node);
|
|
|
|
} else {
|
|
|
|
extend.type = "bi.tree_item";
|
|
|
|
BI.defaults(node, extend);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return nodes;
|
|
|
|
},
|
|
|
|
|
|
|
|
_init: function () {
|
|
|
|
BI.SelectTreePopup.superclass._init.apply(this, arguments);
|
|
|
|
|
|
|
|
var self = this, o = this.options;
|
|
|
|
|
|
|
|
this.tree = BI.createWidget({
|
|
|
|
type: "bi.level_tree",
|
|
|
|
expander: {
|
|
|
|
type: "bi.tree_expander",
|
|
|
|
// isDefaultInit: true,
|
|
|
|
selectable: true,
|
|
|
|
},
|
|
|
|
items: this._formatItems(BI.Tree.transformToTreeFormat(o.items), 0),
|
|
|
|
value: o.value,
|
|
|
|
chooseType: BI.Selection.Single
|
|
|
|
});
|
|
|
|
|
|
|
|
BI.createWidget({
|
|
|
|
type: "bi.vertical",
|
|
|
|
element: this,
|
|
|
|
vgap: 5,
|
|
|
|
items: [this.tree]
|
|
|
|
});
|
|
|
|
|
|
|
|
this.tree.on(BI.Controller.EVENT_CHANGE, function () {
|
|
|
|
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.tree.on(BI.LevelTree.EVENT_CHANGE, function () {
|
|
|
|
self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.check();
|
|
|
|
},
|
|
|
|
|
|
|
|
getValue: function () {
|
|
|
|
return this.tree.getValue();
|
|
|
|
},
|
|
|
|
|
|
|
|
setValue: function (v) {
|
|
|
|
v = BI.isArray(v) ? v : [v];
|
|
|
|
this.tree.setValue(v);
|
|
|
|
},
|
|
|
|
|
|
|
|
populate: function (items) {
|
|
|
|
BI.SelectTreePopup.superclass.populate.apply(this, arguments);
|
|
|
|
this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(items)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
BI.SelectTreePopup.EVENT_CHANGE = "EVENT_CHANGE";
|
|
|
|
BI.shortcut("bi.select_level_tree", BI.SelectTreePopup);
|