← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4313: made availability check auto-adjust interval (online vs offline)

 

------------------------------------------------------------
revno: 4313
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-08-16 14:41:09 +0200
message:
  made availability check auto-adjust interval (online vs offline)
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.availability.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.availability.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.availability.js	2011-08-16 12:16:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.availability.js	2011-08-16 12:41:09 +0000
@@ -35,14 +35,13 @@
  * Start availability check, will trigger dhis2.online / dhis2.offline events
  * when availability changes.
  * 
- * @param checkInterval How often to check for availability, default is 1000.
+ * @param onlineInterval How often to check for availability, default is 1000.
+ * @param offlineInterval How often to check for availability, default is 1000.
  */
-dhis2.availability.startAvailabilityCheck = function( checkInterval )
+dhis2.availability.startAvailabilityCheck = function( onlineInterval, offlineInterval )
 {
-    if ( checkInterval === undefined )
-    {
-        checkInterval = 1000;
-    }
+    onlineInterval = onlineInterval ? onlineInterval : 10000;
+    offlineInterval = offlineInterval ? offlineInterval : 1000;
 
     function _checkAvailability()
     {
@@ -56,7 +55,7 @@
                 if ( loggedIn != dhis2.availability._isLoggedIn )
                 {
                     dhis2.availability._isLoggedIn = loggedIn;
-                    $( document ).trigger( "dhis2.online", [ loggedIn ]);
+                    $( document ).trigger( "dhis2.online", [ loggedIn ] );
                 }
             },
             error : function( jqXHR, textStatus, errorThrown )
@@ -69,11 +68,18 @@
             }
         } ).complete( function()
         {
-            _availableTimeoutHandler = setTimeout( _checkAvailability, checkInterval );
+            if ( dhis2.availability._isAvailable )
+            {
+                dhis2.availability._availableTimeoutHandler = setTimeout( _checkAvailability, onlineInterval );
+            }
+            else
+            {
+                dhis2.availability._availableTimeoutHandler = setTimeout( _checkAvailability, offlineInterval );
+            }
         } );
     }
 
-    _availableTimeoutHandler = setTimeout( _checkAvailability, checkInterval );
+    _availableTimeoutHandler = setTimeout( _checkAvailability, onlineInterval );
 }
 
 /**
@@ -81,5 +87,5 @@
  */
 dhis2.availability.stopAvailabilityCheck = function()
 {
-    clearTimeout( _availableTimeoutHandler );
+    clearTimeout( dhis2.availability._availableTimeoutHandler );
 }