]>
Commit | Line | Data |
---|---|---|
74d63469 | 1 | import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' |
67ed6552 C |
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' | |
74d63469 | 5 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
74d63469 | 6 | import { I18n } from '@ngx-translate/i18n-polyfill' |
74d63469 GR |
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 { | |
f36da21e | 14 | @ViewChild('modal', { static: true }) modal: ElementRef |
74d63469 GR |
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, | |
f8b2c1b4 | 26 | private notifier: Notifier, |
74d63469 GR |
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 | |
24e7916c | 44 | .open(this.modal, { centered: true }) |
74d63469 GR |
45 | .result |
46 | .then(() => this.changeOwnership()) | |
47 | .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing | |
48 | } | |
49 | ||
c199c427 | 50 | search (event: { query: string }) { |
74d63469 GR |
51 | const query = event.query |
52 | this.userService.autocomplete(query) | |
53 | .subscribe( | |
f8b2c1b4 | 54 | usernames => this.usernamePropositions = usernames, |
74d63469 | 55 | |
f8b2c1b4 | 56 | err => this.notifier.error(err.message) |
74d63469 GR |
57 | ) |
58 | } | |
59 | ||
60 | changeOwnership () { | |
61 | const username = this.form.value['username'] | |
62 | ||
63 | this.videoOwnershipService | |
64 | .changeOwnership(this.video.id, username) | |
65 | .subscribe( | |
f8b2c1b4 | 66 | () => this.notifier.success(this.i18n('Ownership change request sent.')), |
74d63469 | 67 | |
f8b2c1b4 | 68 | err => this.notifier.error(err.message) |
74d63469 GR |
69 | ) |
70 | } | |
71 | } |