]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.ts
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-videos / video-change-ownership / video-change-ownership.component.ts
CommitLineData
74d63469 1import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
67ed6552
C
2import { Notifier, UserService } from '@app/core'
3import { FormReactive, FormValidatorService, VideoChangeOwnershipValidatorsService } from '@app/shared/shared-forms'
4import { Video, VideoOwnershipService } from '@app/shared/shared-main'
74d63469 5import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
74d63469
GR
6
7@Component({
8 selector: 'my-video-change-ownership',
9 templateUrl: './video-change-ownership.component.html',
10 styleUrls: [ './video-change-ownership.component.scss' ]
11})
12export class VideoChangeOwnershipComponent extends FormReactive implements OnInit {
f36da21e 13 @ViewChild('modal', { static: true }) modal: ElementRef
74d63469
GR
14
15 usernamePropositions: string[]
16
17 error: string = null
18
19 private video: Video | undefined = undefined
20
21 constructor (
22 protected formValidatorService: FormValidatorService,
23 private videoChangeOwnershipValidatorsService: VideoChangeOwnershipValidatorsService,
24 private videoOwnershipService: VideoOwnershipService,
f8b2c1b4 25 private notifier: Notifier,
74d63469 26 private userService: UserService,
66357162
C
27 private modalService: NgbModal
28 ) {
74d63469
GR
29 super()
30 }
31
32 ngOnInit () {
33 this.buildForm({
34 username: this.videoChangeOwnershipValidatorsService.USERNAME
35 })
36 this.usernamePropositions = []
37 }
38
39 show (video: Video) {
40 this.video = video
41 this.modalService
24e7916c 42 .open(this.modal, { centered: true })
74d63469
GR
43 .result
44 .then(() => this.changeOwnership())
45 .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing
46 }
47
c199c427 48 search (event: { query: string }) {
74d63469
GR
49 const query = event.query
50 this.userService.autocomplete(query)
51 .subscribe(
f8b2c1b4 52 usernames => this.usernamePropositions = usernames,
74d63469 53
f8b2c1b4 54 err => this.notifier.error(err.message)
74d63469
GR
55 )
56 }
57
58 changeOwnership () {
59 const username = this.form.value['username']
60
61 this.videoOwnershipService
62 .changeOwnership(this.video.id, username)
63 .subscribe(
66357162 64 () => this.notifier.success($localize`Ownership change request sent.`),
74d63469 65
f8b2c1b4 66 err => this.notifier.error(err.message)
74d63469
GR
67 )
68 }
69}