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

91 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../../module';
import Input from '../../lib/input';
import asignProps from '../../lib/asign-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');
this.valueField = 'id';
this.showField = 'name';
}
getFields() {
let fields = [];
fields.push(this.valueField);
fields.push(this.showField);
if (this.selectFields)
for (let field of this.selectFields)
fields.push(field);
return fields;
}
onClick(event) {
event.preventDefault();
this.showDropDown();
}
onDropDownSelect(value) {
this.field = value;
if (this.onChange)
this.onChange({value});
}
2017-11-23 13:09:38 +00:00
showDropDown() {
Object.assign(this.$.dropDown.$.model, {
url: this.url,
staticData: this.data
});
asignProps(this, this.$.dropDown, [
'valueField',
'showField',
'where',
'order',
'showFilter',
'multiple',
'limit',
'$transclude',
'translateFields'
]);
this.$.dropDown.selectFields = this.getFields();
this.$.dropDown.parent = this.input;
this.$.dropDown.show();
}
}
IconMenu.$inject = ['$element', '$scope', '$transclude'];
2018-02-10 15:18:01 +00:00
ngModule.component('vnIconMenu', {
template: require('./icon-menu.html'),
bindings: {
url: '@?',
data: '<?',
showField: '@?',
valueField: '@?',
selectFields: '<?',
disabled: '<?',
where: '@?',
order: '@?',
label: '@',
initialData: '<?',
field: '=?',
limit: '<?',
showFilter: '<?',
selection: '<?',
multiple: '<?',
onChange: '&?',
icon: '@?',
translateFields: '<?'
},
transclude: {
tplItem: '?tplItem'
},
controller: IconMenu
});