UNPKG

@asoftwareworld/form-builder-pro

Version:

ASW Form Builder Pro helps you with rapid development and designed web forms which includes several controls. The key feature of Form Builder is to make your content attractive and effective. We can customize our control at run time and preview the same b

247 lines (245 loc) 53.6 kB
import * as i0 from '@angular/core'; import { Inject, Component, EventEmitter, Output, Input, NgModule } from '@angular/core'; import { CSSFrameworkEnum } from '@asoftwareworld/form-builder-pro/api'; import * as i11 from '@asoftwareworld/form-builder-pro/common'; import { Constants, Icons, MaterialModule, AswPipeModule } from '@asoftwareworld/form-builder-pro/common'; import { AswConfirmDialog, AswConfirmDialogModule } from '@asoftwareworld/form-builder-pro/form-control/confirm-dialog'; import { ObjectUtils } from '@asoftwareworld/form-builder-pro/utils'; import * as i1 from '@angular/forms'; import { Validators, FormsModule, ReactiveFormsModule } from '@angular/forms'; import * as i2 from '@angular/material/dialog'; import { MAT_DIALOG_DATA } from '@angular/material/dialog'; import * as i3 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i4 from '@angular/material/core'; import * as i5 from '@angular/material/button'; import * as i6 from '@angular/material/input'; import * as i7 from '@angular/material/form-field'; import * as i8 from '@angular/material/select'; import * as i9 from '@angular/material/tooltip'; import * as i10 from '@asoftwareworld/form-builder-pro/core'; import { AswTranslateModule } from '@asoftwareworld/form-builder-pro/core'; /** * @license * Copyright ASW (A Software World) All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file */ class AswCalculationDialog { formBuilder; dialogRef; data; constants = Constants; icons = Icons; aswEditCalculationForm; constructor(formBuilder, dialogRef, data) { this.formBuilder = formBuilder; this.dialogRef = dialogRef; this.data = data; } ngOnInit() { this.validateFormBuilder(); this.editProperty(this.data.control); } validateFormBuilder() { this.aswEditCalculationForm = this.formBuilder.group({ tooltip: [], label: ['', [Validators.required, Validators.minLength(2)]], value: [{ value: '', disabled: true }], style: ['', [Validators.required]], customClass: [], operations: this.formBuilder.array([this.createOperations()]) }); } editProperty(control) { this.aswEditCalculationForm.patchValue({ tooltip: control.tooltip, label: control.label, customClass: control.customClass ?? '', value: control.value, style: control.style }); const operationFormGroup = control.operations.map((operation) => this.formBuilder.group(operation)); const operationFormArray = this.formBuilder.array(operationFormGroup); this.aswEditCalculationForm.setControl('operations', operationFormArray); } get operations() { return this.aswEditCalculationForm.get('operations'); } createOperations() { return this.formBuilder.group({ id: [], label: [], value: [], operationValue: ['', [Validators.required]], control: [''] }); } onNoClick() { this.dialogRef.close(); } addNewOperation() { this.operations.push(this.createOperations()); } removeOperation(index) { this.operations.removeAt(index); } onSubmit() { if (this.aswEditCalculationForm.invalid) { return; } this.aswEditCalculationForm.value.controlType = this.data.control.controlType; this.aswEditCalculationForm.value.id = this.data.control.id; this.aswEditCalculationForm.value.guid = this.data.control.guid; this.aswEditCalculationForm.value.placeholder = this.data.control.placeholder; this.aswEditCalculationForm.value.operations.forEach((operation) => { operation.id = operation.control.guid; operation.label = operation.control.label; operation.value = operation.control.value; }); this.dialogRef.close(this.aswEditCalculationForm.value); } onOperationChange(event, operation) { if (event.target.value === 'x̄') { operation.controls.label.setErrors(null); } else { operation.controls.label.setValidators(Validators.required); } } onOperatorChange(event, operator) { this.data.numberControls.forEach((operation) => { if (event.target.value === operation.label) { operator.value.id = operation.guid; operator.value.control = operation; } }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCalculationDialog, deps: [{ token: i1.FormBuilder }, { token: i2.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.8", type: AswCalculationDialog, selector: "asw-calculation-dialog", ngImport: i0, template: "<div class=\"asw-dialog-header\">\r\n <div class=\"asw-edit-row-dialog\">\r\n <div class=\"asw-dialog-header clearfix\">\r\n <div class=\"asw-dialog-about\">\r\n <h1 mat-dialog-title class=\"asw-m-0\">{{'FormControl.EditCalculation' | aswTranslate}}</h1>\r\n </div>\r\n </div>\r\n </div>\r\n <button mat-icon-button (click)=\"onNoClick()\" aria-label=\"Close dialog\" class=\"asw-mt-2 asw-me-2\">\r\n <div [innerHTML]=\"icons.close | aswSafeHtml\"></div>\r\n </button>\r\n</div>\r\n<form [formGroup]=\"aswEditCalculationForm\" (ngSubmit)=\"onSubmit()\">\r\n <mat-dialog-content class=\"mat-typography\">\r\n <div class=\"asw-row\">\r\n <ng-container *ngIf=\"data.CSSFramework === 'material'; else bootstrap\">\r\n <div class=\"asw-col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.Label' | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"label\"\r\n placeholder=\"{{'FormControl.Label' | aswTranslate}}\"\r\n matTooltip=\"{{'FormControl.Label' | aswTranslate}}\"\r\n formControlName=\"label\" required>\r\n <mat-error *ngFor=\"let validation of constants.accountValidationMessages.label\">\r\n <ng-container *ngIf=\"aswEditCalculationForm.get('label')?.hasError(validation.type) && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched)\">\r\n {{validation.message | aswTranslate}}\r\n </ng-container>\r\n </mat-error>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"asw-col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.Tooltip' | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"tooltip\"\r\n placeholder=\"{{'FormControl.Tooltip' | aswTranslate}}\"\r\n matTooltip=\"{{'FormControl.Tooltip' | aswTranslate}}\"\r\n formControlName=\"tooltip\">\r\n </mat-form-field>\r\n </div>\r\n <div class=\"asw-col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.Style' | aswTranslate}}</mat-label>\r\n <mat-select formControlName=\"style\" matTooltip=\"{{'FormControl.SelectStyle' | aswTranslate}}\">\r\n <mat-option value=\"legacy\">Legacy</mat-option>\r\n <mat-option value=\"standard\">Standard</mat-option>\r\n <mat-option value=\"fill\">Fill</mat-option>\r\n <mat-option value=\"outline\">Outline</mat-option> \r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"asw-col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.Value' | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"value\"\r\n placeholder=\"{{'FormControl.Value' | aswTranslate}}\"\r\n matTooltip=\"{{'FormControl.Value' | aswTranslate}}\"\r\n formControlName=\"value\"> \r\n </mat-form-field>\r\n </div>\r\n <ng-container *ngIf=\"!data.propertyPersonalization.includes('customCSSClass')\">\r\n <div class=\"asw-col-md-12\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.CustomCSSClass' | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"customClass\"\r\n placeholder=\"{{'FormControl.CustomCSSClass' | aswTranslate}}\"\r\n matTooltip=\"{{'FormControl.CustomCSSClass' | aswTranslate}}\"\r\n formControlName=\"customClass\">\r\n </mat-form-field>\r\n </div>\r\n </ng-container>\r\n </ng-container>\r\n <ng-template #bootstrap>\r\n <div class=\"asw-col-md-6\">\r\n <div class=\"asw-mb-3\">\r\n <label class=\"asw-input-label asw-invalid-label {{(aswEditCalculationForm.get('label')?.invalid && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched)) ? 'asw-red-color' : ''}}\">{{'FormControl.Label' | aswTranslate}}</label>\r\n <input type=\"text\"\r\n name=\"label\"\r\n class=\"asw-input-control\"\r\n matTooltip=\"{{'FormControl.Label' | aswTranslate}}\"\r\n [class.asw-is-invalid]=\"(aswEditCalculationForm.get('label')?.invalid && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched))\"\r\n formControlName=\"label\" required>\r\n <div *ngFor=\"let validation of constants.accountValidationMessages.label\" class=\"invalid-feedback\">\r\n <ng-container *ngIf=\"aswEditCalculationForm.get('label')?.hasError(validation.type) && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched)\">\r\n {{validation.message | aswTranslate}}\r\n </ng-container>\r\n </div>\r\n </div>\r\n </div>\r\n <div class=\"asw-col-md-6\">\r\n <div class=\"asw-mb-3\">\r\n <label class=\"asw-input-label\">{{'FormControl.Tooltip' | aswTranslate}}</label>\r\n <input type=\"text\"\r\n name=\"tooltip\"\r\n class=\"asw-input-control\"\r\n matTooltip=\"{{'FormControl.Tooltip' | aswTranslate}}\"\r\n formControlName=\"tooltip\">\r\n </div>\r\n </div>\r\n <ng-container *ngIf=\"!data.propertyPersonalization.includes('customCSSClass')\">\r\n <div class=\"asw-col-md-12\">\r\n <div class=\"asw-mb-3\">\r\n <label class=\"asw-input-label\">{{'FormControl.CustomCSSClass' | aswTranslate}}</label>\r\n <input type=\"text\"\r\n name=\"customClass\"\r\n class=\"asw-input-control\"\r\n matTooltip=\"{{'FormControl.CustomCSSClass' | aswTranslate}}\"\r\n formControlName=\"customClass\">\r\n </div>\r\n </div>\r\n </ng-container>\r\n <div class=\"asw-col-md-12\">\r\n <div class=\"asw-mb-3\">\r\n <label class=\"asw-input-label\">{{'FormControl.Value' | aswTranslate}}</label>\r\n <input type=\"text\"\r\n name=\"value\"\r\n class=\"asw-input-control\"\r\n matTooltip=\"{{'FormControl.Value' | aswTranslate}}\"\r\n formControlName=\"value\"> \r\n </div>\r\n </div>\r\n </ng-template> \r\n <div class=\"asw-col-md-12\" *ngIf=\"operations.controls.length != 0\">\r\n <table class=\"asw-table asw-table-sm asw-table-bordered\">\r\n <thead>\r\n <tr>\r\n <th>{{'FormControl.Operation' | aswTranslate}}</th>\r\n <th>{{'FormControl.Operator' | aswTranslate}}</th>\r\n <th></th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <ng-container formArrayName=\"operations\">\r\n <tr *ngFor=\"let op of operations.controls; let index = index; let last=last;\" \r\n [formGroupName]=\"index\">\r\n <td>\r\n <ng-container *ngIf=\"index!==0\">\r\n <select formControlName=\"operationValue\" \r\n (change)=\"onOperationChange($event, op)\"\r\n matTooltip=\"{{'FormControl.SelectOperation' | aswTranslate}} {{index+1}}\" required class=\"asw-select\">\r\n <option *ngFor=\"let operation of constants.operations\" [value]=\"operation.value\">\r\n {{operation.label}}\r\n </option>\r\n </select>\r\n <ng-container *ngFor=\"let validation of constants.accountValidationMessages.operationValue\">\r\n <mat-error *ngIf=\"operations.controls[index].get('operationValue')?.hasError(validation.type) && (operations.controls[index].get('operationValue')?.dirty || operations.controls[index].get('operationValue')?.touched)\">\r\n {{validation.message | aswTranslate}}\r\n </mat-error>\r\n </ng-container>\r\n </ng-container>\r\n </td>\r\n <td>\r\n <ng-container *ngIf=\"operations.controls[index].value.operationValue != 'x\u0304'\">\r\n <select formControlName=\"label\"\r\n (change)=\"onOperatorChange($event, op)\"\r\n matTooltip=\"{{'FormControl.SelectOperator' | aswTranslate}} {{index+1}}\" required class=\"asw-select\">\r\n <option *ngFor=\"let control of data.numberControls\" [value]=\"control.label\">\r\n {{control.label}}\r\n </option>\r\n </select>\r\n <ng-container *ngFor=\"let validation of constants.accountValidationMessages.control\">\r\n <mat-error *ngIf=\"operations.controls[index].get('control')?.hasError(validation.type) && (operations.controls[index].get('control')?.dirty || operations.controls[index].get('control')?.touched)\">\r\n {{validation.message | aswTranslate}}\r\n </mat-error>\r\n </ng-container>\r\n </ng-container>\r\n </td>\r\n <td class=\"asw-text-center\"> \r\n <button mat-icon-button *ngIf=\"index != 0\"\r\n type=\"button\" \r\n matTooltip=\"{{'FormControl.Delete' | aswTranslate}}\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"removeOperation(index)\">\r\n <span [innerHTML]=\"icons.delete2 | aswSafeHtml\"></span>\r\n </button>\r\n </td>\r\n </tr>\r\n </ng-container>\r\n <tr>\r\n <td colspan=\"3\">\r\n <button class=\"asw-button asw-button-primary asw-button-sm\"\r\n type=\"button\" \r\n matTooltip=\"{{'FormControl.Add' | aswTranslate}}\" \r\n [matTooltipPosition]=\"'below'\"\r\n (click)=\"addNewOperation()\">\r\n <span class=\"asw-icon asw-me-1\" [innerHTML]=\"icons.add | aswSafeHtml\"></span>\r\n {{'FormControl.AddOperation' | aswTranslate}}\r\n </button>\r\n </td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n </div>\r\n </div>\r\n </mat-dialog-content>\r\n <mat-dialog-actions align=\"end\">\r\n <button type=\"button\"\r\n class=\"asw-button asw-button-danger asw-me-2 asw-mb-1\"\r\n (click)=\"onNoClick()\">\r\n {{'FormControl.No' | aswTranslate}}\r\n </button>\r\n <button type=\"submit\"\r\n class=\"asw-button asw-button-primary asw-mb-1\"\r\n cdkFocusInitial>\r\n {{'FormControl.Yes' | aswTranslate}}\r\n </button>\r\n </mat-dialog-actions>\r\n</form>\r\n\r\n", dependencies: [{ kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: i1.FormGroupName, selector: "[formGroupName]", inputs: ["formGroupName"] }, { kind: "directive", type: i1.FormArrayName, selector: "[formArrayName]", inputs: ["formArrayName"] }, { kind: "component", type: i4.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "component", type: i5.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "directive", type: i2.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { kind: "directive", type: i2.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]", inputs: ["align"] }, { kind: "directive", type: i2.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "directive", type: i6.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "component", type: i7.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i7.MatLabel, selector: "mat-label" }, { kind: "directive", type: i7.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "component", type: i8.MatSelect, selector: "mat-select", inputs: ["aria-describedby", "panelClass", "disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator", "placeholder", "required", "multiple", "disableOptionCentering", "compareWith", "value", "aria-label", "aria-labelledby", "errorStateMatcher", "typeaheadDebounceInterval", "sortComparator", "id", "panelWidth"], outputs: ["openedChange", "opened", "closed", "selectionChange", "valueChange"], exportAs: ["matSelect"] }, { kind: "directive", type: i9.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "pipe", type: i10.AswTranslatePipe, name: "aswTranslate" }, { kind: "pipe", type: i11.AswSafeHtmlPipe, name: "aswSafeHtml" }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCalculationDialog, decorators: [{ type: Component, args: [{ selector: 'asw-calculation-dialog', template: "<div class=\"asw-dialog-header\">\r\n <div class=\"asw-edit-row-dialog\">\r\n <div class=\"asw-dialog-header clearfix\">\r\n <div class=\"asw-dialog-about\">\r\n <h1 mat-dialog-title class=\"asw-m-0\">{{'FormControl.EditCalculation' | aswTranslate}}</h1>\r\n </div>\r\n </div>\r\n </div>\r\n <button mat-icon-button (click)=\"onNoClick()\" aria-label=\"Close dialog\" class=\"asw-mt-2 asw-me-2\">\r\n <div [innerHTML]=\"icons.close | aswSafeHtml\"></div>\r\n </button>\r\n</div>\r\n<form [formGroup]=\"aswEditCalculationForm\" (ngSubmit)=\"onSubmit()\">\r\n <mat-dialog-content class=\"mat-typography\">\r\n <div class=\"asw-row\">\r\n <ng-container *ngIf=\"data.CSSFramework === 'material'; else bootstrap\">\r\n <div class=\"asw-col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.Label' | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"label\"\r\n placeholder=\"{{'FormControl.Label' | aswTranslate}}\"\r\n matTooltip=\"{{'FormControl.Label' | aswTranslate}}\"\r\n formControlName=\"label\" required>\r\n <mat-error *ngFor=\"let validation of constants.accountValidationMessages.label\">\r\n <ng-container *ngIf=\"aswEditCalculationForm.get('label')?.hasError(validation.type) && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched)\">\r\n {{validation.message | aswTranslate}}\r\n </ng-container>\r\n </mat-error>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"asw-col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.Tooltip' | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"tooltip\"\r\n placeholder=\"{{'FormControl.Tooltip' | aswTranslate}}\"\r\n matTooltip=\"{{'FormControl.Tooltip' | aswTranslate}}\"\r\n formControlName=\"tooltip\">\r\n </mat-form-field>\r\n </div>\r\n <div class=\"asw-col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.Style' | aswTranslate}}</mat-label>\r\n <mat-select formControlName=\"style\" matTooltip=\"{{'FormControl.SelectStyle' | aswTranslate}}\">\r\n <mat-option value=\"legacy\">Legacy</mat-option>\r\n <mat-option value=\"standard\">Standard</mat-option>\r\n <mat-option value=\"fill\">Fill</mat-option>\r\n <mat-option value=\"outline\">Outline</mat-option> \r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"asw-col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.Value' | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"value\"\r\n placeholder=\"{{'FormControl.Value' | aswTranslate}}\"\r\n matTooltip=\"{{'FormControl.Value' | aswTranslate}}\"\r\n formControlName=\"value\"> \r\n </mat-form-field>\r\n </div>\r\n <ng-container *ngIf=\"!data.propertyPersonalization.includes('customCSSClass')\">\r\n <div class=\"asw-col-md-12\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-width-100\">\r\n <mat-label>{{'FormControl.CustomCSSClass' | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"customClass\"\r\n placeholder=\"{{'FormControl.CustomCSSClass' | aswTranslate}}\"\r\n matTooltip=\"{{'FormControl.CustomCSSClass' | aswTranslate}}\"\r\n formControlName=\"customClass\">\r\n </mat-form-field>\r\n </div>\r\n </ng-container>\r\n </ng-container>\r\n <ng-template #bootstrap>\r\n <div class=\"asw-col-md-6\">\r\n <div class=\"asw-mb-3\">\r\n <label class=\"asw-input-label asw-invalid-label {{(aswEditCalculationForm.get('label')?.invalid && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched)) ? 'asw-red-color' : ''}}\">{{'FormControl.Label' | aswTranslate}}</label>\r\n <input type=\"text\"\r\n name=\"label\"\r\n class=\"asw-input-control\"\r\n matTooltip=\"{{'FormControl.Label' | aswTranslate}}\"\r\n [class.asw-is-invalid]=\"(aswEditCalculationForm.get('label')?.invalid && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched))\"\r\n formControlName=\"label\" required>\r\n <div *ngFor=\"let validation of constants.accountValidationMessages.label\" class=\"invalid-feedback\">\r\n <ng-container *ngIf=\"aswEditCalculationForm.get('label')?.hasError(validation.type) && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched)\">\r\n {{validation.message | aswTranslate}}\r\n </ng-container>\r\n </div>\r\n </div>\r\n </div>\r\n <div class=\"asw-col-md-6\">\r\n <div class=\"asw-mb-3\">\r\n <label class=\"asw-input-label\">{{'FormControl.Tooltip' | aswTranslate}}</label>\r\n <input type=\"text\"\r\n name=\"tooltip\"\r\n class=\"asw-input-control\"\r\n matTooltip=\"{{'FormControl.Tooltip' | aswTranslate}}\"\r\n formControlName=\"tooltip\">\r\n </div>\r\n </div>\r\n <ng-container *ngIf=\"!data.propertyPersonalization.includes('customCSSClass')\">\r\n <div class=\"asw-col-md-12\">\r\n <div class=\"asw-mb-3\">\r\n <label class=\"asw-input-label\">{{'FormControl.CustomCSSClass' | aswTranslate}}</label>\r\n <input type=\"text\"\r\n name=\"customClass\"\r\n class=\"asw-input-control\"\r\n matTooltip=\"{{'FormControl.CustomCSSClass' | aswTranslate}}\"\r\n formControlName=\"customClass\">\r\n </div>\r\n </div>\r\n </ng-container>\r\n <div class=\"asw-col-md-12\">\r\n <div class=\"asw-mb-3\">\r\n <label class=\"asw-input-label\">{{'FormControl.Value' | aswTranslate}}</label>\r\n <input type=\"text\"\r\n name=\"value\"\r\n class=\"asw-input-control\"\r\n matTooltip=\"{{'FormControl.Value' | aswTranslate}}\"\r\n formControlName=\"value\"> \r\n </div>\r\n </div>\r\n </ng-template> \r\n <div class=\"asw-col-md-12\" *ngIf=\"operations.controls.length != 0\">\r\n <table class=\"asw-table asw-table-sm asw-table-bordered\">\r\n <thead>\r\n <tr>\r\n <th>{{'FormControl.Operation' | aswTranslate}}</th>\r\n <th>{{'FormControl.Operator' | aswTranslate}}</th>\r\n <th></th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <ng-container formArrayName=\"operations\">\r\n <tr *ngFor=\"let op of operations.controls; let index = index; let last=last;\" \r\n [formGroupName]=\"index\">\r\n <td>\r\n <ng-container *ngIf=\"index!==0\">\r\n <select formControlName=\"operationValue\" \r\n (change)=\"onOperationChange($event, op)\"\r\n matTooltip=\"{{'FormControl.SelectOperation' | aswTranslate}} {{index+1}}\" required class=\"asw-select\">\r\n <option *ngFor=\"let operation of constants.operations\" [value]=\"operation.value\">\r\n {{operation.label}}\r\n </option>\r\n </select>\r\n <ng-container *ngFor=\"let validation of constants.accountValidationMessages.operationValue\">\r\n <mat-error *ngIf=\"operations.controls[index].get('operationValue')?.hasError(validation.type) && (operations.controls[index].get('operationValue')?.dirty || operations.controls[index].get('operationValue')?.touched)\">\r\n {{validation.message | aswTranslate}}\r\n </mat-error>\r\n </ng-container>\r\n </ng-container>\r\n </td>\r\n <td>\r\n <ng-container *ngIf=\"operations.controls[index].value.operationValue != 'x\u0304'\">\r\n <select formControlName=\"label\"\r\n (change)=\"onOperatorChange($event, op)\"\r\n matTooltip=\"{{'FormControl.SelectOperator' | aswTranslate}} {{index+1}}\" required class=\"asw-select\">\r\n <option *ngFor=\"let control of data.numberControls\" [value]=\"control.label\">\r\n {{control.label}}\r\n </option>\r\n </select>\r\n <ng-container *ngFor=\"let validation of constants.accountValidationMessages.control\">\r\n <mat-error *ngIf=\"operations.controls[index].get('control')?.hasError(validation.type) && (operations.controls[index].get('control')?.dirty || operations.controls[index].get('control')?.touched)\">\r\n {{validation.message | aswTranslate}}\r\n </mat-error>\r\n </ng-container>\r\n </ng-container>\r\n </td>\r\n <td class=\"asw-text-center\"> \r\n <button mat-icon-button *ngIf=\"index != 0\"\r\n type=\"button\" \r\n matTooltip=\"{{'FormControl.Delete' | aswTranslate}}\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"removeOperation(index)\">\r\n <span [innerHTML]=\"icons.delete2 | aswSafeHtml\"></span>\r\n </button>\r\n </td>\r\n </tr>\r\n </ng-container>\r\n <tr>\r\n <td colspan=\"3\">\r\n <button class=\"asw-button asw-button-primary asw-button-sm\"\r\n type=\"button\" \r\n matTooltip=\"{{'FormControl.Add' | aswTranslate}}\" \r\n [matTooltipPosition]=\"'below'\"\r\n (click)=\"addNewOperation()\">\r\n <span class=\"asw-icon asw-me-1\" [innerHTML]=\"icons.add | aswSafeHtml\"></span>\r\n {{'FormControl.AddOperation' | aswTranslate}}\r\n </button>\r\n </td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n </div>\r\n </div>\r\n </mat-dialog-content>\r\n <mat-dialog-actions align=\"end\">\r\n <button type=\"button\"\r\n class=\"asw-button asw-button-danger asw-me-2 asw-mb-1\"\r\n (click)=\"onNoClick()\">\r\n {{'FormControl.No' | aswTranslate}}\r\n </button>\r\n <button type=\"submit\"\r\n class=\"asw-button asw-button-primary asw-mb-1\"\r\n cdkFocusInitial>\r\n {{'FormControl.Yes' | aswTranslate}}\r\n </button>\r\n </mat-dialog-actions>\r\n</form>\r\n\r\n" }] }], ctorParameters: () => [{ type: i1.FormBuilder }, { type: i2.MatDialogRef }, { type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA] }] }] }); /** * @license * Copyright ASW (A Software World) All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file */ class AswCalculation { dialog; constants = Constants; icons = Icons; /** * Calculation control */ control = null; formControls = []; CSSFramework = CSSFrameworkEnum.Material; isPreviewTemplate = false; propertyPersonalization = []; calculationUpdateEvent = new EventEmitter(); calculationDeleteEvent = new EventEmitter(); aswModelChange = new EventEmitter(); duplicateControl = new EventEmitter(); constructor(dialog) { this.dialog = dialog; } deleteCalculationDialog(control) { const dialogRef = this.dialog.open(AswConfirmDialog, { width: '350px', data: { name: control.controlType, message: this.constants.messages.waringMessage } }); dialogRef.afterClosed().subscribe((result) => { if (result !== undefined) { this.calculationDeleteEvent.emit(control); } }); } editCalculationDialog(control, formControls) { let numberControls = []; this.getNumberControls(formControls, numberControls); numberControls = [...new Set(numberControls.map((numberControl) => numberControl))]; if (!numberControls.length) { control.operations = []; } if (!control.operations.length) { numberControls.forEach((x, index) => { control.operations.push(this.setControloperations(x, index)); }); } else { control.operations.map((operation, index) => { const numberControl = numberControls.find((element) => element.guid === operation.id); if (numberControl) { const updatedOperation = { id: numberControl.guid, label: numberControl.label, value: numberControl.value, operationValue: operation.operationValue, control: numberControl }; control.operations.splice(index, 1, updatedOperation); } }); } const dialogRef = this.dialog.open(AswCalculationDialog, { width: '80%', minWidth: '70vw', disableClose: true, data: { control, numberControls, CSSFramework: this.CSSFramework, propertyPersonalization: this.propertyPersonalization } }); dialogRef.afterClosed().subscribe((result) => { if (result !== undefined) { result.value = ObjectUtils.calculateValue(result.operations).toString(); this.calculationUpdateEvent.emit(result); } }); } getNumberControls(formControls, numberControls) { numberControls.push(...formControls.filter((x) => x.controlType === 'number' || x.controlType === 'currency')); const columnsControls = formControls.filter((x) => x.controlType === 'columns'); if (columnsControls.length) { columnsControls.forEach((control) => { control.columns.forEach((column) => { column.components.forEach((component) => { if (component.controlType === 'columns') { this.getNumberControls(column.components, numberControls); } if (component.controlType === 'number' || component.controlType === 'currency') { numberControls.push(component); } }); }); }); } } setControloperations(control, index) { const operation = { id: control.guid, label: control.label, value: control.value, operationValue: index === 0 ? '' : '+', control }; return operation; } onChange(control) { this.aswModelChange.emit(control); } duplicateCalculationControl(control) { this.duplicateControl.emit(control); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCalculation, deps: [{ token: i2.MatDialog }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.8", type: AswCalculation, selector: "asw-calculation", inputs: { control: "control", formControls: "formControls", CSSFramework: "CSSFramework", isPreviewTemplate: "isPreviewTemplate", propertyPersonalization: "propertyPersonalization" }, outputs: { calculationUpdateEvent: "calculationUpdateEvent", calculationDeleteEvent: "calculationDeleteEvent", aswModelChange: "aswModelChange", duplicateControl: "duplicateControl" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n <ng-container *ngIf=\"CSSFramework === 'material'; else bootstrap\">\r\n <mat-form-field [appearance]=\"control.style\" class=\"asw-width-100 {{control.customClass}}\">\r\n <mat-label>{{control.label | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n [placeholder]=\"control.placeholder | aswTranslate\"\r\n [(ngModel)]=\"control.value\"\r\n #input=\"ngModel\"\r\n (change)=\"onChange(control)\"\r\n [matTooltip]=\"control.tooltip | aswTranslate\"\r\n [disabled]=\"true\">\r\n </mat-form-field>\r\n </ng-container>\r\n <ng-template #bootstrap>\r\n <div class=\"asw-mb-3\">\r\n <label\r\n class=\"asw-input-label {{(input.invalid && (input.dirty || input.touched)) ? 'asw-red-color' : ''}}\"\r\n >{{control.label | aswTranslate}}</label>\r\n <input type=\"text\"\r\n [placeholder]=\"control.placeholder | aswTranslate\"\r\n class=\"asw-input-control {{control.customClass}}\"\r\n [(ngModel)]=\"control.value\"\r\n #input=\"ngModel\"\r\n (change)=\"onChange(control)\"\r\n [matTooltip]=\"control.tooltip | aswTranslate\"\r\n [disabled]=\"true\">\r\n </div>\r\n </ng-template> \r\n <div class=\"asw-row\" *ngIf=\"isPreviewTemplate\">\r\n <div class=\"asw-col-md-12\" align=\"right\">\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"{{'FormControl.Duplicate' | aswTranslate}}\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"duplicateCalculationControl(control)\">\r\n <div [innerHTML]=\"icons.contentCopy | aswSafeHtml\"></div>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"{{'FormControl.Edit' | aswTranslate}}\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"editCalculationDialog(control, formControls)\">\r\n <div [innerHTML]=\"icons.edit | aswSafeHtml\"></div>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"{{'FormControl.Delete' | aswTranslate}}\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"deleteCalculationDialog(control)\">\r\n <div [innerHTML]=\"icons.delete2 | aswSafeHtml\"></div>\r\n </button>\r\n </div>\r\n </div>\r\n</ng-container>", dependencies: [{ kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i5.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "directive", type: i6.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "component", type: i7.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i7.MatLabel, selector: "mat-label" }, { kind: "directive", type: i9.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "pipe", type: i10.AswTranslatePipe, name: "aswTranslate" }, { kind: "pipe", type: i11.AswSafeHtmlPipe, name: "aswSafeHtml" }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCalculation, decorators: [{ type: Component, args: [{ selector: 'asw-calculation', template: "<ng-container *ngIf=\"control as control\">\r\n <ng-container *ngIf=\"CSSFramework === 'material'; else bootstrap\">\r\n <mat-form-field [appearance]=\"control.style\" class=\"asw-width-100 {{control.customClass}}\">\r\n <mat-label>{{control.label | aswTranslate}}</mat-label>\r\n <input matInput type=\"text\"\r\n [placeholder]=\"control.placeholder | aswTranslate\"\r\n [(ngModel)]=\"control.value\"\r\n #input=\"ngModel\"\r\n (change)=\"onChange(control)\"\r\n [matTooltip]=\"control.tooltip | aswTranslate\"\r\n [disabled]=\"true\">\r\n </mat-form-field>\r\n </ng-container>\r\n <ng-template #bootstrap>\r\n <div class=\"asw-mb-3\">\r\n <label\r\n class=\"asw-input-label {{(input.invalid && (input.dirty || input.touched)) ? 'asw-red-color' : ''}}\"\r\n >{{control.label | aswTranslate}}</label>\r\n <input type=\"text\"\r\n [placeholder]=\"control.placeholder | aswTranslate\"\r\n class=\"asw-input-control {{control.customClass}}\"\r\n [(ngModel)]=\"control.value\"\r\n #input=\"ngModel\"\r\n (change)=\"onChange(control)\"\r\n [matTooltip]=\"control.tooltip | aswTranslate\"\r\n [disabled]=\"true\">\r\n </div>\r\n </ng-template> \r\n <div class=\"asw-row\" *ngIf=\"isPreviewTemplate\">\r\n <div class=\"asw-col-md-12\" align=\"right\">\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"{{'FormControl.Duplicate' | aswTranslate}}\" \r\n [matTooltipPosition]=\"'below'\" \r