forked from fanruan/fineui
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.
78 lines
2.1 KiB
78 lines
2.1 KiB
import { shortcut, Widget, extend, createWidget, Controller, Events, contains } from "@/core"; |
|
import { Expander } from "@/base"; |
|
|
|
@shortcut() |
|
export class SelectTreeExpander extends Widget { |
|
static xtype = "bi.select_tree_expander"; |
|
|
|
_defaultConfig() { |
|
return extend(super._defaultConfig(...arguments), { |
|
baseCls: "bi-select-tree-expander", |
|
trigger: "", |
|
toggle: true, |
|
direction: "bottom", |
|
isDefaultInit: true, |
|
el: {}, |
|
popup: {}, |
|
}); |
|
} |
|
|
|
_init() { |
|
super._init(...arguments); |
|
const self = this, |
|
o = this.options; |
|
|
|
this.trigger = createWidget(o.el); |
|
this.trigger.on(Controller.EVENT_CHANGE, function (type) { |
|
if (type === Events.CLICK) { |
|
if (this.isSelected()) { |
|
self.expander.setValue([]); |
|
} |
|
} |
|
self.fireEvent(Controller.EVENT_CHANGE, arguments); |
|
}); |
|
|
|
this.expander = createWidget({ |
|
type: Expander.xtype, |
|
element: this, |
|
trigger: o.trigger, |
|
toggle: o.toggle, |
|
direction: o.direction, |
|
isDefaultInit: o.isDefaultInit, |
|
el: this.trigger, |
|
popup: o.popup, |
|
}); |
|
this.expander.on(Controller.EVENT_CHANGE, function (type) { |
|
if (type === Events.CLICK) { |
|
self.trigger.setSelected(false); |
|
} |
|
self.fireEvent(Controller.EVENT_CHANGE, arguments); |
|
}); |
|
} |
|
|
|
getAllLeaves() { |
|
return this.expander.getAllLeaves(); |
|
} |
|
|
|
setValue(v) { |
|
if (contains(v, this.trigger.getValue())) { |
|
this.trigger.setSelected(true); |
|
this.expander.setValue([]); |
|
} else { |
|
this.trigger.setSelected(false); |
|
this.expander.setValue(v); |
|
} |
|
} |
|
|
|
getValue() { |
|
if (this.trigger.isSelected()) { |
|
return [this.trigger.getValue()]; |
|
} |
|
|
|
return this.expander.getValue(); |
|
} |
|
|
|
populate(items) { |
|
this.expander.populate(items); |
|
} |
|
}
|
|
|