Browse Source

Handle error when loading PDF.

pull/70/head
Joachim Bauch 11 years ago
parent
commit
ccb0ca4d8b
  1. 22
      static/js/directives/pdfcanvas.js
  2. 7
      static/js/directives/presentation.js

22
static/js/directives/pdfcanvas.js

@ -22,7 +22,7 @@ define(['require', 'underscore', 'jquery', 'pdf'], function(require, _, $, pdf) @@ -22,7 +22,7 @@ define(['require', 'underscore', 'jquery', 'pdf'], function(require, _, $, pdf)
pdf.workerSrc = require.toUrl('pdf.worker') + ".js";
return ["$compile", function($compile) {
return ["$compile", "translation", function($compile, translation) {
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
@ -91,6 +91,26 @@ define(['require', 'underscore', 'jquery', 'pdf'], function(require, _, $, pdf) @@ -91,6 +91,26 @@ define(['require', 'underscore', 'jquery', 'pdf'], function(require, _, $, pdf)
console.log("PDF loaded", doc);
scope.$emit("pdfLoaded", source, doc);
}, this));
}, this), _.bind(function(error) {
var loadErrorMessage;
switch (error) {
case "InvalidPDFException":
loadErrorMessage = translation._("Could not load PDF: Invalid or corrupted PDF file.");
break;
case "MissingPDFException":
loadErrorMessage = translation._("'Could not load PDF: Missing PDF file.");
break;
default:
if (error) {
loadErrorMessage = translation._("An error occurred while loading the PDF (%s).", error);
} else {
loadErrorMessage = translation._("An unknown error occurred while loading the PDF.");
}
break;
}
this.scope.$apply(_.bind(function(scope) {
scope.$emit("pdfLoadError", source, loadErrorMessage);
}, this));
}, this));
};

7
static/js/directives/presentation.js

@ -50,6 +50,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($, @@ -50,6 +50,7 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
$scope.$on("pdfLoaded", function(event, source, doc) {
$scope.downloading = false;
$scope.hideControlsBar = !$scope.isPresenter;
$scope.currentPageNumber = -1;
if ($scope.isPresenter) {
$scope.$emit("showPdfPage", 1);
@ -62,6 +63,11 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($, @@ -62,6 +63,11 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
$scope.presentationLoaded = true;
});
$scope.$on("pdfLoadError", function(event, source, errorMessage, moreInfo) {
$scope.downloading = false;
alertify.dialog.alert(errorMessage);
});
$scope.$watch("currentPageNumber", function(newval, oldval) {
$scope.$emit("showPdfPage", newval);
});
@ -285,7 +291,6 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($, @@ -285,7 +291,6 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($,
});
uploadPresentation(fileInfo);
$scope.isPresenter = true;
$scope.hideControlsBar = false;
$scope.currentFileInfo = fileInfo;
$scope.receivedPage = null;
$scope.$emit("openPdf", file);

Loading…
Cancel
Save