Skip to content

Commit

Permalink
fix: remove default type value, don't let save entry without file type
Browse files Browse the repository at this point in the history
  • Loading branch information
diamond-darrell committed Oct 11, 2017
1 parent 62ac4e8 commit 26dc5bf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export class EntryRelatedHandler extends EntryFormWidget
this._relatedFiles.next({ items : [] });
}

protected _onValidate(): Observable<{ isValid: boolean }> {
const fileTypeValid = this._relatedFiles.getValue().items.every(file => !!file.format);
return Observable.of({ isValid: fileTypeValid });
}

protected _onActivate(firstTimeActivating: boolean) {
this._entryId = this.data.id;
super._showLoader();
Expand Down Expand Up @@ -279,37 +284,38 @@ export class EntryRelatedHandler extends EntryFormWidget
this._uploadManagement.cancelUpload(file.uploadFileId, true);
}

private _getFormatByExtension(ext: string): KalturaAttachmentType{
let format : KalturaAttachmentType = null;
switch (ext) {
case "doc":
case "docx":
case "dot":
case "pdf":
case "ppt":
case "pps":
case "xls":
case "xlsx":
case "xml":
format = KalturaAttachmentType.document;
break;
case "gif":
case "png":
case "jpg":
case "jpeg":
case "mp3":
case "mp4":
format = KalturaAttachmentType.media;
break;
case "txt":
format = KalturaAttachmentType.text;
break;
default:
format = KalturaAttachmentType.document;
break;
}
return format;
}
private _getFormatByExtension(ext: string): KalturaAttachmentType {
let format: KalturaAttachmentType = null;
ext = typeof ext === 'string' ? ext.toLowerCase() : ext;
switch (ext) {
case 'doc':
case 'docx':
case 'dot':
case 'pdf':
case 'ppt':
case 'pps':
case 'xls':
case 'xlsx':
case 'xml':
format = KalturaAttachmentType.document;
break;
case 'gif':
case 'png':
case 'jpg':
case 'jpeg':
case 'mp3':
case 'mp4':
format = KalturaAttachmentType.media;
break;
case 'txt':
format = KalturaAttachmentType.text;
break;
default:
break;
}

return format;
}

public _setDirty(){
super._updateWidgetState({isDirty: true});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
</p-column>
<p-column header="{{'applications.content.entryDetails.related.type' | translate}}" [style]="{'width':'140px'}">
<ng-template let-col let-file="rowData" pTemplate="body">
<p-dropdown kDropdownCloseOnScroll [disabled]="file.uploading || file.uploadFailure" [scrollTarget]="related" [options]="_fileTypes" [appendTo]="'body'" [autoWidth]="false" [(ngModel)]="file.format" (onChange)="_handler._setDirty()" placeholder="{{'applications.content.entryDetails.related.select' | translate}}"></p-dropdown>
<p-dropdown kDropdownCloseOnScroll
[disabled]="file.uploading || file.uploadFailure"
[scrollTarget]="related"
[options]="_fileTypes"
[appendTo]="'body'"
[autoWidth]="false"
[placeholder]="'applications.content.entryDetails.related.select' | translate"
[(ngModel)]="file.format"
(onChange)="_handler._setDirty()"></p-dropdown>
</ng-template>
</p-column>
<p-column field="size" header="{{'applications.content.entryDetails.related.size' | translate}}">
Expand Down

0 comments on commit 26dc5bf

Please sign in to comment.