Browse Source

KERNEL-14105 feat:searchmultitextvaluecombo 的es6化

es6
crawford.zhou 2 years ago
parent
commit
ab2eb1f996
  1. 3
      src/widget/index.js
  2. 6
      src/widget/multiselect/index.js
  3. 5
      src/widget/searchmultitextvaluecombo/index.js
  4. 654
      src/widget/searchmultitextvaluecombo/multitextvalue.combo.search.js
  5. 189
      src/widget/searchmultitextvaluecombo/multitextvalue.combo.trigger.search.js
  6. 238
      src/widget/searchmultitextvaluecombo/multitextvalue.loader.search.js
  7. 112
      src/widget/searchmultitextvaluecombo/multitextvalue.popup.view.search.js
  8. 200
      src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js

3
src/widget/index.js

@ -25,6 +25,7 @@ import * as singleselect from "./singleselect";
import * as multilayerdownlist from "./multilayerdownlist"; import * as multilayerdownlist from "./multilayerdownlist";
import * as multilayersingletree from "./multilayersingletree"; import * as multilayersingletree from "./multilayersingletree";
import * as searchmultitextvaluecombo from "./searchmultitextvaluecombo";
Object.assign(BI, { Object.assign(BI, {
Collapse, Collapse,
...calendar, ...calendar,
@ -52,6 +53,7 @@ Object.assign(BI, {
...singleselect, ...singleselect,
...multilayerdownlist, ...multilayerdownlist,
...multilayersingletree, ...multilayersingletree,
...searchmultitextvaluecombo,
}); });
export * from "./date/calendar"; export * from "./date/calendar";
@ -68,6 +70,7 @@ export * from "./downlist";
export * from "./singleslider"; export * from "./singleslider";
export * from "./intervalslider"; export * from "./intervalslider";
export * from "./year"; export * from "./year";
export * from "./searchmultitextvaluecombo";
export * from "./singleselect"; export * from "./singleselect";
export * from "./multilayerdownlist"; export * from "./multilayerdownlist";
export * from "./multilayersingletree"; export * from "./multilayersingletree";

6
src/widget/multiselect/index.js

@ -1,3 +1,9 @@
export { MultiSelectSearchPane } from "./search/multiselect.search.pane";
export { MultiSelectEditor } from "./trigger/editor.multiselect";
export { MultiSelectTrigger } from "./multiselect.trigger";
export { MultiSelectPopupView } from "./multiselect.popup.view";
export { MultiSelectSearcher } from "./trigger/searcher.multiselect";
export { MultiSelectCheckSelectedSwitcher } from "./trigger/switcher.checkselected";
export { MultiSelectCombo } from "./multiselect.combo"; export { MultiSelectCombo } from "./multiselect.combo";
export { MultiSelectNoBarCombo } from "./multiselect.combo.nobar"; export { MultiSelectNoBarCombo } from "./multiselect.combo.nobar";
export { MultiSelectInsertCombo } from "./multiselect.insert.combo"; export { MultiSelectInsertCombo } from "./multiselect.insert.combo";

5
src/widget/searchmultitextvaluecombo/index.js

@ -0,0 +1,5 @@
export { SearchMultiTextValueCombo } from "./multitextvalue.combo.search";
export { SearchMultiSelectPopupView } from "./multitextvalue.popup.view.search";
export { SearchMultiSelectTrigger } from "./multitextvalue.combo.trigger.search";
export { SearchMultiSelectLoader } from "./multitextvalue.loader.search";
export { SearchMultiSelectSearcher } from "./trigger/searcher.multitextvalue";

654
src/widget/searchmultitextvaluecombo/multitextvalue.combo.search.js

@ -1,29 +1,44 @@
/** import { shortcut, extend, isKey, Selection, remove, last, pushDistinct, deepClone, createWidget, toPix, isNotNull, initial, endWith, bind, nextTick, AbsoluteLayout, contains, map, makeObject, each, values, isNull, Func, isNotEmptyArray, isArray, find } from "@/core";
* import { Single, Combo } from "@/base";
* @class BI.SearchMultiTextValueCombo import { MultiSelectTrigger, MultiSelectPopupView, MultiSelectCombo, SearchMultiSelectTrigger, SearchMultiSelectPopupView } from "@/widget";
* @extends BI.Single import { MultiSelectBar, TriggerIconButton } from "@/case";
*/
BI.SearchMultiTextValueCombo = BI.inherit(BI.Single, { @shortcut()
export class SearchMultiTextValueCombo extends Single {
_defaultConfig: function () { static xtype = "bi.search_multi_text_value_combo";
return BI.extend(BI.SearchMultiTextValueCombo.superclass._defaultConfig.apply(this, arguments), {
static REQ_GET_DATA_LENGTH = 1;
static REQ_GET_ALL_DATA = -1;
static EVENT_CONFIRM = "EVENT_CONFIRM";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multi-select-combo bi-search-multi-text-value-combo", baseCls: "bi-multi-select-combo bi-search-multi-text-value-combo",
height: 24, height: 24,
items: [] items: [],
});
}
_init() {
const o = this.options;
const triggerBtn = createWidget({
type: TriggerIconButton.xtype,
width: o.height,
height: o.height,
cls: "multi-select-trigger-icon-button",
}); });
}, super._init(...arguments);
const assertShowValue = () => {
_init: function () { isKey(this._startValue) &&
var self = this, o = this.options; (this.storeValue.type === Selection.All
BI.SearchMultiTextValueCombo.superclass._init.apply(this, arguments); ? remove(this.storeValue.value, this._startValue)
var assertShowValue = function () { : pushDistinct(this.storeValue.value, this._startValue));
BI.isKey(self._startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, self._startValue) : BI.pushDistinct(self.storeValue.value, self._startValue)); this._updateAllValue();
self._updateAllValue(); this._checkError();
self._checkError(); this.trigger.getSearcher().setState(this.storeValue);
self.trigger.getSearcher().setState(self.storeValue); this.trigger.getCounter().setButtonChecked(this.storeValue);
self.trigger.getCounter().setButtonChecked(self.storeValue);
}; };
this.storeValue = BI.deepClone(o.value || {}); this.storeValue = deepClone(o.value || {});
this._updateAllValue(); this._updateAllValue();
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
@ -32,10 +47,10 @@ BI.SearchMultiTextValueCombo = BI.inherit(BI.Single, {
// 标记正在请求数据 // 标记正在请求数据
this.requesting = false; this.requesting = false;
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.search_multi_select_trigger", type: SearchMultiSelectTrigger.xtype,
text: o.text, text: o.text,
height: BI.toPix(o.height, o.simple ? 1 : 2), height: toPix(o.height, o.simple ? 1 : 2),
// adapter: this.popup, // adapter: this.popup,
masker: { masker: {
offset: { offset: {
@ -45,437 +60,450 @@ BI.SearchMultiTextValueCombo = BI.inherit(BI.Single, {
bottom: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 1, bottom: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 1,
}, },
}, },
allValueGetter: function () { allValueGetter: () => this.allValue,
return self.allValue;
},
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemsCreator: function (op, callback) { itemsCreator: (op, callback) => {
self._itemsCreator(op, function (res) { this._itemsCreator(op, res => {
if (op.times === 1 && BI.isNotNull(op.keywords)) { if (op.times === 1 && isNotNull(op.keywords)) {
// 预防trigger内部把当前的storeValue改掉 // 预防trigger内部把当前的storeValue改掉
self.trigger.setValue(BI.deepClone(self.getValue())); this.trigger.setValue(deepClone(this.getValue()));
} }
callback.apply(self, arguments); callback.apply(this, ...arguments);
}); });
}, },
value: this.storeValue, value: this.storeValue,
warningTitle: o.warningTitle warningTitle: o.warningTitle,
}); });
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { this.trigger.on(MultiSelectTrigger.EVENT_START, () => {
self._setStartValue(""); this._setStartValue("");
this.getSearcher().setValue(self.storeValue); this.getSearcher().setValue(this.storeValue);
}); });
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { this.trigger.on(MultiSelectTrigger.EVENT_STOP, () => {
self._setStartValue(""); this._setStartValue("");
}); });
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { this.trigger.on(
var last = BI.last(keywords); MultiSelectTrigger.EVENT_SEARCHING,
keywords = BI.initial(keywords || []); keywords => {
if (keywords.length > 0) { const lastKeyWord = last(keywords);
self._joinKeywords(keywords, function () { keywords = initial(keywords || []);
if (BI.endWith(last, BI.BlankSplitChar)) { if (keywords.length > 0) {
self.combo.setValue(self.storeValue); this._joinKeywords(keywords, () => {
assertShowValue(); if (endWith(lastKeyWord, BI.BlankSplitChar)) {
self.combo.populate(); this.combo.setValue(this.storeValue);
self._setStartValue(""); assertShowValue();
} else { this.combo.populate();
self.combo.setValue(self.storeValue); this._setStartValue("");
assertShowValue(); } else {
} this.combo.setValue(this.storeValue);
self._dataChange = true; assertShowValue();
}); }
this._dataChange = true;
});
}
} }
}); );
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { this.trigger.on(MultiSelectTrigger.EVENT_CHANGE, (value, obj) => {
if (obj instanceof BI.MultiSelectBar) { if (obj instanceof MultiSelectBar) {
self._joinAll(this.getValue(), function () { this._joinAll(this.getValue(), () => {
assertShowValue(); assertShowValue();
}); });
} else { } else {
self._join(this.getValue(), function () { this._join(this.getValue(), () => {
assertShowValue(); assertShowValue();
}); });
} }
self._dataChange = true; this._dataChange = true;
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () {
this.getCounter().setValue(self.storeValue);
}); });
this.trigger.on(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK, function () { this.trigger.on(
if (!self.combo.isViewVisible()) { MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW,
self.combo.showView(); () => {
this.getCounter().setValue(this.storeValue);
}
);
this.trigger.on(MultiSelectTrigger.EVENT_COUNTER_CLICK, () => {
if (!this.combo.isViewVisible()) {
this.combo.showView();
} }
}); });
this.combo = BI.createWidget({ this.combo = createWidget({
type: "bi.combo", type: Combo.xtype,
cls: o.simple ? "bi-border-bottom" : "bi-border bi-border-radius", cls: o.simple ? "bi-border-bottom" : "bi-border bi-border-radius",
toggle: false, toggle: false,
container: o.container, container: o.container,
el: this.trigger, el: this.trigger,
adjustLength: 1, adjustLength: 1,
popup: { popup: {
type: "bi.search_multi_select_popup_view", type: SearchMultiSelectPopupView.xtype,
ref: function () { ref: _ref => {
self.popup = this; this.popup = _ref;
self.trigger.setAdapter(this); this.trigger.setAdapter(_ref);
}, },
listeners: [{ listeners: [
eventName: BI.MultiSelectPopupView.EVENT_CHANGE, {
action: function () { eventName: MultiSelectPopupView.EVENT_CHANGE,
self._dataChange = true; action :() => {
self.storeValue = this.getValue(); this._dataChange = true;
self._adjust(function () { this.storeValue = this.getValue();
assertShowValue(); this._adjust(() => {
}); assertShowValue();
} });
}, { },
eventName: BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM, },
action: function () { {
self._defaultState(); eventName: MultiSelectPopupView.EVENT_CLICK_CONFIRM,
} action :() => {
}, { this._defaultState();
eventName: BI.MultiSelectPopupView.EVENT_CLICK_CLEAR, },
action: function () { },
self._dataChange = true; {
self.setValue(); eventName: MultiSelectPopupView.EVENT_CLICK_CLEAR,
self._defaultState(); action: () => {
this._dataChange = true;
this.setValue();
this._defaultState();
},
} }
}], ],
itemsCreator: BI.bind(self._itemsCreator, this), itemsCreator: bind(this._itemsCreator, this),
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
onLoaded: function () { onLoaded: () => {
BI.nextTick(function () { nextTick(() => {
self.combo.adjustWidth(); this.combo.adjustWidth();
self.combo.adjustHeight(); this.combo.adjustHeight();
self.trigger.getCounter().adjustView(); this.trigger.getCounter().adjustView();
self.trigger.getSearcher().adjustView(); this.trigger.getSearcher().adjustView();
}); });
} },
}, },
value: o.value, value: o.value,
hideChecker: function (e) { hideChecker: e => triggerBtn.element.find(e.target).length === 0,
return triggerBtn.element.find(e.target).length === 0;
}
}); });
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { this.combo.on(Combo.EVENT_BEFORE_POPUPVIEW, () => {
if (!this.isViewVisible()) { if (!this.isViewVisible()) {
self._dataChange = false;// 标记数据是否发生变化 this._dataChange = false; // 标记数据是否发生变化
} }
this.setValue(self.storeValue); this.setValue(this.storeValue);
BI.nextTick(function () { nextTick(() => {
self._populate(); this._populate();
}); });
}); });
// 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件
this.wants2Quit = false; this.wants2Quit = false;
this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { this.combo.on(Combo.EVENT_AFTER_HIDEVIEW, () => {
// important:关闭弹出时又可能没有退出编辑状态 // important:关闭弹出时又可能没有退出编辑状态
self.trigger.stopEditing(); this.trigger.stopEditing();
if (self.requesting === true) { if (this.requesting === true) {
self.wants2Quit = true; this.wants2Quit = true;
} else { } else {
/** /**
* 在存在标红的情况如果popover没有发生改变就确认需要同步trigger的值否则对外value值和trigger样式不统一 * 在存在标红的情况如果popover没有发生改变就确认需要同步trigger的值否则对外value值和trigger样式不统一
*/ */
assertShowValue(); assertShowValue();
self._dataChange && self.fireEvent(BI.SearchMultiTextValueCombo.EVENT_CONFIRM); this._dataChange &&
this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM);
} }
}); });
var triggerBtn = BI.createWidget({ triggerBtn.on(TriggerIconButton.EVENT_CHANGE, () => {
type: "bi.trigger_icon_button", this.trigger.getCounter().hideView();
width: o.height, if (this.combo.isViewVisible()) {
height: o.height, this.combo.hideView();
cls: "multi-select-trigger-icon-button"
});
triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () {
self.trigger.getCounter().hideView();
if (self.combo.isViewVisible()) {
self.combo.hideView();
} else { } else {
self.combo.showView(); this.combo.showView();
} }
}); });
BI.createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.combo, {
left: 0, el: this.combo,
right: 0, left: 0,
top: 0, right: 0,
bottom: 0 top: 0,
}, { bottom: 0,
el: triggerBtn, },
right: 0, {
top: 0, el: triggerBtn,
bottom: 0 right: 0,
}] top: 0,
bottom: 0,
}
],
}); });
this._checkError(); this._checkError();
}, }
_defaultState: function () { _defaultState() {
this.trigger.stopEditing(); this.trigger.stopEditing();
this.combo.hideView(); this.combo.hideView();
}, }
_assertValue: function (val) { _assertValue(val) {
var o = this.options; const o = this.options;
val || (val = {}); val || (val = {});
val.type || (val.type = BI.Selection.Multi); val.type || (val.type = Selection.Multi);
val.value || (val.value = []); val.value || (val.value = []);
BI.remove(val.value, function (idx, value) { remove(val.value, (idx, value) => !contains(map(o.items, "value"), value));
return !BI.contains(BI.map(o.items, "value"), value); }
});
},
_makeMap: function (values) { _makeMap(values) {
return BI.makeObject(values || []); return makeObject(values || []);
}, }
_joinKeywords: function (keywords, callback) { _joinKeywords(keywords, callback) {
var self = this, o = this.options;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.requesting = true; this.requesting = true;
this._itemsCreator({ const digest = items => {
type: BI.SearchMultiTextValueCombo.REQ_GET_ALL_DATA, const selectedMap = this._makeMap(items);
keywords: keywords each(keywords, (i, val) => {
}, function (ob) { if (isNotNull(selectedMap[val])) {
var values = BI.map(ob.items, "value"); this.storeValue.type === Selection.Multi
digest(values); ? pushDistinct(this.storeValue.value, val)
}); : remove(this.storeValue.value, val);
function digest (items) {
var selectedMap = self._makeMap(items);
BI.each(keywords, function (i, val) {
if (BI.isNotNull(selectedMap[val])) {
self.storeValue.type === BI.Selection.Multi ? BI.pushDistinct(self.storeValue.value, val) : BI.remove(self.storeValue.value, val);
} }
}); });
self._adjust(callback); this._adjust(callback);
} };
}, this._itemsCreator(
{
type: SearchMultiTextValueCombo.REQ_GET_ALL_DATA,
keywords,
},
ob => {
const values = map(ob.items, "value");
digest(values);
}
);
}
_joinAll: function (res, callback) { _joinAll(res, callback) {
var self = this, o = this.options;
this._assertValue(res); this._assertValue(res);
this.requesting = true; this.requesting = true;
this._itemsCreator({ this._itemsCreator(
type: BI.SearchMultiTextValueCombo.REQ_GET_ALL_DATA, {
keywords: [this.trigger.getKey()] type: SearchMultiTextValueCombo.REQ_GET_ALL_DATA,
}, function (ob) { keywords: [this.trigger.getKey()],
var items = BI.map(ob.items, "value"); },
if (self.storeValue.type === res.type) { ob => {
var change = false; const map = this._makeMap(this.storeValue.value);
var map = self._makeMap(self.storeValue.value); const items = map(ob.items, "value");
BI.each(items, function (i, v) { if (this.storeValue.type === res.type) {
if (BI.isNotNull(map[v])) { let change = false;
change = true; each(items, (i, v) => {
self.storeValue.assist && self.storeValue.assist.push(map[v]); if (isNotNull(map[v])) {
delete map[v]; change = true;
this.storeValue.assist &&
this.storeValue.assist.push(map[v]);
delete map[v];
}
});
change && (this.storeValue.value = values(map));
this._adjust(callback);
return;
}
const selectedMap = this._makeMap(this.storeValue.value);
const notSelectedMap = this._makeMap(res.value);
const newItems = [];
each(items, (i, item) => {
if (isNotNull(selectedMap[items[i]])) {
this.storeValue.assist &&
this.storeValue.assist.push(selectedMap[items[i]]);
delete selectedMap[items[i]];
}
if (isNull(notSelectedMap[items[i]])) {
remove(this.storeValue.assist, item);
newItems.push(item);
} }
}); });
change && (self.storeValue.value = BI.values(map)); this.storeValue.value = newItems.concat(values(selectedMap));
self._adjust(callback); this._adjust(callback);
return;
} }
var selectedMap = self._makeMap(self.storeValue.value); );
var notSelectedMap = self._makeMap(res.value); }
var newItems = [];
BI.each(items, function (i, item) {
if (BI.isNotNull(selectedMap[items[i]])) {
self.storeValue.assist && self.storeValue.assist.push(selectedMap[items[i]]);
delete selectedMap[items[i]];
}
if (BI.isNull(notSelectedMap[items[i]])) {
BI.remove(self.storeValue.assist, item);
newItems.push(item);
}
});
self.storeValue.value = newItems.concat(BI.values(selectedMap));
self._adjust(callback);
});
},
_adjust: function (callback) {
var self = this, o = this.options;
if (!this._count) {
this._itemsCreator({
type: BI.SearchMultiTextValueCombo.REQ_GET_DATA_LENGTH
}, function (res) {
self._count = res.count;
adjust();
callback();
});
} else {
adjust();
callback();
}
function adjust () { _adjust(callback) {
if (self.storeValue.type === BI.Selection.All && self.storeValue.value.length >= self._count) { const adjust = () => {
self.storeValue = { if (
type: BI.Selection.Multi, this.storeValue.type === Selection.All &&
value: [] this.storeValue.value.length >= this._count
) {
this.storeValue = {
type: Selection.Multi,
value: [],
}; };
} else if (self.storeValue.type === BI.Selection.Multi && self.storeValue.value.length >= self._count) { } else if (
self.storeValue = { this.storeValue.type === Selection.Multi &&
type: BI.Selection.All, this.storeValue.value.length >= this._count
value: [] ) {
this.storeValue = {
type: Selection.All,
value: [],
}; };
} }
self._updateAllValue(); this._updateAllValue();
self._checkError(); this._checkError();
if (self.wants2Quit === true) { if (this.wants2Quit === true) {
self._dataChange && self.fireEvent(BI.SearchMultiTextValueCombo.EVENT_CONFIRM); this._dataChange &&
self.wants2Quit = false; this.fireEvent(SearchMultiTextValueCombo.EVENT_CONFIRM);
this.wants2Quit = false;
} }
self.requesting = false; this.requesting = false;
};
if (!this._count) {
this._itemsCreator(
{
type: SearchMultiTextValueCombo.REQ_GET_DATA_LENGTH,
},
res => {
this._count = res.count;
adjust();
callback();
}
);
} else {
adjust();
callback();
} }
}, }
_join: function (res, callback) { _join(res, callback) {
var self = this, o = this.options;
this._assertValue(res); this._assertValue(res);
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
if (this.storeValue.type === res.type) { if (this.storeValue.type === res.type) {
var map = this._makeMap(this.storeValue.value); const map = this._makeMap(this.storeValue.value);
BI.each(res.value, function (i, v) { each(res.value, (i, v) => {
if (!map[v]) { if (!map[v]) {
self.storeValue.value.push(v); this.storeValue.value.push(v);
BI.remove(self.storeValue.assist, v); remove(this.storeValue.assist, v);
map[v] = v; map[v] = v;
} }
}); });
var change = false; let change = false;
BI.each(res.assist, function (i, v) { each(res.assist, (i, v) => {
if (BI.isNotNull(map[v])) { if (isNotNull(map[v])) {
change = true; change = true;
self.storeValue.assist && self.storeValue.assist.push(map[v]); this.storeValue.assist &&
this.storeValue.assist.push(map[v]);
delete map[v]; delete map[v];
} }
}); });
change && (this.storeValue.value = BI.values(map)); change && (this.storeValue.value = values(map));
self._adjust(callback); this._adjust(callback);
return; return;
} }
this._joinAll(res, callback); this._joinAll(res, callback);
}, }
_setStartValue: function (value) { _setStartValue(value) {
this._startValue = value; this._startValue = value;
this.popup.setStartValue(value); this.popup.setStartValue(value);
}, }
_getItemsByTimes: function (items, times) { _getItemsByTimes(items, times) {
var res = []; const res = [];
for (var i = (times - 1) * 100; items[i] && i < times * 100; i++) { for (let i = (times - 1) * 100; items[i] && i < times * 100; i++) {
res.push(items[i]); res.push(items[i]);
} }
return res; return res;
}, }
_hasNextByTimes: function (items, times) { _hasNextByTimes(items, times) {
return times * 100 < items.length; return times * 100 < items.length;
}, }
_itemsCreator: function (options, callback) { _itemsCreator(options, callback) {
var self = this, o = this.options; const o = this.options;
var items = o.items; let items = o.items;
var keywords = (options.keywords || []).slice(); const keywords = (options.keywords || []).slice();
if (options.keyword) { if (options.keyword) {
keywords.push(options.keyword); keywords.push(options.keyword);
} }
BI.each(keywords, function (i, kw) { each(keywords, (i, kw) => {
var search = BI.Func.getSearchResult(items, kw); const search = Func.getSearchResult(items, kw);
items = search.match.concat(search.find); items = search.match.concat(search.find);
}); });
if (options.selectedValues) {// 过滤 if (options.selectedValues) {
var filter = BI.makeObject(options.selectedValues, true); // 过滤
items = BI.filter(items, function (i, ob) { const filter = makeObject(options.selectedValues, true);
return !filter[ob.value]; items = filter(items, (i, ob) => !filter[ob.value]);
});
} }
if (options.type == BI.MultiSelectCombo.REQ_GET_ALL_DATA) { if (options.type === MultiSelectCombo.REQ_GET_ALL_DATA) {
callback({ callback({
items: items items,
}); });
return; return;
} }
if (options.type == BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { if (options.type === MultiSelectCombo.REQ_GET_DATA_LENGTH) {
callback({count: items.length}); callback({ count: items.length });
return; return;
} }
callback({ callback({
items: self._getItemsByTimes(items, options.times), items: this._getItemsByTimes(items, options.times),
hasNext: self._hasNextByTimes(items, options.times) hasNext: this._hasNextByTimes(items, options.times),
}); });
}, }
_checkError: function () { _checkError() {
var v = this.storeValue.value || []; let v = this.storeValue.value || [];
if(BI.isNotEmptyArray(v)) { if (isNotEmptyArray(v)) {
v = BI.isArray(v) ? v : [v]; v = isArray(v) ? v : [v];
var result = BI.find(this.allValue, function (idx, value) { const result = find(this.allValue, (idx, value) => !contains(v, value));
return !BI.contains(v, value); if (isNull(result)) {
}); isNotNull(this.trigger) && this.trigger.setTipType("success");
if (BI.isNull(result)) {
BI.isNotNull(this.trigger) && (this.trigger.setTipType("success"));
this.element.removeClass("combo-error"); this.element.removeClass("combo-error");
} else { } else {
BI.isNotNull(this.trigger) && (this.trigger.setTipType("warning")); isNotNull(this.trigger) && this.trigger.setTipType("warning");
this.element.addClass("combo-error"); this.element.addClass("combo-error");
} }
} else { } else {
if(v.length === this.allValue.length){ if (v.length === this.allValue.length) {
BI.isNotNull(this.trigger) && (this.trigger.setTipType("success")); isNotNull(this.trigger) && this.trigger.setTipType("success");
this.element.removeClass("combo-error"); this.element.removeClass("combo-error");
}else { } else {
BI.isNotNull(this.trigger) && (this.trigger.setTipType("warning")); isNotNull(this.trigger) && this.trigger.setTipType("warning");
this.element.addClass("combo-error"); this.element.addClass("combo-error");
} }
} }
}, }
_updateAllValue: function () { _updateAllValue() {
this.storeValue = this.storeValue || {}; this.storeValue = this.storeValue || {};
this.allValue = BI.deepClone(this.storeValue.value || []); this.allValue = deepClone(this.storeValue.value || []);
}, }
setValue: function (v) { setValue(v) {
this.storeValue = BI.deepClone(v || {}); this.storeValue = deepClone(v || {});
this._updateAllValue(); this._updateAllValue();
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.combo.setValue(this.storeValue); this.combo.setValue(this.storeValue);
this._checkError(); this._checkError();
}, }
getValue: function () { getValue() {
return BI.deepClone(this.storeValue); return deepClone(this.storeValue);
}, }
_populate: function () { _populate() {
this._count = null; this._count = null;
this.combo.populate(); this.combo.populate();
}, }
populate: function (items) { populate(items) {
this.options.items = items; this.options.items = items;
this._populate(); this._populate();
} }
}); }
extend(SearchMultiTextValueCombo, {
BI.extend(BI.SearchMultiTextValueCombo, {
REQ_GET_DATA_LENGTH: 1, REQ_GET_DATA_LENGTH: 1,
REQ_GET_ALL_DATA: -1 REQ_GET_ALL_DATA: -1,
}); });
BI.SearchMultiTextValueCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.shortcut("bi.search_multi_text_value_combo", BI.SearchMultiTextValueCombo);

