diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-04-03 10:51:44 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2016-08-15 19:46:50 +0200 |
| commit | 457827e85b3dc6189b8d0f47ef79d8cf7c1920c6 (patch) | |
| tree | 05bac8365b3911cc0fbc5fa23a39b68f8e7f4f19 /js | |
| parent | be4a18b2c1bf877ef6a9d1b94e1fd3a378deba2c (diff) | |
| download | wvs-vplan-457827e85b3dc6189b8d0f47ef79d8cf7c1920c6.tar.gz wvs-vplan-457827e85b3dc6189b8d0f47ef79d8cf7c1920c6.zip | |
behebe Kompatibilitätsprobleme und Einrückung in download_pdf; erstelle Ordner beim ersten Appstart
Diffstat (limited to 'js')
| -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){ |
