Reorganize client shared modules
[oweals/peertube.git] / client / src / app / shared / shared-forms / form-validators / instance-validators.service.ts
1 import { I18n } from '@ngx-translate/i18n-polyfill'
2 import { Validators } from '@angular/forms'
3 import { BuildFormValidator } from './form-validator.service'
4 import { Injectable } from '@angular/core'
5
6 @Injectable()
7 export class InstanceValidatorsService {
8   readonly FROM_EMAIL: BuildFormValidator
9   readonly FROM_NAME: BuildFormValidator
10   readonly SUBJECT: BuildFormValidator
11   readonly BODY: BuildFormValidator
12
13   constructor (private i18n: I18n) {
14
15     this.FROM_EMAIL = {
16       VALIDATORS: [ Validators.required, Validators.email ],
17       MESSAGES: {
18         'required': this.i18n('Email is required.'),
19         'email': this.i18n('Email must be valid.')
20       }
21     }
22
23     this.FROM_NAME = {
24       VALIDATORS: [
25         Validators.required,
26         Validators.minLength(1),
27         Validators.maxLength(120)
28       ],
29       MESSAGES: {
30         'required': this.i18n('Your name is required.'),
31         'minlength': this.i18n('Your name must be at least 1 character long.'),
32         'maxlength': this.i18n('Your name cannot be more than 120 characters long.')
33       }
34     }
35
36     this.SUBJECT = {
37       VALIDATORS: [
38         Validators.required,
39         Validators.minLength(1),
40         Validators.maxLength(120)
41       ],
42       MESSAGES: {
43         'required': this.i18n('A subject is required.'),
44         'minlength': this.i18n('The subject must be at least 1 character long.'),
45         'maxlength': this.i18n('The subject cannot be more than 120 characters long.')
46       }
47     }
48
49     this.BODY = {
50       VALIDATORS: [
51         Validators.required,
52         Validators.minLength(3),
53         Validators.maxLength(5000)
54       ],
55       MESSAGES: {
56         'required': this.i18n('A message is required.'),
57         'minlength': this.i18n('The message must be at least 3 characters long.'),
58         'maxlength': this.i18n('The message cannot be more than 5000 characters long.')
59       }
60     }
61   }
62 }