189
src/widget/searchmultitextvaluecombo/multitextvalue.combo.trigger.search.js

@ -1,31 +1,44 @@
BI.SearchMultiSelectTrigger = BI.inherit(BI.Trigger, { import { shortcut, extend, emptyFn, createWidget, Events, nextTick, HTapeLayout, RightVerticalAdaptLayout } from "@/core";
import { Trigger } from "@/base";
import { MultiSelectCheckSelectedSwitcher, MultiSelectSearcher, SearchMultiSelectSearcher } from "@/widget";
constants: { @shortcut()
height: 14, export class SearchMultiSelectTrigger extends Trigger {
rgap: 4, static xtype = "bi.search_multi_select_trigger";
lgap: 4
},
_defaultConfig: function () { constants = { height: 14, rgap: 4, lgap: 4 };
return BI.extend(BI.SearchMultiSelectTrigger.superclass._defaultConfig.apply(this, arguments), {
static EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK";
static EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_START = "EVENT_START";
static EVENT_STOP = "EVENT_STOP";
static EVENT_PAUSE = "EVENT_PAUSE";
static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls: "bi-multi-select-trigger", baseCls: "bi-multi-select-trigger",
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
searcher: {}, searcher: {},
switcher: {}, switcher: {},
adapter: null, adapter: null,
masker: {} masker: {},
}); });
}, }
_init: function () { _init() {
BI.SearchMultiSelectTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
this.searcher = BI.createWidget(o.searcher, { this.searcher = createWidget(o.searcher, {
type: "bi.search_multi_select_searcher", type: SearchMultiSelectSearcher.xtype,
height: o.height, height: o.height,
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
@ -36,119 +49,125 @@ BI.SearchMultiSelectTrigger = BI.inherit(BI.Trigger, {
value: o.value, value: o.value,
text: o.text, text: o.text,
tipType: o.tipType, tipType: o.tipType,
warningTitle: o.warningTitle warningTitle: o.warningTitle,
}); });
this.searcher.on(BI.MultiSelectSearcher.EVENT_START, function () { this.searcher.on(MultiSelectSearcher.EVENT_START, () => {
self.fireEvent(BI.SearchMultiSelectTrigger.EVENT_START); this.fireEvent(SearchMultiSelectTrigger.EVENT_START);
}); });
this.searcher.on(BI.MultiSelectSearcher.EVENT_PAUSE, function () { this.searcher.on(MultiSelectSearcher.EVENT_PAUSE, () => {
self.fireEvent(BI.SearchMultiSelectTrigger.EVENT_PAUSE); this.fireEvent(SearchMultiSelectTrigger.EVENT_PAUSE);
}); });
this.searcher.on(BI.MultiSelectSearcher.EVENT_SEARCHING, function () { this.searcher.on(MultiSelectSearcher.EVENT_SEARCHING, () => {
self.fireEvent(BI.SearchMultiSelectTrigger.EVENT_SEARCHING, arguments); this.fireEvent(SearchMultiSelectTrigger.EVENT_SEARCHING, ...arguments);
}); });
this.searcher.on(BI.MultiSelectSearcher.EVENT_STOP, function () { this.searcher.on(MultiSelectSearcher.EVENT_STOP, () => {
self.fireEvent(BI.SearchMultiSelectTrigger.EVENT_STOP); this.fireEvent(SearchMultiSelectTrigger.EVENT_STOP);
}); });
this.searcher.on(BI.MultiSelectSearcher.EVENT_CHANGE, function () { this.searcher.on(MultiSelectSearcher.EVENT_CHANGE, () => {
self.fireEvent(BI.SearchMultiSelectTrigger.EVENT_CHANGE, arguments); this.fireEvent(SearchMultiSelectTrigger.EVENT_CHANGE, ...arguments);
}); });
this.numberCounter = BI.createWidget(o.switcher, { this.numberCounter = createWidget(o.switcher, {
type: "bi.multi_select_check_selected_switcher", type: MultiSelectCheckSelectedSwitcher.xtype,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
adapter: o.adapter, adapter: o.adapter,
masker: o.masker, masker: o.masker,
value: o.value value: o.value,
});
this.numberCounter.on(BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, function () {
self.fireEvent(BI.SearchMultiSelectTrigger.EVENT_COUNTER_CLICK);
});
this.numberCounter.on(BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, function () {
self.fireEvent(BI.SearchMultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW);
}); });
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE,
() => {
this.fireEvent(SearchMultiSelectTrigger.EVENT_COUNTER_CLICK);
}
);
this.numberCounter.on(
MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW,
() => {
this.fireEvent(
SearchMultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW
);
}
);
var wrapNumberCounter = BI.createWidget({ const wrapNumberCounter = createWidget({
type: "bi.right_vertical_adapt", type: RightVerticalAdaptLayout.xtype,
hgap: 4, hgap: 4,
items: [{ items: [
el: this.numberCounter {
}] el: this.numberCounter,
}
],
}); });
var wrapper = BI.createWidget({ const wrapper = createWidget({
type: "bi.htape", type: HTapeLayout.xtype,
element: this, element: this,
items: [ items: [
{ {
el: this.searcher, el: this.searcher,
width: "fill" width: "fill",
}, { },
{
el: wrapNumberCounter, el: wrapNumberCounter,
width: 0 width: 0,
}, { },
el: BI.createWidget(), {
width: 24 el: createWidget(),
}] width: 24,
}
],
}); });
this.numberCounter.on(BI.Events.VIEW, function (b) { this.numberCounter.on(Events.VIEW, b => {
BI.nextTick(function () {// 自动调整宽度 nextTick(() => {
wrapper.attr("items")[1].width = (b === true ? self.numberCounter.element.outerWidth() + 8 : 0); // 自动调整宽度
wrapper.attr("items")[1].width =
b === true
? this.numberCounter.element.outerWidth() + 8
: 0;
wrapper.resize(); wrapper.resize();
}); });
}); });
this.element.click(function (e) { this.element.click(e => {
if (self.element.find(e.target).length > 0) { if (this.element.find(e.target).length > 0) {
self.numberCounter.hideView(); this.numberCounter.hideView();
} }
}); });
}, }
getCounter: function () { getCounter() {
return this.numberCounter; return this.numberCounter;
}, }
getSearcher: function () { getSearcher() {
return this.searcher; return this.searcher;
}, }
stopEditing: function () { stopEditing() {
this.searcher.stopSearch(); this.searcher.stopSearch();
this.numberCounter.hideView(); this.numberCounter.hideView();
}, }
setAdapter: function (adapter) { setAdapter(adapter) {
this.searcher.setAdapter(adapter); this.searcher.setAdapter(adapter);
this.numberCounter.setAdapter(adapter); this.numberCounter.setAdapter(adapter);
}, }
setValue: function (ob) { setValue(ob) {
this.searcher.setValue(ob); this.searcher.setValue(ob);
this.numberCounter.setValue(ob); this.numberCounter.setValue(ob);
}, }
setTipType: function (v) { setTipType(v) {
this.searcher.setTipType(v); this.searcher.setTipType(v);
}, }
getKey: function () { getKey() {
return this.searcher.getKey(); return this.searcher.getKey();
}, }
getValue: function () { getValue() {
return this.searcher.getValue(); return this.searcher.getValue();
} }
}); }
BI.SearchMultiSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK";
BI.SearchMultiSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK";
BI.SearchMultiSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE";
BI.SearchMultiSelectTrigger.EVENT_START = "EVENT_START";
BI.SearchMultiSelectTrigger.EVENT_STOP = "EVENT_STOP";
BI.SearchMultiSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE";
BI.SearchMultiSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.SearchMultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW";
BI.shortcut("bi.search_multi_select_trigger", BI.SearchMultiSelectTrigger);

