diff options
Diffstat (limited to 'client/src/app/videos/+video-watch/modal/video-report.component.ts')
-rw-r--r-- | client/src/app/videos/+video-watch/modal/video-report.component.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/client/src/app/videos/+video-watch/modal/video-report.component.ts b/client/src/app/videos/+video-watch/modal/video-report.component.ts new file mode 100644 index 000000000..050e827e7 --- /dev/null +++ b/client/src/app/videos/+video-watch/modal/video-report.component.ts | |||
@@ -0,0 +1,68 @@ | |||
1 | import { Component, Input, OnInit, ViewChild } from '@angular/core' | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
3 | import { NotificationsService } from 'angular2-notifications' | ||
4 | import { ModalDirective } from 'ngx-bootstrap/modal' | ||
5 | import { FormReactive, VIDEO_ABUSE_REASON, VideoAbuseService } from '../../../shared/index' | ||
6 | import { VideoDetails } from '../../../shared/video/video-details.model' | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-video-report', | ||
10 | templateUrl: './video-report.component.html', | ||
11 | styleUrls: [ './video-report.component.scss' ] | ||
12 | }) | ||
13 | export class VideoReportComponent extends FormReactive implements OnInit { | ||
14 | @Input() video: VideoDetails = 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 | private notificationsService: NotificationsService | ||
31 | ) { | ||
32 | super() | ||
33 | } | ||
34 | |||
35 | ngOnInit () { | ||
36 | this.buildForm() | ||
37 | } | ||
38 | |||
39 | buildForm () { | ||
40 | this.form = this.formBuilder.group({ | ||
41 | reason: [ '', VIDEO_ABUSE_REASON.VALIDATORS ] | ||
42 | }) | ||
43 | |||
44 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
45 | } | ||
46 | |||
47 | show () { | ||
48 | this.modal.show() | ||
49 | } | ||
50 | |||
51 | hide () { | ||
52 | this.modal.hide() | ||
53 | } | ||
54 | |||
55 | report () { | ||
56 | const reason = this.form.value['reason'] | ||
57 | |||
58 | this.videoAbuseService.reportVideo(this.video.id, reason) | ||
59 | .subscribe( | ||
60 | () => { | ||
61 | this.notificationsService.success('Success', 'Video reported.') | ||
62 | this.hide() | ||
63 | }, | ||
64 | |||
65 | err => this.notificationsService.error('Error', err.message) | ||
66 | ) | ||
67 | } | ||
68 | } | ||