UNPKG

armisa-models

Version:
69 lines (61 loc) 1.89 kB
import { BasePageData } from './BasePageData'; class ChangeValuesClass { constructor(public propertyName: string, public disabled: boolean) { } } export class ChangingControl { public controls: ChangeValuesClass[] = []; constructor(public pageData: BasePageData) { } addControl = (propName: string) => { const control = this.controls.find((i) => i.propertyName === propName); if (control) { control.disabled = false; return; } if ( this.pageData.selfState && this.pageData.selfState[propName] !== undefined && this.pageData.selfState[propName].hasChange ) { const newData = new ChangeValuesClass(propName, false); this.controls.push(newData); } }; disabledControl = <S>(propertyName: keyof S) => { const control = this.controls.find((i) => i.propertyName === propertyName); if (control) { control.disabled = true; } }; removeAllControls = () => { this.controls = []; }; refreshChangeState = (propertyName: string) => { if ( this.pageData.selfState && this.pageData.selfState[propertyName] !== undefined ) { const value = this.pageData.selfState[propertyName]; if (value.showHasChangeFlag) { if (value.hasChange) { this.addControl(propertyName); } else { this.controls = this.controls.filter( (i) => i.propertyName !== propertyName ); } this.pageData.updateHasChange(); } } }; resetAllChange = () => { this.controls.forEach((control) => this.pageData.selfState[control.propertyName].restartDefaultValue() ); this.controls = []; this.pageData.updateHasChange(); }; resetAllChangeNew = () => { this.controls = []; this.pageData.updateHasChange(); }; }