aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-watch/modal/video-report.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/+video-watch/modal/video-report.component.ts')
-rw-r--r--client/src/app/videos/+video-watch/modal/video-report.component.ts68
1 files changed, 68 insertions, 0 deletions
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
new file mode 100644
index 000000000..050e827e7
--- /dev/null
+++ b/client/src/app/videos/+video-watch/modal/video-report.component.ts
@@ -0,0 +1,68 @@
1import { Component, Input, OnInit, ViewChild } from '@angular/core'
2import { FormBuilder, FormGroup } from '@angular/forms'
3import { NotificationsService } from 'angular2-notifications'
4import { ModalDirective } from 'ngx-bootstrap/modal'
5import { FormReactive, VIDEO_ABUSE_REASON, VideoAbuseService } from '../../../shared/index'
6import { VideoDetails } from '../../../shared/video/video-details.model'
7
8@Component({
9 selector: 'my-video-report',
10 templateUrl: './video-report.component.html',
11 styleUrls: [ './video-report.component.scss' ]
12})
13export class VideoReportComponent extends FormReactive implements OnInit {
14 @Input() video: VideoDetails = null
15
16 @ViewChild('modal') modal: ModalDirective
17
18 error: string = null
19 form: FormGroup
20 formErrors = {
21 reason: ''
22 }
23 validationMessages = {
24 reason: VIDEO_ABUSE_REASON.MESSAGES
25 }
26
27 constructor (
28 private formBuilder: FormBuilder,
29 private videoAbuseService: VideoAbuseService,
30 private notificationsService: NotificationsService
31 ) {
32 super()
33 }
34
35 ngOnInit () {
36 this.buildForm()
37 }
38
39 buildForm () {
40 this.form = this.formBuilder.group({
41 reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ]
42 })
43
44 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
45 }
46
47 show () {
48 this.modal.show()
49 }
50
51 hide () {
52 this.modal.hide()
53 }
54
55 report () {
56 const reason = this.form.value['reason']
57
58 this.videoAbuseService.reportVideo(this.video.id, reason)
59 .subscribe(
60 () => {
61 this.notificationsService.success('Success', 'Video reported.')
62 this.hide()
63 },
64
65 err => this.notificationsService.error('Error', err.message)
66 )
67 }
68}