summaryrefslogtreecommitdiff
path: root/js/index.js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-04-13 11:32:12 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2016-08-15 19:46:51 +0200
commit5efbbffb4b75b168a503311685d6aefc773e2f05 (patch)
tree587585d12d35db1806454cf34dc604041676e86f /js/index.js
parentf44b190bf3408bb4291d38b20115f81b9085fe68 (diff)
downloadwvs-vplan-5efbbffb4b75b168a503311685d6aefc773e2f05.tar.gz
wvs-vplan-5efbbffb4b75b168a503311685d6aefc773e2f05.zip
refaktorisiere das Hinzufügen der PDF-Attribute
Diffstat (limited to 'js/index.js')
-rw-r--r--js/index.js41
1 files changed, 15 insertions, 26 deletions
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{