1 import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2 import { Notifier, UserService } from '@app/core'
3 import { FormReactive, FormValidatorService, VideoChangeOwnershipValidatorsService } from '@app/shared/shared-forms'
4 import { Video, VideoOwnershipService } from '@app/shared/shared-main'
5 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
8 selector: 'my-video-change-ownership',
9 templateUrl: './video-change-ownership.component.html',
10 styleUrls: [ './video-change-ownership.component.scss' ]
12 export class VideoChangeOwnershipComponent extends FormReactive implements OnInit {
13 @ViewChild('modal', { static: true }) modal: ElementRef
15 usernamePropositions: string[]
19 private video: Video | undefined = undefined
22 protected formValidatorService: FormValidatorService,
23 private videoChangeOwnershipValidatorsService: VideoChangeOwnershipValidatorsService,
24 private videoOwnershipService: VideoOwnershipService,
25 private notifier: Notifier,
26 private userService: UserService,
27 private modalService: NgbModal
34 username: this.videoChangeOwnershipValidatorsService.USERNAME
36 this.usernamePropositions = []
42 .open(this.modal, { centered: true })
44 .then(() => this.changeOwnership())
45 .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing
48 search (event: { query: string }) {
49 const query = event.query
50 this.userService.autocomplete(query)
52 usernames => this.usernamePropositions = usernames,
54 err => this.notifier.error(err.message)
59 const username = this.form.value['username']
61 this.videoOwnershipService
62 .changeOwnership(this.video.id, username)
64 () => this.notifier.success($localize`Ownership change request sent.`),
66 err => this.notifier.error(err.message)