X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fvideos%2F%2Bvideo-edit%2Fvideo-update.component.ts;h=81c66ff209878d42230380bfaf35da34f4e94deb;hb=03652b3179b7d3d2959b68318fdc5e00f94eb95f;hp=d22ee540a86bbadd704862a40a96f8d87b2b7189;hpb=f8b2c1b4f509c037b9650cca2c5befd21f056df3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/videos/+video-edit/video-update.component.ts b/client/src/app/videos/+video-edit/video-update.component.ts index d22ee540a..81c66ff20 100644 --- a/client/src/app/videos/+video-edit/video-update.component.ts +++ b/client/src/app/videos/+video-edit/video-update.component.ts @@ -1,9 +1,8 @@ import { map, switchMap } from 'rxjs/operators' -import { Component, OnInit } from '@angular/core' +import { Component, HostListener, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { LoadingBarService } from '@ngx-loading-bar/core' import { Notifier } from '@app/core' -import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' import { ServerService } from '../../core' import { FormReactive } from '../../shared' import { VideoEdit } from '../../shared/video/video-edit.model' @@ -13,6 +12,7 @@ import { FormValidatorService } from '@app/shared/forms/form-validators/form-val import { VideoCaptionService } from '@app/shared/video-caption' import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' import { VideoDetails } from '@app/shared/video/video-details.model' +import { VideoPrivacy } from '@shared/models' @Component({ selector: 'my-videos-update', @@ -23,7 +23,6 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { video: VideoEdit isUpdatingVideo = false - videoPrivacies: VideoConstant[] = [] userVideoChannels: { id: number, label: string, support: string }[] = [] schedulePublicationPossible = false videoCaptions: VideoCaptionEdit[] = [] @@ -48,9 +47,6 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { ngOnInit () { this.buildForm({}) - this.serverService.videoPrivaciesLoaded - .subscribe(() => this.videoPrivacies = this.serverService.getVideoPrivacies()) - this.route.data .pipe(map(data => data.videoData)) .subscribe(({ video, videoChannels, videoCaptions }) => { @@ -58,14 +54,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { this.userVideoChannels = videoChannels this.videoCaptions = videoCaptions - // We cannot set private a video that was not private - if (this.video.privacy !== VideoPrivacy.PRIVATE) { - this.videoPrivacies = this.videoPrivacies.filter(p => p.id !== VideoPrivacy.PRIVATE) - } else { // We can schedule video publication only if it it is private - this.schedulePublicationPossible = this.video.privacy === VideoPrivacy.PRIVATE - } - - this.videoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies) + this.schedulePublicationPossible = this.video.privacy === VideoPrivacy.PRIVATE const videoFiles = (video as VideoDetails).files if (videoFiles.length > 1) { // Already transcoded @@ -83,14 +72,26 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { ) } - canDeactivate () { + @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.updateDone === true) return { canDeactivate: true } + const text = this.i18n('You have unsaved changes! If you leave, your changes will be lost.') + for (const caption of this.videoCaptions) { - if (caption.action) return { canDeactivate: false } + if (caption.action) return { canDeactivate: false, text } } - return { canDeactivate: this.formChanged === false } + return { canDeactivate: this.formChanged === false, text } } checkForm () {