zsmj 2 years ago
parent
commit
101b3352fa
  1. 280
      src/widget/editor/editor.search.js
  2. 3
      src/widget/index.js
  3. 4
      src/widget/multiselect/index.js
  4. 3
      src/widget/multiselectlist/index.js
  5. 528
      src/widget/multiselectlist/multiselectlist.insert.js
  6. 547
      src/widget/multiselectlist/multiselectlist.insert.nobar.js
  7. 534
      src/widget/multiselectlist/multiselectlist.js

280
src/widget/editor/editor.search.js

@ -1,26 +1,69 @@
/** import {
* Created by roy on 15/9/14. shortcut,
*/ Widget,
BI.SearchEditor = BI.inherit(BI.Widget, { extend,
_defaultConfig: function (config) { i18nText,
var conf = BI.SearchEditor.superclass._defaultConfig.apply(this, arguments); emptyFn,
return BI.extend(conf, { createWidget,
baseCls: "bi-search-editor bi-focus-shadow " + (config.simple ? "bi-border-bottom" : "bi-border bi-border-radius"), toPix,
isKey,
Controller,
Events,
HTapeLayout,
isEndWithBlank
} from "@/core";
import { IconButton, Editor, IconLabel } from "@/base";
@shortcut()
export class SearchEditor extends Widget {
static xtype = "bi.search_editor";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_CLICK = "EVENT_CLICK";
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
static EVENT_SPACE = "EVENT_SPACE";
static EVENT_BACKSPACE = "EVENT_BACKSPACE";
static EVENT_CLEAR = "EVENT_CLEAR";
static EVENT_START = "EVENT_START";
static EVENT_PAUSE = "EVENT_PAUSE";
static EVENT_STOP = "EVENT_STOP";
static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM";
static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR";
static EVENT_ENTER = "EVENT_ENTER";
static EVENT_RESTRICT = "EVENT_RESTRICT";
static EVENT_REMOVE = "EVENT_REMOVE";
static EVENT_EMPTY = "EVENT_EMPTY";
_defaultConfig(config) {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls:
`bi-search-editor bi-focus-shadow ${
config.simple
? "bi-border-bottom"
: "bi-border bi-border-radius"}`,
height: 24, height: 24,
errorText: "", errorText: "",
watermark: BI.i18nText("BI-Basic_Search"), watermark: i18nText("BI-Basic_Search"),
validationChecker: BI.emptyFn, validationChecker: emptyFn,
quitChecker: BI.emptyFn, quitChecker: emptyFn,
value: "" value: "",
}); });
}, }
_init: function () {
BI.SearchEditor.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
this.editor = BI.createWidget(o.el, { const self = this,
type: "bi.editor", o = this.options;
this.editor = createWidget(o.el, {
type: Editor.xtype,
simple: o.simple, simple: o.simple,
height: BI.toPix(o.height, o.simple ? 1 : 2), height: toPix(o.height, o.simple ? 1 : 2),
watermark: o.watermark, watermark: o.watermark,
allowBlank: true, allowBlank: true,
hgap: 1, hgap: 1,
@ -30,189 +73,172 @@ BI.SearchEditor = BI.inherit(BI.Widget, {
value: o.value, value: o.value,
autoTrim: o.autoTrim, autoTrim: o.autoTrim,
}); });
this.clear = BI.createWidget({ this.clear = createWidget({
type: "bi.icon_button", type: IconButton.xtype,
stopEvent: true, stopEvent: true,
cls: "close-font", cls: "close-font",
invisible: !BI.isKey(o.value) invisible: !isKey(o.value),
}); });
this.clear.on(BI.IconButton.EVENT_CHANGE, function () { this.clear.on(IconButton.EVENT_CHANGE, () => {
self.setValue(""); self.setValue("");
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.STOPEDIT, self.getValue()); self.fireEvent(
Controller.EVENT_CHANGE,
Events.STOPEDIT,
self.getValue()
);
// 从有内容到无内容的清空也是一次change // 从有内容到无内容的清空也是一次change
self.fireEvent(BI.SearchEditor.EVENT_CHANGE); self.fireEvent(SearchEditor.EVENT_CHANGE);
self.fireEvent(BI.SearchEditor.EVENT_CLEAR); self.fireEvent(SearchEditor.EVENT_CLEAR);
}); });
BI.createWidget({ createWidget({
element: this, element: this,
height: BI.toPix(o.height, o.simple ? 1 : 2), height: toPix(o.height, o.simple ? 1 : 2),
type: "bi.htape", type: HTapeLayout.xtype,
items: [ items: [
{ {
el: { el: {
type: "bi.icon_label", type: IconLabel.xtype,
cls: "search-font" cls: "search-font",
}, },
width: 24 width: 24,
}, },
{ {
el: self.editor el: self.editor,
}, },
{ {
el: this.clear, el: this.clear,
width: 24 width: 24,
} }
] ],
}); });
this.editor.on(BI.Controller.EVENT_CHANGE, function () { this.editor.on(Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
this.editor.on(BI.Editor.EVENT_FOCUS, function () { this.editor.on(Editor.EVENT_FOCUS, () => {
self.fireEvent(BI.SearchEditor.EVENT_FOCUS); self.fireEvent(SearchEditor.EVENT_FOCUS);
}); });
this.editor.on(BI.Editor.EVENT_BLUR, function () { this.editor.on(Editor.EVENT_BLUR, () => {
self.fireEvent(BI.SearchEditor.EVENT_BLUR); self.fireEvent(SearchEditor.EVENT_BLUR);
}); });
this.editor.on(BI.Editor.EVENT_CLICK, function () { this.editor.on(Editor.EVENT_CLICK, () => {
self.fireEvent(BI.SearchEditor.EVENT_CLICK); self.fireEvent(SearchEditor.EVENT_CLICK);
}); });
this.editor.on(BI.Editor.EVENT_CHANGE, function () { this.editor.on(Editor.EVENT_CHANGE, () => {
self._checkClear(); self._checkClear();
self.fireEvent(BI.SearchEditor.EVENT_CHANGE); self.fireEvent(SearchEditor.EVENT_CHANGE);
}); });
this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { this.editor.on(Editor.EVENT_KEY_DOWN, v => {
self.fireEvent(BI.SearchEditor.EVENT_KEY_DOWN, v); self.fireEvent(SearchEditor.EVENT_KEY_DOWN, v);
}); });
this.editor.on(BI.Editor.EVENT_SPACE, function () { this.editor.on(Editor.EVENT_SPACE, () => {
self.fireEvent(BI.SearchEditor.EVENT_SPACE); self.fireEvent(SearchEditor.EVENT_SPACE);
}); });
this.editor.on(BI.Editor.EVENT_BACKSPACE, function () { this.editor.on(Editor.EVENT_BACKSPACE, () => {
self.fireEvent(BI.SearchEditor.EVENT_BACKSPACE); self.fireEvent(SearchEditor.EVENT_BACKSPACE);
}); });
this.editor.on(Editor.EVENT_VALID, () => {
this.editor.on(BI.Editor.EVENT_VALID, function () { self.fireEvent(SearchEditor.EVENT_VALID);
self.fireEvent(BI.SearchEditor.EVENT_VALID);
}); });
this.editor.on(BI.Editor.EVENT_ERROR, function () { this.editor.on(Editor.EVENT_ERROR, () => {
self.fireEvent(BI.SearchEditor.EVENT_ERROR); self.fireEvent(SearchEditor.EVENT_ERROR);
}); });
this.editor.on(BI.Editor.EVENT_ENTER, function () { this.editor.on(Editor.EVENT_ENTER, () => {
self.fireEvent(BI.SearchEditor.EVENT_ENTER); self.fireEvent(SearchEditor.EVENT_ENTER);
}); });
this.editor.on(BI.Editor.EVENT_RESTRICT, function () { this.editor.on(Editor.EVENT_RESTRICT, () => {
self.fireEvent(BI.SearchEditor.EVENT_RESTRICT); self.fireEvent(SearchEditor.EVENT_RESTRICT);
}); });
this.editor.on(BI.Editor.EVENT_EMPTY, function () { this.editor.on(Editor.EVENT_EMPTY, () => {
self._checkClear(); self._checkClear();
self.fireEvent(BI.SearchEditor.EVENT_EMPTY); self.fireEvent(SearchEditor.EVENT_EMPTY);
}); });
this.editor.on(BI.Editor.EVENT_REMOVE, function () { this.editor.on(Editor.EVENT_REMOVE, () => {
self.fireEvent(BI.SearchEditor.EVENT_REMOVE); self.fireEvent(SearchEditor.EVENT_REMOVE);
}); });
this.editor.on(BI.Editor.EVENT_CONFIRM, function () { this.editor.on(Editor.EVENT_CONFIRM, () => {
self.fireEvent(BI.SearchEditor.EVENT_CONFIRM); self.fireEvent(SearchEditor.EVENT_CONFIRM);
}); });
this.editor.on(BI.Editor.EVENT_CHANGE_CONFIRM, function () { this.editor.on(Editor.EVENT_CHANGE_CONFIRM, () => {
self.fireEvent(BI.SearchEditor.EVENT_CHANGE_CONFIRM); self.fireEvent(SearchEditor.EVENT_CHANGE_CONFIRM);
}); });
this.editor.on(BI.Editor.EVENT_START, function () { this.editor.on(Editor.EVENT_START, () => {
self.fireEvent(BI.SearchEditor.EVENT_START); self.fireEvent(SearchEditor.EVENT_START);
}); });
this.editor.on(BI.Editor.EVENT_PAUSE, function () { this.editor.on(Editor.EVENT_PAUSE, () => {
self.fireEvent(BI.SearchEditor.EVENT_PAUSE); self.fireEvent(SearchEditor.EVENT_PAUSE);
}); });
this.editor.on(BI.Editor.EVENT_STOP, function () { this.editor.on(Editor.EVENT_STOP, () => {
self.fireEvent(BI.SearchEditor.EVENT_STOP); self.fireEvent(SearchEditor.EVENT_STOP);
}); });
}, }
_checkClear: function () { _checkClear() {
if (!this.getValue()) { if (!this.getValue()) {
this.clear.invisible(); this.clear.invisible();
} else { } else {
this.clear.visible(); this.clear.visible();
} }
}, }
setWaterMark: function (v) { setWaterMark(v) {
this.options.watermark = v; this.options.watermark = v;
this.editor.setWaterMark(v); this.editor.setWaterMark(v);
}, }
focus: function () { focus() {
this.editor.focus(); this.editor.focus();
}, }
blur: function () { blur() {
this.editor.blur(); this.editor.blur();
}, }
getValue: function () { getValue() {
if (this.isValid()) { if (this.isValid()) {
return this.editor.getValue(); return this.editor.getValue();
} }
}, }
getKeywords: function () { getKeywords() {
var val = this.editor.getLastChangedValue(); const val = this.editor.getLastChangedValue();
var keywords = val.match(/[\S]+/g); const keywords = val.match(/[\S]+/g);
if (BI.isEndWithBlank(val)) { if (isEndWithBlank(val)) {
return keywords.concat([" "]); return keywords.concat([" "]);
} }
return keywords; return keywords;
}, }
getLastValidValue: function () { getLastValidValue() {
return this.editor.getLastValidValue(); return this.editor.getLastValidValue();
}, }
getLastChangedValue: function () { getLastChangedValue() {
return this.editor.getLastChangedValue(); return this.editor.getLastChangedValue();
}, }
setValue: function (v) { setValue(v) {
this.editor.setValue(v); this.editor.setValue(v);
if (BI.isKey(v)) { if (isKey(v)) {
this.clear.visible(); this.clear.visible();
} }
}, }
isEditing: function () { isEditing() {
return this.editor.isEditing(); return this.editor.isEditing();
}, }
isValid: function () { isValid() {
return this.editor.isValid(); return this.editor.isValid();
}, }
showClearIcon: function () { showClearIcon() {
this.clear.visible(); this.clear.visible();
}, }
hideClearIcon: function () { hideClearIcon() {
this.clear.invisible(); this.clear.invisible();
} }
}); }
BI.SearchEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.SearchEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.SearchEditor.EVENT_BLUR = "EVENT_BLUR";
BI.SearchEditor.EVENT_CLICK = "EVENT_CLICK";
BI.SearchEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
BI.SearchEditor.EVENT_SPACE = "EVENT_SPACE";
BI.SearchEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE";
BI.SearchEditor.EVENT_CLEAR = "EVENT_CLEAR";
BI.SearchEditor.EVENT_START = "EVENT_START";
BI.SearchEditor.EVENT_PAUSE = "EVENT_PAUSE";
BI.SearchEditor.EVENT_STOP = "EVENT_STOP";
BI.SearchEditor.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.SearchEditor.EVENT_CHANGE_CONFIRM = "EVENT_CHANGE_CONFIRM";
BI.SearchEditor.EVENT_VALID = "EVENT_VALID";
BI.SearchEditor.EVENT_ERROR = "EVENT_ERROR";
BI.SearchEditor.EVENT_ENTER = "EVENT_ENTER";
BI.SearchEditor.EVENT_RESTRICT = "EVENT_RESTRICT";
BI.SearchEditor.EVENT_REMOVE = "EVENT_REMOVE";
BI.SearchEditor.EVENT_EMPTY = "EVENT_EMPTY";
BI.shortcut("bi.search_editor", BI.SearchEditor);

