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