]>
Commit | Line | Data |
---|---|---|
74d63469 | 1 | import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { AuthService, Notifier } from '@app/core' |
67ed6552 C |
3 | import { FormReactive, FormValidatorService, VideoAcceptOwnershipValidatorsService } from '@app/shared/shared-forms' |
4 | import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main' | |
74d63469 | 5 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
67ed6552 C |
6 | import { I18n } from '@ngx-translate/i18n-polyfill' |
7 | import { VideoChangeOwnership, VideoChannel } from '@shared/models' | |
74d63469 GR |
8 | |
9 | @Component({ | |
10 | selector: 'my-account-accept-ownership', | |
11 | templateUrl: './my-account-accept-ownership.component.html', | |
12 | styleUrls: [ './my-account-accept-ownership.component.scss' ] | |
13 | }) | |
14 | export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit { | |
15 | @Output() accepted = new EventEmitter<void>() | |
16 | ||
f36da21e | 17 | @ViewChild('modal', { static: true }) modal: ElementRef |
74d63469 GR |
18 | |
19 | videoChangeOwnership: VideoChangeOwnership | undefined = undefined | |
20 | ||
21 | videoChannels: VideoChannel[] | |
22 | ||
23 | error: string = null | |
24 | ||
25 | constructor ( | |
26 | protected formValidatorService: FormValidatorService, | |
27 | private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService, | |
28 | private videoOwnershipService: VideoOwnershipService, | |
f8b2c1b4 | 29 | private notifier: Notifier, |
74d63469 GR |
30 | private authService: AuthService, |
31 | private videoChannelService: VideoChannelService, | |
32 | private modalService: NgbModal, | |
33 | private i18n: I18n | |
34 | ) { | |
35 | super() | |
36 | } | |
37 | ||
38 | ngOnInit () { | |
39 | this.videoChannels = [] | |
40 | ||
41 | this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account) | |
42 | .subscribe(videoChannels => this.videoChannels = videoChannels.data) | |
43 | ||
44 | this.buildForm({ | |
45 | channel: this.videoChangeOwnershipValidatorsService.CHANNEL | |
46 | }) | |
47 | } | |
48 | ||
49 | show (videoChangeOwnership: VideoChangeOwnership) { | |
50 | this.videoChangeOwnership = videoChangeOwnership | |
51 | this.modalService | |
24e7916c | 52 | .open(this.modal, { centered: true }) |
74d63469 GR |
53 | .result |
54 | .then(() => this.acceptOwnership()) | |
55 | .catch(() => this.videoChangeOwnership = undefined) | |
56 | } | |
57 | ||
58 | acceptOwnership () { | |
59 | const channel = this.form.value['channel'] | |
60 | ||
61 | const videoChangeOwnership = this.videoChangeOwnership | |
62 | this.videoOwnershipService | |
63 | .acceptOwnership(videoChangeOwnership.id, { channelId: channel }) | |
64 | .subscribe( | |
65 | () => { | |
f8b2c1b4 | 66 | this.notifier.success(this.i18n('Ownership accepted')) |
74d63469 GR |
67 | if (this.accepted) this.accepted.emit() |
68 | this.videoChangeOwnership = undefined | |
69 | }, | |
70 | ||
f8b2c1b4 | 71 | err => this.notifier.error(err.message) |
74d63469 GR |
72 | ) |
73 | } | |
74 | } |