diff options
| -rw-r--r-- | index.html | 30 | ||||
| -rw-r--r-- | js/.index.js.swp | bin | 40960 -> 24576 bytes | |||
| -rw-r--r-- | js/index.js | 87 |
3 files changed, 45 insertions, 72 deletions
@@ -28,13 +28,14 @@ </head> <body> <div class="app"> - <div data-role="page" class="page" id="loginpage" data-theme="a"> + <div data-role="page" class="page" id="mainpage" data-theme="a"> <div data-role="header"> <h1>WvS VPlan</h1> </div> + <div role="main" class="ui-content"> <a id="lnklogin" href="#loginpopup" data-rel="popup" data-role="button" data-position-to="window" data-inline="true" style="display:none;"></a> - <div data-role="popup" id="loginpopup" data-theme="a" data-dismissible> + <div data-role="popup" id="loginpopup" data-theme="a"> <form style="padding:10px 20px;" id="loginform" action="javascript:login()"> <h3>Bitte einloggen</h3> <label for="username" class="ui-hidden-accessible">Benutzername</label> @@ -52,20 +53,29 @@ <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" onclick="load()">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> + <button class="ui-btn" id="loadbtn" onclick="$('#loginpopup').close()">Pläne aus dem Speicher anzeigen</button> </div> </div> + <div class="ui-bar ui-bar-a ui-corner-all" style="display:none;" id="error_passwd"> <center>Deine Benutzerdaten stimmen nicht.</center> <center>Bitte versuche es erneut.</center> </div> - </div> - </div> - </div> - </div> + </div> <!-- loginpopup --> + + <div data-role="tabs" id="vplantabs"> + <div data-role="navbar"> + <ul> + <li><a href="#nothing">Nichts1</a></li> + </ul> + </div> + <div id="nothing"> + <p>Es sind noch keine Pläne verfügbar. Bitte logge dich ein!</p> + </div> + </div> <!-- vplantabs --> + </div> <!-- main ui-content --> + </div> <!-- mainpage --> + </div> <!-- app --> <script type="text/javascript" src="js/jquery-2.1.0.min.js"></script> <script type="text/javascript" src="js/jquery.mobile-1.4.2.min.js"></script> diff --git a/js/.index.js.swp b/js/.index.js.swp Binary files differindex 71452a0..b4c26c8 100644 --- a/js/.index.js.swp +++ b/js/.index.js.swp diff --git a/js/index.js b/js/index.js index 01fd866..5c9d89e 100644 --- a/js/index.js +++ b/js/index.js @@ -17,29 +17,19 @@ */ // Login-Popup beim Start -$('#loginpage').on('pagebeforeshow', function(){ +$('#mainpage').on('pagebeforeshow', function(){ setTimeout(function(){ + load(); $('#lnklogin').click(); }, 500); }); -$('#loginpage').on('pageshow', function(){ +$('#mainpage').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\ - <div data-role="header">\n\ - <h1>WvS VPlan | Vertretungen</h1>\n\ - </div>\n\ - <div role="main" class="ui-content" id="pdf-{ID}" data-plan-url="">\n\ - </div>\n\ -</div>\n\ -'; - /* PDF Rendering */ function renderPage(div, pdf, pageNumber, callback){ pdf.getPage(pageNumber).then(function(page){ @@ -70,11 +60,11 @@ function renderPage(div, pdf, pageNumber, callback){ }); } -function render_pdf(viewerstr){ - console.log('Rendere PDF: ' + $(viewerstr).attr('data-plan-url') + ' (' + viewerstr + ')'); +function render_pdf(url, divstr){ + console.log('Rendere PDF: ' + url + ' (' + divstr + ')'); - PDFJS.getDocument($(viewerstr).attr('data-plan-url')).then(function(pdf){ - var viewer = document.getElementById(viewerstr.replace(/#/, '')); + PDFJS.getDocument(url).then(function(pdf){ + var viewer = document.getElementById(divstr); var pageNumber = 1; renderPage(viewer, pdf, pageNumber++, function pageRenderingComplete(){ if(pageNumber > pdf.numPages){ @@ -94,19 +84,23 @@ function fail(text){ } /* fügt die lokale URL des Plans ein und ruft die Seite zum Rendering auf */ -function addplanattr(fileEntry, id){ +function addplanattr(fileEntry){ var sPath = fileEntry.toURL(); + var name = fileEntry.name.replace('.pdf', ''); - console.log('Datei: ' + sPath); - $('#pdf-' + id).attr('data-plan-url', sPath); + console.log('Dateiname: ' + name); - if(location.href.indexOf('page-') == -1){ - $.mobile.changePage('#page-vplan-' + id); - } + var vplantabs = $('#vplantabs').tabs(); + var ul = vplantabs.find('ul'); + $('<li><a href="#' + name + '">' + name + '</a></li>').appendTo(ul); + $('<div id="' + name + '"></div>').appendTo(vplantabs); + + render_pdf(sPath, name); + vplantabs.tabs('refresh'); // TODO geht nicht } /* lädt ein PDF anhand eines Links herunter, benötigt ID zur Sortierung */ -function download_pdf(link, id){ +function download_pdf(link){ var filename = link.substring(link.lastIndexOf("/") + 1); window.requestFileSystem( @@ -118,7 +112,7 @@ function download_pdf(link, id){ function(fileEntry){ // Datei ist schon heruntergeladen console.log('lade Datei nicht erneut herunter'); - addplanattr(fileEntry, id); + addplanattr(fileEntry); }, function(err){ // Datei existiert noch nicht @@ -131,7 +125,7 @@ function download_pdf(link, id){ sPath, function(theFile){ console.log('Download fertig: ' + theFile.toURL()); - addplanattr(theFile, id); + addplanattr(theFile); }, fail); }, fail); }); @@ -140,13 +134,13 @@ function download_pdf(link, id){ } /* sucht den Downloadlink eines Plans mithilfe eines Links aus der Kursübersicht */ -function get_plan(link, id){ +function get_plan(link){ var request = $.ajax({ url: link }); request.done(function gotplan(resulthtml){ - var pdf_re = new RegExp('(http://***REMOVED***\\.de/moodle/pluginfile\\.php/\\d+/mod_resource/content/\\d+.*?\\.pdf)'); + var pdf_re = new RegExp('(http://***REMOVED***\\.de/moodle/pluginfile\\.php/\\d+/mod_resource/content/\\d+/.*?\\.pdf)'); var pdflink = pdf_re.exec(resulthtml)[1]; if(pdflink == null){ @@ -154,7 +148,7 @@ function get_plan(link, id){ } console.log('Plan gefunden: ' + pdflink); - download_pdf(pdflink, id); + download_pdf(pdflink); return 1; }); @@ -162,31 +156,6 @@ function get_plan(link, id){ request.fail(fail); } -/* erstellt dynamisch die Seiten für die Vertretungspläne und aktiviert Wischgesten */ -function prepare_html(number){ - for(j = 0; j < number; j++){ - new_html = page_html.replace(/{ID}/g, j); - - $('#loginpage').after(new_html); - - if(j + 1 < number){ - $('#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')); - }); - } -} - /* ruft get_plan für jeden Link in der Kursübersicht auf */ function gotoverview(resulthtml){ var plans_re = new RegExp('window\\.open\\('(http://***REMOVED***\\.de/moodle/mod/resource/view\\.php\\?id=\\d+)&redirect=1'\\)', 'g'); @@ -202,13 +171,9 @@ function gotoverview(resulthtml){ var resultl = resultarr.length; - prepare_html(resultl); - - j = 0; - while((link = plans_re.exec(resulthtml)) !== null){ console.log('suche Plan ' + link[1]); - get_plan(link[1], j++); + get_plan(link[1]); } console.log('Übersichts-Request erfolgreich'); @@ -360,10 +325,8 @@ function load(){ console.log("Im Speicher: " + actual.length + " Pläne"); if(actual.length > 0){ - prepare_html(actual.length); - for(j = 0; j < actual.length; j++){ - addplanattr(actual[j], j); + addplanattr(actual[j]); } }else{ |
