]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/video-watch/video-report.component.ts
err.text -> err
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-watch / video-report.component.ts
CommitLineData
df98563e
C
1import { Component, Input, OnInit, ViewChild } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
4f8c0eb0 3
df98563e
C
4import { ModalDirective } from 'ngx-bootstrap/modal'
5import { NotificationsService } from 'angular2-notifications'
4f8c0eb0 6
df98563e
C
7import { FormReactive, VideoAbuseService, VIDEO_ABUSE_REASON } from '../../shared'
8import { Video, VideoService } from '../shared'
4f8c0eb0
C
9
10@Component({
11 selector: 'my-video-report',
12 templateUrl: './video-report.component.html'
13})
14export class VideoReportComponent extends FormReactive implements OnInit {
df98563e 15 @Input() video: Video = 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
C
30 private videoAbuseService: VideoAbuseService,
31 private notificationsService: NotificationsService
4f8c0eb0 32 ) {
df98563e 33 super()
4f8c0eb0
C
34 }
35
df98563e
C
36 ngOnInit () {
37 this.buildForm()
4f8c0eb0
C
38 }
39
df98563e 40 buildForm () {
4f8c0eb0 41 this.form = this.formBuilder.group({
11ac88de 42 reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ]
df98563e 43 })
4f8c0eb0 44
df98563e 45 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
4f8c0eb0
C
46 }
47
df98563e
C
48 show () {
49 this.modal.show()
4f8c0eb0
C
50 }
51
df98563e
C
52 hide () {
53 this.modal.hide()
4f8c0eb0
C
54 }
55
df98563e
C
56 report () {
57 const reason = this.form.value['reason']
4f8c0eb0 58
11ac88de 59 this.videoAbuseService.reportVideo(this.video.id, reason)
5769e1db
C
60 .subscribe(
61 () => {
df98563e
C
62 this.notificationsService.success('Success', 'Video reported.')
63 this.hide()
5769e1db 64 },
4f8c0eb0 65
03b40f24 66 err => this.notificationsService.error('Error', err)
df98563e 67 )
4f8c0eb0
C
68 }
69}