2018-10-18 07:24:20 +00:00
|
|
|
import './style.scss';
|
2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../../module';
|
2019-10-28 16:31:33 +00:00
|
|
|
import Popover from '../popover';
|
2018-10-18 07:24:20 +00:00
|
|
|
import ArrayModel from '../array-model/array-model';
|
|
|
|
import CrudModel from '../crud-model/crud-model';
|
2018-12-27 11:54:16 +00:00
|
|
|
import {mergeWhere} from 'vn-loopback/util/filter';
|
2019-11-10 10:08:44 +00:00
|
|
|
import focus from '../../lib/focus';
|
2017-06-13 11:08:06 +00:00
|
|
|
|
2018-10-18 07:24:20 +00:00
|
|
|
/**
|
|
|
|
* @event select Thrown when model item is selected
|
|
|
|
* @event change Thrown when model data is ready
|
|
|
|
*/
|
2019-10-28 16:31:33 +00:00
|
|
|
export default class DropDown extends Popover {
|
|
|
|
constructor($element, $, $transclude) {
|
|
|
|
super($element, $, $transclude);
|
2018-03-09 13:15:30 +00:00
|
|
|
this.valueField = 'id';
|
2018-10-18 18:48:21 +00:00
|
|
|
this.showField = 'name';
|
2018-03-09 13:15:30 +00:00
|
|
|
this._search = undefined;
|
2017-09-14 11:40:55 +00:00
|
|
|
this._activeOption = -1;
|
2018-03-09 13:15:30 +00:00
|
|
|
this.showLoadMore = true;
|
|
|
|
this.showFilter = true;
|
2019-10-28 16:31:33 +00:00
|
|
|
this.searchDelay = 300;
|
2017-10-04 06:47:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 11:40:55 +00:00
|
|
|
get search() {
|
|
|
|
return this._search;
|
|
|
|
}
|
2017-10-04 06:47:16 +00:00
|
|
|
|
2017-09-14 11:40:55 +00:00
|
|
|
set search(value) {
|
2020-03-24 13:10:07 +00:00
|
|
|
function nullify(value) {
|
|
|
|
return value == '' || value == undefined ? null : value;
|
|
|
|
}
|
|
|
|
|
|
|
|
let oldValue = nullify(this._search);
|
2018-03-09 13:15:30 +00:00
|
|
|
this._search = value;
|
2018-10-18 07:24:20 +00:00
|
|
|
|
|
|
|
if (!this.shown) return;
|
|
|
|
|
2020-03-24 13:10:07 +00:00
|
|
|
value = nullify(value);
|
2018-10-18 07:24:20 +00:00
|
|
|
if (value === oldValue && this.modelData != null) return;
|
2018-03-09 13:15:30 +00:00
|
|
|
|
2018-03-17 12:17:48 +00:00
|
|
|
if (value != null)
|
|
|
|
this._activeOption = 0;
|
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
this.$timeout.cancel(this.searchTimeout);
|
2018-10-18 07:24:20 +00:00
|
|
|
|
|
|
|
if (this.model) {
|
|
|
|
this.model.clear();
|
2020-03-24 13:10:07 +00:00
|
|
|
|
|
|
|
if (this.model instanceof CrudModel) {
|
2018-11-20 15:36:37 +00:00
|
|
|
this.searchTimeout = this.$timeout(() => {
|
|
|
|
this.refreshModel();
|
|
|
|
this.searchTimeout = null;
|
2019-10-28 16:31:33 +00:00
|
|
|
}, value != null ? this.searchDelay : 0);
|
2018-11-20 15:36:37 +00:00
|
|
|
} else
|
2018-10-18 07:24:20 +00:00
|
|
|
this.refreshModel();
|
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
this.buildList();
|
|
|
|
}
|
|
|
|
|
|
|
|
get statusText() {
|
2018-10-18 07:24:20 +00:00
|
|
|
let model = this.model;
|
|
|
|
let data = this.modelData;
|
2018-03-09 13:15:30 +00:00
|
|
|
|
2018-10-18 07:24:20 +00:00
|
|
|
if (!model)
|
|
|
|
return 'No data';
|
2018-03-09 13:15:30 +00:00
|
|
|
if (model.isLoading || this.searchTimeout)
|
2018-10-18 07:24:20 +00:00
|
|
|
return 'Loading...';
|
|
|
|
if (data == null)
|
|
|
|
return 'No data';
|
|
|
|
if (model.moreRows)
|
|
|
|
return 'Load More';
|
|
|
|
if (data.length === 0)
|
|
|
|
return 'No results found';
|
|
|
|
|
|
|
|
return null;
|
2017-09-14 11:40:55 +00:00
|
|
|
}
|
2017-10-04 06:47:16 +00:00
|
|
|
|
2017-09-14 11:40:55 +00:00
|
|
|
get activeOption() {
|
|
|
|
return this._activeOption;
|
|
|
|
}
|
2017-10-04 06:47:16 +00:00
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
/**
|
|
|
|
* Shows the drop-down. If a parent is specified it is shown in a visible
|
|
|
|
* relative position to it.
|
|
|
|
*
|
2018-10-18 07:24:20 +00:00
|
|
|
* @param {HTMLElement} parent The parent element to show drop down relative to
|
2018-03-09 13:15:30 +00:00
|
|
|
* @param {String} search The initial search term or %null
|
|
|
|
*/
|
2018-10-18 07:24:20 +00:00
|
|
|
show(parent, search) {
|
2019-11-10 10:08:44 +00:00
|
|
|
if (this.shown) return;
|
2019-10-28 16:31:33 +00:00
|
|
|
super.show(parent);
|
|
|
|
|
2019-11-10 10:08:44 +00:00
|
|
|
this._activeOption = -1;
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
this.list = this.popup.querySelector('.list');
|
|
|
|
this.ul = this.popup.querySelector('ul');
|
|
|
|
|
|
|
|
this.docKeyDownHandler = e => this.onDocKeyDown(e);
|
|
|
|
this.document.addEventListener('keydown', this.docKeyDownHandler);
|
|
|
|
|
|
|
|
this.listScrollHandler = e => this.onScroll(e);
|
|
|
|
this.list.addEventListener('scroll', this.listScrollHandler);
|
|
|
|
this.list.scrollTop = 0;
|
|
|
|
|
2019-10-09 22:47:29 +00:00
|
|
|
this.search = search;
|
2019-01-21 14:21:24 +00:00
|
|
|
this.buildList();
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2019-11-10 10:08:44 +00:00
|
|
|
focus(this.popup.querySelector('input'));
|
2017-06-15 05:45:01 +00:00
|
|
|
}
|
2017-06-29 11:56:52 +00:00
|
|
|
|
2019-11-10 10:08:44 +00:00
|
|
|
hide() {
|
|
|
|
if (!this.shown) return;
|
|
|
|
super.hide();
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
this.document.removeEventListener('keydown', this.docKeyDownHandler);
|
|
|
|
this.docKeyDownHandler = null;
|
|
|
|
|
|
|
|
this.list.removeEventListener('scroll', this.listScrollHandler);
|
|
|
|
this.listScrollHandler = null;
|
2019-11-10 10:08:44 +00:00
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2019-11-10 10:08:44 +00:00
|
|
|
onClose() {
|
|
|
|
this.destroyList();
|
2019-10-28 16:31:33 +00:00
|
|
|
this.list = null;
|
|
|
|
this.ul = null;
|
|
|
|
|
|
|
|
super.onClose();
|
2017-11-22 12:10:33 +00:00
|
|
|
}
|
2017-12-12 12:59:31 +00:00
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
/**
|
2018-03-17 12:17:48 +00:00
|
|
|
* Activates an option and scrolls the drop-down to that option.
|
2018-03-09 13:15:30 +00:00
|
|
|
*
|
|
|
|
* @param {Number} option The option index
|
|
|
|
*/
|
|
|
|
moveToOption(option) {
|
|
|
|
this.activateOption(option);
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
let list = this.list;
|
2018-03-09 13:15:30 +00:00
|
|
|
let li = this.activeLi;
|
|
|
|
if (!li) return;
|
|
|
|
|
|
|
|
let liRect = li.getBoundingClientRect();
|
|
|
|
let listRect = list.getBoundingClientRect();
|
|
|
|
|
|
|
|
if (liRect.bottom > listRect.bottom)
|
|
|
|
list.scrollTop += liRect.bottom - listRect.bottom;
|
|
|
|
else if (liRect.top < listRect.top)
|
|
|
|
list.scrollTop -= listRect.top - liRect.top;
|
2017-12-12 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
/**
|
2018-03-17 12:17:48 +00:00
|
|
|
* Activates an option.
|
2018-03-09 13:15:30 +00:00
|
|
|
*
|
|
|
|
* @param {Number} option The option index
|
|
|
|
*/
|
|
|
|
activateOption(option) {
|
|
|
|
this._activeOption = option;
|
|
|
|
|
|
|
|
if (this.activeLi)
|
|
|
|
this.activeLi.className = '';
|
2017-11-23 13:07:55 +00:00
|
|
|
|
2018-10-18 07:24:20 +00:00
|
|
|
let data = this.modelData;
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
if (option >= 0 && data && option < data.length) {
|
2019-10-28 16:31:33 +00:00
|
|
|
this.activeLi = this.ul.children[option];
|
2018-03-09 13:15:30 +00:00
|
|
|
this.activeLi.className = 'active';
|
2017-11-23 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-22 12:10:33 +00:00
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
/**
|
|
|
|
* Selects an option.
|
|
|
|
*
|
|
|
|
* @param {Number} option The option index
|
|
|
|
*/
|
|
|
|
selectOption(option) {
|
2018-10-18 07:24:20 +00:00
|
|
|
let data = this.modelData;
|
2018-03-17 12:17:48 +00:00
|
|
|
let item = option != -1 && data ? data[option] : null;
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
let value = item[this.valueField];
|
2017-11-22 12:10:33 +00:00
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
if (this.multiple) {
|
|
|
|
if (!Array.isArray(this.selection)) {
|
|
|
|
this.selection = [];
|
|
|
|
this.field = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.selection.push(item);
|
|
|
|
this.field.push(value);
|
|
|
|
} else {
|
|
|
|
this.selection = item;
|
|
|
|
this.field = value;
|
2017-11-22 12:10:33 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
2019-06-13 11:08:11 +00:00
|
|
|
this.emit('select', {item});
|
2017-11-22 12:10:33 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
if (!this.multiple)
|
2019-10-28 16:31:33 +00:00
|
|
|
this.hide();
|
2017-09-20 11:52:53 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
onClearClick() {
|
|
|
|
this.search = null;
|
2017-10-03 07:16:02 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
onScroll() {
|
2019-10-28 16:31:33 +00:00
|
|
|
let list = this.list;
|
2018-03-09 13:15:30 +00:00
|
|
|
let shouldLoad =
|
|
|
|
list.scrollTop + list.clientHeight >= (list.scrollHeight - 40)
|
2018-10-18 07:24:20 +00:00
|
|
|
&& !this.model.isLoading;
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
if (shouldLoad)
|
2018-10-18 07:24:20 +00:00
|
|
|
this.model.loadMore();
|
2017-11-22 12:10:33 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
onLoadMoreClick(event) {
|
2019-01-21 14:21:24 +00:00
|
|
|
if (event.defaultPrevented) return;
|
2018-10-18 07:24:20 +00:00
|
|
|
this.model.loadMore();
|
2018-03-09 13:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onContainerClick(event) {
|
|
|
|
if (event.defaultPrevented) return;
|
2019-10-28 16:31:33 +00:00
|
|
|
let index = getPosition(this.ul, event);
|
|
|
|
if (index != -1) this.selectOption(index);
|
2018-03-09 13:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onDocKeyDown(event) {
|
|
|
|
if (event.defaultPrevented) return;
|
|
|
|
|
2018-10-18 07:24:20 +00:00
|
|
|
let data = this.modelData;
|
2018-03-09 13:15:30 +00:00
|
|
|
let option = this.activeOption;
|
|
|
|
let nOpts = data ? data.length - 1 : 0;
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
switch (event.key) {
|
|
|
|
case 'Tab':
|
2018-03-17 12:17:48 +00:00
|
|
|
this.selectOption(option);
|
|
|
|
return;
|
2019-10-28 16:31:33 +00:00
|
|
|
case 'Enter':
|
2018-03-09 13:15:30 +00:00
|
|
|
this.selectOption(option);
|
|
|
|
break;
|
2019-10-28 16:31:33 +00:00
|
|
|
case 'ArrowUp':
|
2018-03-09 13:15:30 +00:00
|
|
|
this.moveToOption(option <= 0 ? nOpts : option - 1);
|
|
|
|
break;
|
2019-10-28 16:31:33 +00:00
|
|
|
case 'ArrowDown':
|
2018-03-09 13:15:30 +00:00
|
|
|
this.moveToOption(option >= nOpts ? 0 : option + 1);
|
|
|
|
break;
|
2019-10-28 16:31:33 +00:00
|
|
|
case 'End':
|
2018-03-09 13:15:30 +00:00
|
|
|
this.moveToOption(nOpts);
|
|
|
|
break;
|
2019-10-28 16:31:33 +00:00
|
|
|
case 'Home':
|
2018-03-09 13:15:30 +00:00
|
|
|
this.moveToOption(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2017-11-22 12:10:33 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
this.$.$applyAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
buildList() {
|
2018-10-18 07:24:20 +00:00
|
|
|
if (!this.shown) return;
|
2018-03-12 11:31:50 +00:00
|
|
|
this.destroyList();
|
2018-03-09 13:15:30 +00:00
|
|
|
|
2018-06-19 07:06:04 +00:00
|
|
|
let hasTemplate = this.$transclude && this.$transclude.isSlotFilled('tplItem');
|
2018-03-09 13:15:30 +00:00
|
|
|
let fragment = this.document.createDocumentFragment();
|
2018-10-18 07:24:20 +00:00
|
|
|
let data = this.modelData;
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
if (data) {
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
2018-06-19 07:06:04 +00:00
|
|
|
let option = data[i];
|
2019-04-26 10:41:30 +00:00
|
|
|
option.orgShowField = option[this.showField];
|
2018-06-19 07:06:04 +00:00
|
|
|
|
|
|
|
if (this.translateFields) {
|
|
|
|
option = Object.assign({}, option);
|
|
|
|
for (let field of this.translateFields)
|
|
|
|
option[field] = this.$translate.instant(option[field]);
|
|
|
|
}
|
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
let li = this.document.createElement('li');
|
2019-04-26 06:52:43 +00:00
|
|
|
|
2019-04-26 10:41:30 +00:00
|
|
|
li.setAttribute('name', option.orgShowField);
|
2018-03-09 13:15:30 +00:00
|
|
|
fragment.appendChild(li);
|
|
|
|
|
|
|
|
if (this.multiple) {
|
|
|
|
let check = this.document.createElement('input');
|
|
|
|
check.type = 'checkbox';
|
|
|
|
li.appendChild(check);
|
|
|
|
|
2018-06-19 07:06:04 +00:00
|
|
|
if (this.field && this.field.indexOf(option[this.valueField]) != -1)
|
2018-03-09 13:15:30 +00:00
|
|
|
check.checked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasTemplate) {
|
|
|
|
this.$transclude((clone, scope) => {
|
2018-06-19 07:06:04 +00:00
|
|
|
Object.assign(scope, option);
|
2018-03-09 13:15:30 +00:00
|
|
|
li.appendChild(clone[0]);
|
|
|
|
this.scopes[i] = scope;
|
|
|
|
}, null, 'tplItem');
|
|
|
|
} else {
|
2018-06-19 07:06:04 +00:00
|
|
|
let text = this.document.createTextNode(option[this.showField]);
|
2018-03-09 13:15:30 +00:00
|
|
|
li.appendChild(text);
|
|
|
|
}
|
|
|
|
}
|
2017-11-22 12:10:33 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
this.ul.appendChild(fragment);
|
2018-03-09 13:15:30 +00:00
|
|
|
this.activateOption(this._activeOption);
|
2019-10-28 16:31:33 +00:00
|
|
|
this.$.$applyAsync(() => this.relocate());
|
2017-11-22 12:10:33 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
2018-03-12 11:31:50 +00:00
|
|
|
destroyList() {
|
2019-10-28 16:31:33 +00:00
|
|
|
if (this.ul)
|
|
|
|
this.ul.innerHTML = '';
|
2018-03-12 11:31:50 +00:00
|
|
|
|
2018-10-31 10:58:10 +00:00
|
|
|
if (this.scopes) {
|
2018-03-09 13:15:30 +00:00
|
|
|
for (let scope of this.scopes)
|
|
|
|
scope.$destroy();
|
2018-10-31 10:58:10 +00:00
|
|
|
}
|
2018-03-12 11:31:50 +00:00
|
|
|
|
|
|
|
this.scopes = [];
|
2017-09-14 11:40:55 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
2018-10-18 07:24:20 +00:00
|
|
|
getFields() {
|
|
|
|
let fields = [];
|
|
|
|
fields.push(this.valueField);
|
|
|
|
fields.push(this.showField);
|
|
|
|
|
2018-10-31 10:58:10 +00:00
|
|
|
if (this.fields) {
|
2018-10-18 07:24:20 +00:00
|
|
|
for (let field of this.fields)
|
|
|
|
fields.push(field);
|
2018-10-31 10:58:10 +00:00
|
|
|
}
|
2018-10-18 07:24:20 +00:00
|
|
|
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Model related code
|
|
|
|
|
|
|
|
onDataChange() {
|
|
|
|
if (this.model.orgData)
|
|
|
|
this.emit('dataReady');
|
|
|
|
this.buildList();
|
|
|
|
}
|
|
|
|
|
|
|
|
get modelData() {
|
|
|
|
return this._model ? this._model.data : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get model() {
|
|
|
|
return this._model;
|
|
|
|
}
|
|
|
|
|
|
|
|
set model(value) {
|
|
|
|
this.linkEvents({_model: value}, {dataChange: this.onDataChange});
|
|
|
|
this.onDataChange();
|
2020-03-24 13:10:07 +00:00
|
|
|
this.search = this.search;
|
2018-10-18 07:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get url() {
|
|
|
|
return this._url;
|
|
|
|
}
|
|
|
|
|
|
|
|
set url(value) {
|
|
|
|
this._url = value;
|
|
|
|
if (value) {
|
2020-03-24 13:10:07 +00:00
|
|
|
let model = new CrudModel(this.$q, this.$http);
|
|
|
|
model.url = value;
|
|
|
|
this.initModel(model);
|
2018-10-18 07:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
return this._data;
|
|
|
|
}
|
|
|
|
|
|
|
|
set data(value) {
|
|
|
|
this._data = value;
|
|
|
|
if (value) {
|
2020-03-24 13:10:07 +00:00
|
|
|
let model = new ArrayModel(this.$q, this.$filter);
|
|
|
|
model.orgData = value;
|
|
|
|
this.initModel(model);
|
2018-10-18 07:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 13:10:07 +00:00
|
|
|
initModel(model) {
|
|
|
|
model.autoLoad = false;
|
|
|
|
model.$onInit();
|
|
|
|
this.model = model;
|
|
|
|
}
|
|
|
|
|
2018-10-18 07:24:20 +00:00
|
|
|
refreshModel() {
|
|
|
|
let model = this.model;
|
|
|
|
|
|
|
|
let order;
|
|
|
|
if (this.order)
|
|
|
|
order = this.order;
|
|
|
|
else if (this.showField)
|
|
|
|
order = `${this.showField} ASC`;
|
|
|
|
|
|
|
|
let filter = {
|
|
|
|
order,
|
2019-11-14 13:37:18 +00:00
|
|
|
limit: this.limit || 30
|
2018-10-18 07:24:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (model instanceof CrudModel) {
|
|
|
|
let searchExpr = this._search == null
|
|
|
|
? null
|
|
|
|
: this.searchFunction({$search: this._search});
|
|
|
|
|
|
|
|
Object.assign(filter, {
|
|
|
|
fields: this.getFields(),
|
|
|
|
include: this.include,
|
|
|
|
where: mergeWhere(this.where, searchExpr)
|
|
|
|
});
|
|
|
|
} else if (model instanceof ArrayModel) {
|
|
|
|
if (this._search != null)
|
|
|
|
filter.where = this.searchFunction({$search: this._search});
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.model.applyFilter(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
searchFunction(scope) {
|
|
|
|
if (this.model instanceof CrudModel)
|
|
|
|
return {[this.showField]: {like: `%${scope.$search}%`}};
|
|
|
|
if (this.model instanceof ArrayModel)
|
|
|
|
return {[this.showField]: scope.$search};
|
|
|
|
}
|
2017-06-15 05:45:01 +00:00
|
|
|
}
|
2017-10-04 06:47:16 +00:00
|
|
|
|
2018-03-09 13:15:30 +00:00
|
|
|
/**
|
|
|
|
* Gets the position of an event element relative to a parent.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} parent The parent element
|
|
|
|
* @param {Event} event The event object
|
|
|
|
* @return {Number} The element index
|
|
|
|
*/
|
|
|
|
function getPosition(parent, event) {
|
|
|
|
let target = event.target;
|
|
|
|
let children = parent.children;
|
|
|
|
|
|
|
|
if (target === parent)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (target.parentNode !== parent)
|
|
|
|
target = target.parentNode;
|
|
|
|
|
2018-10-31 10:58:10 +00:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
2018-03-09 13:15:30 +00:00
|
|
|
if (children[i] === target)
|
|
|
|
return i;
|
2018-10-31 10:58:10 +00:00
|
|
|
}
|
2018-03-09 13:15:30 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2017-06-13 11:08:06 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
ngModule.vnComponent('vnDropDown', {
|
2020-04-25 09:50:04 +00:00
|
|
|
slotTemplate: require('./index.html'),
|
2017-06-15 05:45:01 +00:00
|
|
|
controller: DropDown,
|
2019-10-28 16:31:33 +00:00
|
|
|
transclude: {
|
|
|
|
tplItem: '?tplItem'
|
|
|
|
},
|
2017-06-13 11:08:06 +00:00
|
|
|
bindings: {
|
2018-03-09 13:15:30 +00:00
|
|
|
field: '=?',
|
|
|
|
selection: '=?',
|
|
|
|
search: '<?',
|
2018-06-19 07:06:04 +00:00
|
|
|
showFilter: '<?',
|
2017-09-20 11:52:53 +00:00
|
|
|
parent: '<?',
|
2018-06-19 07:06:04 +00:00
|
|
|
multiple: '<?',
|
|
|
|
onSelect: '&?',
|
2018-10-18 07:24:20 +00:00
|
|
|
translateFields: '<?',
|
|
|
|
data: '<?',
|
|
|
|
url: '@?',
|
|
|
|
fields: '<?',
|
|
|
|
include: '<?',
|
|
|
|
where: '<?',
|
|
|
|
order: '@?',
|
|
|
|
limit: '<?',
|
2019-10-28 16:31:33 +00:00
|
|
|
searchFunction: '&?',
|
|
|
|
searchDelay: '<?'
|
2017-06-21 11:16:37 +00:00
|
|
|
}
|
2017-06-13 11:08:06 +00:00
|
|
|
});
|