Browse Source
* commit 'bb8aff296461525ae134a90f8c0a580487ab9686': BI-21686 不带全选的,multiselect combo和listes6
guy
7 years ago
12 changed files with 5735 additions and 1869 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,373 @@
|
||||
/** |
||||
* |
||||
* @class BI.MultiSelectInsertCombo |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.MultiSelectInsertNoBarCombo = BI.inherit(BI.Single, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.MultiSelectInsertNoBarCombo.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-multi-select-insert-combo", |
||||
itemsCreator: BI.emptyFn, |
||||
valueFormatter: BI.emptyFn, |
||||
height: 28 |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.MultiSelectInsertNoBarCombo.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
|
||||
var assertShowValue = function () { |
||||
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); |
||||
self.trigger.getSearcher().setState(self.storeValue); |
||||
self.trigger.getCounter().setButtonChecked(self.storeValue); |
||||
}; |
||||
this.storeValue = { |
||||
type: BI.Selection.Multi, |
||||
value: o.value || [] |
||||
}; |
||||
// 标记正在请求数据
|
||||
this.requesting = false; |
||||
|
||||
this.trigger = BI.createWidget({ |
||||
type: "bi.multi_select_trigger", |
||||
height: o.height, |
||||
// adapter: this.popup,
|
||||
masker: { |
||||
offset: { |
||||
left: 1, |
||||
top: 1, |
||||
right: 2, |
||||
bottom: 33 |
||||
} |
||||
}, |
||||
valueFormatter: o.valueFormatter, |
||||
itemsCreator: function (op, callback) { |
||||
o.itemsCreator(op, function (res) { |
||||
if (op.times === 1 && BI.isNotNull(op.keywords)) { |
||||
// 预防trigger内部把当前的storeValue改掉
|
||||
self.trigger.setValue({ |
||||
type: BI.Selection.Multi, |
||||
value: self.getValue() |
||||
}); |
||||
} |
||||
callback.apply(self, arguments); |
||||
}); |
||||
}, |
||||
value: { |
||||
type: BI.Selection.Multi, |
||||
value: o.value |
||||
} |
||||
}); |
||||
|
||||
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { |
||||
self._setStartValue(""); |
||||
this.getSearcher().setValue(self.storeValue); |
||||
}); |
||||
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { |
||||
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 () { |
||||
// 如果在不选的状态下直接把该值添加进来
|
||||
if (self.storeValue.type === BI.Selection.Multi) { |
||||
self.storeValue.value.pushDistinct(keyword); |
||||
} |
||||
self.combo.setValue(self.storeValue); |
||||
self._setStartValue(keyword); |
||||
assertShowValue(); |
||||
self.populate(); |
||||
self._setStartValue(""); |
||||
}); |
||||
// }
|
||||
}); |
||||
this.trigger.on(BI.MultiSelectTrigger.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(); |
||||
} |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { |
||||
if (obj instanceof BI.MultiSelectBar) { |
||||
self._joinAll(this.getValue(), function () { |
||||
assertShowValue(); |
||||
}); |
||||
} else { |
||||
self._join(this.getValue(), function () { |
||||
assertShowValue(); |
||||
}); |
||||
} |
||||
}); |
||||
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { |
||||
this.getCounter().setValue(self.storeValue); |
||||
}); |
||||
this.trigger.on(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK, function () { |
||||
if (!self.combo.isViewVisible()) { |
||||
self.combo.showView(); |
||||
} |
||||
}); |
||||
|
||||
this.combo = BI.createWidget({ |
||||
type: "bi.combo", |
||||
toggle: false, |
||||
el: this.trigger, |
||||
adjustLength: 1, |
||||
popup: { |
||||
type: "bi.multi_select_no_bar_popup_view", |
||||
ref: function () { |
||||
self.popup = this; |
||||
self.trigger.setAdapter(this); |
||||
}, |
||||
listeners: [{ |
||||
eventName: BI.MultiSelectPopupView.EVENT_CHANGE, |
||||
action: function () { |
||||
self.storeValue = this.getValue(); |
||||
self._adjust(function () { |
||||
assertShowValue(); |
||||
}); |
||||
} |
||||
}, { |
||||
eventName: BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM, |
||||
action: function () { |
||||
self._defaultState(); |
||||
} |
||||
}, { |
||||
eventName: BI.MultiSelectPopupView.EVENT_CLICK_CLEAR, |
||||
action: function () { |
||||
self.setValue(); |
||||
self._defaultState(); |
||||
} |
||||
}], |
||||
itemsCreator: o.itemsCreator, |
||||
valueFormatter: o.valueFormatter, |
||||
onLoaded: function () { |
||||
BI.nextTick(function () { |
||||
self.combo.adjustWidth(); |
||||
self.combo.adjustHeight(); |
||||
self.trigger.getCounter().adjustView(); |
||||
self.trigger.getSearcher().adjustView(); |
||||
}); |
||||
} |
||||
}, |
||||
value: { |
||||
type: BI.Selection.Multi, |
||||
value: o.value |
||||
}, |
||||
hideChecker: function (e) { |
||||
return triggerBtn.element.find(e.target).length === 0; |
||||
} |
||||
}); |
||||
|
||||
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { |
||||
this.setValue(self.storeValue); |
||||
BI.nextTick(function () { |
||||
self.populate(); |
||||
}); |
||||
}); |
||||
// 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件
|
||||
this.wants2Quit = false; |
||||
this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { |
||||
// important:关闭弹出时又可能没有退出编辑状态
|
||||
self.trigger.stopEditing(); |
||||
if (self.requesting === true) { |
||||
self.wants2Quit = true; |
||||
} else { |
||||
self.fireEvent(BI.MultiSelectInsertNoBarCombo.EVENT_CONFIRM); |
||||
} |
||||
}); |
||||
|
||||
var triggerBtn = BI.createWidget({ |
||||
type: "bi.trigger_icon_button", |
||||
width: o.height, |
||||
height: o.height, |
||||
cls: "multi-select-trigger-icon-button" |
||||
}); |
||||
triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { |
||||
self.trigger.getCounter().hideView(); |
||||
if (self.combo.isViewVisible()) { |
||||
self.combo.hideView(); |
||||
} else { |
||||
self.combo.showView(); |
||||
} |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this, |
||||
items: [{ |
||||
el: this.combo, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}, { |
||||
el: triggerBtn, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}] |
||||
}); |
||||
}, |
||||
|
||||
_defaultState: function () { |
||||
this.trigger.stopEditing(); |
||||
this.combo.hideView(); |
||||
}, |
||||
|
||||
_assertValue: function (val) { |
||||
val || (val = {}); |
||||
val.type || (val.type = BI.Selection.Multi); |
||||
val.value || (val.value = []); |
||||
}, |
||||
|
||||
_makeMap: function (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.MultiSelectInsertNoBarCombo.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])) { |
||||
self.storeValue.value[self.storeValue.type === BI.Selection.Multi ? "pushDistinct" : "remove"](val); |
||||
} |
||||
}); |
||||
self._adjust(callback); |
||||
} |
||||
}, |
||||
|
||||
_joinAll: function (res, callback) { |
||||
var self = this, o = this.options; |
||||
this._assertValue(res); |
||||
this.requesting = true; |
||||
o.itemsCreator({ |
||||
type: BI.MultiSelectInsertNoBarCombo.REQ_GET_ALL_DATA, |
||||
keywords: [this.trigger.getKey()] |
||||
}, function (ob) { |
||||
var items = BI.map(ob.items, "value"); |
||||
if (self.storeValue.type === res.type) { |
||||
var change = false; |
||||
var map = self._makeMap(self.storeValue.value); |
||||
BI.each(items, function (i, v) { |
||||
if (BI.isNotNull(map[v])) { |
||||
change = true; |
||||
delete map[v]; |
||||
} |
||||
}); |
||||
change && (self.storeValue.value = BI.values(map)); |
||||
self._adjust(callback); |
||||
return; |
||||
} |
||||
var selectedMap = self._makeMap(self.storeValue.value); |
||||
var notSelectedMap = self._makeMap(res.value); |
||||
var newItems = []; |
||||
BI.each(items, function (i, item) { |
||||
if (BI.isNotNull(selectedMap[items[i]])) { |
||||
delete selectedMap[items[i]]; |
||||
} |
||||
if (BI.isNull(notSelectedMap[items[i]])) { |
||||
newItems.push(item); |
||||
} |
||||
}); |
||||
self.storeValue.value = newItems.concat(BI.values(selectedMap)); |
||||
self._adjust(callback); |
||||
}); |
||||
}, |
||||
|
||||
_adjust: function (callback) { |
||||
var self = this, o = this.options; |
||||
adjust(); |
||||
callback(); |
||||
function adjust () { |
||||
if (self.wants2Quit === true) { |
||||
self.fireEvent(BI.MultiSelectInsertNoBarCombo.EVENT_CONFIRM); |
||||
self.wants2Quit = false; |
||||
} |
||||
self.requesting = false; |
||||
} |
||||
}, |
||||
|
||||
_join: function (res, callback) { |
||||
var self = this, o = this.options; |
||||
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) { |
||||
if (!map[v]) { |
||||
self.storeValue.value.push(v); |
||||
map[v] = v; |
||||
} |
||||
}); |
||||
var change = false; |
||||
BI.each(res.assist, function (i, v) { |
||||
if (BI.isNotNull(map[v])) { |
||||
change = true; |
||||
delete map[v]; |
||||
} |
||||
}); |
||||
change && (this.storeValue.value = BI.values(map)); |
||||
self._adjust(callback); |
||||
return; |
||||
} |
||||
this._joinAll(res, callback); |
||||
}, |
||||
|
||||
_setStartValue: function (value) { |
||||
this._startValue = value; |
||||
this.popup.setStartValue(value); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.storeValue = { |
||||
type: BI.Selection.Multi, |
||||
value: v || [] |
||||
}; |
||||
this.combo.setValue(this.storeValue); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return BI.deepClone(this.storeValue.value); |
||||
}, |
||||
|
||||
populate: function () { |
||||
this.combo.populate.apply(this.combo, arguments); |
||||
} |
||||
}); |
||||
|
||||
BI.extend(BI.MultiSelectInsertNoBarCombo, { |
||||
REQ_GET_DATA_LENGTH: 1, |
||||
REQ_GET_ALL_DATA: -1 |
||||
}); |
||||
|
||||
BI.MultiSelectInsertNoBarCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; |
||||
|
||||
BI.shortcut("bi.multi_select_insert_no_bar_combo", BI.MultiSelectInsertNoBarCombo); |
@ -0,0 +1,170 @@
|
||||
/** |
||||
* 多选加载数据面板 |
||||
* Created by guy on 15/11/2. |
||||
* @class BI.MultiSelectNoBarLoader |
||||
* @extends Widget |
||||
*/ |
||||
BI.MultiSelectNoBarLoader = BI.inherit(BI.Widget, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.MultiSelectNoBarLoader.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-multi-select-loader", |
||||
logic: { |
||||
dynamic: true |
||||
}, |
||||
el: { |
||||
height: 400 |
||||
}, |
||||
valueFormatter: BI.emptyFn, |
||||
itemsCreator: BI.emptyFn, |
||||
onLoaded: BI.emptyFn |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.MultiSelectNoBarLoader.superclass._init.apply(this, arguments); |
||||
|
||||
var self = this, opts = this.options; |
||||
var hasNext = false; |
||||
|
||||
this.storeValue = opts.value || {}; |
||||
this._assertValue(this.storeValue); |
||||
|
||||
this.button_group = BI.createWidget({ |
||||
type: "bi.list_pane", |
||||
element: this, |
||||
onLoaded: opts.onLoaded, |
||||
el: { |
||||
type: "bi.loader", |
||||
isDefaultInit: false, |
||||
logic: { |
||||
dynamic: true, |
||||
scrolly: true |
||||
}, |
||||
el: { |
||||
chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, |
||||
behaviors: { |
||||
redmark: function () { |
||||
return true; |
||||
} |
||||
}, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
} |
||||
}, |
||||
itemsCreator: function (op, callback) { |
||||
var startValue = self._startValue; |
||||
self.storeValue && (op = BI.extend(op || {}, { |
||||
selectedValues: BI.isKey(startValue) && self.storeValue.type === BI.Selection.Multi |
||||
? self.storeValue.value.concat(startValue) : self.storeValue.value |
||||
})); |
||||
opts.itemsCreator(op, function (ob) { |
||||
hasNext = ob.hasNext; |
||||
var firstItems = []; |
||||
if (op.times === 1 && self.storeValue) { |
||||
var json = BI.map(self.storeValue.value, function (i, v) { |
||||
var txt = opts.valueFormatter(v) || v; |
||||
return { |
||||
text: txt, |
||||
value: v, |
||||
title: txt, |
||||
selected: self.storeValue.type === BI.Selection.Multi |
||||
}; |
||||
}); |
||||
if (BI.isKey(self._startValue) && !self.storeValue.value.contains(self._startValue)) { |
||||
var txt = opts.valueFormatter(startValue) || startValue; |
||||
json.unshift({ |
||||
text: txt, |
||||
value: startValue, |
||||
title: txt, |
||||
selected: true |
||||
}); |
||||
} |
||||
firstItems = self._createItems(json); |
||||
} |
||||
callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); |
||||
if (op.times === 1 && self.storeValue) { |
||||
BI.isKey(startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](startValue); |
||||
self.setValue(self.storeValue); |
||||
} |
||||
(op.times === 1) && self._scrollToTop(); |
||||
}); |
||||
}, |
||||
hasNext: function () { |
||||
return hasNext; |
||||
}, |
||||
value: this.storeValue |
||||
}, { |
||||
el: opts.el |
||||
}); |
||||
this.button_group.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.button_group.on(BI.SelectList.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.MultiSelectNoBarLoader.EVENT_CHANGE, arguments); |
||||
}); |
||||
}, |
||||
|
||||
_createItems: function (items) { |
||||
return BI.createItems(items, { |
||||
type: "bi.multi_select_item", |
||||
logic: this.options.logic, |
||||
height: 25 |
||||
}); |
||||
}, |
||||
|
||||
_scrollToTop: function () { |
||||
var self = this; |
||||
BI.delay(function () { |
||||
self.button_group.element.scrollTop(0); |
||||
}, 30); |
||||
}, |
||||
|
||||
_assertValue: function (val) { |
||||
val || (val = {}); |
||||
val.type || (val.type = BI.Selection.Multi); |
||||
val.value || (val.value = []); |
||||
}, |
||||
|
||||
setStartValue: function (v) { |
||||
this._startValue = v; |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.storeValue = v || {}; |
||||
this._assertValue(this.storeValue); |
||||
this.button_group.setValue(this.storeValue.value); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return { |
||||
type: BI.Selection.Multi, |
||||
value: this.button_group.getValue() |
||||
}; |
||||
}, |
||||
|
||||
getAllButtons: function () { |
||||
return this.button_group.getAllButtons(); |
||||
}, |
||||
|
||||
empty: function () { |
||||
this.button_group.empty(); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
arguments[0] = this._createItems(items); |
||||
this.button_group.populate.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
resetHeight: function () { |
||||
|
||||
}, |
||||
|
||||
resetWidth: function () { |
||||
|
||||
} |
||||
}); |
||||
|
||||
BI.MultiSelectNoBarLoader.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.multi_select_no_bar_loader", BI.MultiSelectNoBarLoader); |
@ -0,0 +1,89 @@
|
||||
/** |
||||
* 带加载的多选下拉面板 |
||||
* @class BI.MultiSelectPopupView |
||||
* @extends Widget |
||||
*/ |
||||
BI.MultiSelectNoBarPopupView = BI.inherit(BI.Widget, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.MultiSelectNoBarPopupView.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-multi-select-popup-view", |
||||
maxWidth: "auto", |
||||
minWidth: 135, |
||||
maxHeight: 400, |
||||
valueFormatter: BI.emptyFn, |
||||
itemsCreator: BI.emptyFn, |
||||
onLoaded: BI.emptyFn |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.MultiSelectNoBarPopupView.superclass._init.apply(this, arguments); |
||||
var self = this, opts = this.options; |
||||
|
||||
this.loader = BI.createWidget({ |
||||
type: "bi.multi_select_no_bar_loader", |
||||
itemsCreator: opts.itemsCreator, |
||||
valueFormatter: opts.valueFormatter, |
||||
onLoaded: opts.onLoaded, |
||||
value: opts.value |
||||
}); |
||||
|
||||
this.popupView = BI.createWidget({ |
||||
type: "bi.multi_popup_view", |
||||
stopPropagation: false, |
||||
maxWidth: opts.maxWidth, |
||||
minWidth: opts.minWidth, |
||||
maxHeight: opts.maxHeight, |
||||
element: this, |
||||
buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], |
||||
el: this.loader, |
||||
value: opts.value |
||||
}); |
||||
|
||||
this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.MultiSelectNoBarPopupView.EVENT_CHANGE); |
||||
}); |
||||
this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { |
||||
switch (index) { |
||||
case 0: |
||||
self.fireEvent(BI.MultiSelectNoBarPopupView.EVENT_CLICK_CLEAR); |
||||
break; |
||||
case 1: |
||||
self.fireEvent(BI.MultiSelectNoBarPopupView.EVENT_CLICK_CONFIRM); |
||||
break; |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
setStartValue: function (v) { |
||||
this.loader.setStartValue(v); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.popupView.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.popupView.getValue(); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this.popupView.populate.apply(this.popupView, arguments); |
||||
}, |
||||
|
||||
resetHeight: function (h) { |
||||
this.popupView.resetHeight(h); |
||||
}, |
||||
|
||||
resetWidth: function (w) { |
||||
this.popupView.resetWidth(w); |
||||
} |
||||
}); |
||||
|
||||
BI.MultiSelectNoBarPopupView.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.MultiSelectNoBarPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; |
||||
BI.MultiSelectNoBarPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; |
||||
|
||||
|
||||
BI.shortcut("bi.multi_select_no_bar_popup_view", BI.MultiSelectNoBarPopupView); |
@ -0,0 +1,339 @@
|
||||
/** |
||||
* Created by zcf_1 on 2017/5/2. |
||||
*/ |
||||
BI.MultiSelectInsertNoBarList = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.MultiSelectInsertNoBarList.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-multi-select-insert-list", |
||||
itemsCreator: BI.emptyFn, |
||||
valueFormatter: BI.emptyFn |
||||
}); |
||||
}, |
||||
_init: function () { |
||||
BI.MultiSelectInsertNoBarList.superclass._init.apply(this, arguments); |
||||
|
||||
var self = this, o = this.options; |
||||
this.storeValue = { |
||||
type: BI.Selection.Multi, |
||||
value: o.value || [] |
||||
}; |
||||
|
||||
var assertShowValue = function () { |
||||
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); |
||||
// self.trigger.setValue(self.storeValue);
|
||||
}; |
||||
|
||||
this.adapter = BI.createWidget({ |
||||
type: "bi.multi_select_no_bar_loader", |
||||
cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom", |
||||
itemsCreator: o.itemsCreator, |
||||
valueFormatter: o.valueFormatter, |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
// onLoaded: o.onLoaded,
|
||||
el: {}, |
||||
value: { |
||||
type: BI.Selection.Multi, |
||||
value: o.value || [] |
||||
} |
||||
}); |
||||
this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { |
||||
self.storeValue = this.getValue(); |
||||
assertShowValue(); |
||||
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); |
||||
}); |
||||
|
||||
this.searcherPane = BI.createWidget({ |
||||
type: "bi.multi_select_search_pane", |
||||
cls: "bi-border-left bi-border-right bi-border-bottom", |
||||
valueFormatter: o.valueFormatter, |
||||
keywordGetter: function () { |
||||
return self.trigger.getKeyword(); |
||||
}, |
||||
itemsCreator: function (op, callback) { |
||||
op.keywords = [self.trigger.getKeyword()]; |
||||
this.setKeyword(op.keywords[0]); |
||||
o.itemsCreator(op, callback); |
||||
} |
||||
}); |
||||
this.searcherPane.setVisible(false); |
||||
|
||||
this.trigger = BI.createWidget({ |
||||
type: "bi.searcher", |
||||
isAutoSearch: false, |
||||
isAutoSync: false, |
||||
onSearch: function (op, callback) { |
||||
callback(); |
||||
}, |
||||
adapter: this.adapter, |
||||
popup: this.searcherPane, |
||||
height: 200, |
||||
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 keyword = this.getKeyword(); |
||||
if (this.hasMatched()) { |
||||
self._join({ |
||||
type: BI.Selection.Multi, |
||||
value: [keyword] |
||||
}, function () { |
||||
if (self.storeValue.type === BI.Selection.Multi) { |
||||
self.storeValue.value.pushDistinct(keyword); |
||||
} |
||||
self._showAdapter(); |
||||
self.adapter.setValue(self.storeValue); |
||||
self._setStartValue(keyword); |
||||
assertShowValue(); |
||||
self.adapter.populate(); |
||||
self._setStartValue(""); |
||||
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); |
||||
}); |
||||
} else { |
||||
if (self.storeValue.type === BI.Selection.Multi) { |
||||
self.storeValue.value.pushDistinct(keyword); |
||||
} |
||||
self._showAdapter(); |
||||
self.adapter.setValue(self.storeValue); |
||||
self.adapter.populate(); |
||||
if (self.storeValue.type === BI.Selection.Multi) { |
||||
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); |
||||
} |
||||
} |
||||
} |
||||
}, { |
||||
eventName: BI.Searcher.EVENT_SEARCHING, |
||||
action: function () { |
||||
var keywords = this.getKeywords(); |
||||
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, |
||||
action: function (value, obj) { |
||||
if (obj instanceof BI.MultiSelectBar) { |
||||
self._joinAll(this.getValue(), function () { |
||||
assertShowValue(); |
||||
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); |
||||
}); |
||||
} else { |
||||
self._join(this.getValue(), function () { |
||||
assertShowValue(); |
||||
self.fireEvent(BI.MultiSelectInsertNoBarList.EVENT_CHANGE); |
||||
}); |
||||
} |
||||
} |
||||
}], |
||||
value: { |
||||
type: BI.Selection.Multi, |
||||
value: o.value || [] |
||||
} |
||||
}); |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.vtape", |
||||
element: this, |
||||
items: [{ |
||||
el: this.trigger, |
||||
height: 24 |
||||
}, { |
||||
el: this.adapter, |
||||
height: "fill" |
||||
}] |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this, |
||||
items: [{ |
||||
el: this.searcherPane, |
||||
top: 30, |
||||
bottom: 0, |
||||
left: 0, |
||||
right: 0 |
||||
}] |
||||
}); |
||||
}, |
||||
|
||||
_showAdapter: function () { |
||||
this.adapter.setVisible(true); |
||||
this.searcherPane.setVisible(false); |
||||
}, |
||||
|
||||
_showSearcherPane: function () { |
||||
this.searcherPane.setVisible(true); |
||||
this.adapter.setVisible(false); |
||||
}, |
||||
|
||||
_defaultState: function () { |
||||
this.trigger.stopEditing(); |
||||
}, |
||||
|
||||
_assertValue: function (val) { |
||||
val || (val = {}); |
||||
val.type || (val.type = BI.Selection.Multi); |
||||
val.value || (val.value = []); |
||||
}, |
||||
|
||||
_makeMap: function (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.MultiSelectInsertNoBarList.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])) { |
||||
self.storeValue.value[self.storeValue.type === BI.Selection.Multi ? "pushDistinct" : "remove"](val); |
||||
} |
||||
}); |
||||
callback(); |
||||
} |
||||
}, |
||||
|
||||
_joinAll: function (res, callback) { |
||||
var self = this, o = this.options; |
||||
this._assertValue(res); |
||||
o.itemsCreator({ |
||||
type: BI.MultiSelectInsertNoBarList.REQ_GET_ALL_DATA, |
||||
keywords: [self.trigger.getKeyword()] |
||||
}, function (ob) { |
||||
var items = BI.map(ob.items, "value"); |
||||
if (self.storeValue.type === res.type) { |
||||
var change = false; |
||||
var map = self._makeMap(self.storeValue.value); |
||||
BI.each(items, function (i, v) { |
||||
if (BI.isNotNull(map[v])) { |
||||
change = true; |
||||
delete map[v]; |
||||
} |
||||
}); |
||||
change && (self.storeValue.value = BI.values(map)); |
||||
callback(); |
||||
return; |
||||
} |
||||
var selectedMap = self._makeMap(self.storeValue.value); |
||||
var notSelectedMap = self._makeMap(res.value); |
||||
var newItems = []; |
||||
BI.each(items, function (i, item) { |
||||
if (BI.isNotNull(selectedMap[items[i]])) { |
||||
delete selectedMap[items[i]]; |
||||
} |
||||
if (BI.isNull(notSelectedMap[items[i]])) { |
||||
newItems.push(item); |
||||
} |
||||
}); |
||||
self.storeValue.value = newItems.concat(BI.values(selectedMap)); |
||||
callback(); |
||||
}); |
||||
}, |
||||
|
||||
_join: function (res, callback) { |
||||
var self = this, o = this.options; |
||||
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) { |
||||
if (!map[v]) { |
||||
self.storeValue.value.push(v); |
||||
map[v] = v; |
||||
} |
||||
}); |
||||
var change = false; |
||||
BI.each(res.assist, function (i, v) { |
||||
if (BI.isNotNull(map[v])) { |
||||
change = true; |
||||
delete map[v]; |
||||
} |
||||
}); |
||||
change && (this.storeValue.value = BI.values(map)); |
||||
callback(); |
||||
return; |
||||
} |
||||
this._joinAll(res, callback); |
||||
}, |
||||
|
||||
_setStartValue: function (value) { |
||||
this._startValue = value; |
||||
this.adapter.setStartValue(value); |
||||
}, |
||||
|
||||
isAllSelected: function () { |
||||
return this.adapter.isAllSelected(); |
||||
}, |
||||
|
||||
resize: function () { |
||||
// this.trigger.getCounter().adjustView();
|
||||
// this.trigger.adjustView();
|
||||
}, |
||||
setValue: function (v) { |
||||
this.storeValue = { |
||||
type: BI.Selection.Multi, |
||||
value: v || [] |
||||
}; |
||||
this.adapter.setValue(this.storeValue); |
||||
this.trigger.setValue(this.storeValue); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return BI.deepClone(this.storeValue.value); |
||||
}, |
||||
|
||||
populate: function () { |
||||
this._count = null; |
||||
this._allData = null; |
||||
this.adapter.populate.apply(this.adapter, arguments); |
||||
this.trigger.populate.apply(this.trigger, arguments); |
||||
} |
||||
}); |
||||
|
||||
BI.extend(BI.MultiSelectInsertNoBarList, { |
||||
REQ_GET_DATA_LENGTH: 1, |
||||
REQ_GET_ALL_DATA: -1 |
||||
}); |
||||
|
||||
BI.MultiSelectInsertNoBarList.EVENT_CHANGE = "BI.MultiSelectInsertNoBarList.EVENT_CHANGE"; |
||||
BI.shortcut("bi.multi_select_insert_no_bar_list", BI.MultiSelectInsertNoBarList); |
Loading…
Reference in new issue