]> source.dussan.org Git - archiva.git/commitdiff
refactor proxy connectors grid loadind, start edition too
authorOlivier Lamy <olamy@apache.org>
Tue, 7 Feb 2012 18:24:05 +0000 (18:24 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 7 Feb 2012 18:24:05 +0000 (18:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1241542 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/proxy-connectors.html

index 10fec2348b353abd0875ce5dc54c99bc9b037828..f8b78d1c9fdc82cd21f0aba37574a6f9f7f960fa 100644 (file)
@@ -118,7 +118,7 @@ $(function() {
   }
 
   NetworkProxiesViewModel=function(){
-    this.networkProxies=ko.observableArray([]);//.subscribe(function(val){$.log('subscribe')});
+    this.networkProxies=ko.observableArray([]);
 
     var self=this;
 
@@ -220,12 +220,8 @@ $(function() {
 
 
 
-    $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", {
-        type: "GET",
-        dataType: 'json',
-        success: function(data) {
+    loadNetworkProxies( function(data) {
           networkProxiesViewModel.networkProxies(mapNetworkProxies(data));
-          //networkProxiesViewModel.networkProxies.subscribe(function(){$.log("change in networkProxies")});
           networkProxiesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
             data: networkProxiesViewModel.networkProxies,
             columns: [
@@ -257,8 +253,16 @@ $(function() {
           });
           ko.applyBindings(networkProxiesViewModel,$("#main-content #network-proxies-view").get(0));
         }
-      }
-    );
+    )
+  }
+
+  loadNetworkProxies=function(successCallbackFn, errorCallbackFn){
+    $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", {
+        type: "GET",
+        dataType: 'json',
+        success: successCallbackFn,
+        error: errorCallbackFn
+    });
   }
 
   activateNetworkProxyFormValidation=function(){
index 6358f0a92deb1924493a07029cbdcada6d95f9f0..011db78b730e4ad00cd04237333f32b61e1368e7 100644 (file)
@@ -92,6 +92,13 @@ $(function() {
     this.targetRepos=ko.observableArray(targetRepos);
   }
 
+  ProxyConnectorViewModel=function(proxyConnector,update,proxyConnectorsViewModel){
+    var self=this;
+    this.proxyConnector=ko.observable();
+    this.proxyConnectorsViewModel=proxyConnectorsViewModel;
+    //mappe policies avec policyInformations pour avoir object + plus complexe
+  }
+
   ProxyConnectorsViewModel=function(){
     var self=this;
     this.proxyConnectors=ko.observableArray([]);
@@ -99,6 +106,8 @@ $(function() {
     this.policyInformations=ko.observableArray([]);
     this.managedRepositories=ko.observableArray([]);
     this.remoteRepositories=ko.observableArray([]);
+    this.networkProxies=ko.observableArray([]);
+
     editProxyConnector=function(proxyConnector){
 
     }
@@ -186,16 +195,29 @@ $(function() {
           $("#main-content #proxyConnectorsTable [title]").tooltip();
         }
       });
+      var mainContent = $("#main-content");
       this.gridViewModel.getManagedRepository=getManagedRepository;
-      ko.applyBindings(this,$("#main-content #proxyConnectorsTable").get(0));
+      ko.applyBindings(this,mainContent.find("#proxyConnectorsTable").get(0));
       removeSmallSpinnerImg("#main-content");
-      $("#main-content #proxy-connectors-view-tabs a:first").tab('show');
+      this,mainContent.find("#proxy-connectors-view-tabs #proxy-connectors-view-tabs-a-network-proxies-grid").tab('show');
+
+      mainContent.find("#proxy-connectors-view-tabs").on('show', function (e) {
+
+        if ($(e.target).attr("href")=="#proxy-connectors-edit") {
+          var proxyConnectorViewModel=new ProxyConnectorViewModel(new ProxyConnector(),false,self);
+          ko.applyBindings(proxyConnectorViewModel,mainContent.find("#proxy-connectors-edit").get(0));
+
+        }
+        if ($(e.target).attr("href")=="#proxy-connectors-view") {
+          $("#proxy-connectors-view-tabs-a-network-proxies-grid").html($.i18n.prop("add"));
+
+        }
+
+      });
     }
 
   }
 
-  // FIXME use various callback to prevent async false !!
-
   displayProxyConnectors=function(){
     var mainContent = $("#main-content");
     mainContent.html($("#proxyConnectorsMain").tmpl());
@@ -204,44 +226,50 @@ $(function() {
     this.proxyConnectorsViewModel = new ProxyConnectorsViewModel();
     var self=this;
 
-    $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", {
-        type: "GET",
-        dataType: 'json',
-        async: false,
-        success: function(data) {
-          self.proxyConnectorsViewModel.managedRepositories(mapManagedRepositories(data));
-        }
-    });
+    loadManagedRepositories(function(data) {
+      self.proxyConnectorsViewModel.managedRepositories(mapManagedRepositories(data));
+
+      loadRemoteRepositories(function(data) {
+        self.proxyConnectorsViewModel.remoteRepositories(mapRemoteRepositories(data));
+
+        loadNetworkProxies(function(data) {
+          self.proxyConnectorsViewModel.networkProxies(mapNetworkProxies(data));
+
+          loadAllPolicies( function(data) {
+            self.proxyConnectorsViewModel.policyInformations(mapPolicyInformations(data));
+
+            loadAllProxyConnectors( function(data) {
+              self.proxyConnectorsViewModel.proxyConnectors(mapProxyConnectors(data));
+              self.proxyConnectorsViewModel.displayGrid();
+            });
+
+          });
+
+        });
+
+      });
 
-    $.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", {
-        type: "GET",
-        dataType: 'json',
-        async: false,
-        success: function(data) {
-          self.proxyConnectorsViewModel.remoteRepositories(mapRemoteRepositories(data));
-        }
     });
 
+  }
+
+  loadAllPolicies=function(successCallBackFn,errorCallBackFn){
     $.ajax("restServices/archivaServices/proxyConnectorService/allPolicies", {
         type: "GET",
         dataType: 'json',
-        async: false,
-        success: function(data) {
-          self.proxyConnectorsViewModel.policyInformations(mapPolicyInformations(data));
-        }
+        success: successCallBackFn,
+        error: errorCallBackFn
       }
     );
+  }
 
+  loadAllProxyConnectors=function(successCallBackFn,errorCallBackFn){
     $.ajax("restServices/archivaServices/proxyConnectorService/getProxyConnectors", {
-        type: "GET",
-        dataType: 'json',
-        success: function(data) {
-          self.proxyConnectorsViewModel.proxyConnectors(mapProxyConnectors(data));
-          self.proxyConnectorsViewModel.displayGrid();
-        }
-      }
-    );
-
+      type: "GET",
+      dataType: 'json',
+      success: successCallBackFn,
+      error: errorCallBackFn
+     });
   }
 
   mapProxyConnector=function(data){
@@ -251,8 +279,11 @@ $(function() {
     var policies = data.policies == null ? null: $.each(data.policies,function(item){
       return new Entry(item.key, item.value);
     });
+    var properties = data.properties == null ? null: $.each(data.properties,function(item){
+          return new Entry(item.key, item.value);
+        });
     return new ProxyConnector(data.sourceRepoId,data.targetRepoId,data.proxyId,mapStringArray(data.blackListPatterns),
-                              mapStringArray(data.whiteListPatterns),policies,data.properties,
+                              mapStringArray(data.whiteListPatterns),policies,properties,
                               data.disabled,data.order);
   }
 
index d77c543ca3386d8918f45c4b1ed4ca3cc7a4cc5a..9a3e3559fd7164291a43d130e0404884a3ccf241 100644 (file)
@@ -487,20 +487,22 @@ $(function() {
   }
 
   activateManagedRepositoriesGridTab=function(){
-    $("#main-content #managed-repository-edit-li").removeClass("active");
-    $("#main-content #managed-repository-edit").removeClass("active");
+    var mainContent = $("#main-content");
+    mainContent.find("#managed-repository-edit-li").removeClass("active");
+    mainContent.find("#managed-repository-edit").removeClass("active");
 
-    $("#main-content #managed-repositories-view-li").addClass("active");
-    $("#main-content #managed-repositories-view").addClass("active");
-    $("#main-content #managed-repository-edit-li a").html($.i18n.prop("add"));
+    mainContent.find("#managed-repositories-view-li").addClass("active");
+    mainContent.find("#managed-repositories-view").addClass("active");
+    mainContent.find("#managed-repository-edit-li a").html($.i18n.prop("add"));
   }
 
   activateManagedRepositoryEditTab=function(){
-    $("#main-content #managed-repositories-view-li").removeClass("active");
-    $("#main-content #managed-repositories-view").removeClass("active");
+    var mainContent = $("#main-content");
+    mainContent.find("#managed-repositories-view-li").removeClass("active");
+    mainContent.find("#managed-repositories-view").removeClass("active");
 
-    $("#main-content #managed-repository-edit-li").addClass("active");
-    $("#main-content #managed-repository-edit").addClass("active");
+    mainContent.find("#managed-repository-edit-li").addClass("active");
+    mainContent.find("#managed-repository-edit").addClass("active");
   }
 
 
@@ -799,87 +801,77 @@ $(function() {
     var managedRepositoriesViewModel = new ManagedRepositoriesViewModel();
     var remoteRepositoriesViewModel = new RemoteRepositoriesViewModel();
 
-    $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", {
-        type: "GET",
-        dataType: 'json',
-        success: function(data) {
-          managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data));
-          managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
-            data: managedRepositoriesViewModel.managedRepositories,
-            columns: [
-              {
-                headerText: $.i18n.prop('identifier'),
-                rowText: "id"
-              },
-              {
-                headerText: $.i18n.prop('name'),
-                rowText: "name"
-              },
-              {
-              headerText: $.i18n.prop('type'),
-              rowText: "getTypeLabel",
-              // FIXME i18n
-              title: "Repository type (default is Maven 2)"
-              }
-            ],
-            pageSize: 5,
-            gridUpdateCallBack: function(){
-              $("#main-content #managed-repositories-table").find("[title]").tooltip();
-            }
-          });
-          var mainContent = $("#main-content");
-          ko.applyBindings(managedRepositoriesViewModel,mainContent.find("#managed-repositories-view").get(0));
-
-          mainContent.find("#managed-repositories-pills #managed-repositories-view-a").tab('show');
-          removeMediumSpinnerImg("#main-content #managed-repositories-content");
-          activateManagedRepositoriesGridTab();
+    loadManagedRepositories(function(data) {
+      managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data));
+      managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
+        data: managedRepositoriesViewModel.managedRepositories,
+        columns: [
+          {
+            headerText: $.i18n.prop('identifier'),
+            rowText: "id"
+          },
+          {
+            headerText: $.i18n.prop('name'),
+            rowText: "name"
+          },
+          {
+          headerText: $.i18n.prop('type'),
+          rowText: "getTypeLabel",
+          // FIXME i18n
+          title: "Repository type (default is Maven 2)"
+          }
+        ],
+        pageSize: 5,
+        gridUpdateCallBack: function(){
+          $("#main-content #managed-repositories-table").find("[title]").tooltip();
         }
-      }
-    );
+      });
+      var mainContent = $("#main-content");
+      ko.applyBindings(managedRepositoriesViewModel,mainContent.find("#managed-repositories-view").get(0));
 
-    $.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", {
-        type: "GET",
-        dataType: 'json',
-        success: function(data) {
-          remoteRepositoriesViewModel.remoteRepositories(mapRemoteRepositories(data));
-          remoteRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
-            data: remoteRepositoriesViewModel.remoteRepositories,
-            columns: [
-              {
-                headerText: $.i18n.prop('identifier'),
-                rowText: "id"
-              },
-              {
-                headerText: $.i18n.prop('name'),
-                rowText: "name"
-              },
-              {
-                headerText: $.i18n.prop('url'),
-                rowText: "url"
-              },
-              {
-              headerText: $.i18n.prop('type'),
-              rowText: "getTypeLabel",
-              // FIXME i18n
-              title: "Repository type (default is Maven 2)"
-              }
-            ],
-            pageSize: 5,
-            gridUpdateCallBack: function(){
-              $("#main-content #remote-repositories-table").find("[title]").tooltip();
-            }
-          });
-          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");
+      mainContent.find("#managed-repositories-pills #managed-repositories-view-a").tab('show');
+      removeMediumSpinnerImg("#main-content #managed-repositories-content");
+      activateManagedRepositoriesGridTab();
+    });
+
+    loadRemoteRepositories(function(data) {
+      remoteRepositoriesViewModel.remoteRepositories(mapRemoteRepositories(data));
+      remoteRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
+        data: remoteRepositoriesViewModel.remoteRepositories,
+        columns: [
+          {
+            headerText: $.i18n.prop('identifier'),
+            rowText: "id"
+          },
+          {
+            headerText: $.i18n.prop('name'),
+            rowText: "name"
+          },
+          {
+            headerText: $.i18n.prop('url'),
+            rowText: "url"
+          },
+          {
+          headerText: $.i18n.prop('type'),
+          rowText: "getTypeLabel",
+          // FIXME i18n
+          title: "Repository type (default is Maven 2)"
+          }
+        ],
+        pageSize: 5,
+        gridUpdateCallBack: function(){
+          $("#main-content #remote-repositories-table").find("[title]").tooltip();
         }
-      }
-    );
+      });
+      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");
+    });
 
 
 
