← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4354: made ajax-login give correct feedback

 

------------------------------------------------------------
revno: 4354
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-08-18 14:53:28 +0200
message:
  made ajax-login give correct feedback
modified:
  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.select.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.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-18 12:01:44 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.availability.js	2011-08-18 12:53:28 +0000
@@ -92,3 +92,39 @@
 {
     clearTimeout( dhis2.availability._availableTimeoutHandler );
 };
+
+/**
+ * Synchronized one-off check of availability.
+ */
+dhis2.availability.syncCheckAvailability = function()
+{
+    var isLoggedIn = false;
+
+    $.ajax( {
+        url : "../dhis-web-commons-stream/ping.action",
+        async : false,
+        success : function( data, textStatus, jqXHR )
+        {
+            dhis2.availability._isAvailable = true;
+            var loggedIn = data.loggedIn ? true : false;
+
+            if ( loggedIn != dhis2.availability._isLoggedIn )
+            {
+                dhis2.availability._isLoggedIn = loggedIn;
+                $( document ).trigger( "dhis2.online", [ loggedIn ] );
+            }
+
+            isLoggedIn = loggedIn;
+        },
+        error : function( jqXHR, textStatus, errorThrown )
+        {
+            if ( dhis2.availability._isAvailable )
+            {
+                dhis2.availability._isAvailable = false;
+                $( document ).trigger( "dhis2.offline" );
+            }
+        }
+    } );
+
+    return isLoggedIn;
+};

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js	2011-06-19 17:25:08 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js	2011-08-18 12:53:28 +0000
@@ -48,7 +48,7 @@
     }
 
     return $select_ghost;
-}
+};
 
 /**
  * Filter a select on a given key. Options that are not matched, are moved to
@@ -64,7 +64,7 @@
 dhis2.select.filterWithKey = function( $select, key, caseSensitive )
 {
     $select_ghost = dhis2.select.getGhost( $select );
-    caseSensitive = caseSensitive || false;
+    caseSensitive = caseSensitive || false;
 
     if (key.length === 0) {
         dhis2.select.moveSorted( $select, $select_ghost.children() );
@@ -85,7 +85,7 @@
         dhis2.select.moveSorted( $select_ghost, $select_not_matched );
         dhis2.select.moveSorted( $select, $select_ghost_matched );
     }
-}
+};
 
 /**
  * Moves an array of child elements into a select, these will be moved in a
@@ -126,7 +126,7 @@
 
         $select.append(array);
     }
-}
+};
 
 /**
  * Moves an array of child elements into a select.
@@ -137,7 +137,7 @@
 dhis2.select.move = function ($select, $array)
 {
     $select.append($array);
-}
+};
 
 /**
  * Mark all options in a select as selected.
@@ -147,7 +147,7 @@
 dhis2.select.selectAll = function($select)
 {
     $select.children().attr('selected', true);
-}
+};
 
 /**
  * Mark all options as not selected.
@@ -157,7 +157,7 @@
 dhis2.select.selectNone = function($select)
 {
     $select.children().attr('selected', false);
-}
+};
 
 /**
  * Sort options in a select. Based on their html() content. This version is case
@@ -172,7 +172,7 @@
     return $.makeArray($options).sort(function(a, b) {
         return dhis2.comparator.htmlComparator( $(a), $(b) );
     });
-}
+};
 
 /**
  * Sort options in a select. Based on their html() content. This version is case
@@ -187,4 +187,4 @@
     return $($.makeArray($options).sort(function(a, b) {
         return dhis2.comparator.htmlNoCaseComparator( $(a), $(b) );
     }) );
-}
+};

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-08-18 11:51:03 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-08-18 12:53:28 +0000
@@ -111,6 +111,25 @@
     dhis2.availability.startAvailabilityCheck();
 } );
 
+function ajax_login() 
+{
+    $( '#login_button' ).bind( 'click', function() {
+        var username = $( '#username' ).val();
+        var password = $( '#password' ).val();
+
+        $.post( '../dhis-web-commons-security/login.action', {
+            'j_username': username,
+            'j_password': password
+        } ).success( function() {
+            var ret = dhis2.availability.syncCheckAvailability();
+
+            if(!ret) {
+                alert("Login failed, check your username and password and try again.");
+            }
+        } );
+    } );
+}
+
 function loadMetaData()
 {
 	$.getJSON( 'getMetaData.action', function( json ) {
@@ -238,21 +257,6 @@
     })(dataValuesArray);
 }
 
-function ajax_login() 
-{
-    $( '#login_button' ).bind( 'click', function() {
-        var username = $( '#username' ).val();
-        var password = $( '#password' ).val();
-
-        $.post( '../dhis-web-commons-security/login.action', {
-            'j_username': username,
-            'j_password': password
-        } ).success( function() {
-            alert( 'Login attempt successful, TODO check if login was successful with checkAvailability' );
-        } );
-    } );
-}
-
 function addEventListeners()
 {
     $( '[name="ef"]' ).each( function( i )