Browse Source

Merging in latest from upstream (~GUY/fineui:refs/heads/master)

* commit '1007647d229d8efea7d05159576a73de246c6c7e':
  update
  add
  add
  add
  bug
es6
Young 8 years ago
parent
commit
af6bc84dca
  1. 16
      bi/base.js
  2. 18
      bi/case.js
  3. 57
      bi/core.js
  4. 96
      bi/widget.js
  5. 5
      demo/config.js
  6. 21
      demo/js/component/demo.treevaluechoosercombo.js
  7. 26
      demo/js/component/demo.treevaluechooserpane.js
  8. 6
      demo/js/component/demo.valuechooserpane.js
  9. 16
      docs/base.js
  10. 18
      docs/case.js
  11. 57
      docs/core.js
  12. 58
      docs/demo.js
  13. 96
      docs/widget.js
  14. 2
      src/base/tree/asynctree.js
  15. 2
      src/base/tree/parttree.js
  16. 12
      src/base/tree/treeview.js
  17. 18
      src/case/toolbar/toolbar.multiselect.js
  18. 75
      src/component/treevaluechooser/abstract.treevaluechooser.js
  19. 2
      src/component/valuechooser/pane.valuechooser.js
  20. 8
      src/core/base.js
  21. 49
      src/core/utils/tree.js
  22. 6
      src/widget/multiselectlist/multiselectlist.js

16
bi/base.js

