aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/video-watch/video-report.component.ts
blob: 7bc1677abceab356c16809fe9c32db6d32fe19d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';

import { ModalDirective } from 'ng2-bootstrap/modal';

import { FormReactive, VIDEO_REPORT_REASON } from '../../shared';
import { Video, VideoService } from '../shared';

@Component({
  selector: 'my-video-report',
  templateUrl: './video-report.component.html'
})
export class VideoReportComponent extends FormReactive implements OnInit {
  @Input() video: Video = null;

  @ViewChild('modal') modal: ModalDirective;

  error: string = null;
  form: FormGroup;
  formErrors = {
    reason: ''
  };
  validationMessages = {
    reason: VIDEO_REPORT_REASON.MESSAGES
  };

  constructor(
    private formBuilder: FormBuilder,
    private videoService: VideoService
   ) {
    super();
  }

  ngOnInit() {
    this.buildForm();
  }

  buildForm() {
    this.form = this.formBuilder.group({
      reason: [ '', VIDEO_REPORT_REASON.VALIDATORS ]
    });

    this.form.valueChanges.subscribe(data => this.onValueChanged(data));
  }

  show() {
    this.modal.show();
  }

  hide() {
    this.modal.hide();
  }

  report() {
    const reason = this.form.value['reason']

    this.videoService.reportVideo(this.video.id, reason)
                     .subscribe(
                       // TODO: move alert to beautiful notifications
                       ok => {
                         alert('Video reported.');
                         this.hide();
                       },

                       err => alert(err.text)
                      )
  }
}