salix/client/core/src/components/icon-menu/icon-menu.js

106 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../../module';
import Input from '../../lib/input';
2018-10-18 07:24:20 +00:00
import assignProps from '../../lib/assign-props';
import './style.scss';
export default class IconMenu extends Input {
constructor($element, $scope, $transclude) {
super($element, $scope);
this.$transclude = $transclude;
this.input = this.element.querySelector('.mdl-button');
}
2018-10-22 06:23:10 +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) {
event.preventDefault();
2018-10-18 18:48:21 +00:00
this.emit('open');
this.showDropDown();
}
onDropDownSelect(value) {
this.field = value;
2018-10-18 18:48:21 +00:00
this.emit('change', {value});
}
2017-11-23 13:09:38 +00:00
showDropDown() {
2018-10-18 07:24:20 +00:00
assignProps(this, this.$.dropDown, [
'valueField',
'showField',
'showFilter',
'multiple',
'$transclude',
2018-10-18 07:24:20 +00:00
'translateFields',
'model',
'data',
'url',
'fields',
'include',
'where',
'order',
'limit',
'searchFunction'
]);
2018-10-18 07:24:20 +00:00
this.$.dropDown.show(this.input);
}
}
IconMenu.$inject = ['$element', '$scope', '$transclude'];
2018-02-10 15:18:01 +00:00
ngModule.component('vnIconMenu', {
template: require('./icon-menu.html'),
bindings: {
2018-10-18 07:24:20 +00:00
label: '@',
showField: '@?',
2018-10-18 07:24:20 +00:00
selection: '<?',
valueField: '@?',
selectFields: '<?',
disabled: '<?',
initialData: '<?',
2018-10-18 07:24:20 +00:00
showFilter: '<?',
field: '=?',
2018-10-18 07:24:20 +00:00
url: '@?',
data: '<?',
where: '@?',
order: '@?',
limit: '<?',
multiple: '<?',
onChange: '&?',
icon: '@?',
translateFields: '<?',
onOpen: '&?'
},
transclude: {
tplItem: '?tplItem'
},
controller: IconMenu
});