import $ from "jquery"; import FormDispatcher from '@enhavo/app/form/FormDispatcher'; export default class FormInitializer { private html: string; private element: HTMLElement; private converted: boolean = false; private released: boolean = false; private inserted: boolean = false; public setHtml(html: string) { this.html = html.trim(); } public setElement(element: HTMLElement) { this.element = element; } public getElement(): HTMLElement { return this.element; } public insertBefore(element: HTMLElement) { this.insert(); $(this.element).insertBefore(element); this.release(); } public insertAfter(element: HTMLElement) { this.insert(); $(this.element).insertAfter(element); this.release(); } public append(element: HTMLElement) { this.insert(); $(element).append(this.element); this.release(); } public convert() { if(!this.converted) { this.converted = true; if(this.html) { this.html = FormDispatcher.dispatchConvert(this.html).getHtml(); this.element = $($.parseHTML(this.html)).get(0); } } } public release() { if(!this.inserted) { this.insert(); } if(!this.released) { this.released = true; this.element = FormDispatcher.dispatchRelease(this.element).getElement(); } } public init() { this.release(); } public insert() { if(!this.inserted) { this.inserted = true; if(!this.converted) { this.convert(); } this.element = FormDispatcher.dispatchInsert(this.element).getElement(); } } }