]>
Commit | Line | Data |
---|---|---|
4f8c0eb0 C |
1 | import { Component, Input, OnInit, ViewChild } from '@angular/core'; |
2 | import { FormBuilder, FormGroup } from '@angular/forms'; | |
3 | ||
ad42bea3 | 4 | import { ModalDirective } from 'ngx-bootstrap/modal'; |
7ddd02c9 | 5 | import { NotificationsService } from 'angular2-notifications'; |
4f8c0eb0 | 6 | |
11ac88de | 7 | import { FormReactive, VideoAbuseService, VIDEO_ABUSE_REASON } from '../../shared'; |
4f8c0eb0 C |
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 = { | |
11ac88de | 25 | reason: VIDEO_ABUSE_REASON.MESSAGES |
4f8c0eb0 C |
26 | }; |
27 | ||
28 | constructor( | |
29 | private formBuilder: FormBuilder, | |
7ddd02c9 C |
30 | private videoAbuseService: VideoAbuseService, |
31 | private notificationsService: NotificationsService | |
4f8c0eb0 C |
32 | ) { |
33 | super(); | |
34 | } | |
35 | ||
36 | ngOnInit() { | |
37 | this.buildForm(); | |
38 | } | |
39 | ||
40 | buildForm() { | |
41 | this.form = this.formBuilder.group({ | |
11ac88de | 42 | reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ] |
4f8c0eb0 C |
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() { | |
7af75da4 | 57 | const reason = this.form.value['reason']; |
4f8c0eb0 | 58 | |
11ac88de | 59 | this.videoAbuseService.reportVideo(this.video.id, reason) |
5769e1db C |
60 | .subscribe( |
61 | () => { | |
62 | this.notificationsService.success('Success', 'Video reported.'); | |
63 | this.hide(); | |
64 | }, | |
4f8c0eb0 | 65 | |
5769e1db C |
66 | err => this.notificationsService.error('Error', err.text) |
67 | ); | |
4f8c0eb0 C |
68 | } |
69 | } |