238
src/widget/searchmultitextvaluecombo/multitextvalue.loader.search.js

@ -1,184 +1,202 @@
/** import { shortcut, Widget, extend, emptyFn, createWidget, isKey, Selection, map, contains, remove, pushDistinct, Controller, VerticalLayout, createItems, delay, isNotNull } from "@/core";
* 多选加载数据面板 import { ButtonGroup, Loader } from "@/base";
* Created by guy on 15/11/2. import { SelectList, MultiSelectBar, MultiSelectItem } from "@/case";
* @class BI.SearchMultiSelectLoader
* @extends Widget @shortcut()
*/ export class SearchMultiSelectLoader extends Widget {
BI.SearchMultiSelectLoader = BI.inherit(BI.Widget, { static xtype = "bi.search_multi_select_loader";
_defaultConfig: function () { static EVENT_CHANGE = "EVENT_CHANGE";
return BI.extend(BI.SearchMultiSelectLoader.superclass._defaultConfig.apply(this, arguments), {
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multi-select-loader", baseCls: "bi-multi-select-loader",
logic: { logic: {
dynamic: true dynamic: true,
}, },
el: { el: {
height: 400 height: 400,
}, },
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
onLoaded: BI.emptyFn onLoaded: emptyFn,
}); });
}, }
_init: function () { _init() {
BI.SearchMultiSelectLoader.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, opts = this.options; const opts = this.options;
var hasNext = false; let hasNext = false;
this.storeValue = opts.value || {}; this.storeValue = opts.value || {};
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.button_group = BI.createWidget({ this.button_group = createWidget({
type: "bi.select_list", type: SelectList.xtype,
element: this, element: this,
logic: opts.logic, logic: opts.logic,
toolbar: { toolbar: {
type: "bi.multi_select_bar", type: MultiSelectBar.xtype,
cls: "bi-list-item-active", cls: "bi-list-item-active",
height: this.options.itemHeight, height: this.options.itemHeight,
iconWrapperWidth: 36 iconWrapperWidth: 36,
}, },
el: BI.extend({ el: extend(
onLoaded: opts.onLoaded, {
el: { onLoaded: opts.onLoaded,
type: "bi.loader",
isDefaultInit: false,
logic: {
dynamic: true,
scrolly: true
},
el: { el: {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, type: Loader.xtype,
behaviors: { isDefaultInit: false,
redmark: function () { logic: {
return true; dynamic: true,
} scrolly: true,
}, },
layouts: [{ el: {
type: "bi.vertical" chooseType: ButtonGroup.CHOOSE_TYPE_MULTI,
}] behaviors: {
} redmark: () => true,
} },
}, opts.el), layouts: [
itemsCreator: function (op, callback) { {
var startValue = self._startValue; type: VerticalLayout.xtype,
self.storeValue && (op = BI.extend(op || {}, { }
selectedValues: BI.isKey(startValue) && self.storeValue.type === BI.Selection.Multi ],
? self.storeValue.value.concat(startValue) : self.storeValue.value },
})); },
opts.itemsCreator(op, function (ob) { },
opts.el
),
itemsCreator: (op, callback) => {
const startValue = this._startValue;
this.storeValue &&
(op = extend(op || {}, {
selectedValues:
isKey(startValue) &&
this.storeValue.type === Selection.Multi
? this.storeValue.value.concat(startValue)
: this.storeValue.value,
}));
opts.itemsCreator(op, ob => {
hasNext = ob.hasNext; hasNext = ob.hasNext;
var firstItems = []; let firstItems = [];
if (op.times === 1 && self.storeValue) { if (op.times === 1 && this.storeValue) {
var json = BI.map(self.storeValue.value, function (i, v) { const json = map(this.storeValue.value, (i, v) => {
var txt = opts.valueFormatter(v) || v; const txt = opts.valueFormatter(v) || v;
return { return {
text: txt, text: txt,
value: v, value: v,
title: txt, title: txt,
selected: self.storeValue.type === BI.Selection.Multi selected:
this.storeValue.type === Selection.Multi,
}; };
}); });
if (BI.isKey(self._startValue) && !BI.contains(self.storeValue.value, self._startValue)) { if (
var txt = opts.valueFormatter(startValue) || startValue; isKey(this._startValue) &&
!contains(this.storeValue.value, this._startValue)
) {
const txt =
opts.valueFormatter(startValue) || startValue;
json.unshift({ json.unshift({
text: txt, text: txt,
value: startValue, value: startValue,
title: txt, title: txt,
selected: true selected: true,
}); });
} }
firstItems = self._createItems(json); firstItems = this._createItems(json);
} }
callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); callback(
if (op.times === 1 && self.storeValue) { firstItems.concat(this._createItems(ob.items)),
BI.isKey(startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, startValue) : BI.pushDistinct(self.storeValue.value, startValue)); ob.keyword || ""
self.setValue(self.storeValue); );
if (op.times === 1 && this.storeValue) {
isKey(startValue) &&
(this.storeValue.type === Selection.All
? remove(this.storeValue.value, startValue)
: pushDistinct(
this.storeValue.value,
startValue
));
this.setValue(this.storeValue);
} }
(op.times === 1) && self._scrollToTop(); op.times === 1 && this._scrollToTop();
}); });
}, },
hasNext: function () { hasNext: () => hasNext,
return hasNext; value: this.storeValue,
},
value: this.storeValue
}); });
this.button_group.on(BI.Controller.EVENT_CHANGE, function () { this.button_group.on(Controller.EVENT_CHANGE, () => {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); this.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
this.button_group.on(BI.SelectList.EVENT_CHANGE, function () { this.button_group.on(SelectList.EVENT_CHANGE, () => {
self.fireEvent(BI.SearchMultiSelectLoader.EVENT_CHANGE, arguments); this.fireEvent(SearchMultiSelectLoader.EVENT_CHANGE, ...arguments);
}); });
}, }
_createItems: function (items) { _createItems(items) {
return BI.createItems(items, { return createItems(items, {
type: "bi.multi_select_item", type: MultiSelectItem.xtype,
logic: this.options.logic, logic: this.options.logic,
cls: "bi-list-item-active", cls: "bi-list-item-active",
height: this.options.itemHeight, height: this.options.itemHeight,
selected: this.isAllSelected(), selected: this.isAllSelected(),
iconWrapperWidth: 36 iconWrapperWidth: 36,
}); });
}, }
_scrollToTop: function () { _scrollToTop() {
var self = this; delay(() => {
BI.delay(function () { this.button_group.element.scrollTop(0);
self.button_group.element.scrollTop(0);
}, 30); }, 30);
}, }
isAllSelected: function () { isAllSelected() {
return this.button_group.isAllSelected(); return this.button_group.isAllSelected();
}, }
_assertValue: function (val) { _assertValue(val) {
val || (val = {}); val || (val = {});
val.type || (val.type = BI.Selection.Multi); val.type || (val.type = Selection.Multi);
val.value || (val.value = []); val.value || (val.value = []);
}, }
setStartValue: function (v) { setStartValue(v) {
this._startValue = v; this._startValue = v;
}, }
setValue: function (v) { setValue(v) {
this.storeValue = v || {}; this.storeValue = v || {};
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.button_group.setValue(this.storeValue); this.button_group.setValue(this.storeValue);
}, }
getValue: function () { getValue() {
return this.button_group.getValue(); return this.button_group.getValue();
}, }
getAllButtons: function () { getAllButtons() {
return this.button_group.getAllButtons(); return this.button_group.getAllButtons();
}, }
empty: function () { empty() {
this.button_group.empty(); this.button_group.empty();
}, }
populate: function (items) { populate(items) {
if (BI.isNotNull(items)) { if (isNotNull(items)) {
arguments[0] = this._createItems(items); arguments[0] = this._createItems(items);
} }
this.button_group.populate.apply(this.button_group, arguments); this.button_group.populate(...arguments);
}, }
resetHeight: function (h) { resetHeight(h) {
this.button_group.resetHeight(h); this.button_group.resetHeight(h);
}, }
resetWidth: function (w) { resetWidth(w) {
this.button_group.resetWidth(w); this.button_group.resetWidth(w);
} }
}); }
BI.SearchMultiSelectLoader.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.search_multi_select_loader", BI.SearchMultiSelectLoader);

