]>
Commit | Line | Data |
---|---|---|
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, VideoAbuseService, VIDEO_ABUSE_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_ABUSE_REASON.MESSAGES | |
25 | }; | |
26 | ||
27 | constructor( | |
28 | private formBuilder: FormBuilder, | |
29 | private videoAbuseService: VideoAbuseService | |
30 | ) { | |
31 | super(); | |
32 | } | |
33 | ||
34 | ngOnInit() { | |
35 | this.buildForm(); | |
36 | } | |
37 | ||
38 | buildForm() { | |
39 | this.form = this.formBuilder.group({ | |
40 | reason: [ '', VIDEO_ABUSE_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.videoAbuseService.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 | } |