diff options
| -rw-r--r-- | js/index.js | 91 |
1 files changed, 38 insertions, 53 deletions
diff --git a/js/index.js b/js/index.js index 3c67280..6fcf7b7 100644 --- a/js/index.js +++ b/js/index.js @@ -88,73 +88,58 @@ function fail(text){ $('#loginform').removeClass('ui-disabled'); $('#loader').hide('slow'); $('#error_noconn').show('fast'); - console.log('Fehler: ' + text.toString()); + console.log('Fehler: ' + text.toString() + ' / ' + text.code); } -/* - * - */ function download_pdf(link, id){ var filename = link.substring(link.lastIndexOf("/") + 1); window.requestFileSystem( - LocalFileSystem.PERSISTENT, 0, - function onFileSystemSuccess(fileSystem){ - fileSystem.root.getDirectory('WvSVPlan', {create: true, exclusive: false}, - function(dirEntry){ - dirEntry.getFile( - filename, {create: true, exclusive: false}, - function gotFileEntry(fileEntry){ - var sPath; - - if(device.platform == "Android"){ - sPath = "/storage/sdcard0" + fileEntry.fullPath; - }else{ - sPath = fileEntry.fullPath; - } - - console.log('Pfad: ' + sPath); + LocalFileSystem.PERSISTENT, 0, + function(fileSystem){ + fileSystem.root.getDirectory('WvSVPlan', {create: true, exclusive: false}, + function(dirEntry){ + dirEntry.getFile(filename, {create: false, exclusive: false}, + function(fileEntry){ + // Datei ist schon heruntergeladen + var sPath = fileEntry.toURL(); - if(fileEntry.file.size != 0){ // TODO file.size gibt undefined: file ist eine Funktion!!! - var fileTransfer = new FileTransfer(); + console.log('Datei vorhanden: ' + sPath); + $('#pdf-' + id).attr('data-plan-url', sPath); - 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(err){ + // Datei existiert noch nicht + dirEntry.getFile(filename, {create: true, exclusive: false}, + function(fileEntry){ + var sPath = fileEntry.toURL(); - if(location.href.indexOf('page-') == -1){ - $.mobile.changePage('#page-vplan-' + id); - } - }, - function(error){ - console.log('Fehler: ' + error.source + ' - '+ error.target + ' - ' + error.code); - fail(); - } - ); - }else{ - // Datei ist schon heruntergeladen - var sPath; + console.log('Pfad: ' + sPath); - if(device.platform == "Android"){ - sPath = "/storage/sdcard0" + fileEntry.fullPath; - }else{ - sPath = fileEntry.fullPath; - } + var fileTransfer = new FileTransfer(); - console.log('Datei vorhanden: ' + sPath); - $('#pdf-' + id).attr('data-plan-url', sPath); + 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); - } - } - }, fail); + if(location.href.indexOf('page-') == -1){ + $.mobile.changePage('#page-vplan-' + id); + } }, - fail); + function(error){ + console.log('Fehler: ' + error.source + ' - '+ error.target + ' - ' + error.code); + fail(); + }); + }, fail); }); + }, fail); + }); } function get_plan(link, id){ |
