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