diff options
Diffstat (limited to 'client/src/app/shared/shared-forms/form-validators/video-change-ownership-validators.service.ts')
-rw-r--r-- | client/src/app/shared/shared-forms/form-validators/video-change-ownership-validators.service.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-forms/form-validators/video-change-ownership-validators.service.ts b/client/src/app/shared/shared-forms/form-validators/video-change-ownership-validators.service.ts new file mode 100644 index 000000000..59659defd --- /dev/null +++ b/client/src/app/shared/shared-forms/form-validators/video-change-ownership-validators.service.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
2 | import { AbstractControl, ValidationErrors, Validators } from '@angular/forms' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { BuildFormValidator } from './form-validator.service' | ||
5 | |||
6 | @Injectable() | ||
7 | export class VideoChangeOwnershipValidatorsService { | ||
8 | readonly USERNAME: BuildFormValidator | ||
9 | |||
10 | constructor (private i18n: I18n) { | ||
11 | this.USERNAME = { | ||
12 | VALIDATORS: [ Validators.required, this.localAccountValidator ], | ||
13 | MESSAGES: { | ||
14 | 'required': this.i18n('The username is required.'), | ||
15 | 'localAccountOnly': this.i18n('You can only transfer ownership to a local account') | ||
16 | } | ||
17 | } | ||
18 | } | ||
19 | |||
20 | localAccountValidator (control: AbstractControl): ValidationErrors { | ||
21 | if (control.value.includes('@')) { | ||
22 | return { 'localAccountOnly': true } | ||
23 | } | ||
24 | |||
25 | return null | ||
26 | } | ||
27 | } | ||