]> source.dussan.org Git - archiva.git/commitdiff
add a bulk update mode. Users can update more than one network proxy and save all...
authorOlivier Lamy <olamy@apache.org>
Tue, 31 Jan 2012 14:40:57 +0000 (14:40 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 31 Jan 2012 14:40:57 +0000 (14:40 +0000)
BTW to do for other screens :-)

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1238622 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/templates/network-proxies.html

index 8f5f8544d0765fd1f24e6ab07fe39d652ab84e6b..893fdf1475c218ad7cb809e18c9bf4ecc66661b0 100644 (file)
@@ -48,17 +48,20 @@ $(function() {
     this.modified=ko.observable(false);
   }
 
-  NetworkProxyViewModel=function(networkProxy, update, networkProxiesViewModel){
+  NetworkProxyViewModel=function(networkProxy, update, networkProxiesViewModel,bulkMode){
     this.update=update;
     this.networkProxy=networkProxy;
     this.networkProxiesViewModel=networkProxiesViewModel;
     var self=this;
+    this.bulkMode=false || bulkMode;
 
     this.save=function(){
       if (!$("#main-content #network-proxy-edit-form").valid()){
         return;
       }
-      clearUserMessages();
+      if (!this.bulkMode){
+        clearUserMessages();
+      }
       if (update){
         $.ajax("restServices/archivaServices/networkProxyService/updateNetworkProxy",
           {
@@ -69,7 +72,9 @@ $(function() {
             success: function(data) {
               displaySuccessMessage($.i18n.prop('networkproxy.updated',self.networkProxy.id()));
               self.networkProxy.modified(false);
-              activateNetworkProxiesGridTab();
+              if (!this.bulkMode){
+                activateNetworkProxiesGridTab();
+              }
             },
             error: function(data) {
               var res = $.parseJSON(data.responseText);
@@ -121,8 +126,29 @@ $(function() {
       activateNetworkProxyEditTab();
     }
 
+    this.bulkSave=function(){
+      return getModifiedNetworkProxies().length>0;
+    }
+
+    getModifiedNetworkProxies=function(){
+      var prx = $.grep(self.networkProxies(),
+          function (networkProxy,i) {
+            $.log("networkProxy.modified():"+networkProxy.modified())
+            return networkProxy.modified();
+          });
+      return prx;
+    }
+
+    updateNetworkProxies=function(){
+      var modifiedNetworkProxies = getModifiedNetworkProxies();
+      for(i=0;i<modifiedNetworkProxies.length;i++){
+        var viewModel = new NetworkProxyViewModel(modifiedNetworkProxies[i],true,self,false);
+        viewModel.save();
+      }
+    }
+
     updateNetworkProxy=function(networkProxy){
-      var viewModel = new NetworkProxyViewModel(networkProxy,true,self);
+      var viewModel = new NetworkProxyViewModel(networkProxy,true,self,false);
       viewModel.save();
     }
 
@@ -210,6 +236,7 @@ $(function() {
             }
           });
           ko.applyBindings(networkProxiesViewModel,$("#main-content #networkProxiesTable").get(0));
+          ko.applyBindings(networkProxiesViewModel,$("#main-content #network-proxies-bulk-save-btn").get(0));
         }
       }
     );
index 5ffaa40512d53fa88cc0ee06151bf52b56ab74c4..a517d1843d92e51f3e968cffea18e31fd267ed0c 100644 (file)
@@ -31,6 +31,7 @@
   </ul>
   <div id="network-proxies-view-tabs-content" class="tab-content">
     <div id="network-proxies-view" class="active">
+        <div id="network-proxies-bulk-save-btn" data-bind='template:{name:"network-proxies-bulk-save-tmpl"}'></div>
         <table class="bordered-table zebra-striped" id="networkProxiesTable"
                data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko-network-proxies-grid',pageLinksId:'network-proxiesPagination'">
         </table>
       <button data-bind="click: save" class="btn">${$.i18n.prop('save')}</button>
       <button data-bind="click: displayGrid" class="btn">${$.i18n.prop('cancel')}</button>
     </form>
+</script>
+
+<script id="network-proxies-bulk-save-tmpl" type='text/x-jquery-tmpl'>
+  {{if bulkSave()}}
+    <button data-bind="click: updateNetworkProxies" class="btn">${$.i18n.prop('save.all')}</button>
+  {{/if}}
 </script>
\ No newline at end of file