"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var core_1 = require('@angular/core'); var router_1 = require('@angular/router'); var application_service_1 = require('../services/application.service'); //import { OnlyNumber } from '../components/shared/only-number-validator.directive'; //import { EmailValidator } from '../components/shared/email-validator.directive'; //import { forbiddenNameValidator } from '../components/shared/forbidden-name-validator.directive'; var forms_1 = require('@angular/forms'); var AddNewLicenseComponent = (function () { function AddNewLicenseComponent(application, router, fb) { this.application = application; this.router = router; this.fb = fb; //addNewLicenseForm: FormGroup; this.addNewLicenseForm = new forms_1.FormGroup({ licenseType: new forms_1.FormControl(), accountNo: new forms_1.FormControl(), licenseeFirstName: new forms_1.FormControl(), licenseeLastName: new forms_1.FormControl(), accountType: new forms_1.FormControl(), institutionName: new forms_1.FormControl(), address: new forms_1.FormControl(), city: new forms_1.FormControl(), state: new forms_1.FormControl(), country: new forms_1.FormControl(), zip: new forms_1.FormControl(), phone: new forms_1.FormControl(), email: new forms_1.FormControl(), subscriptionStartDate: new forms_1.FormControl(), subscriptionEndDate: new forms_1.FormControl(), subscriptionPrice: new forms_1.FormControl(), exportImages: new forms_1.FormControl(), userName1: new forms_1.FormControl(), password: new forms_1.FormControl(), securityQuestion: new forms_1.FormControl(), answer: new forms_1.FormControl() }); this.LicenseTypes = ['Concurrent License', 'Single License', 'Site License', 'Reseller']; this.AccountTypes = ['High School', 'Community College', 'Career College', 'Higher Education', 'Library', 'Medical School', 'Corporate Training', 'Other']; this.SecurityQuestions = ['What is your pets name', 'Where did you spend your ....', 'What was the last name of your ....', 'What is the name of your ....']; this.formErrors = { 'licenseType': '', 'accountNo': '', 'licenseeFirstName': '', 'licenseeLastName': '', 'accountType': '', 'institutionName': '', 'address': '', 'city': '', 'state': '', 'country': '', 'zip': '', 'phone': '', 'email': '', 'subscriptionStartDate': '', 'subscriptionEndDate': '', 'subscriptionPrice': '', 'exportImages': '', 'userName1': '', 'password': '', 'securityQuestion': '', 'answer': '' }; this.validationMessages = { 'licenseType': { 'required': 'License type is required.' }, 'accountNo': { 'required': 'Account Number is required.' }, 'licenseeFirstName': { 'required': 'LicenseeFirstName is required.', 'forbiddenName': 'Someone named "Bob" cannot be a Licensee' }, 'licenseeLastName': { 'required': 'LicenseeLastName is required.' }, 'accountType': { 'required': 'AccountType is required.' }, 'institutionName': { 'required': 'InstitutionName is required.' }, 'address': { 'required': 'Address is required.' }, 'city': { 'required': 'City is required.' }, 'state': { 'required': 'State is required.' }, 'country': { 'required': 'Country is required.' }, 'zip': { 'required': 'Zip is required.', 'pattern': 'Only 5 digited numbers (US zip) are allowed.' }, 'phone': { 'required': 'Phone is required.', 'pattern': 'Not a valid US pattern.' }, 'email': { 'required': 'Email is required.', 'pattern': 'Email pattern is not valid.' }, 'subscriptionStartDate': { 'required': 'SubscriptionStartDate is required.' }, 'subscriptionEndDate': { 'required': 'SubscriptionEndDate is required.' }, 'subscriptionPrice': { 'required': 'SubscriptionPrice is required.', 'pattern': 'Currency not valid.' }, 'exportImages': { 'required': 'ExportImages is required.', 'pattern': 'Only numbers are allowed.' }, 'userName1': { 'required': 'UserName is required.' }, 'password': { 'required': 'Password is required.' }, 'securityQuestion': { 'required': 'SecurityQuestion is required.' }, 'answer': { 'required': 'Answer is required.' } }; this.createForm(); } AddNewLicenseComponent.prototype.createForm = function () { var _this = this; this.addNewLicenseForm = this.fb.group({ licenseType: ['', forms_1.Validators.required], accountNo: ['', [forms_1.Validators.required]], licenseeFirstName: ['', forms_1.Validators.required], licenseeLastName: ['', forms_1.Validators.required], accountType: ['', forms_1.Validators.required], institutionName: ['', forms_1.Validators.required], address: ['', forms_1.Validators.required], city: ['', forms_1.Validators.required], state: ['', forms_1.Validators.required], country: ['', forms_1.Validators.required], zip: ['', forms_1.Validators.compose([(forms_1.Validators.required, forms_1.Validators.pattern(/^\d{5}$/))])], phone: ['', forms_1.Validators.compose([(forms_1.Validators.required, forms_1.Validators.pattern(/^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/))])], email: ['', forms_1.Validators.compose([forms_1.Validators.required, forms_1.Validators.pattern(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)])], subscriptionStartDate: ['', forms_1.Validators.required], subscriptionEndDate: ['', forms_1.Validators.required], subscriptionPrice: ['', [(forms_1.Validators.required, forms_1.Validators.pattern(/^\$?[0-9][0-9,]*[0-9]\.?[0-9]{0,2}$/i))]], exportImages: ['', forms_1.Validators.compose([forms_1.Validators.required, forms_1.Validators.pattern('(?:NaN|-?(?:(?:\\d+|\\d*\\.\\d+)(?:[E|e][+|-]?\\d+)?|Infinity))')])], userName1: ['', forms_1.Validators.required], password: ['', forms_1.Validators.required], securityQuestion: ['', forms_1.Validators.required], answer: ['', forms_1.Validators.required] }); this.addNewLicenseForm.valueChanges .subscribe(function (data) { return _this.onValueChanged(data); }); this.onValueChanged(); // (re)set validation messages now }; AddNewLicenseComponent.prototype.ngAfterViewInit = function () { this.initializeUIElements(); jQuery(function () { jQuery('#datetimepicker1, #datetimepicker2').datetimepicker({}); }); }; AddNewLicenseComponent.prototype.initializeUIElements = function () { }; AddNewLicenseComponent.prototype.ngOnInit = function () { /*if (this.application.currentUser == null) { this.router.navigate(['/login']); }*/ this.createForm(); }; AddNewLicenseComponent.prototype.showAlert = function (id) { jQuery('#' + id).modal('show'); }; //ngOnInit(): void { // this.buildForm(); //} //buildForm(): void { // this.heroForm = this.fb.group({ // 'name': [this.hero.name, [ // Validators.required, // Validators.minLength(4), // Validators.maxLength(24), // forbiddenNameValidator(/bob/i) // ] // ], // 'alterEgo': [this.hero.alterEgo], // 'power': [this.hero.power, Validators.required] // }); // this.heroForm.valueChanges // .subscribe(data => this.onValueChanged(data)); // this.onValueChanged(); // (re)set validation messages now //} AddNewLicenseComponent.prototype.onValueChanged = function (data) { if (!this.addNewLicenseForm) { return; } var form = this.addNewLicenseForm; for (var field in this.formErrors) { // clear previous error message (if any) this.formErrors[field] = ''; var control = form.get(field); if (control && control.dirty && !control.valid) { var messages = this.validationMessages[field]; for (var key in control.errors) { this.formErrors[field] += messages[key] + ' '; } } } }; AddNewLicenseComponent = __decorate([ core_1.Component({ templateUrl: './app/components/add-new-license.component.html' }), __metadata('design:paramtypes', [application_service_1.ApplicationService, router_1.Router, forms_1.FormBuilder]) ], AddNewLicenseComponent); return AddNewLicenseComponent; }()); exports.AddNewLicenseComponent = AddNewLicenseComponent; //# sourceMappingURL=add-new-license.component.js.map