]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1578] REST call for add/update network proxy
authorOlivier Lamy <olamy@apache.org>
Thu, 26 Jan 2012 22:57:48 +0000 (22:57 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 26 Jan 2012 22:57:48 +0000 (22:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1236436 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/repositories.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/network-proxies.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js

index d3b1df30f85f86bcb6ae88de5d3bd6cafa739eac..75a0b828579f37c72c00b05c9d4a4822b7ab0d7a 100644 (file)
@@ -50,7 +50,48 @@ $(function() {
     var self=this;
 
     save=function(){
+      if (!$("#main-content #network-proxy-edit-form").valid()){
+        return;
+      }
+      clearUserMessages();
+      if (update){
+        $.ajax("restServices/archivaServices/networkProxyService/updateNetworkProxy",
+          {
+            type: "POST",
+            contentType: 'application/json',
+            data: "{\"networkProxy\": " + ko.toJSON(networkProxy)+"}",
+            dataType: 'json',
+            success: function(data) {
+              displaySuccessMessage($.i18n.prop('networkproxy.updated'));
+              activateNetworkProxiesGridTab();
+            },
+            error: function(data) {
+              var res = $.parseJSON(data.responseText);
+              displayRestError(res);
+            }
+          }
+        );
+      } else {
+
+        $.ajax("restServices/archivaServices/networkProxyService/addNetworkProxy",
+          {
+            type: "POST",
+            contentType: 'application/json',
+            data: "{\"networkProxy\": " + ko.toJSON(networkProxy)+"}",
+            dataType: 'json',
+            success: function(data) {
+              self.networkProxiesViewModel.networkProxies.push(self.networkProxy);
+              displaySuccessMessage($.i18n.prop('networkproxy.added'));
+              activateNetworkProxiesGridTab();
+            },
+            error: function(data) {
+              var res = $.parseJSON(data.responseText);
+              displayRestError(res);
+            }
+          }
+        );
 
+      }
     }
 
     displayGrid=function(){
@@ -66,7 +107,12 @@ $(function() {
     this.gridViewModel = null;
 
     editNetworkProxy=function(networkProxy){
+      $.log("editNetworkProxy");
       $("#main-content #network-proxies-edit a").html($.i18n.prop("edit"));
+      var viewModel = new NetworkProxyViewModel(networkProxy,true,self);
+      ko.applyBindings(viewModel,$("#main-content #network-proxies-edit").get(0));
+      activateNetworkProxyFormValidation();
+      activateNetworkProxyEditTab();
     }
 
     removeNetworkProxy=function(networkProxy){
@@ -87,7 +133,7 @@ $(function() {
       if ($(e.target).attr("href")=="#network-proxies-edit") {
         var viewModel = new NetworkProxyViewModel(new NetworkProxy(),false,networkProxiesViewModel);
         ko.applyBindings(viewModel,$("#main-content #network-proxies-edit").get(0));
-        //activateManagedRepositoryFormValidation();
+        activateNetworkProxyFormValidation();
       }
       if ($(e.target).attr("href")=="#network-proxies-view") {
         $("#main-content #network-proxies-edit a").html($.i18n.prop("add"));
@@ -141,21 +187,26 @@ $(function() {
     );
   }
 
+  activateNetworkProxyFormValidation=function(){
+    $("#main-content #network-proxy-edit-form").validate();
+  }
+
   activateNetworkProxiesGridTab=function(){
     $("#main-content #network-proxies-view-tabs-li-edit").removeClass("active");
     $("#main-content #network-proxies-edit").removeClass("active");
-    // activate roles grid tab
+
     $("#main-content #network-proxies-view-tabs-li-grid").addClass("active");
     $("#main-content #network-proxies-view").addClass("active");
     $("#main-content #network-proxies-view-tabs-li-edit a").html($.i18n.prop("add"));
   }
 
   activateNetworkProxyEditTab=function(){
-    $("#main-content #remote-repositories-view-li").removeClass("active");
-    $("#main-content #remote-repositories-view").removeClass("active");
-    // activate role edit tab
-    $("#main-content #remote-repository-edit-li").addClass("active");
-    $("#main-content #remote-repository-edit").addClass("active");
+    $("#main-content #network-proxies-view-tabs-li-grid").removeClass("active");
+    $("#main-content #network-proxies-view").removeClass("active");
+
+    $("#main-content #network-proxies-view-tabs-li-edit").addClass("active");
+    $("#main-content #network-proxies-edit").addClass("active");
+
   }
 
   mapNetworkProxy=function(data){
index 4585adf6e8fc5120a39a93ffa3cbada6d31f6b5a..7ced787c06e88508e27fc9b6c010dc8370512edb 100644 (file)
@@ -431,7 +431,7 @@ $(function() {
   activateManagedRepositoriesGridTab=function(){
     $("#main-content #managed-repository-edit-li").removeClass("active");
     $("#main-content #managed-repository-edit").removeClass("active");
-    // activate roles grid tab
+
     $("#main-content #managed-repositories-view-li").addClass("active");
     $("#main-content #managed-repositories-view").addClass("active");
     $("#main-content #managed-repository-edit-li a").html($.i18n.prop("add"));
@@ -440,7 +440,7 @@ $(function() {
   activateManagedRepositoryEditTab=function(){
     $("#main-content #managed-repositories-view-li").removeClass("active");
     $("#main-content #managed-repositories-view").removeClass("active");
-    // activate role edit tab
+
     $("#main-content #managed-repository-edit-li").addClass("active");
     $("#main-content #managed-repository-edit").addClass("active");
   }
@@ -676,7 +676,7 @@ $(function() {
   activateRemoteRepositoriesGridTab=function(){
     $("#main-content #remote-repository-edit-li").removeClass("active");
     $("#main-content #remote-repository-edit").removeClass("active");
-    // activate roles grid tab
+
     $("#main-content #remote-repositories-view-li").addClass("active");
     $("#main-content #remote-repositories-view").addClass("active");
     $("#main-content #remote-repository-edit-li a").html($.i18n.prop("add"));
@@ -685,7 +685,7 @@ $(function() {
   activateRemoteRepositoryEditTab=function(){
     $("#main-content #remote-repositories-view-li").removeClass("active");
     $("#main-content #remote-repositories-view").removeClass("active");
-    // activate role edit tab
+
     $("#main-content #remote-repository-edit-li").addClass("active");
     $("#main-content #remote-repository-edit").addClass("active");
   }
index dddf3ab7c8cd368d01b900dfdb6f3f7612e40d54..50cf35e43334013ffb5f85975450d8e020c34f00 100644 (file)
         <div class="clearfix">
           <label for="port">${$.i18n.prop('port')}</label>
           <div class="input">
-            <input type="text" class="xlarge required" id="port" name="port" size="6"
+            <input type="text" class="xlarge required digits" id="port" name="port" size="6"
                    data-bind="value: networkProxy.port"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="username">${$.i18n.prop('username')}</label>
           <div class="input">
-            <input type="text" class="xlarge required" id="username" name="username" size="50"
+            <input type="text" class="xlarge" id="username" name="username" size="50"
                    data-bind="value: networkProxy.username"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="password">${$.i18n.prop('password')}</label>
           <div class="input">
-            <input type="text" class="xlarge required" id="password" name="password" size="50"
+            <input type="text" class="xlarge" id="password" name="password" size="50"
                    data-bind="value: networkProxy.password"/>
           </div>
         </div>
index ab239c74e6b8b7fc7bbe075269b08c7e46a18a68..eb5c4c1a13b5313aadba15147d69a3f8eeb5fb9c 100644 (file)
@@ -34,7 +34,8 @@ $(function() {
    * @param passwordChangeRequired
    * @param ownerViewModel
    */
-  User=function(username, password, confirmPassword,fullName,email,permanent,validated,timestampAccountCreation,timestampLastLogin,timestampLastPasswordChange,locked,passwordChangeRequired,ownerViewModel) {
+  User=function(username, password, confirmPassword,fullName,email,permanent,validated,timestampAccountCreation,
+                timestampLastLogin,timestampLastPasswordChange,locked,passwordChangeRequired,ownerViewModel) {
       // Potentially Editable Field.
       this.username = ko.observable(username);
       // Editable Fields.
@@ -630,7 +631,9 @@ $(function() {
    * @param data User response from redback rest api
    */
   mapUser=function(data) {
-    return new User(data.username, data.password, null,data.fullName,data.email,data.permanent,data.validated,data.timestampAccountCreation,data.timestampLastLogin,data.timestampLastPasswordChange,data.locked,data.passwordChangeRequired,self);
+    return new User(data.username, data.password, null,data.fullName,data.email,data.permanent,data.validated,
+                    data.timestampAccountCreation,data.timestampLastLogin,data.timestampLastPasswordChange,
+                    data.locked,data.passwordChangeRequired,self);
   }