/* * Copyright (C) 2014 * This file is part of WvS VPlan. * * WvS VPlan is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ function setDNT(dntrack){ dntrack = dntrack.toString(); _paq.push(['setDoNotTrack', dntrack]); localStorage.setItem('dntrack', dntrack); $('#disclaimerpopup').popup('close'); $('#dntflip').val(dntrack); } function track(what){ _paq.push(['setCustomUrl', what]); _paq.push(['trackPageView', what]); } function trackPlan(vdate){ track('ui/tab/plan'); track('plan/' + vdate.format('YYYY/MM/DD')); } $('#settingspanel').on('panelclose', function(){ localStorage.setItem('dntrack', $('#dntflip').val()); localStorage.setItem('classes', $('#addclass').val().toUpperCase()); localStorage.setItem('notifyday', $('#notifydayflip').val()); localStorage.setItem('notifydate', $('#notifydate').val()); }); document.addEventListener('pause', function(){ track('event/pause'); }); document.addEventListener('resume', function(){ track('event/resume'); }); document.addEventListener('offline', function offline(){ $('#loginsubmit').prop('disabled', true); $('#error_noconn').show('fast'); }, false); document.addEventListener('online', function online(){ $('#loginsubmit').prop('disabled', false); $('#error_noconn').hide('fast'); }, false); var _paq = _paq || []; $('#mainpage').on('pagebeforeshow', function(){ /* Sprache setzen */ moment.lang('de'); /* Nutzungsstatistiken */ _paq.push(['setTrackerUrl', 'http://klimaag.***REMOVED***/piwik/piwik.php']); // TODO Https wäre schön. _paq.push(['setSiteId', 5]); console.log('Piwik initialisiert'); /* gespeicherte Daten laden */ var dntrack = localStorage.getItem('dntrack'); var additionalClasses = localStorage.getItem('classes'); var notifyDay = localStorage.getItem('notifyday'); var notifyDate = localStorage.getItem('notifydate'); if(dntrack === null || dntrack.length === 0){ dntrack = 'false'; } $('#dntflip').val(dntrack).slider('refresh'); if(additionalClasses === null || additionalClasses.length === 0){ additionalClasses = ''; } $('#addclass').val(additionalClasses).textinput('refresh'); if(notifyDay === null || notifyDay.length === 0){ notifyDay = 0; } $('#notifydayflip').val(notifyDay).slider('refresh'); if(notifyDate === null || notifyDate.length === 0){ notifyDate = '18:00'; } $('#notifydate').val(notifyDate).textinput('refresh'); /* Piwik initialisieren */ _paq.push(['setDoNotTrack', dntrack]); }); // Login-Popup beim Start document.addEventListener('deviceready', function(){ /* los geht's */ _paq.push(['setCustomVariable', 1, 'Modell', device.model, 'visit']); _paq.push(['setCustomVariable', 2, 'Version', device.version, 'visit']); track('event/load'); var dntrack = localStorage.getItem('dntrack'); if(dntrack === null || dntrack.length === 0){ setTimeout(function(){ $('#lnkdisclaimer').click(); }, 2000); }else{ fillForm(); window.plugin.notification.local.cancelAll(); // alle Benachrichtigungen canceln, werden während des Renderings neu gesetzt load(); tryLogin(); } }, false); /* der Loader wird nur angezeigt, wenn das Popup zu ist */ $('#loginpopup').on('popupafteropen', function(){ $.mobile.loading('hide'); }); $('#disclaimerpopup').on('popupafterclose', function(){ fillForm(); window.plugin.notification.local.cancelAll(); load(); tryLogin(); }); /* füllt die Loginform mit gespeicherten Werten */ function fillForm(){ var username = localStorage.getItem('username'); if(username !== null && username.length !== 0){ $('#username').val(username); } var password = localStorage.getItem('password'); if(password !== null && password.length !== 0){ $('#password').val(password); } } /* benachrichtigt den Benutzer an vdate mit msg */ function addNotification(vdate, msg, $div){ var title = 'Vertretung für ' + vdate.format('dddd'); vdate = vdate.subtract('days', 1).add('days', $('#notifydayflip').val()); // Bei Bedarf einen Tag vorher if(moment().isBefore(vdate)){ window.plugin.notification.local.add({ date: vdate.toDate(), message: msg, title: title, autoCancel: true, json: JSON.stringify({id: $div.attr('id')}), //badge: 0 //TODO }); window.plugin.notification.local.onclick = function(id, state, json){ var div = JSON.parse(json).id; location.href = '#' + div; // TODO hoffentlich funktioniert das auch immer... }; console.log('Benachrichtigung hinzugefügt: ' + vdate.format('DD.MM. HH:mm') + '; ' + msg); } } /* zeigt einen Button an, mit dem die Vertretung geteilt werden kann */ function addSocialButton(vdate, msg, $div){ if(moment().isBefore(vdate)){ var datestr = vdate.format('dddd'); var btn = $('