diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-05 15:01:45 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-05 15:02:27 +0200 |
commit | e309822b93d9b69f30cbe830ef3d09dfdb2c13b2 (patch) | |
tree | 41dbc3b3108ced7fdba4062974e568695c30e486 /client/src/app/shared/forms/form-validators/user-validators.service.ts | |
parent | d4d5853e65e584ca51c718f8df590b987f981047 (diff) | |
download | PeerTube-e309822b93d9b69f30cbe830ef3d09dfdb2c13b2.tar.gz PeerTube-e309822b93d9b69f30cbe830ef3d09dfdb2c13b2.tar.zst PeerTube-e309822b93d9b69f30cbe830ef3d09dfdb2c13b2.zip |
Add form validator translations
Diffstat (limited to 'client/src/app/shared/forms/form-validators/user-validators.service.ts')
-rw-r--r-- | client/src/app/shared/forms/form-validators/user-validators.service.ts | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/client/src/app/shared/forms/form-validators/user-validators.service.ts b/client/src/app/shared/forms/form-validators/user-validators.service.ts new file mode 100644 index 000000000..bb6ff2068 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/user-validators.service.ts | |||
@@ -0,0 +1,93 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { Validators } from '@angular/forms' | ||
3 | import { BuildFormValidator } from '@app/shared' | ||
4 | import { Injectable } from '@angular/core' | ||
5 | |||
6 | @Injectable() | ||
7 | export class UserValidatorsService { | ||
8 | readonly USER_USERNAME: BuildFormValidator | ||
9 | readonly USER_EMAIL: BuildFormValidator | ||
10 | readonly USER_PASSWORD: BuildFormValidator | ||
11 | readonly USER_VIDEO_QUOTA: BuildFormValidator | ||
12 | readonly USER_ROLE: BuildFormValidator | ||
13 | readonly USER_DISPLAY_NAME: BuildFormValidator | ||
14 | readonly USER_DESCRIPTION: BuildFormValidator | ||
15 | |||
16 | constructor (private i18n: I18n) { | ||
17 | |||
18 | this.USER_USERNAME = { | ||
19 | VALIDATORS: [ | ||
20 | Validators.required, | ||
21 | Validators.minLength(3), | ||
22 | Validators.maxLength(20), | ||
23 | Validators.pattern(/^[a-z0-9._]+$/) | ||
24 | ], | ||
25 | MESSAGES: { | ||
26 | 'required': this.i18n('Username is required.'), | ||
27 | 'minlength': this.i18n('Username must be at least 3 characters long.'), | ||
28 | 'maxlength': this.i18n('Username cannot be more than 20 characters long.'), | ||
29 | 'pattern': this.i18n('Username should be only lowercase alphanumeric characters.') | ||
30 | } | ||
31 | } | ||
32 | |||
33 | this.USER_EMAIL = { | ||
34 | VALIDATORS: [ Validators.required, Validators.email ], | ||
35 | MESSAGES: { | ||
36 | 'required': this.i18n('Email is required.'), | ||
37 | 'email': this.i18n('Email must be valid.') | ||
38 | } | ||
39 | } | ||
40 | |||
41 | this.USER_PASSWORD = { | ||
42 | VALIDATORS: [ | ||
43 | Validators.required, | ||
44 | Validators.minLength(6), | ||
45 | Validators.maxLength(255) | ||
46 | ], | ||
47 | MESSAGES: { | ||
48 | 'required': this.i18n('Password is required.'), | ||
49 | 'minlength': this.i18n('Password must be at least 6 characters long.'), | ||
50 | 'maxlength': this.i18n('Password cannot be more than 255 characters long.') | ||
51 | } | ||
52 | } | ||
53 | |||
54 | this.USER_VIDEO_QUOTA = { | ||
55 | VALIDATORS: [ Validators.required, Validators.min(-1) ], | ||
56 | MESSAGES: { | ||
57 | 'required': this.i18n('Video quota is required.'), | ||
58 | 'min': this.i18n('Quota must be greater than -1.') | ||
59 | } | ||
60 | } | ||
61 | |||
62 | this.USER_ROLE = { | ||
63 | VALIDATORS: [ Validators.required ], | ||
64 | MESSAGES: { | ||
65 | 'required': this.i18n('User role is required.') | ||
66 | } | ||
67 | } | ||
68 | |||
69 | this.USER_DISPLAY_NAME = { | ||
70 | VALIDATORS: [ | ||
71 | Validators.required, | ||
72 | Validators.minLength(3), | ||
73 | Validators.maxLength(120) | ||
74 | ], | ||
75 | MESSAGES: { | ||
76 | 'required': this.i18n('Display name is required.'), | ||
77 | 'minlength': this.i18n('Display name must be at least 3 characters long.'), | ||
78 | 'maxlength': this.i18n('Display name cannot be more than 120 characters long.') | ||
79 | } | ||
80 | } | ||
81 | |||
82 | this.USER_DESCRIPTION = { | ||
83 | VALIDATORS: [ | ||
84 | Validators.minLength(3), | ||
85 | Validators.maxLength(250) | ||
86 | ], | ||
87 | MESSAGES: { | ||
88 | 'minlength': this.i18n('Description must be at least 3 characters long.'), | ||
89 | 'maxlength': this.i18n('Description cannot be more than 250 characters long.') | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||