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