]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1576] rewrite proxies connector page
authorOlivier Lamy <olamy@apache.org>
Thu, 9 Feb 2012 23:07:15 +0000 (23:07 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 9 Feb 2012 23:07:15 +0000 (23:07 +0000)
add now works !

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1242593 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

index ec12e68322efcc65e74b81bbfd6ba7b64bcd53d8..b8dc2f91949e9a0e0c922ce698f6d5a5de6ddef1 100644 (file)
@@ -127,22 +127,15 @@ $(function() {
     this.proxyConnectorsViewModel=proxyConnectorsViewModel;
     this.update=update;
     this.modified=ko.observable(false);
-    getSelectedPolicyOption=function(id,updateVal){
-      $.log("getSelectedPolicyOption:"+id+","+updateVal);
-      if (!update){
-        // we are on add mode so use default option
-        var policyInformations=self.proxyConnectorsViewModel.policyInformations();
-        for (i=0;i<policyInformations.length;i++){
-          if (policyInformations[i].id()==id) {
-            return policyInformations[i].defaultOption;
-          }
-        }
-      }
-      var policies=self.proxyConnector().policies();
+    getSelectedPolicyOption=function(id){
+      $.log("getSelectedPolicyOption:"+id);
+
+      var policies=self.proxyConnector.policies();
+      $.log("getSelectedPolicyOption policies.length:"+policies.length);
       if (policies!=null){
-        for (i=0;i<policies().length;i++){
-          if (id==policies()[i].key()){
-            return policies()[i].value();
+        for (i=0;i<policies.length;i++){
+          if (id==policies[i].key()){
+            return policies[i].value();
           }
         }
       }
@@ -200,6 +193,37 @@ $(function() {
     removeWhitelistPattern=function(pattern){
       self.proxyConnector.whiteListPatterns.remove(pattern);
     }
+
+    save=function(){
+      //FIXME data controls !!!
+
+      if (this.update){
+
+      } else {
+        $.ajax("restServices/archivaServices/proxyConnectorService/addProxyConnector",
+          {
+            type: "POST",
+            data: "{\"proxyConnector\": " + ko.toJSON(self.proxyConnector)+"}",
+            contentType: 'application/json',
+            dataType: 'json',
+            success: function(data) {
+              displaySuccessMessage($.i18n.prop('proxyconnector.added'));
+              activateProxyConnectorsGridTab();
+              self.proxyConnector.modified(false);
+            },
+            error: function(data) {
+              var res = $.parseJSON(data.responseText);
+              displayRestError(res);
+            }
+          }
+        );
+
+      }
+    }
+
+    displayGrid=function(){
+      activateProxyConnectorsGridTab();
+    }
   }
 
   ProxyConnectorsViewModel=function(){
@@ -307,6 +331,13 @@ $(function() {
 
         if ($(e.target).attr("href")=="#proxy-connectors-edit") {
           var proxyConnector=new ProxyConnector();
+          var defaultPolicies=new Array();
+          // populate with defaut policies options
+          for (i=0;i<self.policyInformations().length;i++){
+            defaultPolicies.push(new Entry(self.policyInformations()[i].id(),self.policyInformations()[i].defaultOption));
+          }
+          proxyConnector.policies(defaultPolicies);
+          $.log("proxyConnector.policies().length:"+proxyConnector.policies().length);
           var proxyConnectorViewModel=new ProxyConnectorViewModel(proxyConnector,false,self);
           mainContent.find("#proxy-connectors-edit").html($("#proxy-connector-edit-form-tmpl").tmpl());
           ko.applyBindings(proxyConnectorViewModel,mainContent.find("#proxy-connectors-edit").get(0));
@@ -375,6 +406,26 @@ $(function() {
      });
   }
 
+  activateProxyConnectorsGridTab=function(){
+    var mainContent = $("#main-content");
+    mainContent.find("#proxy-connectors-edit").removeClass("active");
+    mainContent.find("#proxy-connectors-view-tabs-li-edit").removeClass("active");
+
+    mainContent.find("#proxy-connectors-view").addClass("active");
+    mainContent.find("#proxy-connectors-view-tabs-li-grid").addClass("active");
+    mainContent.find("#proxy-connectors-view-tabs-li-edit a").html($.i18n.prop("add"));
+
+  }
+
+  activateProxyConnectorsEditTab=function(){
+    var mainContent = $("#main-content");
+    mainContent.find("#proxy-connectors-edit").addClass("active");
+    mainContent.find("#proxy-connectors-view-tabs-li-edit").addClass("active");
+
+    mainContent.find("#proxy-connectors-view").removeClass("active");
+    mainContent.find("#proxy-connectors-view-tabs-li-grid").removeClass("active");
+  }
+
   mapProxyConnector=function(data){
     if (data==null){
       return null;
index d92395448c30a45d834bec652798baf1b71a1766..6635d40208d6c119c84c25ade4e386e6ac7cb9f9 100644 (file)
                   <tr>
                     <td data-bind="text: name"></td>
                     <td>
-                      <select id="policy-${policyId}"
-                              data-bind="options: getPolicyOptions(id()),value:getSelectedPolicyOption(id())"></select>
+                      <select data-bind="options: getPolicyOptions(id()),value:getSelectedPolicyOption(id()),attr: { id: 'policy-'+id() }"></select>
                     </td>
                   </tr>
               </tbody>
         </div>
 
       </fieldset>
+
+      <button id="proxy-connector-btn-save" data-bind="click: save" class="btn">${$.i18n.prop('save')}</button>
+      {{if modified()}}
+       ${("#network-proxy-btn-save").button('reset')}
+      {{/if}}
+      <button data-bind="click: displayGrid" class="btn">${$.i18n.prop('cancel')}</button>
+
     </form>
 
 </script>