3
src/widget/index.js

@ -12,6 +12,7 @@ import { MultiTreeCombo } from "./multitree/multi.tree.combo";
import { MultiTreeInsertCombo } from "./multitree/multi.tree.insert.combo"; import { MultiTreeInsertCombo } from "./multitree/multi.tree.insert.combo";
import { MultiTreeListCombo } from "./multitree/multi.tree.list.combo"; import { MultiTreeListCombo } from "./multitree/multi.tree.list.combo";
import * as multiselect from "./multiselect"; import * as multiselect from "./multiselect";
import * as multiselectlist from "./multiselectlist";
Object.assign(BI, { Object.assign(BI, {
Collapse, Collapse,
@ -28,6 +29,7 @@ Object.assign(BI, {
MultiTreeInsertCombo, MultiTreeInsertCombo,
MultiTreeListCombo, MultiTreeListCombo,
...multiselect, ...multiselect,
...multiselectlist,
}); });
export * from "./date/calendar"; export * from "./date/calendar";
@ -43,6 +45,7 @@ export { MultiTreeCombo } from "./multitree/multi.tree.combo";
export { MultiTreeInsertCombo } from "./multitree/multi.tree.insert.combo"; export { MultiTreeInsertCombo } from "./multitree/multi.tree.insert.combo";
export { MultiTreeListCombo } from "./multitree/multi.tree.list.combo"; export { MultiTreeListCombo } from "./multitree/multi.tree.list.combo";
export * from "./multiselect"; export * from "./multiselect";
export * from "./multiselectlist";
export { export {
Collapse Collapse

4
src/widget/multiselect/index.js

@ -0,0 +1,4 @@
export { MultiSelectCombo } from "./multiselect.combo";
export { MultiSelectNoBarCombo } from "./multiselect.combo.nobar";
export { MultiSelectInsertCombo } from "./multiselect.insert.combo";
export { MultiSelectInsertNoBarCombo } from "./multiselect.insert.combo.nobar";

3
src/widget/multiselectlist/index.js

@ -0,0 +1,3 @@
export * from "./multiselectlist.insert";
export * from "./multiselectlist.insert.nobar";
export * from "./multiselectlist";

528
src/widget/multiselectlist/multiselectlist.insert.js

@ -1,59 +1,105 @@
/** import {
* Created by zcf_1 on 2017/5/2. shortcut,
*/ extend,
BI.MultiSelectInsertList = BI.inherit(BI.Single, { emptyFn,
_defaultConfig: function () { deepClone,
return BI.extend(BI.MultiSelectInsertList.superclass._defaultConfig.apply(this, arguments), { isKey,
Selection,
remove,
pushDistinct,
createWidget,
isNotEmptyString,
i18nText,
isEmptyArray,
last,
initial,
endWith,
AbsoluteLayout,
isEmptyString,
makeObject,
each,
Func,
map,
concat,
isNotNull,
values,
filter,
contains,
isNull, VerticalFillLayout
} from "@/core";
import { Single, Searcher } from "@/base";
import { MultiSelectBar } from "@/case";
import { SelectPatchEditor } from "../multiselect/trigger/editor/editor.patch";
import { MultiSelectLoader } from "../multiselect/multiselect.loader";
import { MultiSelectSearchInsertPane } from "../multiselect/search/multiselect.search.insert.pane";
import { SearchEditor } from "@/widget/editor/editor.search";
@shortcut()
export class MultiSelectInsertList extends Single {
static xtype = "bi.multi_select_insert_list";
static REQ_GET_DATA_LENGTH = "1";
static REQ_GET_ALL_DATA = "-1";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multi-select-insert-list", baseCls: "bi-multi-select-insert-list",
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
searcherHeight: BI.SIZE_CONSANTS.TRIGGER_HEIGHT, searcherHeight: BI.SIZE_CONSANTS.TRIGGER_HEIGHT,
itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
}); });
}, }
_init: function () {
BI.MultiSelectInsertList.superclass._init.apply(this, arguments);
var self = this, o = this.options; _init() {
this.storeValue = this._assertValue(BI.deepClone(o.value) || {}); super._init(...arguments);
var assertShowValue = function () { const self = this,
BI.isKey(self._startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, self._startValue) : BI.pushDistinct(self.storeValue.value, self._startValue)); o = this.options;
this.storeValue = this._assertValue(deepClone(o.value) || {});
function assertShowValue() {
isKey(self._startValue) &&
(self.storeValue.type === Selection.All
? remove(self.storeValue.value, self._startValue)
: pushDistinct(self.storeValue.value, self._startValue));
// self.trigger.setValue(self.storeValue); // self.trigger.setValue(self.storeValue);
}; }
this.adapter = BI.createWidget({ this.adapter = createWidget({
type: "bi.multi_select_loader", type: MultiSelectLoader.xtype,
cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom", cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
itemHeight: o.itemHeight, itemHeight: o.itemHeight,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemFormatter: o.itemFormatter, itemFormatter: o.itemFormatter,
logic: { logic: {
dynamic: false dynamic: false,
}, },
// onLoaded: o.onLoaded, // onLoaded: o.onLoaded,
el: {}, el: {},
isDefaultInit: true, isDefaultInit: true,
value: o.value value: o.value,
}); });
this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { this.adapter.on(MultiSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue(); self.storeValue = this.getValue();
assertShowValue(); assertShowValue();
self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); self.fireEvent(MultiSelectInsertList.EVENT_CHANGE);
}); });
this.searcherPane = BI.createWidget({ this.searcherPane = createWidget({
type: "bi.multi_select_search_insert_pane", type: MultiSelectSearchInsertPane.xtype,
cls: "bi-border-left bi-border-right bi-border-bottom", cls: "bi-border-left bi-border-right bi-border-bottom",
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemFormatter: o.itemFormatter, itemFormatter: o.itemFormatter,
keywordGetter: function () { keywordGetter() {
return self.trigger.getKeyword(); return self.trigger.getKeyword();
}, },
itemsCreator: function (op, callback) { itemsCreator(op, callback) {
var keyword = self.trigger.getKeyword(); const keyword = self.trigger.getKeyword();
if (BI.isNotEmptyString(keyword)) { if (isNotEmptyString(keyword)) {
op.keywords = [keyword]; op.keywords = [keyword];
this.setKeyword(op.keywords[0]); this.setKeyword(op.keywords[0]);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
@ -63,298 +109,338 @@ BI.MultiSelectInsertList = BI.inherit(BI.Single, {
}); });
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.searcher", type: Searcher.xtype,
el: { el: {
type: "bi.select_patch_editor", type: SelectPatchEditor.xtype,
el: { el: {
type: "bi.search_editor", type: SearchEditor.xtype,
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"), watermark: i18nText("BI-Basic_Search_And_Patch_Paste"),
}, },
ref: function (ref) { ref(ref) {
self.editor = ref; self.editor = ref;
}, },
}, },
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch(op, callback) {
callback(); callback();
}, },
adapter: this.adapter, adapter: this.adapter,
popup: this.searcherPane, popup: this.searcherPane,
masker: false, masker: false,
listeners: [{ listeners: [
eventName: BI.Searcher.EVENT_START, {
action: function () { eventName: Searcher.EVENT_START,
self._showSearcherPane(); action() {
self._setStartValue(""); self._showSearcherPane();
this.setValue(BI.deepClone(self.storeValue)); self._setStartValue("");
} this.setValue(deepClone(self.storeValue));
}, { },
eventName: BI.Searcher.EVENT_STOP, },
action: function () { {
self._showAdapter(); eventName: Searcher.EVENT_STOP,
self._setStartValue(""); action() {
self.adapter.setValue(self.storeValue);
// 需要刷新回到初始界面,否则搜索的结果不能放在最前面
self.adapter.populate();
}
}, {
eventName: BI.Searcher.EVENT_PAUSE,
action: function () {
var keywords = self._getKeywords();
if (keywords[keywords.length - 1] === BI.BlankSplitChar) {
keywords = keywords.slice(0, keywords.length - 1);
}
var keyword = BI.isEmptyArray(keywords) ? "" : keywords[keywords.length - 1];
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
if (self.storeValue.type === BI.Selection.Multi) {
BI.pushDistinct(self.storeValue.value, keyword);
}
self._showAdapter(); self._showAdapter();
self._setStartValue("");
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
self._setStartValue(keyword); // 需要刷新回到初始界面,否则搜索的结果不能放在最前面
assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); },
self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); },
}); {
self._showAdapter(); eventName: Searcher.EVENT_PAUSE,
} action() {
}, { let keywords = self._getKeywords();
eventName: BI.Searcher.EVENT_SEARCHING, if (
action: function () { keywords[keywords.length - 1] === BI.BlankSplitChar
var keywords = self._getKeywords(); ) {
var last = BI.last(keywords); keywords = keywords.slice(0, keywords.length - 1);
keywords = BI.initial(keywords || []); }
if (keywords.length > 0) { const keyword = isEmptyArray(keywords)
self._joinKeywords(keywords, function () { ? ""
if (BI.endWith(last, BI.BlankSplitChar)) { : keywords[keywords.length - 1];
self._join(
{
type: Selection.Multi,
value: [keyword],
},
() => {
if (self.storeValue.type === Selection.Multi) {
pushDistinct(
self.storeValue.value,
keyword
);
}
self._showAdapter();
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); self._setStartValue("");
} else { self.fireEvent(
self.adapter.setValue(self.storeValue); MultiSelectInsertList.EVENT_CHANGE
assertShowValue(); );
} }
self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); );
}); self._showAdapter();
self._getKeywordsLength() > 2000 && BI.Msg.alert(BI.i18nText("BI-Basic_Prompt"), BI.i18nText("BI-Basic_Too_Much_Value_Get_Two_Thousand")); },
} },
} {
}, { eventName: Searcher.EVENT_SEARCHING,
eventName: BI.Searcher.EVENT_CHANGE, action() {
action: function (value, obj) { let keywords = self._getKeywords();
if (obj instanceof BI.MultiSelectBar) { const lastKeyword = last(keywords);
self._joinAll(this.getValue(), function () { keywords = initial(keywords || []);
assertShowValue(); if (keywords.length > 0) {
self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); self._joinKeywords(keywords, () => {
}); if (endWith(lastKeyword, BI.BlankSplitChar)) {
} else { self.adapter.setValue(self.storeValue);
self._join(this.getValue(), function () { assertShowValue();
assertShowValue(); self.adapter.populate();
self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); self._setStartValue("");
}); } else {
} self.adapter.setValue(self.storeValue);
assertShowValue();
}
self.fireEvent(
MultiSelectInsertList.EVENT_CHANGE
);
});
self._getKeywordsLength() > 2000 &&
BI.Msg.alert(
i18nText("BI-Basic_Prompt"),
i18nText(
"BI-Basic_Too_Much_Value_Get_Two_Thousand"
)
);
}
},
},
{
eventName: Searcher.EVENT_CHANGE,
action(value, obj) {
if (obj instanceof MultiSelectBar) {
self._joinAll(this.getValue(), () => {
assertShowValue();
self.fireEvent(
MultiSelectInsertList.EVENT_CHANGE
);
});
} else {
self._join(this.getValue(), () => {
assertShowValue();
self.fireEvent(
MultiSelectInsertList.EVENT_CHANGE
);
});
}
},
} }
}], ],
value: o.value value: o.value,
}); });
BI.createWidget({ createWidget({
type: "bi.vertical_fill", type: VerticalFillLayout.xtype,
rowSize: ["", "fill"], rowSize: ["", "fill"],
element: this, element: this,
items: [{ items: [
el: this.trigger, {
}, { el: this.trigger,
el: this.adapter, },
}] {
el: this.adapter,
}
],
}); });
BI.createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.searcherPane, {
top: o.searcherHeight || BI.SIZE_CONSANTS.TRIGGER_HEIGHT, el: this.searcherPane,
bottom: 0, top: o.searcherHeight || BI.SIZE_CONSANTS.TRIGGER_HEIGHT,
left: 0, bottom: 0,
right: 0 left: 0,
}] right: 0,
}
],
}); });
}, }
_getKeywords: function () { _getKeywords() {
var val = this.editor.getValue(); const val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/); let keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) { if (isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1); keywords = keywords.slice(0, keywords.length - 1);
} }
if (/\u200b\s\u200b$/.test(val)) { if (/\u200b\s\u200b$/.test(val)) {
keywords = keywords.concat([BI.BlankSplitChar]); keywords = keywords.concat([BI.BlankSplitChar]);
} }
return keywords.length > 2000 ? keywords.slice(0, 2000).concat([BI.BlankSplitChar]) : keywords.slice(0, 2000); return keywords.length > 2000
}, ? keywords.slice(0, 2000).concat([BI.BlankSplitChar])
: keywords.slice(0, 2000);
}
_getKeywordsLength: function () { _getKeywordsLength() {
var val = this.editor.getValue(); const val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/); const keywords = val.split(/\u200b\s\u200b/);
return keywords.length - 1; return keywords.length - 1;
}, }
_showAdapter: function () { _showAdapter() {
this.adapter.setVisible(true); this.adapter.setVisible(true);
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
}, }
_showSearcherPane: function () { _showSearcherPane() {
this.searcherPane.setVisible(true); this.searcherPane.setVisible(true);
this.adapter.setVisible(false); this.adapter.setVisible(false);
}, }
_defaultState: function () { _defaultState() {
this.trigger.stopEditing(); this.trigger.stopEditing();
}, }
_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 = []);
return val; return val;
}, }
_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; const self = this;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
// 和复选下拉框同步,allData做缓存是会爆炸的 // 和复选下拉框同步,allData做缓存是会爆炸的
digest(); digest();
function digest() { function digest() {
BI.each(keywords, function (i, val) { each(keywords, (i, val) => {
self.storeValue.type === BI.Selection.Multi ? BI.pushDistinct(self.storeValue.value, val) : BI.remove(self.storeValue.value, val); self.storeValue.type === Selection.Multi
? pushDistinct(self.storeValue.value, val)
: remove(self.storeValue.value, val);
}); });
callback(); callback();
} }
}, }
_joinAll: function (res, callback) { _joinAll(res, callback) {
var self = this, o = this.options; const self = this,
o = this.options;
this._assertValue(res); this._assertValue(res);
if (this.storeValue.type === res.type) { if (this.storeValue.type === res.type) {
var result = BI.Func.getSearchResult(BI.map(this.storeValue.value, function (_i, v) { const result = Func.getSearchResult(
return { map(this.storeValue.value, (_i, v) => {
text: o.valueFormatter(v) || v, return {
value: v text: o.valueFormatter(v) || v,
}; value: v,
}), this.trigger.getKeyword()); };
var change = false; }),
var map = this._makeMap(this.storeValue.value); this.trigger.getKeyword()
BI.each(BI.concat(result.match, result.find), function (i, obj) { );
var v = obj.value; let change = false;
if (BI.isNotNull(map[v])) { const tempMap = this._makeMap(this.storeValue.value);
each(concat(result.match, result.find), (i, obj) => {
const v = obj.value;
if (isNotNull(tempMap[v])) {
change = true; change = true;
delete map[v]; delete tempMap[v];
} }
}); });
change && (this.storeValue.value = BI.values(map)); change && (this.storeValue.value = values(tempMap));
callback(); callback();
return; return;
} }
o.itemsCreator({ o.itemsCreator(
type: BI.MultiSelectInsertList.REQ_GET_ALL_DATA, {
keywords: [this.trigger.getKeyword()], type: MultiSelectInsertList.REQ_GET_ALL_DATA,
selectedValues: BI.filter(this.storeValue.value, function (_i, v) { keywords: [this.trigger.getKeyword()],
return !BI.contains(res.value, v); selectedValues: filter(this.storeValue.value, (_i, v) => !contains(res.value, v)),
}), },
}, function (ob) { ob => {
var items = BI.map(ob.items, "value"); const items = map(ob.items, "value");
var selectedMap = self._makeMap(self.storeValue.value); const selectedMap = self._makeMap(self.storeValue.value);
var notSelectedMap = self._makeMap(res.value); const notSelectedMap = self._makeMap(res.value);
var newItems = []; const newItems = [];
BI.each(items, function (i, item) { each(items, (i, item) => {
if (BI.isNotNull(selectedMap[items[i]])) { if (isNotNull(selectedMap[items[i]])) {
delete selectedMap[items[i]]; delete selectedMap[items[i]];
} }
if (BI.isNull(notSelectedMap[items[i]])) { if (isNull(notSelectedMap[items[i]])) {
newItems.push(item); newItems.push(item);
} }
}); });
self.storeValue.value = newItems.concat(BI.values(selectedMap)); self.storeValue.value = newItems.concat(values(selectedMap));
callback(); callback();
}); }
}, );
}
_join: function (res, callback) { _join(res, callback) {
var self = this, o = this.options; const self = this;
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]) {
BI.pushDistinct(self.storeValue.value, v); pushDistinct(self.storeValue.value, 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;
delete map[v]; delete map[v];
} }
}); });
change && (this.storeValue.value = BI.values(map)); change && (this.storeValue.value = values(map));
callback(); callback();
return; return;
} }
this._joinAll(res, callback); this._joinAll(res, callback);
}, }
_setStartValue: function (value) { _setStartValue(value) {
this._startValue = value; this._startValue = value;
this.adapter.setStartValue(value); this.adapter.setStartValue(value);
}, }
isAllSelected: function () { isAllSelected() {
return this.adapter.isAllSelected(); return this.adapter.isAllSelected();
}, }
resize: function () { resize() {
// this.trigger.getCounter().adjustView(); // this.trigger.getCounter().adjustView();
// this.trigger.adjustView(); // this.trigger.adjustView();
}, }
setValue: function (v) {
setValue(v) {
this.storeValue = v || {}; this.storeValue = v || {};
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.adapter.setValue(this.storeValue); this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue); this.trigger.setValue(this.storeValue);
},
getValue: function () {
return BI.deepClone(this.storeValue);
},
populate: function () {
this.adapter.populate.apply(this.adapter, arguments);
this.trigger.populate.apply(this.trigger, arguments);
} }
});
BI.extend(BI.MultiSelectInsertList, { getValue() {
REQ_GET_DATA_LENGTH: 1, return deepClone(this.storeValue);
REQ_GET_ALL_DATA: -1 }
});
BI.MultiSelectInsertList.EVENT_CHANGE = "EVENT_CHANGE"; populate() {
BI.shortcut("bi.multi_select_insert_list", BI.MultiSelectInsertList); this.adapter.populate(...arguments);
this.trigger.populate(...arguments);
}
}

