Browse Source

@working on notification types

halphass 7 years ago
parent
commit
06a3344b27
1 changed files with 40 additions and 26 deletions
  1. 40 26
      www/js/push.js

+ 40 - 26
www/js/push.js

@@ -31,37 +31,51 @@ function onDeviceReadyPush() {
     /*
      * gestisce la notifica ricevuta
      */
-    push.on('notification', function(data) {
-        console.log(JSON.stringify(data));
+    push.on('notification', function(notification) {
+        console.log(JSON.stringify(notification));
 
-        if(data.additionalData.type === 'alarm')
-        {
-            /*
-             *   QUESTA è una COMUNICAZIONE IMPORTANTE!
-             */
-            $("body").pagecontainer("change", "#alert");
-            $("#alert-title").html(data.title);
-            $("#alert-message").html(data.message);
-        }
-        else
-        {
-            /*
-             *   QUESTO è un SEMPLICE AGGIORNAMENTO!
-             */
-            if(!empty(data.additionalData.url))
-            {
-                console.log('HO UN URL '+data.additionalData.url);
+        switch(notification.additionalData.type) {
+            case 'event':
                 /*
-                    TODO: va aggiunto come si deve comportare l'app
+                 *   Questo è il reminder o la pubblicazione di un evento
                  */
-            }
-            else {
-                console.log('NESSUN URL, DEVO VISUALIZZARE DA QUALCHE PARTE MESSAGGIO E TITOLO..');
+                var eventId = notification.additionalData.data.id;
+                var eventUrl = notification.additionalData.url;
                 /*
-                 TODO: va aggiunto come si deve comportare l'app
+                 * TODO: mandare l'utente all'evento..
+                 * l'url servirebbe solo se lo si vuole fare in webview
+                 * altrimenti bisognerebbe fare il fetch dell'xml dal sito,
+                 * salvarlo o comunque visualizzare la pagina
                  */
-            }
-
+                break;
+            case 'post':
+                /*
+                 *   Questo è il reminder o la pubblicazione di un post
+                 */
+                var postId = notification.additionalData.data.id;
+                var postUrl = notification.additionalData.url;
+                /*
+                 * TODO: mandare l'utente al post..
+                 * l'url servirebbe solo se lo si vuole fare in webview
+                 * altrimenti bisognerebbe fare il fetch dell'xml o json dal sito,
+                 * salvarlo o comunque visualizzare la pagina
+                 */
+                break;
+            case 'notice':
+                /*
+                 *   Questa è una comunicazione generica
+                 */
+                // TODO: cosa mettere nel payload? Che fare?
+                break;
+            case 'alarm':
+                /*
+                 *   Questa è una comunicazione importante
+                 */
+                // TODO: cosa mettere nel payload? Che fare? Qui per esempio mostro semplicemente il messaggio
+                $("body").pagecontainer("change", "#alert");
+                $("#alert-title").html(notification.title);
+                $("#alert-message").html(notification.message);
+                break;
         }
 
     });