UNPKG

@ng2-dynamic-forms/ui-foundation

Version:

Foundation UI package for ng2 Dynamic Forms

18 lines (15 loc) 11.2 kB
/*! ng2-dynamic-forms 1.4.19 2017-07-17 20:12 UTC Copyright (c) 2016-2017, Udo Schöfer http://www.udos86.de Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core"),require("@angular/forms"),require("@ng2-dynamic-forms/core"),require("@angular/common"),require("angular2-text-mask")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/forms","@ng2-dynamic-forms/core","@angular/common","angular2-text-mask"],o):o((e.ng2DF=e.ng2DF||{},e.ng2DF.uiFoundation={}),e.ng.core,e.ng.forms,e.ng2DF.core,e.ng.common,e["angular2-text-mask"])}(this,function(e,o,n,t,l,a){"use strict";var r=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,o){e.__proto__=o}||function(e,o){for(var n in o)o.hasOwnProperty(n)&&(e[n]=o[n])};return function(o,n){function t(){this.constructor=o}e(o,n),o.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}}(),d=this&&this.__decorate||function(e,o,n,t){var l,a=arguments.length,r=a<3?o:null===t?t=Object.getOwnPropertyDescriptor(o,n):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,o,n,t);else for(var d=e.length-1;d>=0;d--)(l=e[d])&&(r=(a<3?l(r):a>3?l(o,n,r):l(o,n))||r);return a>3&&r&&Object.defineProperty(o,n,r),r},s=this&&this.__metadata||function(e,o){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,o)},i=function(e){function l(n){var t=e.call(this,n)||this;return t.validationService=n,t.bindId=!0,t.context=null,t.hasErrorMessaging=!1,t.blur=new o.EventEmitter,t.change=new o.EventEmitter,t.focus=new o.EventEmitter,t}return r(l,e),a=l,l.prototype.ngOnChanges=function(o){e.prototype.ngOnChanges.call(this,o),o.model&&(this.type=a.getFormControlType(this.model))},l.getFormControlType=function(e){switch(e.type){case t.DYNAMIC_FORM_CONTROL_TYPE_ARRAY:return 1;case t.DYNAMIC_FORM_CONTROL_TYPE_CHECKBOX:return 2;case t.DYNAMIC_FORM_CONTROL_TYPE_CHECKBOX_GROUP:case t.DYNAMIC_FORM_CONTROL_TYPE_GROUP:return 3;case t.DYNAMIC_FORM_CONTROL_TYPE_INPUT:return 4;case t.DYNAMIC_FORM_CONTROL_TYPE_RADIO_GROUP:return 5;case t.DYNAMIC_FORM_CONTROL_TYPE_SELECT:return 6;case t.DYNAMIC_FORM_CONTROL_TYPE_SWITCH:return 7;case t.DYNAMIC_FORM_CONTROL_TYPE_TEXTAREA:return 8;default:return null}},d([o.Input(),s("design:type",Boolean)],l.prototype,"bindId",void 0),d([o.Input(),s("design:type",t.DynamicFormArrayGroupModel)],l.prototype,"context",void 0),d([o.Input(),s("design:type",n.FormGroup)],l.prototype,"group",void 0),d([o.Input(),s("design:type",Boolean)],l.prototype,"hasErrorMessaging",void 0),d([o.Input(),s("design:type",t.DynamicFormControlModel)],l.prototype,"model",void 0),d([o.Input(),s("design:type",o.QueryList)],l.prototype,"nestedTemplates",void 0),d([o.Output(),s("design:type",o.EventEmitter)],l.prototype,"blur",void 0),d([o.Output(),s("design:type",o.EventEmitter)],l.prototype,"change",void 0),d([o.Output(),s("design:type",o.EventEmitter)],l.prototype,"focus",void 0),d([o.ContentChildren(t.DynamicTemplateDirective),s("design:type",o.QueryList)],l.prototype,"contentTemplates",void 0),l=a=d([o.Component({selector:"dynamic-form-foundation-sites-control",template:'<div [formGroup]="group" [ngClass]="[model.cls.element.container, model.cls.grid.container]"><div *ngIf="type !== 2 && model.label !== null" [ngClass]="model.cls.grid.label"><label [attr.for]="model.id" [class.is-invalid-label]="hasErrorMessaging && !hasFocus && isInvalid" [innerHTML]="model.label" [ngClass]="model.cls.element.label"></label></div><ng-template *ngIf="type !== 1 && template?.align === \'START\'" [ngTemplateOutlet]="template.templateRef" [ngTemplateOutletContext]="model"></ng-template><div [ngClass]="model.cls.grid.control"><ng-container [ngSwitch]="type"><div *ngSwitchCase="1" [dynamicId]="bindId && model.id" [formArrayName]="model.id" [ngClass]="model.cls.element.control"><div *ngFor="let groupModel of model.groups; let idx = index" role="group" [formGroupName]="idx" [ngClass]="[model.cls.element.group, model.cls.grid.group]"><dynamic-form-foundation-sites-control *ngFor="let item of groupModel.group" [bindId]="false" [context]="groupModel" [group]="control.at(idx)" [hasErrorMessaging]="item.hasErrorMessages" [model]="item" [nestedTemplates]="templates" [ngClass]="[item.cls.element.host, item.cls.grid.host]" (blur)="onFocusChange($event)" (change)="onValueChange($event)" (focus)="onFocusChange($event)"></dynamic-form-foundation-sites-control><ng-container *ngTemplateOutlet="template?.templateRef; context: groupModel"></ng-container></div></div><label *ngSwitchCase="2"><input type="checkbox" [attr.tabindex]="model.tabIndex" [checked]="model.checked" [dynamicId]="bindId && model.id" [formControlName]="model.id" [name]="model.name" [ngClass]="model.cls.element.control" [required]="model.required" [value]="model.value" (blur)="onFocusChange($event)" (change)="onValueChange($event)" (focus)="onFocusChange($event)"><span [ngClass]="[model.cls.element.label, model.cls.grid.label]" [innerHTML]="model.label"></span></label><fieldset *ngSwitchCase="3" [dynamicId]="bindId && model.id" [formGroupName]="model.id" [name]="model.name" [ngClass]="model.cls.element.control"><legend *ngIf="model.legend">{{model.legend}}</legend><dynamic-form-foundation-sites-control *ngFor="let itemModel of model.group" [group]="control" [hasErrorMessaging]="itemModel.hasErrorMessages" [model]="itemModel" [nestedTemplates]="templates" [ngClass]="[itemModel.cls.element.host, itemModel.cls.grid.host]" (blur)="onFocusChange($event)" (change)="onValueChange($event)" (focus)="onFocusChange($event)"></dynamic-form-foundation-sites-control></fieldset><div *ngSwitchCase="4" class="input-group"><span *ngIf="model.prefix" class="input-group-label" [innerHTML]="model.prefix"></span> <input class="input-group-field" [attr.accept]="model.accept" [attr.autoComplete]="model.autoComplete" [attr.list]="model.listId" [attr.max]="model.max" [attr.min]="model.min" [attr.multiple]="model.multiple" [attr.step]="model.step" [attr.tabindex]="model.tabIndex" [autofocus]="model.autoFocus" [class.is-invalid-input]="hasErrorMessaging && !hasFocus && isInvalid" [dynamicId]="bindId && model.id" [formControlName]="model.id" [maxlength]="model.maxLength" [minlength]="model.minLength" [name]="model.name" [ngClass]="model.cls.element.control" [pattern]="model.pattern" [placeholder]="model.placeholder" [readonly]="model.readOnly" [required]="model.required" [spellcheck]="model.spellCheck" [textMask]="{mask: (model.mask || false), showMask: model.mask && !(model.placeholder)}" [type]="model.inputType" (blur)="onFocusChange($event)" (change)="onValueChange($event)" (focus)="onFocusChange($event)"> <span *ngIf="model.suffix" class="input-group-label" [innerHTML]="model.suffix"></span><datalist *ngIf="model.list" [id]="model.listId"><option *ngFor="let option of model.list" [value]="option"></option></datalist></div><fieldset *ngSwitchCase="5" role="radiogroup" [attr.tabindex]="model.tabIndex" [dynamicId]="bindId && model.id" [name]="model.name" (change)="onValueChange($event)"><legend *ngIf="model.legend" [innerHTML]="model.legend"></legend><label *ngFor="let option of model.options$ | async"><input type="radio" [formControlName]="model.id" [name]="model.name" [ngClass]="model.cls.element.control" [value]="option.value" (blur)="onFocusChange($event)" (focus)="onFocusChange($event)"><span [innerHTML]="option.label"></span></label></fieldset><select *ngSwitchCase="6" [attr.tabindex]="model.tabIndex" [dynamicId]="bindId && model.id" [formControlName]="model.id" [name]="model.name" [ngClass]="model.cls.element.control" [required]="model.required" (blur)="onFocusChange($event)" (change)="onValueChange($event)" (focus)="onFocusChange($event)"><option *ngFor="let option of model.options$ | async" [attr.name]="model.name" [ngValue]="option.value">{{option.label}}</option></select><div *ngSwitchCase="7" class="switch" [ngClass]="model.cls.element.control"><input type="checkbox" class="switch-input" [attr.tabindex]="model.tabIndex" [checked]="model.checked" [dynamicId]="bindId && model.id" [formControlName]="model.id" [name]="model.name" [required]="model.required" [value]="model.value" (blur)="onFocusChange($event)" (change)="onValueChange($event)" (focus)="onFocusChange($event)"><label class="switch-paddle" [attr.for]="model.id"><span class="switch-active" aria-hidden="true">{{model.onLabel}}</span> <span class="switch-inactive" aria-hidden="true">{{model.offLabel}}</span></label></div><textarea *ngSwitchCase="8" [attr.tabindex]="model.tabIndex" [class.is-invalid-input]="hasErrorMessaging && !hasFocus && isInvalid" [cols]="model.cols" [dynamicId]="bindId && model.id" [formControlName]="model.id" [maxlength]="model.maxLength" [minlength]="model.minLength" [name]="model.name" [ngClass]="model.cls.element.control" [placeholder]="model.placeholder" [readonly]="model.readOnly" [required]="model.required" [rows]="model.rows" [spellcheck]="model.spellCheck" [wrap]="model.wrap" (blur)="onFocusChange($event)" (change)="onValueChange($event)" (focus)="onFocusChange($event)"></textarea></ng-container><p *ngIf="hasHint" class="help-text" [ngClass]="model.cls.element.hint" [innerHTML]="model.hint"></p></div><ul *ngIf="hasErrorMessaging" [ngClass]="[model.cls.element.errors, model.cls.grid.errors]"><li *ngFor="let message of errorMessages" class="form-error" [class.is-visible]="showErrorMessages">{{message}}</li></ul><ng-template *ngIf="type !== 1 && template?.align === \'END\'" [ngTemplateOutlet]="template.templateRef" [ngTemplateOutletContext]="model"></ng-template><ng-content></ng-content></div>'}),s("design:paramtypes",[t.DynamicFormValidationService])],l);var a}(t.DynamicFormControlComponent),m=this&&this.__decorate||function(e,o,n,t){var l,a=arguments.length,r=a<3?o:null===t?t=Object.getOwnPropertyDescriptor(o,n):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,o,n,t);else for(var d=e.length-1;d>=0;d--)(l=e[d])&&(r=(a<3?l(r):a>3?l(o,n,r):l(o,n))||r);return a>3&&r&&Object.defineProperty(o,n,r),r},c=function(){function e(){}return e=m([o.NgModule({imports:[l.CommonModule,n.ReactiveFormsModule,a.TextMaskModule,t.DynamicFormsCoreModule],declarations:[i],exports:[t.DynamicFormsCoreModule,i]})],e)}();e.DynamicFormFoundationSitesComponent=i,e.DynamicFormsFoundationUIModule=c,Object.defineProperty(e,"__esModule",{value:!0})});