547
src/widget/multiselectlist/multiselectlist.insert.nobar.js

@ -1,61 +1,107 @@
/** import {
* Created by zcf_1 on 2017/5/2. shortcut,
*/ extend,
BI.MultiSelectInsertNoBarList = BI.inherit(BI.Single, { emptyFn,
_defaultConfig: function () { Selection,
return BI.extend(BI.MultiSelectInsertNoBarList.superclass._defaultConfig.apply(this, arguments), { deepClone,
isKey,
remove,
pushDistinct,
createWidget,
isNotEmptyString,
i18nText,
isEmptyArray,
last,
initial,
endWith,
AbsoluteLayout,
isEmptyString,
makeObject,
each,
Func,
map,
concat,
isNotNull,
values,
filter,
contains,
isNull, VTapeLayout
} from "@/core";
import { Single, Searcher, Msg } from "@/base";
import { MultiSelectBar } from "@/case";
import { SelectPatchEditor } from "../multiselect/trigger/editor/editor.patch";
import { MultiSelectNoBarLoader } from "../multiselect/multiselect.loader.nobar";
import { MultiSelectSearchInsertPane } from "../multiselect/search/multiselect.search.insert.pane";
import { SearchEditor } from "../editor/editor.search";
@shortcut()
export class MultiSelectInsertNoBarList extends Single {
static xtype = "bi.multi_select_insert_no_bar_list";
static REQ_GET_DATA_LENGTH = "1";
static REQ_GET_ALL_DATA = "-1";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multi-select-insert-list", baseCls: "bi-multi-select-insert-list",
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
searcherHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, searcherHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
}); });
}, }
_init: function () {
BI.MultiSelectInsertNoBarList.superclass._init.apply(this, arguments);
var self = this, o = this.options; _init() {
super._init(...arguments);
const self = this,
o = this.options;
this.storeValue = { this.storeValue = {
type: BI.Selection.Multi, type: Selection.Multi,
value: BI.deepClone(o.value) || [] value: deepClone(o.value) || [],
}; };
var assertShowValue = function () { function assertShowValue() {
BI.isKey(self._startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, self._startValue) : BI.pushDistinct(self.storeValue.value, self._startValue)); isKey(self._startValue) &&
(self.storeValue.type === Selection.All
? remove(self.storeValue.value, self._startValue)
: pushDistinct(self.storeValue.value, self._startValue));
// self.trigger.setValue(self.storeValue); // self.trigger.setValue(self.storeValue);
}; }
this.adapter = BI.createWidget({ this.adapter = createWidget({
type: "bi.multi_select_no_bar_loader", type: MultiSelectNoBarLoader.xtype,
cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom", cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
itemHeight: o.itemHeight, itemHeight: o.itemHeight,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
logic: { logic: {
dynamic: false dynamic: false,
}, },
// onLoaded: o.onLoaded, // onLoaded: o.onLoaded,
el: {}, el: {},
value: { value: {
type: BI.Selection.Multi, type: Selection.Multi,
value: o.value || [] value: o.value || [],
} },
}); });
this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { this.adapter.on(MultiSelectNoBarLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue(); self.storeValue = this.getValue();
assertShowValue(); assertShowValue();
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); self.fireEvent(MultiSelectInsertNoBarList.EVENT_CHANGE);
}); });
this.searcherPane = BI.createWidget({ this.searcherPane = createWidget({
type: "bi.multi_select_search_insert_pane", type: MultiSelectSearchInsertPane.xtype,
cls: "bi-border-left bi-border-right bi-border-bottom", cls: "bi-border-left bi-border-right bi-border-bottom",
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
keywordGetter: function () { keywordGetter() {
return self.trigger.getKeyword(); return self.trigger.getKeyword();
}, },
itemsCreator: function (op, callback) { itemsCreator(op, callback) {
var keyword = self.trigger.getKeyword(); const keyword = self.trigger.getKeyword();
if (BI.isNotEmptyString(keyword)) { if (isNotEmptyString(keyword)) {
op.keywords = [keyword]; op.keywords = [keyword];
this.setKeyword(op.keywords[0]); this.setKeyword(op.keywords[0]);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
@ -64,303 +110,342 @@ BI.MultiSelectInsertNoBarList = BI.inherit(BI.Single, {
}); });
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.searcher", type: Searcher.xtype,
el: { el: {
type: "bi.select_patch_editor", type: SelectPatchEditor.xtype,
el: { el: {
type: "bi.search_editor", type: SearchEditor.xtype,
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"), watermark: i18nText("BI-Basic_Search_And_Patch_Paste"),
}, },
ref: function (ref) { ref(ref) {
self.editor = ref; self.editor = ref;
}, },
height: o.searcherHeight height: o.searcherHeight,
}, },
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch(op, callback) {
callback(); callback();
}, },
adapter: this.adapter, adapter: this.adapter,
popup: this.searcherPane, popup: this.searcherPane,
height: 200, height: 200,
masker: false, masker: false,
listeners: [{ listeners: [
eventName: BI.Searcher.EVENT_START, {
action: function () { eventName: Searcher.EVENT_START,
self._showSearcherPane(); action() {
self._setStartValue(""); self._showSearcherPane();
this.setValue(BI.deepClone(self.storeValue)); self._setStartValue("");
} this.setValue(deepClone(self.storeValue));
}, { },
eventName: BI.Searcher.EVENT_STOP, },
action: function () { {
self._showAdapter(); eventName: Searcher.EVENT_STOP,
self._setStartValue(""); action() {
self.adapter.setValue(self.storeValue);
// 需要刷新回到初始界面,否则搜索的结果不能放在最前面
self.adapter.populate();
}
}, {
eventName: BI.Searcher.EVENT_PAUSE,
action: function () {
var keywords = self._getKeywords();
if (keywords[keywords.length - 1] === BI.BlankSplitChar) {
keywords = keywords.slice(0, keywords.length - 1);
}
var keyword = BI.isEmptyArray(keywords) ? "" : keywords[keywords.length - 1];
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
if (self.storeValue.type === BI.Selection.Multi) {
BI.pushDistinct(self.storeValue.value, keyword);
}
self._showAdapter(); self._showAdapter();
self._setStartValue("");
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
self._setStartValue(keyword); // 需要刷新回到初始界面,否则搜索的结果不能放在最前面
assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); },
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); },
}); {
} eventName: Searcher.EVENT_PAUSE,
}, { action() {
eventName: BI.Searcher.EVENT_SEARCHING, let keywords = self._getKeywords();
action: function () { if (
var keywords = self._getKeywords(); keywords[keywords.length - 1] === BI.BlankSplitChar
var last = BI.last(keywords); ) {
keywords = BI.initial(keywords || []); keywords = keywords.slice(0, keywords.length - 1);
if (keywords.length > 0) { }
self._joinKeywords(keywords, function () { const keyword = isEmptyArray(keywords)
if (BI.endWith(last, BI.BlankSplitChar)) { ? ""
: keywords[keywords.length - 1];
self._join(
{
type: Selection.Multi,
value: [keyword],
},
() => {
if (self.storeValue.type === Selection.Multi) {
pushDistinct(
self.storeValue.value,
keyword
);
}
self._showAdapter();
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
self._setStartValue(""); self._setStartValue("");
} else { self.fireEvent(
self.adapter.setValue(self.storeValue); MultiSelectInsertNoBarList.EVENT_CHANGE
assertShowValue(); );
} }
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); );
}); },
self._getKeywordsLength() > 2000 && BI.Msg.alert(BI.i18nText("BI-Basic_Prompt"), BI.i18nText("BI-Basic_Too_Much_Value_Get_Two_Thousand")); },
} {
} eventName: Searcher.EVENT_SEARCHING,
}, { action() {
eventName: BI.Searcher.EVENT_CHANGE, let keywords = self._getKeywords();
action: function (value, obj) { const lastKeyword = last(keywords);
if (obj instanceof BI.MultiSelectBar) { keywords = initial(keywords || []);
self._joinAll(this.getValue(), function () { if (keywords.length > 0) {
assertShowValue(); self._joinKeywords(keywords, () => {
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); if (endWith(lastKeyword, BI.BlankSplitChar)) {
}); self.adapter.setValue(self.storeValue);
} else { assertShowValue();
self._join(this.getValue(), function () { self.adapter.populate();
assertShowValue(); self._setStartValue("");
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); } else {
}); self.adapter.setValue(self.storeValue);
} assertShowValue();
}
self.fireEvent(
MultiSelectInsertNoBarList.EVENT_CHANGE
);
});
self._getKeywordsLength() > 2000 &&
Msg.alert(
i18nText("BI-Basic_Prompt"),
i18nText(
"BI-Basic_Too_Much_Value_Get_Two_Thousand"
)
);
}
},
},
{
eventName: Searcher.EVENT_CHANGE,
action(value, obj) {
if (obj instanceof MultiSelectBar) {
self._joinAll(this.getValue(), () => {
assertShowValue();
self.fireEvent(
MultiSelectInsertNoBarList.EVENT_CHANGE
);
});
} else {
self._join(this.getValue(), () => {
assertShowValue();
self.fireEvent(
MultiSelectInsertNoBarList.EVENT_CHANGE
);
});
}
},
} }
}], ],
value: { value: {
type: BI.Selection.Multi, type: Selection.Multi,
value: o.value || [] value: o.value || [],
} },
}); });
BI.createWidget({ createWidget({
type: "bi.vtape", type: VTapeLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.trigger, {
height: o.searcherHeight el: this.trigger,
}, { height: o.searcherHeight,
el: this.adapter, },
height: "fill" {
}] el: this.adapter,
height: "fill",
}
],
}); });
BI.createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.searcherPane, {
top: o.searcherHeight, el: this.searcherPane,
bottom: 0, top: o.searcherHeight,
left: 0, bottom: 0,
right: 0 left: 0,
}] right: 0,
}
],
}); });
}, }
_getKeywords: function () { _getKeywords() {
var val = this.editor.getValue(); const val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/); let keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) { if (isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1); keywords = keywords.slice(0, keywords.length - 1);
} }
if (/\u200b\s\u200b$/.test(val)) { if (/\u200b\s\u200b$/.test(val)) {
keywords = keywords.concat([BI.BlankSplitChar]); keywords = keywords.concat([BI.BlankSplitChar]);
} }
return keywords.length > 2000 ? keywords.slice(0, 2000).concat([BI.BlankSplitChar]) : keywords.slice(0, 2000); return keywords.length > 2000
}, ? keywords.slice(0, 2000).concat([BI.BlankSplitChar])
: keywords.slice(0, 2000);
}
_getKeywordsLength: function () { _getKeywordsLength() {
var val = this.editor.getValue(); const val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/); const keywords = val.split(/\u200b\s\u200b/);
return keywords.length - 1; return keywords.length - 1;
}, }
_showAdapter: function () { _showAdapter() {
this.adapter.setVisible(true); this.adapter.setVisible(true);
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
}, }
_showSearcherPane: function () { _showSearcherPane() {
this.searcherPane.setVisible(true); this.searcherPane.setVisible(true);
this.adapter.setVisible(false); this.adapter.setVisible(false);
}, }
_defaultState: function () { _defaultState() {
this.trigger.stopEditing(); this.trigger.stopEditing();
}, }
_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 = []);
}, }
_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; const self = this;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
// 和复选下拉框同步,allData做缓存是会爆炸的 // 和复选下拉框同步,allData做缓存是会爆炸的
digest(); digest();
function digest (items) { function digest(items) {
BI.each(keywords, function (i, val) { each(keywords, (i, val) => {
self.storeValue.type === BI.Selection.Multi ? BI.pushDistinct(self.storeValue.value, val) : BI.remove(self.storeValue.value, val); self.storeValue.type === Selection.Multi
? pushDistinct(self.storeValue.value, val)
: remove(self.storeValue.value, val);
}); });
callback(); callback();
} }
}, }
_joinAll: function (res, callback) { _joinAll(res, callback) {
var self = this, o = this.options; const self = this,
o = this.options;
this._assertValue(res); this._assertValue(res);
if (this.storeValue.type === res.type) { if (this.storeValue.type === res.type) {
var result = BI.Func.getSearchResult(BI.map(this.storeValue.value, function (_i, v) { const result = Func.getSearchResult(
return { map(this.storeValue.value, (_i, v) => {
text: o.valueFormatter(v) || v, return {
value: v text: o.valueFormatter(v) || v,
}; value: v,
}), this.trigger.getKeyword()); };
var change = false; }),
var map = this._makeMap(this.storeValue.value); this.trigger.getKeyword()
BI.each(BI.concat(result.match, result.find), function (i, obj) { );
var v = obj.value; let change = false;
if (BI.isNotNull(map[v])) { const tempMap = this._makeMap(this.storeValue.value);
each(concat(result.match, result.find), (i, obj) => {
const v = obj.value;
if (isNotNull(tempMap[v])) {
change = true; change = true;
delete map[v]; delete tempMap[v];
} }
}); });
change && (this.storeValue.value = BI.values(map)); change && (this.storeValue.value = values(tempMap));
callback(); callback();
return; return;
} }
o.itemsCreator({ o.itemsCreator(
type: BI.MultiSelectInsertNoBarList.REQ_GET_ALL_DATA, {
keywords: [this.trigger.getKeyword()], type: MultiSelectInsertNoBarList.REQ_GET_ALL_DATA,
selectedValues: BI.filter(this.storeValue.value, function (_i, v) { keywords: [this.trigger.getKeyword()],
return !BI.contains(res.value, v); selectedValues: filter(this.storeValue.value, (_i, v) => !contains(res.value, v)),
}), },
}, function (ob) { ob => {
var items = BI.map(ob.items, "value"); const items = map(ob.items, "value");
var selectedMap = self._makeMap(self.storeValue.value); const selectedMap = self._makeMap(self.storeValue.value);
var notSelectedMap = self._makeMap(res.value); const notSelectedMap = self._makeMap(res.value);
var newItems = []; const newItems = [];
BI.each(items, function (i, item) { each(items, (i, item) => {
if (BI.isNotNull(selectedMap[items[i]])) { if (isNotNull(selectedMap[items[i]])) {
delete selectedMap[items[i]]; delete selectedMap[items[i]];
} }
if (BI.isNull(notSelectedMap[items[i]])) { if (isNull(notSelectedMap[items[i]])) {
newItems.push(item); newItems.push(item);
} }
}); });
self.storeValue.value = newItems.concat(BI.values(selectedMap)); self.storeValue.value = newItems.concat(values(selectedMap));
callback(); callback();
}); }
}, );
}
_join: function (res, callback) { _join(res, callback) {
var self = this, o = this.options; const self = this;
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]) {
BI.pushDistinct(self.storeValue.value, v); pushDistinct(self.storeValue.value, 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;
delete map[v]; delete map[v];
} }
}); });
change && (this.storeValue.value = BI.values(map)); change && (this.storeValue.value = values(map));
callback(); callback();
return; return;
} }
this._joinAll(res, callback); this._joinAll(res, callback);
}, }
_setStartValue: function (value) { _setStartValue(value) {
this._startValue = value; this._startValue = value;
this.adapter.setStartValue(value); this.adapter.setStartValue(value);
}, }
isAllSelected: function () { isAllSelected() {
return this.adapter.isAllSelected(); return this.adapter.isAllSelected();
}, }
resize: function () { resize() {
// this.trigger.getCounter().adjustView(); // this.trigger.getCounter().adjustView();
// this.trigger.adjustView(); // this.trigger.adjustView();
}, }
setValue: function (v) {
setValue(v) {
this.storeValue = { this.storeValue = {
type: BI.Selection.Multi, type: Selection.Multi,
value: v || [] value: v || [],
}; };
this.adapter.setValue(this.storeValue); this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue); this.trigger.setValue(this.storeValue);
},
getValue: function () {
return BI.deepClone(this.storeValue.value);
},
populate: function () {
this.adapter.populate.apply(this.adapter, arguments);
this.trigger.populate.apply(this.trigger, arguments);
} }
});
BI.extend(BI.MultiSelectInsertNoBarList, { getValue() {
REQ_GET_DATA_LENGTH: 1, return deepClone(this.storeValue.value);
REQ_GET_ALL_DATA: -1 }
});
BI.MultiSelectInsertNoBarList.EVENT_CHANGE = "EVENT_CHANGE"; populate() {
BI.shortcut("bi.multi_select_insert_no_bar_list", BI.MultiSelectInsertNoBarList); this.adapter.populate(...arguments);
this.trigger.populate(...arguments);
}
}

