improve a bit js loading, move more function to utils.js

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1212454 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-12-09 14:50:26 +00:00
parent 9df8caaadd
commit cd96001a38
7 changed files with 216 additions and 203 deletions

View File

@ -41,18 +41,17 @@
}); });
$LAB.setGlobalDefaults({AlwaysPreserveOrder:true,BasePath:"js/",explicit_preloading:false}); $LAB.setGlobalDefaults({AlwaysPreserveOrder:true,BasePath:"js/",explicit_preloading:false});
$LAB $LAB
.script("archiva/utils.js").wait()
.script("jquery.tmpl.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("jquery.cookie.1.0.0.js").wait()
.script("knockout-debug.js").wait() .script("knockout-debug.js").wait()
.script("jquery-ui-1.8.16.custom.min.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.validate.js").wait()
.script("jquery.json-2.3.min.js").wait() .script("jquery.json-2.3.min.js").wait()
.script("redback/operation.js").wait() .script("redback/operation.js").wait()
.script("archiva/main-tmpl.js").wait()
.script("redback/redback-tmpl.js").wait() .script("redback/redback-tmpl.js").wait()
.script("bootstrap-modal.js").wait() .script("bootstrap-modal.js").wait()
.script("bootstrap-alerts.js").wait() .script("bootstrap-alerts.js").wait()
@ -60,6 +59,8 @@
.script("knockout.simpleGrid.js").wait() .script("knockout.simpleGrid.js").wait()
.script("redback/user.js").wait() .script("redback/user.js").wait()
.script("redback/users.js").wait() .script("redback/users.js").wait()
.script("redback/redback.js").wait()
.script("redback/register.js").wait()
.script("archiva/main.js"); .script("archiva/main.js");
</script> </script>

View File

@ -19,9 +19,10 @@
require( ["order!jquery" ,"order!redback/redback"], require( ["order!jquery" ,"order!redback/redback"],
function($) { function($) {
$(function() { $(function() {
//$LAB.script("main-tmpl.js").wait(function(){
$.log("main karma"); $.log("main karma");
customShowError=function(validator, errorMap, errorList) { customShowError=function(validator, errorMap, errorList) {
$( "div.clearfix" ).removeClass( "error" ); $( "div.clearfix" ).removeClass( "error" );
@ -130,8 +131,7 @@ function($) {
} }
$('#topbar-menu-container').html($("#topbar-menu"));
$('#sidebar-content').html($("#main-menu"));
checkCreateAdminLink=function(){ checkCreateAdminLink=function(){
$.ajax("restServices/redbackServices/userService/isAdminUserExists", { $.ajax("restServices/redbackServices/userService/isAdminUserExists", {
@ -148,9 +148,6 @@ function($) {
}); });
} }
checkCreateAdminLink();
hideElementWithKarma();
checkSecurityLinks=function(){ checkSecurityLinks=function(){
var user = userLogged(); var user = userLogged();
$.log("checkSecurityLinks, user:"+user); $.log("checkSecurityLinks, user:"+user);
@ -168,67 +165,16 @@ function($) {
} }
} }
$.log("main.js dom ready");
$('#topbar-menu-container').html($("#topbar-menu"));
$('#sidebar-content').html($("#main-menu"));
checkCreateAdminLink();
hideElementWithKarma();
checkSecurityLinks(); 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();
}
/**
* 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("");
});
}
});
//});
}); });

View File

@ -3,7 +3,7 @@
<div class="topbar" data-dropdown="dropdown"> <div class="topbar" data-dropdown="dropdown">
<div class="topbar-inner"> <div class="topbar-inner">
<div class="container-fluid"> <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"> <ul class="nav secondary-nav">
<li id="create-admin-link" style="display: none"> <li id="create-admin-link" style="display: none">
<a href="#" onclick="adminCreateBox();">Admin User Creation</a> <a href="#" onclick="adminCreateBox();">Admin User Creation</a>

View File

@ -31,3 +31,60 @@ $.urlParam = function(name){
} }
return null; 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("");
});
}

View File

@ -25,12 +25,15 @@ $(function() {
displayRedbackError=function(obj,idToAppend) { displayRedbackError=function(obj,idToAppend) {
// {"redbackRestError":{"errorMessages":{"args":1,"errorKey":"user.password.violation.numeric"}}} // {"redbackRestError":{"errorMessages":{"args":1,"errorKey":"user.password.violation.numeric"}}}
if ($.isArray(obj.redbackRestError.errorMessages)) { if ($.isArray(obj.redbackRestError.errorMessages)) {
$.log("displayRedbackError with array");
for(var i=0; i<obj.redbackRestError.errorMessages.length; i++ ) { for(var i=0; i<obj.redbackRestError.errorMessages.length; i++ ) {
if(obj.redbackRestError.errorMessages[i].errorKey) { 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); displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages[i].errorKey, obj.redbackRestError.errorMessages[i].args ),idToAppend);
} }
} }
} else { } else {
$.log("displayRedbackError no array");
displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages.errorKey, obj.redbackRestError.errorMessages.args ),idToAppend); displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages.errorKey, obj.redbackRestError.errorMessages.args ),idToAppend);
} }
} }

View File

@ -90,19 +90,22 @@ $(function() {
* @param key * @param key
*/ */
validateKey=function(key) { validateKey=function(key) {
// spinner display // FIXME spinner display
$.ajax({ $.ajax({
url: 'restServices/redbackServices/userService/validateKey/'+key, url: 'restServices/redbackServices/userService/validateKey/'+key,
type: 'GET', type: 'GET',
success: function(result){ success: function(result){
window.redbackModel.key=key; window.redbackModel.key=key;
$.log("validateKey#sucess");
changePasswordBox(false,true); changePasswordBox(false,true);
}, },
complete: function(){ complete: function(){
// hide spinner // hide spinner
}, },
error: function(result) { error: function(result) {
$.log("validateKey#error");
var obj = jQuery.parseJSON(result.responseText); var obj = jQuery.parseJSON(result.responseText);
$.log("validateKey#error response:"+obj);
displayRedbackError(obj); displayRedbackError(obj);
} }
}) })

View File

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