X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fvideos%2F%2Bvideo-edit%2Fvideo-add.component.ts;h=01fdfcb66742e3a9eb89b85a9fb0f8d0636f676e;hb=7b992a86b107fc2917b993127df8e95a66ae94db;hp=7d360598dfdae54bcf31b034e8bb2683ca709783;hpb=ce33919c24e7402d92d81f3cd8e545df52d98240;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/videos/+video-edit/video-add.component.ts b/client/src/app/videos/+video-edit/video-add.component.ts index 7d360598d..01fdfcb66 100644 --- a/client/src/app/videos/+video-edit/video-add.component.ts +++ b/client/src/app/videos/+video-edit/video-add.component.ts @@ -1,4 +1,4 @@ -import { Component, ViewChild } from '@angular/core' +import { Component, HostListener, ViewChild } from '@angular/core' import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component' import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component' @@ -27,7 +27,22 @@ export class VideoAddComponent implements CanComponentDeactivate { this.videoName = videoName } - canDeactivate () { + onError () { + this.videoName = undefined + this.secondStepType = undefined + } + + @HostListener('window:beforeunload', [ '$event' ]) + onUnload (event: any) { + const { text, canDeactivate } = this.canDeactivate() + + if (canDeactivate) return + + event.returnValue = text + return text + } + + canDeactivate (): { canDeactivate: boolean, text?: string} { if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate() if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate() if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate() @@ -40,6 +55,6 @@ export class VideoAddComponent implements CanComponentDeactivate { } isVideoImportTorrentEnabled () { - return this.serverService.getConfig().import.videos.http.enabled + return this.serverService.getConfig().import.videos.torrent.enabled } }