]>
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 | import { NotificationsService } from 'angular2-notifications'; | |
6 | ||
7 | import { FormReactive, VideoAbuseService, VIDEO_ABUSE_REASON } from '../../shared'; | |
8 | import { Video, VideoService } from '../shared'; | |
9 | ||
10 | @Component({ | |
11 | selector: 'my-video-report', | |
12 | templateUrl: './video-report.component.html' | |
13 | }) | |
14 | export class VideoReportComponent extends FormReactive implements OnInit { | |
15 | @Input() video: Video = null; | |
16 | ||
17 | @ViewChild('modal') modal: ModalDirective; | |
18 | ||
19 | error: string = null; | |
20 | form: FormGroup; | |
21 | formErrors = { | |
22 | reason: '' | |
23 | }; | |
24 | validationMessages = { | |
25 | reason: VIDEO_ABUSE_REASON.MESSAGES | |
26 | }; | |
27 | ||
28 | constructor( | |
29 | private formBuilder: FormBuilder, | |
30 | private videoAbuseService: VideoAbuseService, | |
31 | private notificationsService: NotificationsService | |
32 | ) { | |
33 | super(); | |
34 | } | |
35 | ||
36 | ngOnInit() { | |
37 | this.buildForm(); | |
38 | } | |
39 | ||
40 | buildForm() { | |
41 | this.form = this.formBuilder.group({ | |
42 | reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ] | |
43 | }); | |
44 | ||
45 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | |
46 | } | |
47 | ||
48 | show() { | |
49 | this.modal.show(); | |
50 | } | |
51 | ||
52 | hide() { | |
53 | this.modal.hide(); | |
54 | } | |
55 | ||
56 | report() { | |
57 | const reason = this.form.value['reason']; | |
58 | ||
59 | this.videoAbuseService.reportVideo(this.video.id, reason) | |
60 | .subscribe( | |
61 | () => { | |
62 | this.notificationsService.success('Success', 'Video reported.'); | |
63 | this.hide(); | |
64 | }, | |
65 | ||
66 | err => this.notificationsService.error('Error', err.text) | |
67 | ); | |
68 | } | |
69 | } |