]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1574] add managed repo now implemented.
authorOlivier Lamy <olamy@apache.org>
Mon, 16 Jan 2012 16:53:57 +0000 (16:53 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 16 Jan 2012 16:53:57 +0000 (16:53 +0000)
change the rest service to return the repo rather than a Boolean to have real path available in the ui.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1232062 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js

index 7e34d35c732a980843599e876c68183580d897dc..0f3ed07607321d061a9d7a20af891623656182b5 100644 (file)
@@ -68,7 +68,7 @@ public interface ManagedRepositoriesService
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
-    Boolean addManagedRepository( ManagedRepository managedRepository )
+    ManagedRepository addManagedRepository( ManagedRepository managedRepository )
         throws ArchivaRestServiceException;
 
 
index 9903a8e3bb871bafdc2269f32f1de272ce4ab480..a9f51284cfc849d3b4689961a528ef7b1f852818 100644 (file)
@@ -93,15 +93,20 @@ public class DefaultManagedRepositoriesService
         }
     }
 
-    public Boolean addManagedRepository( ManagedRepository managedRepository )
+    public ManagedRepository addManagedRepository( ManagedRepository managedRepository )
         throws ArchivaRestServiceException
     {
 
         try
         {
-            return managedRepositoryAdmin.addManagedRepository( managedRepository,
-                                                                managedRepository.isStageRepoNeeded(),
-                                                                getAuditInformation() );
+            boolean res =
+                managedRepositoryAdmin.addManagedRepository( managedRepository, managedRepository.isStageRepoNeeded(),
+                                                             getAuditInformation() );
+            if ( res )
+            {
+                return getManagedRepository( managedRepository.getId() );
+            }
+            throw new ArchivaRestServiceException( "fail to created managed Repository" );
         }
         catch ( RepositoryAdminException e )
         {
index e0472b2903ebf262470f1563a49392044bde25b1..45bfff92689cd2340b02ed2df5f8523973c82e4b 100644 (file)
@@ -67,10 +67,10 @@ $(function() {
     this.stageRepoNeeded=ko.observable(stageRepoNeeded);
   }
 
-  ManagedRepositoryViewModel=function(managedRepository, update){
+  ManagedRepositoryViewModel=function(managedRepository, update, managedRepositoriesViewModel){
     this.managedRepository=ko.observable(managedRepository);
+    this.managedRepositoriesViewModel = managedRepositoriesViewModel;
     this.update = update;
-
     save=function(){
       var valid = $("#main-content #managed-repository-edit-form").valid();
       if (valid==false) {
@@ -78,22 +78,41 @@ $(function() {
       }
       $.log("save:"+this.managedRepository().name());
       clearUserMessages();
-      $.ajax("restServices/archivaServices/managedRepositoriesService/updateManagedRepository",
-        {
-          type: "POST",
-          contentType: 'application/json',
-          data: "{\"managedRepository\": " +  ko.toJSON(this.managedRepository)+"}",
-          dataType: 'json',
-            success: function(data) {
-              displaySuccessMessage($.i18n.prop('managedrepository.updated'));
-            },
-            error: function(data) {
-              var res = $.parseJSON(data.responseText);
-              displayRestError(res);
-            }
-        }
-      );
-
+      if (this.update){
+        $.ajax("restServices/archivaServices/managedRepositoriesService/updateManagedRepository",
+          {
+            type: "POST",
+            contentType: 'application/json',
+            data: "{\"managedRepository\": " +  ko.toJSON(this.managedRepository)+"}",
+            dataType: 'json',
+              success: function(data) {
+                displaySuccessMessage($.i18n.prop('managedrepository.updated'));
+              },
+              error: function(data) {
+                var res = $.parseJSON(data.responseText);
+                displayRestError(res);
+              }
+          }
+        );
+      } else {
+        $.log("add managedRepo");
+        $.ajax("restServices/archivaServices/managedRepositoriesService/addManagedRepository",
+          {
+            type: "POST",
+            contentType: 'application/json',
+            data: "{\"managedRepository\": " +  ko.toJSON(this.managedRepository)+"}",
+            dataType: 'json',
+              success: function(data) {
+                this.managedRepositoriesViewModel.managedRepositories.push(mapManagedRepository(data));
+                displaySuccessMessage($.i18n.prop('managedrepository.added'));
+              },
+              error: function(data) {
+                var res = $.parseJSON(data.responseText);
+                displayRestError(res);
+              }
+          }
+        );
+      }
     }
 
     displayGrid=function(){
@@ -102,29 +121,34 @@ $(function() {
 
   }
 
+  activateManagedRepositoryFormValidation=function(){
+    $("#main-content #managed-repository-edit-form").validate({
+      rules: {
+        daysOlder : {
+          digits: true
+        },
+        retentionCount : {
+          digits: true
+        }
+      },
+      showErrors: function(validator, errorMap, errorList) {
+        customShowError(validator,errorMap,errorMap);
+      }
+    });
+  }
+
   ManagedRepositoriesViewModel=function(){
     this.managedRepositories=ko.observableArray(new Array());
 
     this.gridViewModel = null;
+    var self = this;
 
     editManagedRepository=function(managedRepository){
-      var viewModel = new ManagedRepositoryViewModel(managedRepository,true);
+      var viewModel = new ManagedRepositoryViewModel(managedRepository,true,self);
       ko.applyBindings(viewModel,$("#main-content #managed-repository-edit").get(0));
       activateManagedRepositoryEditTab();
       $("#managed-repository-edit-li a").html($.i18n.prop('edit'));
-      $("#main-content #managed-repository-edit-form").validate({
-        rules: {
-          daysOlder : {
-            digits: true
-          },
-          retentionCount : {
-            digits: true
-          }
-        },
-        showErrors: function(validator, errorMap, errorList) {
-          customShowError(validator,errorMap,errorMap);
-        }
-      });
+      activateManagedRepositoryFormValidation();
     }
 
   }
@@ -149,7 +173,7 @@ $(function() {
     clearUserMessages();
     $("#main-content").html(mediumSpinnerImg());
     $("#main-content").html($("#repositoriesMain").tmpl());
-    $("#repositories-tabs").tabs();
+    $("#main-content #repositories-tabs").tabs();
 
     $("#main-content #managed-repositories-content").append(mediumSpinnerImg());
     $("#main-content #remote-repositories-content").append(mediumSpinnerImg());
@@ -189,6 +213,18 @@ $(function() {
           removeMediumSpinnerImg("#main-content #managed-repositories-content");
           $("#main-content #managed-repositories-table [title]").twipsy();
           activateManagedRepositoriesGridTab();
+          $("#main-content #managed-repositories-pills").bind('change', function (e) {
+
+            if ($(e.target).attr("href")=="#managed-repository-edit") {
+              var viewModel = new ManagedRepositoryViewModel(new ManagedRepository(),false,managedRepositoriesViewModel);
+              ko.applyBindings(viewModel,$("#main-content #managed-repository-edit").get(0));
+              activateManagedRepositoryFormValidation();
+            }
+            if ($(e.target).attr("href")=="#managed-repositories-view") {
+              $("#main-content #managed-repository-edit-li a").html($.i18n.prop("add"));
+            }
+
+          });
         }
       }
     );