Browse Source

Pull request #1931: BI-87205 feat: fineui搜索功能支持搜索空格

Merge in VISUAL/fineui from ~WINDY/fui:master to master

* commit '1344d9febc79b46c81f2f443c72bea45c3e53ff4':
  水印提示文本
  searcher的pause
  BI-87205 feat: fineui搜索功能支持搜索空格
es6
windy 3 years ago
parent
commit
4e72bb2310
  1. 1
      changelog.md
  2. 2
      demo/js/widget/singleselct/demo.single_select_combo.js
  3. 3
      i18n/i18n.cn.js
  4. 11
      src/base/combination/searcher.js
  5. 51
      src/base/single/editor/editor.textarea.js
  6. 5
      src/case/editor/editor.state.js
  7. 3
      src/core/constant/var.js
  8. 2
      src/widget/editor/editor.search.js
  9. 18
      src/widget/multiselect/multiselect.combo.js
  10. 9
      src/widget/multiselect/multiselect.combo.nobar.js
  11. 31
      src/widget/multiselect/multiselect.insert.combo.js
  12. 31
      src/widget/multiselect/multiselect.insert.combo.nobar.js
  13. 4
      src/widget/multiselect/multiselect.insert.trigger.js
  14. 49
      src/widget/multiselect/search/multiselect.search.insert.pane.js
  15. 48
      src/widget/multiselect/search/multiselect.search.pane.js
  16. 34
      src/widget/multiselect/trigger/editor.multiselect.js
  17. 199
      src/widget/multiselect/trigger/editor/editor.patch.js
  18. 21
      src/widget/multiselect/trigger/searcher.multiselect.insert.js
  19. 6
      src/widget/multiselect/trigger/searcher.multiselect.js
  20. 59
      src/widget/multiselectlist/multiselectlist.insert.js
  21. 56
      src/widget/multiselectlist/multiselectlist.insert.nobar.js
  22. 39
      src/widget/multiselectlist/multiselectlist.js
  23. 18
      src/widget/searchmultitextvaluecombo/multitextvalue.combo.search.js
  24. 2
      src/widget/searchmultitextvaluecombo/trigger/searcher.multitextvalue.js
  25. 20
      src/widget/singleselect/search/singleselect.search.pane.insert.js
  26. 14
      src/widget/singleselect/search/singleselect.search.pane.js
  27. 27
      src/widget/singleselect/singleselect.combo.js
  28. 64
      src/widget/singleselect/singleselect.insert.combo.js
  29. 1
      src/widget/singleselect/singleselect.trigger.js
  30. 77
      src/widget/singleselect/singleselectlist.insert.js
  31. 40
      src/widget/singleselect/trigger/editor.singleselect.js
  32. 6
      src/widget/singleselect/trigger/searcher.singleselect.js
  33. 1
      typescript/core/var.ts

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志 # 更新日志
2.0(2021-05) 2.0(2021-05)
- 支持搜索的控件支持搜索包含空格的字符串
- 解决了树列表populate调用两次itemsCreator的问题 - 解决了树列表populate调用两次itemsCreator的问题
2.0(2021-03) 2.0(2021-03)

2
demo/js/widget/singleselct/demo.single_select_combo.js

