From 5efbbffb4b75b168a503311685d6aefc773e2f05 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sun, 13 Apr 2014 11:32:12 +0200 Subject: refaktorisiere das Hinzufügen der PDF-Attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/index.js | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'js') diff --git a/js/index.js b/js/index.js index 7191ae4..28c736c 100644 --- a/js/index.js +++ b/js/index.js @@ -91,6 +91,17 @@ function fail(text){ console.log('Fehler: ' + text.toString() + ' / ' + text.code); } +function addplanattr(fileEntry, id){ + var sPath = fileEntry.toURL(); + + console.log('Datei: ' + sPath); + $('#pdf-' + id).attr('data-plan-url', sPath); + + if(location.href.indexOf('page-') == -1){ + $.mobile.changePage('#page-vplan-' + id); + } +} + function download_pdf(link, id){ var filename = link.substring(link.lastIndexOf("/") + 1); @@ -102,23 +113,13 @@ function download_pdf(link, id){ dirEntry.getFile(filename, {create: false, exclusive: false}, function(fileEntry){ // Datei ist schon heruntergeladen - var sPath = fileEntry.toURL(); - - console.log('Datei vorhanden: ' + sPath); - $('#pdf-' + id).attr('data-plan-url', sPath); - - if(location.href.indexOf('page-') == -1){ - $.mobile.changePage('#page-vplan-' + id); - } + console.log('lade Datei nicht erneut herunter'); + addplanattr(fileEntry, id); }, function(err){ // Datei existiert noch nicht dirEntry.getFile(filename, {create: true, exclusive: false}, function(fileEntry){ - var sPath = fileEntry.toURL(); - - console.log('Pfad: ' + sPath); - var fileTransfer = new FileTransfer(); fileTransfer.download( @@ -126,11 +127,7 @@ function download_pdf(link, id){ 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); - } + addplanattr(theFile, id); }, function(error){ console.log('Fehler: ' + error.source + ' - '+ error.target + ' - ' + error.code); @@ -357,15 +354,7 @@ function load(){ var fdate = new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3])); if(fdate >= today){ - var sPath = entries[j].toURL(); - - console.log('lade Datei offline: ' + sPath); - $('#pdf-' + actual).attr('data-plan-url', sPath); - - if(location.href.indexOf('page-') == -1){ - $.mobile.changePage('#page-vplan-' + actual); - } - actual++; + addplanattr(entries[j], actual++); } } }else{ -- cgit v1.3.1