112
src/widget/searchmultitextvaluecombo/multitextvalue.popup.view.search.js

@ -1,92 +1,104 @@
BI.SearchMultiSelectPopupView = BI.inherit(BI.Widget, { import { shortcut, Widget, extend, emptyFn, createWidget, i18nText } from "@/core";
import { MultiPopupView } from "@/case";
import { SearchMultiSelectLoader } from "@/widget";
_defaultConfig: function () { @shortcut()
return BI.extend(BI.SearchMultiSelectPopupView.superclass._defaultConfig.apply(this, arguments), { export class SearchMultiSelectPopupView extends Widget {
static xtype = "bi.search_multi_select_popup_view";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM";
static EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multi-select-popup-view", baseCls: "bi-multi-select-popup-view",
maxWidth: "auto", maxWidth: "auto",
minWidth: 135, minWidth: 135,
maxHeight: 400, maxHeight: 400,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
onLoaded: BI.emptyFn onLoaded: emptyFn,
}); });
}, }
_init: function () { _init() {
BI.SearchMultiSelectPopupView.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, opts = this.options; const opts = this.options;
this.loader = BI.createWidget({ this.loader = createWidget({
type: "bi.search_multi_select_loader", type: SearchMultiSelectLoader.xtype,
itemsCreator: opts.itemsCreator, itemsCreator: opts.itemsCreator,
valueFormatter: opts.valueFormatter, valueFormatter: opts.valueFormatter,
onLoaded: opts.onLoaded, onLoaded: opts.onLoaded,
value: opts.value value: opts.value,
}); });
this.popupView = BI.createWidget({ this.popupView = createWidget({
type: "bi.multi_popup_view", type: MultiPopupView.xtype,
stopPropagation: false, stopPropagation: false,
maxWidth: opts.maxWidth, maxWidth: opts.maxWidth,
minWidth: opts.minWidth, minWidth: opts.minWidth,
maxHeight: opts.maxHeight, maxHeight: opts.maxHeight,
element: this, element: this,
buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_OK")], buttons: [i18nText("BI-Basic_Clears"), i18nText("BI-Basic_OK")],
el: this.loader, el: this.loader,
value: opts.value value: opts.value,
}); });
this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { this.popupView.on(MultiPopupView.EVENT_CHANGE, () => {
self.fireEvent(BI.SearchMultiSelectPopupView.EVENT_CHANGE); this.fireEvent(SearchMultiSelectPopupView.EVENT_CHANGE);
}); });
this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { this.popupView.on(
switch (index) { MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON,
index => {
switch (index) {
case 0: case 0:
self.fireEvent(BI.SearchMultiSelectPopupView.EVENT_CLICK_CLEAR); this.fireEvent(
SearchMultiSelectPopupView.EVENT_CLICK_CLEAR
);
break; break;
case 1: case 1:
self.fireEvent(BI.SearchMultiSelectPopupView.EVENT_CLICK_CONFIRM); this.fireEvent(
SearchMultiSelectPopupView.EVENT_CLICK_CONFIRM
);
break; break;
default:
break;
}
} }
}); );
}, }
isAllSelected: function () { isAllSelected() {
return this.loader.isAllSelected(); return this.loader.isAllSelected();
}, }
setStartValue: function (v) { setStartValue(v) {
this.loader.setStartValue(v); this.loader.setStartValue(v);
}, }
setValue: function (v) { setValue(v) {
this.popupView.setValue(v); this.popupView.setValue(v);
}, }
getValue: function () { getValue() {
return this.popupView.getValue(); return this.popupView.getValue();
}, }
populate: function (items) { populate(items) {
this.popupView.populate.apply(this.popupView, arguments); this.popupView.populate(...arguments);
}, }
resetHeight: function (h) { resetHeight(h) {
this.popupView.resetHeight(h); this.popupView.resetHeight(h);
}, }
resetWidth: function (w) { resetWidth(w) {
this.popupView.resetWidth(w); this.popupView.resetWidth(w);
}, }
setDirection: function (direction, position) { setDirection(direction, position) {
this.popupView.setDirection(direction, position); this.popupView.setDirection(direction, position);
}, }
}); }
BI.SearchMultiSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE";
BI.SearchMultiSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM";
BI.SearchMultiSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR";
BI.shortcut("bi.search_multi_select_popup_view", BI.SearchMultiSelectPopupView);

