From a8e1682ec729d8c7134224549760315289d34fe2 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sun, 30 Mar 2014 18:00:30 +0200 Subject: lade bereits vorhandene Pläne nicht erneut herunter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/index.js | 58 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'js') diff --git a/js/index.js b/js/index.js index ab3ac6e..f28e144 100644 --- a/js/index.js +++ b/js/index.js @@ -90,6 +90,9 @@ function fail(text){ $('#error_noconn').show('fast'); console.log('Fehler: ' + text.toString()); } +/* + * + */ function download_pdf(link, id){ var filename = link.substring(link.lastIndexOf("/") + 1); @@ -111,27 +114,44 @@ function download_pdf(link, id){ } console.log('Pfad: ' + sPath); - var fileTransfer = new FileTransfer(); - fileEntry.remove(); - - fileTransfer.download( - link, - sPath, - function(theFile){ - console.log('Download fertig: ' + theFile.toURL()); - $('#pdf-' + id).attr('data-plan-url', theFile.toURL()); - - if(location.href.indexOf('page-') == -1){ - $.mobile.changePage('#page-vplan-' + id); + + if(fileEntry.file.size == 0){ + var fileTransfer = new FileTransfer(); + + fileTransfer.download( + link, + sPath, + function(theFile){ + console.log('Download fertig: ' + theFile.toURL()); + $('#pdf-' + id).attr('data-plan-url', theFile.toURL()); + + if(location.href.indexOf('page-') == -1){ + $.mobile.changePage('#page-vplan-' + id); + } + }, + function(error){ + console.log('Fehler: ' + error.source + ' - '+ error.target + ' - ' + error.code); + fail(); } - }, - function(error){ - console.log('Fehler: ' + error.source + ' - '+ error.target + ' - ' + error.code); - fail(); + ); + }else{ + // Datei ist schon heruntergeladen + var sPath; + + if(device.platform == "Android"){ + sPath = "/storage/sdcard0" + fileEntry.fullPath; + }else{ + sPath = fileEntry.fullPath; } - ); - }, - fail); + + console.log('Datei vorhanden: ' + sPath); + $('#pdf-' + id).attr('data-plan-url', sPath); + + if(location.href.indexOf('page-') == -1){ + $.mobile.changePage('#page-vplan-' + id); + } + } + }, fail); }, fail); }); -- cgit v1.3.1