salix/front/core/components/button-menu/index.js

106 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

import ngModule from '../../module';
2019-10-18 19:36:30 +00:00
import Button from '../button';
import assignProps from '../../lib/assign-props';
import './style.scss';
2019-10-18 19:36:30 +00:00
export default class ButtonMenu extends Button {
constructor($element, $scope, $transclude) {
super($element, $scope);
this.$transclude = $transclude;
2019-11-10 10:08:44 +00:00
$element.on('click', e => this.onButtonClick(e));
}
get model() {
return this._model;
}
set model(value) {
this.dropDownAssign({model: value});
}
get data() {
return this._data;
}
set data(value) {
this.dropDownAssign({data: value});
}
get url() {
return this._url;
}
set url(value) {
this.dropDownAssign({url: value});
}
dropDownAssign(props) {
for (let prop in props)
this[`_${prop}`] = props[prop];
if (this.$.dropDown)
Object.assign(this.$.dropDown, props);
}
2019-11-10 10:08:44 +00:00
onButtonClick(event) {
2019-01-21 14:21:24 +00:00
if (event.defaultPrevented) return;
this.emit('open');
this.showDropDown();
}
onDropDownSelect(item) {
const value = item[this.valueField];
this.field = value;
this.emit('change', {value});
}
showDropDown() {
this.$.dropDown.copySlot('tplItem', this.$transclude);
assignProps(this, this.$.dropDown, [
'valueField',
'showField',
'showFilter',
'multiple',
'translateFields',
'model',
'data',
'url',
'fields',
'include',
'where',
'order',
'limit',
'searchFunction'
]);
2019-01-21 14:21:24 +00:00
this.$.dropDown.show(this.element);
}
}
ButtonMenu.$inject = ['$element', '$scope', '$transclude'];
2019-10-18 19:36:30 +00:00
ngModule.vnComponent('vnButtonMenu', {
template: require('./index.html'),
controller: ButtonMenu,
bindings: {
showField: '@?',
selection: '<?',
valueField: '@?',
selectFields: '<?',
initialData: '<?',
showFilter: '<?',
2023-01-31 09:37:18 +00:00
fields: '<?',
field: '=?',
url: '@?',
data: '<?',
where: '@?',
order: '@?',
limit: '<?',
multiple: '<?',
onChange: '&?',
translateFields: '<?',
onOpen: '&?'
},
transclude: {
tplItem: '?tplItem'
2019-10-18 19:36:30 +00:00
}
});