From eebb79b1ac48d251ce43ad722ebddb527ba99fea Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 20 May 2017 15:20:57 +0800 Subject: [PATCH 1/2] add --- bi/base.js | 12 ++++++------ docs/base.js | 12 ++++++------ src/base/collection/collection.js | 4 ++-- src/base/grid/grid.js | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bi/base.js b/bi/base.js index 165a9b0259..728e5fd04f 100644 --- a/bi/base.js +++ b/bi/base.js @@ -2532,8 +2532,8 @@ BI.CollectionView = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.CollectionView.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-collection", - width: 400, - height: 300, + // width: 400, + // height: 300, overflowX: true, overflowY: true, cellSizeAndPositionGetter: BI.emptyFn, @@ -14673,16 +14673,16 @@ BI.GridView = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.GridView.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-grid-view", - width: 400, - height: 300, + // width: 400, + // height: 300, overflowX: true, overflowY: true, overscanColumnCount: 0, overscanRowCount: 0, rowHeightGetter: BI.emptyFn, columnWidthGetter: BI.emptyFn, - estimatedColumnSize: 100, - estimatedRowSize: 30, + // estimatedColumnSize: 100, + // estimatedRowSize: 30, scrollLeft: 0, scrollTop: 0, items: [] diff --git a/docs/base.js b/docs/base.js index 165a9b0259..728e5fd04f 100644 --- a/docs/base.js +++ b/docs/base.js @@ -2532,8 +2532,8 @@ BI.CollectionView = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.CollectionView.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-collection", - width: 400, - height: 300, + // width: 400, + // height: 300, overflowX: true, overflowY: true, cellSizeAndPositionGetter: BI.emptyFn, @@ -14673,16 +14673,16 @@ BI.GridView = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.GridView.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-grid-view", - width: 400, - height: 300, + // width: 400, + // height: 300, overflowX: true, overflowY: true, overscanColumnCount: 0, overscanRowCount: 0, rowHeightGetter: BI.emptyFn, columnWidthGetter: BI.emptyFn, - estimatedColumnSize: 100, - estimatedRowSize: 30, + // estimatedColumnSize: 100, + // estimatedRowSize: 30, scrollLeft: 0, scrollTop: 0, items: [] diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index d359668a56..ab942f7bcf 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -9,8 +9,8 @@ BI.CollectionView = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.CollectionView.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-collection", - width: 400, - height: 300, + // width: 400, + // height: 300, overflowX: true, overflowY: true, cellSizeAndPositionGetter: BI.emptyFn, diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index c76f354c75..3ff3ff30fd 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -9,16 +9,16 @@ BI.GridView = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.GridView.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-grid-view", - width: 400, - height: 300, + // width: 400, + // height: 300, overflowX: true, overflowY: true, overscanColumnCount: 0, overscanRowCount: 0, rowHeightGetter: BI.emptyFn, columnWidthGetter: BI.emptyFn, - estimatedColumnSize: 100, - estimatedRowSize: 30, + // estimatedColumnSize: 100, + // estimatedRowSize: 30, scrollLeft: 0, scrollTop: 0, items: [] From e15c61b6e4e9c0baa007c4e6b02b0ab0e7f79ed2 Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 20 May 2017 17:19:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=A0=91=E3=80=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/widget.js | 402 +++++++++---- ...ooser.js => demo.treevaluechoosercombo.js} | 6 +- .../js/component/demo.treevaluechooserpane.js | 34 ++ ...uechooser.js => demo.valuechoosercombo.js} | 0 demo/js/component/demo.valuechooserpane.js | 15 + demo/js/config/component.js | 10 +- docs/demo.js | 66 ++- docs/widget.js | 402 +++++++++---- .../abstract.allvaluechooser.js | 79 +++ .../allvaluechooser/combo.allvaluechooser.js | 62 +- .../allvaluechooser/pane.allvaluechooser.js | 62 ++ .../abstract.treevaluechooser.js | 555 ++++++++++++++++++ .../combo.treevaluechooser.js | 550 +---------------- .../treevaluechooser/pane.treevaluechooser.js | 49 ++ .../valuechooser/abstract.valuechooser.js | 89 +++ .../valuechooser/combo.valuechooser.js | 72 +-- .../valuechooser/pane.valuechooser.js | 58 ++ src/widget/multiselectlist/multiselectlist.js | 7 +- src/widget/multiselecttree/multiselecttree.js | 8 +- .../multiselecttree/multiselecttree.popup.js | 1 - 20 files changed, 1629 insertions(+), 898 deletions(-) rename demo/js/component/{demo.treevaluechooser.js => demo.treevaluechoosercombo.js} (85%) create mode 100644 demo/js/component/demo.treevaluechooserpane.js rename demo/js/component/{demo.valuechooser.js => demo.valuechoosercombo.js} (100%) create mode 100644 demo/js/component/demo.valuechooserpane.js create mode 100644 src/component/allvaluechooser/abstract.allvaluechooser.js create mode 100644 src/component/allvaluechooser/pane.allvaluechooser.js create mode 100644 src/component/treevaluechooser/abstract.treevaluechooser.js create mode 100644 src/component/treevaluechooser/pane.treevaluechooser.js create mode 100644 src/component/valuechooser/abstract.valuechooser.js create mode 100644 src/component/valuechooser/pane.valuechooser.js diff --git a/bi/widget.js b/bi/widget.js index 55d86a401e..7e9bde29b8 100644 --- a/bi/widget.js +++ b/bi/widget.js @@ -10962,8 +10962,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { return BI.extend(BI.MultiSelectList.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-select-list', itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - el: {} + valueFormatter: BI.emptyFn }) }, _init: function () { @@ -11096,8 +11095,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.vtape", element: this, - height: "100%", - width: "100%", items: [{ el: this.trigger, height: 30 @@ -11109,8 +11106,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.absolute", element: this, - height: "100%", - width: "100%", items: [{ el: this.searcherPane, top: 30, @@ -11307,8 +11302,7 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-select-tree', - itemsCreator: BI.emptyFn, - height: 25 + itemsCreator: BI.emptyFn }) }, @@ -11354,7 +11348,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { }, adapter: this.adapter, popup: this.searcherPane, - height: 200, masker: false, listeners: [{ eventName: BI.Searcher.EVENT_START, @@ -11394,8 +11387,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.vtape", element: this, - height: "100%", - width: "100%", items: [{ el: this.trigger, height: 30 @@ -11407,8 +11398,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.absolute", element: this, - height: "100%", - width: "100%", items: [{ el: this.searcherPane, top: 30, @@ -11469,7 +11458,6 @@ BI.MultiSelectTreePopup = BI.inherit(BI.Widget, { var self = this, o = this.options; this.popup = BI.createWidget({ type: "bi.async_tree", - height: 400, element: this, itemsCreator: o.itemsCreator }); @@ -16978,14 +16966,14 @@ BI.shortcut('bi.year_quarter_combo', BI.YearQuarterCombo);/** * @class BI.AllValueChooserCombo * @extends BI.Widget */ -BI.AllValueChooserCombo = BI.inherit(BI.Widget, { +BI.AbstractAllValueChooser = BI.inherit(BI.Widget, { _const: { - perPage: 10 + perPage: 100 }, + _defaultConfig: function () { return BI.extend(BI.AllValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-all-value-chooser-combo", width: 200, height: 30, items: null, @@ -16994,35 +16982,17 @@ BI.AllValueChooserCombo = BI.inherit(BI.Widget, { }); }, - _init: function () { - BI.AllValueChooserCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNotNull(o.items)) { - this.items = o.items; - } - this.combo = BI.createWidget({ - type: 'bi.multi_select_combo', - element: this, - itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: function (v) { - var text = v; - if (BI.isNotNull(self.items)) { - BI.some(self.items, function (i, item) { - if (item.value === v) { - text = item.text; - return true; - } - }); + _valueFormatter: function (v) { + var text = v; + if (BI.isNotNull(this.items)) { + BI.some(this.items, function (i, item) { + if (item.value === v) { + text = item.text; + return true; } - return text; - }, - width: o.width, - height: o.height - }); - - this.combo.on(BI.MultiSelectCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.AllValueChooserCombo.EVENT_CONFIRM); - }); + }); + } + return text; }, _itemsCreator: function (options, callback) { @@ -17065,6 +17035,46 @@ BI.AllValueChooserCombo = BI.inherit(BI.Widget, { hasNext: false }); } + } +});/** + * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.AllValueChooserCombo + * @extends BI.AbstractAllValueChooser + */ +BI.AllValueChooserCombo = BI.inherit(BI.AbstractAllValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.AllValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-all-value-chooser-combo", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _init: function () { + BI.AllValueChooserCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNotNull(o.items)) { + this.items = o.items; + } + this.combo = BI.createWidget({ + type: 'bi.multi_select_combo', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this), + width: o.width, + height: o.height + }); + + this.combo.on(BI.MultiSelectCombo.EVENT_CONFIRM, function () { + self.fireEvent(BI.AllValueChooserCombo.EVENT_CONFIRM); + }); }, setValue: function (v) { @@ -17088,44 +17098,76 @@ BI.AllValueChooserCombo = BI.inherit(BI.Widget, { }); BI.AllValueChooserCombo.EVENT_CONFIRM = "AllValueChooserCombo.EVENT_CONFIRM"; BI.shortcut('bi.all_value_chooser_combo', BI.AllValueChooserCombo);/** - * 简单的复选下拉树控件, 适用于数据量少的情况 + * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 + * 封装了字段处理逻辑 * * Created by GUY on 2015/10/29. - * @class BI.TreeValueChooserCombo - * @extends BI.Widget + * @class BI.AllValueChooserPane + * @extends BI.AbstractAllValueChooser */ -BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { - - _const: { - perPage: 10 - }, +BI.AllValueChooserPane = BI.inherit(BI.AbstractAllValueChooser, { _defaultConfig: function () { - return BI.extend(BI.TreeValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-tree-value-chooser-combo", + return BI.extend(BI.AllValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-all-value-chooser-pane", width: 200, height: 30, items: null, - itemsCreator: BI.emptyFn + itemsCreator: BI.emptyFn, + cache: true }); }, _init: function () { - BI.TreeValueChooserCombo.superclass._init.apply(this, arguments); + BI.AllValueChooserPane.superclass._init.apply(this, arguments); var self = this, o = this.options; if (BI.isNotNull(o.items)) { - this._initData(o.items); + this.items = o.items; } - this.combo = BI.createWidget({ - type: 'bi.multi_tree_combo', + this.list = BI.createWidget({ + type: 'bi.multi_select_list', element: this, itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this), width: o.width, height: o.height }); - this.combo.on(BI.MultiTreeCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_CONFIRM); + this.list.on(BI.MultiSelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.AllValueChooserPane.EVENT_CHANGE); + }); + }, + + setValue: function (v) { + this.list.setValue({ + type: BI.Selection.Multi, + value: v || [] + }); + }, + + getValue: function () { + var val = this.list.getValue() || {}; + if (val.type === BI.Selection.All) { + return val.assist; + } + return val.value || []; + }, + + populate: function () { + this.list.populate.apply(this.list, arguments); + } +}); +BI.AllValueChooserPane.EVENT_CHANGE = "AllValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { + + _const: { + perPage: 100 + }, + + _defaultConfig: function () { + return BI.extend(BI.AbstractTreeValueChooser.superclass._defaultConfig.apply(this, arguments), { + items: null, + itemsCreator: BI.emptyFn }); }, @@ -17669,6 +17711,43 @@ BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { _getChildCount: function (parentValues) { return this._getChildren(parentValues).length; + } +});/** + * 简单的复选下拉树控件, 适用于数据量少的情况 + * + * Created by GUY on 2015/10/29. + * @class BI.TreeValueChooserCombo + * @extends BI.Widget + */ +BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.TreeValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-tree-value-chooser-combo", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn + }); + }, + + _init: function () { + BI.TreeValueChooserCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNotNull(o.items)) { + this._initData(o.items); + } + this.combo = BI.createWidget({ + type: 'bi.multi_tree_combo', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + width: o.width, + height: o.height + }); + + this.combo.on(BI.MultiTreeCombo.EVENT_CONFIRM, function () { + self.fireEvent(BI.TreeValueChooserCombo.EVENT_CONFIRM); + }); }, setValue: function (v) { @@ -17680,63 +17759,91 @@ BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { }, populate: function () { - this.combo.populate.apply(this, arguments); + this.combo.populate.apply(this.combo, arguments); } }); BI.TreeValueChooserCombo.EVENT_CONFIRM = "TreeValueChooserCombo.EVENT_CONFIRM"; BI.shortcut('bi.tree_value_chooser_combo', BI.TreeValueChooserCombo);/** + * 简单的复选下拉树控件, 适用于数据量少的情况 + * + * Created by GUY on 2015/10/29. + * @class BI.TreeValueChooserPane + * @extends BI.AbstractTreeValueChooser + */ +BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.TreeValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-tree-value-chooser-pane", + items: null, + itemsCreator: BI.emptyFn + }); + }, + + _init: function () { + BI.TreeValueChooserPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.pane = BI.createWidget({ + type: 'bi.multi_select_tree', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this) + }); + + this.pane.on(BI.MultiSelectTree.EVENT_CHANGE, function () { + self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE); + }); + if (BI.isNotNull(o.items)) { + this._initData(o.items); + this.populate(); + } + }, + + setValue: function (v) { + this.pane.setValue(v); + }, + + getValue: function () { + return this.pane.getValue(); + }, + + populate: function () { + this.pane.populate.apply(this.pane, arguments); + } +}); +BI.TreeValueChooserPane.EVENT_CHANGE = "TreeValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.tree_value_chooser_pane', BI.TreeValueChooserPane);/** * 简单的复选下拉框控件, 适用于数据量少的情况 * 封装了字段处理逻辑 * * Created by GUY on 2015/10/29. - * @class BI.ValueChooserCombo + * @class BI.AbstractValueChooser * @extends BI.Widget */ -BI.ValueChooserCombo = BI.inherit(BI.Widget, { +BI.AbstractValueChooser = BI.inherit(BI.Widget, { _const: { - perPage: 10 + perPage: 100 }, + _defaultConfig: function () { - return BI.extend(BI.ValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-value-chooser-combo", - width: 200, - height: 30, + return BI.extend(BI.AbstractValueChooser.superclass._defaultConfig.apply(this, arguments), { items: null, itemsCreator: BI.emptyFn, cache: true }); }, - _init: function () { - BI.ValueChooserCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNotNull(o.items)) { - this.items = o.items; - } - this.combo = BI.createWidget({ - type: 'bi.multi_select_combo', - element: this, - itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: function (v) { - var text = v; - if (BI.isNotNull(self.items)) { - BI.some(self.items, function (i, item) { - if (item.value === v) { - text = item.text; - return true; - } - }); + _valueFormatter: function (v) { + var text = v; + if (BI.isNotNull(this.items)) { + BI.some(this.items, function (i, item) { + if (item.value === v) { + text = item.text; + return true; } - return text; - }, - width: o.width, - height: o.height - }); - - this.combo.on(BI.MultiSelectCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.ValueChooserCombo.EVENT_CONFIRM); - }); + }); + } + return text; }, _getItemsByTimes: function (items, times) { @@ -17791,6 +17898,46 @@ BI.ValueChooserCombo = BI.inherit(BI.Widget, { hasNext: self._hasNextByTimes(items, options.times) }); } + } +});/** + * 简单的复选下拉框控件, 适用于数据量少的情况 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.ValueChooserCombo + * @extends BI.Widget + */ +BI.ValueChooserCombo = BI.inherit(BI.AbstractValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.ValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-value-chooser-combo", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _init: function () { + BI.ValueChooserCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNotNull(o.items)) { + this.items = o.items; + } + this.combo = BI.createWidget({ + type: 'bi.multi_select_combo', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this), + width: o.width, + height: o.height + }); + + this.combo.on(BI.MultiSelectCombo.EVENT_CONFIRM, function () { + self.fireEvent(BI.ValueChooserCombo.EVENT_CONFIRM); + }); }, setValue: function (v) { @@ -17810,4 +17957,61 @@ BI.ValueChooserCombo = BI.inherit(BI.Widget, { } }); BI.ValueChooserCombo.EVENT_CONFIRM = "ValueChooserCombo.EVENT_CONFIRM"; -BI.shortcut('bi.value_chooser_combo', BI.ValueChooserCombo); \ No newline at end of file +BI.shortcut('bi.value_chooser_combo', BI.ValueChooserCombo);/** + * 简单的复选下拉框控件, 适用于数据量少的情况 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.ValueChooserPane + * @extends BI.Widget + */ +BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-value-chooser-pane", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _init: function () { + BI.ValueChooserPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.list = BI.createWidget({ + type: 'bi.multi_select_list', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this) + }); + + this.list.on(BI.MultiSelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.ValueChooserPane.EVENT_CHANGE); + }); + if (BI.isNotNull(o.items)) { + this.items = o.items; + this.populate(); + } + }, + + setValue: function (v) { + this.list.setValue(v); + }, + + getValue: function () { + var val = this.list.getValue() || {}; + return { + type: val.type, + value: val.value + } + }, + + populate: function () { + this.list.populate.apply(this.list, arguments); + } +}); +BI.ValueChooserPane.EVENT_CHANGE = "ValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.value_chooser_pane', BI.ValueChooserPane); \ No newline at end of file diff --git a/demo/js/component/demo.treevaluechooser.js b/demo/js/component/demo.treevaluechoosercombo.js similarity index 85% rename from demo/js/component/demo.treevaluechooser.js rename to demo/js/component/demo.treevaluechoosercombo.js index dcbcc8c4b2..5de2bcdeb7 100644 --- a/demo/js/component/demo.treevaluechooser.js +++ b/demo/js/component/demo.treevaluechoosercombo.js @@ -1,11 +1,11 @@ Demo.TreeValueChooser = BI.inherit(BI.Widget, { props: { - baseCls: "demo-tree-value-chooser" + baseCls: "demo-tree-value-chooser-combo" }, render: function () { var tree = []; - for (var i = 0; i < 21; i++) { + for (var i = 0; i < 221; i++) { tree.push({ value: "" + i + "", text: "" + i + "", @@ -37,4 +37,4 @@ Demo.TreeValueChooser = BI.inherit(BI.Widget, { }; } }); -BI.shortcut("demo.tree_value_chooser", Demo.TreeValueChooser); +BI.shortcut("demo.tree_value_chooser_combo", Demo.TreeValueChooser); diff --git a/demo/js/component/demo.treevaluechooserpane.js b/demo/js/component/demo.treevaluechooserpane.js new file mode 100644 index 0000000000..e74caac7e7 --- /dev/null +++ b/demo/js/component/demo.treevaluechooserpane.js @@ -0,0 +1,34 @@ +Demo.TreeValueChooser = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-tree-value-chooser" + }, + 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 { + type: "bi.tree_value_chooser_pane", + width: 300, + items: tree, + itemsCreator: function (op, callback) { + callback(tree); + } + }; + } +}); +BI.shortcut("demo.tree_value_chooser_pane", Demo.TreeValueChooser); diff --git a/demo/js/component/demo.valuechooser.js b/demo/js/component/demo.valuechoosercombo.js similarity index 100% rename from demo/js/component/demo.valuechooser.js rename to demo/js/component/demo.valuechoosercombo.js diff --git a/demo/js/component/demo.valuechooserpane.js b/demo/js/component/demo.valuechooserpane.js new file mode 100644 index 0000000000..f2ff3ba7e6 --- /dev/null +++ b/demo/js/component/demo.valuechooserpane.js @@ -0,0 +1,15 @@ +Demo.ValueChooserPane = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-value-chooser-pane" + }, + render: function () { + return { + type: "bi.value_chooser_pane", + items: BI.deepClone(Demo.CONSTANTS.ITEMS), + itemsCreator: function (op, callback) { + callback(BI.deepClone(Demo.CONSTANTS.ITEMS)); + } + }; + } +}); +BI.shortcut("demo.value_chooser_pane", Demo.ValueChooserPane); \ No newline at end of file diff --git a/demo/js/config/component.js b/demo/js/config/component.js index b797e09f3c..1815ca70a0 100644 --- a/demo/js/config/component.js +++ b/demo/js/config/component.js @@ -8,8 +8,16 @@ Demo.COMPONENT_CONFIG = [{ pId: 5, text: "bi.value_chooser_combo", value: "demo.value_chooser_combo" +}, { + pId: 5, + text: "bi.value_chooser_pane", + value: "demo.value_chooser_pane" }, { pId: 5, text: "bi.tree_value_chooser_combo", - value: "demo.tree_value_chooser" + value: "demo.tree_value_chooser_combo" +}, { + pId: 5, + text: "bi.tree_value_chooser_pane", + value: "demo.tree_value_chooser_pane" }]; \ No newline at end of file diff --git a/docs/demo.js b/docs/demo.js index f1787c8f12..7cec4c55d6 100644 --- a/docs/demo.js +++ b/docs/demo.js @@ -2620,12 +2620,12 @@ BI.shortcut("demo.center", Demo.Center);Demo.Func = BI.inherit(BI.Widget, { BI.shortcut("demo.axis_chart", Demo.Func); Demo.TreeValueChooser = BI.inherit(BI.Widget, { props: { - baseCls: "demo-tree-value-chooser" + baseCls: "demo-tree-value-chooser-combo" }, render: function () { var tree = []; - for (var i = 0; i < 21; i++) { + for (var i = 0; i < 221; i++) { tree.push({ value: "" + i + "", text: "" + i + "", @@ -2657,7 +2657,41 @@ Demo.TreeValueChooser = BI.inherit(BI.Widget, { }; } }); -BI.shortcut("demo.tree_value_chooser", Demo.TreeValueChooser); +BI.shortcut("demo.tree_value_chooser_combo", Demo.TreeValueChooser); +Demo.TreeValueChooser = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-tree-value-chooser" + }, + 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 { + type: "bi.tree_value_chooser_pane", + width: 300, + items: tree, + itemsCreator: function (op, callback) { + callback(tree); + } + }; + } +}); +BI.shortcut("demo.tree_value_chooser_pane", Demo.TreeValueChooser); Demo.ValueChooserCombo = BI.inherit(BI.Widget, { props: { baseCls: "demo-value-chooser-combo" @@ -2677,7 +2711,21 @@ Demo.ValueChooserCombo = BI.inherit(BI.Widget, { }; } }); -BI.shortcut("demo.value_chooser_combo", Demo.ValueChooserCombo);Demo.BASE_CONFIG = [{ +BI.shortcut("demo.value_chooser_combo", Demo.ValueChooserCombo);Demo.ValueChooserPane = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-value-chooser-pane" + }, + render: function () { + return { + type: "bi.value_chooser_pane", + items: BI.deepClone(Demo.CONSTANTS.ITEMS), + itemsCreator: function (op, callback) { + callback(BI.deepClone(Demo.CONSTANTS.ITEMS)); + } + }; + } +}); +BI.shortcut("demo.value_chooser_pane", Demo.ValueChooserPane);Demo.BASE_CONFIG = [{ id: 2, text: "基础控件", open: true @@ -2906,10 +2954,18 @@ Demo.COMPONENT_CONFIG = [{ pId: 5, text: "bi.value_chooser_combo", value: "demo.value_chooser_combo" +}, { + pId: 5, + text: "bi.value_chooser_pane", + value: "demo.value_chooser_pane" }, { pId: 5, text: "bi.tree_value_chooser_combo", - value: "demo.tree_value_chooser" + value: "demo.tree_value_chooser_combo" +}, { + pId: 5, + text: "bi.tree_value_chooser_pane", + value: "demo.tree_value_chooser_pane" }];Demo.CORE_CONFIG = [{ id: 1, text: "核心控件", diff --git a/docs/widget.js b/docs/widget.js index 55d86a401e..7e9bde29b8 100644 --- a/docs/widget.js +++ b/docs/widget.js @@ -10962,8 +10962,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { return BI.extend(BI.MultiSelectList.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-select-list', itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - el: {} + valueFormatter: BI.emptyFn }) }, _init: function () { @@ -11096,8 +11095,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.vtape", element: this, - height: "100%", - width: "100%", items: [{ el: this.trigger, height: 30 @@ -11109,8 +11106,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.absolute", element: this, - height: "100%", - width: "100%", items: [{ el: this.searcherPane, top: 30, @@ -11307,8 +11302,7 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-select-tree', - itemsCreator: BI.emptyFn, - height: 25 + itemsCreator: BI.emptyFn }) }, @@ -11354,7 +11348,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { }, adapter: this.adapter, popup: this.searcherPane, - height: 200, masker: false, listeners: [{ eventName: BI.Searcher.EVENT_START, @@ -11394,8 +11387,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.vtape", element: this, - height: "100%", - width: "100%", items: [{ el: this.trigger, height: 30 @@ -11407,8 +11398,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.absolute", element: this, - height: "100%", - width: "100%", items: [{ el: this.searcherPane, top: 30, @@ -11469,7 +11458,6 @@ BI.MultiSelectTreePopup = BI.inherit(BI.Widget, { var self = this, o = this.options; this.popup = BI.createWidget({ type: "bi.async_tree", - height: 400, element: this, itemsCreator: o.itemsCreator }); @@ -16978,14 +16966,14 @@ BI.shortcut('bi.year_quarter_combo', BI.YearQuarterCombo);/** * @class BI.AllValueChooserCombo * @extends BI.Widget */ -BI.AllValueChooserCombo = BI.inherit(BI.Widget, { +BI.AbstractAllValueChooser = BI.inherit(BI.Widget, { _const: { - perPage: 10 + perPage: 100 }, + _defaultConfig: function () { return BI.extend(BI.AllValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-all-value-chooser-combo", width: 200, height: 30, items: null, @@ -16994,35 +16982,17 @@ BI.AllValueChooserCombo = BI.inherit(BI.Widget, { }); }, - _init: function () { - BI.AllValueChooserCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNotNull(o.items)) { - this.items = o.items; - } - this.combo = BI.createWidget({ - type: 'bi.multi_select_combo', - element: this, - itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: function (v) { - var text = v; - if (BI.isNotNull(self.items)) { - BI.some(self.items, function (i, item) { - if (item.value === v) { - text = item.text; - return true; - } - }); + _valueFormatter: function (v) { + var text = v; + if (BI.isNotNull(this.items)) { + BI.some(this.items, function (i, item) { + if (item.value === v) { + text = item.text; + return true; } - return text; - }, - width: o.width, - height: o.height - }); - - this.combo.on(BI.MultiSelectCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.AllValueChooserCombo.EVENT_CONFIRM); - }); + }); + } + return text; }, _itemsCreator: function (options, callback) { @@ -17065,6 +17035,46 @@ BI.AllValueChooserCombo = BI.inherit(BI.Widget, { hasNext: false }); } + } +});/** + * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.AllValueChooserCombo + * @extends BI.AbstractAllValueChooser + */ +BI.AllValueChooserCombo = BI.inherit(BI.AbstractAllValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.AllValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-all-value-chooser-combo", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _init: function () { + BI.AllValueChooserCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNotNull(o.items)) { + this.items = o.items; + } + this.combo = BI.createWidget({ + type: 'bi.multi_select_combo', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this), + width: o.width, + height: o.height + }); + + this.combo.on(BI.MultiSelectCombo.EVENT_CONFIRM, function () { + self.fireEvent(BI.AllValueChooserCombo.EVENT_CONFIRM); + }); }, setValue: function (v) { @@ -17088,44 +17098,76 @@ BI.AllValueChooserCombo = BI.inherit(BI.Widget, { }); BI.AllValueChooserCombo.EVENT_CONFIRM = "AllValueChooserCombo.EVENT_CONFIRM"; BI.shortcut('bi.all_value_chooser_combo', BI.AllValueChooserCombo);/** - * 简单的复选下拉树控件, 适用于数据量少的情况 + * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 + * 封装了字段处理逻辑 * * Created by GUY on 2015/10/29. - * @class BI.TreeValueChooserCombo - * @extends BI.Widget + * @class BI.AllValueChooserPane + * @extends BI.AbstractAllValueChooser */ -BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { - - _const: { - perPage: 10 - }, +BI.AllValueChooserPane = BI.inherit(BI.AbstractAllValueChooser, { _defaultConfig: function () { - return BI.extend(BI.TreeValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-tree-value-chooser-combo", + return BI.extend(BI.AllValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-all-value-chooser-pane", width: 200, height: 30, items: null, - itemsCreator: BI.emptyFn + itemsCreator: BI.emptyFn, + cache: true }); }, _init: function () { - BI.TreeValueChooserCombo.superclass._init.apply(this, arguments); + BI.AllValueChooserPane.superclass._init.apply(this, arguments); var self = this, o = this.options; if (BI.isNotNull(o.items)) { - this._initData(o.items); + this.items = o.items; } - this.combo = BI.createWidget({ - type: 'bi.multi_tree_combo', + this.list = BI.createWidget({ + type: 'bi.multi_select_list', element: this, itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this), width: o.width, height: o.height }); - this.combo.on(BI.MultiTreeCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_CONFIRM); + this.list.on(BI.MultiSelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.AllValueChooserPane.EVENT_CHANGE); + }); + }, + + setValue: function (v) { + this.list.setValue({ + type: BI.Selection.Multi, + value: v || [] + }); + }, + + getValue: function () { + var val = this.list.getValue() || {}; + if (val.type === BI.Selection.All) { + return val.assist; + } + return val.value || []; + }, + + populate: function () { + this.list.populate.apply(this.list, arguments); + } +}); +BI.AllValueChooserPane.EVENT_CHANGE = "AllValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { + + _const: { + perPage: 100 + }, + + _defaultConfig: function () { + return BI.extend(BI.AbstractTreeValueChooser.superclass._defaultConfig.apply(this, arguments), { + items: null, + itemsCreator: BI.emptyFn }); }, @@ -17669,6 +17711,43 @@ BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { _getChildCount: function (parentValues) { return this._getChildren(parentValues).length; + } +});/** + * 简单的复选下拉树控件, 适用于数据量少的情况 + * + * Created by GUY on 2015/10/29. + * @class BI.TreeValueChooserCombo + * @extends BI.Widget + */ +BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.TreeValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-tree-value-chooser-combo", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn + }); + }, + + _init: function () { + BI.TreeValueChooserCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNotNull(o.items)) { + this._initData(o.items); + } + this.combo = BI.createWidget({ + type: 'bi.multi_tree_combo', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + width: o.width, + height: o.height + }); + + this.combo.on(BI.MultiTreeCombo.EVENT_CONFIRM, function () { + self.fireEvent(BI.TreeValueChooserCombo.EVENT_CONFIRM); + }); }, setValue: function (v) { @@ -17680,63 +17759,91 @@ BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { }, populate: function () { - this.combo.populate.apply(this, arguments); + this.combo.populate.apply(this.combo, arguments); } }); BI.TreeValueChooserCombo.EVENT_CONFIRM = "TreeValueChooserCombo.EVENT_CONFIRM"; BI.shortcut('bi.tree_value_chooser_combo', BI.TreeValueChooserCombo);/** + * 简单的复选下拉树控件, 适用于数据量少的情况 + * + * Created by GUY on 2015/10/29. + * @class BI.TreeValueChooserPane + * @extends BI.AbstractTreeValueChooser + */ +BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.TreeValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-tree-value-chooser-pane", + items: null, + itemsCreator: BI.emptyFn + }); + }, + + _init: function () { + BI.TreeValueChooserPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.pane = BI.createWidget({ + type: 'bi.multi_select_tree', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this) + }); + + this.pane.on(BI.MultiSelectTree.EVENT_CHANGE, function () { + self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE); + }); + if (BI.isNotNull(o.items)) { + this._initData(o.items); + this.populate(); + } + }, + + setValue: function (v) { + this.pane.setValue(v); + }, + + getValue: function () { + return this.pane.getValue(); + }, + + populate: function () { + this.pane.populate.apply(this.pane, arguments); + } +}); +BI.TreeValueChooserPane.EVENT_CHANGE = "TreeValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.tree_value_chooser_pane', BI.TreeValueChooserPane);/** * 简单的复选下拉框控件, 适用于数据量少的情况 * 封装了字段处理逻辑 * * Created by GUY on 2015/10/29. - * @class BI.ValueChooserCombo + * @class BI.AbstractValueChooser * @extends BI.Widget */ -BI.ValueChooserCombo = BI.inherit(BI.Widget, { +BI.AbstractValueChooser = BI.inherit(BI.Widget, { _const: { - perPage: 10 + perPage: 100 }, + _defaultConfig: function () { - return BI.extend(BI.ValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-value-chooser-combo", - width: 200, - height: 30, + return BI.extend(BI.AbstractValueChooser.superclass._defaultConfig.apply(this, arguments), { items: null, itemsCreator: BI.emptyFn, cache: true }); }, - _init: function () { - BI.ValueChooserCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNotNull(o.items)) { - this.items = o.items; - } - this.combo = BI.createWidget({ - type: 'bi.multi_select_combo', - element: this, - itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: function (v) { - var text = v; - if (BI.isNotNull(self.items)) { - BI.some(self.items, function (i, item) { - if (item.value === v) { - text = item.text; - return true; - } - }); + _valueFormatter: function (v) { + var text = v; + if (BI.isNotNull(this.items)) { + BI.some(this.items, function (i, item) { + if (item.value === v) { + text = item.text; + return true; } - return text; - }, - width: o.width, - height: o.height - }); - - this.combo.on(BI.MultiSelectCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.ValueChooserCombo.EVENT_CONFIRM); - }); + }); + } + return text; }, _getItemsByTimes: function (items, times) { @@ -17791,6 +17898,46 @@ BI.ValueChooserCombo = BI.inherit(BI.Widget, { hasNext: self._hasNextByTimes(items, options.times) }); } + } +});/** + * 简单的复选下拉框控件, 适用于数据量少的情况 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.ValueChooserCombo + * @extends BI.Widget + */ +BI.ValueChooserCombo = BI.inherit(BI.AbstractValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.ValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-value-chooser-combo", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _init: function () { + BI.ValueChooserCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNotNull(o.items)) { + this.items = o.items; + } + this.combo = BI.createWidget({ + type: 'bi.multi_select_combo', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this), + width: o.width, + height: o.height + }); + + this.combo.on(BI.MultiSelectCombo.EVENT_CONFIRM, function () { + self.fireEvent(BI.ValueChooserCombo.EVENT_CONFIRM); + }); }, setValue: function (v) { @@ -17810,4 +17957,61 @@ BI.ValueChooserCombo = BI.inherit(BI.Widget, { } }); BI.ValueChooserCombo.EVENT_CONFIRM = "ValueChooserCombo.EVENT_CONFIRM"; -BI.shortcut('bi.value_chooser_combo', BI.ValueChooserCombo); \ No newline at end of file +BI.shortcut('bi.value_chooser_combo', BI.ValueChooserCombo);/** + * 简单的复选下拉框控件, 适用于数据量少的情况 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.ValueChooserPane + * @extends BI.Widget + */ +BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-value-chooser-pane", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _init: function () { + BI.ValueChooserPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.list = BI.createWidget({ + type: 'bi.multi_select_list', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this) + }); + + this.list.on(BI.MultiSelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.ValueChooserPane.EVENT_CHANGE); + }); + if (BI.isNotNull(o.items)) { + this.items = o.items; + this.populate(); + } + }, + + setValue: function (v) { + this.list.setValue(v); + }, + + getValue: function () { + var val = this.list.getValue() || {}; + return { + type: val.type, + value: val.value + } + }, + + populate: function () { + this.list.populate.apply(this.list, arguments); + } +}); +BI.ValueChooserPane.EVENT_CHANGE = "ValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.value_chooser_pane', BI.ValueChooserPane); \ No newline at end of file diff --git a/src/component/allvaluechooser/abstract.allvaluechooser.js b/src/component/allvaluechooser/abstract.allvaluechooser.js new file mode 100644 index 0000000000..fadfd6d3f8 --- /dev/null +++ b/src/component/allvaluechooser/abstract.allvaluechooser.js @@ -0,0 +1,79 @@ +/** + * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.AllValueChooserCombo + * @extends BI.Widget + */ +BI.AbstractAllValueChooser = BI.inherit(BI.Widget, { + + _const: { + perPage: 100 + }, + + _defaultConfig: function () { + return BI.extend(BI.AllValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _valueFormatter: function (v) { + var text = v; + if (BI.isNotNull(this.items)) { + BI.some(this.items, function (i, item) { + if (item.value === v) { + text = item.text; + return true; + } + }); + } + return text; + }, + + _itemsCreator: function (options, callback) { + var self = this, o = this.options; + if (!o.cache || !this.items) { + o.itemsCreator({}, function (items) { + self.items = items; + call(items); + }); + } else { + call(this.items); + } + function call(items) { + var keywords = (options.keywords || []).slice(); + if (options.keyword) { + keywords.push(options.keyword); + } + BI.each(keywords, function (i, kw) { + var search = BI.Func.getSearchResult(items, kw); + items = search.matched.concat(search.finded); + }); + if (options.selectedValues) {//过滤 + var filter = BI.makeObject(options.selectedValues, true); + items = BI.filter(items, function (i, ob) { + return !filter[ob.value]; + }); + } + if (options.type === BI.MultiSelectCombo.REQ_GET_ALL_DATA) { + callback({ + items: items + }); + return; + } + if (options.type === BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { + callback({count: items.length}); + return; + } + callback({ + items: items, + hasNext: false + }); + } + } +}); \ No newline at end of file diff --git a/src/component/allvaluechooser/combo.allvaluechooser.js b/src/component/allvaluechooser/combo.allvaluechooser.js index 25d797533b..908da7ec95 100644 --- a/src/component/allvaluechooser/combo.allvaluechooser.js +++ b/src/component/allvaluechooser/combo.allvaluechooser.js @@ -4,13 +4,10 @@ * * Created by GUY on 2015/10/29. * @class BI.AllValueChooserCombo - * @extends BI.Widget + * @extends BI.AbstractAllValueChooser */ -BI.AllValueChooserCombo = BI.inherit(BI.Widget, { +BI.AllValueChooserCombo = BI.inherit(BI.AbstractAllValueChooser, { - _const: { - perPage: 10 - }, _defaultConfig: function () { return BI.extend(BI.AllValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-all-value-chooser-combo", @@ -32,18 +29,7 @@ BI.AllValueChooserCombo = BI.inherit(BI.Widget, { type: 'bi.multi_select_combo', element: this, itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: function (v) { - var text = v; - if (BI.isNotNull(self.items)) { - BI.some(self.items, function (i, item) { - if (item.value === v) { - text = item.text; - return true; - } - }); - } - return text; - }, + valueFormatter: BI.bind(this._valueFormatter, this), width: o.width, height: o.height }); @@ -53,48 +39,6 @@ BI.AllValueChooserCombo = BI.inherit(BI.Widget, { }); }, - _itemsCreator: function (options, callback) { - var self = this, o = this.options; - if (!o.cache || !this.items) { - o.itemsCreator({}, function (items) { - self.items = items; - call(items); - }); - } else { - call(this.items); - } - function call(items) { - var keywords = (options.keywords || []).slice(); - if (options.keyword) { - keywords.push(options.keyword); - } - BI.each(keywords, function (i, kw) { - var search = BI.Func.getSearchResult(items, kw); - items = search.matched.concat(search.finded); - }); - if (options.selectedValues) {//过滤 - var filter = BI.makeObject(options.selectedValues, true); - items = BI.filter(items, function (i, ob) { - return !filter[ob.value]; - }); - } - if (options.type === BI.MultiSelectCombo.REQ_GET_ALL_DATA) { - callback({ - items: items - }); - return; - } - if (options.type === BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { - callback({count: items.length}); - return; - } - callback({ - items: items, - hasNext: false - }); - } - }, - setValue: function (v) { this.combo.setValue({ type: BI.Selection.Multi, diff --git a/src/component/allvaluechooser/pane.allvaluechooser.js b/src/component/allvaluechooser/pane.allvaluechooser.js new file mode 100644 index 0000000000..4d9a1f4086 --- /dev/null +++ b/src/component/allvaluechooser/pane.allvaluechooser.js @@ -0,0 +1,62 @@ +/** + * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.AllValueChooserPane + * @extends BI.AbstractAllValueChooser + */ +BI.AllValueChooserPane = BI.inherit(BI.AbstractAllValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.AllValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-all-value-chooser-pane", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _init: function () { + BI.AllValueChooserPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNotNull(o.items)) { + this.items = o.items; + } + this.list = BI.createWidget({ + type: 'bi.multi_select_list', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this), + width: o.width, + height: o.height + }); + + this.list.on(BI.MultiSelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.AllValueChooserPane.EVENT_CHANGE); + }); + }, + + setValue: function (v) { + this.list.setValue({ + type: BI.Selection.Multi, + value: v || [] + }); + }, + + getValue: function () { + var val = this.list.getValue() || {}; + if (val.type === BI.Selection.All) { + return val.assist; + } + return val.value || []; + }, + + populate: function () { + this.list.populate.apply(this.list, arguments); + } +}); +BI.AllValueChooserPane.EVENT_CHANGE = "AllValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane); \ No newline at end of file diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.js b/src/component/treevaluechooser/abstract.treevaluechooser.js new file mode 100644 index 0000000000..ea539c1508 --- /dev/null +++ b/src/component/treevaluechooser/abstract.treevaluechooser.js @@ -0,0 +1,555 @@ +BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { + + _const: { + perPage: 100 + }, + + _defaultConfig: function () { + return BI.extend(BI.AbstractTreeValueChooser.superclass._defaultConfig.apply(this, arguments), { + items: null, + itemsCreator: BI.emptyFn + }); + }, + + _initData: function (items) { + this.items = items; + var nodes = BI.Tree.transformToTreeFormat(items); + this.tree = new BI.Tree(); + 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) { + var self = this, o = this.options; + if (!this.items) { + o.itemsCreator({}, function (items) { + self._initData(items); + call(); + }); + } else { + call(); + } + function call() { + switch (options.type) { + case BI.TreeView.REQ_TYPE_INIT_DATA: + self._reqInitTreeNode(options, callback); + break; + case BI.TreeView.REQ_TYPE_ADJUST_DATA: + self._reqAdjustTreeNode(options, callback); + break; + case BI.TreeView.REQ_TYPE_SELECT_DATA: + self._reqSelectedTreeNode(options, callback); + break; + case BI.TreeView.REQ_TYPE_GET_SELECTED_DATA: + self._reqDisplayTreeNode(options, callback); + break; + default : + self._reqTreeNode(options, callback); + break; + } + } + }, + + _reqDisplayTreeNode: function (op, callback) { + var self = this; + var result = []; + var selectedValues = op.selectedValues; + + if (selectedValues == null || BI.isEmpty(selectedValues)) { + callback({}); + return; + } + + doCheck(0, [], this.tree.getRoot(), selectedValues); + + callback({ + items: result + }); + + function doCheck(floor, parentValues, node, selected) { + if (floor >= self.floors) { + return; + } + if (selected == null || BI.isEmpty(selected)) { + BI.each(node.getChildren(), function (i, child) { + var newParents = BI.clone(parentValues); + newParents.push(child.value); + var llen = self._getChildCount(newParents); + createOneJson(child, node.id, llen); + doCheck(floor + 1, newParents, child, {}); + }); + return; + } + BI.each(selected, function (k) { + var node = self._getNode(k); + var newParents = BI.clone(parentValues); + newParents.push(node.value); + createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); + doCheck(floor + 1, newParents, node, selected[k]); + }) + } + + function getCount(jo, parentValues) { + if (jo == null) { + return 0; + } + if (BI.isEmpty(jo)) { + return self._getChildCount(parentValues); + } + + return BI.size(jo); + } + + function createOneJson(node, pId, llen) { + result.push({ + id: node.id, + pId: pId, + text: node.text + (llen > 0 ? ("(" + BI.i18nText("BI-Basic_Altogether") + llen + BI.i18nText("BI-Basic_Count") + ")") : ""), + value: node.value, + open: true + }); + } + }, + + _reqSelectedTreeNode: function (op, callback) { + var self = this; + var selectedValues = op.selectedValues; + var notSelectedValue = op.notSelectedValue || {}; + var keyword = op.keyword || ""; + var parentValues = op.parentValues || []; + + if (selectedValues == null || BI.isEmpty(selectedValues)) { + callback({}); + return; + } + + dealWithSelectedValues(selectedValues); + callback(selectedValues); + + + function dealWithSelectedValues(selectedValues) { + var p = BI.clone(parentValues); + p.push(notSelectedValue); + + if (isChild(selectedValues, p)) { + var result = []; + var finded = search(parentValues.length + 1, parentValues, notSelectedValue, result); + + if (finded === true) { + var next = selectedValues; + BI.each(p, function (i, v) { + var t = next[v]; + if (t == null) { + if (BI.isEmpty(next)) { + var split = p.slice(0, i); + var expanded = self._getChildren(split); + BI.each(expanded, function (m, child) { + if (i === p.length - 1 && child.value === notSelectedValue) { + return true; + } + next[child.value] = {}; + }); + next = next[v]; + } else { + next = {}; + next[v] = {}; + } + } else { + next = t; + } + }); + + if (result.length > 0) { + BI.each(result, function (i, strs) { + self._buildTree(selectedValues, strs); + }) + } + } + } + + } + + function search(deep, parents, current, result) { + var newParents = BI.clone(parents); + newParents.push(current); + if (self._isMatch(current, keyword)) { + return true; + } + if (deep >= self.floors) { + return false; + } + + var children = self._getChildren(newParents); + + var notSearch = []; + var can = false; + + BI.each(children, function (i, child) { + if (search(deep + 1, newParents, child.value, result)) { + can = true; + } else { + notSearch.push(child.value); + } + }); + if (can === true) { + BI.each(notSearch, function (i, v) { + var next = BI.clone(newParents); + next.push(v); + result.push(next); + }); + } + return can; + } + + function isChild(selectedValues, parents) { + var t = selectedValues; + for (var i = 0; i < parents.length; i++) { + var v = parents[i]; + if (!BI.has(t, v)) { + return false; + } + t = t[v]; + if (t == null || BI.isEmpty(t)) { + return true; + } + } + return true; + } + }, + + _reqAdjustTreeNode: function (op, callback) { + var self = this; + var result = []; + var selectedValues = op.selectedValues; + if (selectedValues == null || BI.isEmpty(selectedValues)) { + callback({}); + return; + } + BI.each(selectedValues, function (k, v) { + result.push([k]); + }); + + dealWithSelectedValues(selectedValues, []); + + var jo = {}; + BI.each(result, function (i, strs) { + self._buildTree(jo, strs); + }); + callback(jo); + + function dealWithSelectedValues(selected, parents) { + if (selected == null || BI.isEmpty(selected)) { + return true; + } + var can = true; + BI.each(selected, function (k, v) { + var p = BI.clone(parents); + p.push(k); + if (!dealWithSelectedValues(selected[k], p)) { + BI.each(selected[k], function (nk, nv) { + var t = BI.clone(p); + t.push(nk); + result.push(t); + }); + can = false; + } + }); + return can && isAllSelected(selected, parents); + } + + function isAllSelected(selected, parents) { + return BI.isEmpty(selected) || self._getChildCount(parents) === BI.size(selected); + } + }, + + _reqInitTreeNode: function (op, callback) { + var self = this; + var result = []; + var keyword = op.keyword || ""; + var selectedValues = op.selectedValues; + var lastSearchValue = op.lastSearchValue || ""; + var output = search(); + BI.nextTick(function () { + callback({ + hasNext: output.length > self._const.perPage, + items: result, + lastSearchValue: BI.last(output) + }) + }); + + function search() { + var children = self._getChildren([]); + var start = children.length; + if (lastSearchValue !== "") { + for (var j = 0, len = start; j < len; j++) { + if (children[j].value === lastSearchValue) { + start = j + 1; + break; + } + } + } else { + start = 0; + } + var output = []; + for (var i = start, len = children.length; i < len; i++) { + if (output.length < self._const.perPage) { + var find = nodeSearch(1, [], children[i].value, false, result); + } else if (output.length === self._const.perPage) { + var find = nodeSearch(1, [], children[i].value, false, []); + } + if (find[0] === true) { + output.push(children[i].value); + } + if (output.length > self._const.perPage) { + break; + } + } + return output; + } + + function nodeSearch(deep, parentValues, current, isAllSelect, result) { + if (self._isMatch(current, keyword)) { + var checked = isAllSelect || isSelected(parentValues, current); + createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result); + return [true, checked]; + } + if (deep >= self.floors) { + return [false, false]; + } + var newParents = BI.clone(parentValues); + newParents.push(current); + var children = self._getChildren(newParents); + + var can = false, checked = false; + + var isCurAllSelected = isAllSelect || isAllSelected(parentValues, current); + BI.each(children, function (i, child) { + var state = nodeSearch(deep + 1, newParents, child.value, isCurAllSelected, result); + if (state[1] === true) { + checked = true; + } + if (state[0] === true) { + can = true; + } + }); + if (can === true) { + checked = isCurAllSelected || (isSelected(parentValues, current) && checked); + createOneJson(parentValues, current, true, checked, false, false, result); + } + return [can, checked]; + } + + function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { + var node = self.map[value]; + result.push({ + id: node.id, + pId: node.pId, + text: node.text, + value: node.value, + title: node.title, + isParent: parentValues.length + 1 < self.floors, + open: isOpen, + checked: checked, + halfCheck: half, + flag: flag + }); + } + + function isHalf(parentValues, value) { + var find = findSelectedObj(parentValues); + if (find == null) { + return null; + } + return BI.any(find, function (v, ob) { + if (v === value) { + if (ob != null && !BI.isEmpty(ob)) { + return true; + } + } + }); + } + + function isAllSelected(parentValues, value) { + var find = findSelectedObj(parentValues); + if (find == null) { + return null; + } + return BI.any(find, function (v, ob) { + if (v === value) { + if (ob != null && BI.isEmpty(ob)) { + return true; + } + } + }); + } + + function isSelected(parentValues, value) { + var find = findSelectedObj(parentValues); + if (find == null) { + return false; + } + return BI.any(find, function (v) { + if (v === value) { + return true; + } + }); + } + + function findSelectedObj(parentValues) { + var find = selectedValues; + if (find == null) { + return null; + } + BI.every(parentValues, function (i, v) { + find = find[v]; + if (find == null) { + return false; + } + return true; + }); + return find; + } + }, + + _reqTreeNode: function (op, callback) { + var self = this; + var result = []; + var times = op.times; + var checkState = op.checkState || {}; + var parentValues = op.parentValues || []; + var selectedValues = op.selectedValues; + var valueMap = {}; + if (judgeState(parentValues, selectedValues, checkState)) { + valueMap = dealWidthSelectedValue(parentValues, selectedValues); + } + var nodes = this._getChildren(parentValues); + for (var i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { + var state = getCheckState(nodes[i].value, parentValues, valueMap, checkState); + result.push({ + id: nodes[i].id, + pId: nodes[i].pId, + value: nodes[i].value, + text: nodes[i].text, + times: 1, + isParent: parentValues.length + 1 < this.floors, + checked: state[0], + halfCheck: state[1] + }) + } + BI.nextTick(function () { + callback({ + items: result, + hasNext: nodes.length > times * self._const.perPage + }); + }); + + function judgeState(parentValues, selected_value, checkState) { + var checked = checkState.checked, half = checkState.half; + if (parentValues.length > 0 && !checked) { + return false; + } + return (parentValues.length === 0 || (checked && half) && !BI.isEmpty(selected_value)); + } + + function dealWidthSelectedValue(parentValues, selectedValues) { + var valueMap = {}; + BI.each(parentValues, function (i, v) { + selectedValues = selectedValues[v]; + }); + BI.each(selectedValues, function (value, obj) { + if (BI.isNull(obj)) { + valueMap[value] = [0, 0]; + return; + } + if (BI.isEmpty(obj)) { + valueMap[value] = [2, 0]; + return; + } + var nextNames = {}; + BI.each(obj, function (t, o) { + if (BI.isNull(o) || BI.isEmpty(o)) { + nextNames[t] = true; + } + }); + valueMap[value] = [1, BI.size(nextNames)]; + }); + return valueMap; + } + + function getCheckState(current, parentValues, valueMap, checkState) { + var checked = checkState.checked, half = checkState.half; + var hasChild = parentValues.length + 1 < self.floors; + var tempCheck = false, halfCheck = false; + if (BI.has(valueMap, current)) { + //可能是半选 + if (valueMap[current][0] === 1) { + var values = BI.clone(parentValues); + values.push(current); + if (hasChild && self._getChildCount(values) !== valueMap[current][1]) { + halfCheck = true; + } + } else if (valueMap[current][0] === 2) { + tempCheck = true; + } + } + var check; + if (!checked && !halfCheck && !tempCheck) { + check = BI.has(valueMap, current); + } else { + check = ((tempCheck || checked) && !half) || BI.has(valueMap, current); + } + return [check, halfCheck]; + } + }, + + + _buildTree: function (jo, values) { + var t = jo; + BI.each(values, function (i, v) { + if (!BI.has(t, v)) { + t[v] = {}; + } + t = t[v]; + }); + }, + + _isMatch: function (value, keyword) { + var finded = BI.Func.getSearchResult([value], keyword); + return finded.finded.length > 0 || finded.matched.length > 0; + }, + + _getNode: function (v) { + return this.tree.search(v, "value"); + }, + + _getChildren: function (parentValues) { + if (parentValues.length > 0) { + var value = BI.last(parentValues); + var parent = this.tree.search(value, "value"); + } else { + var parent = this.tree.getRoot(); + } + return parent.getChildren(); + }, + + _getChildCount: function (parentValues) { + return this._getChildren(parentValues).length; + } +}); \ No newline at end of file diff --git a/src/component/treevaluechooser/combo.treevaluechooser.js b/src/component/treevaluechooser/combo.treevaluechooser.js index 1a35109144..5a7fa64ac0 100644 --- a/src/component/treevaluechooser/combo.treevaluechooser.js +++ b/src/component/treevaluechooser/combo.treevaluechooser.js @@ -5,11 +5,7 @@ * @class BI.TreeValueChooserCombo * @extends BI.Widget */ -BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { - - _const: { - perPage: 10 - }, +BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, { _defaultConfig: function () { return BI.extend(BI.TreeValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { @@ -40,548 +36,6 @@ BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { }); }, - _initData: function (items) { - this.items = items; - var nodes = BI.Tree.transformToTreeFormat(items); - this.tree = new BI.Tree(); - 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) { - var self = this, o = this.options; - if (!this.items) { - o.itemsCreator({}, function (items) { - self._initData(items); - call(); - }); - } else { - call(); - } - function call() { - switch (options.type) { - case BI.TreeView.REQ_TYPE_INIT_DATA: - self._reqInitTreeNode(options, callback); - break; - case BI.TreeView.REQ_TYPE_ADJUST_DATA: - self._reqAdjustTreeNode(options, callback); - break; - case BI.TreeView.REQ_TYPE_SELECT_DATA: - self._reqSelectedTreeNode(options, callback); - break; - case BI.TreeView.REQ_TYPE_GET_SELECTED_DATA: - self._reqDisplayTreeNode(options, callback); - break; - default : - self._reqTreeNode(options, callback); - break; - } - } - }, - - _reqDisplayTreeNode: function (op, callback) { - var self = this; - var result = []; - var selectedValues = op.selectedValues; - - if (selectedValues == null || BI.isEmpty(selectedValues)) { - callback({}); - return; - } - - doCheck(0, [], this.tree.getRoot(), selectedValues); - - callback({ - items: result - }); - - function doCheck(floor, parentValues, node, selected) { - if (floor >= self.floors) { - return; - } - if (selected == null || BI.isEmpty(selected)) { - BI.each(node.getChildren(), function (i, child) { - var newParents = BI.clone(parentValues); - newParents.push(child.value); - var llen = self._getChildCount(newParents); - createOneJson(child, node.id, llen); - doCheck(floor + 1, newParents, child, {}); - }); - return; - } - BI.each(selected, function (k) { - var node = self._getNode(k); - var newParents = BI.clone(parentValues); - newParents.push(node.value); - createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); - doCheck(floor + 1, newParents, node, selected[k]); - }) - } - - function getCount(jo, parentValues) { - if (jo == null) { - return 0; - } - if (BI.isEmpty(jo)) { - return self._getChildCount(parentValues); - } - - return BI.size(jo); - } - - function createOneJson(node, pId, llen) { - result.push({ - id: node.id, - pId: pId, - text: node.text + (llen > 0 ? ("(" + BI.i18nText("BI-Basic_Altogether") + llen + BI.i18nText("BI-Basic_Count") + ")") : ""), - value: node.value, - open: true - }); - } - }, - - _reqSelectedTreeNode: function (op, callback) { - var self = this; - var selectedValues = op.selectedValues; - var notSelectedValue = op.notSelectedValue || {}; - var keyword = op.keyword || ""; - var parentValues = op.parentValues || []; - - if (selectedValues == null || BI.isEmpty(selectedValues)) { - callback({}); - return; - } - - dealWithSelectedValues(selectedValues); - callback(selectedValues); - - - function dealWithSelectedValues(selectedValues) { - var p = BI.clone(parentValues); - p.push(notSelectedValue); - - if (isChild(selectedValues, p)) { - var result = []; - var finded = search(parentValues.length + 1, parentValues, notSelectedValue, result); - - if (finded === true) { - var next = selectedValues; - BI.each(p, function (i, v) { - var t = next[v]; - if (t == null) { - if (BI.isEmpty(next)) { - var split = p.slice(0, i); - var expanded = self._getChildren(split); - BI.each(expanded, function (m, child) { - if (i === p.length - 1 && child.value === notSelectedValue) { - return true; - } - next[child.value] = {}; - }); - next = next[v]; - } else { - next = {}; - next[v] = {}; - } - } else { - next = t; - } - }); - - if (result.length > 0) { - BI.each(result, function (i, strs) { - self._buildTree(selectedValues, strs); - }) - } - } - } - - } - - function search(deep, parents, current, result) { - var newParents = BI.clone(parents); - newParents.push(current); - if (self._isMatch(current, keyword)) { - return true; - } - if (deep >= self.floors) { - return false; - } - - var children = self._getChildren(newParents); - - var notSearch = []; - var can = false; - - BI.each(children, function (i, child) { - if (search(deep + 1, newParents, child.value, result)) { - can = true; - } else { - notSearch.push(child.value); - } - }); - if (can === true) { - BI.each(notSearch, function (i, v) { - var next = BI.clone(newParents); - next.push(v); - result.push(next); - }); - } - return can; - } - - function isChild(selectedValues, parents) { - var t = selectedValues; - for (var i = 0; i < parents.length; i++) { - var v = parents[i]; - if (!BI.has(t, v)) { - return false; - } - t = t[v]; - if (t == null || BI.isEmpty(t)) { - return true; - } - } - return true; - } - }, - - _reqAdjustTreeNode: function (op, callback) { - var self = this; - var result = []; - var selectedValues = op.selectedValues; - if (selectedValues == null || BI.isEmpty(selectedValues)) { - callback({}); - return; - } - BI.each(selectedValues, function (k, v) { - result.push([k]); - }); - - dealWithSelectedValues(selectedValues, []); - - var jo = {}; - BI.each(result, function (i, strs) { - self._buildTree(jo, strs); - }); - callback(jo); - - function dealWithSelectedValues(selected, parents) { - if (selected == null || BI.isEmpty(selected)) { - return true; - } - var can = true; - BI.each(selected, function (k, v) { - var p = BI.clone(parents); - p.push(k); - if (!dealWithSelectedValues(selected[k], p)) { - BI.each(selected[k], function (nk, nv) { - var t = BI.clone(p); - t.push(nk); - result.push(t); - }); - can = false; - } - }); - return can && isAllSelected(selected, parents); - } - - function isAllSelected(selected, parents) { - return BI.isEmpty(selected) || self._getChildCount(parents) === BI.size(selected); - } - }, - - _reqInitTreeNode: function (op, callback) { - var self = this; - var result = []; - var keyword = op.keyword || ""; - var selectedValues = op.selectedValues; - var lastSearchValue = op.lastSearchValue || ""; - var output = search(); - BI.nextTick(function () { - callback({ - hasNext: output.length > self._const.perPage, - items: result, - lastSearchValue: BI.last(output) - }) - }); - - function search() { - var children = self._getChildren([]); - var start = children.length; - if (lastSearchValue !== "") { - for (var j = 0, len = start; j < len; j++) { - if (children[j].value === lastSearchValue) { - start = j + 1; - break; - } - } - } else { - start = 0; - } - var output = []; - for (var i = start, len = children.length; i < len; i++) { - if (output.length < self._const.perPage) { - var find = nodeSearch(1, [], children[i].value, false, result); - } else if (output.length === self._const.perPage) { - var find = nodeSearch(1, [], children[i].value, false, []); - } - if (find[0] === true) { - output.push(children[i].value); - } - if (output.length > self._const.perPage) { - break; - } - } - return output; - } - - function nodeSearch(deep, parentValues, current, isAllSelect, result) { - if (self._isMatch(current, keyword)) { - var checked = isAllSelect || isSelected(parentValues, current); - createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result); - return [true, checked]; - } - if (deep >= self.floors) { - return [false, false]; - } - var newParents = BI.clone(parentValues); - newParents.push(current); - var children = self._getChildren(newParents); - - var can = false, checked = false; - - var isCurAllSelected = isAllSelect || isAllSelected(parentValues, current); - BI.each(children, function (i, child) { - var state = nodeSearch(deep + 1, newParents, child.value, isCurAllSelected, result); - if (state[1] === true) { - checked = true; - } - if (state[0] === true) { - can = true; - } - }); - if (can === true) { - checked = isCurAllSelected || (isSelected(parentValues, current) && checked); - createOneJson(parentValues, current, true, checked, false, false, result); - } - return [can, checked]; - } - - function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { - var node = self.map[value]; - result.push({ - id: node.id, - pId: node.pId, - text: node.text, - value: node.value, - title: node.title, - isParent: parentValues.length + 1 < self.floors, - open: isOpen, - checked: checked, - halfCheck: half, - flag: flag - }); - } - - function isHalf(parentValues, value) { - var find = findSelectedObj(parentValues); - if (find == null) { - return null; - } - return BI.any(find, function (v, ob) { - if (v === value) { - if (ob != null && !BI.isEmpty(ob)) { - return true; - } - } - }); - } - - function isAllSelected(parentValues, value) { - var find = findSelectedObj(parentValues); - if (find == null) { - return null; - } - return BI.any(find, function (v, ob) { - if (v === value) { - if (ob != null && BI.isEmpty(ob)) { - return true; - } - } - }); - } - - function isSelected(parentValues, value) { - var find = findSelectedObj(parentValues); - if (find == null) { - return false; - } - return BI.any(find, function (v) { - if (v === value) { - return true; - } - }); - } - - function findSelectedObj(parentValues) { - var find = selectedValues; - if (find == null) { - return null; - } - BI.every(parentValues, function (i, v) { - find = find[v]; - if (find == null) { - return false; - } - return true; - }); - return find; - } - }, - - _reqTreeNode: function (op, callback) { - var self = this; - var result = []; - var times = op.times; - var checkState = op.checkState || {}; - var parentValues = op.parentValues || []; - var selectedValues = op.selectedValues; - var valueMap = {}; - if (judgeState(parentValues, selectedValues, checkState)) { - valueMap = dealWidthSelectedValue(parentValues, selectedValues); - } - var nodes = this._getChildren(parentValues); - for (var i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { - var state = getCheckState(nodes[i].value, parentValues, valueMap, checkState); - result.push({ - id: nodes[i].id, - pId: nodes[i].pId, - value: nodes[i].value, - text: nodes[i].text, - times: 1, - isParent: parentValues.length + 1 < this.floors, - checked: state[0], - halfCheck: state[1] - }) - } - BI.nextTick(function () { - callback({ - items: result, - hasNext: nodes.length > times * self._const.perPage - }); - }); - - function judgeState(parentValues, selected_value, checkState) { - var checked = checkState.checked, half = checkState.half; - if (parentValues.length > 0 && !checked) { - return false; - } - return (parentValues.length === 0 || (checked && half) && !BI.isEmpty(selected_value)); - } - - function dealWidthSelectedValue(parentValues, selectedValues) { - var valueMap = {}; - BI.each(parentValues, function (i, v) { - selectedValues = selectedValues[v]; - }); - BI.each(selectedValues, function (value, obj) { - if (BI.isNull(obj)) { - valueMap[value] = [0, 0]; - return; - } - if (BI.isEmpty(obj)) { - valueMap[value] = [2, 0]; - return; - } - var nextNames = {}; - BI.each(obj, function (t, o) { - if (BI.isNull(o) || BI.isEmpty(o)) { - nextNames[t] = true; - } - }); - valueMap[value] = [1, BI.size(nextNames)]; - }); - return valueMap; - } - - function getCheckState(current, parentValues, valueMap, checkState) { - var checked = checkState.checked, half = checkState.half; - var hasChild = parentValues.length + 1 < self.floors; - var tempCheck = false, halfCheck = false; - if (BI.has(valueMap, current)) { - //可能是半选 - if (valueMap[current][0] === 1) { - var values = BI.clone(parentValues); - values.push(current); - if (hasChild && self._getChildCount(values) !== valueMap[current][1]) { - halfCheck = true; - } - } else if (valueMap[current][0] === 2) { - tempCheck = true; - } - } - var check; - if (!checked && !halfCheck && !tempCheck) { - check = BI.has(valueMap, current); - } else { - check = ((tempCheck || checked) && !half) || BI.has(valueMap, current); - } - return [check, halfCheck]; - } - }, - - - _buildTree: function (jo, values) { - var t = jo; - BI.each(values, function (i, v) { - if (!BI.has(t, v)) { - t[v] = {}; - } - t = t[v]; - }); - }, - - _isMatch: function (value, keyword) { - var finded = BI.Func.getSearchResult([value], keyword); - return finded.finded.length > 0 || finded.matched.length > 0; - }, - - _getNode: function (v) { - return this.tree.search(v, "value"); - }, - - _getChildren: function (parentValues) { - if (parentValues.length > 0) { - var value = BI.last(parentValues); - var parent = this.tree.search(value, "value"); - } else { - var parent = this.tree.getRoot(); - } - return parent.getChildren(); - }, - - _getChildCount: function (parentValues) { - return this._getChildren(parentValues).length; - }, - setValue: function (v) { this.combo.setValue(v); }, @@ -591,7 +45,7 @@ BI.TreeValueChooserCombo = BI.inherit(BI.Widget, { }, populate: function () { - this.combo.populate.apply(this, arguments); + this.combo.populate.apply(this.combo, arguments); } }); BI.TreeValueChooserCombo.EVENT_CONFIRM = "TreeValueChooserCombo.EVENT_CONFIRM"; diff --git a/src/component/treevaluechooser/pane.treevaluechooser.js b/src/component/treevaluechooser/pane.treevaluechooser.js new file mode 100644 index 0000000000..dd924c925d --- /dev/null +++ b/src/component/treevaluechooser/pane.treevaluechooser.js @@ -0,0 +1,49 @@ +/** + * 简单的复选下拉树控件, 适用于数据量少的情况 + * + * Created by GUY on 2015/10/29. + * @class BI.TreeValueChooserPane + * @extends BI.AbstractTreeValueChooser + */ +BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.TreeValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-tree-value-chooser-pane", + items: null, + itemsCreator: BI.emptyFn + }); + }, + + _init: function () { + BI.TreeValueChooserPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.pane = BI.createWidget({ + type: 'bi.multi_select_tree', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this) + }); + + this.pane.on(BI.MultiSelectTree.EVENT_CHANGE, function () { + self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE); + }); + if (BI.isNotNull(o.items)) { + this._initData(o.items); + this.populate(); + } + }, + + setValue: function (v) { + this.pane.setValue(v); + }, + + getValue: function () { + return this.pane.getValue(); + }, + + populate: function () { + this.pane.populate.apply(this.pane, arguments); + } +}); +BI.TreeValueChooserPane.EVENT_CHANGE = "TreeValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.tree_value_chooser_pane', BI.TreeValueChooserPane); \ No newline at end of file diff --git a/src/component/valuechooser/abstract.valuechooser.js b/src/component/valuechooser/abstract.valuechooser.js new file mode 100644 index 0000000000..9b96e1ab51 --- /dev/null +++ b/src/component/valuechooser/abstract.valuechooser.js @@ -0,0 +1,89 @@ +/** + * 简单的复选下拉框控件, 适用于数据量少的情况 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.AbstractValueChooser + * @extends BI.Widget + */ +BI.AbstractValueChooser = BI.inherit(BI.Widget, { + + _const: { + perPage: 100 + }, + + _defaultConfig: function () { + return BI.extend(BI.AbstractValueChooser.superclass._defaultConfig.apply(this, arguments), { + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _valueFormatter: function (v) { + var text = v; + if (BI.isNotNull(this.items)) { + BI.some(this.items, function (i, item) { + if (item.value === v) { + text = item.text; + return true; + } + }); + } + return text; + }, + + _getItemsByTimes: function (items, times) { + var res = []; + for (var i = (times - 1) * this._const.perPage; items[i] && i < times * this._const.perPage; i++) { + res.push(items[i]); + } + return res; + }, + + _hasNextByTimes: function (items, times) { + return times * this._const.perPage < items.length; + }, + + _itemsCreator: function (options, callback) { + var self = this, o = this.options; + if (!o.cache || !this.items) { + o.itemsCreator({}, function (items) { + self.items = items; + call(items); + }); + } else { + call(this.items); + } + function call(items) { + var keywords = (options.keywords || []).slice(); + if (options.keyword) { + keywords.push(options.keyword); + } + BI.each(keywords, function (i, kw) { + var search = BI.Func.getSearchResult(items, kw); + items = search.matched.concat(search.finded); + }); + if (options.selectedValues) {//过滤 + var filter = BI.makeObject(options.selectedValues, true); + items = BI.filter(items, function (i, ob) { + return !filter[ob.value]; + }); + } + if (options.type === BI.MultiSelectCombo.REQ_GET_ALL_DATA) { + callback({ + items: items + }); + return; + } + if (options.type === BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { + callback({count: items.length}); + return; + } + callback({ + items: self._getItemsByTimes(items, options.times), + hasNext: self._hasNextByTimes(items, options.times) + }); + } + } +}); \ No newline at end of file diff --git a/src/component/valuechooser/combo.valuechooser.js b/src/component/valuechooser/combo.valuechooser.js index 778865ffbc..2f88d21281 100644 --- a/src/component/valuechooser/combo.valuechooser.js +++ b/src/component/valuechooser/combo.valuechooser.js @@ -6,11 +6,8 @@ * @class BI.ValueChooserCombo * @extends BI.Widget */ -BI.ValueChooserCombo = BI.inherit(BI.Widget, { +BI.ValueChooserCombo = BI.inherit(BI.AbstractValueChooser, { - _const: { - perPage: 10 - }, _defaultConfig: function () { return BI.extend(BI.ValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-value-chooser-combo", @@ -32,18 +29,7 @@ BI.ValueChooserCombo = BI.inherit(BI.Widget, { type: 'bi.multi_select_combo', element: this, itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: function (v) { - var text = v; - if (BI.isNotNull(self.items)) { - BI.some(self.items, function (i, item) { - if (item.value === v) { - text = item.text; - return true; - } - }); - } - return text; - }, + valueFormatter: BI.bind(this._valueFormatter, this), width: o.width, height: o.height }); @@ -53,60 +39,6 @@ BI.ValueChooserCombo = BI.inherit(BI.Widget, { }); }, - _getItemsByTimes: function (items, times) { - var res = []; - for (var i = (times - 1) * this._const.perPage; items[i] && i < times * this._const.perPage; i++) { - res.push(items[i]); - } - return res; - }, - - _hasNextByTimes: function (items, times) { - return times * this._const.perPage < items.length; - }, - - _itemsCreator: function (options, callback) { - var self = this, o = this.options; - if (!o.cache || !this.items) { - o.itemsCreator({}, function (items) { - self.items = items; - call(items); - }); - } else { - call(this.items); - } - function call(items) { - var keywords = (options.keywords || []).slice(); - if (options.keyword) { - keywords.push(options.keyword); - } - BI.each(keywords, function (i, kw) { - var search = BI.Func.getSearchResult(items, kw); - items = search.matched.concat(search.finded); - }); - if (options.selectedValues) {//过滤 - var filter = BI.makeObject(options.selectedValues, true); - items = BI.filter(items, function (i, ob) { - return !filter[ob.value]; - }); - } - if (options.type === BI.MultiSelectCombo.REQ_GET_ALL_DATA) { - callback({ - items: items - }); - return; - } - if (options.type === BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { - callback({count: items.length}); - return; - } - callback({ - items: self._getItemsByTimes(items, options.times), - hasNext: self._hasNextByTimes(items, options.times) - }); - } - }, - setValue: function (v) { this.combo.setValue(v); }, diff --git a/src/component/valuechooser/pane.valuechooser.js b/src/component/valuechooser/pane.valuechooser.js new file mode 100644 index 0000000000..67ef9cab98 --- /dev/null +++ b/src/component/valuechooser/pane.valuechooser.js @@ -0,0 +1,58 @@ +/** + * 简单的复选下拉框控件, 适用于数据量少的情况 + * 封装了字段处理逻辑 + * + * Created by GUY on 2015/10/29. + * @class BI.ValueChooserPane + * @extends BI.Widget + */ +BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, { + + _defaultConfig: function () { + return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-value-chooser-pane", + width: 200, + height: 30, + items: null, + itemsCreator: BI.emptyFn, + cache: true + }); + }, + + _init: function () { + BI.ValueChooserPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.list = BI.createWidget({ + type: 'bi.multi_select_list', + element: this, + itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this) + }); + + this.list.on(BI.MultiSelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.ValueChooserPane.EVENT_CHANGE); + }); + if (BI.isNotNull(o.items)) { + this.items = o.items; + this.populate(); + } + }, + + setValue: function (v) { + this.list.setValue(v); + }, + + getValue: function () { + var val = this.list.getValue() || {}; + return { + type: val.type, + value: val.value + } + }, + + populate: function () { + this.list.populate.apply(this.list, arguments); + } +}); +BI.ValueChooserPane.EVENT_CHANGE = "ValueChooserPane.EVENT_CHANGE"; +BI.shortcut('bi.value_chooser_pane', BI.ValueChooserPane); \ No newline at end of file diff --git a/src/widget/multiselectlist/multiselectlist.js b/src/widget/multiselectlist/multiselectlist.js index 4913c7e410..aaf5239436 100644 --- a/src/widget/multiselectlist/multiselectlist.js +++ b/src/widget/multiselectlist/multiselectlist.js @@ -6,8 +6,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { return BI.extend(BI.MultiSelectList.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-select-list', itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - el: {} + valueFormatter: BI.emptyFn }) }, _init: function () { @@ -140,8 +139,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.vtape", element: this, - height: "100%", - width: "100%", items: [{ el: this.trigger, height: 30 @@ -153,8 +150,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.absolute", element: this, - height: "100%", - width: "100%", items: [{ el: this.searcherPane, top: 30, diff --git a/src/widget/multiselecttree/multiselecttree.js b/src/widget/multiselecttree/multiselecttree.js index 4475e433e2..0fc868b97f 100644 --- a/src/widget/multiselecttree/multiselecttree.js +++ b/src/widget/multiselecttree/multiselecttree.js @@ -5,8 +5,7 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-select-tree', - itemsCreator: BI.emptyFn, - height: 25 + itemsCreator: BI.emptyFn }) }, @@ -52,7 +51,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { }, adapter: this.adapter, popup: this.searcherPane, - height: 200, masker: false, listeners: [{ eventName: BI.Searcher.EVENT_START, @@ -92,8 +90,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.vtape", element: this, - height: "100%", - width: "100%", items: [{ el: this.trigger, height: 30 @@ -105,8 +101,6 @@ BI.MultiSelectTree = BI.inherit(BI.Widget, { BI.createWidget({ type: "bi.absolute", element: this, - height: "100%", - width: "100%", items: [{ el: this.searcherPane, top: 30, diff --git a/src/widget/multiselecttree/multiselecttree.popup.js b/src/widget/multiselecttree/multiselecttree.popup.js index 8f8ee61b2e..f461f87877 100644 --- a/src/widget/multiselecttree/multiselecttree.popup.js +++ b/src/widget/multiselecttree/multiselecttree.popup.js @@ -13,7 +13,6 @@ BI.MultiSelectTreePopup = BI.inherit(BI.Widget, { var self = this, o = this.options; this.popup = BI.createWidget({ type: "bi.async_tree", - height: 400, element: this, itemsCreator: o.itemsCreator });