You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/02/07 19:24:19 UTC

svn commit: r1241544 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js: archiva/proxy-connectors.js archiva/templates/proxy-connectors.html knockout.simpleGrid.js

Author: olamy
Date: Tue Feb  7 18:24:18 2012
New Revision: 1241544

URL: http://svn.apache.org/viewvc?rev=1241544&view=rev
Log:
[MRM-1576] rewrite proxies connector page
pushing some stuff for edition.

Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js?rev=1241544&r1=1241543&r2=1241544&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js Tue Feb  7 18:24:18 2012
@@ -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

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html?rev=1241544&r1=1241543&r2=1241544&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html Tue Feb  7 18:24:18 2012
@@ -54,7 +54,7 @@
   </thead>
 
   {{each(i, row) itemsOnCurrentPage()}}
-    <tr>
+    <tr data-bind="css:{ 'modified': row.modified()}">
         {{var val = row.source()}}
       <td>
         <blockquote>
@@ -133,22 +133,43 @@
                    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

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js?rev=1241544&r1=1241543&r2=1241544&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js Tue Feb  7 18:24:18 2012
@@ -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",