UNPKG

@asoftwareworld/form-builder

Version:

ASW Form Builder 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 befor

209 lines (203 loc) 17 kB
import * as i0 from '@angular/core'; import { EventEmitter, Component, Input, Output, NgModule } from '@angular/core'; import { AswConfirmDialog, AswConfirmDialogModule } from '@asoftwareworld/form-builder/form-control/confirm-dialog'; import { Constants, AswSingleSelectDialog, AswSharedDialogModule } from '@asoftwareworld/form-builder/form-control/core'; import * as i1 from '@angular/material/dialog'; import { MatDialogModule } from '@angular/material/dialog'; import * as i2 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i3 from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import * as i4 from '@angular/material/input'; import { MatInputModule } from '@angular/material/input'; import * as i5 from '@angular/material/form-field'; import * as i6 from '@angular/material/core'; import * as i7 from '@angular/material/tooltip'; import { MatTooltipModule } from '@angular/material/tooltip'; import * as i8 from '@angular/material/icon'; import { MatIconModule } from '@angular/material/icon'; import * as i9 from '@angular/material/autocomplete'; import { MatAutocompleteModule } from '@angular/material/autocomplete'; import * as i10 from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button'; import { MatDividerModule } from '@angular/material/divider'; import { MatRadioModule } from '@angular/material/radio'; import { MatSelectModule } from '@angular/material/select'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; /** * @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 AswAutocomplete { dialog; constants = Constants; filteredOptions; /** * Autocomplete control */ control = null; /** * Autocomplete control index to help update or delete button from drop area */ controlIndex; isPreviewTemplate = false; autocompleteUpdateEvent = new EventEmitter(); autocompleteDeleteEvent = new EventEmitter(); selectionChange = new EventEmitter(); duplicateControl = new EventEmitter(); constructor(dialog) { this.dialog = dialog; } ngOnInit() { this.filteredOptions = this.control?.options; } filter(control) { if (control.value) { const filterValue = control.value.toLowerCase(); control.options.forEach(element => { element.isChecked = control.value === element.key ? true : false; }); this.selectionChange.emit(control); return this.control?.options.filter(option => option.value.toLowerCase().startsWith(filterValue)); } return this.control?.options; } /** * Delete autocomplete control based on control index * @param control autocomplete control items * @param controlIndex autocomplete control index */ deleteAutocompleteDialog(control, controlIndex) { 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.autocompleteDeleteEvent.emit(controlIndex); } }); } editAutocompleteDialog(control, controlIndex) { control.options.forEach(element => { element.isChecked = control.value === element.key ? true : false; }); const dialogRef = this.dialog.open(AswSingleSelectDialog, { disableClose: true, width: '80%', minWidth: '70vw', data: control }); dialogRef.afterClosed().subscribe(result => { if (result !== undefined) { this.autocompleteUpdateEvent.emit({ control: result, index: controlIndex }); } }); } duplicateAutocompleteControl(control) { this.duplicateControl.emit(control); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswAutocomplete, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.11", type: AswAutocomplete, selector: "asw-autocomplete", inputs: { control: "control", controlIndex: "controlIndex", isPreviewTemplate: "isPreviewTemplate" }, outputs: { autocompleteUpdateEvent: "autocompleteUpdateEvent", autocompleteDeleteEvent: "autocompleteDeleteEvent", selectionChange: "selectionChange", duplicateControl: "duplicateControl" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n <mat-form-field [appearance]=\"control.style\" class=\"asw-mat-form-field {{control.customClass}}\">\r\n <mat-label>{{control.label}}</mat-label>\r\n <input [placeholder]=\"control.label\"\r\n [id]=\"control.id\"\r\n [matAutocomplete]=\"auto\"\r\n matInput\r\n [(ngModel)]=\"control.value\" \r\n #input=\"ngModel\"\r\n [matTooltip]=\"control.tooltip\"\r\n (ngModelChange)=\"filteredOptions = filter(control)\"\r\n [required]=\"control.isRequired\"\r\n [disabled]=\"control.isDisabled ? true : false\">\r\n <mat-autocomplete autoActiveFirstOption #auto=\"matAutocomplete\">\r\n <mat-option *ngFor=\"let option of filteredOptions\" [value]=\"option.key\">\r\n {{option.value}}\r\n </mat-option>\r\n </mat-autocomplete>\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"input.invalid && (input.dirty || input.touched)\">\r\n <ng-container *ngIf=\"input?.errors?.required\">\r\n {{control.label}} is required\r\n </ng-container>\r\n </mat-error>\r\n </mat-form-field>\r\n <ng-template [ngIf]=\"isPreviewTemplate\">\r\n <div class=\"row\">\r\n <div class=\"col-md-12\">\r\n <button mat-icon-button\r\n type=\"button\" \r\n matTooltip=\"Duplicate\" \r\n [matTooltipPosition]=\"'below'\"\r\n (click)=\"duplicateAutocompleteControl(control)\">\r\n <mat-icon>content_copy</mat-icon>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Edit\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"editAutocompleteDialog(control, controlIndex)\">\r\n <mat-icon>edit</mat-icon>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Delete\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"deleteAutocompleteDialog(control, controlIndex)\">\r\n <mat-icon>delete</mat-icon>\r\n </button>\r\n </div> \r\n </div>\r\n </ng-template> \r\n</ng-container>", dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.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: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i4.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: i5.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i5.MatLabel, selector: "mat-label" }, { kind: "directive", type: i5.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "component", type: i6.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "directive", type: i7.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: i8.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i9.MatAutocomplete, selector: "mat-autocomplete", inputs: ["aria-label", "aria-labelledby", "displayWith", "autoActiveFirstOption", "autoSelectActiveOption", "requireSelection", "panelWidth", "disableRipple", "class", "hideSingleSelectionIndicator"], outputs: ["optionSelected", "opened", "closed", "optionActivated"], exportAs: ["matAutocomplete"] }, { kind: "directive", type: i9.MatAutocompleteTrigger, selector: "input[matAutocomplete], textarea[matAutocomplete]", inputs: ["matAutocomplete", "matAutocompletePosition", "matAutocompleteConnectedTo", "autocomplete", "matAutocompleteDisabled"], exportAs: ["matAutocompleteTrigger"] }, { kind: "component", type: i10.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswAutocomplete, decorators: [{ type: Component, args: [{ selector: 'asw-autocomplete', template: "<ng-container *ngIf=\"control as control\">\r\n <mat-form-field [appearance]=\"control.style\" class=\"asw-mat-form-field {{control.customClass}}\">\r\n <mat-label>{{control.label}}</mat-label>\r\n <input [placeholder]=\"control.label\"\r\n [id]=\"control.id\"\r\n [matAutocomplete]=\"auto\"\r\n matInput\r\n [(ngModel)]=\"control.value\" \r\n #input=\"ngModel\"\r\n [matTooltip]=\"control.tooltip\"\r\n (ngModelChange)=\"filteredOptions = filter(control)\"\r\n [required]=\"control.isRequired\"\r\n [disabled]=\"control.isDisabled ? true : false\">\r\n <mat-autocomplete autoActiveFirstOption #auto=\"matAutocomplete\">\r\n <mat-option *ngFor=\"let option of filteredOptions\" [value]=\"option.key\">\r\n {{option.value}}\r\n </mat-option>\r\n </mat-autocomplete>\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"input.invalid && (input.dirty || input.touched)\">\r\n <ng-container *ngIf=\"input?.errors?.required\">\r\n {{control.label}} is required\r\n </ng-container>\r\n </mat-error>\r\n </mat-form-field>\r\n <ng-template [ngIf]=\"isPreviewTemplate\">\r\n <div class=\"row\">\r\n <div class=\"col-md-12\">\r\n <button mat-icon-button\r\n type=\"button\" \r\n matTooltip=\"Duplicate\" \r\n [matTooltipPosition]=\"'below'\"\r\n (click)=\"duplicateAutocompleteControl(control)\">\r\n <mat-icon>content_copy</mat-icon>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Edit\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"editAutocompleteDialog(control, controlIndex)\">\r\n <mat-icon>edit</mat-icon>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Delete\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"deleteAutocompleteDialog(control, controlIndex)\">\r\n <mat-icon>delete</mat-icon>\r\n </button>\r\n </div> \r\n </div>\r\n </ng-template> \r\n</ng-container>" }] }], ctorParameters: () => [{ type: i1.MatDialog }], propDecorators: { control: [{ type: Input }], controlIndex: [{ type: Input }], isPreviewTemplate: [{ type: Input }], autocompleteUpdateEvent: [{ type: Output }], autocompleteDeleteEvent: [{ 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 AswAutocompleteModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswAutocompleteModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.11", ngImport: i0, type: AswAutocompleteModule, declarations: [AswAutocomplete], imports: [CommonModule, FormsModule, ReactiveFormsModule, MatInputModule, MatSelectModule, MatDialogModule, MatSlideToggleModule, MatDividerModule, MatTooltipModule, MatRadioModule, MatIconModule, MatAutocompleteModule, AswConfirmDialogModule, MatButtonModule, AswSharedDialogModule], exports: [AswAutocomplete] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswAutocompleteModule, imports: [CommonModule, FormsModule, ReactiveFormsModule, MatInputModule, MatSelectModule, MatDialogModule, MatSlideToggleModule, MatDividerModule, MatTooltipModule, MatRadioModule, MatIconModule, MatAutocompleteModule, AswConfirmDialogModule, MatButtonModule, AswSharedDialogModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswAutocompleteModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule, FormsModule, ReactiveFormsModule, MatInputModule, MatSelectModule, MatDialogModule, MatSlideToggleModule, MatDividerModule, MatTooltipModule, MatRadioModule, MatIconModule, MatAutocompleteModule, AswConfirmDialogModule, MatButtonModule, AswSharedDialogModule ], declarations: [ AswAutocomplete ], exports: [ AswAutocomplete ] }] }] }); /** * @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 { AswAutocomplete, AswAutocompleteModule }; //# sourceMappingURL=asoftwareworld-form-builder-form-control-autocomplete.mjs.map