summaryrefslogtreecommitdiff
path: root/js/index.js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-03-30 17:16:00 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2016-08-15 19:46:49 +0200
commitd2627ce165bef202ff833d2766e307bcb6fb2bdb (patch)
tree7b4cc2db4a75d6c570d0d55e4bac77ce520bf3a1 /js/index.js
parent9139039b98545523887a407607ac77509e273918 (diff)
downloadwvs-vplan-d2627ce165bef202ff833d2766e307bcb6fb2bdb.tar.gz
wvs-vplan-d2627ce165bef202ff833d2766e307bcb6fb2bdb.zip
automatisiere Login; vereinfachere Debugmessages
Diffstat (limited to 'js/index.js')
-rw-r--r--js/index.js69
1 files changed, 58 insertions, 11 deletions
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\
<div data-role="page" class="page" id="page-vplan-{ID}" data-prefetch>\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\\(&#039;(http://***REMOVED***\\.de/moodle/mod/resource/view\\.php\\?id=\\d+)&amp;redirect=1&#039;\\)', '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();
+ }
+}