Commits

Juan Carlos Picado Herrera committed af392ab
  • Participants
  • Parent commits caca1e4

Comments (0)

Files changed (3)

enme-war/src/main/webapp/resource/js/me/activity/Activity.js

                 }
             };
 
-
             /**
              * Function invoked when first contacting the server and when the server has lost the state of this client
              * @method _metaHandshake
              */
             var _metaHandshake = function(handshake) {
-                console.warn("_metaHandshake =====");
-                if (handshake.successful === true)
-                {
-                    cometd.batch(function()
-                    {
-                        cometd.subscribe('/service/notification/status', function(message)
-                        {
-                           console.info("****************************** /service/notification/status", message);
+                console.warn("_metaHandshake =====", handshake);
+                if (handshake.successful === true) {
+                    parent.clientId = handshake.clientId;
+                    cometd.batch(function() {
+                        cometd.subscribe('/service/notification/status', function(message) {
+                           dojo.publish('/notifications/service/messages', message.data);
                         });
                         // Publish on a service channel since the message is for the server only
-                        cometd.publish('/service/notification/status', { name: 'World' });
+                        cometd.publish('/service/notification/status', { r: '0' });
                     });
                 }
             };

enme-war/src/main/webapp/resource/js/me/web/widget/notifications/Notification.js

 
 define([
          "dojo",
+         'dojo/_base/json',
          "dojo/_base/declare",
          "dijit/_WidgetBase",
          "dijit/_TemplatedMixin",
          "dojo/text!me/web/widget/notifications/template/notification.html" ],
         function(
                 dojo,
+                json,
                 declare,
                 _WidgetBase,
                 _TemplatedMixin,
             return declare([ _WidgetBase, _TemplatedMixin, main_widget, _WidgetsInTemplateMixin], {
 
           // template string.
-            templateString : template,
+          templateString : template,
 
           /*
           * delay to retrieve new notification.
           */
-         delay: _ENME.config('notification_delay'),
+         delay: _ENME.config('activity').delay,
 
          /*
           * limit of notifications.
           */
          _originalTitle : null,
 
+         /**
+          *
+          * @property
+          */
+          storage_key : "enme-not",
+
          /*
           *
           */
          postCreate: function() {
+            // after refresh, clean all possible storage key.
+             _ENME.removeItem(this.storage_key);
+             // get the current activity
              this.activity = _ENME.getActivity();
-             console.log("NOTIFICATION", this.activity.cometd);
              var parent = this;
 
-             var jota = function () {
+             // create a timer to get possible new notifications
+             var _timer = function () {
                 console.log("enviando jota /service/notification/status");
-                parent.activity.cometd.publish('/service/notification/status', { name: 'World' });
+                parent.activity.cometd.publish('/service/notification/status', { r : 0 });
              };
+            window.setInterval(_timer, this.delay || 20000);
 
-              window.setInterval(jota, 20000);
-
-            //  load from cookie.
-            //  this._count.innerHTML = encuestame.session.activity.cookie().n;
-            //  //loadin notification subscription.
-            //  var subscriptionNotification;
-             dojo.addOnLoad(dojo.hitch(this, function() {
-                  //this.loadStatus();
-                  //this.loadTimer();
-                  dojo.subscribe("/encuestame/notifications/update/status", this, "_updateStatus");
-                  subscriptionNotification  = parent.activity.cometd.subscribe('/service/notification/status',
-                      dojo.hitch(this, function(message) {
-                          this._updateStatus(message.data.totalNewNot, message.data.totalNot);
-                  }));
-              }));
-              dojo.addOnUnload(function() {
+            dojo.subscribe("/notifications/service/messages", this, "_updateStatus");
+
+            dojo.addOnUnload(function() {
                 if (subscriptionNotification !== null) {
                     parent.activity.cometd.unsubscribe(subscriptionNotification);
                 }
           * @param totalNew
           * @param lastNew
           */
-         _updateStatus : function(totalNew, total){
-             if (totalNew < encuestame.session.activity.cookie().n
-                 || totalNew == encuestame.session.activity.cookie().n) {
+         _updateStatus : function(notStatus) {
+             var _storage =  (json.fromJson(_ENME.restoreItem(this.storage_key)) || ({ n : null , t : null }));
+             if (notStatus.totalNewNot < _storage.n || notStatus.totalNewNot == _storage.n) {
                  //highlight new notifications.
                  this._updateNotifications = true;
                  this._displayNewHighlight();
                  //update title to show number of new notifications
-                 var newTitle = this._originalTitle + " ("+totalNew+")";
+                 var newTitle = this._originalTitle + " ("+  notStatus.totalNewNot + ")";
                  //console.debug("newTitle", newTitle);
                  document.title = newTitle;
              } else {
                  this._hideNewHighlight();
                  this._updateNotifications = false;
              }
-             //update cookie
-             encuestame.session.activity.updateNot(total, totalNew);
-             this.totalNot = totalNew;
-             this._count.innerHTML = this.totalNot;
+             // update cookie
+             _ENME.storeItem(this.storage_key, {
+                t : notStatus.totalNot,
+                n : notStatus.totalNewNot
+             });
+             //encuestame.session.activity.updateNot(total, notStatus.totalNewNot);
+             notStatus.totalNot = notStatus.totalNewNot;
+             this._count.innerHTML = notStatus.totalNot;
          },
 
          /*
         <spring.version>3.1.3.RELEASE</spring.version>
         <env>development</env>
         <javascript.minimize>false</javascript.minimize>
-        <spring.webflow.version>2.3.1.RELEASE</spring.webflow.version>
-        <spring.security.version>3.1.3.RELEASE</spring.security.version>
+        <spring.webflow.version>2.3.0.RELEASE</spring.webflow.version>
+        <spring.security.version>3.1.0.RELEASE</spring.security.version>
         <!-- 3.1.0.CI-SNAPSHOT once compatible with OAuth -->
         <spring-integration-core>2.1.0.RELEASE</spring-integration-core>
         <spring-oauth.version>1.0.0.M6</spring-oauth.version>
             <dependency>
                 <groupId>org.springframework</groupId>
                 <artifactId>spring-orm</artifactId>
-                <version>${spring.version}</version>
+                <version>${spring.orm}</version>
             </dependency>
             <dependency>
                 <groupId>commons-httpclient</groupId>