If image preview fails to load, just show the "no preview" message

This commit is contained in:
Shane Kilkelly 2016-05-04 09:32:59 +01:00
parent aa301dacb9
commit 9738703424
2 changed files with 15 additions and 2 deletions

View file

@ -4,15 +4,21 @@ div.binary-file.full-size(
ng-if="openFile" ng-if="openFile"
) )
img( img(
ng-show="!failedLoad"
ng-src="/project/{{ project_id }}/file/{{ openFile.id }}" ng-src="/project/{{ project_id }}/file/{{ openFile.id }}"
ng-if="['png', 'jpg', 'jpeg', 'gif'].indexOf(extension(openFile)) > -1" ng-if="['png', 'jpg', 'jpeg', 'gif'].indexOf(extension(openFile)) > -1"
onerror="sl_binaryFilePreviewError()"
onabort="sl_binaryFilePreviewError()"
) )
img( img(
ng-show="!failedLoad"
ng-src="/project/{{ project_id }}/file/{{ openFile.id }}?format=png" ng-src="/project/{{ project_id }}/file/{{ openFile.id }}?format=png"
ng-if="['pdf', 'eps'].indexOf(extension(openFile)) > -1" ng-if="['pdf', 'eps'].indexOf(extension(openFile)) > -1"
onerror="sl_binaryFilePreviewError()"
onabort="sl_binaryFilePreviewError()"
) )
p.no-preview( p.no-preview(
ng-if="['png', 'jpg', 'jpeg', 'gif', 'pdf', 'eps'].indexOf(extension(openFile)) == -1" ng-if="failedLoad || ['png', 'jpg', 'jpeg', 'gif', 'pdf', 'eps'].indexOf(extension(openFile)) == -1"
) #{translate("no_preview_available")} ) #{translate("no_preview_available")}
a.btn.btn-info( a.btn.btn-info(
ng-href="/project/{{ project_id }}/file/{{ openFile.id }}" ng-href="/project/{{ project_id }}/file/{{ openFile.id }}"

View file

@ -2,6 +2,13 @@ define [
"base" "base"
], (App) -> ], (App) ->
App.controller "BinaryFileController", ["$scope", ($scope) -> App.controller "BinaryFileController", ["$scope", ($scope) ->
$scope.failedLoad = false
window.sl_binaryFilePreviewError = () =>
$scope.failedLoad = true
$scope.$apply()
$scope.extension = (file) -> $scope.extension = (file) ->
return file.name.split(".").pop()?.toLowerCase() return file.name.split(".").pop()?.toLowerCase()
] ]