armisa-models
Version:
models of armisa!
186 lines (185 loc) • 7.51 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElementTabbing = void 0;
const ElementFactory_1 = require("../ElementFactory");
const ValidationTabbing_1 = require("./ValidationTabbing");
class MergeElementAndGridEdit {
constructor(element, tabIndex, factory) {
this.element = element;
this.tabIndex = tabIndex;
this.factory = factory;
}
}
class ElementTabbing {
constructor(tabbing) {
this.tabbing = tabbing;
this.isEmpty = () => {
if (!this.getFocusAbleElements) {
return true;
}
else if (this.getFocusAbleElements.length <= 0) {
return true;
}
return false;
};
this.getFocusAbleElements = () => {
const elements = this.focusAbleElements.filter(i => !i.disabled
&& !i.hidden
&& i.element
&& i.element.tabIndex >= 0).map(i => new MergeElementAndGridEdit(i.element, i.tabIndex, i));
const grids = this.tabbing.gridEditTabbing.focusAbleGridEdit.filter(i => typeof i.tabbing.tabIndex === 'number'
&& i.tabbing.refElement
&& i.tabbing.refElement.current
&& i.tabbing.refElement.current.tabIndex >= 0).map(i => new MergeElementAndGridEdit(i.tabbing.refElement.current, i.tabbing.tabIndex, i));
return [...elements, ...grids].sort((a, b) => a.tabIndex - b.tabIndex);
};
this.focus = () => {
let result = false;
result = this.focusToActiveElementTabIndex();
if (result) {
return;
}
result = this.focusToZeroTabIndexElement();
if (result) {
return;
}
result = this.focusToFirstTabIndexElement();
if (result) {
return;
}
this.tabbing.toolboxTabbing.focus(false);
};
this.focusToActiveElementTabIndex = () => {
const find = this.getFocusAbleElements().find(i => i.tabIndex === this.tabbing.activeElementIndex);
if (find && find.element) {
this.setFocus(find);
return true;
}
return false;
};
this.focusToZeroTabIndexOrFirstElementOrToolbox = () => {
let result = false;
result = this.focusToZeroTabIndexElement();
if (result) {
return;
}
result = this.focusToFirstTabIndexElement();
if (result) {
return;
}
this.tabbing.toolboxTabbing.focus(false);
};
this.focusToZeroTabIndexElement = () => {
const find = this.getFocusAbleElements().find(i => i.tabIndex === 0);
if (find && find.element) {
this.setFocus(find);
return true;
}
return false;
};
this.focusToFirstTabIndexElement = () => {
const find = this.getFocusAbleElements()[0];
if (find && find.element) {
this.setFocus(find);
return true;
}
return false;
};
this.focusToMaxTabIndexOrLastElement = () => {
let result = false;
result = this.focusToMaxTabIndexElement();
if (result) {
return;
}
result = this.focusToLastTabIndexElement();
if (result) {
return;
}
this.tabbing.toolboxTabbing.focus(false);
};
this.focusToMaxTabIndexElement = () => {
const tabindexs = this.getFocusAbleElements().map(i => i.tabIndex);
const maxIndex = Math.max(...tabindexs);
return this.focusToElementByTabIndex(maxIndex);
};
this.focusToLastTabIndexElement = () => {
const find = this.getFocusAbleElements()[this.focusAbleElements.length - 1];
if (find && find.element) {
this.setFocus(find);
return true;
}
return false;
};
this.focusToElementByTabIndex = (tabIndex) => {
const find = this.getFocusAbleElements().find(i => i.tabIndex === tabIndex);
if (find && find.element) {
this.setFocus(find);
return true;
}
return false;
};
this.focusToElementByHTMLElement = (element) => {
const find = this.getFocusAbleElements().find(i => i.element === element);
if (find && find.element) {
this.setFocus(find);
return true;
}
return false;
};
// public focusToElementByFactory = (factory: IFocusAbleElementFactory): boolean => {
// const find = this.focusAbleElements.find(i => i === factory);
// if (find && find.element) {
// this.tabbing.activeElementIndex = find.tabIndex;
// find.element.focus();
// return true;
// }
// return false;
// }
this.validateAndFocusNextElement = () => {
const focusAbleElements = this.getFocusAbleElements();
const current = focusAbleElements.find(i => i.tabIndex === this.tabbing.activeElementIndex);
if (current && current instanceof MergeElementAndGridEdit && current.factory && current.factory instanceof ElementFactory_1.ElementFactory) {
ValidationTabbing_1.validationTabbing.gotoNextElement(this.tabbing, current.factory);
}
else {
this.focusNextElement();
}
};
this.focusNextElement = () => {
const focusAbleElements = this.getFocusAbleElements();
const currentIndex = focusAbleElements.findIndex(i => i.tabIndex === this.tabbing.activeElementIndex);
if (currentIndex === focusAbleElements.length - 1) {
this.tabbing.toolboxTabbing.focus(false);
}
else {
const newElement = focusAbleElements[currentIndex + 1];
if (newElement && newElement.element) {
this.setFocus(newElement);
}
}
};
this.focusPreviousElement = () => {
const focusAbleElements = this.getFocusAbleElements();
const currentIndex = focusAbleElements.findIndex(i => i.tabIndex === this.tabbing.activeElementIndex);
if (currentIndex === 0) {
this.tabbing.toolboxTabbing.focus(false);
}
else {
const newElement = focusAbleElements[currentIndex - 1];
if (newElement && newElement.element) {
this.setFocus(newElement);
}
}
};
this.focusAbleElements = [];
}
isThereAnyElement(element) {
const find = this.getFocusAbleElements().find(item => item.element === element);
return find;
}
setFocus(find) {
this.tabbing.activeElementIndex = find.tabIndex;
find.element.focus();
}
}
exports.ElementTabbing = ElementTabbing;