]>
Commit | Line | Data |
---|---|---|
674a66bb | 1 | import { Component, HostListener, ViewChild } from '@angular/core' |
f6a043df | 2 | import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' |
78848714 C |
3 | import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component' |
4 | import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component' | |
5d08a6a7 | 5 | import { ServerService } from '@app/core' |
ce33919c | 6 | import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.component' |
1553e15d | 7 | |
dc8bc31b C |
8 | @Component({ |
9 | selector: 'my-videos-add', | |
27e1a06c | 10 | templateUrl: './video-add.component.html', |
fbad87b0 | 11 | styleUrls: [ './video-add.component.scss' ] |
dc8bc31b | 12 | }) |
fbad87b0 C |
13 | export class VideoAddComponent implements CanComponentDeactivate { |
14 | @ViewChild('videoUpload') videoUpload: VideoUploadComponent | |
047559af | 15 | @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent |
ce33919c | 16 | @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent |
bfb3a98f | 17 | |
ce33919c | 18 | secondStepType: 'upload' | 'import-url' | 'import-torrent' |
fbad87b0 | 19 | videoName: string |
bbe0f064 | 20 | |
5d08a6a7 C |
21 | constructor ( |
22 | private serverService: ServerService | |
23 | ) {} | |
24 | ||
ce33919c | 25 | onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) { |
fbad87b0 C |
26 | this.secondStepType = type |
27 | this.videoName = videoName | |
f6a043df C |
28 | } |
29 | ||
7373507f C |
30 | onError () { |
31 | this.videoName = undefined | |
32 | this.secondStepType = undefined | |
33 | } | |
34 | ||
674a66bb C |
35 | @HostListener('window:beforeunload', [ '$event' ]) |
36 | onUnload (event: any) { | |
37 | const { text, canDeactivate } = this.canDeactivate() | |
38 | ||
39 | if (canDeactivate) return | |
40 | ||
41 | event.returnValue = text | |
42 | return text | |
43 | } | |
44 | ||
45 | canDeactivate (): { canDeactivate: boolean, text?: string} { | |
fbad87b0 | 46 | if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate() |
047559af | 47 | if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate() |
ce33919c | 48 | if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate() |
40e87e9e | 49 | |
fbad87b0 | 50 | return { canDeactivate: true } |
27e1a06c | 51 | } |
5d08a6a7 | 52 | |
ce33919c C |
53 | isVideoImportHttpEnabled () { |
54 | return this.serverService.getConfig().import.videos.http.enabled | |
55 | } | |
56 | ||
57 | isVideoImportTorrentEnabled () { | |
a84b8fa5 | 58 | return this.serverService.getConfig().import.videos.torrent.enabled |
5d08a6a7 | 59 | } |
dc8bc31b | 60 | } |