You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2011/12/09 15:50:26 UTC

svn commit: r1212454 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp: index.html js/archiva/main.js js/archiva/templates/topbar.html js/archiva/utils.js js/redback/redback.js js/redback/register.js js/redback/user.js

Author: olamy
Date: Fri Dec  9 14:50:26 2011
New Revision: 1212454

URL: http://svn.apache.org/viewvc?rev=1212454&view=rev
Log:
improve a bit js loading, move more function to utils.js

Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/topbar.html
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/register.js
    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/index.html
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html?rev=1212454&r1=1212453&r2=1212454&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html Fri Dec  9 14:50:26 2011
@@ -2,7 +2,7 @@
 <html>
 <head>
   <link rel="stylesheet" href="css/aristo.css"/>
-    <link rel="stylesheet" href="css/bootstrap.min.1.4.0.css">
+  <link rel="stylesheet" href="css/bootstrap.min.1.4.0.css">
 
   <script type="text/javascript" src="js/jquery-1.7.js"></script>
 
@@ -41,18 +41,17 @@
       });
     $LAB.setGlobalDefaults({AlwaysPreserveOrder:true,BasePath:"js/",explicit_preloading:false});
     $LAB
-       .script("archiva/utils.js").wait()
        .script("jquery.tmpl.js").wait()
+       .script("archiva/utils.js").wait()
+       .script("jquery.i18n.properties-1.0.9.js").wait()
+       .script("redback/i18nload.js").wait()
+       .script("archiva/main-tmpl.js").wait()
        .script("jquery.cookie.1.0.0.js").wait()
        .script("knockout-debug.js").wait()
        .script("jquery-ui-1.8.16.custom.min.js").wait()
-       .script("redback/register.js").wait()
-       .script("jquery.i18n.properties-1.0.9.js").wait()
-       .script("redback/i18nload.js").wait()
        .script("jquery.validate.js").wait()
        .script("jquery.json-2.3.min.js").wait()
        .script("redback/operation.js").wait()
-       .script("archiva/main-tmpl.js").wait()
        .script("redback/redback-tmpl.js").wait()
        .script("bootstrap-modal.js").wait()
        .script("bootstrap-alerts.js").wait()
@@ -60,6 +59,8 @@
        .script("knockout.simpleGrid.js").wait()
        .script("redback/user.js").wait()
        .script("redback/users.js").wait()
