]>
Commit | Line | Data |
---|---|---|
74d63469 | 1 | import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' |
67ed6552 | 2 | import { Notifier, UserService } from '@app/core' |
7ed1edbb C |
3 | import { OWNERSHIP_CHANGE_USERNAME_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators' |
4 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | |
67ed6552 | 5 | import { Video, VideoOwnershipService } from '@app/shared/shared-main' |
74d63469 | 6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
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, | |
74d63469 | 24 | private videoOwnershipService: VideoOwnershipService, |
f8b2c1b4 | 25 | private notifier: Notifier, |
74d63469 | 26 | private userService: UserService, |
66357162 | 27 | private modalService: NgbModal |
9df52d66 | 28 | ) { |
74d63469 GR |
29 | super() |
30 | } | |
31 | ||
32 | ngOnInit () { | |
33 | this.buildForm({ | |
7ed1edbb | 34 | username: OWNERSHIP_CHANGE_USERNAME_VALIDATOR |
74d63469 GR |
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) | |
1378c0d3 | 51 | .subscribe({ |
9df52d66 C |
52 | next: usernames => { |
53 | this.usernamePropositions = usernames | |
54 | }, | |
74d63469 | 55 | |
1378c0d3 C |
56 | error: err => this.notifier.error(err.message) |
57 | }) | |
74d63469 GR |
58 | } |
59 | ||
60 | changeOwnership () { | |
61 | const username = this.form.value['username'] | |
62 | ||
63 | this.videoOwnershipService | |
64 | .changeOwnership(this.video.id, username) | |
1378c0d3 C |
65 | .subscribe({ |
66 | next: () => this.notifier.success($localize`Ownership change request sent.`), | |
74d63469 | 67 | |
1378c0d3 C |
68 | error: err => this.notifier.error(err.message) |
69 | }) | |
74d63469 GR |
70 | } |
71 | } |