2018-11-08 08:20:06 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import Input from '../../lib/input';
|
|
|
|
import assignProps from '../../lib/assign-props';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
export default class ButtonMenu extends Input {
|
|
|
|
constructor($element, $scope, $transclude) {
|
|
|
|
super($element, $scope);
|
|
|
|
this.$transclude = $transclude;
|
|
|
|
this.input = this.element.querySelector('.mdl-button');
|
2019-01-21 14:21:24 +00:00
|
|
|
$element.on('click', e => this.onClick(e));
|
2018-11-08 08:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
onClick(event) {
|
2019-01-21 14:21:24 +00:00
|
|
|
if (event.defaultPrevented) return;
|
2018-11-08 08:20:06 +00:00
|
|
|
event.preventDefault();
|
|
|
|
this.emit('open');
|
|
|
|
this.showDropDown();
|
|
|
|
}
|
|
|
|
|
2019-01-21 14:21:24 +00:00
|
|
|
onDropDownClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:20:06 +00:00
|
|
|
onDropDownSelect(value) {
|
|
|
|
this.field = value;
|
|
|
|
this.emit('change', {value});
|
|
|
|
}
|
|
|
|
|
|
|
|
showDropDown() {
|
|
|
|
assignProps(this, this.$.dropDown, [
|
|
|
|
'valueField',
|
|
|
|
'showField',
|
|
|
|
'showFilter',
|
|
|
|
'multiple',
|
|
|
|
'$transclude',
|
|
|
|
'translateFields',
|
|
|
|
'model',
|
|
|
|
'data',
|
|
|
|
'url',
|
|
|
|
'fields',
|
|
|
|
'include',
|
|
|
|
'where',
|
|
|
|
'order',
|
|
|
|
'limit',
|
|
|
|
'searchFunction'
|
|
|
|
]);
|
2019-01-21 14:21:24 +00:00
|
|
|
this.$.dropDown.show(this.element);
|
2018-11-08 08:20:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ButtonMenu.$inject = ['$element', '$scope', '$transclude'];
|
|
|
|
|
|
|
|
ngModule.component('vnButtonMenu', {
|
|
|
|
template: require('./button-menu.html'),
|
|
|
|
bindings: {
|
|
|
|
label: '@',
|
|
|
|
showField: '@?',
|
|
|
|
selection: '<?',
|
|
|
|
valueField: '@?',
|
|
|
|
selectFields: '<?',
|
|
|
|
disabled: '<?',
|
|
|
|
initialData: '<?',
|
|
|
|
showFilter: '<?',
|
|
|
|
field: '=?',
|
|
|
|
url: '@?',
|
|
|
|
data: '<?',
|
|
|
|
where: '@?',
|
|
|
|
order: '@?',
|
|
|
|
limit: '<?',
|
|
|
|
multiple: '<?',
|
|
|
|
onChange: '&?',
|
|
|
|
icon: '@?',
|
|
|
|
translateFields: '<?',
|
|
|
|
onOpen: '&?'
|
|
|
|
},
|
|
|
|
transclude: {
|
|
|
|
tplItem: '?tplItem'
|
|
|
|
},
|
|
|
|
controller: ButtonMenu
|
|
|
|
});
|