@uiowa/uiowa-account
Version:
Angular library to manage MFK and UNI Account output
2 lines • 8.47 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/forms"),require("@uiowa/digit-only"),require("@angular/common"),require("@ng-bootstrap/ng-bootstrap")):"function"==typeof define&&define.amd?define("@uiowa/uiowa-account",["exports","@angular/core","@angular/forms","@uiowa/digit-only","@angular/common","@ng-bootstrap/ng-bootstrap"],e):e((t.uiowa=t.uiowa||{},t.uiowa["uiowa-account"]={}),t.ng.core,t.ng.forms,t["@uiowa/digit-only"],t.ng.common,t["@ng-bootstrap/ng-bootstrap"])}(this,function(t,e,n,o,i,r){"use strict";var s=function(){function t(){this.options=[],this.output=[]}return t.prototype.ngOnInit=function(){var n=this;this.account.elements.forEach(function(t,e){n.output.push({value:n.getElementOutput(t.webApiProperty,e),display:t.display,showDelimeter:n.account.showDelimeter(e)})})},t.prototype.getOverrideValue=function(e){var t=this.options.find(function(t){return t.name===e});if(t)return t.display},t.prototype.getElementOutput=function(t,e){if(0<this.options.length){var n=this.getOverrideValue(t);if(n)return n}return this.account.getElementString(e)},t.decorators=[{type:e.Component,args:[{selector:"uiowa-account-string",template:'\n <span *ngFor="let element of output" placement="bottom" ngbTooltip="{{element.display}}">{{element.value}}<span\n *ngIf="element.showDelimeter">{{account.delimiter}}</span></span>\n '}]}],t.ctorParameters=function(){return[]},t.propDecorators={account:[{type:e.Input}],options:[{type:e.Input}]},t}(),u=function(){function t(t,e,n,o){void 0===t&&(t=null),void 0===e&&(e="-"),void 0===n&&(n=[]),void 0===o&&(o="X"),this.elements=n,this.value=t,this.delimiter=e,this.valueAry=this.value.split(this.delimiter),this.defaultString=o}return t.prototype.getElementString=function(t){var e=this.valueAry[t];if(!e){var n=this.elements[t];if(n.isRequired)for(var o=1;o<=n.size;o++)e+=this.defaultString}return e},t.prototype.showDelimeter=function(t,e){return void 0===e&&(e=!1),!(this.lastElementIsOptionalAndEmpty(t)&&!e)&&!this.indexIsTheLastElement(t)},t.prototype.indexIsTheLastElement=function(t){return t===this.elements.length-1},t.prototype.lastElementIsOptionalAndEmpty=function(t){return t+2===this.elements.length&&!this.elements[t+1].isRequired&&!this.valueAry[t+1]},t}(),a=function v(t,e,n,o){void 0===e&&(e=0),void 0===n&&(n=null),this.display=t,this.size=e,this.webApiProperty=n,this.isRequired=o},l=function b(t,e,n){void 0===n&&(n=""),this.name=t,this.display=e,this.defaultValue=n},p=function(t,e){return(p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function c(t,e){function n(){this.constructor=t}p(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var d=function w(t){void 0===t&&(t={}),this.value=t.value,this.key=t.key||"",this.label=t.label||"",this.required=!!t.required,this.order=t.order===undefined?1:t.order,this.controlType=t.controlType||"",this.id=t.id||"",this.size=t.size||10,this.display=t.display||""},h=function(n){function t(t){void 0===t&&(t={});var e=n.call(this,t)||this;return e.controlType="textbox",e.type="string",e.type=t.type,e}return c(t,n),t}(d),f=function(n){function t(t){void 0===t&&(t={});var e=n.call(this,t)||this;return e.controlType="hidden",e.type="string",e.type=t.type,e}return c(t,n),t}(d),m=function(){function t(){}return t.prototype.toFormGroup=function(t){var e={};return t.forEach(function(t){e[t.key]=t.required?new n.FormControl(t.value||"",n.Validators.required):new n.FormControl(t.value||"")}),new n.FormGroup(e)},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[]},t}(),y=function(){function t(t){this.inputControlService=t,this.options=[],this.index=0,this.accountChange=new e.EventEmitter,this.questions=[]}return t.prototype.ngOnInit=function(){var o=this;this.account.elements.forEach(function(e,t){if(o.options.find(function(t){return t.name===e.webApiProperty})){var n=o.options.find(function(t){return t.name===e.webApiProperty});o.questions.push(new f({value:n.defaultValue,label:e.display,key:e.webApiProperty+"_"+o.index,size:e.size,display:n.display,id:e.webApiProperty+"_"+o.index}))}else o.questions.push(new h({value:o.account.getElementString(t),label:e.display,key:e.webApiProperty+"_"+o.index,size:e.size,name:e.webApiProperty,id:e.webApiProperty+"_"+o.index}))}),this.form=this.inputControlService.toFormGroup(this.questions),this.accountString=this.parse(this.questions,this.account.delimiter)},t.prototype.parseAccount=function(){return this.parse(this.questions,this.account.delimiter)},t.prototype.parse=function(t,n){var o=this,i="";return t.forEach(function(t,e){i+=t.value,o.account.showDelimeter(e,!0)&&(i+=n)}),i},t.prototype.paste=function(t){var e=t.clipboardData.getData("text/plain").trim();t.preventDefault(),e&&(this.pasteAccount(e.split(this.account.delimiter)),this.accountChange.emit(this.parseAccount()))},t.prototype.pasteAccount=function(t){var n=this;t.forEach(function(t,e){e+1<=n.questions.length&&"hidden"!==n.questions[e].controlType&&!isNaN(+t)&&n.questions[e].size===t.trim().length&&n.form.controls[n.questions[e].id].patchValue(t)})},t.prototype.onKeyup=function(t){if(this.accountChange.emit(this.parseAccount()),!(t.keyCode<48||57<t.keyCode)||!(t.keyCode<96||105<t.keyCode)){var e=t.target.id;if(this.form.controls[e].value.length===t.target.maxLength)for(var n=this.questions.findIndex(function(t){return t.key===e}),o=function(t){if("hidden"===i.questions[t].controlType)return"continue";var e=i.questions[t];return i.formInputs.find(function(t){return t.el.nativeElement.id===e.key}).el.nativeElement.focus(),"break"},i=this,r=n+1;r<this.questions.length;r++){if("break"===o(r))break}}},t.prototype.onKeydown=function(t){if(9===t.keyCode&&!t.target.readOnly)for(;this.form.controls[t.target.id].value.length<t.target.maxLength;)this.form.controls[t.target.id].patchValue(this.form.controls[t.target.id].value.concat(0))},t.decorators=[{type:e.Component,args:[{selector:"uiowa-account-input",template:'<div id="account-container">\n <form (ngSubmit)="null" [formGroup]="form">\n <div *ngFor="let question of questions" class="account-field" [style.width.rem]="question.size + 1">\n <div [formGroup]="form">\n <label [attr.for]="question.id" class="account-field-label">{{question.label}}</label>\n\n <div [ngSwitch]="question.controlType" [ngClass]="{hiddenLabel: question.controlType === \'hidden\'}">\n\n <input *ngSwitchCase="\'textbox\'" [formControlName]="question.key" [id]="question.id" [type]="question.controlType"\n [attr.maxlength]="question.size" [style.width.rem]="question.size+1" [attr.maxlength]="question.size"\n inputmode="numeric" pattern="[0-9]*" digitOnly class="form-control" (keydown)="onKeydown($event)" (keyup)="onKeyup($event)"\n (paste)="paste($event)">\n <input *ngSwitchCase="\'hidden\'" [formControlName]="question.key" [id]="question.id" [type]="question.controlType"\n [attr.maxlength]="question.size" [style.width.rem]="question.size">\n <span *ngSwitchCase="\'hidden\'">{{question.display}}</span>\n </div>\n </div>\n </div>\n </form>\n</div>\n',providers:[m],styles:[":host{display:inline-flex}.account-field{display:inline-block;vertical-align:bottom;margin-right:.25rem}.account-field .form-control{padding:.375rem!important;text-align:center;font-size:1rem;font-weight:400;font-style:normal;font-variant:normal}label.account-field-label{display:block;font-size:.625rem;margin-bottom:0;text-align:center;white-space:nowrap}div.hiddenLabel{margin-top:7px;text-align:center;padding-bottom:6px}"]}]}],t.ctorParameters=function(){return[{type:m}]},t.propDecorators={account:[{type:e.Input}],options:[{type:e.Input}],index:[{type:e.Input}],accountChange:[{type:e.Output}],formInputs:[{type:e.ViewChildren,args:[o.DigitOnlyDirective]}]},t}(),g=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[i.CommonModule,r.NgbModule,o.DigitOnlyModule,n.ReactiveFormsModule,n.FormsModule],declarations:[s,y],exports:[s,y]}]}],t}();t.AccountStringComponent=s,t.UiowaAccountModule=g,t.Account=u,t.Element=a,t.FieldOption=l,t.ElementInputText=h,t.ElementInputBase=d,t.ElementInputHidden=f,t.ɵa=y,t.ɵb=m,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=uiowa-uiowa-account.umd.min.js.map