archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1212451 - /archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js
Date Fri, 09 Dec 2011 14:49:15 GMT
Author: olamy
Date: Fri Dec  9 14:49:15 2011
New Revision: 1212451

URL: http://svn.apache.org/viewvc?rev=1212451&view=rev
Log:
login call moved to a function with configurable callback

Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js?rev=1212451&r1=1212450&r2=1212451&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js
Fri Dec  9 14:49:15 2011
@@ -224,52 +224,69 @@ $(function() {
     var url = 'restServices/redbackServices/loginService/logIn?userName='+$("#user-login-form-username").val();
     url += "&password="+$("#user-login-form-password").val();
 
-    $.ajax({
-      url: url,
-      success: function(result){
-        var logged = false;
-        if (result == null) {
-          logged = false;
-        } else {
-          if (result.user) {
-            logged = true;
-          }
+    var successCallbackFn=function(result){
+      var logged = false;
+      if (result == null) {
+        logged = false;
+      } else {
+        if (result.user) {
+          logged = true;
         }
-        if (logged == true) {
-          var user = mapUser(result.user);
-          $.log("user.passwordChangeRequired:"+user.passwordChangeRequired());
-          if (user.passwordChangeRequired()==true){
-            changePasswordBox(true,false,user);
-            return;
-          }
-          // not really needed as an exception is returned but "ceintures et bretelles" as
we said in French :-)
-          if (user.locked()==true){
-            $.log("user locked");
-            displayErrorMessage($.i18n.prop("accout.locked"));
-            return
-          }          
-          // FIXME check validated
-          reccordLoginCookie(user);
-          $("#login-link").hide();
-          $("#logout-link").show();
-          $("#register-link").hide();
-          $("#change-password-link").show();
-          window.modalLoginWindow.modal('hide');
-          clearForm("#user-login-form");
-          decorateMenuWithKarma(user);
+      }
+      if (logged == true) {
+        var user = mapUser(result.user);
+        $.log("user.passwordChangeRequired:"+user.passwordChangeRequired());
+        if (user.passwordChangeRequired()==true){
+          changePasswordBox(true,false,user);
           return;
         }
-        $("#modal-login-err-message").html($.i18n.prop("incorrect.username.password"));
-        $("#modal-login-err-message").show();
-      },
-      error: function(result) {
-       var obj = jQuery.parseJSON(result.responseText);
-       displayRedbackError(obj);
-      },
-      complete: function(){
-        $("#modal-login-ok").removeAttr("disabled");
-        $("#login-spinner").remove();
+        // not really needed as an exception is returned but "ceintures et bretelles" as
we said in French :-)
+        if (user.locked()==true){
+          $.log("user locked");
+          displayErrorMessage($.i18n.prop("accout.locked"));
+          return
+        }
+        // FIXME check validated
+        reccordLoginCookie(user);
+        $("#login-link").hide();
+        $("#logout-link").show();
+        $("#register-link").hide();
+        $("#change-password-link").show();
+        window.modalLoginWindow.modal('hide');
+        clearForm("#user-login-form");
+        decorateMenuWithKarma(user);
+        return;
       }
+      $("#modal-login-err-message").html($.i18n.prop("incorrect.username.password"));
+      $("#modal-login-err-message").show();
+    }
+
+    var errorCallbackFn= function(result) {
+     var obj = jQuery.parseJSON(result.responseText);
+     displayRedbackError(obj);
+    }
+
+    var completeCallbackFn=function(){
+      $("#modal-login-ok").removeAttr("disabled");
+      $("#login-spinner").remove();
+    }
+
+    loginCall($("#user-login-form-username").val(),$("#user-login-form-password").val()
+        ,successCallbackFn,errorCallbackFn,completeCallbackFn);
+
+
+
+  }
+
+  loginCall=function(username,password,successCallbackFn, errorCallbackFn, completeCallbackFn)
{
+    var url = 'restServices/redbackServices/loginService/logIn?userName='+username;
+    url += "&password="+password;
+
+    $.ajax({
+      url: url,
+      success: successCallbackFn,
+      error: errorCallbackFn,
+      complete: completeCallbackFn
     });
 
   }



Mime
View raw message