From bc5654c3318eac28a66c41878c49d6e4d42b3259 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 26 Jan 2012 22:57:48 +0000 Subject: [PATCH] [MRM-1578] REST call for add/update network proxy git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1236436 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/webapp/js/archiva/network-proxies.js | 65 +++++++++++++++++-- .../main/webapp/js/archiva/repositories.js | 8 +-- .../js/archiva/templates/network-proxies.html | 6 +- .../src/main/webapp/js/redback/user.js | 7 +- 4 files changed, 70 insertions(+), 16 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js index d3b1df30f..75a0b8285 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js @@ -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){ diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js index 4585adf6e..7ced787c0 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js @@ -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"); } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/network-proxies.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/network-proxies.html index dddf3ab7c..50cf35e43 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/network-proxies.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/network-proxies.html @@ -86,21 +86,21 @@
-
-
-
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js index ab239c74e..eb5c4c1a1 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js @@ -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); } -- 2.39.5