@ -9,7 +9,7 @@ Demo.SingleSelectCombo = BI.inherit(BI.Widget, {
_createSingleSelectCombo: function () { _createSingleSelectCombo: function () {
var self = this; var self = this;
var widget = BI.createWidget({ var widget = BI.createWidget({
type: "bi.single_select_insert_combo", type: "bi.single_select_combo",
itemsCreator: BI.bind(this._itemsCreator, this), itemsCreator: BI.bind(this._itemsCreator, this),
width: 200, width: 200,
ref: function () { ref: function () {

3
i18n/i18n.cn.js

@ -166,7 +166,7 @@ BI.i18n = {
"BI-More_Than": "大于", "BI-More_Than": "大于",
"BI-More_And_Equal": "大于等于", "BI-More_And_Equal": "大于等于",
"BI-Please_Enter_SQL": "请输入SQL", "BI-Please_Enter_SQL": "请输入SQL",
"BI-Basic_Click_To_Add_Text": "+点击新增\"{R1}\"", "BI-Basic_Click_To_Add_Text": "点按回车键添加\"{R1}\"",
"BI-Basic_Please_Select": "请选择", "BI-Basic_Please_Select": "请选择",
"BI-Basic_Font_Color": "文字颜色", "BI-Basic_Font_Color": "文字颜色",
"BI-Basic_Background_Color": "背景色", "BI-Basic_Background_Color": "背景色",
@ -195,4 +195,5 @@ BI.i18n = {
"BI-Basic_Year_Range_Error": "请选择{R1}年-{R2}年的日期", "BI-Basic_Year_Range_Error": "请选择{R1}年-{R2}年的日期",
"BI-Basic_Year_Month_Range_Error": "请选择{R1}年{R2}月-{R3}年{R4}月的日期", "BI-Basic_Year_Month_Range_Error": "请选择{R1}年{R2}月-{R3}年{R4}月的日期",
"BI-Basic_Year_Quarter_Range_Error": "请选择{R1}年{R2}季度-{R3}年{R4}季度的日期", "BI-Basic_Year_Quarter_Range_Error": "请选择{R1}年{R2}季度-{R3}年{R4}季度的日期",
"BI-Basic_Search_And_Patch_Paste": "搜索,支持批量粘贴、粘贴值通过换行识别"
}; };

11
src/base/combination/searcher.js

@ -21,7 +21,6 @@ BI.Searcher = BI.inherit(BI.Widget, {
isAutoSearch: true, // 是否自动搜索 isAutoSearch: true, // 是否自动搜索
isAutoSync: true, // 是否自动同步数据, 即是否保持搜索面板和adapter面板状态值的统一 isAutoSync: true, // 是否自动同步数据, 即是否保持搜索面板和adapter面板状态值的统一
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
allowSearchBlank: true, // 是否能够搜索包含空格的字符串
// isAutoSearch为false时启用 // isAutoSearch为false时启用
onSearch: function (op, callback) { onSearch: function (op, callback) {
@ -80,8 +79,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
search(); search();
break; break;
case BI.Events.PAUSE: case BI.Events.PAUSE:
// 可以搜索空格的情况下输入空格不做处理, 展示上一次的结果 if (BI.endWith(this.getValue(), BI.BlankSplitChar)) {
if (!o.allowSearchBlank) {
self._pauseSearch(); self._pauseSearch();
} }
break; break;
@ -167,7 +165,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
}, },
_search: function () { _search: function () {
var self = this, o = this.options, keyword = o.allowSearchBlank ? this.editor.getValue() : this._getLastSearchKeyword(); var self = this, o = this.options, keyword = this.editor.getValue();
if (keyword === "" || this._stop) { if (keyword === "" || this._stop) {
return; return;
} }
@ -202,7 +200,10 @@ BI.Searcher = BI.inherit(BI.Widget, {
_getLastSearchKeyword: function () { _getLastSearchKeyword: function () {
if (this.isValid()) { if (this.isValid()) {
var res = this.editor.getValue().match(/[\S]+/g); var res = this.editor.getValue().split(/\u200b\s\u200b/);
if (BI.isEmptyString(res[res.length - 1])) {
res = res.slice(0, res.length - 1);
}
return BI.isNull(res) ? "" : res[res.length - 1]; return BI.isNull(res) ? "" : res[res.length - 1];
} }
}, },

51
src/base/single/editor/editor.textarea.js

@ -16,6 +16,7 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
validationChecker: function () { validationChecker: function () {
return true; return true;
}, },
scrolly: true,
}); });
}, },
@ -26,7 +27,10 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
tagName: "textarea", tagName: "textarea",
width: "100%", width: "100%",
height: "100%", height: "100%",
cls: "bi-textarea textarea-editor-content display-block" cls: "bi-textarea textarea-editor-content display-block",
css: o.scrolly ? null : {
overflowY: "hidden",
},
}); });
this.content.element.css({ resize: "none" }); this.content.element.css({ resize: "none" });
BI.createWidget({ BI.createWidget({
@ -47,7 +51,11 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
this.content.element.on("input propertychange", function (e) { this.content.element.on("input propertychange", function (e) {
self._checkError(); self._checkError();
self._checkWaterMark(); self._checkWaterMark();
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CHANGE, self.getValue(), self);
self.fireEvent(BI.TextAreaEditor.EVENT_CHANGE); self.fireEvent(BI.TextAreaEditor.EVENT_CHANGE);
if (BI.isEmptyString(self.getValue())) {
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, self.getValue(), self);
}
}); });
this.content.element.focus(function () { this.content.element.focus(function () {
@ -64,9 +72,19 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
this.content.element.blur(function () { this.content.element.blur(function () {
self._setErrorVisible(false); self._setErrorVisible(false);
self._blur(); self._blur();
if (!self._isError()) {
self.fireEvent(BI.TextAreaEditor.EVENT_CONFIRM);
}
self.fireEvent(BI.TextAreaEditor.EVENT_BLUR); self.fireEvent(BI.TextAreaEditor.EVENT_BLUR);
BI.Widget._renderEngine.createElement(document).unbind("mousedown." + self.getName()); BI.Widget._renderEngine.createElement(document).unbind("mousedown." + self.getName());
}); });
this.content.element.keydown(function () {
// 水印快速消失
self.watermark && self.watermark.setVisible(false);
});
this.content.element.click(function (e) {
e.stopPropagation();
});
if (BI.isKey(o.value)) { if (BI.isKey(o.value)) {
this.setValue(o.value); this.setValue(o.value);
} }
@ -89,12 +107,13 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
type: "bi.label", type: "bi.label",
cls: "bi-water-mark textarea-watermark", cls: "bi-water-mark textarea-watermark",
textAlign: "left", textAlign: "left",
whiteSpace: "normal", whiteSpace: o.scrolly ? "normal" : "nowrap",
title: o.watermark,
text: o.watermark, text: o.watermark,
invalid: o.invalid, invalid: o.invalid,
disabled: o.disabled, disabled: o.disabled,
hgap: 4, hgap: 6,
vgap: 4 vgap: o.height > 24 ? 4 : 2,
}); });
this.watermark.element.bind({ this.watermark.element.bind({
mousedown: function (e) { mousedown: function (e) {
@ -104,7 +123,10 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
self.blur(); self.blur();
} }
e.stopEvent(); e.stopEvent();
} },
click: function (e) {
e.stopPropagation();
},
}); });
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
@ -125,13 +147,20 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
} }
}, },
_isError: function () {
return this.isEnabled() && !this.options.validationChecker(this.getValue());
},
_checkError: function () { _checkError: function () {
this._setErrorVisible(this.isEnabled() && !this.options.validationChecker(this.getValue())); this._setErrorVisible(this._isError());
}, },
_focus: function () { _focus: function () {
this.content.element.addClass("textarea-editor-focus"); this.content.element.addClass("textarea-editor-focus");
this._checkWaterMark(); this._checkWaterMark();
if (BI.isEmptyString(this.getValue())) {
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this);
}
}, },
_blur: function () { _blur: function () {
@ -155,6 +184,13 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
} }
}, },
_defaultState: function () {
if (BI.isEmptyString(this.getValue())) {
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this);
this.fireEvent(BI.TextAreaEditor.EVENT_EMPTY);
}
},
focus: function () { focus: function () {
this._focus(); this._focus();
this.content.element.focus(); this.content.element.focus();
@ -173,6 +209,7 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
this.content.element.val(value); this.content.element.val(value);
this._checkError(); this._checkError();
this._checkWaterMark(); this._checkWaterMark();
this._defaultState();
}, },
setStyle: function (style) { setStyle: function (style) {
@ -206,4 +243,6 @@ BI.TextAreaEditor = BI.inherit(BI.Single, {
BI.TextAreaEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.TextAreaEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.TextAreaEditor.EVENT_BLUR = "EVENT_BLUR"; BI.TextAreaEditor.EVENT_BLUR = "EVENT_BLUR";
BI.TextAreaEditor.EVENT_FOCUS = "EVENT_FOCUS"; BI.TextAreaEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.TextAreaEditor.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.TextAreaEditor.EVENT_EMPTY = "EVENT_EMPTY";
BI.shortcut("bi.textarea_editor", BI.TextAreaEditor); BI.shortcut("bi.textarea_editor", BI.TextAreaEditor);

5
src/case/editor/editor.state.js

@ -22,14 +22,15 @@ BI.StateEditor = BI.inherit(BI.Widget, {
errorText: "", errorText: "",
height: 24, height: 24,
defaultText: "", // 默认显示值,默认显示值与显示值的区别是默认显示值标记灰色 defaultText: "", // 默认显示值,默认显示值与显示值的区别是默认显示值标记灰色
text: BI.i18nText("BI-Basic_Unrestricted") // 显示值 text: BI.i18nText("BI-Basic_Unrestricted"), // 显示值
el: {}
}); });
}, },
_init: function () { _init: function () {
BI.StateEditor.superclass._init.apply(this, arguments); BI.StateEditor.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.editor = BI.createWidget({ this.editor = BI.createWidget(o.el, {
type: "bi.editor", type: "bi.editor",
height: o.height, height: o.height,
hgap: o.hgap, hgap: o.hgap,

3
src/core/constant/var.js

@ -135,5 +135,6 @@ _.extend(BI, {
Bottom: "bottom", Bottom: "bottom",
Stretch: "stretch" Stretch: "stretch"
}, },
StartOfWeek: 1 StartOfWeek: 1,
BlankSplitChar: "\u200b \u200b",
}); });

2
src/widget/editor/editor.search.js

@ -17,7 +17,7 @@ BI.SearchEditor = BI.inherit(BI.Widget, {
this.options.height -= 2; this.options.height -= 2;
BI.SearchEditor.superclass._init.apply(this, arguments); BI.SearchEditor.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.editor = BI.createWidget({ this.editor = BI.createWidget(o.el, {
type: "bi.editor", type: "bi.editor",
height: o.height, height: o.height,
watermark: o.watermark, watermark: o.watermark,

18
src/widget/multiselect/multiselect.combo.js

@ -76,28 +76,12 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, {
self._setStartValue(""); self._setStartValue("");
self.fireEvent(BI.MultiSelectCombo.EVENT_STOP); self.fireEvent(BI.MultiSelectCombo.EVENT_STOP);
}); });
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) {
var keyword = this.getSearcher().getMatchedItemValue();
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self.combo.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
self._setStartValue("");
self._dataChange = true;
});
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords); var last = BI.last(keywords);
keywords = BI.initial(keywords || []); keywords = BI.initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.endWith(last, BI.BlankSplitChar)) {
self.combo.setValue(self.storeValue); self.combo.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.combo.populate(); self.combo.populate();

9
src/widget/multiselect/multiselect.combo.nobar.js

@ -76,18 +76,13 @@ BI.MultiSelectNoBarCombo = BI.inherit(BI.Single, {
self._setStartValue(""); self._setStartValue("");
self.fireEvent(BI.MultiSelectNoBarCombo.EVENT_STOP); self.fireEvent(BI.MultiSelectNoBarCombo.EVENT_STOP);
}); });
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) {
self._addItem(assertShowValue, true);
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords); var last = BI.last(keywords);
keywords = BI.initial(keywords || []); keywords = BI.initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.endWith(last, BI.BlankSplitChar)) {
self.combo.setValue(self.storeValue); self.combo.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.combo.populate(); self.combo.populate();
@ -292,7 +287,7 @@ BI.MultiSelectNoBarCombo = BI.inherit(BI.Single, {
_addItem: function (assertShowValue, matched) { _addItem: function (assertShowValue, matched) {
var self = this; var self = this;
var keyword = matched ? this.trigger.getSearcher().getMatchedItemValue() : this.trigger.getSearcher().getKeyword(); var keyword = this.trigger.getSearcher().getKeyword();
this._join({ this._join({
type: BI.Selection.Multi, type: BI.Selection.Multi,
value: [keyword] value: [keyword]

31
src/widget/multiselect/multiselect.insert.combo.js

@ -74,24 +74,14 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, {
self.fireEvent(BI.MultiSelectInsertCombo.EVENT_STOP); self.fireEvent(BI.MultiSelectInsertCombo.EVENT_STOP);
}); });
this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_PAUSE, function () { this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) {
self._addItem(assertShowValue, true); self._addItem(assertShowValue, true);
}
});
this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_ADD_ITEM, function () {
if (!this.getSearcher().hasMatched()) {
self._addItem(assertShowValue);
var addedValue = this.getSearcher().getKeyword();
self._stopEditing();
self.fireEvent(BI.MultiSelectInsertCombo.EVENT_ADD_ITEM, addedValue);
}
}); });
this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_SEARCHING, function (keywords) { this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords); var last = BI.last(keywords);
keywords = BI.initial(keywords || []); keywords = BI.initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.endWith(last, BI.BlankSplitChar)) {
self.combo.setValue(self.storeValue); self.combo.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.combo.populate(); self.combo.populate();
@ -300,9 +290,9 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, {
}); });
}, },
_addItem: function (assertShowValue, matched) { _addItem: function (assertShowValue) {
var self = this; var self = this;
var keyword = matched ? this.trigger.getSearcher().getMatchedItemValue() : this.trigger.getSearcher().getKeyword(); var keyword = this.trigger.getSearcher().getKeyword();
this._join({ this._join({
type: BI.Selection.Multi, type: BI.Selection.Multi,
value: [keyword] value: [keyword]
@ -344,20 +334,12 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, {
var self = this, o = this.options; var self = this, o = this.options;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.requesting = true; this.requesting = true;
o.itemsCreator({
type: BI.MultiSelectInsertCombo.REQ_GET_ALL_DATA,
keywords: keywords
}, function (ob) {
var values = BI.map(ob.items, "value");
digest(values);
});
function digest (items) { digest();
var selectedMap = self._makeMap(items);
function digest () {
BI.each(keywords, function (i, val) { 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.storeValue.type === BI.Selection.Multi ? BI.pushDistinct(self.storeValue.value, val) : BI.remove(self.storeValue.value, val);
}
}); });
self._adjust(callback); self._adjust(callback);
} }
@ -491,6 +473,5 @@ BI.MultiSelectInsertCombo.EVENT_STOP = "EVENT_STOP";
BI.MultiSelectInsertCombo.EVENT_SEARCHING = "EVENT_SEARCHING"; BI.MultiSelectInsertCombo.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.MultiSelectInsertCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM"; BI.MultiSelectInsertCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
BI.MultiSelectInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; BI.MultiSelectInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.MultiSelectInsertCombo.EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
BI.shortcut("bi.multi_select_insert_combo", BI.MultiSelectInsertCombo); BI.shortcut("bi.multi_select_insert_combo", BI.MultiSelectInsertCombo);

31
src/widget/multiselect/multiselect.insert.combo.nobar.js

@ -69,24 +69,14 @@ BI.MultiSelectInsertNoBarCombo = BI.inherit(BI.Single, {
self._setStartValue(""); self._setStartValue("");
}); });
this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_PAUSE, function () { this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) {
self._addItem(assertShowValue, true); self._addItem(assertShowValue, true);
}
});
this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_ADD_ITEM, function () {
if (!this.getSearcher().hasMatched()) {
self._addItem(assertShowValue);
var addedValue = this.getSearcher().getKeyword();
self._stopEditing();
self.fireEvent(BI.MultiSelectInsertNoBarCombo.EVENT_ADD_ITEM, addedValue);
}
}); });
this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_SEARCHING, function (keywords) { this.trigger.on(BI.MultiSelectInsertTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords); var last = BI.last(keywords);
keywords = BI.initial(keywords || []); keywords = BI.initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.endWith(last, BI.BlankSplitChar)) {
self.combo.setValue(self.storeValue); self.combo.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.combo.populate(); self.combo.populate();
@ -298,9 +288,9 @@ BI.MultiSelectInsertNoBarCombo = BI.inherit(BI.Single, {
}); });
}, },
_addItem: function (assertShowValue, matched) { _addItem: function (assertShowValue) {
var self = this; var self = this;
var keyword = matched ? this.trigger.getSearcher().getMatchedItemValue() : this.trigger.getSearcher().getKeyword(); var keyword = this.trigger.getSearcher().getKeyword();
this._join({ this._join({
type: BI.Selection.Multi, type: BI.Selection.Multi,
value: [keyword] value: [keyword]
@ -342,20 +332,12 @@ BI.MultiSelectInsertNoBarCombo = BI.inherit(BI.Single, {
var self = this, o = this.options; var self = this, o = this.options;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.requesting = true; this.requesting = true;
o.itemsCreator({
type: BI.MultiSelectInsertNoBarCombo.REQ_GET_ALL_DATA,
keywords: keywords
}, function (ob) {
var values = BI.map(ob.items, "value");
digest(values);
});
function digest (items) { digest();
var selectedMap = self._makeMap(items);
function digest () {
BI.each(keywords, function (i, val) { 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.storeValue.type === BI.Selection.Multi ? BI.pushDistinct(self.storeValue.value, val) : BI.remove(self.storeValue.value, val);
}
}); });
self._adjust(callback); self._adjust(callback);
} }
@ -485,6 +467,5 @@ BI.extend(BI.MultiSelectInsertNoBarCombo, {
}); });
BI.MultiSelectInsertNoBarCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; BI.MultiSelectInsertNoBarCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.MultiSelectInsertNoBarCombo.EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
BI.shortcut("bi.multi_select_insert_no_bar_combo", BI.MultiSelectInsertNoBarCombo); BI.shortcut("bi.multi_select_insert_no_bar_combo", BI.MultiSelectInsertNoBarCombo);

4
src/widget/multiselect/multiselect.insert.trigger.js

@ -49,9 +49,6 @@ BI.MultiSelectInsertTrigger = BI.inherit(BI.Trigger, {
this.searcher.on(BI.MultiSelectInsertSearcher.EVENT_START, function () { this.searcher.on(BI.MultiSelectInsertSearcher.EVENT_START, function () {
self.fireEvent(BI.MultiSelectInsertTrigger.EVENT_START); self.fireEvent(BI.MultiSelectInsertTrigger.EVENT_START);
}); });
this.searcher.on(BI.MultiSelectInsertSearcher.EVENT_ADD_ITEM, function () {
self.fireEvent(BI.MultiSelectInsertTrigger.EVENT_ADD_ITEM);
});
this.searcher.on(BI.MultiSelectInsertSearcher.EVENT_PAUSE, function () { this.searcher.on(BI.MultiSelectInsertSearcher.EVENT_PAUSE, function () {
self.fireEvent(BI.MultiSelectInsertTrigger.EVENT_PAUSE); self.fireEvent(BI.MultiSelectInsertTrigger.EVENT_PAUSE);
}); });
@ -150,7 +147,6 @@ BI.MultiSelectInsertTrigger.EVENT_STOP = "EVENT_STOP";
BI.MultiSelectInsertTrigger.EVENT_PAUSE = "EVENT_PAUSE"; BI.MultiSelectInsertTrigger.EVENT_PAUSE = "EVENT_PAUSE";
BI.MultiSelectInsertTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; BI.MultiSelectInsertTrigger.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.MultiSelectInsertTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; BI.MultiSelectInsertTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW";
BI.MultiSelectInsertTrigger.EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
BI.MultiSelectInsertTrigger.EVENT_FOCUS = "EVENT_FOCUS"; BI.MultiSelectInsertTrigger.EVENT_FOCUS = "EVENT_FOCUS";
BI.MultiSelectInsertTrigger.EVENT_BLUR = "EVENT_BLUR"; BI.MultiSelectInsertTrigger.EVENT_BLUR = "EVENT_BLUR";

49
src/widget/multiselect/search/multiselect.search.insert.pane.js

@ -27,24 +27,12 @@ BI.MultiSelectSearchInsertPane = BI.inherit(BI.Widget, {
BI.MultiSelectSearchInsertPane.superclass._init.apply(this, arguments); BI.MultiSelectSearchInsertPane.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.tooltipClick = BI.createWidget({
type: "bi.label",
invisible: true,
text: BI.i18nText("BI-Click_Blank_To_Select"),
cls: "multi-select-toolbar",
height: this.constants.height
});
this.addNotMatchTip = BI.createWidget({ this.addNotMatchTip = BI.createWidget({
type: "bi.text_button", type: "bi.label",
invisible: true,
text: BI.i18nText("BI-Basic_Click_To_Add_Text", ""), text: BI.i18nText("BI-Basic_Click_To_Add_Text", ""),
height: this.constants.height, height: this.constants.height,
cls: "bi-high-light", cls: "bi-high-light",
hgap: 5, hgap: 5,
handler: function () {
self.fireEvent(BI.MultiSelectSearchInsertPane.EVENT_ADD_ITEM, o.keywordGetter());
}
}); });
this.loader = BI.createWidget({ this.loader = BI.createWidget({
@ -68,38 +56,16 @@ BI.MultiSelectSearchInsertPane = BI.inherit(BI.Widget, {
type: "bi.vtape", type: "bi.vtape",
element: this, element: this,
items: [{ items: [{
type: "bi.vertical", el: this.addNotMatchTip,
items: [this.tooltipClick, this.addNotMatchTip], height: this.constants.height,
height: this.constants.height
}, { }, {
el: this.loader el: this.loader,
}] }],
}); });
}, },
setKeyword: function (keyword) { setKeyword: function (keyword) {
var o = this.options; this.addNotMatchTip.setText(BI.i18nText("BI-Basic_Click_To_Add_Text", keyword));
var hasSameValue = BI.some(this.loader.getAllButtons(), function (idx, btn) {
return keyword === (o.valueFormatter(btn.getValue()) || btn.getValue());
});
var isMatchTipVisible = this.loader.getAllButtons().length > 0 && hasSameValue;
this.tooltipClick.setVisible(isMatchTipVisible);
this.addNotMatchTip.setVisible(!isMatchTipVisible);
!isMatchTipVisible && this.addNotMatchTip.setText(BI.i18nText("BI-Basic_Click_To_Add_Text", keyword));
},
getMatchedItemValue: function () {
var value;
var o = this.options;
BI.some(this.loader.getAllButtons(), function (idx, btn) {
var v = btn.getValue();
if (o.keywordGetter() === (o.valueFormatter(v) || v)) {
value = v;
return true;
}
});
return value;
}, },
isAllSelected: function () { isAllSelected: function () {
@ -107,7 +73,7 @@ BI.MultiSelectSearchInsertPane = BI.inherit(BI.Widget, {
}, },
hasMatched: function () { hasMatched: function () {
return this.tooltipClick.isVisible(); return false;
}, },
setValue: function (v) { setValue: function (v) {
@ -128,6 +94,5 @@ BI.MultiSelectSearchInsertPane = BI.inherit(BI.Widget, {
}); });
BI.MultiSelectSearchInsertPane.EVENT_CHANGE = "EVENT_CHANGE"; BI.MultiSelectSearchInsertPane.EVENT_CHANGE = "EVENT_CHANGE";
BI.MultiSelectSearchInsertPane.EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
BI.shortcut("bi.multi_select_search_insert_pane", BI.MultiSelectSearchInsertPane); BI.shortcut("bi.multi_select_search_insert_pane", BI.MultiSelectSearchInsertPane);

48
src/widget/multiselect/search/multiselect.search.pane.js

@ -27,14 +27,6 @@ BI.MultiSelectSearchPane = BI.inherit(BI.Widget, {
BI.MultiSelectSearchPane.superclass._init.apply(this, arguments); BI.MultiSelectSearchPane.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.tooltipClick = BI.createWidget({
type: "bi.label",
invisible: true,
text: BI.i18nText("BI-Click_Blank_To_Select"),
cls: "multi-select-toolbar",
height: this.constants.height
});
this.loader = BI.createWidget({ this.loader = BI.createWidget({
type: "bi.multi_select_search_loader", type: "bi.multi_select_search_loader",
keywordGetter: o.keywordGetter, keywordGetter: o.keywordGetter,
@ -42,7 +34,6 @@ BI.MultiSelectSearchPane = BI.inherit(BI.Widget, {
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
o.itemsCreator.apply(self, [op, function (res) { o.itemsCreator.apply(self, [op, function (res) {
callback(res); callback(res);
self.setKeyword(o.keywordGetter());
}]); }]);
}, },
itemHeight: o.itemHeight, itemHeight: o.itemHeight,
@ -53,40 +44,16 @@ BI.MultiSelectSearchPane = BI.inherit(BI.Widget, {
}); });
this.resizer = BI.createWidget({ this.resizer = BI.createWidget({
type: "bi.vtape", type: "bi.absolute",
element: this, element: this,
items: [{ items: [{
el: this.tooltipClick, el: this.loader,
height: 0 left: 0,
}, { right: 0,
el: this.loader bottom: 0,
}] top: 0,
}); }],
this.tooltipClick.setVisible(false);
},
setKeyword: function (keyword) {
var btn, o = this.options;
var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === (o.valueFormatter(btn.getValue()) || btn.getValue()));
if (isVisible !== this.tooltipClick.isVisible()) {
this.tooltipClick.setVisible(isVisible);
this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0);
this.resizer.resize();
}
},
getMatchedItemValue: function () {
var value;
var o = this.options;
BI.some(this.loader.getAllButtons(), function (idx, btn) {
var v = btn.getValue();
if (o.keywordGetter() === (o.valueFormatter(v) || v)) {
value = v;
return true;
}
}); });
return value;
}, },
isAllSelected: function () { isAllSelected: function () {
@ -94,7 +61,6 @@ BI.MultiSelectSearchPane = BI.inherit(BI.Widget, {
}, },
hasMatched: function () { hasMatched: function () {
return this.tooltipClick.isVisible();
}, },
setValue: function (v) { setValue: function (v) {

34
src/widget/multiselect/trigger/editor.multiselect.js

@ -18,7 +18,7 @@ BI.MultiSelectEditor = BI.inherit(BI.Widget, {
BI.MultiSelectEditor.superclass._init.apply(this, arguments); BI.MultiSelectEditor.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.editor = BI.createWidget(o.el, { this.editor = BI.createWidget(o.el, {
type: "bi.state_editor", type: "bi.select_patch_editor",
element: this, element: this,
height: o.height, height: o.height,
watermark: o.watermark, watermark: o.watermark,
@ -33,10 +33,6 @@ BI.MultiSelectEditor = BI.inherit(BI.Widget, {
this.editor.on(BI.Controller.EVENT_CHANGE, function () { this.editor.on(BI.Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
}); });
this.editor.on(BI.StateEditor.EVENT_PAUSE, function () {
self.fireEvent(BI.MultiSelectEditor.EVENT_PAUSE);
});
this.editor.on(BI.StateEditor.EVENT_FOCUS, function () { this.editor.on(BI.StateEditor.EVENT_FOCUS, function () {
self.fireEvent(BI.MultiSelectEditor.EVENT_FOCUS); self.fireEvent(BI.MultiSelectEditor.EVENT_FOCUS);
}); });
@ -66,12 +62,7 @@ BI.MultiSelectEditor = BI.inherit(BI.Widget, {
}, },
getValue: function () { getValue: function () {
var v = this.editor.getState(); return this.editor.getValue();
if (BI.isArray(v) && v.length > 0) {
return v[v.length - 1];
}
return "";
}, },
getState: function () { getState: function () {
@ -79,14 +70,27 @@ BI.MultiSelectEditor = BI.inherit(BI.Widget, {
}, },
getKeywords: function () { getKeywords: function () {
var val = this.editor.getLastChangedValue(); var val = this.editor.getValue();
var keywords = val.match(/[\S]+/g); var keywords = val.split(/\u200b\s\u200b/);
if (BI.isEndWithBlank(val)) { if (BI.isEmptyString(keywords[keywords.length - 1])) {
return keywords.concat([" "]); keywords = keywords.slice(0, keywords.length - 1);
}
if (/\u200b\s\u200b$/.test(val)) {
return keywords.concat([BI.BlankSplitChar]);
} }
return keywords; return keywords;
}, },
getKeyword: function () {
var val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1);
}
return BI.isEmptyArray(keywords) ? "" : keywords[keywords.length - 1];
},
populate: function (items) { populate: function (items) {
} }

199
src/widget/multiselect/trigger/editor/editor.patch.js

@ -0,0 +1,199 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2021/5/18
*/
BI.SelectPatchEditor = BI.inherit(BI.Widget, {
props: {
baseCls: "bi-patch-select-editor",
height: 24,
},
render: function () {
var self = this, o = this.options;
var debounceInputChange = BI.debounce(BI.bind(this._dealChange, this), 300);
return BI.extend({
type: "bi.state_editor",
ref: function (_ref) {
self.editor = _ref;
},
hgap: o.hgap,
vgap: o.vgap,
lgap: o.lgap,
rgap: o.rgap,
tgap: o.tgap,
bgap: o.bgap,
height: o.height,
watermark: o.watermark,
allowBlank: true,
value: o.value,
defaultText: o.text,
text: o.text,
tipType: o.tipType,
warningTitle: o.warningTitle,
el: {
type: 'bi.textarea_editor',
scrolly: false,
validationChecker: function () {
return true;
},
throttle: true,
},
listeners: [{
eventName: BI.Controller.EVENT_CHANGE,
action: function (type, v) {
if (BI.contains(v, "\n")) {
self._dealChange(type, v);
} else {
debounceInputChange(type, v);
}
},
}, {
eventName: BI.Editor.EVENT_FOCUS,
action: function () {
self.fireEvent(BI.SelectPatchEditor.EVENT_FOCUS, arguments);
},
}, {
eventName: BI.Editor.EVENT_BLUR,
action: function () {
self.fireEvent(BI.SelectPatchEditor.EVENT_BLUR, arguments);
},
}],
}, o.el);
},
_dealChange: function (type, v) {
var value = "";
if (BI.isKey(v)) {
value = this._formatText(v);
}
if (type === BI.Events.CHANGE) {
this._setValue(value);
if (this._trimValue(value) !== "") {
if (!this._start || !BI.isKey(this._lastValue) || (this._pause === true && !/\u200b\s\u200b$/.test(this.getValue()))) {
this._start = true;
this._pause = false;
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.STARTEDIT, this.getValue(), this);
}
}
if (this._trimValue(this._lastValue) !== this._trimValue(value)) {
this.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
}
if (BI.endWith(value, BI.BlankSplitChar)) {
this._pause = true;
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.PAUSE, "", this);
}
}
if (type === BI.Events.EMPTY || type === BI.Events.STOPEDIT) {
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY);
}
this._lastValue = value;
},
_trimValue: function (v) {
return BI.trim(BI.replaceAll(v || "", BI.BlankSplitChar, ""));
},
_formatText: function (v) {
return BI.replaceAll(v || "", "\n", BI.BlankSplitChar);
},
setWaterMark: function (v) {
this.editor.setWaterMark(v);
},
doRedMark: function () {
this.editor.doRedMark.apply(this.editor, arguments);
},
unRedMark: function () {
this.editor.unRedMark.apply(this.editor, arguments);
},
doHighLight: function () {
this.editor.doHighLight.apply(this.editor, arguments);
},
unHighLight: function () {
this.text.unHighLight.apply(this.text, arguments);
},
focus: function () {
this.editor.focus();
},
blur: function () {
this.editor.blur();
},
_setValue: function (v) {
this.editor.setValue(this._formatText(v));
},
_showInput: function () {
this.editor.visible();
this.text.invisible();
},
_showHint: function () {
this.editor.invisible();
this.text.visible();
},
isValid: function () {
return this.editor.isValid();
},
setErrorText: function (text) {
this.editor.setErrorText(text);
},
getErrorText: function () {
return this.editor.getErrorText();
},
isEditing: function () {
return this.editor.isEditing();
},
getLastValidValue: function () {
return this.editor.getLastValidValue();
},
getLastChangedValue: function () {
return this.editor.getLastChangedValue();
},
setValue: function (v) {
this._setValue(v);
this._lastValue = this._trimValue(v);
},
getValue: function () {
return BI.trim(this.editor.getValue());
},
getState: function () {
return this.editor.getState();
},
setState: function (v) {
this.editor.setState(v);
},
setTipType: function (v) {
this.editor.setTipType(v);
},
getText: function () {
return this.editor.getText();
},
});
BI.SelectPatchEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.SelectPatchEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.SelectPatchEditor.EVENT_BLUR = "EVENT_BLUR";
BI.shortcut("bi.select_patch_editor", BI.SelectPatchEditor);

21
src/widget/multiselect/trigger/searcher.multiselect.insert.js

@ -16,7 +16,8 @@ BI.MultiSelectInsertSearcher = BI.inherit(BI.Widget, {
valueFormatter: BI.emptyFn, valueFormatter: BI.emptyFn,
adapter: null, adapter: null,
masker: {}, masker: {},
text: BI.i18nText("BI-Basic_Please_Select") text: BI.i18nText("BI-Basic_Please_Select"),
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"),
}); });
}, },
@ -43,7 +44,6 @@ BI.MultiSelectInsertSearcher = BI.inherit(BI.Widget, {
this.searcher = BI.createWidget({ this.searcher = BI.createWidget({
type: "bi.searcher", type: "bi.searcher",
allowSearchBlank: false,
element: this, element: this,
height: o.height, height: o.height,
isAutoSearch: false, isAutoSearch: false,
@ -57,22 +57,16 @@ BI.MultiSelectInsertSearcher = BI.inherit(BI.Widget, {
type: "bi.multi_select_search_insert_pane", type: "bi.multi_select_search_insert_pane",
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
keywordGetter: function () { keywordGetter: function () {
return self.editor.getValue(); return self.editor.getKeyword();
}, },
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
var keyword = self.editor.getValue(); var keyword = self.editor.getKeyword();
op.keywords = [keyword]; op.keywords = [keyword];
this.setKeyword(keyword); this.setKeyword(keyword);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
}, },
itemHeight: o.itemHeight, itemHeight: o.itemHeight,
value: o.value, value: o.value,
listeners: [{
eventName: BI.MultiSelectSearchInsertPane.EVENT_ADD_ITEM,
action: function () {
self.fireEvent(BI.MultiSelectInsertSearcher.EVENT_ADD_ITEM);
}
}]
}, o.popup), }, o.popup),
adapter: o.adapter, adapter: o.adapter,
@ -115,7 +109,7 @@ BI.MultiSelectInsertSearcher = BI.inherit(BI.Widget, {
}, },
getKeyword: function () { getKeyword: function () {
return this.editor.getValue(); return this.editor.getKeyword();
}, },
hasMatched: function () { hasMatched: function () {
@ -169,10 +163,6 @@ BI.MultiSelectInsertSearcher = BI.inherit(BI.Widget, {
} }
}, },
getMatchedItemValue: function() {
return this.searcher.getView().getMatchedItemValue();
},
getState: function() { getState: function() {
return this.editor.getState(); return this.editor.getState();
}, },
@ -201,7 +191,6 @@ BI.MultiSelectInsertSearcher.EVENT_START = "EVENT_START";
BI.MultiSelectInsertSearcher.EVENT_STOP = "EVENT_STOP"; BI.MultiSelectInsertSearcher.EVENT_STOP = "EVENT_STOP";
BI.MultiSelectInsertSearcher.EVENT_PAUSE = "EVENT_PAUSE"; BI.MultiSelectInsertSearcher.EVENT_PAUSE = "EVENT_PAUSE";
BI.MultiSelectInsertSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; BI.MultiSelectInsertSearcher.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.MultiSelectInsertSearcher.EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
BI.MultiSelectInsertSearcher.EVENT_FOCUS = "EVENT_FOCUS"; BI.MultiSelectInsertSearcher.EVENT_FOCUS = "EVENT_FOCUS";
BI.MultiSelectInsertSearcher.EVENT_BLUR = "EVENT_BLUR"; BI.MultiSelectInsertSearcher.EVENT_BLUR = "EVENT_BLUR";
BI.shortcut("bi.multi_select_insert_searcher", BI.MultiSelectInsertSearcher); BI.shortcut("bi.multi_select_insert_searcher", BI.MultiSelectInsertSearcher);

6
src/widget/multiselect/trigger/searcher.multiselect.js

@ -43,7 +43,6 @@ BI.MultiSelectSearcher = BI.inherit(BI.Widget, {
this.searcher = BI.createWidget({ this.searcher = BI.createWidget({
type: "bi.searcher", type: "bi.searcher",
allowSearchBlank: false,
element: this, element: this,
height: o.height, height: o.height,
isAutoSearch: false, isAutoSearch: false,
@ -62,7 +61,6 @@ BI.MultiSelectSearcher = BI.inherit(BI.Widget, {
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
var keyword = self.editor.getValue(); var keyword = self.editor.getValue();
op.keywords = [keyword]; op.keywords = [keyword];
this.setKeyword(keyword);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
}, },
itemHeight: o.itemHeight, itemHeight: o.itemHeight,
@ -96,10 +94,6 @@ BI.MultiSelectSearcher = BI.inherit(BI.Widget, {
} }
}, },
getMatchedItemValue: function() {
return this.searcher.getView().getMatchedItemValue();
},
adjustView: function () { adjustView: function () {
this.searcher.adjustView(); this.searcher.adjustView();
}, },

59
src/widget/multiselectlist/multiselectlist.insert.js

@ -57,32 +57,22 @@ BI.MultiSelectInsertList = BI.inherit(BI.Single, {
} }
}, },
itemHeight: o.itemHeight, itemHeight: o.itemHeight,
listeners: [{
eventName: BI.MultiSelectSearchInsertPane.EVENT_ADD_ITEM,
action: function () {
var keyword = self.trigger.getKeyword();
if (!self.trigger.hasMatched()) {
if (self.storeValue.type === BI.Selection.Multi) {
BI.pushDistinct(self.storeValue.value, keyword);
}
self._showAdapter();
self.adapter.setValue(self.storeValue);
self.adapter.populate();
if (self.storeValue.type === BI.Selection.Multi) {
self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE);
}
}
}
}]
}); });
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
this.trigger = BI.createWidget({ this.trigger = BI.createWidget({
type: "bi.searcher", type: "bi.searcher",
el: { el: {
type: "bi.select_patch_editor",
el: {
type: "bi.search_editor",
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"),
},
ref: function (ref) {
self.editor = ref;
},
height: o.searcherHeight, height: o.searcherHeight,
}, },
allowSearchBlank: false,
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch: function (op, callback) {
@ -112,7 +102,6 @@ BI.MultiSelectInsertList = BI.inherit(BI.Single, {
eventName: BI.Searcher.EVENT_PAUSE, eventName: BI.Searcher.EVENT_PAUSE,
action: function () { action: function () {
var keyword = this.getKeyword(); var keyword = this.getKeyword();
if (this.hasMatched()) {
self._join({ self._join({
type: BI.Selection.Multi, type: BI.Selection.Multi,
value: [keyword] value: [keyword]
@ -128,18 +117,17 @@ BI.MultiSelectInsertList = BI.inherit(BI.Single, {
self._setStartValue(""); self._setStartValue("");
self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE);
}); });
}
self._showAdapter(); self._showAdapter();
} }
}, { }, {
eventName: BI.Searcher.EVENT_SEARCHING, eventName: BI.Searcher.EVENT_SEARCHING,
action: function () { action: function () {
var keywords = this.getKeywords(); var keywords = self._getKeywords();
var last = BI.last(keywords); var last = BI.last(keywords);
keywords = BI.initial(keywords || []); keywords = BI.initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.endWith(last, BI.BlankSplitChar)) {
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
@ -195,6 +183,19 @@ BI.MultiSelectInsertList = BI.inherit(BI.Single, {
}); });
}, },
_getKeywords: function () {
var val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1);
}
if (/\u200b\s\u200b$/.test(val)) {
return keywords.concat([BI.BlankSplitChar]);
}
return keywords;
},
_showAdapter: function () { _showAdapter: function () {
this.adapter.setVisible(true); this.adapter.setVisible(true);
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
@ -224,20 +225,12 @@ BI.MultiSelectInsertList = BI.inherit(BI.Single, {
var self = this, o = this.options; var self = this, o = this.options;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
// 和复选下拉框同步,allData做缓存是会爆炸的 // 和复选下拉框同步,allData做缓存是会爆炸的
o.itemsCreator({
type: BI.MultiSelectInsertList.REQ_GET_ALL_DATA,
keywords: keywords
}, function (ob) {
var values = BI.map(ob.items, "value");
digest(values);
});
function digest (items) { digest();
var selectedMap = self._makeMap(items);
function digest () {
BI.each(keywords, function (i, val) { 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.storeValue.type === BI.Selection.Multi ? BI.pushDistinct(self.storeValue.value, val) : BI.remove(self.storeValue.value, val);
}
}); });
callback(); callback();
} }

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

@ -61,32 +61,22 @@ BI.MultiSelectInsertNoBarList = BI.inherit(BI.Single, {
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
} }
}, },
listeners: [{
eventName: BI.MultiSelectSearchInsertPane.EVENT_ADD_ITEM,
action: function () {
var keyword = self.trigger.getKeyword();
if (!self.trigger.hasMatched()) {
if (self.storeValue.type === BI.Selection.Multi) {
BI.pushDistinct(self.storeValue.value, keyword);
}
self._showAdapter();
self.adapter.setValue(self.storeValue);
self.adapter.populate();
if (self.storeValue.type === BI.Selection.Multi) {
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE);
}
}
}
}]
}); });
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
this.trigger = BI.createWidget({ this.trigger = BI.createWidget({
type: "bi.searcher", type: "bi.searcher",
el: { el: {
type: "bi.select_patch_editor",
el: {
type: "bi.search_editor",
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"),
},
ref: function (ref) {
self.editor = ref;
},
height: o.searcherHeight height: o.searcherHeight
}, },
allowSearchBlank: false,
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch: function (op, callback) {
@ -116,7 +106,6 @@ BI.MultiSelectInsertNoBarList = BI.inherit(BI.Single, {
eventName: BI.Searcher.EVENT_PAUSE, eventName: BI.Searcher.EVENT_PAUSE,
action: function () { action: function () {
var keyword = this.getKeyword(); var keyword = this.getKeyword();
if (this.hasMatched()) {
self._join({ self._join({
type: BI.Selection.Multi, type: BI.Selection.Multi,
value: [keyword] value: [keyword]
@ -133,16 +122,15 @@ BI.MultiSelectInsertNoBarList = BI.inherit(BI.Single, {
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE);
}); });
} }
}
}, { }, {
eventName: BI.Searcher.EVENT_SEARCHING, eventName: BI.Searcher.EVENT_SEARCHING,
action: function () { action: function () {
var keywords = this.getKeywords(); var keywords = self._getKeywords();
var last = BI.last(keywords); var last = BI.last(keywords);
keywords = BI.initial(keywords || []); keywords = BI.initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.endWith(last, BI.BlankSplitChar)) {
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
@ -201,6 +189,19 @@ BI.MultiSelectInsertNoBarList = BI.inherit(BI.Single, {
}); });
}, },
_getKeywords: function () {
var val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1);
}
if (/\u200b\s\u200b$/.test(val)) {
return keywords.concat([BI.BlankSplitChar]);
}
return keywords;
},
_showAdapter: function () { _showAdapter: function () {
this.adapter.setVisible(true); this.adapter.setVisible(true);
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
@ -229,20 +230,11 @@ BI.MultiSelectInsertNoBarList = BI.inherit(BI.Single, {
var self = this, o = this.options; var self = this, o = this.options;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
// 和复选下拉框同步,allData做缓存是会爆炸的 // 和复选下拉框同步,allData做缓存是会爆炸的
o.itemsCreator({ digest();
type: BI.MultiSelectInsertNoBarList.REQ_GET_ALL_DATA,
keywords: keywords
}, function (ob) {
var values = BI.map(ob.items, "value");
digest(values);
});
function digest (items) { function digest (items) {
var selectedMap = self._makeMap(items);
BI.each(keywords, function (i, val) { 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.storeValue.type === BI.Selection.Multi ? BI.pushDistinct(self.storeValue.value, val) : BI.remove(self.storeValue.value, val);
}
}); });
callback(); callback();
} }

39
src/widget/multiselectlist/multiselectlist.js

@ -53,7 +53,6 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
var keyword = self.trigger.getKeyword(); var keyword = self.trigger.getKeyword();
if (BI.isNotEmptyString(keyword)) { if (BI.isNotEmptyString(keyword)) {
op.keywords = [keyword]; op.keywords = [keyword];
this.setKeyword(op.keywords[0]);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
} }
}, },
@ -64,9 +63,15 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
this.trigger = BI.createWidget({ this.trigger = BI.createWidget({
type: "bi.searcher", type: "bi.searcher",
el: { el: {
type: "bi.select_patch_editor",
el: {
type: "bi.search_editor",
},
ref: function (ref) {
self.editor = ref;
},
height: o.searcherHeight height: o.searcherHeight
}, },
allowSearchBlank: false,
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch: function (op, callback) {
@ -95,22 +100,9 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
}, { }, {
eventName: BI.Searcher.EVENT_PAUSE, eventName: BI.Searcher.EVENT_PAUSE,
action: function () { action: function () {
var keyword = this.getKeyword();
if (this.hasMatched()) {
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self._showAdapter(); self._showAdapter();
self.adapter.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.adapter.populate();
self._setStartValue("");
self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); self.fireEvent(BI.MultiSelectList.EVENT_CHANGE);
}); },
}
}
}, { }, {
eventName: BI.Searcher.EVENT_SEARCHING, eventName: BI.Searcher.EVENT_SEARCHING,
action: function () { action: function () {
@ -119,7 +111,7 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
keywords = BI.initial(keywords || []); keywords = BI.initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.endWith(last, BI.BlankSplitChar)) {
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.adapter.populate(); self.adapter.populate();
@ -174,6 +166,19 @@ BI.MultiSelectList = BI.inherit(BI.Widget, {
}); });
}, },
_getKeywords: function () {
var val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1);
}
if (/\u200b\s\u200b$/.test(val)) {
return keywords.concat([BI.BlankSplitChar]);
}
return keywords;
},
_showAdapter: function () { _showAdapter: function () {
this.adapter.setVisible(true); this.adapter.setVisible(true);
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);

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

@ -69,28 +69,12 @@ BI.SearchMultiTextValueCombo = BI.inherit(BI.Single, {
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () {
self._setStartValue(""); self._setStartValue("");
}); });
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) {
var keyword = this.getSearcher().getKeyword();
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self.combo.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self._populate();
self._setStartValue("");
self._dataChange = true;
});
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords); var last = BI.last(keywords);
keywords = BI.initial(keywords || []); keywords = BI.initial(keywords || []);
if (keywords.length > 0) { if (keywords.length > 0) {
self._joinKeywords(keywords, function () { self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) { if (BI.endWith(last, BI.BlankSplitChar)) {
self.combo.setValue(self.storeValue); self.combo.setValue(self.storeValue);
assertShowValue(); assertShowValue();
self.combo.populate(); self.combo.populate();

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

@ -25,7 +25,6 @@ BI.SearchMultiSelectSearcher = BI.inherit(BI.Widget, {
this.searcher = BI.createWidget({ this.searcher = BI.createWidget({
type: "bi.searcher", type: "bi.searcher",
allowSearchBlank: false,
element: this, element: this,
height: o.height, height: o.height,
isAutoSearch: false, isAutoSearch: false,
@ -44,7 +43,6 @@ BI.SearchMultiSelectSearcher = BI.inherit(BI.Widget, {
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
var keyword = self.editor.getValue(); var keyword = self.editor.getValue();
op.keywords = [keyword]; op.keywords = [keyword];
this.setKeyword(keyword);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
}, },
value: o.value value: o.value

20
src/widget/singleselect/search/singleselect.search.pane.insert.js

@ -36,15 +36,12 @@ BI.SingleSelectSearchInsertPane = BI.inherit(BI.Widget, {
}); });
this.addNotMatchTip = BI.createWidget({ this.addNotMatchTip = BI.createWidget({
type: "bi.text_button", type: "bi.label",
invisible: true, invisible: true,
text: BI.i18nText("BI-Basic_Click_To_Add_Text", ""), text: BI.i18nText("BI-Basic_Click_To_Add_Text", ""),
height: this.constants.height, height: this.constants.height,
cls: "bi-high-light", cls: "bi-high-light",
hgap: 5, hgap: 5,
handler: function () {
self.fireEvent(BI.SingleSelectSearchInsertPane.EVENT_ADD_ITEM, o.keywordGetter());
}
}); });
this.loader = BI.createWidget({ this.loader = BI.createWidget({
@ -88,20 +85,6 @@ BI.SingleSelectSearchInsertPane = BI.inherit(BI.Widget, {
!isMatchTipVisible && this.addNotMatchTip.setText(BI.i18nText("BI-Basic_Click_To_Add_Text", keyword)); !isMatchTipVisible && this.addNotMatchTip.setText(BI.i18nText("BI-Basic_Click_To_Add_Text", keyword));
}, },
getMatchedItemValue: function () {
var value;
var o = this.options;
BI.some(this.loader.getAllButtons(), function (idx, btn) {
var v = btn.getValue();
if (o.keywordGetter() === (o.valueFormatter(v) || v)) {
value = v;
return true;
}
});
return value;
},
hasMatched: function () { hasMatched: function () {
return this.tooltipClick.isVisible(); return this.tooltipClick.isVisible();
}, },
@ -124,6 +107,5 @@ BI.SingleSelectSearchInsertPane = BI.inherit(BI.Widget, {
}); });
BI.SingleSelectSearchInsertPane.EVENT_CHANGE = "EVENT_CHANGE"; BI.SingleSelectSearchInsertPane.EVENT_CHANGE = "EVENT_CHANGE";
BI.SingleSelectSearchInsertPane.EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
BI.shortcut("bi.single_select_search_insert_pane", BI.SingleSelectSearchInsertPane); BI.shortcut("bi.single_select_search_insert_pane", BI.SingleSelectSearchInsertPane);

14
src/widget/singleselect/search/singleselect.search.pane.js

@ -75,20 +75,6 @@ BI.SingleSelectSearchPane = BI.inherit(BI.Widget, {
} }
}, },
getMatchedItemValue: function () {
var value;
var o = this.options;
BI.some(this.loader.getAllButtons(), function (idx, btn) {
var v = btn.getValue();
if (o.keywordGetter() === (o.valueFormatter(v) || v)) {
value = v;
return true;
}
});
return value;
},
hasMatched: function () { hasMatched: function () {
return this.tooltipClick.isVisible(); return this.tooltipClick.isVisible();
}, },

27
src/widget/singleselect/singleselect.combo.js

@ -63,32 +63,7 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, {
self._setStartValue(); self._setStartValue();
self.fireEvent(BI.SingleSelectCombo.EVENT_STOP); self.fireEvent(BI.SingleSelectCombo.EVENT_STOP);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function () {
if (this.getSearcher().hasMatched()) {
var keyword = this.getSearcher().getMatchedItemValue();
self.combo.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
self._setStartValue();
}
});
this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.combo.setValue(self.storeValue);
assertShowValue();
self.combo.populate();
self._setStartValue();
} else {
self.combo.setValue(self.storeValue);
assertShowValue();
}
});
}
self.fireEvent(BI.SingleSelectCombo.EVENT_SEARCHING); self.fireEvent(BI.SingleSelectCombo.EVENT_SEARCHING);
}); });

64
src/widget/singleselect/singleselect.insert.combo.js

@ -12,7 +12,8 @@ BI.SingleSelectInsertCombo = BI.inherit(BI.Single, {
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: BI.emptyFn,
height: 24, height: 24,
allowEdit: true allowEdit: true,
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"),
}); });
}, },
@ -29,6 +30,7 @@ BI.SingleSelectInsertCombo = BI.inherit(BI.Single, {
this.trigger = BI.createWidget({ this.trigger = BI.createWidget({
type: "bi.single_select_trigger", type: "bi.single_select_trigger",
watermark: o.watermark,
height: o.height - 2, height: o.height - 2,
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
allowEdit: o.allowEdit, allowEdit: o.allowEdit,
@ -48,16 +50,6 @@ BI.SingleSelectInsertCombo = BI.inherit(BI.Single, {
searcher: { searcher: {
popup: { popup: {
type: "bi.single_select_search_insert_pane", type: "bi.single_select_search_insert_pane",
listeners: [{
eventName: BI.SingleSelectSearchInsertPane.EVENT_ADD_ITEM,
action: function () {
if (!self.trigger.getSearcher().hasMatched()) {
self.storeValue = self.trigger.getSearcher().getKeyword();
assertShowValue();
self._defaultState();
}
}
}]
} }
} }
}); });
@ -78,32 +70,11 @@ BI.SingleSelectInsertCombo = BI.inherit(BI.Single, {
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_STOP); self.fireEvent(BI.SingleSelectInsertCombo.EVENT_STOP);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) { self.storeValue = self.trigger.getSearcher().getKeyword();
var keyword = this.getSearcher().getMatchedItemValue();
self.storeValue = keyword;
self.combo.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
self._setStartValue();
}
});
this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.combo.setValue(self.storeValue);
assertShowValue();
self.combo.populate();
self._setStartValue();
} else {
self.combo.setValue(self.storeValue);
assertShowValue(); assertShowValue();
} self._defaultState();
}); });
} this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function () {
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_SEARCHING); self.fireEvent(BI.SingleSelectInsertCombo.EVENT_SEARCHING);
}); });
@ -220,29 +191,6 @@ BI.SingleSelectInsertCombo = BI.inherit(BI.Single, {
return BI.makeObject(values || []); return BI.makeObject(values || []);
}, },
_joinKeywords: function (keywords, callback) {
var self = this, o = this.options;
this._assertValue(this.storeValue);
this.requesting = true;
o.itemsCreator({
type: BI.SingleSelectInsertCombo.REQ_GET_ALL_DATA,
keywords: keywords
}, function (ob) {
var values = BI.map(ob.items, "value");
digest(values);
});
function digest (items) {
var selectedMap = self._makeMap(items);
BI.each(keywords, function (i, val) {
if (BI.isNotNull(selectedMap[val])) {
BI.remove(self.storeValue.value, val);
}
});
self._adjust(callback);
}
},
_adjust: function (callback) { _adjust: function (callback) {
var self = this, o = this.options; var self = this, o = this.options;
adjust(); adjust();

1
src/widget/singleselect/singleselect.trigger.js

@ -35,6 +35,7 @@ BI.SingleSelectTrigger = BI.inherit(BI.Trigger, {
this.searcher = BI.createWidget(o.searcher, { this.searcher = BI.createWidget(o.searcher, {
type: "bi.single_select_searcher", type: "bi.single_select_searcher",
watermark: o.watermark,
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
text: o.text, text: o.text,
height: o.height, height: o.height,

77
src/widget/singleselect/singleselectlist.insert.js

@ -9,7 +9,8 @@ BI.SingleSelectInsertList = BI.inherit(BI.Single, {
baseCls: "bi-multi-select-insert-list", baseCls: "bi-multi-select-insert-list",
allowNoSelect: false, allowNoSelect: false,
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
valueFormatter: BI.emptyFn valueFormatter: BI.emptyFn,
searcherHeight: 24,
}); });
}, },
_init: function () { _init: function () {
@ -55,25 +56,22 @@ BI.SingleSelectInsertList = BI.inherit(BI.Single, {
this.setKeyword(op.keywords[0]); this.setKeyword(op.keywords[0]);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
}, },
listeners: [{
eventName: BI.SingleSelectSearchInsertPane.EVENT_ADD_ITEM,
action: function () {
var keyword = self.trigger.getKeyword();
if (!self.trigger.hasMatched()) {
self.storeValue = keyword;
self._showAdapter();
self.adapter.setValue(self.storeValue);
self.adapter.populate();
self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE);
}
}
}]
}); });
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
this.trigger = BI.createWidget({ this.trigger = BI.createWidget({
type: "bi.searcher", type: "bi.searcher",
allowSearchBlank: false, el: {
type: "bi.select_patch_editor",
el: {
type: "bi.search_editor",
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"),
},
ref: function (ref) {
self.editor = ref;
},
height: o.searcherHeight,
},
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch: function (op, callback) {
@ -104,7 +102,6 @@ BI.SingleSelectInsertList = BI.inherit(BI.Single, {
eventName: BI.Searcher.EVENT_PAUSE, eventName: BI.Searcher.EVENT_PAUSE,
action: function () { action: function () {
var keyword = this.getKeyword(); var keyword = this.getKeyword();
if (this.hasMatched()) {
self.storeValue = keyword; self.storeValue = keyword;
self._showAdapter(); self._showAdapter();
self.adapter.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
@ -113,31 +110,8 @@ BI.SingleSelectInsertList = BI.inherit(BI.Single, {
self.adapter.populate(); self.adapter.populate();
self._setStartValue(); self._setStartValue();
self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE); self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE);
} else {
self._showAdapter();
}
} }
}, {
eventName: BI.Searcher.EVENT_SEARCHING,
action: function () {
var keywords = this.getKeyword();
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.adapter.setValue(self.storeValue);
assertShowValue();
self.adapter.populate();
self._setStartValue();
} else {
self.adapter.setValue(self.storeValue);
assertShowValue();
}
});
}
}
}, { }, {
eventName: BI.Searcher.EVENT_CHANGE, eventName: BI.Searcher.EVENT_CHANGE,
action: function () { action: function () {
@ -191,31 +165,6 @@ BI.SingleSelectInsertList = BI.inherit(BI.Single, {
return BI.makeObject(values || []); return BI.makeObject(values || []);
}, },
_joinKeywords: function (keywords, callback) {
var self = this, o = this.options;
this._assertValue(this.storeValue);
if (!this._allData) {
o.itemsCreator({
type: BI.SingleSelectInsertList.REQ_GET_ALL_DATA
}, function (ob) {
self._allData = BI.map(ob.items, "value");
digest(self._allData);
});
} else {
digest(this._allData);
}
function digest (items) {
var selectedMap = self._makeMap(items);
BI.each(keywords, function (i, val) {
if (BI.isNotNull(selectedMap[val])) {
BI.pushDistinct(self.storeValue.value, val)
}
});
callback();
}
},
_setStartValue: function (value) { _setStartValue: function (value) {
this._startValue = value; this._startValue = value;
this.adapter.setStartValue(value); this.adapter.setStartValue(value);

40
src/widget/singleselect/trigger/editor.singleselect.js

@ -10,7 +10,8 @@ BI.SingleSelectEditor = BI.inherit(BI.Widget, {
return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-single-select-editor", baseCls: "bi-single-select-editor",
el: {}, el: {},
text: BI.i18nText("BI-Basic_Please_Select") text: BI.i18nText("BI-Basic_Please_Select"),
watermark: BI.i18nText("BI-Basic_Search"),
}); });
}, },
@ -18,10 +19,10 @@ BI.SingleSelectEditor = BI.inherit(BI.Widget, {
BI.SingleSelectEditor.superclass._init.apply(this, arguments); BI.SingleSelectEditor.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.editor = BI.createWidget(o.el, { this.editor = BI.createWidget(o.el, {
type: "bi.state_editor", type: "bi.select_patch_editor",
element: this, element: this,
height: o.height, height: o.height,
watermark: BI.i18nText("BI-Basic_Search"), watermark: o.watermark,
allowBlank: true, allowBlank: true,
value: o.value, value: o.value,
defaultText: o.text, defaultText: o.text,
@ -31,10 +32,6 @@ BI.SingleSelectEditor = BI.inherit(BI.Widget, {
this.editor.on(BI.Controller.EVENT_CHANGE, function () { this.editor.on(BI.Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
}); });
this.editor.on(BI.StateEditor.EVENT_PAUSE, function () {
self.fireEvent(BI.SingleSelectEditor.EVENT_PAUSE);
});
this.editor.on(BI.StateEditor.EVENT_FOCUS, function () { this.editor.on(BI.StateEditor.EVENT_FOCUS, function () {
self.fireEvent(BI.SingleSelectEditor.EVENT_FOCUS); self.fireEvent(BI.SingleSelectEditor.EVENT_FOCUS);
}); });
@ -60,23 +57,31 @@ BI.SingleSelectEditor = BI.inherit(BI.Widget, {
}, },
getValue: function () { getValue: function () {
var v = this.editor.getState(); return this.editor.getValue();
if (BI.isArray(v) && v.length > 0) {
return v[v.length - 1];
}
return "";
}, },
getKeywords: function () { getKeywords: function () {
var val = this.editor.getLastChangedValue(); var val = this.editor.getValue();
var keywords = val.match(/[\S]+/g); var keywords = val.split(/\u200b\s\u200b/);
if (BI.isEndWithBlank(val)) { if (BI.isEmptyString(keywords[keywords.length - 1])) {
return keywords.concat([" "]); keywords = keywords.slice(0, keywords.length - 1);
} }
if (/\u200b\s\u200b$/.test(val)) {
return keywords.concat([BI.BlankSplitChar]);
}
return keywords; return keywords;
}, },
getKeyword: function () {
var val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1);
}
return BI.isEmptyArray(keywords) ? "" : keywords[keywords.length - 1];
},
populate: function (items) { populate: function (items) {
} }
@ -84,5 +89,4 @@ BI.SingleSelectEditor = BI.inherit(BI.Widget, {
BI.SingleSelectEditor.EVENT_FOCUS = "EVENT_FOCUS"; BI.SingleSelectEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.SingleSelectEditor.EVENT_BLUR = "EVENT_BLUR"; BI.SingleSelectEditor.EVENT_BLUR = "EVENT_BLUR";
BI.SingleSelectEditor.EVENT_PAUSE = "EVENT_PAUSE";
BI.shortcut("bi.single_select_editor", BI.SingleSelectEditor); BI.shortcut("bi.single_select_editor", BI.SingleSelectEditor);

6
src/widget/singleselect/trigger/searcher.singleselect.js

@ -25,6 +25,7 @@ BI.SingleSelectSearcher = BI.inherit(BI.Widget, {
this.editor = BI.createWidget(o.el, { this.editor = BI.createWidget(o.el, {
type: "bi.single_select_editor", type: "bi.single_select_editor",
height: o.height, height: o.height,
watermark: o.watermark,
text: o.text, text: o.text,
listeners: [{ listeners: [{
eventName: BI.SingleSelectEditor.EVENT_FOCUS, eventName: BI.SingleSelectEditor.EVENT_FOCUS,
@ -41,7 +42,6 @@ BI.SingleSelectSearcher = BI.inherit(BI.Widget, {
this.searcher = BI.createWidget({ this.searcher = BI.createWidget({
type: "bi.searcher", type: "bi.searcher",
allowSearchBlank: false,
element: this, element: this,
height: o.height, height: o.height,
isAutoSearch: false, isAutoSearch: false,
@ -95,10 +95,6 @@ BI.SingleSelectSearcher = BI.inherit(BI.Widget, {
} }
}, },
getMatchedItemValue: function() {
return this.searcher.getView().getMatchedItemValue();
},
adjustView: function () { adjustView: function () {
this.searcher.adjustView(); this.searcher.adjustView();
}, },

1
typescript/core/var.ts

@ -129,4 +129,5 @@ export interface _var {
Stretch: string; Stretch: string;
}, },
StartOfWeek: number; StartOfWeek: number;
BlankSplitChar: string;
} }

Loading…
Cancel
Save