-

Bitte einloggen

@@ -64,8 +63,9 @@ - + + diff --git a/js/index.js b/js/index.js index 4c8f926..bd399ff 100644 --- a/js/index.js +++ b/js/index.js @@ -17,12 +17,18 @@ */ // Login-Popup beim Start -$('#loginpage').on('pagebeforeshow', function loginform(){ +$('#loginpage').on('pagebeforeshow', function(){ setTimeout(function(){ $('#lnklogin').click(); }, 500); }); +$('#loginpage').on('pageshow', function(){ + setTimeout(function(){ + trylogin(); + }, 2000); +}) + // Page-Template für Vertretungsplan var page_html = '\n\
\n\ @@ -149,6 +155,8 @@ function get_overview(link){ url: link }); + console.log('Hole Übersicht'); + request.done(function(result){ var plans_re = new RegExp('window\\.open\\('(http://***REMOVED***\\.de/moodle/mod/resource/view\\.php\\?id=\\d+)&redirect=1'\\)', 'g'); var link; @@ -173,20 +181,16 @@ function get_overview(link){ if(j + 1 < resultl){ $('#page-vplan-' + j).on('swipeleft', function(event){ - console.log('Wisch links'); $.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){ - console.log('Wisch rechts'); $.mobile.changePage('#page-vplan-' + (parseInt($('.ui-page-active').attr('id').match(/\d+/)[0]) - 1)); }); } - console.log('Html hinzugefügt zu: ' + j); - $('#page-vplan-' + j).on('pageshow', function(event){ render_pdf($('.ui-page-active').attr('id').replace(/page-vplan/, '#pdf')); }); @@ -202,12 +206,12 @@ function get_overview(link){ console.log('Übersichts-Request erfolgreich'); }); - request.fail(fail); + request.fail(function(){ + return false; + }); } -function login(){ - var username = encodeURIComponent($('#username').val()); - var password = encodeURIComponent($('#password').val()); +function sendlogin(username, password){ var params = 'username=' + username + '&password=' + password; $('#loginform').addClass('ui-disabled'); @@ -222,13 +226,56 @@ function login(){ data: {username: username, password: password} }); + console.log('Logge ein'); + request.done(function(result){ var vertretungs_re = new RegExp('title="Vertretungsplan" href="(http://***REMOVED***\\.de/moodle/course/view\\.php\\?id=\\d+)"'); var link = vertretungs_re.exec(result)[1]; - console.log('Login-Request erfolgreich: ' + link); - get_overview(link); + window.localStorage.setItem('overviewlink', link); + console.log('Eingeloggt'); + get_overview(link, false); }); request.fail(fail); } + +function login(){ + var username = encodeURIComponent($('#username').val()); + if(username == ''){ + username = window.localStorage.getItem('username'); + }else{ + window.localStorage.setItem('username', username); + } + + var password = encodeURIComponent($('#password').val()); + if(password == ''){ + password = window.localStorage.getItem('password'); + }else{ + window.localStorage.setItem('password', password); + } + + console.log('Benutzerdaten geladen'); + + if(username !== 'undefined' && username != null && username != '' && password !== 'undefined' && password != null && password != ''){ + sendlogin(username, password); + } +} + +// prüfen, ob ein Login notwendig ist oder ob die Session noch gültig ist +function trylogin(){ + var link = window.localStorage.getItem('overviewlink'); + + $('#loginform').addClass('ui-disabled'); + $('#loader').show('fast'); + + if(typeof link !== 'undefined' && link != null){ + console.log('Teste Login'); + + if(get_overview(link) == false){ + login(); + } + }else{ + login(); + } +} -- cgit v1.3.1