1 import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { FormReactive, UserService } from '../../../shared/index'
5 import { Video } from '@app/shared/video/video.model'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { FormValidatorService, VideoChangeOwnershipValidatorsService } from '@app/shared'
8 import { VideoOwnershipService } from '@app/shared/video-ownership'
11 selector: 'my-video-change-ownership',
12 templateUrl: './video-change-ownership.component.html',
13 styleUrls: [ './video-change-ownership.component.scss' ]
15 export class VideoChangeOwnershipComponent extends FormReactive implements OnInit {
16 @ViewChild('modal', { static: true }) modal: ElementRef
18 usernamePropositions: string[]
22 private video: Video | undefined = undefined
25 protected formValidatorService: FormValidatorService,
26 private videoChangeOwnershipValidatorsService: VideoChangeOwnershipValidatorsService,
27 private videoOwnershipService: VideoOwnershipService,
28 private notifier: Notifier,
29 private userService: UserService,
30 private modalService: NgbModal,
38 username: this.videoChangeOwnershipValidatorsService.USERNAME
40 this.usernamePropositions = []
48 .then(() => this.changeOwnership())
49 .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing
52 search (event: { query: string }) {
53 const query = event.query
54 this.userService.autocomplete(query)
56 usernames => this.usernamePropositions = usernames,
58 err => this.notifier.error(err.message)
63 const username = this.form.value['username']
65 this.videoOwnershipService
66 .changeOwnership(this.video.id, username)
68 () => this.notifier.success(this.i18n('Ownership change request sent.')),
70 err => this.notifier.error(err.message)