From 0ed11d79e90fd8e41a90307a4a43fc4fbc4a34f3 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 7 Feb 2012 18:23:50 +0000 Subject: [PATCH] reuse jquery selector already evaluated when possible git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1241541 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/webapp/js/archiva/network-proxies.js | 34 ++++---- .../webapp/js/archiva/proxy-connectors.js | 66 +++++++++++++--- .../main/webapp/js/archiva/repositories.js | 79 ++++++++++--------- .../js/archiva/templates/repositories.html | 4 +- .../src/main/webapp/js/archiva/utils.js | 14 ++++ 5 files changed, 131 insertions(+), 66 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js index 6c12f773d..10fec2348 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js @@ -127,9 +127,10 @@ $(function() { editNetworkProxy=function(networkProxy){ clearUserMessages(); $.log("editNetworkProxy"); - $("#main-content #network-proxies-view-tabs-li-edit a").html($.i18n.prop("edit")); + var mainContent = $("#main-content"); + mainContent.find("#network-proxies-view-tabs-li-edit a").html($.i18n.prop("edit")); var viewModel = new NetworkProxyViewModel(networkProxy,true,self); - ko.applyBindings(viewModel,$("#main-content #network-proxies-edit").get(0)); + ko.applyBindings(viewModel,mainContent.find("#network-proxies-edit").get(0)); activateNetworkProxyFormValidation(); activateNetworkProxyEditTab(); } @@ -196,13 +197,14 @@ $(function() { displayNetworkProxies=function(){ clearUserMessages(); - $("#main-content").html(mediumSpinnerImg()); - $("#main-content").html($("#networkProxiesMain").tmpl()); - $("#main-content #network-proxies-view-tabs a:first").tab('show'); + var mainContent = $("#main-content"); + mainContent.html(mediumSpinnerImg()); + mainContent.html($("#networkProxiesMain").tmpl()); + mainContent.find("#network-proxies-view-tabs a:first").tab('show'); var networkProxiesViewModel = new NetworkProxiesViewModel(); - $("#main-content #network-proxies-view-tabs").on('show', function (e) { + mainContent.find("#network-proxies-view-tabs").on('show', function (e) { if ($(e.target).attr("href")=="#network-proxies-edit") { var viewModel = new NetworkProxyViewModel(new NetworkProxy(),false,networkProxiesViewModel); ko.applyBindings(viewModel,$("#main-content #network-proxies-edit").get(0)); @@ -276,21 +278,23 @@ $(function() { } activateNetworkProxiesGridTab=function(){ - $("#main-content #network-proxies-view-tabs-li-edit").removeClass("active"); - $("#main-content #network-proxies-edit").removeClass("active"); + var mainContent = $("#main-content"); + mainContent.find("#network-proxies-view-tabs-li-edit").removeClass("active"); + mainContent.find("#network-proxies-edit").removeClass("active"); - $("#main-content #network-proxies-view-tabs-li-grid").addClass("active"); - $("#main-content #network-proxies-view").addClass("active"); - $("#main-content #network-proxies-view-tabs-li-edit a").html($.i18n.prop("add")); + mainContent.find("#network-proxies-view-tabs-li-grid").addClass("active"); + mainContent.find("#network-proxies-view").addClass("active"); + mainContent.find("#network-proxies-view-tabs-li-edit a").html($.i18n.prop("add")); } activateNetworkProxyEditTab=function(){ - $("#main-content #network-proxies-view-tabs-li-grid").removeClass("active"); - $("#main-content #network-proxies-view").removeClass("active"); + var mainContent = $("#main-content"); + mainContent.find("#network-proxies-view-tabs-li-grid").removeClass("active"); + mainContent.find("#network-proxies-view").removeClass("active"); - $("#main-content #network-proxies-view-tabs-li-edit").addClass("active"); - $("#main-content #network-proxies-edit").addClass("active"); + mainContent.find("#network-proxies-view-tabs-li-edit").addClass("active"); + mainContent.find("#network-proxies-edit").addClass("active"); } mapNetworkProxy=function(data){ diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js index 0b0deab0e..6358f0a92 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js @@ -20,45 +20,81 @@ $(function() { ProxyConnector=function(sourceRepoId,targetRepoId,proxyId,blackListPatterns,whiteListPatterns,policies,properties, disabled,order){ + var self=this; + this.modified=ko.observable(false); + //private String sourceRepoId; this.sourceRepoId=ko.observable(sourceRepoId); + this.sourceRepoId.subscribe(function(newValue){self.modified(true)}); + //private String targetRepoId; this.targetRepoId=ko.observable(targetRepoId); + this.targetRepoId.subscribe(function(newValue){self.modified(true)}); + //private String proxyId; this.proxyId=ko.observable(proxyId); + this.proxyId.subscribe(function(newValue){self.modified(true)}); + //private List blackListPatterns; this.blackListPatterns=ko.observableArray(blackListPatterns); + this.blackListPatterns.subscribe(function(newValue){self.modified(true)}); + //private List whiteListPatterns; this.whiteListPatterns=ko.observableArray(whiteListPatterns); + this.whiteListPatterns.subscribe(function(newValue){self.modified(true)}); + //private Map policies; this.policies=ko.observable(policies); + this.policies.subscribe(function(newValue){self.modified(true)}); + //private Map properties; this.properties=ko.observable(properties); + this.properties.subscribe(function(newValue){self.modified(true)}); + //private boolean disabled = false; this.disabled=ko.observable(disabled); + this.disabled.subscribe(function(newValue){self.modified(true)}); + //private int order = 0; this.order=ko.observable(order); + this.order.subscribe(function(newValue){self.modified(true)}); + + this.modified=ko.observable(false); } PolicyInformation=function(options,defaultOption,id,name){ + + var self=this; + this.modified=ko.observable(false); + //private List options; this.options=ko.observableArray(options); + this.options.subscribe(function(newValue){self.modified(true)}); + //private String defaultOption; this.defaultOption=ko.observable(defaultOption); + this.defaultOption.subscribe(function(newValue){self.modified(true)}); + //private String id; this.id=ko.observable(id); + this.id.subscribe(function(newValue){self.modified(true)}); + //private String name; this.name=ko.observable(name); + this.name.subscribe(function(newValue){self.modified(true)}); } ManagedRepositoryConnectorView=function(source,targetRepos){ + var self=this; + this.modified=ko.observable(false); + this.source=ko.observable(source); this.targetRepos=ko.observableArray(targetRepos); } ProxyConnectorsViewModel=function(){ - this.proxyConnectors=ko.observableArray([]); var self=this; + this.proxyConnectors=ko.observableArray([]); this.managedRepositoryConnectorViews=ko.observableArray([]); this.policyInformations=ko.observableArray([]); this.managedRepositories=ko.observableArray([]); @@ -121,14 +157,14 @@ $(function() { } showSettings=function(sourceRepoId,targetRepoId){ - //proxy-connectors-grid-remoterepo-settings-edit-internal-central - var targetImgId="#proxy-connectors-grid-remoterepo-settings-edit-"+sourceRepoId+"-"+targetRepoId; - //proxy-connectors.grid-remoterepo-settings-content-internal-central - var targetContentId="#proxy-connectors-grid-remoterepo-settings-content-"+sourceRepoId+"-"+targetRepoId; - $(targetContentId).html(""); - $(targetContentId).append($("#proxy-connectors-remote-settings-popover-tmpl").tmpl(self.getProxyConnector(sourceRepoId,targetRepoId))); - $(targetImgId).attr("data-content",$(targetContentId).html()); - $(targetImgId).popover( + var targetContent = $("#proxy-connectors-grid-remoterepo-settings-content-"+sourceRepoId+"-"+targetRepoId); + targetContent.html(""); + targetContent.append($("#proxy-connectors-remote-settings-popover-tmpl") + .tmpl(self.getProxyConnector(sourceRepoId,targetRepoId))); + + var targetImg = $("#proxy-connectors-grid-remoterepo-settings-edit-"+sourceRepoId+"-"+targetRepoId); + targetImg.attr("data-content",targetContent.html()); + targetImg.popover( { placement: "left", html: true, @@ -136,7 +172,7 @@ $(function() { } ); - $(targetImgId).popover('show'); + targetImg.popover('show'); } @@ -161,8 +197,9 @@ $(function() { // FIXME use various callback to prevent async false !! displayProxyConnectors=function(){ - $("#main-content").html($("#proxyConnectorsMain").tmpl()); - $("#main-content").append(smallSpinnerImg()); + var mainContent = $("#main-content"); + mainContent.html($("#proxyConnectorsMain").tmpl()); + mainContent.append(smallSpinnerImg()); this.proxyConnectorsViewModel = new ProxyConnectorsViewModel(); var self=this; @@ -211,8 +248,11 @@ $(function() { if (data==null){ return null; } + var policies = data.policies == null ? null: $.each(data.policies,function(item){ + return new Entry(item.key, item.value); + }); return new ProxyConnector(data.sourceRepoId,data.targetRepoId,data.proxyId,mapStringArray(data.blackListPatterns), - mapStringArray(data.whiteListPatterns),data.policies,data.properties, + mapStringArray(data.whiteListPatterns),policies,data.properties, data.disabled,data.order); } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js index b906848e1..d77c543ca 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js @@ -173,7 +173,6 @@ $(function() { this.availableLayouts = window.managedRepositoryTypes; this.save=function(){ - $.log("repositories.js#save"); var valid = $("#main-content #managed-repository-edit-form").valid(); if (valid==false) { return; @@ -297,10 +296,11 @@ $(function() { var self = this; editManagedRepository=function(managedRepository){ + var mainContent = $("#main-content"); var viewModel = new ManagedRepositoryViewModel(managedRepository,true,self); - ko.applyBindings(viewModel,$("#main-content #managed-repository-edit").get(0)); + ko.applyBindings(viewModel,mainContent.find("#managed-repository-edit").get(0)); activateManagedRepositoryEditTab(); - $("#managed-repository-edit-li a").html($.i18n.prop('edit')); + mainContent.find("#managed-repository-edit-li a").html($.i18n.prop('edit')); activateManagedRepositoryFormValidation(); } @@ -427,10 +427,10 @@ $(function() { } var archivaRepositoryStatistics=mapArchivaRepositoryStatistics(data.archivaRepositoryStatistics); archivaRepositoryStatistics.managedRepository=curRepo; - - $("#managedrepository-stats-"+curRepo.id()).append($("#managed-repository-stats-tmpl").tmpl(archivaRepositoryStatistics)); - $("#managedrepository-stats-img-"+curRepo.id()).attr("data-content",$(calculatePopoverId(curRepo)).html()); - $("#managedrepository-stats-img-"+curRepo.id()).popover( + var mainContent = $("#main-content"); + mainContent.find("#managedrepository-stats-"+curRepo.id()).append($("#managed-repository-stats-tmpl").tmpl(archivaRepositoryStatistics)); + mainContent.find("#managedrepository-stats-img-"+curRepo.id()).attr("data-content",$(calculatePopoverId(curRepo)).html()); + mainContent.find("#managedrepository-stats-img-"+curRepo.id()).popover( { placement: "left", html: true, @@ -438,7 +438,7 @@ $(function() { } ); - $("#managedrepository-stats-img-"+curRepo.id()).popover('show'); + mainContent.find("#managedrepository-stats-img-"+curRepo.id()).popover('show'); removeSmallSpinnerImg(); }, error: function(data) { @@ -452,7 +452,7 @@ $(function() { } calculatePopoverId=function(managedRepository){ - return "#managedrepository-stats-"+managedRepository.id() + " #managedrepository-stats-"+managedRepository.id()+"-popover"; + return "#main-content #managedrepository-stats-"+managedRepository.id() + " #managedrepository-stats-"+managedRepository.id()+"-popover"; } hideStats=function(managedRepository){ @@ -460,9 +460,9 @@ $(function() { } showPomSnippet=function(managedRepository){ - - $("#managed-repositories-pom-snippet").html(mediumSpinnerImg()); - $('#managed-repositories-pom-snippet').show(); + var mainContent = $("#main-content"); + mainContent.find("#managed-repositories-pom-snippet").html(mediumSpinnerImg()); + mainContent.find('#managed-repositories-pom-snippet').show(); var url = "restServices/archivaServices/managedRepositoriesService/getPomSnippet/"+encodeURIComponent(managedRepository.id()); $.ajax(url, { @@ -671,9 +671,10 @@ $(function() { success: function(data) { var viewModel = new RemoteRepositoryViewModel(remoteRepository,true,self); viewModel.networkProxies(mapNetworkProxies(data)); - ko.applyBindings(viewModel,$("#main-content #remote-repository-edit").get(0)); + var mainContent = $("#main-content"); + ko.applyBindings(viewModel,mainContent.find("#remote-repository-edit").get(0)); activateRemoteRepositoryEditTab(); - $("#remote-repository-edit-li a").html($.i18n.prop('edit')); + mainContent.find("#remote-repository-edit-li a").html($.i18n.prop('edit')); activateRemoteRepositoryFormValidation(); } }) @@ -763,20 +764,22 @@ $(function() { } activateRemoteRepositoriesGridTab=function(){ - $("#main-content #remote-repository-edit-li").removeClass("active"); - $("#main-content #remote-repository-edit").removeClass("active"); + var mainContent = $("#main-content"); + mainContent.find("#remote-repository-edit-li").removeClass("active"); + mainContent.find("#remote-repository-edit").removeClass("active"); - $("#main-content #remote-repositories-view-li").addClass("active"); - $("#main-content #remote-repositories-view").addClass("active"); - $("#main-content #remote-repository-edit-li a").html($.i18n.prop("add")); + mainContent.find("#remote-repositories-view-li").addClass("active"); + mainContent.find("#remote-repositories-view").addClass("active"); + mainContent.find("#remote-repository-edit-li a").html($.i18n.prop("add")); } activateRemoteRepositoryEditTab=function(){ - $("#main-content #remote-repositories-view-li").removeClass("active"); - $("#main-content #remote-repositories-view").removeClass("active"); + var mainContent = $("#main-content"); + mainContent.find("#remote-repositories-view-li").removeClass("active"); + mainContent.find("#remote-repositories-view").removeClass("active"); - $("#main-content #remote-repository-edit-li").addClass("active"); - $("#main-content #remote-repository-edit").addClass("active"); + mainContent.find("#remote-repository-edit-li").addClass("active"); + mainContent.find("#remote-repository-edit").addClass("active"); } //--------------------------- @@ -785,12 +788,13 @@ $(function() { displayRepositoriesGrid=function(){ clearUserMessages(); - $("#main-content").html(mediumSpinnerImg()); - $("#main-content").html($("#repositoriesMain").tmpl()); - $("#main-content #repositories-tabs a:first").tab("show"); + var mainContent = $("#main-content"); + mainContent.html(mediumSpinnerImg()); + mainContent.html($("#repositoriesMain").tmpl()); + mainContent.find("#repositories-tabs a:first").tab("show"); - $("#main-content #managed-repositories-content").append(mediumSpinnerImg()); - $("#main-content #remote-repositories-content").append(mediumSpinnerImg()); + mainContent.find("#managed-repositories-content").append(mediumSpinnerImg()); + mainContent.find("#remote-repositories-content").append(mediumSpinnerImg()); var managedRepositoriesViewModel = new ManagedRepositoriesViewModel(); var remoteRepositoriesViewModel = new RemoteRepositoriesViewModel(); @@ -820,12 +824,13 @@ $(function() { ], pageSize: 5, gridUpdateCallBack: function(){ - $("#main-content #managed-repositories-table [title]").tooltip(); + $("#main-content #managed-repositories-table").find("[title]").tooltip(); } }); - ko.applyBindings(managedRepositoriesViewModel,$("#main-content #managed-repositories-view").get(0)); + var mainContent = $("#main-content"); + ko.applyBindings(managedRepositoriesViewModel,mainContent.find("#managed-repositories-view").get(0)); - $("#main-content #managed-repositories-pills a:first").tab('show'); + mainContent.find("#managed-repositories-pills #managed-repositories-view-a").tab('show'); removeMediumSpinnerImg("#main-content #managed-repositories-content"); activateManagedRepositoriesGridTab(); } @@ -861,11 +866,12 @@ $(function() { ], pageSize: 5, gridUpdateCallBack: function(){ - $("#main-content #remote-repositories-table [title]").tooltip(); + $("#main-content #remote-repositories-table").find("[title]").tooltip(); } }); - ko.applyBindings(remoteRepositoriesViewModel,$("#main-content #remote-repositories-table").get(0)); - $("#main-content #remote-repositories-pills a:first").tab('show') + var mainContent = $("#main-content"); + ko.applyBindings(remoteRepositoriesViewModel,mainContent.find("#remote-repositories-table").get(0)); + mainContent.find("#remote-repositories-pills #remote-repositories-view-a").tab('show') removeMediumSpinnerImg("#main-content #remote-repositories-content"); } } @@ -874,13 +880,14 @@ $(function() { $("#main-content #managed-repositories-pills").on('show', function (e) { + var mainContent = $("#main-content"); if ($(e.target).attr("href")=="#managed-repository-edit") { var viewModel = new ManagedRepositoryViewModel(new ManagedRepository(),false,managedRepositoriesViewModel); - ko.applyBindings(viewModel,$("#main-content #managed-repository-edit").get(0)); + ko.applyBindings(viewModel,mainContent.find("#managed-repository-edit").get(0)); activateManagedRepositoryFormValidation(); } if ($(e.target).attr("href")=="#managed-repositories-view") { - $("#main-content #managed-repository-edit-li a").html($.i18n.prop("add")); + mainContent.find("#managed-repository-edit-li a").html($.i18n.prop("add")); } }); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/repositories.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/repositories.html index f9cc304d5..0c8692fe7 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/repositories.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/repositories.html @@ -33,7 +33,7 @@