534
src/widget/multiselectlist/multiselectlist.js

@ -1,177 +1,233 @@
/** import {
* Created by zcf_1 on 2017/5/2. shortcut,
*/ Widget,
BI.MultiSelectList = BI.inherit(BI.Widget, { extend,
_defaultConfig: function () { emptyFn,
return BI.extend(BI.MultiSelectList.superclass._defaultConfig.apply(this, arguments), { deepClone,
isKey,
Selection,
remove,
pushDistinct,
createWidget,
isNotEmptyString,
last,
initial,
endWith,
AbsoluteLayout,
isEmptyString,
makeObject,
map,
each,
isNotNull,
Func,
concat,
values,
filter,
contains,
isNull, VTapeLayout
} from "@/core";
import { Searcher } from "@/base";
import { MultiSelectBar } from "@/case";
import { MultiSelectLoader } from "../multiselect/multiselect.loader";
import { MultiSelectSearchPane } from "../multiselect/search/multiselect.search.pane";
import { SelectPatchEditor } from "../multiselect/trigger/editor/editor.patch";
import { SearchEditor } from "../editor/editor.search";
@shortcut()
export class MultiSelectList extends Widget {
static xtype = "bi.multi_select_list";
static REQ_GET_DATA_LENGTH = "1";
static REQ_GET_ALL_DATA = "-1";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multi-select-list", baseCls: "bi-multi-select-list",
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
searcherHeight: 24, searcherHeight: 24,
itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
}); });
}, }
_init: function () {
BI.MultiSelectList.superclass._init.apply(this, arguments); _init() {
super._init(...arguments);
var self = this, o = this.options; const self = this,
this.storeValue = this._assertValue(BI.deepClone(o.value) || {}); o = this.options;
this.storeValue = this._assertValue(deepClone(o.value) || {});
var assertShowValue = function () { function assertShowValue() {
BI.isKey(self._startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, self._startValue) : BI.pushDistinct(self.storeValue.value, self._startValue)); isKey(self._startValue) &&
(self.storeValue.type === Selection.All
? remove(self.storeValue.value, self._startValue)
: pushDistinct(self.storeValue.value, self._startValue));
// self.trigger.setValue(self.storeValue); // self.trigger.setValue(self.storeValue);
}; }
this.adapter = BI.createWidget({ this.adapter = createWidget({
type: "bi.multi_select_loader", type: MultiSelectLoader.xtype,
cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom", cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemHeight: o.itemHeight, itemHeight: o.itemHeight,
logic: { logic: {
dynamic: false dynamic: false,
}, },
value: o.value, value: o.value,
isDefaultInit: true, isDefaultInit: true,
// onLoaded: o.onLoaded, // onLoaded: o.onLoaded,
el: {} el: {},
}); });
this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { this.adapter.on(MultiSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue(); self.storeValue = this.getValue();
self._adjust(function () { self._adjust(() => {
assertShowValue(); assertShowValue();
self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); self.fireEvent(MultiSelectList.EVENT_CHANGE);
}); });
}); });
this.searcherPane = BI.createWidget({ this.searcherPane = createWidget({
type: "bi.multi_select_search_pane", type: MultiSelectSearchPane.xtype,
cls: "bi-border-left bi-border-right bi-border-bottom", cls: "bi-border-left bi-border-right bi-border-bottom",
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
keywordGetter: function () { keywordGetter() {
return self.trigger.getKeyword(); return self.trigger.getKeyword();
}, },
itemsCreator: function (op, callback) { itemsCreator(op, callback) {
var keyword = self.trigger.getKeyword(); const keyword = self.trigger.getKeyword();
if (BI.isNotEmptyString(keyword)) { if (isNotEmptyString(keyword)) {
op.keywords = [keyword]; op.keywords = [keyword];
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
} }
}, },
itemHeight: o.itemHeight itemHeight: o.itemHeight,
}); });
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.searcher", type: Searcher.xtype,
el: { el: {
type: "bi.select_patch_editor", type: SelectPatchEditor.xtype,
el: { el: {
type: "bi.search_editor", type: SearchEditor.xtype,
}, },
ref: function (ref) { ref(ref) {
self.editor = ref; self.editor = ref;
}, },
height: o.searcherHeight height: o.searcherHeight,
}, },
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch(op, callback) {
callback(); callback();
}, },
adapter: this.adapter, adapter: this.adapter,
popup: this.searcherPane, popup: this.searcherPane,
height: 200, height: 200,
masker: false, masker: false,
listeners: [{ listeners: [
eventName: BI.Searcher.EVENT_START, {
action: function () { eventName: Searcher.EVENT_START,
self._showSearcherPane(); action() {
self._setStartValue(""); self._showSearcherPane();
this.setValue(BI.deepClone(self.storeValue)); self._setStartValue("");
} this.setValue(deepClone(self.storeValue));
}, { },
eventName: BI.Searcher.EVENT_STOP, },
action: function () { {
self._showAdapter(); eventName: Searcher.EVENT_STOP,
self._setStartValue(""); action() {
self.adapter.setValue(self.storeValue); self._showAdapter();
// 需要刷新回到初始界面,否则搜索的结果不能放在最前面 self._setStartValue("");
self.adapter.populate(); self.adapter.setValue(self.storeValue);
} // 需要刷新回到初始界面,否则搜索的结果不能放在最前面
}, { self.adapter.populate();
eventName: BI.Searcher.EVENT_PAUSE, },
action: function () { },
self._showAdapter(); {
self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); eventName: Searcher.EVENT_PAUSE,
action() {
self._showAdapter();
self.fireEvent(MultiSelectList.EVENT_CHANGE);
},
}, },
}, { {
eventName: BI.Searcher.EVENT_SEARCHING, eventName: Searcher.EVENT_SEARCHING,
action: function () { action() {
var keywords = this.getKeyword(); let keywords = this.getKeyword();
var last = BI.last(keywords); const lastKeyword = last(keywords);
keywords = BI.initial(keywords || []); keywords = initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, () => {
if (BI.endWith(last, BI.BlankSplitChar)) { if (endWith(lastKeyword, BI.BlankSplitChar)) {
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue();
self.adapter.populate();
self._setStartValue("");
} else {
self.adapter.setValue(self.storeValue);
assertShowValue();
}
self.fireEvent(MultiSelectList.EVENT_CHANGE);
});
}
},
},
{
eventName: Searcher.EVENT_CHANGE,
action(value, obj) {
if (obj instanceof MultiSelectBar) {
self._joinAll(this.getValue(), () => {
assertShowValue(); assertShowValue();
self.adapter.populate(); self.fireEvent(MultiSelectList.EVENT_CHANGE);
self._setStartValue(""); });
} else { } else {
self.adapter.setValue(self.storeValue); self._join(this.getValue(), () => {
assertShowValue(); assertShowValue();
} self.fireEvent(MultiSelectList.EVENT_CHANGE);
self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); });
}); }
} },
}
}, {
eventName: BI.Searcher.EVENT_CHANGE,
action: function (value, obj) {
if (obj instanceof BI.MultiSelectBar) {
self._joinAll(this.getValue(), function () {
assertShowValue();
self.fireEvent(BI.MultiSelectList.EVENT_CHANGE);
});
} else {
self._join(this.getValue(), function () {
assertShowValue();
self.fireEvent(BI.MultiSelectList.EVENT_CHANGE);
});
}
} }
}] ],
}); });
BI.createWidget({ createWidget({
type: "bi.vtape", type: VTapeLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.trigger, {
height: o.searcherHeight el: this.trigger,
}, { height: o.searcherHeight,
el: this.adapter, },
height: "fill" {
}] el: this.adapter,
height: "fill",
}
],
}); });
BI.createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.searcherPane, {
top: o.searcherHeight, el: this.searcherPane,
bottom: 0, top: o.searcherHeight,
left: 0, bottom: 0,
right: 0 left: 0,
}] right: 0,
}
],
}); });
}, }
_getKeywords: function () { _getKeywords() {
var val = this.editor.getValue(); const val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/); let keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) { if (isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1); keywords = keywords.slice(0, keywords.length - 1);
} }
if (/\u200b\s\u200b$/.test(val)) { if (/\u200b\s\u200b$/.test(val)) {
@ -179,193 +235,209 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
} }
return keywords; return keywords;
}, }
_showAdapter: function () { _showAdapter() {
this.adapter.setVisible(true); this.adapter.setVisible(true);
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
}, }
_showSearcherPane: function () { _showSearcherPane() {
this.searcherPane.setVisible(true); this.searcherPane.setVisible(true);
this.adapter.setVisible(false); this.adapter.setVisible(false);
}, }
_defaultState: function () { _defaultState() {
this.trigger.stopEditing(); this.trigger.stopEditing();
}, }
_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 = []);
return val; return val;
}, }
_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; const self = this,
o = this.options;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
// 和复选下拉框同步,allData做缓存是会爆炸的 // 和复选下拉框同步,allData做缓存是会爆炸的
o.itemsCreator({ o.itemsCreator(
type: BI.MultiSelectList.REQ_GET_ALL_DATA, {
keywords: keywords type: MultiSelectList.REQ_GET_ALL_DATA,
}, function (ob) { keywords,
var values = BI.map(ob.items, "value"); },
digest(values); ob => {
}); const values = map(ob.items, "value");
digest(values);
}
);
function digest(items) { function digest(items) {
var selectedMap = self._makeMap(items); const selectedMap = self._makeMap(items);
BI.each(keywords, function (i, val) { each(keywords, (i, val) => {
if (BI.isNotNull(selectedMap[val])) { if (isNotNull(selectedMap[val])) {
self.storeValue.type === BI.Selection.Multi ? BI.pushDistinct(self.storeValue.value, val) : BI.remove(self.storeValue.value, val); self.storeValue.type === Selection.Multi
? pushDistinct(self.storeValue.value, val)
: remove(self.storeValue.value, val);
} }
}); });
self._adjust(callback); self._adjust(callback);
} }
}, }
_joinAll: function (res, callback) { _joinAll(res, callback) {
var self = this, o = this.options; const self = this,
o = this.options;
this._assertValue(res); this._assertValue(res);
if (this.storeValue.type === res.type) { if (this.storeValue.type === res.type) {
var result = BI.Func.getSearchResult(BI.map(this.storeValue.value, function (_i, v) { const result = Func.getSearchResult(
return { map(this.storeValue.value, (_i, v) => {
text: o.valueFormatter(v) || v, return {
value: v text: o.valueFormatter(v) || v,
}; value: v,
}), this.trigger.getKeyword()); };
var change = false; }),
var map = this._makeMap(this.storeValue.value); this.trigger.getKeyword()
BI.each(BI.concat(result.match, result.find), function (i, obj) { );
var v = obj.value; let change = false;
if (BI.isNotNull(map[v])) { const tempMap = this._makeMap(this.storeValue.value);
each(concat(result.match, result.find), (i, obj) => {
const v = obj.value;
if (isNotNull(tempMap[v])) {
change = true; change = true;
delete map[v]; delete tempMap[v];
} }
}); });
change && (this.storeValue.value = BI.values(map)); change && (this.storeValue.value = values(tempMap));
this._adjust(callback); this._adjust(callback);
return; return;
} }
o.itemsCreator({ o.itemsCreator(
type: BI.MultiSelectList.REQ_GET_ALL_DATA, {
keywords: [this.trigger.getKeyword()], type: MultiSelectList.REQ_GET_ALL_DATA,
selectedValues: BI.filter(this.storeValue.value, function (_i, v) { keywords: [this.trigger.getKeyword()],
return !BI.contains(res.value, v); selectedValues: filter(this.storeValue.value, (_i, v) => !contains(res.value, v)),
}), },
}, function (ob) { ob => {
var items = BI.map(ob.items, "value"); const items = map(ob.items, "value");
var selectedMap = self._makeMap(self.storeValue.value); const selectedMap = self._makeMap(self.storeValue.value);
var notSelectedMap = self._makeMap(res.value); const notSelectedMap = self._makeMap(res.value);
var newItems = []; const newItems = [];
BI.each(items, function (i, item) { each(items, (i, item) => {
if (BI.isNotNull(selectedMap[items[i]])) { if (isNotNull(selectedMap[items[i]])) {
delete selectedMap[items[i]]; delete selectedMap[items[i]];
} }
if (BI.isNull(notSelectedMap[items[i]])) { if (isNull(notSelectedMap[items[i]])) {
newItems.push(item); newItems.push(item);
} }
}); });
self.storeValue.value = newItems.concat(BI.values(selectedMap)); self.storeValue.value = newItems.concat(values(selectedMap));
self._adjust(callback); self._adjust(callback);
}); }
}, );
}
_adjust: function (callback) { _adjust(callback) {
var self = this, o = this.options; const self = this,
o = this.options;
if (!this._count) { if (!this._count) {
o.itemsCreator({ o.itemsCreator(
type: BI.MultiSelectList.REQ_GET_DATA_LENGTH {
}, function (res) { type: MultiSelectList.REQ_GET_DATA_LENGTH,
self._count = res.count; },
adjust(); res => {
callback(); self._count = res.count;
}); adjust();
callback();
}
);
} else { } else {
adjust(); adjust();
callback(); callback();
} }
function adjust() { function adjust() {
if (self.storeValue.type === BI.Selection.All && self.storeValue.value.length >= self._count) { if (
self.storeValue.type === Selection.All &&
self.storeValue.value.length >= self._count
) {
self.storeValue = { self.storeValue = {
type: BI.Selection.Multi, type: Selection.Multi,
value: [] value: [],
}; };
} else if (self.storeValue.type === BI.Selection.Multi && self.storeValue.value.length >= self._count) { } else if (
self.storeValue.type === Selection.Multi &&
self.storeValue.value.length >= self._count
) {
self.storeValue = { self.storeValue = {
type: BI.Selection.All, type: Selection.All,
value: [] value: [],
}; };
} }
} }
}, }
_join: function (res, callback) { _join(res, callback) {
var self = this, o = this.options; const self = this;
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]) {
BI.pushDistinct(self.storeValue.value, v); pushDistinct(self.storeValue.value, 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;
delete map[v]; delete map[v];
} }
}); });
change && (this.storeValue.value = BI.values(map)); change && (this.storeValue.value = values(map));
self._adjust(callback); self._adjust(callback);
return; return;
} }
this._joinAll(res, callback); this._joinAll(res, callback);
}, }
_setStartValue: function (value) { _setStartValue(value) {
this._startValue = value; this._startValue = value;
this.adapter.setStartValue(value); this.adapter.setStartValue(value);
}, }
isAllSelected: function () { isAllSelected() {
return this.adapter.isAllSelected(); return this.adapter.isAllSelected();
}, }
resize: function () { resize() {
// this.trigger.getCounter().adjustView();
// this.trigger.adjustView(); }
},
setValue: function (v) { setValue(v) {
this.storeValue = v || {}; this.storeValue = v || {};
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.adapter.setValue(this.storeValue); this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue); this.trigger.setValue(this.storeValue);
},
getValue: function () {
return BI.deepClone(this.storeValue);
},
populate: function () {
this.adapter.populate.apply(this.adapter, arguments);
this.trigger.populate.apply(this.trigger, arguments);
} }
});
BI.extend(BI.MultiSelectList, { getValue() {
REQ_GET_DATA_LENGTH: 1, return deepClone(this.storeValue);
REQ_GET_ALL_DATA: -1 }
});
BI.MultiSelectList.EVENT_CHANGE = "EVENT_CHANGE"; populate() {
BI.shortcut("bi.multi_select_list", BI.MultiSelectList); this.adapter.populate(...arguments);
this.trigger.populate(...arguments);
}
}

Loading…
Cancel
Save