1 import { Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
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'
11 import { AuthService } from '@app/core'
12 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
15 selector: 'my-account-accept-ownership',
16 templateUrl: './my-account-accept-ownership.component.html',
17 styleUrls: [ './my-account-accept-ownership.component.scss' ]
19 export class MyAccountAcceptOwnershipComponent extends FormReactive implements OnInit {
20 @Output() accepted = new EventEmitter<void>()
22 @ViewChild('modal') modal: ElementRef
24 videoChangeOwnership: VideoChangeOwnership | undefined = undefined
26 videoChannels: VideoChannel[]
31 protected formValidatorService: FormValidatorService,
32 private videoChangeOwnershipValidatorsService: VideoAcceptOwnershipValidatorsService,
33 private videoOwnershipService: VideoOwnershipService,
34 private notificationsService: NotificationsService,
35 private authService: AuthService,
36 private videoChannelService: VideoChannelService,
37 private modalService: NgbModal,
44 this.videoChannels = []
46 this.videoChannelService.listAccountVideoChannels(this.authService.getUser().account)
47 .subscribe(videoChannels => this.videoChannels = videoChannels.data)
50 channel: this.videoChangeOwnershipValidatorsService.CHANNEL
54 show (videoChangeOwnership: VideoChangeOwnership) {
55 this.videoChangeOwnership = videoChangeOwnership
59 .then(() => this.acceptOwnership())
60 .catch(() => this.videoChangeOwnership = undefined)
64 const channel = this.form.value['channel']
66 const videoChangeOwnership = this.videoChangeOwnership
67 this.videoOwnershipService
68 .acceptOwnership(videoChangeOwnership.id, { channelId: channel })
71 this.notificationsService.success(this.i18n('Success'), this.i18n('Ownership accepted'))
72 if (this.accepted) this.accepted.emit()
73 this.videoChangeOwnership = undefined
76 err => this.notificationsService.error(this.i18n('Error'), err.message)