fix jquery issues reported by idea

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1376878 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-08-24 09:59:56 +00:00
parent 8ffeff592c
commit d3926adc7d
2 changed files with 57 additions and 57 deletions

View File

@ -19,22 +19,22 @@
appendArchivaVersion=function(){ appendArchivaVersion=function(){
return "_archivaVersion="+window.archivaRuntimeInfo.version; return "_archivaVersion="+window.archivaRuntimeInfo.version;
} };
timestampNoCache=function(){ timestampNoCache=function(){
if (window.archivaRuntimeInfo.version.match("SNAPSHOT$")){ if (window.archivaRuntimeInfo.version.match("SNAPSHOT$")){
return "&archivaTimestamp="+window.archivaRuntimeInfo.timestamp+(window.archivaRuntimeInfo.devMode?"&_="+jQuery.now():""); return "&archivaTimestamp="+window.archivaRuntimeInfo.timestamp+(window.archivaRuntimeInfo.devMode?"&_="+jQuery.now():"");
} }
return ""; return "";
} };
appendTemplateUrl=function(){ appendTemplateUrl=function(){
return appendArchivaVersion()+timestampNoCache(); return appendArchivaVersion()+timestampNoCache();
} };
appendJsNoCacheUrl=function(){ appendJsNoCacheUrl=function(){
return appendArchivaVersion()+timestampNoCache(); return appendArchivaVersion()+timestampNoCache();
} };
$.ajax({ $.ajax({
url: "restServices/archivaUiServices/runtimeInfoService/archivaRuntimeInfo/en", url: "restServices/archivaUiServices/runtimeInfoService/archivaRuntimeInfo/en",
@ -117,4 +117,4 @@ $.ajax({
}); });
}) })
} }
}) });

View File

