You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
6.5 KiB
186 lines
6.5 KiB
/** |
|
* 多选加载数据面板 |
|
* Created by guy on 15/11/2. |
|
* @class BI.MultiSelectLoader |
|
* @extends Widget |
|
*/ |
|
BI.MultiSelectLoader = BI.inherit(BI.Widget, { |
|
|
|
_defaultConfig: function () { |
|
return BI.extend(BI.MultiSelectLoader.superclass._defaultConfig.apply(this, arguments), { |
|
baseCls: "bi-multi-select-loader", |
|
logic: { |
|
dynamic: true |
|
}, |
|
el: { |
|
height: 400 |
|
}, |
|
valueFormatter: BI.emptyFn, |
|
itemsCreator: BI.emptyFn, |
|
itemFormatter: BI.emptyFn, |
|
onLoaded: BI.emptyFn, |
|
itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
|
isDefaultInit: false, |
|
}); |
|
}, |
|
|
|
_init: function () { |
|
BI.MultiSelectLoader.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.select_list", |
|
logic: opts.logic, |
|
toolbar: { |
|
type: "bi.multi_select_bar", |
|
cls: "bi-list-item-active", |
|
height: this.options.itemHeight || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
|
iconWrapperWidth: 36 |
|
}, |
|
el: BI.extend({ |
|
onLoaded: opts.onLoaded, |
|
el: { |
|
type: "bi.multi_select_inner_loader", |
|
isDefaultInit: opts.isDefaultInit, |
|
} |
|
}, opts.el), |
|
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) && !BI.contains(self.storeValue.value, 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.type === BI.Selection.All ? BI.remove(self.storeValue.value, startValue) : BI.pushDistinct(self.storeValue.value, startValue)); |
|
self.setValue(self.storeValue); |
|
} |
|
(op.times === 1) && self._scrollToTop(); |
|
}); |
|
}, |
|
hasNext: function () { |
|
return hasNext; |
|
}, |
|
value: this.storeValue |
|
}); |
|
|
|
BI.createWidget(BI.extend({ |
|
element: this |
|
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Top), BI.extend({ |
|
scrolly: true, |
|
vgap: 5 |
|
}, opts.logic, { |
|
items: BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Top, this.button_group) |
|
})))); |
|
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.MultiSelectLoader.EVENT_CHANGE, arguments); |
|
}); |
|
}, |
|
|
|
_createItems: function (items) { |
|
var allSelected = this.isAllSelected(); |
|
var itemFormatter = this.options.itemFormatter; |
|
return BI.map(items, (i, item) => { |
|
return { |
|
type: "bi.multi_select_item", |
|
logic: this.options.logic, |
|
cls: "bi-list-item-active", |
|
height: this.options.itemHeight || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
|
selected: allSelected, |
|
iconWrapperWidth: 36, |
|
...item, |
|
...itemFormatter(item), |
|
}; |
|
}); |
|
}, |
|
|
|
_scrollToTop: function () { |
|
var self = this; |
|
BI.delay(function () { |
|
self.button_group.element.scrollTop(0); |
|
}, 30); |
|
}, |
|
|
|
isAllSelected: function () { |
|
return this.button_group.isAllSelected(); |
|
}, |
|
|
|
_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); |
|
}, |
|
|
|
getValue: function () { |
|
return this.button_group.getValue(); |
|
}, |
|
|
|
getAllButtons: function () { |
|
return this.button_group.getAllButtons(); |
|
}, |
|
|
|
empty: function () { |
|
this.button_group.empty(); |
|
}, |
|
|
|
populate: function (items) { |
|
// arguments.length为0时对arguments[0]赋值后不同环境对其length的取值不同(nashorn) |
|
if (BI.isNotNull(items)) { |
|
arguments[0] = this._createItems(items); |
|
} |
|
this.button_group.populate.apply(this.button_group, arguments); |
|
}, |
|
|
|
resetHeight: function (h) { |
|
this.button_group.resetHeight(h - 10); |
|
}, |
|
|
|
resetWidth: function (w) { |
|
this.button_group.resetWidth(w); |
|
} |
|
}); |
|
|
|
BI.MultiSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; |
|
BI.shortcut("bi.multi_select_loader", BI.MultiSelectLoader);
|
|
|