+       .script("redback/redback.js").wait()
+       .script("redback/register.js").wait()
        .script("archiva/main.js");
 
 </script>

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js?rev=1212454&r1=1212453&r2=1212454&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js Fri Dec  9 14:50:26 2011
@@ -19,216 +19,162 @@
 require( ["order!jquery" ,"order!redback/redback"],
 function($) {
 
-  $(function() {
+$(function() {
 
-    //$LAB.script("main-tmpl.js").wait(function(){
-      $.log("main karma");
-      customShowError=function(validator, errorMap, errorList) {
-        $( "div.clearfix" ).removeClass( "error" );
-        $( "span.help-inline" ).remove();
-        for ( var i = 0; errorList[i]; i++ ) {
-          var error = errorList[i];
-          var field = $("#"+error.element.id);
-          field.parents( "div.clearfix" ).addClass( "error" );
-          field.parent().append( "<span class=\"help-inline\">" + error.message + "</span>" )
-        }
-      }
-
-      /**
-       * return a user see user.js if user logged otherwise null
-       */
-      userLogged=function() {
-        // call restServices/redbackServices/loginService/isLogged to know
-        // if a session exists and check the cookie
-        var userLogged = true;
-        $.ajax("restServices/redbackServices/loginService/isLogged", {
-          type: "GET",
-          async: false,
-          success: function(data) {
-            userLogged = JSON.parse(data);
-          }
-        });
-        if (userLogged == false)
-        {
-          return null;
-        }
-        return jQuery.parseJSON($.cookie('redback_login'));
-      }
-
-      /**
-       * reccord a cookie for session with the logged user
-       * @param user see user.js
-       */
-      reccordLoginCookie=function(user) {
-        $.cookie('redback_login', ko.toJSON(user));
-      }
 
-      getUserFromLoginCookie=function(){
-        return $.parseJSON($.cookie('redback_login'));
-      }
 
-      deleteLoginCookie=function(){
-        $.cookie('redback_login', null);
+  $.log("main karma");
+  customShowError=function(validator, errorMap, errorList) {
+    $( "div.clearfix" ).removeClass( "error" );
+    $( "span.help-inline" ).remove();
+    for ( var i = 0; errorList[i]; i++ ) {
+      var error = errorList[i];
+      var field = $("#"+error.element.id);
+      field.parents( "div.clearfix" ).addClass( "error" );
+      field.parent().append( "<span class=\"help-inline\">" + error.message + "</span>" )
+    }
+  }
+
+  /**
+   * return a user see user.js if user logged otherwise null
+   */
+  userLogged=function() {
+    // call restServices/redbackServices/loginService/isLogged to know
+    // if a session exists and check the cookie
+    var userLogged = true;
+    $.ajax("restServices/redbackServices/loginService/isLogged", {
+      type: "GET",
+      async: false,
+      success: function(data) {
+        userLogged = JSON.parse(data);
       }
+    });
+    if (userLogged == false)
+    {
+      return null;
+    }
+    return jQuery.parseJSON($.cookie('redback_login'));
+  }
+
+  /**
+   * reccord a cookie for session with the logged user
+   * @param user see user.js
+   */
+  reccordLoginCookie=function(user) {
+    $.cookie('redback_login', ko.toJSON(user));
+  }
+
+  getUserFromLoginCookie=function(){
+    return $.parseJSON($.cookie('redback_login'));
+  }
+
+  deleteLoginCookie=function(){
+    $.cookie('redback_login', null);
+  }
+
+  logout=function(){
+    deleteLoginCookie();
+    $("#login-link").show();
+    $("#register-link").show();
+    $("#logout-link").hide();
+    $("#change-password-link").hide();
+    hideElementWithKarma();
+    screenChange();
+    $("#main-content").html("");
+    $.ajax({
+      url: 'restServices/redbackServices/loginService/logout'
+    });
+  }
 
-      logout=function(){
-        deleteLoginCookie();
-        $("#login-link").show();
-        $("#register-link").show();
-        $("#logout-link").hide();
-        $("#change-password-link").hide();
-        hideElementWithKarma();
-        screenChange();
-        $("#main-content").html("");
-        $.ajax({
-          url: 'restServices/redbackServices/loginService/logout'
-        });
-      }
+  decorateMenuWithKarma=function(user) {
+      var username = user.username;
+      // we can receive an observable user so take if it's a function or not
+      if ($.isFunction(username)){
+        username = user.username();
+      }
+      var url = 'restServices/redbackServices/userService/getCurrentUserOperations';
+      $.ajax({
+        url: url,
+        success: function(data){
+          var mappedOperations = $.map(data.operation, function(item) {
+              return mapOperation(item);
+          });
+          window.redbackModel.operatioNames = $.map(mappedOperations, function(item){
+            return item.name;
+          });
 
-      decorateMenuWithKarma=function(user) {
-          var username = user.username;
-          // we can receive an observable user so take if it's a function or not
-          if ($.isFunction(username)){
-            username = user.username();
-          }
-          var url = 'restServices/redbackServices/userService/getCurrentUserOperations';
-          $.ajax({
-            url: url,
-            success: function(data){
-              var mappedOperations = $.map(data.operation, function(item) {
-                  return mapOperation(item);
-              });
-              window.redbackModel.operatioNames = $.map(mappedOperations, function(item){
-                return item.name;
-              });
-
-              $("[redback-permissions]").each(function(element){
-                var bindingValue = $(this).attr("redback-permissions");
-                $(this).hide();
-                var neededKarmas = $(eval(bindingValue)).toArray();
-                var karmaOk = false;
-                $(neededKarmas).each(function(value){
-                  //alert(neededKarmas[value]);
-                  if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) {
-                    karmaOk = true;
-                  }
-                });
-                if (karmaOk == false) {
-                  $(this).hide();
-                } else {
-                  $(this).show();
-                }
-              });
+          $("[redback-permissions]").each(function(element){
+            var bindingValue = $(this).attr("redback-permissions");
+            $(this).hide();
+            var neededKarmas = $(eval(bindingValue)).toArray();
+            var karmaOk = false;
+            $(neededKarmas).each(function(value){
+              //alert(neededKarmas[value]);
+              if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) {
+                karmaOk = true;
+              }
+            });
+            if (karmaOk == false) {
+              $(this).hide();
+            } else {
+              $(this).show();
             }
           });
         }
+      });
+    }
 
-      hideElementWithKarma=function(){
-        $("[redback-permissions]").each(function(element){
-          $(this).hide();
-        });
-      }
-
+  hideElementWithKarma=function(){
+    $("[redback-permissions]").each(function(element){
+      $(this).hide();
+    });
+  }
 
-      $('#topbar-menu-container').html($("#topbar-menu"));
-      $('#sidebar-content').html($("#main-menu"));
 
-      checkCreateAdminLink=function(){
-        $.ajax("restServices/redbackServices/userService/isAdminUserExists", {
-          type: "GET",
-          dataType: 'json',
-          success: function(data) {
-            var adminExists = JSON.parse(data);
-            if (adminExists == false) {
-              $("#create-admin-link").show();
-            } else {
-              $("#create-admin-link").hide();
-            }
-          }
-        });
-      }
 
-      checkCreateAdminLink();
-      hideElementWithKarma();
 
-      checkSecurityLinks=function(){
-        var user = userLogged();
-        $.log("checkSecurityLinks, user:"+user);
-
-        if (!user) {
-          $("#login-link").show();
-          $("#register-link").show();
-          $("#change-password-link").hide();
+  checkCreateAdminLink=function(){
+    $.ajax("restServices/redbackServices/userService/isAdminUserExists", {
+      type: "GET",
+      dataType: 'json',
+      success: function(data) {
+        var adminExists = JSON.parse(data);
+        if (adminExists == false) {
+          $("#create-admin-link").show();
         } else {
-          $("#change-password-link").show();
-          $("#logout-link").show();
-          $("#register-link").hide();
-          $("#login-link").hide();
-          decorateMenuWithKarma(user);
+          $("#create-admin-link").hide();
         }
       }
+    });
+  }
 
-      checkSecurityLinks();
-
-
-      /**
-       * display a success message
-       * @param text the success text
-       * @param idToAppend the id to append the success box
-       */
-      displaySuccessMessage=function(text,idToAppend){
-        var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
-        $.tmpl($("#alert-message-success").html(), { "message" : text }).appendTo( textId );
-        $(textId).focus();
-      }
-
-      clearUserMessages=function(idToAppend){
-        var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
-        $(textId).html('');
-      }
-
-      /**
-       * display an error message
-       * @param text the success text
-       * @param idToAppend the id to append the success box
-       */
-      displayErrorMessage=function(text,idToAppend){
-        var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
-        $.tmpl($("#alert-message-error").html(), { "message" : text }).appendTo( textId );
-        $(textId).focus();
-      }
+  checkSecurityLinks=function(){
+    var user = userLogged();
+    $.log("checkSecurityLinks, user:"+user);
+
+    if (!user) {
+      $("#login-link").show();
+      $("#register-link").show();
+      $("#change-password-link").hide();
+    } else {
+      $("#change-password-link").show();
+      $("#logout-link").show();
+      $("#register-link").hide();
+      $("#login-link").hide();
+      decorateMenuWithKarma(user);
+    }
+  }
 
-      /**
-       * display a warning message
-       * @param text the success text
-       * @param idToAppend the id to append the success box
-       */
-      displayWarningMessage=function(text,idToAppend){
-        var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
-        $.tmpl($("#alert-message-warning").html(), { "message" : text }).appendTo( textId );
-        $(textId).focus();
-      }
 
-      screenChange=function(){
-        $("#main-content").html("");
-        clearUserMessages();
-      }
 
-      /**
-       * clear all input text and password found in the the selector
-       * @param selectorStr
-       */
-      clearForm=function(selectorStr){
-        $(selectorStr+" input[type='text']").each(function(ele){
-          $(this).val("");
-        });
-        $(selectorStr+" input[type='password']").each(function(ele){
-          $(this).val("");
-        });
 
-      }
-    });
-  //});
+    $.log("main.js dom ready");
+    $('#topbar-menu-container').html($("#topbar-menu"));
+    $('#sidebar-content').html($("#main-menu"));
+    checkCreateAdminLink();
+    hideElementWithKarma();
+    checkSecurityLinks();
 
+})
 });
 

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/topbar.html
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/topbar.html?rev=1212454&r1=1212453&r2=1212454&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/topbar.html (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/topbar.html Fri Dec  9 14:50:26 2011
@@ -3,7 +3,7 @@
 <div class="topbar" data-dropdown="dropdown">
   <div class="topbar-inner">
     <div class="container-fluid">
-      <h4 class="brand"><a href="/index.html">Archiva</a></h4>
+      <h4 class="brand"><a href="index.html">Archiva</a></h4>
       <ul class="nav secondary-nav">
         <li id="create-admin-link" style="display: none">
           <a href="#" onclick="adminCreateBox();">Admin User Creation</a>

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js?rev=1212454&r1=1212453&r2=1212454&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js Fri Dec  9 14:50:26 2011
@@ -30,4 +30,61 @@ $.urlParam = function(name){
       return results[1] || 0;
     }
     return null;
+}
+
+/**
+ * display a success message
+ * @param text the success text
+ * @param idToAppend the id to append the success box
+ */
+displaySuccessMessage=function(text,idToAppend){
+  var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
+  $.tmpl($("#alert-message-success").html(), { "message" : text }).appendTo( textId );
+  $(textId).focus();
+}
+
+/**
+ * display an error message
+ * @param text the success text
+ * @param idToAppend the id to append the success box
+ */
+displayErrorMessage=function(text,idToAppend){
+  var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
+  $.tmpl($("#alert-message-error").html(), { "message" : text }).appendTo( textId );
+  $(textId).focus();
+}
+
+/**
+ * display a warning message
+ * @param text the success text
+ * @param idToAppend the id to append the success box
+ */
+displayWarningMessage=function(text,idToAppend){
+  var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
+  $.tmpl($("#alert-message-warning").html(), { "message" : text }).appendTo( textId );
+  $(textId).focus();
+}
+
+screenChange=function(){
+  $("#main-content").html("");
+  clearUserMessages();
+}
+
+clearUserMessages=function(idToAppend){
+  var textId = idToAppend ? $("#"+idToAppend) : $("#user-messages");
+  $(textId).html('');
+}
+
+/**
+ * clear all input text and password found in the the selector
+ * @param selectorStr
+ */
+clearForm=function(selectorStr){
+  $(selectorStr+" input[type='text']").each(function(ele){
+    $(this).val("");
+  });
+  $(selectorStr+" input[type='password']").each(function(ele){
+    $(this).val("");
+  });
+
 }
\ No newline at end of file

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js?rev=1212454&r1=1212453&r2=1212454&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js Fri Dec  9 14:50:26 2011
@@ -25,12 +25,15 @@ $(function() {
   displayRedbackError=function(obj,idToAppend) {
     // {"redbackRestError":{"errorMessages":{"args":1,"errorKey":"user.password.violation.numeric"}}}
     if ($.isArray(obj.redbackRestError.errorMessages)) {
+      $.log("displayRedbackError with array");
       for(var i=0; i<obj.redbackRestError.errorMessages.length; i++ ) {
         if(obj.redbackRestError.errorMessages[i].errorKey) {
+          $.log("displayRedbackError with array loop");
           displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages[i].errorKey, obj.redbackRestError.errorMessages[i].args ),idToAppend);
         }
       }
     } else {
+      $.log("displayRedbackError no array");
       displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages.errorKey, obj.redbackRestError.errorMessages.args ),idToAppend);
     }
   }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/register.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/register.js?rev=1212454&r1=1212453&r2=1212454&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/register.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/register.js Fri Dec  9 14:50:26 2011
@@ -90,19 +90,22 @@ $(function() {
    * @param key
    */
   validateKey=function(key) {
-    // spinner display
+    // FIXME spinner display
     $.ajax({
       url: 'restServices/redbackServices/userService/validateKey/'+key,
       type: 'GET',
        success: function(result){
          window.redbackModel.key=key;
+         $.log("validateKey#sucess");
          changePasswordBox(false,true);
        },
        complete: function(){
          // hide spinner
        },
        error: function(result) {
+         $.log("validateKey#error");
          var obj = jQuery.parseJSON(result.responseText);
+         $.log("validateKey#error response:"+obj);
          displayRedbackError(obj);
        }
     })

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=1212454&r1=1212453&r2=1212454&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:50:26 2011
@@ -103,7 +103,7 @@ $(function() {
       };
 
       this.deleteUser=function() {
-        screenChange();
+        clearUserMessages();
         // FIXME i18n
         var currentUser = this;
         openDialogConfirm(function(){
@@ -212,6 +212,7 @@ $(function() {
   }
 
   login=function(){
+    $("#modal-login-err-message").html("");
     screenChange();
     var valid = $("#user-login-form").valid();
     if (!valid) {
@@ -264,7 +265,8 @@ $(function() {
 
     var errorCallbackFn= function(result) {
      var obj = jQuery.parseJSON(result.responseText);
-     displayRedbackError(obj);
+     displayRedbackError(obj,"modal-login-err-message");
+     $("#modal-login-err-message").show();
     }
 
     var completeCallbackFn=function(){
@@ -299,6 +301,7 @@ $(function() {
    */
   changePasswordBox=function(previousPassword,registration,user){
     screenChange();
+    $.log("changePasswordBox previousPassword:"+previousPassword+",registration:"+registration+",user:"+user);
     if (previousPassword==true){
       $("#password-change-form-current-password-div").show();
       $("#password-change-form-current-password").addClass("required");