diff options
| -rw-r--r-- | index.html | 6 | ||||
| -rw-r--r-- | js/index.js | 90 |
2 files changed, 70 insertions, 26 deletions
@@ -51,6 +51,12 @@ <div class="ui-bar ui-bar-a ui-corner-all" style="display:none;" id="error_noconn"> <center>Etwas ist schiefgelaufen.</center> <center>Versuche es in Kürze noch einmal.</center> + <div style="width:100%;margin 0 auto;"> + <button class="ui-btn" id="loadbtn">Pläne aus dem Speicher anzeigen</button> + </div> + <div class="ui-bar ui-bar-a ui-corner-all" id="error_nofiles" style="display:none;"> + <center>keine Pläne im Speicher :(</center> + </div> </div> <div class="ui-bar ui-bar-a ui-corner-all" style="display:none;" id="error_passwd"> <center>Deine Benutzerdaten stimmen nicht.</center> diff --git a/js/index.js b/js/index.js index 6fcf7b7..af5aeb4 100644 --- a/js/index.js +++ b/js/index.js @@ -27,7 +27,12 @@ $('#loginpage').on('pageshow', function(){ setTimeout(function(){ trylogin(); }, 2000); -}) +}); + +// Ladebutton bei fehlender Verbindung +$('#loadbtn').click(function(){ + load(); +}); // Page-Template für Vertretungsplan var page_html = '\n\ @@ -196,8 +201,6 @@ function get_overview(link, callback){ var plans_re = new RegExp('window\\.open\\('(http://***REMOVED***\\.de/moodle/mod/resource/view\\.php\\?id=\\d+)&redirect=1'\\)', 'g'); var link; - // Pages für Vertretungsplände erstellen und pageshow-Events festlegen - var resultarr = result.match(plans_re); if(resultarr == null){ @@ -209,27 +212,7 @@ function get_overview(link, callback){ var resultl = resultarr.length; - for(j = 0; j < resultl; j++){ - new_html = page_html.replace(/{ID}/g, j); - - $('#loginpage').after(new_html); - - if(j + 1 < resultl){ - $('#page-vplan-' + j).on('swipeleft', function(event){ - $.mobile.changePage('#page-vplan-' + (parseInt($('.ui-page-active').attr('id').match(/\d+/)[0]) + 1)); - }); - } - - if(j - 1 >= 0){ - $('#page-vplan-' + j).on('swiperight', function(event){ - $.mobile.changePage('#page-vplan-' + (parseInt($('.ui-page-active').attr('id').match(/\d+/)[0]) - 1)); - }); - } - - $('#page-vplan-' + j).on('pageshow', function(event){ - render_pdf($('.ui-page-active').attr('id').replace(/page-vplan/, '#pdf')); - }); - } + prepare_html(resultl); j = 0; @@ -308,10 +291,65 @@ function trylogin(){ if(typeof link !== 'undefined' && link != null){ console.log('Teste Login'); - if(get_overview(link) == false){ + get_overview(link, function(){ login(); - } + }); }else{ login(); } } + +function load(){ + window.requestFileSystem( + LocalFileSystem.PERSISTENT, 0, + function(fileSystem){ + fileSystem.root.getDirectory('WvSVPlan', {create: true, exclusive: false}, + function(dirEntry){ + var dirReader = dirEntry.createReader(); + + dirReader.readEntries( + function(entries){ + var actual = 0; + var today = new Date(); + var fname_re = new RegExp('([^-]{4})-([^-]{2})-([^-]{2})(.*?)\.pdf'); // \d funktioniert nicht + + for(j = 0; j < entries.length; j++){ + var name = entries[j].name; + console.log(name); + var results = name.match(fname_re); + var fdate = new Date(parseInt(results[1]), parseInt(results[2]), parseInt(results[3])); + + if(fdate >= today){ + actual++; + } + console.log(actual); + } + + console.log("Im Speicher: " + actual + " Pläne"); + + if(actual > 0){ + prepare_html(actual); + + for(j = 0; j < entries.length; j++){ + var results = entries[j].name.match(fname_re); + var fdate = new Date(results[1], results[2], results[3]); + + if(fdate >= today){ + var sPath = entries[j].toURL(); + + console.log('lade Datei offline: ' + sPath); + $('#pdf-' + j).attr('data-plan-url', sPath); + + if(location.href.indexOf('page-') == -1){ + $.mobile.changePage('#page-vplan-' + j); + } + + } + } + }else{ + + } + }, fail); + }, fail); + }); +} |
