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'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
9 selector: 'my-video-change-ownership',
10 templateUrl: './video-change-ownership.component.html',
11 styleUrls: [ './video-change-ownership.component.scss' ]
13 export class VideoChangeOwnershipComponent extends FormReactive implements OnInit {
14 @ViewChild('modal', { static: true }) modal: ElementRef
16 usernamePropositions: string[]
20 private video: Video | undefined = undefined
23 protected formValidatorService: FormValidatorService,
24 private videoChangeOwnershipValidatorsService: VideoChangeOwnershipValidatorsService,
25 private videoOwnershipService: VideoOwnershipService,
26 private notifier: Notifier,
27 private userService: UserService,
28 private modalService: NgbModal,
36 username: this.videoChangeOwnershipValidatorsService.USERNAME
38 this.usernamePropositions = []
44 .open(this.modal, { centered: true })
46 .then(() => this.changeOwnership())
47 .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing
50 search (event: { query: string }) {
51 const query = event.query
52 this.userService.autocomplete(query)
54 usernames => this.usernamePropositions = usernames,
56 err => this.notifier.error(err.message)
61 const username = this.form.value['username']
63 this.videoOwnershipService
64 .changeOwnership(this.video.id, username)
66 () => this.notifier.success(this.i18n('Ownership change request sent.')),
68 err => this.notifier.error(err.message)