2017-06-13 11:08:06 +00:00
|
|
|
import {module} from '../module';
|
2017-06-15 09:22:47 +00:00
|
|
|
import './style.scss';
|
2017-06-13 11:08:06 +00:00
|
|
|
|
|
|
|
export default class IconMenu {
|
|
|
|
constructor($element, $http, $timeout) {
|
|
|
|
this.$element = $element;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$timeout = $timeout;
|
|
|
|
this._showDropDown = false;
|
2017-06-29 12:28:22 +00:00
|
|
|
this.finding = false;
|
2017-07-03 06:38:45 +00:00
|
|
|
this.findMore = false;
|
2017-09-14 11:40:55 +00:00
|
|
|
this.element = $element[0];
|
2017-06-13 11:08:06 +00:00
|
|
|
}
|
|
|
|
get showDropDown() {
|
|
|
|
return this._showDropDown;
|
|
|
|
}
|
|
|
|
set showDropDown(value) {
|
|
|
|
this._showDropDown = value;
|
|
|
|
}
|
2017-06-29 11:56:52 +00:00
|
|
|
findItems(search) {
|
|
|
|
if (!this.url)
|
|
|
|
return this.items ? this.items : [];
|
|
|
|
|
2017-06-29 12:28:22 +00:00
|
|
|
if (search && !this.finding) {
|
2017-06-29 11:56:52 +00:00
|
|
|
let filter = {where: {name: {regexp: search}}};
|
|
|
|
let json = JSON.stringify(filter);
|
2017-06-29 12:28:22 +00:00
|
|
|
this.finding = true;
|
2017-06-29 11:56:52 +00:00
|
|
|
this.$http.get(`${this.url}?filter=${json}`).then(
|
|
|
|
json => {
|
|
|
|
this.items = json.data;
|
2017-06-29 12:28:22 +00:00
|
|
|
this.finding = false;
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.finding = false;
|
2017-06-29 11:56:52 +00:00
|
|
|
}
|
|
|
|
);
|
2017-06-29 12:28:22 +00:00
|
|
|
} else if (!search && !this.finding) {
|
2017-09-14 11:40:55 +00:00
|
|
|
this.maxRow = 10;
|
2017-06-29 11:56:52 +00:00
|
|
|
this.items = [];
|
|
|
|
this.getItems();
|
|
|
|
}
|
|
|
|
}
|
2017-06-13 11:08:06 +00:00
|
|
|
getItems() {
|
2017-06-29 11:56:52 +00:00
|
|
|
let filter = {};
|
|
|
|
|
|
|
|
if (this.maxRow) {
|
|
|
|
if (this.items) {
|
|
|
|
filter.skip = this.items.length;
|
|
|
|
}
|
|
|
|
filter.limit = this.maxRow;
|
|
|
|
filter.order = 'name ASC';
|
|
|
|
}
|
|
|
|
|
|
|
|
let json = JSON.stringify(filter);
|
|
|
|
|
|
|
|
this.$http.get(`${this.url}?filter=${json}`).then(
|
2017-06-13 11:08:06 +00:00
|
|
|
json => {
|
2017-06-29 11:56:52 +00:00
|
|
|
if (json.data.length)
|
|
|
|
json.data.forEach(
|
|
|
|
el => {
|
|
|
|
this.items.push(el);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
else
|
|
|
|
this.maxRow = false;
|
2017-06-13 11:08:06 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$onInit() {
|
|
|
|
if (!this.items && this.url) {
|
2017-06-29 11:56:52 +00:00
|
|
|
this.items = [];
|
2017-06-13 11:08:06 +00:00
|
|
|
this.getItems();
|
|
|
|
}
|
|
|
|
|
2017-07-03 06:38:45 +00:00
|
|
|
this.findMore = this.url && this.maxRow;
|
|
|
|
|
2017-06-15 05:45:01 +00:00
|
|
|
this.$element.bind('mouseover', e => {
|
2017-06-13 11:08:06 +00:00
|
|
|
this.$timeout(() => {
|
|
|
|
this.showDropDown = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$element.bind('mouseout', () => {
|
|
|
|
this.$timeout(() => {
|
|
|
|
this.showDropDown = false;
|
|
|
|
});
|
|
|
|
});
|
2017-09-14 11:40:55 +00:00
|
|
|
this.$element.bind('focusin', e => {
|
|
|
|
this.$timeout(() => {
|
|
|
|
this.showDropDown = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.$element.bind('focusout', e => {
|
|
|
|
this.$timeout(() => {
|
|
|
|
this.showDropDown = false;
|
|
|
|
});
|
|
|
|
});
|
2017-06-13 11:08:06 +00:00
|
|
|
}
|
2017-09-14 11:40:55 +00:00
|
|
|
|
2017-06-15 05:45:01 +00:00
|
|
|
$onDestroy() {
|
|
|
|
this.$element.unbind('mouseover');
|
|
|
|
this.$element.unbind('mouseout');
|
2017-09-14 11:40:55 +00:00
|
|
|
this.$element.unbind('focusin');
|
|
|
|
this.$element.unbind('focusout');
|
2017-06-15 05:45:01 +00:00
|
|
|
}
|
2017-06-13 11:08:06 +00:00
|
|
|
}
|
|
|
|
IconMenu.$inject = ['$element', '$http', '$timeout'];
|
|
|
|
|
|
|
|
module.component('vnIconMenu', {
|
|
|
|
template: require('./icon-menu.html'),
|
|
|
|
bindings: {
|
|
|
|
url: '@?',
|
2017-06-15 13:00:43 +00:00
|
|
|
items: '<?',
|
2017-06-13 11:08:06 +00:00
|
|
|
icon: '@',
|
2017-06-29 11:56:52 +00:00
|
|
|
maxRow: '@?',
|
2017-06-13 11:08:06 +00:00
|
|
|
selected: '='
|
|
|
|
},
|
2017-06-15 13:00:43 +00:00
|
|
|
controller: IconMenu
|
2017-06-13 11:08:06 +00:00
|
|
|
});
|