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