UNPKG

armisa-models

Version:
141 lines (140 loc) 6.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TabbingControl = exports.TabingValuesClass = void 0; const BaseSelfControl_1 = require("../SelfModels/BaseSelfControl"); const ElementsOfFormFactory_1 = require("./ElementsOfFormFactory"); class TabingValuesClass { constructor(propertyName, control, tabIndex, isStatusbarOfStackControl) { this.propertyName = propertyName; this.control = control; this.tabIndex = tabIndex; this.isStatusbarOfStackControl = isStatusbarOfStackControl; } } exports.TabingValuesClass = TabingValuesClass; class TabbingControl { constructor(pageData) { this.pageData = pageData; this.controls = []; this.addControl = (propertyName, value, tabIndex, isStatusbarOfStackControl) => { const control = this.controls.find((i) => i.propertyName === propertyName); if (control) { return; } const newControl = new TabingValuesClass(propertyName, value, tabIndex, isStatusbarOfStackControl); this.controls.push(newControl); this.controls.sort((a, b) => a.tabIndex - b.tabIndex); if (this.pageData.mainStacksFactory && this.pageData.mainStacksFactory.currentStack) { this.pageData.mainStacksFactory.currentStack.pageData.Eventing.trigger('form.control.new.add', newControl); } else { this.pageData.Eventing.trigger('form.control.new.add', newControl); } }; this.removeControl = (propertyName) => { this.controls = this.controls.filter((i) => i.propertyName !== propertyName); }; this.removeAllControls = () => { this.controls = []; }; this.getCurrentItem = () => { if (this.controls.length) { return this.controls.find((i) => i.tabIndex === this.pageData.activeElementIndex); } return undefined; }; this.gotoNextElementOfStatusBar = () => { const statusBarControl = this.controls.filter(i => i.isStatusbarOfStackControl); if (statusBarControl.length) { let nextItem; const currentIndex = this.pageData.activeElementIndex; if (typeof currentIndex === 'number') { nextItem = statusBarControl.find((i) => i.tabIndex > currentIndex && i.control.tabIndex >= 0 && !i.control.disabled && !i.control.hidden) || statusBarControl[0]; } else { nextItem = statusBarControl[0]; } this.pageData.activeElementIndex = nextItem.tabIndex; nextItem.control.focus(); this.pageData.Eventing.trigger('form.change'); } }; this.gotoPreviousElementOfStatusBar = () => { const reverse = [...this.controls.filter(i => i.isStatusbarOfStackControl)].reverse(); if (reverse.length) { let previousItem; const currentIndex = this.pageData.activeElementIndex; if (typeof currentIndex === 'number') { previousItem = reverse.find((i) => i.tabIndex < currentIndex && i.control.tabIndex >= 0 && !i.control.disabled && !i.control.hidden) || reverse[0]; } else { previousItem = reverse[0]; } this.pageData.activeElementIndex = previousItem.tabIndex; previousItem.control.focus(); } }; } focuseToThisElement(parameter1) { if (typeof parameter1 === 'number') { const current = this.controls.find((i) => i.tabIndex === parameter1); if (current) { current.control.focus(); } } else if (typeof parameter1 === 'string') { const current = this.controls.find((i) => i.propertyName === parameter1); if (current) { this.pageData.updateFocuseState(current.tabIndex); } } } updateCurrentIndexByFocusForm(element) { if (this.pageData.selfState && this.pageData.selfState.elementsOfForm instanceof ElementsOfFormFactory_1.ElementsOfFormFactory) { this.pageData.selfState.elementsOfForm.updateCurrentIndexByFocusForm(element); } else { const current = this.controls.find((i) => i.control === element); if (current) { this.pageData.updateFocuseState(current.tabIndex); } } } gotoNextElementByEnter() { if (this.controls.length) { const currentItem = this.controls.find((i) => i.tabIndex === this.pageData.activeElementIndex); if (currentItem) { if (!this.pageData.selfState) { return; } const property = this.pageData.selfState[currentItem.propertyName]; if (property instanceof BaseSelfControl_1.BaseSelfControl) { property.validate(); if (property.validation instanceof Array) { if (property.onErrorSimulateKey) { this.pageData.selfState.codeSimulateKeyDown(property.onErrorSimulateKey, currentItem.propertyName); } else { this.pageData.Eventing.trigger('form.controlValueNotValid', property.validation); } return; } } } } this.gotoNextElement(); } gotoNextElement() { } gotoPreviousElement() { } } exports.TabbingControl = TabbingControl;