|
|
|
@ -31,7 +31,7 @@ export class ButtonGroup extends Widget {
|
|
|
|
|
const behaviors = {}; |
|
|
|
|
each(optionsBehaviors, (key, rule) => { |
|
|
|
|
behaviors[key] = BI.BehaviorFactory.createBehavior(key, { |
|
|
|
|
rule: rule, |
|
|
|
|
rule, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
this.behaviors = behaviors; |
|
|
|
@ -65,25 +65,26 @@ export class ButtonGroup extends Widget {
|
|
|
|
|
args[0] = buttons; |
|
|
|
|
|
|
|
|
|
each(this.behaviors, (i, behavior) => { |
|
|
|
|
behavior.doBehavior.apply(behavior, args); |
|
|
|
|
behavior.doBehavior(...args); |
|
|
|
|
}); |
|
|
|
|
each(buttons, (i, btn) => { |
|
|
|
|
btn.on(Controller.EVENT_CHANGE, (type, value, obj, ...arg) => { |
|
|
|
|
btn.on(Controller.EVENT_CHANGE, (...arg) => { |
|
|
|
|
const [type, value, obj] = arg; |
|
|
|
|
if (type === BI.Events.CLICK) { |
|
|
|
|
switch (chooseType) { |
|
|
|
|
case ButtonGroup.CHOOSE_TYPE_SINGLE: |
|
|
|
|
this.setValue(btn.getValue()); |
|
|
|
|
break; |
|
|
|
|
case ButtonGroup.CHOOSE_TYPE_NONE: |
|
|
|
|
this.setValue([]); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
case ButtonGroup.CHOOSE_TYPE_SINGLE: |
|
|
|
|
this.setValue(btn.getValue()); |
|
|
|
|
break; |
|
|
|
|
case ButtonGroup.CHOOSE_TYPE_NONE: |
|
|
|
|
this.setValue([]); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...arg); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, ...arg); |
|
|
|
|
this.fireEvent(ButtonGroup.EVENT_CHANGE, value, obj); |
|
|
|
|
} else { |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...arg); |
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, ...arg); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
btn.on(BI.Events.DESTROY, () => { |
|
|
|
@ -98,15 +99,13 @@ export class ButtonGroup extends Widget {
|
|
|
|
|
const { layouts: optionsLayouts } = this.options; |
|
|
|
|
const layouts = isArray(optionsLayouts) ? optionsLayouts : [optionsLayouts]; |
|
|
|
|
for (let i = layouts.length - 1; i > 0; i--) { |
|
|
|
|
btns = map(btns, (k, it) => { |
|
|
|
|
return extend({}, layouts[i], { |
|
|
|
|
items: [ |
|
|
|
|
extend({}, layouts[i].el, { |
|
|
|
|
el: it, |
|
|
|
|
}) |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
btns = map(btns, (k, it) => extend({}, layouts[i], { |
|
|
|
|
items: [ |
|
|
|
|
extend({}, layouts[i].el, { |
|
|
|
|
el: it, |
|
|
|
|
}) |
|
|
|
|
], |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return btns; |
|
|
|
@ -154,12 +153,12 @@ export class ButtonGroup extends Widget {
|
|
|
|
|
const args = Array.prototype.slice.call(arguments); |
|
|
|
|
args.unshift(this.buttons); |
|
|
|
|
each(this.behaviors, (i, behavior) => { |
|
|
|
|
behavior.doBehavior.apply(behavior, args); |
|
|
|
|
behavior.doBehavior(...args); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
prependItems(items) { |
|
|
|
|
const btns = this._btnsCreator.apply(this, arguments); |
|
|
|
|
const btns = this._btnsCreator(...arguments); |
|
|
|
|
this.buttons = concat(btns, this.buttons); |
|
|
|
|
|
|
|
|
|
if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { |
|
|
|
@ -173,7 +172,7 @@ export class ButtonGroup extends Widget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
addItems(items) { |
|
|
|
|
const btns = this._btnsCreator.apply(this, arguments); |
|
|
|
|
const btns = this._btnsCreator(...arguments); |
|
|
|
|
this.buttons = concat(this.buttons, btns); |
|
|
|
|
|
|
|
|
|
// 如果是一个简单的layout
|
|
|
|
@ -209,7 +208,7 @@ export class ButtonGroup extends Widget {
|
|
|
|
|
this.empty(); |
|
|
|
|
this.options.items = items; |
|
|
|
|
|
|
|
|
|
this.buttons = this._btnsCreator.apply(this, arguments); |
|
|
|
|
this.buttons = this._btnsCreator(...arguments); |
|
|
|
|
if (this._isSimpleLayout()) { |
|
|
|
|
items = this._packageSimpleItems(this.buttons); |
|
|
|
|
} else { |
|
|
|
|