]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1576] rewrite proxies connector page
authorOlivier Lamy <olamy@apache.org>
Tue, 7 Feb 2012 18:24:18 +0000 (18:24 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 7 Feb 2012 18:24:18 +0000 (18:24 +0000)
pushing some stuff for edition.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1241544 13f79535-47bb-0310-9956-ffa450edef68

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/templates/proxy-connectors.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js

index 011db78b730e4ad00cd04237333f32b61e1368e7..1ad691917f6a487360e0eed06b2c85d42cd2ed1e 100644 (file)
@@ -59,7 +59,8 @@ $(function() {
     this.order=ko.observable(order);
     this.order.subscribe(function(newValue){self.modified(true)});
 
-    this.modified=ko.observable(false);
+    this.modified=ko.observable(true);
+    this.modified.subscribe(function(newValue){$.log("ProxyConnector modified")});
   }
 
   PolicyInformation=function(options,defaultOption,id,name){
@@ -82,21 +83,41 @@ $(function() {
     //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);
   }
 
   ProxyConnectorViewModel=function(proxyConnector,update,proxyConnectorsViewModel){
     var self=this;
-    this.proxyConnector=ko.observable();
+    this.proxyConnector=ko.observable(proxyConnector);
     this.proxyConnectorsViewModel=proxyConnectorsViewModel;
-    //mappe policies avec policyInformations pour avoir object + plus complexe
+    this.update=update;
+    getSelectedPolicyOption=function(id){
+      var policies=self.proxyConnector().policies();
+      for (i=0;i<policies().length;i++){
+        if (id==policies()[i].key()){
+          return policies()[i].value();
+        }
+      }
+      return "";
+    }
+    getPolicyOptions=function(id){
+      var policyInformations=self.proxyConnectorsViewModel.policyInformations();
+      for(i=0;i<policyInformations.length;i++){
+        $.log("getPolicyOptions:"+id+",cur:"+policyInformations[i].id());
+        if (policyInformations[i].id()==id){
+          return policyInformations[i].options();
+        }
+      }
+    }
   }
 
   ProxyConnectorsViewModel=function(){
@@ -187,7 +208,6 @@ $(function() {
 
     this.displayGrid=function(){
       self.managedRepositoryConnectorViews(this.findUniqueManagedRepos());
-      $.log("uniqueManagedRepos:"+self.managedRepositoryConnectorViews().length);
       this.gridViewModel = new ko.simpleGrid.viewModel({
         data: self.managedRepositoryConnectorViews,
         pageSize: 5,
@@ -204,8 +224,13 @@ $(function() {
       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);
+          var proxyConnector=new ProxyConnector();
+          for (i=0;i<self.policyInformations.length;i++){
+            //proxyConnector[]
+          }
+          var proxyConnectorViewModel=new ProxyConnectorViewModel(proxyConnector,false,self);
           ko.applyBindings(proxyConnectorViewModel,mainContent.find("#proxy-connectors-edit").get(0));
+          //ko.applyBindings(proxyConnectorViewModel,mainContent.find("#proxy-connector-policies-binding").get(0));
 
         }
         if ($(e.target).attr("href")=="#proxy-connectors-view") {
@@ -307,4 +332,50 @@ $(function() {
            });
   }
 
-});
\ No newline at end of file
+});
+
+(function () {
+
+
+  // Templates used for rendering
+  var templateEngine = new ko.jqueryTmplTemplateEngine();
+  TemporaryViewModel=function(currentPolicyInformation,selectedOption){
+    var self=this;
+    this.policyInformation=currentPolicyInformation;
+    this.selectedValue=selectedOption;
+    isSelectedOption=function(id){
+      return (id==self.selectedValue);
+    }
+  }
+  ko.bindingHandlers.proxyConnectorPolicies = {
+      update: function(element, valueAccessor, allBindingsAccessor, proxyConnectorViewModel) {
+        // This will be called once when the binding is first applied to an element,
+        // and again whenever the associated observable changes value.
+        // Update the DOM element based on the supplied values here.
+        var jqueryElement=$(element);
+        $.log("update:"+proxyConnectorViewModel.proxyConnectorsViewModel.managedRepositories().length);
+        // Empty the element
+        while(element.firstChild) {
+            ko.removeNode(element.firstChild);
+        }
+        var policyInformations = proxyConnectorViewModel.proxyConnectorsViewModel.policyInformations();
+        for (i=0;i<policyInformations.length;i++){
+          var currentPolicyInformation=policyInformations[i];
+          var gridContainer = element.appendChild(document.createElement("DIV"));
+          var selectedOption =
+              proxyConnectorViewModel.update ?
+                  proxyConnectorViewModel.getSelectedOptionForPolicy(currentPolicyInformation.id()):currentPolicyInformation.defaultOption();
+
+          var tmpViewModel = new TemporaryViewModel(currentPolicyInformation,selectedOption);
+          ko.renderTemplate("proxy-connector-edit-form-policies-tmpl", tmpViewModel
+                            , { templateEngine: templateEngine }, gridContainer, "replaceNode");
+          ko.utils.registerEventHandler($("#policy-"+currentPolicyInformation.id()).get(0), "change", function () {
+            $.log("change policy:"+$(this).attr('value')+" for policy " + tmpViewModel.currentPolicyInformation.id());
+          });
+          /*.change(function(event){
+            $.log("change policy:"+$(this).attr('value')+" for policy " + tmpViewModel.currentPolicyInformation.id());
+          });*/
+        }
+      }
+  };
+})();
\ No newline at end of file
index 1987c80e310a8c7ed1e1b6d588cd0cbe8faf8b97..77146d9963834e88327e0b113279a2064feb846b 100644 (file)
@@ -54,7 +54,7 @@
   </thead>
 
   {{each(i, row) itemsOnCurrentPage()}}
-    <tr>
+    <tr data-bind="css:{ 'modified': row.modified()}">
         {{var val = row.source()}}
       <td>
         <blockquote>
                    value: proxyConnector.targetRepoId"></select>
         </div>
       </div>
-      <div class="control-group span5">
+      <div class="control-group span6">
           <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 proxyConnectorsViewModel.policyInformations()}}
+              {{var policyId=$value.id()}}
+                <tr>
+                  <td>${$value.name()}</td>
+                  <td>
+                    <select id="policy-${policyId}" data-bind="options: getPolicyOptions(policyId),value:getSelectedPolicyOption(policyId)"></select>
+                  </td>
+                </tr>
               {{/each}}
             </tbody>
           </table>
       </div>
     </fieldset>
   </form>
+</script>
+
+<script id="proxy-connector-edit-form-policies-tmpl" type='text/x-jquery-tmpl'>
+   <tr>
+     <td>${policyInformation.name()}</td>
+     <td>
+       <select id="policy-${policyInformation.id()}">
+         {{each(i, curOption) policyInformation.options()}}
+           {{if isSelectedOption(curOption)}}
+             <option selected value="${curOption}">${curOption}</option>
+           {{else}}
+             <option value="${curOption}">${curOption}</option>
+           {{/if}}
+         {{/each}}
+       </select>
+     </td>
+   </tr>
+
+   <br/>
 </script>
\ No newline at end of file
index af95ad36aee4527dc8e25e1b868ceea1328a6f72..cc56f592b4895b172616ffcdcf5fc46f7d4e6009 100644 (file)
@@ -47,8 +47,9 @@
           var viewModel = viewModelAccessor(), allBindings = allBindingsAccessor();
 
           // Empty the element
-          while(element.firstChild)
+          while(element.firstChild) {
               ko.removeNode(element.firstChild);
+          }
 
           // Allow the default templates to be overridden
           var gridTemplateName      = allBindings.simpleGridTemplate || "ko_usersGrid_grid",