200
src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js

@ -1,175 +1,179 @@
BI.SearchMultiSelectSearcher = BI.inherit(BI.Widget, { import { shortcut, Widget, extend, emptyFn, createWidget, isNotNull, Selection, size, each } from "@/core";
import { Searcher } from "@/base";
_defaultConfig: function () { import { MultiSelectEditor, MultiSelectSearchPane } from "@/widget";
return BI.extend(BI.SearchMultiSelectSearcher.superclass._defaultConfig.apply(this, arguments), {
@shortcut()
export class SearchMultiSelectSearcher extends Widget {
static xtype = "bi.search_multi_select_searcher";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_START = "EVENT_START";
static EVENT_STOP = "EVENT_STOP";
static EVENT_PAUSE = "EVENT_PAUSE";
static EVENT_SEARCHING = "EVENT_SEARCHING";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multi-select-searcher", baseCls: "bi-multi-select-searcher",
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
el: {}, el: {},
popup: {}, popup: {},
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
adapter: null, adapter: null,
masker: {} masker: {},
}); });
}, }
_init: function () { _init() {
BI.SearchMultiSelectSearcher.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
this.editor = BI.createWidget(o.el, { this.editor = createWidget(o.el, {
type: "bi.multi_select_editor", type: MultiSelectEditor.xtype,
height: o.height, height: o.height,
text: o.text, text: o.text,
tipType: o.tipType, tipType: o.tipType,
warningTitle: o.warningTitle warningTitle: o.warningTitle,
}); });
this.searcher = BI.createWidget({ this.searcher = createWidget({
type: "bi.searcher", type: Searcher.xtype,
element: this, element: this,
height: o.height, height: o.height,
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch: (op, callback) => {
callback(); callback();
}, },
el: this.editor, el: this.editor,
popup: BI.extend({ popup: extend(
type: "bi.multi_select_search_pane", {
valueFormatter: o.valueFormatter, type: MultiSelectSearchPane.xtype,
keywordGetter: function () { valueFormatter: o.valueFormatter,
return self.editor.getValue(); keywordGetter: () => this.editor.getValue(),
}, itemsCreator: (op, callback) => {
itemsCreator: function (op, callback) { const keyword = this.editor.getValue();
var keyword = self.editor.getValue(); op.keywords = [keyword];
op.keywords = [keyword]; o.itemsCreator(op, callback);
o.itemsCreator(op, callback); },
value: o.value,
}, },
value: o.value o.popup
}, o.popup), ),
adapter: o.adapter, adapter: o.adapter,
masker: o.masker masker: o.masker,
}); });
this.searcher.on(BI.Searcher.EVENT_START, function () { this.searcher.on(Searcher.EVENT_START, () => {
self.fireEvent(BI.SearchMultiSelectSearcher.EVENT_START); this.fireEvent(SearchMultiSelectSearcher.EVENT_START);
}); });
this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { this.searcher.on(Searcher.EVENT_PAUSE, () => {
if (this.hasMatched()) { this.fireEvent(SearchMultiSelectSearcher.EVENT_PAUSE);
}
self.fireEvent(BI.SearchMultiSelectSearcher.EVENT_PAUSE);
}); });
this.searcher.on(BI.Searcher.EVENT_STOP, function () { this.searcher.on(Searcher.EVENT_STOP, () => {
self.fireEvent(BI.SearchMultiSelectSearcher.EVENT_STOP); this.fireEvent(SearchMultiSelectSearcher.EVENT_STOP);
}); });
this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { this.searcher.on(Searcher.EVENT_CHANGE, () => {
self.fireEvent(BI.SearchMultiSelectSearcher.EVENT_CHANGE, arguments); this.fireEvent(SearchMultiSelectSearcher.EVENT_CHANGE, ...arguments);
}); });
this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { this.searcher.on(Searcher.EVENT_SEARCHING, () => {
var keywords = this.getKeywords(); const keywords = this.getKeywords();
self.fireEvent(BI.SearchMultiSelectSearcher.EVENT_SEARCHING, keywords); this.fireEvent(SearchMultiSelectSearcher.EVENT_SEARCHING, keywords);
}); });
if(BI.isNotNull(o.value)) { if (isNotNull(o.value)) {
this.setState(o.value); this.setState(o.value);
} }
}, }
adjustView: function () { adjustView() {
this.searcher.adjustView(); this.searcher.adjustView();
}, }
isSearching: function () { isSearching() {
return this.searcher.isSearching(); return this.searcher.isSearching();
}, }
stopSearch: function () { stopSearch() {
this.searcher.stopSearch(); this.searcher.stopSearch();
}, }
getKeyword: function () { getKeyword() {
return this.editor.getValue(); return this.editor.getValue();
}, }
hasMatched: function () { hasMatched() {
return this.searcher.hasMatched(); return this.searcher.hasMatched();
}, }
hasChecked: function () { hasChecked() {
return this.searcher.getView() && this.searcher.getView().hasChecked(); return this.searcher.getView() && this.searcher.getView().hasChecked();
}, }
setAdapter: function (adapter) { setAdapter(adapter) {
this.searcher.setAdapter(adapter); this.searcher.setAdapter(adapter);
}, }
setState: function (obj) { setState(obj) {
var o = this.options; let state;
var ob = {}; const o = this.options;
const ob = {};
ob.type = obj.type; ob.type = obj.type;
ob.value = o.allValueGetter() || []; ob.value = o.allValueGetter() || [];
ob.assist = obj.assist; ob.assist = obj.assist;
if (ob.type === BI.Selection.All) { if (ob.type === Selection.All) {
if (ob.value.length === 0) { if (ob.value.length === 0) {
this.editor.setState(BI.Selection.All); this.editor.setState(Selection.All);
} else if (BI.size(ob.assist) <= 20) { } else if (size(ob.assist) <= 20) {
var state = ""; state = "";
BI.each(ob.assist, function (i, v) { each(ob.assist, (i, v) => {
if (i === 0) { if (i === 0) {
state += "" + (o.valueFormatter(v + "") || v); state += `${o.valueFormatter(`${v}`) || v}`;
} else { } else {
state += "," + (o.valueFormatter(v + "") || v); state += `,${o.valueFormatter(`${v}`) || v}`;
} }
}); });
this.editor.setState(state); this.editor.setState(state);
} else { } else {
this.editor.setState(BI.Selection.Multi); this.editor.setState(Selection.Multi);
} }
} else { } else {
if (ob.value.length === 0) { if (ob.value.length === 0) {
this.editor.setState(BI.Selection.None); this.editor.setState(Selection.None);
} else if (BI.size(ob.value) <= 20) { } else if (size(ob.value) <= 20) {
var state = ""; state = "";
BI.each(ob.value, function (i, v) { each(ob.value, (i, v) => {
if (i === 0) { if (i === 0) {
state += "" + (o.valueFormatter(v + "") || v); state += `${o.valueFormatter(`${v}`) || v}`;
} else { } else {
state += "," + (o.valueFormatter(v + "") || v); state += `,${o.valueFormatter(`${v}`) || v}`;
} }
}); });
this.editor.setState(state); this.editor.setState(state);
} else { } else {
this.editor.setState(BI.Selection.Multi); this.editor.setState(Selection.Multi);
} }
} }
}, }
setTipType: function (v) { setTipType(v) {
this.editor.setTipType(v); this.editor.setTipType(v);
}, }
setValue: function (ob) { setValue(ob) {
this.setState(ob); this.setState(ob);
this.searcher.setValue(ob); this.searcher.setValue(ob);
}, }
getKey: function () { getKey() {
return this.editor.getValue(); return this.editor.getValue();
}, }
getValue: function () { getValue() {
return this.searcher.getValue(); return this.searcher.getValue();
}, }
populate: function (items) { populate(items) {
this.searcher.populate.apply(this.searcher, arguments); this.searcher.populate(...arguments);
} }
}); }
BI.SearchMultiSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.SearchMultiSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE";
BI.SearchMultiSelectSearcher.EVENT_START = "EVENT_START";
BI.SearchMultiSelectSearcher.EVENT_STOP = "EVENT_STOP";
BI.SearchMultiSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE";
BI.SearchMultiSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.shortcut("bi.search_multi_select_searcher", BI.SearchMultiSelectSearcher);

Loading…
Cancel
Save