1 import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2 import { Notifier, UserService } from '@app/core'
3 import { OWNERSHIP_CHANGE_USERNAME_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
4 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5 import { Video, VideoOwnershipService } from '@app/shared/shared-main'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
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 videoOwnershipService: VideoOwnershipService,
25 private notifier: Notifier,
26 private userService: UserService,
27 private modalService: NgbModal
34 username: OWNERSHIP_CHANGE_USERNAME_VALIDATOR
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)
53 this.usernamePropositions = usernames
56 error: err => this.notifier.error(err.message)
61 const username = this.form.value['username']
63 this.videoOwnershipService
64 .changeOwnership(this.video.id, username)
66 next: () => this.notifier.success($localize`Ownership change request sent.`),
68 error: err => this.notifier.error(err.message)