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

246 lines (240 loc) 16.3 kB
import * as i0 from '@angular/core'; import { EventEmitter, Output, Input, Component, NgModule } from '@angular/core'; import { CSSFrameworkEnum } from '@asoftwareworld/form-builder-pro/api'; import * as i2 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 { AswMultiSelectDialog, AswSharedDialogModule } from '@asoftwareworld/form-builder-pro/form-control/shared'; import * as i1 from '@angular/material/dialog'; import * as i3 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i4 from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import * as i5 from '@angular/material/button'; import * as i6 from '@angular/material/checkbox'; import * as i7 from '@angular/material/form-field'; import * as i8 from '@angular/material/tooltip'; import * as i9 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 AswCheckbox { dialog; aswApiService; constants = Constants; icons = Icons; control; propertyPersonalization = []; isPreviewTemplate = false; CSSFramework = CSSFrameworkEnum.Material; formControls = []; checkboxUpdateEvent = new EventEmitter(); checkboxDeleteEvent = new EventEmitter(); selectionChange = new EventEmitter(); duplicateControl = new EventEmitter(); constructor(dialog, aswApiService) { this.dialog = dialog; this.aswApiService = aswApiService; } ngOnInit() { if (this.control?.apiUrl) { this.callApiToFetchData(this.control); } } callApiToFetchData(control) { switch (control.method) { case 'GET': { this.aswApiService.get(control.apiUrl, control.headers).subscribe({ next: (data) => { if (data?.value) { this.control.options = data.value; } else { this.control.options = data; } } }); break; } case 'POST': { this.aswApiService.post(control.apiUrl, control.body, control.headers).subscribe({ next: (data) => { if (data?.value) { this.control.options = data.value; } else { this.control.options = data; } } }); break; } case 'PUT': { this.aswApiService.put(control.apiUrl, control.body, control.headers).subscribe({ next: (data) => { if (data?.value) { this.control.options = data.value; } else { this.control.options = data; } } }); break; } case 'PATCH': { this.aswApiService.patch(control.apiUrl, control.body, control.headers).subscribe({ next: (data) => { if (data?.value) { this.control.options = data.value; } else { this.control.options = data; } } }); break; } case 'DELETE': { this.aswApiService.delete(control.apiUrl, control.headers).subscribe({ next: (data) => { if (data?.value) { this.control.options = data.value; } else { this.control.options = data; } } }); break; } } } deleteCheckboxDialog(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.checkboxDeleteEvent.emit(control); } }); } editCheckboxDialog(control, formControls) { let allControls = []; this.getAllExceptCurrentControl(formControls, allControls); allControls = [...new Set(allControls.map((control) => control))]; control.options.forEach((element) => { if (!element.hideControl) { element.hideControl = []; } }); const dialogRef = this.dialog.open(AswMultiSelectDialog, { width: '80%', minWidth: '70vw', disableClose: true, data: { control, CSSFramework: this.CSSFramework, propertyPersonalization: this.propertyPersonalization, allControls } }); dialogRef.afterClosed().subscribe((result) => { if (result !== undefined) { this.checkboxUpdateEvent.emit(result); } }); } onSelectionChange(control) { control.value = []; control.options.forEach((element) => { if (element.isChecked) { control.value.push(element.key); } }); this.selectionChange.emit(control); } duplicateCheckboxControl(control) { this.duplicateControl.emit(control); } getAllExceptCurrentControl(formControls, allControls) { //allControls.push(...formControls.filter((x) => x.id !== this.control.id)); const columnsControls = formControls.filter((x) => x.controlType === 'columns'); if (columnsControls.length) { columnsControls.forEach((control) => { let isSelectedControl = false; control.columns.forEach((column) => { column.components.forEach((component) => { if (component.controlType === 'columns') { this.getAllExceptCurrentControl(column.components, allControls); } if (component.id === this.control.id) { isSelectedControl = true; } }); }); if (!isSelectedControl) { allControls.push(control); } }); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCheckbox, deps: [{ token: i1.MatDialog }, { token: i2.AswApiService }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.8", type: AswCheckbox, selector: "asw-checkbox", inputs: { control: "control", propertyPersonalization: "propertyPersonalization", isPreviewTemplate: "isPreviewTemplate", CSSFramework: "CSSFramework", formControls: "formControls" }, outputs: { checkboxUpdateEvent: "checkboxUpdateEvent", checkboxDeleteEvent: "checkboxDeleteEvent", selectionChange: "selectionChange", duplicateControl: "duplicateControl" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n <mat-label [innerHTML]=\"(control.label | aswTranslate) | aswSafeHtml\"></mat-label>\r\n <div *ngFor=\"let option of control.options\">\r\n <mat-checkbox color=\"primary\"\r\n [class]=\"control.customClass\"\r\n [matTooltip]=\"option.value\"\r\n [(ngModel)]=\"option.isChecked\"\r\n (change)=\"onSelectionChange(control)\"\r\n [required]=\"control.isRequired\"\r\n [disabled]=\"control.isDisabled ? true : false\">\r\n {{option.value}}\r\n </mat-checkbox>\r\n </div>\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)=\"duplicateCheckboxControl(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)=\"editCheckboxDialog(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)=\"deleteCheckboxDialog(control)\">\r\n <div [innerHTML]=\"icons.delete2 | aswSafeHtml\"></div>\r\n </button>\r\n </div>\r\n </div>\r\n</ng-container>\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: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i4.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: "component", type: i6.MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "disabledInteractive", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }, { kind: "directive", type: i7.MatLabel, selector: "mat-label" }, { kind: "directive", type: i8.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "pipe", type: i9.AswTranslatePipe, name: "aswTranslate" }, { kind: "pipe", type: i2.AswSafeHtmlPipe, name: "aswSafeHtml" }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCheckbox, decorators: [{ type: Component, args: [{ selector: 'asw-checkbox', template: "<ng-container *ngIf=\"control as control\">\r\n <mat-label [innerHTML]=\"(control.label | aswTranslate) | aswSafeHtml\"></mat-label>\r\n <div *ngFor=\"let option of control.options\">\r\n <mat-checkbox color=\"primary\"\r\n [class]=\"control.customClass\"\r\n [matTooltip]=\"option.value\"\r\n [(ngModel)]=\"option.isChecked\"\r\n (change)=\"onSelectionChange(control)\"\r\n [required]=\"control.isRequired\"\r\n [disabled]=\"control.isDisabled ? true : false\">\r\n {{option.value}}\r\n </mat-checkbox>\r\n </div>\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)=\"duplicateCheckboxControl(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)=\"editCheckboxDialog(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)=\"deleteCheckboxDialog(control)\">\r\n <div [innerHTML]=\"icons.delete2 | aswSafeHtml\"></div>\r\n </button>\r\n </div>\r\n </div>\r\n</ng-container>\r\n" }] }], ctorParameters: () => [{ type: i1.MatDialog }, { type: i2.AswApiService }], propDecorators: { control: [{ type: Input }], propertyPersonalization: [{ type: Input }], isPreviewTemplate: [{ type: Input }], CSSFramework: [{ type: Input }], formControls: [{ type: Input }], checkboxUpdateEvent: [{ type: Output }], checkboxDeleteEvent: [{ type: Output }], selectionChange: [{ type: Output }], duplicateControl: [{ type: Output }] } }); /** * @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 AswCheckboxModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCheckboxModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.8", ngImport: i0, type: AswCheckboxModule, declarations: [AswCheckbox], imports: [CommonModule, FormsModule, ReactiveFormsModule, MaterialModule, AswConfirmDialogModule, AswSharedDialogModule, AswTranslateModule, AswPipeModule], exports: [AswCheckbox] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCheckboxModule, imports: [CommonModule, FormsModule, ReactiveFormsModule, MaterialModule, AswConfirmDialogModule, AswSharedDialogModule, AswTranslateModule, AswPipeModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.8", ngImport: i0, type: AswCheckboxModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, FormsModule, ReactiveFormsModule, MaterialModule, AswConfirmDialogModule, AswSharedDialogModule, AswTranslateModule, AswPipeModule], declarations: [AswCheckbox], exports: [AswCheckbox] }] }] }); /** * @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 */ /** * Generated bundle index. Do not edit. */ export { AswCheckbox, AswCheckboxModule }; //# sourceMappingURL=asoftwareworld-form-builder-pro-form-control-checkbox.mjs.map