-    $("#main-content #managed-repositories-pills").on('show', function (e) {
+    mainContent.find("#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);
@@ -892,7 +884,7 @@ $(function() {
 
     });
 
-    $("#main-content #remote-repositories-pills").on('show', function (e) {
+    mainContent.find("#remote-repositories-pills").on('show', function (e) {
       if ($(e.target).attr("href")=="#remote-repository-edit") {
         $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", {
             type: "GET",
@@ -913,4 +905,22 @@ $(function() {
 
   }
 
+  loadManagedRepositories=function(successCallBackFn,errorCallBackFn){
+    $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", {
+        type: "GET",
+        dataType: 'json',
+        success: successCallBackFn,
+        error: errorCallBackFn
+    });
+  }
+
+  loadRemoteRepositories=function(successCallBackFn,errorCallBackFn){
+    $.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", {
+        type: "GET",
+        dataType: 'json',
+        success: successCallBackFn,
+        error: errorCallBackFn
+    });
+  }
+
 });
\ No newline at end of file
index d5c764c26157f2152e53457a0168683a2444cb66..1987c80e310a8c7ed1e1b6d588cd0cbe8faf8b97 100644 (file)
@@ -26,7 +26,7 @@
       <a data-toggle="tab" href="#proxy-connectors-view" id="proxy-connectors-view-tabs-a-network-proxies-grid">${$.i18n.prop('proxy-connectors.grid.tab.title')}</a>
     </li>
     <li id="proxy-connectors-view-tabs-li-edit">
-      <a data-toggle="tab" href="#proxy-connectors-edit">${$.i18n.prop('add')}</a>
+      <a data-toggle="tab" href="#proxy-connectors-edit" id="proxy-connectors-view-tabs-a-edit">${$.i18n.prop('add')}</a>
     </li>
   </ul>
   <div id="proxy-connectors-view-tabs-content" class="tab-content">
@@ -36,7 +36,7 @@
       </table>
       <div id="proxy-connectorsPagination"></div>
     </div>
-    <div id="proxy-connectors-edit" class="tab-pane" data-bind='template: {name:"proxy-connectors-edit-tmpl"}'></div>
+    <div id="proxy-connectors-edit" class="tab-pane" data-bind='template: {name:"proxy-connector-edit-form-tmpl"}'></div>
   </div>
 
 </script>
@@ -92,7 +92,7 @@
     {{/if}}
     <table class="table">
       <thead>
-        <th colspan="2">Policies</th>
+        <th colspan="2">${$.i18n.prop('proxy-connector.policies')}</th>
       </thead>
       <tbody>
         {{each policies().entry}}
       </tbody>
     </table>
   </div>
+</script>
+
+<script id="proxy-connector-edit-form-tmpl" type='text/x-jquery-tmpl'>
+  <form id="proxy-connector-edit-form" class="form-horizontal">
+    <fieldset id="remote-repository-edit-fieldset">
+      <div class="control-group">
+        <label class="control-label" for="proxyId">${$.i18n.prop('proxy-connector.network-proxy.id')}</label>
+        <div class="controls">
+          <select id="proxyId"
+                  data-bind="options: proxyConnectorsViewModel.networkProxies, optionsText: 'id',optionsValue:'id',
+                   value: proxyConnector.proxyId, optionsCaption: 'direct connection'"></select>
+        </div>
+      </div>
+      <div class="control-group">
+        <label class="control-label" for="proxyId">${$.i18n.prop('proxy-connector.managed.repository.id')}</label>
+        <div class="controls">
+          <select id="sourceRepoId"
+                  data-bind="options: proxyConnectorsViewModel.managedRepositories, optionsText: 'id',optionsValue:'id',
+                   value: proxyConnector.sourceRepoId"></select>
+        </div>
+      </div>
+      <div class="control-group">
+        <label class="control-label" for="proxyId">${$.i18n.prop('proxy-connector.remote.repository.id')}</label>
+        <div class="controls">
+          <select id="targetRepoId"
+                  data-bind="options: proxyConnectorsViewModel.remoteRepositories, optionsText: 'id',optionsValue:'id',
+                   value: proxyConnector.targetRepoId"></select>
+        </div>
+      </div>
+      <div class="control-group span5">
+          <table class="table">
+            <thead>
+              <th colspan="2">${$.i18n.prop('proxy-connector.policies')}</th>
+            </thead>
+            <tbody>
+              {{each proxyConnector.policies}}
+
+              <tr>
+                <td>${$value.key}</td>
+                <td>${$value.value}</td>
+              </tr>
+              {{/each}}
+            </tbody>
+          </table>
+      </div>
+    </fieldset>
+  </form>
 </script>
\ No newline at end of file