summaryrefslogtreecommitdiff
path: root/js/index.js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-03-22 16:52:01 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2016-08-15 19:46:45 +0200
commit67087e36ae59c6dc1b80c97cfcd1b9f3a4b03e28 (patch)
treec3376bd1e960278a635eb6d306e9daaa0783232b /js/index.js
parent9a56238cd200874616b0cd8e133db1d795cc75f2 (diff)
downloadwvs-vplan-67087e36ae59c6dc1b80c97cfcd1b9f3a4b03e28.tar.gz
wvs-vplan-67087e36ae59c6dc1b80c97cfcd1b9f3a4b03e28.zip
implementiere Download des PDFs
Diffstat (limited to 'js/index.js')
-rw-r--r--js/index.js98
1 files changed, 56 insertions, 42 deletions
diff --git a/js/index.js b/js/index.js
index 8b5f6ca..b9c7242 100644
--- a/js/index.js
+++ b/js/index.js
@@ -16,57 +16,71 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-function fail(text){
- alert("Etwas ist schiefgelaufen: " + text.toString());
-}
+function show_pdf(url){
+ $('#input').attr('src', url);
-function download_pdf(link){
- var filename = link.substring(link.lastIndexOf('/') + 1);
+ console.log("Download fertig, parse PDF");
+
+ var input = document.getElementById("input");
+ var processor = document.getElementById("processor");
+ var output = document.getElementById("output");
+
+ window.addEventListener("message", function(event){
+ if(event.source != processor.contentWindow) return;
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
- fileSystem.root.getFile(filename, {create: true, exclusive: false}, function(fileEntry){
- console.log("Bereite Download vor");
- var localPath = fileEntry.fullPath;
- if(/*device.platform == "Android" && /* TODO fehleranfällig? */localPath.indexOf("file://") == 0){
- localPath = localPath.substring(7);
- }
- var ft = new FileTransfer();
- console.log("Bereit für Download " + ft);
- ft.download(link,
- localPath, function(entry){
- console.log("foo");
- $('#input').attr('src', entry.fullPath);
+ switch(event.data){
+ case "ready":
+ var xhr = new XMLHttpRequest;
+ xhr.open("GET", input.getAttribute("src"), true);
+ xhr.responseType = "arraybuffer";
- console.log("Download fertig, parse PDF");
+ xhr.onload = function(event){
+ processor.contentWindow.postMessage(this.response, "*");
+ };
- var input = document.getElementById("input");
- var processor = document.getElementById("processor");
- var output = document.getElementById("output");
+ xhr.send();
+ break;
- window.addEventListener("message", function(event){
- if(event.source != processor.contentWindow) return;
+ default:
+ output.textContent = event.data.replace(/\s+/g, " ");
+ break;
+ }
+ }, true);
+}
- switch(event.data){
- case "ready":
- var xhr = new XMLHttpRequest;
- xhr.open("GET", input.getAttribute("src"), true);
- xhr.responseType = "arraybuffer";
+function fail(text){
+ alert("Etwas ist schiefgelaufen: " + text.toString());
+}
- xhr.onload = function(event){
- processor.contentWindow.postMessage(this.response, "*");
- };
+function download_pdf(link){
+ var filename = link.substring(link.lastIndexOf('/') + 1);
- xhr.send();
- break;
+ window.requestFileSystem(
+ LocalFileSystem.PERSISTENT, 0,
+ function onFileSystemSuccess(fileSystem){
+ fileSystem.root.getFile(
+ filename, {create: true, exclusive: false},
+ function gotFileEntry(fileEntry){
+ var sPath = "/storage/sdcard0" + fileEntry.fullPath; // !!! TODO Unterstützung anderer Geräte
+ console.log("Pfad: " + sPath);
+ var fileTransfer = new FileTransfer();
+ fileEntry.remove();
- default:
- output.textContent = event.data.replace(/\s+/g, " ");
- break;
- }
- }, true);
- }, fail);
- }, fail);
- }, fail);
+ fileTransfer.download(
+ link,
+ sPath,
+ function(theFile){
+ console.log("Download fertig: " + theFile.toURL());
+ show_pdf(theFile.toURL());
+ },
+ function(error){
+ console.log("Fehler: " + error.source + " - "+ error.target + " - " + error.code);
+ }
+ );
+ },
+ fail);
+ },
+ fail);
}
function get_plan(link){