From: Olivier Lamy Date: Mon, 23 Jan 2012 16:22:01 +0000 (+0000) Subject: use a callback pattern with non blocking call to check admin exists and menu entries... X-Git-Tag: archiva-1.4-M3~1499 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5475f8d4f908d63325dab57cb41a9df99c122f2b;p=archiva.git use a callback pattern with non blocking call to check admin exists and menu entries needed karmas git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1234883 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js index 50240e282..c52b5bf31 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js @@ -114,11 +114,8 @@ $(function() { $.log("hideElementWithKarma"); } - - checkSecurityLinks=function(){ - $.log("checkSecurityLinks"); - var user = userLogged(); - $.log("checkSecurityLinks, user:"+user); + userLoggedCallbackFn=function(user){ + $.log("userLoggedCallbackFn:"+ (user?user.username:null)); if (!user) { $("#login-link").show(); @@ -133,11 +130,14 @@ $(function() { } } + checkSecurityLinks=function(){ + userLogged(userLoggedCallbackFn); + } + checkCreateAdminLink=function(){ $.ajax("restServices/redbackServices/userService/isAdminUserExists", { type: "GET", dataType: 'json', - async: false, success: function(data) { var adminExists = JSON.parse(data); if (adminExists == false) { @@ -165,9 +165,9 @@ $(function() { $('#topbar-menu-container').html($("#topbar-menu")); $('#sidebar-content').html($("#main-menu")); - checkCreateAdminLink(); hideElementWithKarma(); checkSecurityLinks(); + checkCreateAdminLink(); } startArchivaApplication(); }) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js index 1f80baa21..186ddec26 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js @@ -32,25 +32,22 @@ $(function() { }); /** - * return a user see user.js if user logged otherwise null + * call successFn on success with passing user object coming from cookie */ - userLogged=function() { + userLogged=function(successFn) { // call restServices/redbackServices/loginService/isLogged to know // if a session exists and check the cookie $.log("userLogged"); var userLogged = true; $.ajax("restServices/redbackServices/loginService/isLogged", { type: "GET", - async: false, success: function(data) { userLogged = JSON.parse(data); + if (successFn){ + successFn(userLogged == false ? null : jQuery.parseJSON($.cookie('redback_login'))); + } } }); - if (userLogged == false) - { - return null; - } - return jQuery.parseJSON($.cookie('redback_login')); } }); \ No newline at end of file