|
|
|
@ -1,100 +1,105 @@
|
|
|
|
|
/** |
|
|
|
|
* 选择列表 |
|
|
|
|
* |
|
|
|
|
* Created by GUY on 2015/11/1. |
|
|
|
|
* @class BI.SelectList |
|
|
|
|
* @extends BI.Widget |
|
|
|
|
*/ |
|
|
|
|
BI.SelectList = BI.inherit(BI.Widget, { |
|
|
|
|
|
|
|
|
|
_defaultConfig: function () { |
|
|
|
|
return BI.extend(BI.SelectList.superclass._defaultConfig.apply(this, arguments), { |
|
|
|
|
/* eslint-disable no-mixed-spaces-and-tabs */ |
|
|
|
|
|
|
|
|
|
import { shortcut, Widget, extend, emptyFn, Controller, createWidget, Events, isNotNull, isEmptyString, isEmptyArray, Direction, get, LogicFactory, each, pixFormat } from "@/core"; |
|
|
|
|
import { ButtonGroup } from "@/base"; |
|
|
|
|
@shortcut() |
|
|
|
|
export class SelectList extends Widget { |
|
|
|
|
static xtype = "bi.select_list"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_defaultConfig() { |
|
|
|
|
return extend(super._defaultConfig(...arguments), { |
|
|
|
|
baseCls: "bi-select-list", |
|
|
|
|
direction: BI.Direction.Top, // toolbar的位置
|
|
|
|
|
direction: Direction.Top, // toolbar的位置
|
|
|
|
|
logic: { |
|
|
|
|
dynamic: true |
|
|
|
|
dynamic: true, |
|
|
|
|
}, |
|
|
|
|
items: [], |
|
|
|
|
itemsCreator: BI.emptyFn, |
|
|
|
|
hasNext: BI.emptyFn, |
|
|
|
|
onLoaded: BI.emptyFn, |
|
|
|
|
itemsCreator: emptyFn, |
|
|
|
|
hasNext: emptyFn, |
|
|
|
|
onLoaded: emptyFn, |
|
|
|
|
toolbar: { |
|
|
|
|
type: "bi.multi_select_bar", |
|
|
|
|
iconWrapperWidth: 36 |
|
|
|
|
iconWrapperWidth: 36, |
|
|
|
|
}, |
|
|
|
|
el: { |
|
|
|
|
type: "bi.list_pane" |
|
|
|
|
} |
|
|
|
|
type: "bi.list_pane", |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
_init: function () { |
|
|
|
|
BI.SelectList.superclass._init.apply(this, arguments); |
|
|
|
|
var self = this, o = this.options; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_init() { |
|
|
|
|
super._init(...arguments); |
|
|
|
|
const o = this.options; |
|
|
|
|
|
|
|
|
|
// 全选
|
|
|
|
|
this.toolbar = BI.createWidget(o.toolbar); |
|
|
|
|
this.toolbar = createWidget(o.toolbar); |
|
|
|
|
this.allSelected = false; |
|
|
|
|
this.toolbar.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
|
|
|
|
self.allSelected = this.isSelected(); |
|
|
|
|
if (type === BI.Events.CLICK) { |
|
|
|
|
self.setAllSelected(self.allSelected); |
|
|
|
|
self.fireEvent(BI.SelectList.EVENT_CHANGE, value, obj); |
|
|
|
|
this.toolbar.on(Controller.EVENT_CHANGE, (type, value, obj) => { |
|
|
|
|
this.allSelected = this.toolbar.isSelected(); |
|
|
|
|
if (type === Events.CLICK) { |
|
|
|
|
this.setAllSelected(this.allSelected); |
|
|
|
|
this.fireEvent(SelectList.EVENT_CHANGE, value, obj); |
|
|
|
|
} |
|
|
|
|
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, arguments); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.list = BI.createWidget(o.el, { |
|
|
|
|
this.list = createWidget(o.el, { |
|
|
|
|
type: "bi.list_pane", |
|
|
|
|
items: o.items, |
|
|
|
|
itemsCreator: function (op, callback) { |
|
|
|
|
op.times === 1 && self.toolbar.setVisible(false); |
|
|
|
|
o.itemsCreator(op, function (items, keywords, context) { |
|
|
|
|
callback.apply(self, arguments); |
|
|
|
|
itemsCreator(op, callback) { |
|
|
|
|
op.times === 1 && this.toolbar.setVisible(false); |
|
|
|
|
o.itemsCreator(op, (items, keywords, context, ...args) => { |
|
|
|
|
callback(items, keywords, context, ...args); |
|
|
|
|
if (op.times === 1) { |
|
|
|
|
var tipText = BI.get(context, 'tipText', ''); |
|
|
|
|
var visible = BI.isEmptyString(tipText) && items && items.length > 0; |
|
|
|
|
self.toolbar.setVisible(visible); |
|
|
|
|
self.toolbar.setEnable(self.isEnabled() && visible); |
|
|
|
|
const tipText = get(context, "tipText", ""); |
|
|
|
|
const visible = isEmptyString(tipText) && items && items.length > 0; |
|
|
|
|
this.toolbar.setVisible(visible); |
|
|
|
|
this.toolbar.setEnable(this.isEnabled() && visible); |
|
|
|
|
} |
|
|
|
|
self._checkAllSelected(); |
|
|
|
|
this._checkAllSelected(); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
onLoaded: o.onLoaded, |
|
|
|
|
hasNext: o.hasNext |
|
|
|
|
hasNext: o.hasNext, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.list.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
|
|
|
|
if (type === BI.Events.CLICK) { |
|
|
|
|
self._checkAllSelected(); |
|
|
|
|
self.fireEvent(BI.SelectList.EVENT_CHANGE, value, obj); |
|
|
|
|
this.list.on(Controller.EVENT_CHANGE, (type, value, obj) => { |
|
|
|
|
if (type === Events.CLICK) { |
|
|
|
|
this._checkAllSelected(); |
|
|
|
|
this.fireEvent(SelectList.EVENT_CHANGE, value, obj); |
|
|
|
|
} |
|
|
|
|
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, arguments); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
BI.createWidget(BI.extend({ |
|
|
|
|
element: this |
|
|
|
|
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ |
|
|
|
|
scrolly: true |
|
|
|
|
createWidget(extend({ |
|
|
|
|
element: this, |
|
|
|
|
}, LogicFactory.createLogic(LogicFactory.createLogicTypeByDirection(o.direction), extend({ |
|
|
|
|
scrolly: true, |
|
|
|
|
}, o.logic, { |
|
|
|
|
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.toolbar, this.list) |
|
|
|
|
items: LogicFactory.createLogicItemsByDirection(o.direction, this.toolbar, this.list), |
|
|
|
|
})))); |
|
|
|
|
|
|
|
|
|
if (o.items.length <= 0) { |
|
|
|
|
this.toolbar.setVisible(false); |
|
|
|
|
this.toolbar.setEnable(false); |
|
|
|
|
} |
|
|
|
|
if(BI.isNotNull(o.value)){ |
|
|
|
|
if (isNotNull(o.value)) { |
|
|
|
|
this.setValue(o.value); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_checkAllSelected: function () { |
|
|
|
|
var selectLength = this.list.getValue().length; |
|
|
|
|
var notSelectLength = this.getAllLeaves().length - selectLength; |
|
|
|
|
var hasNext = this.list.hasNext(); |
|
|
|
|
var isAlreadyAllSelected = this.toolbar.isSelected(); |
|
|
|
|
var isHalf = selectLength > 0 && notSelectLength > 0; |
|
|
|
|
var allSelected = selectLength > 0 && notSelectLength <= 0 && (!hasNext || isAlreadyAllSelected); |
|
|
|
|
_checkAllSelected() { |
|
|
|
|
const selectLength = this.list.getValue().length; |
|
|
|
|
const notSelectLength = this.getAllLeaves().length - selectLength; |
|
|
|
|
const hasNext = this.list.hasNext(); |
|
|
|
|
const isAlreadyAllSelected = this.toolbar.isSelected(); |
|
|
|
|
let isHalf = selectLength > 0 && notSelectLength > 0; |
|
|
|
|
let allSelected = selectLength > 0 && notSelectLength <= 0 && (!hasNext || isAlreadyAllSelected); |
|
|
|
|
|
|
|
|
|
if (this.isAllSelected() === false) { |
|
|
|
|
hasNext && (isHalf = selectLength > 0); |
|
|
|
@ -110,127 +115,125 @@ BI.SelectList = BI.inherit(BI.Widget, {
|
|
|
|
|
|
|
|
|
|
this.toolbar.setHalfSelected(isHalf); |
|
|
|
|
!isHalf && this.toolbar.setSelected(allSelected); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setAllSelected: function (v) { |
|
|
|
|
setAllSelected(v) { |
|
|
|
|
if (this.list.setAllSelected) { |
|
|
|
|
this.list.setAllSelected(v); |
|
|
|
|
} else { |
|
|
|
|
BI.each(this.getAllButtons(), function (i, btn) { |
|
|
|
|
each(this.getAllButtons(), (i, btn) => { |
|
|
|
|
(btn.setSelected || btn.setAllSelected).apply(btn, [v]); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
this.allSelected = !!v; |
|
|
|
|
this.toolbar.setSelected(v); |
|
|
|
|
this.toolbar.setHalfSelected(false); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setToolBarVisible: function (b) { |
|
|
|
|
setToolBarVisible(b) { |
|
|
|
|
this.toolbar.setVisible(b); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
isAllSelected: function () { |
|
|
|
|
isAllSelected() { |
|
|
|
|
return this.allSelected; |
|
|
|
|
// return this.toolbar.isSelected();
|
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hasPrev: function () { |
|
|
|
|
hasPrev() { |
|
|
|
|
return this.list.hasPrev(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hasNext: function () { |
|
|
|
|
hasNext() { |
|
|
|
|
return this.list.hasNext(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
prependItems: function (items) { |
|
|
|
|
this.list.prependItems.apply(this.list, arguments); |
|
|
|
|
}, |
|
|
|
|
prependItems(items) { |
|
|
|
|
this.list.prependItems(...arguments); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
addItems: function (items) { |
|
|
|
|
this.list.addItems.apply(this.list, arguments); |
|
|
|
|
}, |
|
|
|
|
addItems(items) { |
|
|
|
|
this.list.addItems(...arguments); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setValue: function (data) { |
|
|
|
|
var selectAll = data.type === BI.ButtonGroup.CHOOSE_TYPE_ALL; |
|
|
|
|
setValue(data) { |
|
|
|
|
const selectAll = data.type === ButtonGroup.CHOOSE_TYPE_ALL; |
|
|
|
|
this.setAllSelected(selectAll); |
|
|
|
|
this.list[selectAll ? "setNotSelectedValue" : "setValue"](data.value); |
|
|
|
|
this._checkAllSelected(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getValue: function () { |
|
|
|
|
getValue() { |
|
|
|
|
if (this.isAllSelected() === false) { |
|
|
|
|
return { |
|
|
|
|
type: BI.ButtonGroup.CHOOSE_TYPE_MULTI, |
|
|
|
|
type: ButtonGroup.CHOOSE_TYPE_MULTI, |
|
|
|
|
value: this.list.getValue(), |
|
|
|
|
assist: this.list.getNotSelectedValue() |
|
|
|
|
assist: this.list.getNotSelectedValue(), |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
type: BI.ButtonGroup.CHOOSE_TYPE_ALL, |
|
|
|
|
type: ButtonGroup.CHOOSE_TYPE_ALL, |
|
|
|
|
value: this.list.getNotSelectedValue(), |
|
|
|
|
assist: this.list.getValue() |
|
|
|
|
assist: this.list.getValue(), |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
empty: function () { |
|
|
|
|
empty() { |
|
|
|
|
this.list.empty(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
populate: function (items) { |
|
|
|
|
this.toolbar.setVisible(!BI.isEmptyArray(items)); |
|
|
|
|
this.toolbar.setEnable(this.isEnabled() && !BI.isEmptyArray(items)); |
|
|
|
|
this.list.populate.apply(this.list, arguments); |
|
|
|
|
populate(items) { |
|
|
|
|
this.toolbar.setVisible(!isEmptyArray(items)); |
|
|
|
|
this.toolbar.setEnable(this.isEnabled() && !isEmptyArray(items)); |
|
|
|
|
this.list.populate(...arguments); |
|
|
|
|
this._checkAllSelected(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_setEnable: function (enable) { |
|
|
|
|
BI.SelectList.superclass._setEnable.apply(this, arguments); |
|
|
|
|
_setEnable(enable) { |
|
|
|
|
super._setEnable(...arguments); |
|
|
|
|
this.toolbar.setEnable(enable); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resetHeight: function (h) { |
|
|
|
|
var toolHeight = ( this.toolbar.element.outerHeight() || 25) * ( this.toolbar.isVisible() ? 1 : 0); |
|
|
|
|
resetHeight(h) { |
|
|
|
|
const toolHeight = (this.toolbar.element.outerHeight() || 25) * (this.toolbar.isVisible() ? 1 : 0); |
|
|
|
|
this.list.resetHeight ? this.list.resetHeight(h - toolHeight) : |
|
|
|
|
this.list.element.css({"max-height": BI.pixFormat(h - toolHeight)}); |
|
|
|
|
}, |
|
|
|
|
this.list.element.css({ "max-height": pixFormat(h - toolHeight) }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setNotSelectedValue: function () { |
|
|
|
|
this.list.setNotSelectedValue.apply(this.list, arguments); |
|
|
|
|
setNotSelectedValue() { |
|
|
|
|
this.list.setNotSelectedValue(...arguments); |
|
|
|
|
this._checkAllSelected(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getNotSelectedValue: function () { |
|
|
|
|
getNotSelectedValue() { |
|
|
|
|
return this.list.getNotSelectedValue(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getAllButtons: function () { |
|
|
|
|
getAllButtons() { |
|
|
|
|
return this.list.getAllButtons(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getAllLeaves: function () { |
|
|
|
|
getAllLeaves() { |
|
|
|
|
return this.list.getAllLeaves(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getSelectedButtons: function () { |
|
|
|
|
getSelectedButtons() { |
|
|
|
|
return this.list.getSelectedButtons(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getNotSelectedButtons: function () { |
|
|
|
|
getNotSelectedButtons() { |
|
|
|
|
return this.list.getNotSelectedButtons(); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getIndexByValue: function (value) { |
|
|
|
|
getIndexByValue(value) { |
|
|
|
|
return this.list.getIndexByValue(value); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getNodeById: function (id) { |
|
|
|
|
getNodeById(id) { |
|
|
|
|
return this.list.getNodeById(id); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getNodeByValue: function (value) { |
|
|
|
|
getNodeByValue(value) { |
|
|
|
|
return this.list.getNodeByValue(value); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
BI.SelectList.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
|
BI.shortcut("bi.select_list", BI.SelectList); |
|
|
|
|
} |
|
|
|
|