]> 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
Add ListOverflow component to prevent sub-menu overflow
[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'
f8b2c1b4 2import { Notifier } from '@app/core'
74d63469
GR
3import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4import { FormReactive, UserService } from '../../../shared/index'
5import { Video } from '@app/shared/video/video.model'
6import { I18n } from '@ngx-translate/i18n-polyfill'
7import { FormValidatorService, VideoChangeOwnershipValidatorsService } from '@app/shared'
8import { VideoOwnershipService } from '@app/shared/video-ownership'
9
10@Component({
11 selector: 'my-video-change-ownership',
12 templateUrl: './video-change-ownership.component.html',
13 styleUrls: [ './video-change-ownership.component.scss' ]
14})
15export class VideoChangeOwnershipComponent extends FormReactive implements OnInit {
f36da21e 16 @ViewChild('modal', { static: true }) modal: ElementRef
74d63469
GR
17
18 usernamePropositions: string[]
19
20 error: string = null
21
22 private video: Video | undefined = undefined
23
24 constructor (
25 protected formValidatorService: FormValidatorService,
26 private videoChangeOwnershipValidatorsService: VideoChangeOwnershipValidatorsService,
27 private videoOwnershipService: VideoOwnershipService,
f8b2c1b4 28 private notifier: Notifier,
74d63469
GR
29 private userService: UserService,
30 private modalService: NgbModal,
31 private i18n: I18n
32 ) {
33 super()
34 }
35
36 ngOnInit () {
37 this.buildForm({
38 username: this.videoChangeOwnershipValidatorsService.USERNAME
39 })
40 this.usernamePropositions = []
41 }
42
43 show (video: Video) {
44 this.video = video
45 this.modalService
24e7916c 46 .open(this.modal, { centered: true })
74d63469
GR
47 .result
48 .then(() => this.changeOwnership())
49 .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing
50 }
51
c199c427 52 search (event: { query: string }) {
74d63469
GR
53 const query = event.query
54 this.userService.autocomplete(query)
55 .subscribe(
f8b2c1b4 56 usernames => this.usernamePropositions = usernames,
74d63469 57
f8b2c1b4 58 err => this.notifier.error(err.message)
74d63469
GR
59 )
60 }
61
62 changeOwnership () {
63 const username = this.form.value['username']
64
65 this.videoOwnershipService
66 .changeOwnership(this.video.id, username)
67 .subscribe(
f8b2c1b4 68 () => this.notifier.success(this.i18n('Ownership change request sent.')),
74d63469 69
f8b2c1b4 70 err => this.notifier.error(err.message)
74d63469
GR
71 )
72 }
73}