1 import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { AuthService, Notifier } from '@app/core'
3 import { FormReactive, FormValidatorService, VideoAcceptOwnershipValidatorsService } from '@app/shared/shared-forms'
4 import { VideoChannelService, VideoOwnershipService } from '@app/shared/shared-main'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
6 import { VideoChangeOwnership, VideoChannel } from '@shared/models'
9 selector: 'my-account-accept-ownership',
10 templateUrl: './my-account-accept-ownership.component.html',
11 styleUrls: [ './my-account-accept-ownership.component.scss' ]
13 export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit {
14 @Output() accepted = new EventEmitter<void>()
16 @ViewChild('modal', { static: true }) modal: ElementRef
18 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
20 videoChannels: VideoChannel[]
25 protected formValidatorService: FormValidatorService,
26 private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService,
27 private videoOwnershipService: VideoOwnershipService,
28 private notifier: Notifier,
29 private authService: AuthService,
30 private videoChannelService: VideoChannelService,
31 private modalService: NgbModal
37 this.videoChannels = []
39 this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)
40 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
43 channel: this.videoChangeOwnershipValidatorsService.CHANNEL
47 show (videoChangeOwnership: VideoChangeOwnership) {
48 this.videoChangeOwnership = videoChangeOwnership
50 .open(this.modal, { centered: true })
52 .then(() => this.acceptOwnership())
53 .catch(() => this.videoChangeOwnership = undefined)
57 const channel = this.form.value['channel']
59 const videoChangeOwnership = this.videoChangeOwnership
60 this.videoOwnershipService
61 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
64 this.notifier.success($localize`Ownership accepted`)
65 if (this.accepted) this.accepted.emit()
66 this.videoChangeOwnership = undefined
69 err => this.notifier.error(err.message)