]>
Commit | Line | Data |
---|---|---|
df98563e C |
1 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
2 | import { FormBuilder, FormGroup } from '@angular/forms' | |
df98563e | 3 | import { NotificationsService } from 'angular2-notifications' |
202f6b6c C |
4 | import { ModalDirective } from 'ngx-bootstrap/modal' |
5 | import { FormReactive, VIDEO_ABUSE_REASON, VideoAbuseService } from '../../shared' | |
6 | import { VideoDetails } from '../../shared/video/video-details.model' | |
4f8c0eb0 C |
7 | |
8 | @Component({ | |
9 | selector: 'my-video-report', | |
10 | templateUrl: './video-report.component.html' | |
11 | }) | |
12 | export class VideoReportComponent extends FormReactive implements OnInit { | |
404b54e1 | 13 | @Input() video: VideoDetails = null |
4f8c0eb0 | 14 | |
df98563e | 15 | @ViewChild('modal') modal: ModalDirective |
4f8c0eb0 | 16 | |
df98563e C |
17 | error: string = null |
18 | form: FormGroup | |
4f8c0eb0 C |
19 | formErrors = { |
20 | reason: '' | |
df98563e | 21 | } |
4f8c0eb0 | 22 | validationMessages = { |
11ac88de | 23 | reason: VIDEO_ABUSE_REASON.MESSAGES |
df98563e | 24 | } |
4f8c0eb0 | 25 | |
df98563e | 26 | constructor ( |
4f8c0eb0 | 27 | private formBuilder: FormBuilder, |
7ddd02c9 C |
28 | private videoAbuseService: VideoAbuseService, |
29 | private notificationsService: NotificationsService | |
4f8c0eb0 | 30 | ) { |
df98563e | 31 | super() |
4f8c0eb0 C |
32 | } |
33 | ||
df98563e C |
34 | ngOnInit () { |
35 | this.buildForm() | |
4f8c0eb0 C |
36 | } |
37 | ||
df98563e | 38 | buildForm () { |
4f8c0eb0 | 39 | this.form = this.formBuilder.group({ |
11ac88de | 40 | reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ] |
df98563e | 41 | }) |
4f8c0eb0 | 42 | |
df98563e | 43 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) |
4f8c0eb0 C |
44 | } |
45 | ||
df98563e C |
46 | show () { |
47 | this.modal.show() | |
4f8c0eb0 C |
48 | } |
49 | ||
df98563e C |
50 | hide () { |
51 | this.modal.hide() | |
4f8c0eb0 C |
52 | } |
53 | ||
df98563e C |
54 | report () { |
55 | const reason = this.form.value['reason'] | |
4f8c0eb0 | 56 | |
11ac88de | 57 | this.videoAbuseService.reportVideo(this.video.id, reason) |
5769e1db C |
58 | .subscribe( |
59 | () => { | |
df98563e C |
60 | this.notificationsService.success('Success', 'Video reported.') |
61 | this.hide() | |
5769e1db | 62 | }, |
4f8c0eb0 | 63 | |
bfb3a98f | 64 | err => this.notificationsService.error('Error', err.message) |
df98563e | 65 | ) |
4f8c0eb0 C |
66 | } |
67 | } |