From e309822b93d9b69f30cbe830ef3d09dfdb2c13b2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Jun 2018 15:01:45 +0200 Subject: Add form validator translations --- .../+video-edit/shared/video-edit.component.ts | 43 +++++++++------------- .../comment/video-comment-add.component.ts | 5 ++- .../+video-watch/modal/video-report.component.ts | 8 ++-- 3 files changed, 25 insertions(+), 31 deletions(-) (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/+video-edit/shared/video-edit.component.ts b/client/src/app/videos/+video-edit/shared/video-edit.component.ts index cd2a26ae3..61515c0b0 100644 --- a/client/src/app/videos/+video-edit/shared/video-edit.component.ts +++ b/client/src/app/videos/+video-edit/shared/video-edit.component.ts @@ -1,20 +1,9 @@ import { Component, Input, OnInit } from '@angular/core' -import { FormGroup } from '@angular/forms' +import { FormGroup, ValidatorFn } from '@angular/forms' import { ActivatedRoute, Router } from '@angular/router' -import { VIDEO_SUPPORT } from '@app/shared' +import { FormReactiveValidationMessages, VideoValidatorsService } from '@app/shared' import { NotificationsService } from 'angular2-notifications' import { ServerService } from '../../../core/server' -import { VIDEO_CHANNEL } from '../../../shared/forms/form-validators' -import { ValidatorMessage } from '../../../shared/forms/form-validators/validator-message' -import { - VIDEO_CATEGORY, - VIDEO_DESCRIPTION, - VIDEO_LANGUAGE, - VIDEO_LICENCE, - VIDEO_NAME, - VIDEO_PRIVACY, - VIDEO_TAGS -} from '../../../shared/forms/form-validators/video' import { VideoEdit } from '../../../shared/video/video-edit.model' import { map } from 'rxjs/operators' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' @@ -28,7 +17,7 @@ import { FormValidatorService } from '@app/shared/forms/form-validators/form-val export class VideoEditComponent implements OnInit { @Input() form: FormGroup @Input() formErrors: { [ id: string ]: string } = {} - @Input() validationMessages: ValidatorMessage = {} + @Input() validationMessages: FormReactiveValidationMessages = {} @Input() videoPrivacies = [] @Input() userVideoChannels: { id: number, label: string, support: string }[] = [] @@ -37,18 +26,22 @@ export class VideoEditComponent implements OnInit { videoLanguages = [] video: VideoEdit - tagValidators = VIDEO_TAGS.VALIDATORS - tagValidatorsMessages = VIDEO_TAGS.MESSAGES + tagValidators: ValidatorFn[] + tagValidatorsMessages: { [ name: string ]: string } error: string = null constructor ( private formValidatorService: FormValidatorService, + private videoValidatorsService: VideoValidatorsService, private route: ActivatedRoute, private router: Router, private notificationsService: NotificationsService, private serverService: ServerService - ) { } + ) { + this.tagValidators = this.videoValidatorsService.VIDEO_TAGS.VALIDATORS + this.tagValidatorsMessages = this.videoValidatorsService.VIDEO_TAGS.MESSAGES + } updateForm () { const defaultValues = { @@ -57,19 +50,19 @@ export class VideoEditComponent implements OnInit { tags: [] } const obj = { - name: VIDEO_NAME, - privacy: VIDEO_PRIVACY, - channelId: VIDEO_CHANNEL, + name: this.videoValidatorsService.VIDEO_NAME, + privacy: this.videoValidatorsService.VIDEO_PRIVACY, + channelId: this.videoValidatorsService.VIDEO_CHANNEL, nsfw: null, commentsEnabled: null, - category: VIDEO_CATEGORY, - licence: VIDEO_LICENCE, - language: VIDEO_LANGUAGE, - description: VIDEO_DESCRIPTION, + category: this.videoValidatorsService.VIDEO_CATEGORY, + licence: this.videoValidatorsService.VIDEO_LICENCE, + language: this.videoValidatorsService.VIDEO_LANGUAGE, + description: this.videoValidatorsService.VIDEO_DESCRIPTION, tags: null, thumbnailfile: null, previewfile: null, - support: VIDEO_SUPPORT + support: this.videoValidatorsService.VIDEO_SUPPORT } this.formValidatorService.updateForm( diff --git a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts index c70e544a3..46d7a4e9e 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts @@ -3,13 +3,13 @@ import { NotificationsService } from 'angular2-notifications' import { Observable } from 'rxjs' import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model' import { FormReactive } from '../../../shared' -import { VIDEO_COMMENT_TEXT } from '../../../shared/forms/form-validators/video-comment' import { User } from '../../../shared/users' import { Video } from '../../../shared/video/video.model' import { VideoComment } from './video-comment.model' import { VideoCommentService } from './video-comment.service' import { I18n } from '@ngx-translate/i18n-polyfill' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' +import { VideoCommentValidatorsService } from '@app/shared/forms/form-validators/video-comment-validators.service' @Component({ selector: 'my-video-comment-add', @@ -29,6 +29,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { constructor ( protected formValidatorService: FormValidatorService, + private videoCommentValidatorsService: VideoCommentValidatorsService, private notificationsService: NotificationsService, private videoCommentService: VideoCommentService, private i18n: I18n @@ -38,7 +39,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { ngOnInit () { this.buildForm({ - text: VIDEO_COMMENT_TEXT + text: this.videoCommentValidatorsService.VIDEO_COMMENT_TEXT }) if (this.focusOnInit === true) { diff --git a/client/src/app/videos/+video-watch/modal/video-report.component.ts b/client/src/app/videos/+video-watch/modal/video-report.component.ts index 8641e8dfb..d9768fdac 100644 --- a/client/src/app/videos/+video-watch/modal/video-report.component.ts +++ b/client/src/app/videos/+video-watch/modal/video-report.component.ts @@ -1,12 +1,11 @@ import { Component, Input, OnInit, ViewChild } from '@angular/core' -import { FormBuilder, FormGroup } from '@angular/forms' import { NotificationsService } from 'angular2-notifications' import { ModalDirective } from 'ngx-bootstrap/modal' -import { FormReactive, VIDEO_ABUSE_REASON, VideoAbuseService } from '../../../shared/index' +import { FormReactive, VideoAbuseService } from '../../../shared/index' import { VideoDetails } from '../../../shared/video/video-details.model' import { I18n } from '@ngx-translate/i18n-polyfill' -import { FormReactiveErrors, FormReactiveValidationMessages } from '@app/shared' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' +import { VideoAbuseValidatorsService } from '@app/shared/forms/form-validators/video-abuse-validators.service' @Component({ selector: 'my-video-report', @@ -22,6 +21,7 @@ export class VideoReportComponent extends FormReactive implements OnInit { constructor ( protected formValidatorService: FormValidatorService, + private videoAbuseValidatorsService: VideoAbuseValidatorsService, private videoAbuseService: VideoAbuseService, private notificationsService: NotificationsService, private i18n: I18n @@ -31,7 +31,7 @@ export class VideoReportComponent extends FormReactive implements OnInit { ngOnInit () { this.buildForm({ - reason: VIDEO_ABUSE_REASON + reason: this.videoAbuseValidatorsService.VIDEO_ABUSE_REASON }) } -- cgit v1.2.3