import { NotificationsService } from 'angular2-notifications'
import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos'
import { ServerService } from '../../core'
-import { AuthService } from '../../core/auth'
import { FormReactive } from '../../shared'
import { VideoEdit } from '../../shared/video/video-edit.model'
import { VideoService } from '../../shared/video/video.service'
-import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
import { VideoCaptionService } from '@app/shared/video-caption'
video: VideoEdit
isUpdatingVideo = false
- videoPrivacies: VideoConstant<string>[] = []
+ videoPrivacies: VideoConstant<VideoPrivacy>[] = []
userVideoChannels: { id: number, label: string, support: string }[] = []
schedulePublicationPossible = false
videoCaptions: VideoCaptionEdit[] = []
+ private updateDone = false
+
constructor (
protected formValidatorService: FormValidatorService,
private route: ActivatedRoute,
private notificationsService: NotificationsService,
private serverService: ServerService,
private videoService: VideoService,
- private authService: AuthService,
private loadingBar: LoadingBarService,
- private videoChannelService: VideoChannelService,
private videoCaptionService: VideoCaptionService,
private i18n: I18n
) {
// We cannot set private a video that was not private
if (this.video.privacy !== VideoPrivacy.PRIVATE) {
- this.videoPrivacies = this.videoPrivacies.filter(p => p.id.toString() !== VideoPrivacy.PRIVATE.toString())
+ 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
}
- // FIXME: Angular does not detec
+ this.videoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
+
+ // FIXME: Angular does not detect the change inside this subscription, so use the patched setTimeout
setTimeout(() => this.hydrateFormFromVideo())
},
)
}
+ canDeactivate () {
+ if (this.updateDone === true) return { canDeactivate: true }
+
+ for (const caption of this.videoCaptions) {
+ if (caption.action) return { canDeactivate: false }
+ }
+
+ return { canDeactivate: this.formChanged === false }
+ }
+
checkForm () {
this.forceCheck()
}
update () {
- if (this.checkForm() === false) {
+ if (this.checkForm() === false
+ || this.isUpdatingVideo === true) {
return
}
)
.subscribe(
() => {
+ this.updateDone = true
this.isUpdatingVideo = false
this.loadingBar.complete()
this.notificationsService.success(this.i18n('Success'), this.i18n('Video updated.'))
console.error(err)
}
)
-
}
private hydrateFormFromVideo () {