From fdf8325d8dbca9bfa2a65a73f3c5bf8f9867564d Mon Sep 17 00:00:00 2001 From: schneefux Date: Thu, 1 May 2014 17:18:39 +0200 Subject: ersetze LocalNotification-Plugin --- BUILDING | 4 ++-- js/index.js | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/BUILDING b/BUILDING index 5d0d168..07d4f5b 100644 --- a/BUILDING +++ b/BUILDING @@ -1,10 +1,10 @@ npm -g install cordova #(https://cordova.apache.org/) cordova create WvSVPlan cordova platform add android # und mehr -cordova plugin add https://github.com/Wizcorp/phonegap-plugin-localNotifications #jp.wizcorp.phonegap.plugin.localNotificationPlugin cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin #nl.x-services.plugins.socialsharing cordova plugin add org.apache.cordova.device cordova plugin add org.apache.cordova.file cordova plugin add org.apache.cordova.file-transfer -cordova build cordova plugin add org.apache.cordova.network-information +cordova plugin add de.appplant.cordova.plugin.local-notification +cordova build diff --git a/js/index.js b/js/index.js index 4c97132..8fe8240 100644 --- a/js/index.js +++ b/js/index.js @@ -116,6 +116,7 @@ document.addEventListener('deviceready', function(){ }, 2000); }else{ fillForm(); + window.plugin.notification.local.cancelAll(); // alle Benachrichtigungen canceln, werden während des Renderings neu gesetzt load(); tryLogin(); } @@ -128,6 +129,7 @@ $('#loginpopup').on('popupafteropen', function(){ $('#disclaimerpopup').on('popupafterclose', function(){ fillForm(); + window.plugin.notification.local.cancelAll(); load(); tryLogin(); }); @@ -148,17 +150,24 @@ function fillForm(){ } /* benachrichtigt den Benutzer an vdate mit msg */ -var notifications = 0; -function addNotification(vdate, 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 - var secondsUntilDate = vdate.diff(moment(), 'seconds'); - - if(secondsUntilDate > 0){ - localNotification.add(++notifications, { - seconds: secondsUntilDate, + if(moment().isBefore(vdate)){ + window.plugin.notification.local.add({ + date: vdate.toDate(), message: msg, - badge: 0}); + 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); } @@ -360,7 +369,7 @@ function renderPage($div, pdf, pageNumber, callback){ vdate.set('hour', time[0]); vdate.set('minute', time[1]); - addNotification(vdate, vertretungen.join('\n')); + addNotification(vdate, vertretungen.join('\n'), $div); addSocialButton(vdate, vertretungen.join(', '), $div); } }); -- cgit v1.3.1