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