]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-videos/video-change-ownership/video-change-ownership.component.ts
Update build steps for localization
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-videos / video-change-ownership / video-change-ownership.component.ts
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'
7
8 @Component({
9 selector: 'my-video-change-ownership',
10 templateUrl: './video-change-ownership.component.html',
11 styleUrls: [ './video-change-ownership.component.scss' ]
12 })
13 export class VideoChangeOwnershipComponent extends FormReactive implements OnInit {
14 @ViewChild('modal', { static: true }) modal: ElementRef
15
16 usernamePropositions: string[]
17
18 error: string = null
19
20 private video: Video | undefined = undefined
21
22 constructor (
23 protected formValidatorService: FormValidatorService,
24 private videoChangeOwnershipValidatorsService: VideoChangeOwnershipValidatorsService,
25 private videoOwnershipService: VideoOwnershipService,
26 private notifier: Notifier,
27 private userService: UserService,
28 private modalService: NgbModal,
29 private i18n: I18n
30 ) {
31 super()
32 }
33
34 ngOnInit () {
35 this.buildForm({
36 username: this.videoChangeOwnershipValidatorsService.USERNAME
37 })
38 this.usernamePropositions = []
39 }
40
41 show (video: Video) {
42 this.video = video
43 this.modalService
44 .open(this.modal, { centered: true })
45 .result
46 .then(() => this.changeOwnership())
47 .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing
48 }
49
50 search (event: { query: string }) {
51 const query = event.query
52 this.userService.autocomplete(query)
53 .subscribe(
54 usernames => this.usernamePropositions = usernames,
55
56 err => this.notifier.error(err.message)
57 )
58 }
59
60 changeOwnership () {
61 const username = this.form.value['username']
62
63 this.videoOwnershipService
64 .changeOwnership(this.video.id, username)
65 .subscribe(
66 () => this.notifier.success(this.i18n('Ownership change request sent.')),
67
68 err => this.notifier.error(err.message)
69 )
70 }
71 }