diff options
Diffstat (limited to 'client/src/app/videos/video-watch/video-report.component.ts')
-rw-r--r-- | client/src/app/videos/video-watch/video-report.component.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/client/src/app/videos/video-watch/video-report.component.ts b/client/src/app/videos/video-watch/video-report.component.ts new file mode 100644 index 000000000..7bc1677ab --- /dev/null +++ b/client/src/app/videos/video-watch/video-report.component.ts | |||
@@ -0,0 +1,68 @@ | |||
1 | import { Component, Input, OnInit, ViewChild } from '@angular/core'; | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms'; | ||
3 | |||
4 | import { ModalDirective } from 'ng2-bootstrap/modal'; | ||
5 | |||
6 | import { FormReactive, VIDEO_REPORT_REASON } from '../../shared'; | ||
7 | import { Video, VideoService } from '../shared'; | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-video-report', | ||
11 | templateUrl: './video-report.component.html' | ||
12 | }) | ||
13 | export class VideoReportComponent extends FormReactive implements OnInit { | ||
14 | @Input() video: Video = 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_REPORT_REASON.MESSAGES | ||
25 | }; | ||
26 | |||
27 | constructor( | ||
28 | private formBuilder: FormBuilder, | ||
29 | private videoService: VideoService | ||
30 | ) { | ||
31 | super(); | ||
32 | } | ||
33 | |||
34 | ngOnInit() { | ||
35 | this.buildForm(); | ||
36 | } | ||
37 | |||
38 | buildForm() { | ||
39 | this.form = this.formBuilder.group({ | ||
40 | reason: [ '', VIDEO_REPORT_REASON.VALIDATORS ] | ||
41 | }); | ||
42 | |||
43 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | ||
44 | } | ||
45 | |||
46 | show() { | ||
47 | this.modal.show(); | ||
48 | } | ||
49 | |||
50 | hide() { | ||
51 | this.modal.hide(); | ||
52 | } | ||
53 | |||
54 | report() { | ||
55 | const reason = this.form.value['reason'] | ||
56 | |||
57 | this.videoService.reportVideo(this.video.id, reason) | ||
58 | .subscribe( | ||
59 | // TODO: move alert to beautiful notifications | ||
60 | ok => { | ||
61 | alert('Video reported.'); | ||
62 | this.hide(); | ||
63 | }, | ||
64 | |||
65 | err => alert(err.text) | ||
66 | ) | ||
67 | } | ||
68 | } | ||