@ -28,15 +28,15 @@ function(jquery,ui,sammy,tmpl) {
*/ */
reccordLoginCookie=function(user) { reccordLoginCookie=function(user) {
$.cookie('redback_login', ko.toJSON(user)); $.cookie('redback_login', ko.toJSON(user));
} };
getUserFromLoginCookie=function(){ getUserFromLoginCookie=function(){
return $.parseJSON($.cookie('redback_login')); return $.parseJSON($.cookie('redback_login'));
} };
deleteLoginCookie=function(){ deleteLoginCookie=function(){
$.cookie('redback_login', null); $.cookie('redback_login', null);
} };
logout=function(doScreenChange){ logout=function(doScreenChange){
deleteLoginCookie(); deleteLoginCookie();
@ -50,7 +50,7 @@ function(jquery,ui,sammy,tmpl) {
$.ajax({ $.ajax({
url: 'restServices/redbackServices/loginService/logout' url: 'restServices/redbackServices/loginService/logout'
}); });
} };
@ -75,13 +75,13 @@ function(jquery,ui,sammy,tmpl) {
$("#topbar-menu-container").find("[redback-permissions]").each(function(element){ $("#topbar-menu-container").find("[redback-permissions]").each(function(element){
checkElementKarma(this); checkElementKarma(this);
}); });
$("#sidebar-content [redback-permissions]").each(function(element){ $("#sidebar-content").find("[redback-permissions]").each(function(element){
checkElementKarma(this); checkElementKarma(this);
}); });
checkUrlParams(); checkUrlParams();
} }
}); });
} };
checkElementKarma=function(element){ checkElementKarma=function(element){
var bindingValue = $(element).attr("redback-permissions"); var bindingValue = $(element).attr("redback-permissions");
@ -98,7 +98,7 @@ function(jquery,ui,sammy,tmpl) {
} else { } else {
$(element).show(); $(element).show();
} }
} };
hideElementWithKarma=function(){ hideElementWithKarma=function(){
$("#topbar-menu-container [redback-permissions]").each(function(element){ $("#topbar-menu-container [redback-permissions]").each(function(element){
@ -109,7 +109,7 @@ function(jquery,ui,sammy,tmpl) {
$(this).hide(); $(this).hide();
}); });
$.log("hideElementWithKarma"); $.log("hideElementWithKarma");
} };
//------------------------------------// //------------------------------------//
// Change UI with appearance settings // // Change UI with appearance settings //
@ -119,31 +119,32 @@ function(jquery,ui,sammy,tmpl) {
type: "GET", type: "GET",
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
if(data.url){ var organisationLogo=$("#organisation-logo");
var url = data.url.startsWith("http://") || data.url.startsWith("https://") ? data.url : "http://"+data.url; if(data.url){
var link="<a href='"+url+"' class='brand'>"; var url = data.url.startsWith("http://") || data.url.startsWith("https://") ? data.url : "http://"+data.url;
if (data.logoLocation) { var link="<a href='"+url+"' class='brand'>";
link+="<img src='"+data.logoLocation+"' style='max-height: 30px'/>"; if (data.logoLocation) {
} else if (data.name) { link+="<img src='"+data.logoLocation+"' style='max-height: 30px'/>";
link+=data.name; } else if (data.name) {
} else { link+=data.name;
link+="Archiva"; } else {
} link+="Archiva";
link+="</a>";
$("#organisation-logo").html(link);
} }
link+="</a>";
organisationLogo.html(link);
}
if (!data.url && data.name){ if (!data.url && data.name){
$("#organisation-logo").html("<a href='/' class='brand'>"+data.name+"</a>"); organisationLogo.html("<a href='/' class='brand'>"+data.name+"</a>");
} }
if (!data.url && !data.name){ if (!data.url && !data.name){
$("#organisation-logo").html("<a href='/' class='brand'>Archiva</a>"); organisationLogo.html("<a href='/' class='brand'>Archiva</a>");
} }
}, },
error: function() { error: function() {
$("#organisation-logo").html("<a href='/' class='brand'>Archiva</a>"); organisationLogo.html("<a href='/' class='brand'>Archiva</a>");
} }
}); });
} };
MainMenuViewModel=function() { MainMenuViewModel=function() {
@ -274,7 +275,7 @@ function(jquery,ui,sammy,tmpl) {
searchViewModel.search("restServices/archivaServices/searchService/searchArtifacts",repos);//,repositoryIds); searchViewModel.search("restServices/archivaServices/searchService/searchArtifacts",repos);//,repositoryIds);
},searchViewModel); },searchViewModel);
} };
this.get("#advancedsearch/:queryterms",function(){ this.get("#advancedsearch/:queryterms",function(){
advancedSearchRoute(this.params); advancedSearchRoute(this.params);
@ -298,8 +299,6 @@ function(jquery,ui,sammy,tmpl) {
var artifactId= this.params.artifactId; var artifactId= this.params.artifactId;
$.log("get #artifact:"+groupId+":"+artifactId); $.log("get #artifact:"+groupId+":"+artifactId);
goToBrowseArtifactDetail(groupId,artifactId);//,null,null); goToBrowseArtifactDetail(groupId,artifactId);//,null,null);
return;
}); });
this.get('#artifact~:repositoryId/:groupId/:artifactId',function(context){ this.get('#artifact~:repositoryId/:groupId/:artifactId',function(context){
var groupId= this.params.groupId; var groupId= this.params.groupId;
@ -307,7 +306,6 @@ function(jquery,ui,sammy,tmpl) {
var repositoryId = this.params.repositoryId; var repositoryId = this.params.repositoryId;
$.log("get #artifact:"+groupId+":"+artifactId); $.log("get #artifact:"+groupId+":"+artifactId);
goToBrowseArtifactDetail(groupId,artifactId,repositoryId);//,null,null); goToBrowseArtifactDetail(groupId,artifactId,repositoryId);//,null,null);
return;
}); });
var checkArtifactDetailContent=function(groupId,artifactId,version,repositoryId,tabToActivate,idContentToCheck,contentDisplayFn){ var checkArtifactDetailContent=function(groupId,artifactId,version,repositoryId,tabToActivate,idContentToCheck,contentDisplayFn){
@ -316,19 +314,19 @@ function(jquery,ui,sammy,tmpl) {
var htmlIdSelect = $("#main-content #"+htmlId ); var htmlIdSelect = $("#main-content #"+htmlId );
if(htmlIdSelect.html()!=null){ if(htmlIdSelect.html()!=null){
if( $.trim(htmlIdSelect.html().length)>0){ if( $.trim(htmlIdSelect.html().length)>0){
$("#main-content #"+tabToActivate).tab('show') $("#main-content #"+tabToActivate).tab('show');
return; return;
} }
} }
generalDisplayArtifactDetailsVersionView(groupId,artifactId,version,repositoryId, generalDisplayArtifactDetailsVersionView(groupId,artifactId,version,repositoryId,
function(artifactVersionDetailViewModel){ function(artifactVersionDetailViewModel){
$("#main-content #"+tabToActivate).tab('show') $("#main-content #"+tabToActivate).tab('show');
if(contentDisplayFn){ if(contentDisplayFn){
contentDisplayFn(groupId,artifactId,version,artifactVersionDetailViewModel); contentDisplayFn(groupId,artifactId,version,artifactVersionDetailViewModel);
} }
} }
); );
} };
this.get('#artifact/:groupId/:artifactId/:version',function(context){ this.get('#artifact/:groupId/:artifactId/:version',function(context){
@ -388,7 +386,7 @@ function(jquery,ui,sammy,tmpl) {
var calculateUsedBy=function(groupId,artifactId,version){ var calculateUsedBy=function(groupId,artifactId,version){
var dependeesContentDiv=$("#main-content #artifact-details-used-by-content" ); var dependeesContentDiv=$("#main-content" ).find("#artifact-details-used-by-content" );
if( $.trim(dependeesContentDiv.html()).length<1){ if( $.trim(dependeesContentDiv.html()).length<1){
dependeesContentDiv.html(mediumSpinnerImg()); dependeesContentDiv.html(mediumSpinnerImg());
var dependeesUrl="restServices/archivaServices/browseService/dependees/"+encodeURIComponent(groupId); var dependeesUrl="restServices/archivaServices/browseService/dependees/"+encodeURIComponent(groupId);
@ -407,7 +405,7 @@ function(jquery,ui,sammy,tmpl) {
} }
}); });
} }
} };
this.get('#artifact-used-by/:groupId/:artifactId/:version',function(context){ this.get('#artifact-used-by/:groupId/:artifactId/:version',function(context){
@ -429,7 +427,7 @@ function(jquery,ui,sammy,tmpl) {
var calculateMetadatas=function(groupId,artifactId,version,artifactVersionDetailViewModel){ var calculateMetadatas=function(groupId,artifactId,version,artifactVersionDetailViewModel){
var metadatasContentDiv=$("#main-content #artifact-details-metadatas-content" ); var metadatasContentDiv=$("#main-content" ).find("#artifact-details-metadatas-content" );
var metadatasUrl="restServices/archivaServices/browseService/metadatas/"+encodeURIComponent(groupId); var metadatasUrl="restServices/archivaServices/browseService/metadatas/"+encodeURIComponent(groupId);
metadatasUrl+="/"+encodeURIComponent(artifactId); metadatasUrl+="/"+encodeURIComponent(artifactId);
metadatasUrl+="/"+encodeURIComponent(version); metadatasUrl+="/"+encodeURIComponent(version);
@ -450,7 +448,7 @@ function(jquery,ui,sammy,tmpl) {
artifactVersionDetailViewModel.entries(entries); artifactVersionDetailViewModel.entries(entries);
} }
}); });
} };
this.get('#artifact-metadatas/:groupId/:artifactId/:version',function(context){ this.get('#artifact-metadatas/:groupId/:artifactId/:version',function(context){
@ -501,34 +499,35 @@ function(jquery,ui,sammy,tmpl) {
ko.utils.arrayFirst(baseItems.concat(self.usersMenuItems, self.administrationMenuItems), function(p) { ko.utils.arrayFirst(baseItems.concat(self.usersMenuItems, self.administrationMenuItems), function(p) {
if ( p.href == "#"+self.activeMenuId()) { if ( p.href == "#"+self.activeMenuId()) {
p.func(); p.func();
return;
} }
}); });
}); });
//this.get('', function () { this.app.runRoute('get', '#search') }); //this.get('', function () { this.app.runRoute('get', '#search') });
}); });
} };
userLoggedCallbackFn=function(user){ userLoggedCallbackFn=function(user){
$.log("userLoggedCallbackFn:"+ (user?user.username:null)); $.log("userLoggedCallbackFn:"+ (user?user.username:null));
var loginLink=$("#login-link");
var registerLink=$("#register-link");
var changePasswordLink=$("#change-password-link");
if (!user) { if (!user) {
$("#login-link").show(); loginLink.show();
$("#register-link").show(); registerLink.show();
$("#change-password-link").hide(); changePasswordLink.hide();
checkUrlParams(); checkUrlParams();
} else { } else {
$("#change-password-link").show(); changePasswordLink.show();
$("#logout-link").show(); $("#logout-link").show();
$("#register-link").hide(); registerLink.hide();
$("#login-link").hide(); loginLink.hide();
decorateMenuWithKarma(user); decorateMenuWithKarma(user);
} }
} };
checkSecurityLinks=function(){ checkSecurityLinks=function(){
userLogged(userLoggedCallbackFn); userLogged(userLoggedCallbackFn);
} };
checkCreateAdminLink=function(callbackFn){ checkCreateAdminLink=function(callbackFn){
$.ajax("restServices/redbackServices/userService/isAdminUserExists", { $.ajax("restServices/redbackServices/userService/isAdminUserExists", {
@ -536,12 +535,13 @@ function(jquery,ui,sammy,tmpl) {
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
var adminExists = data; var adminExists = data;
var createAdminLink=$("#create-admin-link");
if (adminExists == false) { if (adminExists == false) {
$("#create-admin-link").show(); createAdminLink.show();
$("#login-link").hide(); $("#login-link").hide();
$("#register-link").hide(); $("#register-link").hide();
} else { } else {
$("#create-admin-link").hide(); createAdminLink.hide();
} }
if(callbackFn){ if(callbackFn){
callbackFn() callbackFn()
@ -549,7 +549,7 @@ function(jquery,ui,sammy,tmpl) {
$.log("adminExists:"+adminExists); $.log("adminExists:"+adminExists);
} }
}); });
} };
// handle url with registration link // handle url with registration link
checkUrlParams=function(){ checkUrlParams=function(){
@ -572,11 +572,11 @@ function(jquery,ui,sammy,tmpl) {
window.sammyArchivaApplication.setLocation("#search"); window.sammyArchivaApplication.setLocation("#search");
} }
} };
hasKarma=function(karmaName){ hasKarma=function(karmaName){
return $.inArray(karmaName,window.redbackModel.operatioNames)>=0; return $.inArray(karmaName,window.redbackModel.operatioNames)>=0;
} };
startArchivaApplication=function(){ startArchivaApplication=function(){
@ -603,7 +603,7 @@ function(jquery,ui,sammy,tmpl) {
window.sammyArchivaApplication.run(); window.sammyArchivaApplication.run();
} };
drawQuickSearchAutocomplete=function(){ drawQuickSearchAutocomplete=function(){