]> source.dussan.org Git - archiva.git/commitdiff
reuse jquery selector already evaluated when possible
authorOlivier Lamy <olamy@apache.org>
Tue, 7 Feb 2012 18:23:50 +0000 (18:23 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 7 Feb 2012 18:23:50 +0000 (18:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1241541 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/repositories.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js

index 6c12f773ddccb594cf4ea07bb471cdfe6ea6af21..10fec2348b353abd0875ce5dc54c99bc9b037828 100644 (file)
@@ -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){
index 0b0deab0e25709a5cc8f1966e1f80675fed22f5f..6358f0a92deb1924493a07029cbdcada6d95f9f0 100644 (file)
@@ -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<String> blackListPatterns;
     this.blackListPatterns=ko.observableArray(blackListPatterns);
+    this.blackListPatterns.subscribe(function(newValue){self.modified(true)});
+
     //private List<String> whiteListPatterns;
     this.whiteListPatterns=ko.observableArray(whiteListPatterns);
+    this.whiteListPatterns.subscribe(function(newValue){self.modified(true)});
+
     //private Map<String, String> policies;
     this.policies=ko.observable(policies);
+    this.policies.subscribe(function(newValue){self.modified(true)});
+
     //private Map<String, String> 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<String> 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);
   }
 
index b906848e1112bb20f8ec457f5c68b038f4e9ab3c..d77c543ca3386d8918f45c4b1ed4ca3cc7a4cc5a 100644 (file)
@@ -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"));
       }
 
     });
index f9cc304d57720ebb1516a54fe33de995d770aee9..0c8692fe75df65d4731497c648598566a02e2ff9 100644 (file)
@@ -33,7 +33,7 @@
        <div id="managed-repositories-content" class="tab-pane active">
             <ul id="managed-repositories-pills" class="nav nav-pills">
               <li class="active" id="managed-repositories-view-li">
-                <a data-toggle="tab" href="#managed-repositories-view">${$.i18n.prop('managedrepositories.grid.tab.title')}</a>
+                <a data-toggle="tab" href="#managed-repositories-view" id="managed-repositories-view-a">${$.i18n.prop('managedrepositories.grid.tab.title')}</a>
               </li>
               <li id="managed-repository-edit-li">
                 <a data-toggle="tab" href="#managed-repository-edit">${$.i18n.prop('add')}</a>
@@ -57,7 +57,7 @@
        <div id="remote-repositories-content" class="tab-pane">
             <ul id="remote-repositories-pills" class="nav nav-pills">
               <li class="active" id="remote-repositories-view-li">
-                <a data-toggle="tab" href="#remote-repositories-view">${$.i18n.prop('remoterepositories.grid.tab.title')}</a>
+                <a data-toggle="tab" href="#remote-repositories-view" id="remote-repositories-view-a">${$.i18n.prop('remoterepositories.grid.tab.title')}</a>
               </li>
               <li id="remote-repository-edit-li">
                 <a data-toggle="tab" href="#remote-repository-edit">${$.i18n.prop('add')}</a>
index 0067cc4fd926d3b4c65a0ffca31e4b6c1845e4ec..366d888fd5684e347dcffbaadcb6dd10ed0c9a50 100644 (file)
@@ -305,6 +305,20 @@ appendTemplateUrl=function(){
   return "?"+appendArchivaVersion()+timestampNoCache();
 }
 
+/**
+ * mapping for a java Map entry
+ * @param key
+ * @param value
+ */
+Entry=function(key,value){
+  var self=this;
+  this.modified=ko.observable(false);
+  this.key=ko.observable(key);
+  this.key.subscribe(function(newValue){self.modified(true)});
+
+  this.value=ko.observable(value);
+  this.value.subscribe(function(newValue){self.modified(true)});
+}
 
 // extends jquery tmpl to support var def
 $.extend($.tmpl.tag, {