+ this.form.addControl('captions', new FormArray([
+ new FormGroup({
+ language: new FormControl(),
+ captionfile: new FormControl()
+ })
+ ]))
+
+ this.trackChannelChange()
+ this.trackPrivacyChange()
+ }
+
+ ngOnInit () {
+ this.updateForm()
+
+ this.videoCategories = this.serverService.getVideoCategories()
+ this.videoLicences = this.serverService.getVideoLicences()
+ this.videoLanguages = this.serverService.getVideoLanguages()
+
+ this.schedulerInterval = setInterval(() => this.minScheduledDate = new Date(), 1000 * 60) // Update every minute
+ }
+
+ ngOnDestroy () {
+ if (this.schedulerInterval) clearInterval(this.schedulerInterval)
+ }
+
+ getExistingCaptions () {
+ return this.videoCaptions.map(c => c.language.id)
+ }
+
+ onCaptionAdded (caption: VideoCaptionEdit) {
+ this.videoCaptions.push(
+ Object.assign(caption, { action: 'CREATE' as 'CREATE' })
+ )
+ }
+
+ deleteCaption (caption: VideoCaptionEdit) {
+ // This caption is not on the server, just remove it from our array
+ if (caption.action === 'CREATE') {
+ removeElementFromArray(this.videoCaptions, caption)
+ return
+ }
+
+ caption.action = 'REMOVE' as 'REMOVE'
+ }
+
+ openAddCaptionModal () {
+ this.videoCaptionAddModal.show()
+ }
+
+ private trackPrivacyChange () {
+ // We will update the "support" field depending on the channel
+ this.form.controls[ 'privacy' ]
+ .valueChanges
+ .pipe(map(res => parseInt(res.toString(), 10)))
+ .subscribe(
+ newPrivacyId => {
+ this.schedulePublicationEnabled = newPrivacyId === this.SPECIAL_SCHEDULED_PRIVACY
+
+ // Value changed
+ const scheduleControl = this.form.get('schedulePublicationAt')
+ const waitTranscodingControl = this.form.get('waitTranscoding')
+
+ if (this.schedulePublicationEnabled) {
+ scheduleControl.setValidators([ Validators.required ])
+
+ waitTranscodingControl.disable()
+ waitTranscodingControl.setValue(false)
+ } else {
+ scheduleControl.clearValidators()
+
+ waitTranscodingControl.enable()
+ waitTranscodingControl.setValue(true)
+ }
+
+ scheduleControl.updateValueAndValidity()
+ waitTranscodingControl.updateValueAndValidity()
+ }
+ )
+ }
+
+ private trackChannelChange () {