]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/modal/video-report.component.ts
Add i18n attributes
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-report.component.ts
1 import { Component, Input, OnInit, ViewChild } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { NotificationsService } from 'angular2-notifications'
4 import { ModalDirective } from 'ngx-bootstrap/modal'
5 import { FormReactive, VIDEO_ABUSE_REASON, VideoAbuseService } from '../../../shared/index'
6 import { VideoDetails } from '../../../shared/video/video-details.model'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8
9 @Component({
10 selector: 'my-video-report',
11 templateUrl: './video-report.component.html',
12 styleUrls: [ './video-report.component.scss' ]
13 })
14 export class VideoReportComponent extends FormReactive implements OnInit {
15 @Input() video: VideoDetails = null
16
17 @ViewChild('modal') modal: ModalDirective
18
19 error: string = null
20 form: FormGroup
21 formErrors = {
22 reason: ''
23 }
24 validationMessages = {
25 reason: VIDEO_ABUSE_REASON.MESSAGES
26 }
27
28 constructor (
29 private formBuilder: FormBuilder,
30 private videoAbuseService: VideoAbuseService,
31 private notificationsService: NotificationsService,
32 private i18n: I18n
33 ) {
34 super()
35 }
36
37 ngOnInit () {
38 this.buildForm()
39 }
40
41 buildForm () {
42 this.form = this.formBuilder.group({
43 reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ]
44 })
45
46 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
47 }
48
49 show () {
50 this.modal.show()
51 }
52
53 hide () {
54 this.modal.hide()
55 }
56
57 report () {
58 const reason = this.form.value['reason']
59
60 this.videoAbuseService.reportVideo(this.video.id, reason)
61 .subscribe(
62 () => {
63 this.notificationsService.success(this.i18n('Success'), this.i18n('Video reported.'))
64 this.hide()
65 },
66
67 err => this.notificationsService.error(this.i18n('Error'), err.message)
68 )
69 }
70 }