]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1712] Add buttons for managing proxy connectors rules as can be a pain with...
authorOlivier Lamy <olamy@apache.org>
Mon, 19 Nov 2012 15:22:47 +0000 (15:22 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 19 Nov 2012 15:22:47 +0000 (15:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1411243 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html

index efcbda1dbe6acb4ec2edde4e32223eda50574be6..ef2b2e99b4a68cf37350209d16822539e5f7312b 100644 (file)
@@ -40,6 +40,15 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra
       return ruleType;
     }
 
+    this.findProxyConnector=function(sourceRepoId,targetRepoId){
+      for(var i=0;i<self.proxyConnectors().length;i++){
+        var proxyConnector=self.proxyConnectors()[i];
+        if(proxyConnector.sourceRepoId()==sourceRepoId && proxyConnector.targetRepoId()==targetRepoId){
+          return proxyConnector;
+        }
+      }
+    }
+
     this.displayGrid=function(){
       var mainContent = $("#main-content");
 
@@ -57,7 +66,7 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra
 
       ko.applyBindings(self,mainContent.find("#proxy-connector-rules-view").get(0));
 
-      removeSmallSpinnerImg();
+      removeSmallSpinnerImg(mainContent);
 
       mainContent.find("#proxy-connectors-rules-view-tabs").on('show', function (e) {
         $.log("on show:"+$(e.target).attr("href"));
@@ -162,13 +171,18 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra
       var proxyConnectorRuleViewModel=new ProxyConnectorRuleViewModel(proxyConnectorRule,self,true);
       ko.applyBindings(proxyConnectorRuleViewModel,$("#main-content").find("#proxy-connector-rules-edit" ).get(0));
       activateProxyConnectorRulesEditTab();
-
+      proxyConnectorRuleViewModel.activateRemoveChoosen(self);
+      proxyConnectorRuleViewModel.activateRemoveAvailable(self);
     }
 
+
+
     remove=function(){
       $.log("remove");
     }
 
+
+
   }
 
   ProxyConnectorRuleViewModel=function(proxyConnectorRule,proxyConnectorRulesViewModel,update){
@@ -180,34 +194,76 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra
     this.update=update;
 
 
-      $.each(this.proxyConnectorRulesViewModel.proxyConnectors(), function(idx, value) {
-        $.log(idx + ': ' + value.sourceRepoId() +":"+value.targetRepoId());
-        var available=true;
-        // is it in proxyConnectorRule.proxyConnectors
-        $.each(self.proxyConnectorRule.proxyConnectors(),function(index,proxyConnector){
-          if(value.sourceRepoId()==proxyConnector.sourceRepoId() && value.targetRepoId()==proxyConnector.targetRepoId()){
-            available=false;
-          }
-        });
-        if(available==true){
-          self.availableProxyConnectors.push(value);
+    $.each(this.proxyConnectorRulesViewModel.proxyConnectors(), function(idx, value) {
+      $.log(idx + ': ' + value.sourceRepoId() +":"+value.targetRepoId());
+      var available=true;
+      // is it in proxyConnectorRule.proxyConnectors
+      $.each(self.proxyConnectorRule.proxyConnectors(),function(index,proxyConnector){
+        if(value.sourceRepoId()==proxyConnector.sourceRepoId() && value.targetRepoId()==proxyConnector.targetRepoId()){
+          available=false;
         }
       });
+      if(available==true){
+        self.availableProxyConnectors.push(value);
+      }
+    });
 
     proxyConnectorMoved=function(arg){
       $.log("repositoryMoved:"+arg.sourceIndex+" to " + arg.targetIndex);
       self.proxyConnectorRule.modified(true);
-      ///arg.sourceParent.remove(arg.item);
-      //arg.targetParent.push(arg.item);
+      self.activateRemoveChoosen(self.proxyConnectorRulesViewModel);
     }
 
     saveProxyConnectorRule=function(){
-      $.log("pattern:"+self.proxyConnectorRule.pattern());
-      $.log("proxyConnectorRuleType:"+proxyConnectorRule.proxyConnectorRuleType());
-      $.log("proxyConnectors:"+proxyConnectorRule.proxyConnectors().length);
       self.proxyConnectorRulesViewModel.saveProxyConnectorRule(self.proxyConnectorRule)
     }
 
+    this.removeChoosen=function(proxyConnectorRulesViewModel,sourceRepoId,targetRepoId){
+      $.log("removeChoosen:"+sourceRepoId+":"+targetRepoId);
+
+      $.log("size before:"+self.proxyConnectorRule.proxyConnectors().length);
+      var proxyConnectorToRemove=null;
+      for(var i=0;i<self.proxyConnectorRule.proxyConnectors().length;i++){
+        if(self.proxyConnectorRule.proxyConnectors()[i].sourceRepoId()==sourceRepoId &&
+            self.proxyConnectorRule.proxyConnectors()[i].targetRepoId()==targetRepoId){
+          $.log("found");
+          proxyConnectorToRemove=self.proxyConnectorRule.proxyConnectors()[i];
+        }
+      }
+      self.proxyConnectorRule.proxyConnectors.remove(proxyConnectorToRemove);
+      self.availableProxyConnectors.push(proxyConnectorToRemove);
+      $.log("size after:"+self.proxyConnectorRule.proxyConnectors().length);
+    }
+
+    this.activateRemoveChoosen=function(proxyConnectorRulesViewModel){
+      $("#main-content" ).find("#proxy-connectors-rules-edit-order-div" ).find(".icon-minus-sign" ).on("click", function(){
+        self.removeChoosen(proxyConnectorRulesViewModel,$(this).attr("data-source-repoId"),$(this).attr("data-target-repoId"));
+      });
+    }
+
+    this.removeAvailable=function(proxyConnectorRulesViewModel,sourceRepoId,targetRepoId){
+      $.log("removeAvailable:"+sourceRepoId+":"+targetRepoId);
+
+      $.log("size before:"+self.availableProxyConnectors().length);
+      var proxyConnectorToAdd=null;
+      for(var i=0;i<self.availableProxyConnectors().length;i++){
+        if(self.availableProxyConnectors()[i].sourceRepoId()==sourceRepoId &&
+            self.availableProxyConnectors()[i].targetRepoId()==targetRepoId){
+          $.log("found");
+          proxyConnectorToAdd=self.availableProxyConnectors()[i];
+        }
+      }
+      self.proxyConnectorRule.proxyConnectors.push(proxyConnectorToAdd);
+      self.availableProxyConnectors.remove(proxyConnectorToAdd);
+      $.log("size after:"+self.proxyConnectorRule.proxyConnectors().length);
+    }
+
+    this.activateRemoveAvailable=function(proxyConnectorRulesViewModel){
+      $("#main-content" ).find("#proxy-connectors-rules-available-proxy-connectors" ).find(".icon-plus-sign" ).on("click", function(){
+        self.removeAvailable(proxyConnectorRulesViewModel,$(this).attr("data-source-repoId"),$(this).attr("data-target-repoId"));
+      });
+    }
+
   }
 
 
@@ -247,7 +303,6 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra
     //private String sourceRepoId;
     this.pattern=ko.observable(pattern);
     this.pattern.subscribe(function(newValue){
-      $.log("pattern modified");
       self.modified(true);
     });
 
index 4fe831774ebc738b17998d4cdb3316297f13f165..790d696caf8e187b4a4ad096cd4194d121c654f2 100644 (file)
             <div class="span6 dotted">
               <div id="proxy-connectors-rules-edit-div" data-bind='template:{name:"proxy-connectors-rules-edit-tmpl"}'></div>
               <div id="proxy-connectors-rules-edit-order-div" style="min-height: 80px"
-                 data-bind="sortable: { template: 'proxy-connectors-rules-edit-proxy-connectors-tmpl',data:proxyConnectorRule.proxyConnectors,afterMove:proxyConnectorMoved}">
+                 data-bind="sortable: { template: 'proxy-connectors-rules-edit-proxy-connectors-tmpl-choosen',data:proxyConnectorRule.proxyConnectors,afterMove:proxyConnectorMoved}">
               </div>
             </div>
 
             <div class="span6 dotted">
               <h5>${$.i18n.prop('proxy-connector-rules.available.proxyConnectors')}</h5>
               <br/>
-              <div id="proxy-connectors-rules-available-repositories" style="min-height: 80px"
-                   data-bind="sortable: { template: 'proxy-connectors-rules-edit-proxy-connectors-tmpl',data:availableProxyConnectors,afterMove:proxyConnectorMoved}">
+              <div id="proxy-connectors-rules-available-proxy-connectors" style="min-height: 80px"
+                   data-bind="sortable: { template: 'proxy-connectors-rules-edit-proxy-connectors-tmpl-availables',data:availableProxyConnectors,afterMove:proxyConnectorMoved}">
 
               </div>
             </div>
     </div>
 </script>
 
-<script id="proxy-connectors-rules-edit-proxy-connectors-tmpl" type="text/html">
-    <div class="well draggable-item">
-      <blockquote>
-        ${$data.sourceRepoId()} <-> ${$data.targetRepoId()}
-      </blockquote>
+<script id="proxy-connectors-rules-edit-proxy-connectors-tmpl-choosen" type="text/html">
+  <div class="well draggable-item">
+    <i class="icon-minus-sign cursor-hand pull-right" data-source-repoId="${$data.sourceRepoId()}" data-target-repoId="${$data.targetRepoId()}"/>
+    <blockquote>
+      ${$data.sourceRepoId()} <-> ${$data.targetRepoId()}
+    </blockquote>
 
-    </div>
+  </div>
+</script>
+
+<script id="proxy-connectors-rules-edit-proxy-connectors-tmpl-availables" type="text/html">
+  <div class="well draggable-item">
+    <i class="icon-plus-sign cursor-hand pull-right" data-source-repoId="${$data.sourceRepoId()}" data-target-repoId="${$data.targetRepoId()}"/>
+    <blockquote>
+      ${$data.sourceRepoId()} <-> ${$data.targetRepoId()}
+    </blockquote>
+
+  </div>
 </script>
\ No newline at end of file