add-new-license.component.js
10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
"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