@ -1710,7 +1710,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
_getNodeValue: function (node) { _getNodeValue: function (node) {
//去除标红 //去除标红
return node.value || node.text.replace(/<[^>]+>/g, ""); return node.value == null ? node.text.replace(/<[^>]+>/g, "") : node.value;
}, },
//获取半选框值 //获取半选框值
@ -1802,6 +1802,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
var self = this, o = this.options; var self = this, o = this.options;
var ns = BI.Tree.arrayFormat(nodes); var ns = BI.Tree.arrayFormat(nodes);
BI.each(ns, function (i, n) { BI.each(ns, function (i, n) {
n.title = n.title || n.text || n.value;
//处理标红 //处理标红
if (BI.isKey(o.paras.keyword)) { if (BI.isKey(o.paras.keyword)) {
n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html(); n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html();
@ -1944,7 +1945,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
}, },
setSelectedValue: function (value) { setSelectedValue: function (value) {
this.options.paras.selectedValues = value || {}; this.options.paras.selectedValues = BI.deepClone(value) || {};
this.selectedValues = BI.deepClone(value) || {}; this.selectedValues = BI.deepClone(value) || {};
}, },
@ -1980,14 +1981,9 @@ BI.TreeView = BI.inherit(BI.Pane, {
return this._getSelectedValues(); return this._getSelectedValues();
}, },
empty: function () { destroyed: function () {
BI.isNotNull(this.nodes) && this.nodes.destroy();
},
destroy: function () {
this.stop(); this.stop();
this.nodes && this.nodes.destroy(); this.nodes && this.nodes.destroy();
BI.TreeView.superclass.destroy.apply(this, arguments);
} }
}); });
BI.extend(BI.TreeView, { BI.extend(BI.TreeView, {
@ -2190,7 +2186,7 @@ BI.AsyncTree = BI.inherit(BI.TreeView, {
} }
var checkedValues = this._getSelectedValues(); var checkedValues = this._getSelectedValues();
if (BI.isEmpty(checkedValues)) { if (BI.isEmpty(checkedValues)) {
return this.selectedValues; return BI.deepClone(this.selectedValues);
} }
if (BI.isEmpty(this.selectedValues)) { if (BI.isEmpty(this.selectedValues)) {
return checkedValues; return checkedValues;
@ -2257,7 +2253,7 @@ BI.PartTree = BI.inherit(BI.AsyncTree, {
BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
} else { } else {
o.itemsCreator(BI.extend({}, o.paras, { o.itemsCreator(BI.extend({}, o.paras, {
type: BI.TreeView.REQ_TYPE_CALCULATE_SELECT_DATA, type: BI.TreeView.REQ_TYPE_SELECT_DATA,
selectedValues: this.selectedValues, selectedValues: this.selectedValues,
notSelectedValue: name, notSelectedValue: name,
parentValues: parentValues parentValues: parentValues

18
bi/case.js

@ -10269,7 +10269,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
height: 25, height: 25,
text: BI.i18nText('BI-Select_All'), text: BI.i18nText('BI-Select_All'),
isAllCheckedBySelectedValue: BI.emptyFn, isAllCheckedBySelectedValue: BI.emptyFn,
onCheck: BI.emptyFn,
isHalfCheckedBySelectedValue: function (selectedValues) { isHalfCheckedBySelectedValue: function (selectedValues) {
return selectedValues.length > 0; return selectedValues.length > 0;
} }
@ -10283,7 +10282,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
stopPropagation: true, stopPropagation: true,
handler: function () { handler: function () {
self.setSelected(self.isSelected()); self.setSelected(self.isSelected());
o.onCheck.call(self, self.isSelected());
} }
}); });
this.half = BI.createWidget({ this.half = BI.createWidget({
@ -10291,7 +10289,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
stopPropagation: true, stopPropagation: true,
handler: function () { handler: function () {
self.setSelected(true); self.setSelected(true);
o.onCheck.call(self, self.isSelected());
} }
}); });
this.checkbox.on(BI.Controller.EVENT_CHANGE, function () { this.checkbox.on(BI.Controller.EVENT_CHANGE, function () {
@ -10334,21 +10331,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
this.half.invisible(); this.half.invisible();
}, },
doClick: function () {
var isHalf = this.isHalfSelected(), isSelected = this.isSelected();
if (isHalf === true) {
this.setSelected(true);
} else {
this.setSelected(!isSelected);
}
if (this.isValid()) {
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, this.getValue(), this);
this.options.onCheck.call(this, this.isSelected());
this.fireEvent(BI.MultiSelectBar.EVENT_CHANGE, this.isSelected(), this);
}
},
setSelected: function (v) { setSelected: function (v) {
this.checkbox.setSelected(v); this.checkbox.setSelected(v);
this.setHalfSelected(false); this.setHalfSelected(false);

57
bi/core.js

@ -2352,15 +2352,15 @@ if (!window.BI) {
}, },
has: function (obj, keys) { has: function (obj, keys) {
if (BI.isKey(keys)) { if (BI.isArray(keys)) {
return _.has.apply(_, arguments); if (keys.length === 0) {
}
if (!keys || BI.isEmpty(keys)) {
return false; return false;
} }
return BI.every(keys, function (i, key) { return BI.every(keys, function (i, key) {
return _.has(obj, key); return _.has(obj, key);
}); });
}
return _.has.apply(_, arguments);
}, },
//数字和字符串可以作为key //数字和字符串可以作为key
@ -9990,7 +9990,7 @@ $.extend(BI, {
}, },
isRoot: function (node) { isRoot: function (node) {
return node === this.root || node.id === this.root.id; return node === this.root;
}, },
getRoot: function () { getRoot: function () {
@ -10367,7 +10367,7 @@ $.extend(BI, {
if (BI.isArray(nodes)) { if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
var node = BI.clone(nodes[i]); var node = BI.clone(nodes[i]);
node.pId = pId; node.pId = node.pId == null ? pId : node.pId;
delete node.children; delete node.children;
r.push(node); r.push(node);
if (nodes[i]["children"]) { if (nodes[i]["children"]) {
@ -10376,7 +10376,7 @@ $.extend(BI, {
} }
} else { } else {
var newNodes = BI.clone(nodes); var newNodes = BI.clone(nodes);
newNodes.pId = pId; newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
delete newNodes.children; delete newNodes.children;
r.push(newNodes); r.push(newNodes);
if (nodes["children"]) { if (nodes["children"]) {
@ -10387,21 +10387,25 @@ $.extend(BI, {
}, },
arrayFormat: function (nodes, pId) { arrayFormat: function (nodes, pId) {
if (!nodes) return []; if (!nodes) {
return [];
}
var r = []; var r = [];
if (BI.isArray(nodes)) { if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
var node = nodes[i]; var node = nodes[i];
node.pId = node.pId == null ? pId : node.pId;
r.push(node); r.push(node);
if (nodes[i]["children"]) { if (nodes[i]["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[i]["children"], node.id)); r = r.concat(BI.Tree.arrayFormat(nodes[i]["children"], node.id));
} }
} }
} else { } else {
var newNodes = nodes; var newNodes = nodes;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
r.push(newNodes); r.push(newNodes);
if (nodes["children"]) { if (nodes["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes["children"], newNodes.id)); r = r.concat(BI.Tree.arrayFormat(nodes["children"], newNodes.id));
} }
} }
return r; return r;
@ -10423,7 +10427,7 @@ $.extend(BI, {
tmpMap[sNodes[i].id] = BI.clone(sNodes[i]); tmpMap[sNodes[i].id] = BI.clone(sNodes[i]);
} }
for (i = 0, l = sNodes.length; i < l; i++) { for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id != sNodes[i].pId) { if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) { if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = []; tmpMap[sNodes[i].pId].children = [];
} }
@ -10439,6 +10443,37 @@ $.extend(BI, {
} }
}, },
treeFormat: function (sNodes) {
var i, l;
if (!sNodes) {
return [];
}
if (BI.isArray(sNodes)) {
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = sNodes[i];
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
tmpMap[sNodes[i].pId].children.push(tmpMap[sNodes[i].id]);
} else {
r.push(tmpMap[sNodes[i].id]);
}
}
return r;
} else {
return [sNodes];
}
},
traversal: function (array, callback) { traversal: function (array, callback) {
if (BI.isNull(array)) { if (BI.isNull(array)) {
return; return;

96
bi/widget.js

@ -10973,6 +10973,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
var assertShowValue = function () { var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue);
self.trigger.setValue(self.storeValue);
}; };
this.adapter = BI.createWidget({ this.adapter = BI.createWidget({
@ -11032,6 +11033,8 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
self._showAdapter(); self._showAdapter();
self._setStartValue(""); self._setStartValue("");
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
//需要刷新回到初始界面,否则搜索的结果不能放在最前面
self.adapter.populate();
} }
}, { }, {
eventName: BI.Searcher.EVENT_PAUSE, eventName: BI.Searcher.EVENT_PAUSE,
@ -11043,7 +11046,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
value: [keyword] value: [keyword]
}, function () { }, function () {
self._showAdapter(); self._showAdapter();
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
self._setStartValue(keyword); self._setStartValue(keyword);
assertShowValue(); assertShowValue();
@ -11063,13 +11065,11 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); self._setStartValue("");
} else { } else {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
} }
@ -11433,6 +11433,14 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, {
}); });
}, },
stopSearch: function () {
this.trigger.stopSearch();
},
updateValue: function (v) {
this.adapter.updateValue(v);
},
getValue: function () { getValue: function () {
return this.storeValue.value; return this.storeValue.value;
}, },
@ -11482,6 +11490,11 @@ BI.MultiSelectTreePopup = BI.inherit(BI.Widget, {
this.popup.setValue(v.value); this.popup.setValue(v.value);
}, },
updateValue: function (v) {
this.popup.updateValue(v);
this.popup.refresh();
},
populate: function (config) { populate: function (config) {
this.popup.stroke(config); this.popup.stroke(config);
} }
@ -17173,27 +17186,9 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
_initData: function (items) { _initData: function (items) {
this.items = items; this.items = items;
var nodes = BI.Tree.transformToTreeFormat(items); var nodes = BI.Tree.treeFormat(items);
this.tree = new BI.Tree(); this.tree = new BI.Tree();
this.tree.initTree(nodes); this.tree.initTree(nodes);
this._initMap();
this._initFloors();
},
_initMap: function () {
var map = this.map = {};
BI.each(this.items, function (i, item) {
map[item.value] = item;
});
},
_initFloors: function () {
this.floors = -1;
var root = this.tree.getRoot();
while (root) {
this.floors++;
root = root.getChildren()[0];
}
}, },
_itemsCreator: function (options, callback) { _itemsCreator: function (options, callback) {
@ -17237,32 +17232,29 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
return; return;
} }
doCheck(0, [], this.tree.getRoot(), selectedValues); doCheck([], this.tree.getRoot(), selectedValues);
callback({ callback({
items: result items: result
}); });
function doCheck(floor, parentValues, node, selected) { function doCheck(parentValues, node, selected) {
if (floor >= self.floors) {
return;
}
if (selected == null || BI.isEmpty(selected)) { if (selected == null || BI.isEmpty(selected)) {
BI.each(node.getChildren(), function (i, child) { BI.each(node.getChildren(), function (i, child) {
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(child.value); newParents.push(child.value);
var llen = self._getChildCount(newParents); var llen = self._getChildCount(newParents);
createOneJson(child, node.id, llen); createOneJson(child, node.id, llen);
doCheck(floor + 1, newParents, child, {}); doCheck(newParents, child, {});
}); });
return; return;
} }
BI.each(selected, function (k) { BI.each(selected, function (k) {
var node = self._getNode(k); var node = self._getNode(parentValues, k);
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(node.value); newParents.push(node.value);
createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents));
doCheck(floor + 1, newParents, node, selected[k]); doCheck(newParents, node, selected[k]);
}) })
} }
@ -17352,9 +17344,6 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
if (self._isMatch(current, keyword)) { if (self._isMatch(current, keyword)) {
return true; return true;
} }
if (deep >= self.floors) {
return false;
}
var children = self._getChildren(newParents); var children = self._getChildren(newParents);
@ -17490,9 +17479,6 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result); createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result);
return [true, checked]; return [true, checked];
} }
if (deep >= self.floors) {
return [false, false];
}
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(current); newParents.push(current);
var children = self._getChildren(newParents); var children = self._getChildren(newParents);
@ -17517,14 +17503,14 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
} }
function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { function createOneJson(parentValues, value, isOpen, checked, half, flag, result) {
var node = self.map[value]; var node = self._getNode(parentValues, value)
result.push({ result.push({
id: node.id, id: node.id,
pId: node.pId, pId: node.pId,
text: node.text, text: node.text,
value: node.value, value: node.value,
title: node.title, title: node.title,
isParent: parentValues.length + 1 < self.floors, isParent: node.getChildrenLength() > 0,
open: isOpen, open: isOpen,
checked: checked, checked: checked,
halfCheck: half, halfCheck: half,
@ -17608,7 +17594,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
value: nodes[i].value, value: nodes[i].value,
text: nodes[i].text, text: nodes[i].text,
times: 1, times: 1,
isParent: parentValues.length + 1 < this.floors, isParent: nodes[i].getChildrenLength() > 0,
checked: state[0], checked: state[0],
halfCheck: state[1] halfCheck: state[1]
}) })
@ -17655,14 +17641,14 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
function getCheckState(current, parentValues, valueMap, checkState) { function getCheckState(current, parentValues, valueMap, checkState) {
var checked = checkState.checked, half = checkState.half; var checked = checkState.checked, half = checkState.half;
var hasChild = parentValues.length + 1 < self.floors;
var tempCheck = false, halfCheck = false; var tempCheck = false, halfCheck = false;
if (BI.has(valueMap, current)) { if (BI.has(valueMap, current)) {
//可能是半选 //可能是半选
if (valueMap[current][0] === 1) { if (valueMap[current][0] === 1) {
var values = BI.clone(parentValues); var values = BI.clone(parentValues);
values.push(current); values.push(current);
if (hasChild && self._getChildCount(values) !== valueMap[current][1]) { var childCount = self._getChildCount(values);
if (childCount > 0 && childCount !== valueMap[current][1]) {
halfCheck = true; halfCheck = true;
} }
} else if (valueMap[current][0] === 2) { } else if (valueMap[current][0] === 2) {
@ -17695,14 +17681,34 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
return finded.finded.length > 0 || finded.matched.length > 0; return finded.finded.length > 0 || finded.matched.length > 0;
}, },
_getNode: function (v) { _getNode: function (parentValues, v) {
return this.tree.search(v, "value"); var self = this;
var findedParentNode;
var index = 0;
this.tree.traverse(function (node) {
if (self.tree.isRoot(node)) {
return;
}
if (index > parentValues.length) {
return false;
}
if (index === parentValues.length && node.value === v) {
findedParentNode = node;
return false;
}
if (node.value === parentValues[index]) {
index++;
return;
}
return true;
});
return findedParentNode;
}, },
_getChildren: function (parentValues) { _getChildren: function (parentValues) {
if (parentValues.length > 0) { if (parentValues.length > 0) {
var value = BI.last(parentValues); var value = BI.last(parentValues);
var parent = this.tree.search(value, "value"); var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value);
} else { } else {
var parent = this.tree.getRoot(); var parent = this.tree.getRoot();
} }
@ -17970,8 +17976,6 @@ BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-value-chooser-pane", baseCls: "bi-value-chooser-pane",
width: 200,
height: 30,
items: null, items: null,
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
cache: true cache: true

5
demo/config.js

File diff suppressed because one or more lines are too long

21
demo/js/component/demo.treevaluechoosercombo.js

@ -4,29 +4,12 @@ Demo.TreeValueChooser = BI.inherit(BI.Widget, {
}, },
render: function () { render: function () {
var tree = [];
for (var i = 0; i < 221; i++) {
tree.push({
value: "" + i + "",
text: "" + i + "",
id: i + "",
pId: null
});
for (var j = 0; j < 9; j++) {
tree.push({
value: i + "-" + j,
text: j + "",
id: i + "-" + j,
pId: i + ""
})
}
}
var widget = BI.createWidget({ var widget = BI.createWidget({
type: "bi.tree_value_chooser_combo", type: "bi.tree_value_chooser_combo",
width: 300, width: 300,
items: tree, // items: BI.deepClone(Demo.CONSTANTS.TREEITEMS),
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
callback(tree); callback(BI.deepClone(Demo.CONSTANTS.TREEITEMS));
} }
}); });
return { return {

26
demo/js/component/demo.treevaluechooserpane.js

@ -4,30 +4,12 @@ Demo.TreeValueChooser = BI.inherit(BI.Widget, {
}, },
render: function () { render: function () {
var tree = [];
for (var i = 0; i < 221; i++) {
tree.push({
value: "" + i + "",
text: "" + i + "",
id: i + "",
pId: null
});
for (var j = 0; j < 9; j++) {
tree.push({
value: i + "-" + j,
text: j + "",
id: i + "-" + j,
pId: i + ""
})
}
}
return { return {
type: "bi.tree_value_chooser_pane", type: "bi.tree_value_chooser_pane",
width: 300, items: BI.deepClone(Demo.CONSTANTS.TREEITEMS),
items: tree, // itemsCreator: function (op, callback) {
itemsCreator: function (op, callback) { // callback(tree);
callback(tree); // }
}
}; };
} }
}); });

6
demo/js/component/demo.valuechooserpane.js

@ -6,9 +6,9 @@ Demo.ValueChooserPane = BI.inherit(BI.Widget, {
return { return {
type: "bi.value_chooser_pane", type: "bi.value_chooser_pane",
items: BI.deepClone(Demo.CONSTANTS.ITEMS), items: BI.deepClone(Demo.CONSTANTS.ITEMS),
itemsCreator: function (op, callback) { // itemsCreator: function (op, callback) {
callback(BI.deepClone(Demo.CONSTANTS.ITEMS)); // callback(BI.deepClone(Demo.CONSTANTS.ITEMS));
} // }
}; };
} }
}); });

16
docs/base.js

@ -1710,7 +1710,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
_getNodeValue: function (node) { _getNodeValue: function (node) {
//去除标红 //去除标红
return node.value || node.text.replace(/<[^>]+>/g, ""); return node.value == null ? node.text.replace(/<[^>]+>/g, "") : node.value;
}, },
//获取半选框值 //获取半选框值
@ -1802,6 +1802,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
var self = this, o = this.options; var self = this, o = this.options;
var ns = BI.Tree.arrayFormat(nodes); var ns = BI.Tree.arrayFormat(nodes);
BI.each(ns, function (i, n) { BI.each(ns, function (i, n) {
n.title = n.title || n.text || n.value;
//处理标红 //处理标红
if (BI.isKey(o.paras.keyword)) { if (BI.isKey(o.paras.keyword)) {
n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html(); n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html();
@ -1944,7 +1945,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
}, },
setSelectedValue: function (value) { setSelectedValue: function (value) {
this.options.paras.selectedValues = value || {}; this.options.paras.selectedValues = BI.deepClone(value) || {};
this.selectedValues = BI.deepClone(value) || {}; this.selectedValues = BI.deepClone(value) || {};
}, },
@ -1980,14 +1981,9 @@ BI.TreeView = BI.inherit(BI.Pane, {
return this._getSelectedValues(); return this._getSelectedValues();
}, },
empty: function () { destroyed: function () {
BI.isNotNull(this.nodes) && this.nodes.destroy();
},
destroy: function () {
this.stop(); this.stop();
this.nodes && this.nodes.destroy(); this.nodes && this.nodes.destroy();
BI.TreeView.superclass.destroy.apply(this, arguments);
} }
}); });
BI.extend(BI.TreeView, { BI.extend(BI.TreeView, {
@ -2190,7 +2186,7 @@ BI.AsyncTree = BI.inherit(BI.TreeView, {
} }
var checkedValues = this._getSelectedValues(); var checkedValues = this._getSelectedValues();
if (BI.isEmpty(checkedValues)) { if (BI.isEmpty(checkedValues)) {
return this.selectedValues; return BI.deepClone(this.selectedValues);
} }
if (BI.isEmpty(this.selectedValues)) { if (BI.isEmpty(this.selectedValues)) {
return checkedValues; return checkedValues;
@ -2257,7 +2253,7 @@ BI.PartTree = BI.inherit(BI.AsyncTree, {
BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
} else { } else {
o.itemsCreator(BI.extend({}, o.paras, { o.itemsCreator(BI.extend({}, o.paras, {
type: BI.TreeView.REQ_TYPE_CALCULATE_SELECT_DATA, type: BI.TreeView.REQ_TYPE_SELECT_DATA,
selectedValues: this.selectedValues, selectedValues: this.selectedValues,
notSelectedValue: name, notSelectedValue: name,
parentValues: parentValues parentValues: parentValues

18
docs/case.js

@ -10269,7 +10269,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
height: 25, height: 25,
text: BI.i18nText('BI-Select_All'), text: BI.i18nText('BI-Select_All'),
isAllCheckedBySelectedValue: BI.emptyFn, isAllCheckedBySelectedValue: BI.emptyFn,
onCheck: BI.emptyFn,
isHalfCheckedBySelectedValue: function (selectedValues) { isHalfCheckedBySelectedValue: function (selectedValues) {
return selectedValues.length > 0; return selectedValues.length > 0;
} }
@ -10283,7 +10282,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
stopPropagation: true, stopPropagation: true,
handler: function () { handler: function () {
self.setSelected(self.isSelected()); self.setSelected(self.isSelected());
o.onCheck.call(self, self.isSelected());
} }
}); });
this.half = BI.createWidget({ this.half = BI.createWidget({
@ -10291,7 +10289,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
stopPropagation: true, stopPropagation: true,
handler: function () { handler: function () {
self.setSelected(true); self.setSelected(true);
o.onCheck.call(self, self.isSelected());
} }
}); });
this.checkbox.on(BI.Controller.EVENT_CHANGE, function () { this.checkbox.on(BI.Controller.EVENT_CHANGE, function () {
@ -10334,21 +10331,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
this.half.invisible(); this.half.invisible();
}, },
doClick: function () {
var isHalf = this.isHalfSelected(), isSelected = this.isSelected();
if (isHalf === true) {
this.setSelected(true);
} else {
this.setSelected(!isSelected);
}
if (this.isValid()) {
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, this.getValue(), this);
this.options.onCheck.call(this, this.isSelected());
this.fireEvent(BI.MultiSelectBar.EVENT_CHANGE, this.isSelected(), this);
}
},
setSelected: function (v) { setSelected: function (v) {
this.checkbox.setSelected(v); this.checkbox.setSelected(v);
this.setHalfSelected(false); this.setHalfSelected(false);

57
docs/core.js

@ -13494,15 +13494,15 @@ if (!window.BI) {
}, },
has: function (obj, keys) { has: function (obj, keys) {
if (BI.isKey(keys)) { if (BI.isArray(keys)) {
return _.has.apply(_, arguments); if (keys.length === 0) {
}
if (!keys || BI.isEmpty(keys)) {
return false; return false;
} }
return BI.every(keys, function (i, key) { return BI.every(keys, function (i, key) {
return _.has(obj, key); return _.has(obj, key);
}); });
}
return _.has.apply(_, arguments);
}, },
//数字和字符串可以作为key //数字和字符串可以作为key
@ -18448,7 +18448,7 @@ $.extend(BI, {
}, },
isRoot: function (node) { isRoot: function (node) {
return node === this.root || node.id === this.root.id; return node === this.root;
}, },
getRoot: function () { getRoot: function () {
@ -18825,7 +18825,7 @@ $.extend(BI, {
if (BI.isArray(nodes)) { if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
var node = BI.clone(nodes[i]); var node = BI.clone(nodes[i]);
node.pId = pId; node.pId = node.pId == null ? pId : node.pId;
delete node.children; delete node.children;
r.push(node); r.push(node);
if (nodes[i]["children"]) { if (nodes[i]["children"]) {
@ -18834,7 +18834,7 @@ $.extend(BI, {
} }
} else { } else {
var newNodes = BI.clone(nodes); var newNodes = BI.clone(nodes);
newNodes.pId = pId; newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
delete newNodes.children; delete newNodes.children;
r.push(newNodes); r.push(newNodes);
if (nodes["children"]) { if (nodes["children"]) {
@ -18845,21 +18845,25 @@ $.extend(BI, {
}, },
arrayFormat: function (nodes, pId) { arrayFormat: function (nodes, pId) {
if (!nodes) return []; if (!nodes) {
return [];
}
var r = []; var r = [];
if (BI.isArray(nodes)) { if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
var node = nodes[i]; var node = nodes[i];
node.pId = node.pId == null ? pId : node.pId;
r.push(node); r.push(node);
if (nodes[i]["children"]) { if (nodes[i]["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[i]["children"], node.id)); r = r.concat(BI.Tree.arrayFormat(nodes[i]["children"], node.id));
} }
} }
} else { } else {
var newNodes = nodes; var newNodes = nodes;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
r.push(newNodes); r.push(newNodes);
if (nodes["children"]) { if (nodes["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes["children"], newNodes.id)); r = r.concat(BI.Tree.arrayFormat(nodes["children"], newNodes.id));
} }
} }
return r; return r;
@ -18881,7 +18885,7 @@ $.extend(BI, {
tmpMap[sNodes[i].id] = BI.clone(sNodes[i]); tmpMap[sNodes[i].id] = BI.clone(sNodes[i]);
} }
for (i = 0, l = sNodes.length; i < l; i++) { for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id != sNodes[i].pId) { if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) { if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = []; tmpMap[sNodes[i].pId].children = [];
} }
@ -18897,6 +18901,37 @@ $.extend(BI, {
} }
}, },
treeFormat: function (sNodes) {
var i, l;
if (!sNodes) {
return [];
}
if (BI.isArray(sNodes)) {
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = sNodes[i];
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
tmpMap[sNodes[i].pId].children.push(tmpMap[sNodes[i].id]);
} else {
r.push(tmpMap[sNodes[i].id]);
}
}
return r;
} else {
return [sNodes];
}
},
traversal: function (array, callback) { traversal: function (array, callback) {
if (BI.isNull(array)) { if (BI.isNull(array)) {
return; return;

58
docs/demo.js

File diff suppressed because one or more lines are too long

96
docs/widget.js

@ -10973,6 +10973,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
var assertShowValue = function () { var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue);
self.trigger.setValue(self.storeValue);
}; };
this.adapter = BI.createWidget({ this.adapter = BI.createWidget({
@ -11032,6 +11033,8 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
self._showAdapter(); self._showAdapter();
self._setStartValue(""); self._setStartValue("");
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
//需要刷新回到初始界面,否则搜索的结果不能放在最前面
self.adapter.populate();
} }
}, { }, {
eventName: BI.Searcher.EVENT_PAUSE, eventName: BI.Searcher.EVENT_PAUSE,
@ -11043,7 +11046,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
value: [keyword] value: [keyword]
}, function () { }, function () {
self._showAdapter(); self._showAdapter();
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
self._setStartValue(keyword); self._setStartValue(keyword);
assertShowValue(); assertShowValue();
@ -11063,13 +11065,11 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); self._setStartValue("");
} else { } else {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
} }
@ -11433,6 +11433,14 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, {
}); });
}, },
stopSearch: function () {
this.trigger.stopSearch();
},
updateValue: function (v) {
this.adapter.updateValue(v);
},
getValue: function () { getValue: function () {
return this.storeValue.value; return this.storeValue.value;
}, },
@ -11482,6 +11490,11 @@ BI.MultiSelectTreePopup = BI.inherit(BI.Widget, {
this.popup.setValue(v.value); this.popup.setValue(v.value);
}, },
updateValue: function (v) {
this.popup.updateValue(v);
this.popup.refresh();
},
populate: function (config) { populate: function (config) {
this.popup.stroke(config); this.popup.stroke(config);
} }
@ -17173,27 +17186,9 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
_initData: function (items) { _initData: function (items) {
this.items = items; this.items = items;
var nodes = BI.Tree.transformToTreeFormat(items); var nodes = BI.Tree.treeFormat(items);
this.tree = new BI.Tree(); this.tree = new BI.Tree();
this.tree.initTree(nodes); this.tree.initTree(nodes);
this._initMap();
this._initFloors();
},
_initMap: function () {
var map = this.map = {};
BI.each(this.items, function (i, item) {
map[item.value] = item;
});
},
_initFloors: function () {
this.floors = -1;
var root = this.tree.getRoot();
while (root) {
this.floors++;
root = root.getChildren()[0];
}
}, },
_itemsCreator: function (options, callback) { _itemsCreator: function (options, callback) {
@ -17237,32 +17232,29 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
return; return;
} }
doCheck(0, [], this.tree.getRoot(), selectedValues); doCheck([], this.tree.getRoot(), selectedValues);
callback({ callback({
items: result items: result
}); });
function doCheck(floor, parentValues, node, selected) { function doCheck(parentValues, node, selected) {
if (floor >= self.floors) {
return;
}
if (selected == null || BI.isEmpty(selected)) { if (selected == null || BI.isEmpty(selected)) {
BI.each(node.getChildren(), function (i, child) { BI.each(node.getChildren(), function (i, child) {
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(child.value); newParents.push(child.value);
var llen = self._getChildCount(newParents); var llen = self._getChildCount(newParents);
createOneJson(child, node.id, llen); createOneJson(child, node.id, llen);
doCheck(floor + 1, newParents, child, {}); doCheck(newParents, child, {});
}); });
return; return;
} }
BI.each(selected, function (k) { BI.each(selected, function (k) {
var node = self._getNode(k); var node = self._getNode(parentValues, k);
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(node.value); newParents.push(node.value);
createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents));
doCheck(floor + 1, newParents, node, selected[k]); doCheck(newParents, node, selected[k]);
}) })
} }
@ -17352,9 +17344,6 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
if (self._isMatch(current, keyword)) { if (self._isMatch(current, keyword)) {
return true; return true;
} }
if (deep >= self.floors) {
return false;
}
var children = self._getChildren(newParents); var children = self._getChildren(newParents);
@ -17490,9 +17479,6 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result); createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result);
return [true, checked]; return [true, checked];
} }
if (deep >= self.floors) {
return [false, false];
}
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(current); newParents.push(current);
var children = self._getChildren(newParents); var children = self._getChildren(newParents);
@ -17517,14 +17503,14 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
} }
function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { function createOneJson(parentValues, value, isOpen, checked, half, flag, result) {
var node = self.map[value]; var node = self._getNode(parentValues, value)
result.push({ result.push({
id: node.id, id: node.id,
pId: node.pId, pId: node.pId,
text: node.text, text: node.text,
value: node.value, value: node.value,
title: node.title, title: node.title,
isParent: parentValues.length + 1 < self.floors, isParent: node.getChildrenLength() > 0,
open: isOpen, open: isOpen,
checked: checked, checked: checked,
halfCheck: half, halfCheck: half,
@ -17608,7 +17594,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
value: nodes[i].value, value: nodes[i].value,
text: nodes[i].text, text: nodes[i].text,
times: 1, times: 1,
isParent: parentValues.length + 1 < this.floors, isParent: nodes[i].getChildrenLength() > 0,
checked: state[0], checked: state[0],
halfCheck: state[1] halfCheck: state[1]
}) })
@ -17655,14 +17641,14 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
function getCheckState(current, parentValues, valueMap, checkState) { function getCheckState(current, parentValues, valueMap, checkState) {
var checked = checkState.checked, half = checkState.half; var checked = checkState.checked, half = checkState.half;
var hasChild = parentValues.length + 1 < self.floors;
var tempCheck = false, halfCheck = false; var tempCheck = false, halfCheck = false;
if (BI.has(valueMap, current)) { if (BI.has(valueMap, current)) {
//可能是半选 //可能是半选
if (valueMap[current][0] === 1) { if (valueMap[current][0] === 1) {
var values = BI.clone(parentValues); var values = BI.clone(parentValues);
values.push(current); values.push(current);
if (hasChild && self._getChildCount(values) !== valueMap[current][1]) { var childCount = self._getChildCount(values);
if (childCount > 0 && childCount !== valueMap[current][1]) {
halfCheck = true; halfCheck = true;
} }
} else if (valueMap[current][0] === 2) { } else if (valueMap[current][0] === 2) {
@ -17695,14 +17681,34 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree
return finded.finded.length > 0 || finded.matched.length > 0; return finded.finded.length > 0 || finded.matched.length > 0;
}, },
_getNode: function (v) { _getNode: function (parentValues, v) {
return this.tree.search(v, "value"); var self = this;
var findedParentNode;
var index = 0;
this.tree.traverse(function (node) {
if (self.tree.isRoot(node)) {
return;
}
if (index > parentValues.length) {
return false;
}
if (index === parentValues.length && node.value === v) {
findedParentNode = node;
return false;
}
if (node.value === parentValues[index]) {
index++;
return;
}
return true;
});
return findedParentNode;
}, },
_getChildren: function (parentValues) { _getChildren: function (parentValues) {
if (parentValues.length > 0) { if (parentValues.length > 0) {
var value = BI.last(parentValues); var value = BI.last(parentValues);
var parent = this.tree.search(value, "value"); var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value);
} else { } else {
var parent = this.tree.getRoot(); var parent = this.tree.getRoot();
} }
@ -17970,8 +17976,6 @@ BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-value-chooser-pane", baseCls: "bi-value-chooser-pane",
width: 200,
height: 30,
items: null, items: null,
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
cache: true cache: true

2
src/base/tree/asynctree.js

@ -187,7 +187,7 @@ BI.AsyncTree = BI.inherit(BI.TreeView, {
} }
var checkedValues = this._getSelectedValues(); var checkedValues = this._getSelectedValues();
if (BI.isEmpty(checkedValues)) { if (BI.isEmpty(checkedValues)) {
return this.selectedValues; return BI.deepClone(this.selectedValues);
} }
if (BI.isEmpty(this.selectedValues)) { if (BI.isEmpty(this.selectedValues)) {
return checkedValues; return checkedValues;

2
src/base/tree/parttree.js

@ -46,7 +46,7 @@ BI.PartTree = BI.inherit(BI.AsyncTree, {
BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments); BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
} else { } else {
o.itemsCreator(BI.extend({}, o.paras, { o.itemsCreator(BI.extend({}, o.paras, {
type: BI.TreeView.REQ_TYPE_CALCULATE_SELECT_DATA, type: BI.TreeView.REQ_TYPE_SELECT_DATA,
selectedValues: this.selectedValues, selectedValues: this.selectedValues,
notSelectedValue: name, notSelectedValue: name,
parentValues: parentValues parentValues: parentValues

12
src/base/tree/treeview.js

@ -216,7 +216,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
_getNodeValue: function (node) { _getNodeValue: function (node) {
//去除标红 //去除标红
return node.value || node.text.replace(/<[^>]+>/g, ""); return node.value == null ? node.text.replace(/<[^>]+>/g, "") : node.value;
}, },
//获取半选框值 //获取半选框值
@ -308,6 +308,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
var self = this, o = this.options; var self = this, o = this.options;
var ns = BI.Tree.arrayFormat(nodes); var ns = BI.Tree.arrayFormat(nodes);
BI.each(ns, function (i, n) { BI.each(ns, function (i, n) {
n.title = n.title || n.text || n.value;
//处理标红 //处理标红
if (BI.isKey(o.paras.keyword)) { if (BI.isKey(o.paras.keyword)) {
n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html(); n.text = $("<div>").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html();
@ -450,7 +451,7 @@ BI.TreeView = BI.inherit(BI.Pane, {
}, },
setSelectedValue: function (value) { setSelectedValue: function (value) {
this.options.paras.selectedValues = value || {}; this.options.paras.selectedValues = BI.deepClone(value) || {};
this.selectedValues = BI.deepClone(value) || {}; this.selectedValues = BI.deepClone(value) || {};
}, },
@ -486,14 +487,9 @@ BI.TreeView = BI.inherit(BI.Pane, {
return this._getSelectedValues(); return this._getSelectedValues();
}, },
empty: function () { destroyed: function () {
BI.isNotNull(this.nodes) && this.nodes.destroy();
},
destroy: function () {
this.stop(); this.stop();
this.nodes && this.nodes.destroy(); this.nodes && this.nodes.destroy();
BI.TreeView.superclass.destroy.apply(this, arguments);
} }
}); });
BI.extend(BI.TreeView, { BI.extend(BI.TreeView, {

18
src/case/toolbar/toolbar.multiselect.js

@ -12,7 +12,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
height: 25, height: 25,
text: BI.i18nText('BI-Select_All'), text: BI.i18nText('BI-Select_All'),
isAllCheckedBySelectedValue: BI.emptyFn, isAllCheckedBySelectedValue: BI.emptyFn,
onCheck: BI.emptyFn,
isHalfCheckedBySelectedValue: function (selectedValues) { isHalfCheckedBySelectedValue: function (selectedValues) {
return selectedValues.length > 0; return selectedValues.length > 0;
} }
@ -26,7 +25,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
stopPropagation: true, stopPropagation: true,
handler: function () { handler: function () {
self.setSelected(self.isSelected()); self.setSelected(self.isSelected());
o.onCheck.call(self, self.isSelected());
} }
}); });
this.half = BI.createWidget({ this.half = BI.createWidget({
@ -34,7 +32,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
stopPropagation: true, stopPropagation: true,
handler: function () { handler: function () {
self.setSelected(true); self.setSelected(true);
o.onCheck.call(self, self.isSelected());
} }
}); });
this.checkbox.on(BI.Controller.EVENT_CHANGE, function () { this.checkbox.on(BI.Controller.EVENT_CHANGE, function () {
@ -77,21 +74,6 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, {
this.half.invisible(); this.half.invisible();
}, },
doClick: function () {
var isHalf = this.isHalfSelected(), isSelected = this.isSelected();
if (isHalf === true) {
this.setSelected(true);
} else {
this.setSelected(!isSelected);
}
if (this.isValid()) {
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, this.getValue(), this);
this.options.onCheck.call(this, this.isSelected());
this.fireEvent(BI.MultiSelectBar.EVENT_CHANGE, this.isSelected(), this);
}
},
setSelected: function (v) { setSelected: function (v) {
this.checkbox.setSelected(v); this.checkbox.setSelected(v);
this.setHalfSelected(false); this.setHalfSelected(false);

75
src/component/treevaluechooser/abstract.treevaluechooser.js

@ -13,27 +13,9 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
_initData: function (items) { _initData: function (items) {
this.items = items; this.items = items;
var nodes = BI.Tree.transformToTreeFormat(items); var nodes = BI.Tree.treeFormat(items);
this.tree = new BI.Tree(); this.tree = new BI.Tree();
this.tree.initTree(nodes); this.tree.initTree(nodes);
this._initMap();
this._initFloors();
},
_initMap: function () {
var map = this.map = {};
BI.each(this.items, function (i, item) {
map[item.value] = item;
});
},
_initFloors: function () {
this.floors = -1;
var root = this.tree.getRoot();
while (root) {
this.floors++;
root = root.getChildren()[0];
}
}, },
_itemsCreator: function (options, callback) { _itemsCreator: function (options, callback) {
@ -77,32 +59,29 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
return; return;
} }
doCheck(0, [], this.tree.getRoot(), selectedValues); doCheck([], this.tree.getRoot(), selectedValues);
callback({ callback({
items: result items: result
}); });
function doCheck(floor, parentValues, node, selected) { function doCheck(parentValues, node, selected) {
if (floor >= self.floors) {
return;
}
if (selected == null || BI.isEmpty(selected)) { if (selected == null || BI.isEmpty(selected)) {
BI.each(node.getChildren(), function (i, child) { BI.each(node.getChildren(), function (i, child) {
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(child.value); newParents.push(child.value);
var llen = self._getChildCount(newParents); var llen = self._getChildCount(newParents);
createOneJson(child, node.id, llen); createOneJson(child, node.id, llen);
doCheck(floor + 1, newParents, child, {}); doCheck(newParents, child, {});
}); });
return; return;
} }
BI.each(selected, function (k) { BI.each(selected, function (k) {
var node = self._getNode(k); var node = self._getNode(parentValues, k);
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(node.value); newParents.push(node.value);
createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents));
doCheck(floor + 1, newParents, node, selected[k]); doCheck(newParents, node, selected[k]);
}) })
} }
@ -192,9 +171,6 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
if (self._isMatch(current, keyword)) { if (self._isMatch(current, keyword)) {
return true; return true;
} }
if (deep >= self.floors) {
return false;
}
var children = self._getChildren(newParents); var children = self._getChildren(newParents);
@ -330,9 +306,6 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result); createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result);
return [true, checked]; return [true, checked];
} }
if (deep >= self.floors) {
return [false, false];
}
var newParents = BI.clone(parentValues); var newParents = BI.clone(parentValues);
newParents.push(current); newParents.push(current);
var children = self._getChildren(newParents); var children = self._getChildren(newParents);
@ -357,14 +330,14 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
} }
function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { function createOneJson(parentValues, value, isOpen, checked, half, flag, result) {
var node = self.map[value]; var node = self._getNode(parentValues, value)
result.push({ result.push({
id: node.id, id: node.id,
pId: node.pId, pId: node.pId,
text: node.text, text: node.text,
value: node.value, value: node.value,
title: node.title, title: node.title,
isParent: parentValues.length + 1 < self.floors, isParent: node.getChildrenLength() > 0,
open: isOpen, open: isOpen,
checked: checked, checked: checked,
halfCheck: half, halfCheck: half,
@ -448,7 +421,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
value: nodes[i].value, value: nodes[i].value,
text: nodes[i].text, text: nodes[i].text,
times: 1, times: 1,
isParent: parentValues.length + 1 < this.floors, isParent: nodes[i].getChildrenLength() > 0,
checked: state[0], checked: state[0],
halfCheck: state[1] halfCheck: state[1]
}) })
@ -495,14 +468,14 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
function getCheckState(current, parentValues, valueMap, checkState) { function getCheckState(current, parentValues, valueMap, checkState) {
var checked = checkState.checked, half = checkState.half; var checked = checkState.checked, half = checkState.half;
var hasChild = parentValues.length + 1 < self.floors;
var tempCheck = false, halfCheck = false; var tempCheck = false, halfCheck = false;
if (BI.has(valueMap, current)) { if (BI.has(valueMap, current)) {
//可能是半选 //可能是半选
if (valueMap[current][0] === 1) { if (valueMap[current][0] === 1) {
var values = BI.clone(parentValues); var values = BI.clone(parentValues);
values.push(current); values.push(current);
if (hasChild && self._getChildCount(values) !== valueMap[current][1]) { var childCount = self._getChildCount(values);
if (childCount > 0 && childCount !== valueMap[current][1]) {
halfCheck = true; halfCheck = true;
} }
} else if (valueMap[current][0] === 2) { } else if (valueMap[current][0] === 2) {
@ -535,14 +508,34 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
return finded.finded.length > 0 || finded.matched.length > 0; return finded.finded.length > 0 || finded.matched.length > 0;
}, },
_getNode: function (v) { _getNode: function (parentValues, v) {
return this.tree.search(v, "value"); var self = this;
var findedParentNode;
var index = 0;
this.tree.traverse(function (node) {
if (self.tree.isRoot(node)) {
return;
}
if (index > parentValues.length) {
return false;
}
if (index === parentValues.length && node.value === v) {
findedParentNode = node;
return false;
}
if (node.value === parentValues[index]) {
index++;
return;
}
return true;
});
return findedParentNode;
}, },
_getChildren: function (parentValues) { _getChildren: function (parentValues) {
if (parentValues.length > 0) { if (parentValues.length > 0) {
var value = BI.last(parentValues); var value = BI.last(parentValues);
var parent = this.tree.search(value, "value"); var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value);
} else { } else {
var parent = this.tree.getRoot(); var parent = this.tree.getRoot();
} }

2
src/component/valuechooser/pane.valuechooser.js

@ -11,8 +11,6 @@ BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-value-chooser-pane", baseCls: "bi-value-chooser-pane",
width: 200,
height: 30,
items: null, items: null,
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
cache: true cache: true

8
src/core/base.js

@ -457,15 +457,15 @@ if (!window.BI) {
}, },
has: function (obj, keys) { has: function (obj, keys) {
if (BI.isKey(keys)) { if (BI.isArray(keys)) {
return _.has.apply(_, arguments); if (keys.length === 0) {
}
if (!keys || BI.isEmpty(keys)) {
return false; return false;
} }
return BI.every(keys, function (i, key) { return BI.every(keys, function (i, key) {
return _.has(obj, key); return _.has(obj, key);
}); });
}
return _.has.apply(_, arguments);
}, },
//数字和字符串可以作为key //数字和字符串可以作为key

49
src/core/utils/tree.js

@ -17,7 +17,7 @@
}, },
isRoot: function (node) { isRoot: function (node) {
return node === this.root || node.id === this.root.id; return node === this.root;
}, },
getRoot: function () { getRoot: function () {
@ -394,7 +394,7 @@
if (BI.isArray(nodes)) { if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
var node = BI.clone(nodes[i]); var node = BI.clone(nodes[i]);
node.pId = pId; node.pId = node.pId == null ? pId : node.pId;
delete node.children; delete node.children;
r.push(node); r.push(node);
if (nodes[i]["children"]) { if (nodes[i]["children"]) {
@ -403,7 +403,7 @@
} }
} else { } else {
var newNodes = BI.clone(nodes); var newNodes = BI.clone(nodes);
newNodes.pId = pId; newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
delete newNodes.children; delete newNodes.children;
r.push(newNodes); r.push(newNodes);
if (nodes["children"]) { if (nodes["children"]) {
@ -414,21 +414,25 @@
}, },
arrayFormat: function (nodes, pId) { arrayFormat: function (nodes, pId) {
if (!nodes) return []; if (!nodes) {
return [];
}
var r = []; var r = [];
if (BI.isArray(nodes)) { if (BI.isArray(nodes)) {
for (var i = 0, l = nodes.length; i < l; i++) { for (var i = 0, l = nodes.length; i < l; i++) {
var node = nodes[i]; var node = nodes[i];
node.pId = node.pId == null ? pId : node.pId;
r.push(node); r.push(node);
if (nodes[i]["children"]) { if (nodes[i]["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes[i]["children"], node.id)); r = r.concat(BI.Tree.arrayFormat(nodes[i]["children"], node.id));
} }
} }
} else { } else {
var newNodes = nodes; var newNodes = nodes;
newNodes.pId = newNodes.pId == null ? pId : newNodes.pId;
r.push(newNodes); r.push(newNodes);
if (nodes["children"]) { if (nodes["children"]) {
r = r.concat(BI.Tree.transformToArrayFormat(nodes["children"], newNodes.id)); r = r.concat(BI.Tree.arrayFormat(nodes["children"], newNodes.id));
} }
} }
return r; return r;
@ -450,7 +454,7 @@
tmpMap[sNodes[i].id] = BI.clone(sNodes[i]); tmpMap[sNodes[i].id] = BI.clone(sNodes[i]);
} }
for (i = 0, l = sNodes.length; i < l; i++) { for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id != sNodes[i].pId) { if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) { if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = []; tmpMap[sNodes[i].pId].children = [];
} }
@ -466,6 +470,37 @@
} }
}, },
treeFormat: function (sNodes) {
var i, l;
if (!sNodes) {
return [];
}
if (BI.isArray(sNodes)) {
var r = [];
var tmpMap = [];
for (i = 0, l = sNodes.length; i < l; i++) {
if (BI.isNull(sNodes[i].id)) {
return sNodes;
}
tmpMap[sNodes[i].id] = sNodes[i];
}
for (i = 0, l = sNodes.length; i < l; i++) {
if (tmpMap[sNodes[i].pId] && sNodes[i].id !== sNodes[i].pId) {
if (!tmpMap[sNodes[i].pId].children) {
tmpMap[sNodes[i].pId].children = [];
}
tmpMap[sNodes[i].pId].children.push(tmpMap[sNodes[i].id]);
} else {
r.push(tmpMap[sNodes[i].id]);
}
}
return r;
} else {
return [sNodes];
}
},
traversal: function (array, callback) { traversal: function (array, callback) {
if (BI.isNull(array)) { if (BI.isNull(array)) {
return; return;

6
src/widget/multiselectlist/multiselectlist.js

@ -17,6 +17,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
var assertShowValue = function () { var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue);
self.trigger.setValue(self.storeValue);
}; };
this.adapter = BI.createWidget({ this.adapter = BI.createWidget({
@ -76,6 +77,8 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
self._showAdapter(); self._showAdapter();
self._setStartValue(""); self._setStartValue("");
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
//需要刷新回到初始界面,否则搜索的结果不能放在最前面
self.adapter.populate();
} }
}, { }, {
eventName: BI.Searcher.EVENT_PAUSE, eventName: BI.Searcher.EVENT_PAUSE,
@ -87,7 +90,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
value: [keyword] value: [keyword]
}, function () { }, function () {
self._showAdapter(); self._showAdapter();
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
self._setStartValue(keyword); self._setStartValue(keyword);
assertShowValue(); assertShowValue();
@ -107,13 +109,11 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); self._setStartValue("");
} else { } else {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
} }

Loading…
Cancel
Save