UNPKG

@uiowa/uiowa-mfk-material

Version:

mfk, uiowa-mfk

2 lines 9.05 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common"),require("@angular/forms"),require("@uiowa/digit-only"),require("@angular/platform-browser/animations"),require("@angular/flex-layout"),require("@angular/material")):"function"==typeof define&&define.amd?define("@uiowa/uiowa-mfk-material",["exports","@angular/core","@angular/common","@angular/forms","@uiowa/digit-only","@angular/platform-browser/animations","@angular/flex-layout","@angular/material"],e):e(((t=t||self).uiowa=t.uiowa||{},t.uiowa["uiowa-mfk-material"]={}),t.ng.core,t.ng.common,t.ng.forms,t.digitOnly,t.ng.platformBrowser.animations,t.ng["flex-layout"],t.ng.material)}(this,function(t,e,n,i,r,o,a,s){"use strict";function l(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(s){r={error:s}}finally{try{i&&!i.done&&(n=o["return"])&&n.call(o)}finally{if(r)throw r.error}}return a}var u=new e.InjectionToken("config"),f=function(){function t(t){void 0===t&&(t=null),this.FUND="",this.ORG="",this.DEPT="",this.SUBDEPT="",this.GRANTPGM="",this.IACT="",this.OACT="",this.DACT="",this.FN="",this.CCTR="",this.BRF="",t&&this.parseString(t)}return t.cast=function(e){var n=new t;return Object.keys(e).forEach(function(t){return n[t.toUpperCase()]=e[t]}),n},t.prototype.equals=function(t){return this.FUND===t.FUND&&this.ORG===t.ORG&&this.DEPT===t.DEPT&&this.SUBDEPT===t.SUBDEPT&&this.GRANTPGM===t.GRANTPGM&&this.IACT===t.IACT&&this.DACT===t.DACT&&this.OACT===t.OACT&&this.FN===t.FN&&this.CCTR===t.CCTR},t.prototype.to40String=function(t){var e=this;return void 0===t&&(t=""),Object.keys(this).filter(function(t){return"BRF"!==t}).map(function(t){return e[t]}).join(t)},t.prototype.validateFormat=function(){var t=this.to40String();return 40!==t.length?"MFK is not 40 digits long.":isNaN(Number(t))?"MFK ["+t+"] should be all numbers.":null},t.prototype.isIn=function(t){var e=this;return!(!t||t.length<1)&&t.some(function(t){return t.matches(e)})},t.prototype.parseString=function(t){var e=t.replace(/\D/g,"");!e||e.length<40||(this.FUND=e.substring(0,3),this.ORG=e.substring(3,5),this.DEPT=e.substring(5,9),this.SUBDEPT=e.substring(9,14),this.GRANTPGM=e.substring(14,22),this.IACT=e.substring(22,26),this.OACT=e.substring(26,29),this.DACT=e.substring(29,34),this.FN=e.substring(34,36),this.CCTR=e.substring(36,40),e.length>=42&&(this.BRF=e.substring(40,42)))},t}(),h=function(){function t(){}return t.FUND="FUND",t.ORG="ORG",t.DEPT="DEPT",t.SUBDEPT="SUBDEPT",t.GRANTPGM="GRANTPGM",t.IACT="IACT",t.OACT="OACT",t.DACT="DACT",t.FN="FN",t.CCTR="CCTR",t.BRF="BRF",t}(),p=function(){function t(t,e,n,i){if(void 0===e&&(e=""),void 0===n&&(n=!1),void 0===i&&(i="^[0-9]+$"),this.name=t,this.defaultValue=e,this.readonly=n,this.valuePattern=i,this.numericRegex="^[0-9]+$",this.getFieldLabelAndLength(),this.width=.65*this.length+.75,i||(i=this.numericRegex),this.readonly){if(!this.defaultValue)throw new Error("Default value for readonly field ["+t+"] is required.")}else if(e){if(e.length!==this.length)throw new Error("The default value ["+e+"] for "+t+" is not "+this.length+" digits long.");var r=new RegExp(this.numericRegex);if(!r.test(e))throw new Error("The default value ["+e+"] for "+t+" is not a number.");if(i!==this.numericRegex&&!(r=new RegExp(i)).test(e))throw new Error("The default value ["+e+"] for "+t+" doesn't match RegEx \""+i+'".')}}return t.prototype.getFieldLabelAndLength=function(){switch(this.name){case h.FUND:this.label="Fund",this.length=3;break;case h.ORG:this.label="Org",this.length=2;break;case h.DEPT:this.label="Dept",this.length=4;break;case h.SUBDEPT:this.label="Subdept",this.length=5;break;case h.GRANTPGM:this.label="Grant/Pgm",this.length=8;break;case h.IACT:this.label="Iact",this.length=4;break;case h.OACT:this.label="Oact",this.length=3;break;case h.DACT:this.label="Dact",this.length=5;break;case h.FN:this.label="Fn",this.length=2;break;case h.CCTR:this.label="Cctr",this.length=4;break;case h.BRF:this.label="Brf",this.length=2;break;default:throw new Error("MFK field name ["+this.name+"] is invalid.")}},t}(),c=function(){function t(){this.defaultOptions=[new p(h.FUND),new p(h.ORG),new p(h.DEPT),new p(h.SUBDEPT),new p(h.GRANTPGM),new p(h.IACT),new p(h.OACT),new p(h.DACT),new p(h.FN),new p(h.CCTR)]}return t.prototype.getOptions=function(t){var e,n;void 0===t&&(t=[]);var i=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(l(arguments[e]));return t}(this.defaultOptions);if(t&&t.length>0){var r=function(t){var e=i.find(function(e){return e.name===t.name});if(e){var n=i.indexOf(e);i[n]=t}else i.push(t)};try{for(var o=function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}(t),a=o.next();!a.done;a=o.next()){r(a.value)}}catch(s){e={error:s}}finally{try{a&&!a.done&&(n=o["return"])&&n.call(o)}finally{if(e)throw e.error}}}return i},t.prototype.getAllOptions=function(){return this.defaultOptions},t.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t},token:t,providedIn:"root"}),t}(),m=function(){function t(t){this.optionsService=t,this._mfk=new f,this.options=[],this.mfkChange=new e.EventEmitter}return Object.defineProperty(t.prototype,"mfk",{get:function(){var t=this;return this.options.filter(function(t){return t.readonly}).forEach(function(e){t._mfk[e.name]=e.defaultValue}),this._mfk},set:function(t){this.options.filter(function(t){return t.defaultValue}).forEach(function(e){t[e.name]||(t[e.name]=e.defaultValue)}),this._mfk=t},enumerable:!0,configurable:!0}),t.prototype.ngOnChanges=function(t){t.mfk&&(this.mfk=t.mfk.currentValue),t.options&&(this.options=t.options.currentValue,this.options=this.optionsService.getOptions(this.options))},t.prototype.ngOnInit=function(){this.options=this.optionsService.getAllOptions(),console.log(this.options)},t.prototype.ngAfterViewInit=function(){},t.prototype.paste=function(t){var e=t.clipboardData.getData("text/plain").replace(/\D/g,"");t.preventDefault(),e&&(e.length<40?document.execCommand("insertText",!1,e):this.mfk.parseString(e),this.mfkChange.emit(this.mfk))},t.prototype.onKeyup=function(t){var e=this;if(this.mfkChange.emit(this.mfk),!(t.keyCode<48||t.keyCode>57)||!(t.keyCode<96||t.keyCode>105)){var n=t.target.name;if(this.mfk[n].length===t.target.maxLength)for(var i=this.options.findIndex(function(t){return t.name===n}),r=function(t){return o.options[t].readonly?"continue":(o.mfkInputFields.find(function(n){return n.el.nativeElement.name===e.options[t].name}).el.nativeElement.focus(),"break")},o=this,a=i+1;a<this.options.length;a++){if("break"===r(a))break}}},t.prototype.onKeydown=function(t){if(9===t.keyCode&&!t.target.readOnly)for(var e=t.target.maxLength;this.mfk[t.target.name].length<e;)this.mfk[t.target.name]=this.mfk[t.target.name].concat("0")},t.decorators=[{type:e.Component,args:[{selector:"uiowa-mfk-input",template:'<div id="mfk-container">\r\n <div class="mfk-field" fxLayout="row inline" fxLayout.xs="column" fxLayoutAlign="start center"\r\n *ngFor="let option of options" fxLayoutWrap fxLayoutGap="0.5%">\r\n <mat-form-field class="form-control" [ngStyle]="{\'width.rem\': option.width+0.5}" appearance="outline"\r\n floatLabel="always" style=" font-size: 14px;">\r\n <mat-label>{{option.label}}</mat-label>\r\n <input matInput [attr.aria-label]="option.name" [attr.name]="option.name" [attr.maxlength]="option.length"\r\n [readOnly]="option.readonly" [(ngModel)]="mfk[option.name]" (paste)="paste($event)" (keyup)="onKeyup($event)"\r\n (keydown)="onKeydown($event)" inputmode="numeric" pattern="[0-9]*" digitOnly>\r\n </mat-form-field>\r\n\r\n\r\n </div>\r\n</div>\r\n',styles:[":host{display:inline-flex}.mfk-field{display:flex;flex-direction:row;flex-flow:row;vertical-align:bottom;margin-right:.25rem}.mat-form-field{padding:.375rem!important;font-size:1rem;font-weight:400;font-style:normal;font-variant:normal}.mat-label{font-size:.625rem;margin-bottom:0;white-space:nowrap}"]}]}],t.ctorParameters=function(){return[{type:c}]},t.propDecorators={mfk:[{type:e.Input}],options:[{type:e.Input}],mfkChange:[{type:e.Output}],mfkInputFields:[{type:e.ViewChildren,args:[r.DigitOnlyDirective]}]},t}(),g=function(){function t(){}return t.forRoot=function(e){return void 0===e&&(e={favoriteMfksApiUrl:"api/myFavoriteMfks"}),{ngModule:t,providers:[{provide:u,useValue:e}]}},t.decorators=[{type:e.NgModule,args:[{declarations:[m],imports:[n.CommonModule,i.FormsModule,r.DigitOnlyModule,s.MatFormFieldModule,o.BrowserAnimationsModule,s.MatInputModule,a.FlexLayoutModule],exports:[m]}]}],t}();t.Mfk=f,t.MfkFieldName=h,t.MfkFieldOption=p,t.MfkInputComponent=m,t.UiowaMfkMaterialModule=g,t.ɵa=c,t.ɵb=u,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=uiowa-uiowa-mfk-material.umd.min.js.map