salix/client/core/src/drop-down/drop-down.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

import {module} from '../module';
import './style.scss';
export default class DropDown {
constructor($element, $filter) {
this.$element = $element;
this.$filter = $filter;
this.search = '';
this.itemsFiltered = [];
}
filterItems() {
this.itemsFiltered = this.search ? this.$filter('filter')(this.items, this.search) : this.items;
2017-06-29 06:13:30 +00:00
}
onFilterRest() {
this.showLoadMore = false;
if (this.filterAction) {
this.filterAction({search: this.search});
}
2017-06-29 06:13:30 +00:00
}
$onChanges(changesObj) {
if (changesObj.show && changesObj.top && changesObj.top.currentValue) {
this.$element.css('top', changesObj.top.currentValue + 'px');
}
if (changesObj.items) {
this.filterItems();
2017-06-29 06:13:30 +00:00
}
}
clearSearch() {
this.search = '';
this.showLoadMore = this.loadMore != null;
if (this.filterAction) {
this.filterAction();
}
}
}
DropDown.$inject = ['$element', '$filter'];
module.component('vnDropDown', {
template: require('./drop-down.html'),
controller: DropDown,
bindings: {
items: '<',
show: '<',
2017-06-21 11:16:37 +00:00
filter: '@?',
selected: '=',
2017-06-29 06:13:30 +00:00
loadMore: '&?',
filterAction: '&?',
showLoadMore: '<?',
top: '<?'
2017-06-21 11:16:37 +00:00
}
});