UNPKG

armisa-models

Version:
199 lines (198 loc) 8.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MainStacksFactory = void 0; const BaseSelfControl_1 = require("../SelfModels/BaseSelfControl"); const BasePageData_1 = require("../Page/BasePageData"); const Stack_1 = require("./Stack"); const TabData_1 = require("../Page/Tab/TabData"); class MainStacksFactory { constructor(pageData) { this.pageData = pageData; this.initializeFormStartPage = false; this.initializeHookStartPage = false; this.initializeTabsOfStacks = false; this.initializeStatusBarIcons = false; this.initializeTabPage = false; this.currentStackMainDivHead = null; this.updateTextOfStackHeaderInitial = () => { let currentPageData; if (this.currentStack) { currentPageData = this.currentStack.pageData; } else { currentPageData = this.pageData; } if (currentPageData.selfState && currentPageData.selfState.inittializeStackHeaderText) { if (!(currentPageData.stackHeaderFields && currentPageData.stackHeaderFields.length)) { currentPageData.selfState.inittializeStackHeaderText().forEach((i) => { currentPageData.addStackHeadersField(i); }); } } if (currentPageData.stackHeaderFields && currentPageData.stackHeaderFields.length) { let stackHeaderText = ''; currentPageData.stackHeaderFields.forEach(i => { const caption = i.caption ? i.caption + ':' : ''; const field = currentPageData.selfState[i.fieldName]; let value; if (field instanceof BaseSelfControl_1.BaseSelfControl) { value = field.value ? field.value.toString() : ''; } else if (typeof field === 'string') { value = field; } else if (typeof field === 'number') { value = field.toString(); } if (value) { if (value.length > 20) { value = value.substring(0, 17) + '...'; } if (stackHeaderText) { stackHeaderText += ' - ' + caption + value; } else { stackHeaderText += caption + value; } } }); if (stackHeaderText) { if (!currentPageData.defaultCaptionOfPage) { currentPageData.defaultCaptionOfPage = currentPageData.caption; } currentPageData.caption = stackHeaderText; this.trigger('stack.header.text.refresh'); } else if (currentPageData.defaultCaptionOfPage) { currentPageData.caption = currentPageData.defaultCaptionOfPage; this.trigger('stack.header.text.refresh'); } } }; this.updateTextOfStackHeader = (changeHeadOfStack) => { if (typeof changeHeadOfStack !== 'number') { return; } let currentPageData; if (this.currentStack) { currentPageData = this.currentStack.pageData; } else { currentPageData = this.pageData; } if (currentPageData.stackHeaderFields && currentPageData.stackHeaderFields.length) { let stackHeaderText = ''; currentPageData.stackHeaderFields.forEach(i => { const caption = i.caption ? i.caption + ':' : ''; const field = currentPageData.selfState[i.fieldName]; let value; if (field instanceof BaseSelfControl_1.BaseSelfControl) { value = field.value ? field.value.toString() : ''; } if (value) { if (value.length > 20) { value = value.substring(0, 17) + '...'; } if (stackHeaderText) { stackHeaderText += ' - ' + caption + value; } else { stackHeaderText += caption + value; } } }); if (stackHeaderText) { if (!currentPageData.defaultCaptionOfPage) { currentPageData.defaultCaptionOfPage = currentPageData.caption; } currentPageData.caption = stackHeaderText; this.trigger('stack.header.text.refresh'); } else if (currentPageData.defaultCaptionOfPage) { currentPageData.caption = currentPageData.defaultCaptionOfPage; this.trigger('stack.header.text.refresh'); } } }; this.stacks = []; this.gotoMainStack = () => { if (!this.currentStack) { return; } this.currentStack.stackWillUnMount(); this.currentStack.pageData.stackHeaderFields = undefined; this.currentStack = undefined; this.trigger('stack.get.active'); }; this.selectThisStack = (stack) => { if (this.currentStack === stack) { return; } if (this.currentStack) { this.currentStack.stackWillUnMount(); stack.pageData.stackHeaderFields = undefined; } this.currentStack = stack; this.trigger('stack.get.active', stack); }; this.closeThisStack = (stack) => { stack.stackWillUnMount(); stack.isDeleted = this.stacks.filter((s) => s.isDeleted).length + 1; let notDeleted = this.stacks.filter((s) => !s.isDeleted); if (notDeleted.length) { this.currentStack = notDeleted[notDeleted.length - 1]; this.currentStack.pageData.stackHeaderFields = undefined; } else { this.currentStack = undefined; } stack.pageData.stackHeaderFields = undefined; this.trigger('stack.closed', stack); }; this.trigger = (eventName, ...args) => { this.pageData.Eventing.triggerControl(eventName, `stack-${this.pageData.id}-0`, args); }; this.on = (eventName, callBack) => { this.pageData.Eventing.onControl(eventName, `stack-${this.pageData.id}-0`, callBack); }; this.removeOn = (eventName) => { this.pageData.Eventing.removeOnControl(eventName, `stack-${this.pageData.id}-0`); }; this.addNewStack = (...args) => { const [pageKey, props, caption, stackHeaderFields] = args; const newTab = new TabData_1.TabPageData(this.pageData.mainStateManager); const stackFactory = new Stack_1.StackFactory(newTab, this); newTab.pageKey = pageKey; newTab.props = props; if (typeof caption === 'string') { newTab.caption = caption; } else if (caption instanceof Array) { newTab.caption = this.pageData.mainStateManager.getCaptionNaming(caption); } else { // newTab.caption = this.pageData.mainStateManager.MenuIteming.getCaptionOfPage(newTab.pageKey); } if (stackHeaderFields) { if (stackHeaderFields instanceof Array) { stackHeaderFields.forEach(i => { if (i instanceof BasePageData_1.StackHeaderFields) { newTab.addStackHeadersField(i); } }); } } if (props) { if (props.headId) { newTab.caption += ` ${props.headId}`; } } newTab.mainStacksFactory = this; this.stacks.push(stackFactory); this.currentStack = stackFactory; this.trigger('stack.add.new', newTab); }; } static buildNew(pageData) { return new MainStacksFactory(pageData); } } exports.MainStacksFactory = MainStacksFactory;