summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-04-03 11:27:12 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2016-08-15 19:46:50 +0200
commit4d3f658a710f4d88d65c9e6ed1c659946e378007 (patch)
tree2a2b0d7795c008feeff8cc0ad681c9b45d4e290b /js
parent457827e85b3dc6189b8d0f47ef79d8cf7c1920c6 (diff)
downloadwvs-vplan-4d3f658a710f4d88d65c9e6ed1c659946e378007.tar.gz
wvs-vplan-4d3f658a710f4d88d65c9e6ed1c659946e378007.zip
füge Option zum Laden von Plänen aus dem Speicher hinzu
Diffstat (limited to 'js')
-rw-r--r--js/index.js90
1 files changed, 64 insertions, 26 deletions
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\\(&#039;(http://***REMOVED***\\.de/moodle/mod/resource/view\\.php\\?id=\\d+)&amp;redirect=1&#039;\\)', '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);
+ });
+}