]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1574] fix issue after add: the new repository was not correctly displayed in...
authorOlivier Lamy <olamy@apache.org>
Mon, 16 Jan 2012 22:57:18 +0000 (22:57 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 16 Jan 2012 22:57:18 +0000 (22:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1232214 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.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/repositories.html

index ddbce533f361a0fab66fb1f19a7b5de50e841e45..bde8281edf81badc3bddbc03392478a3476afb5d 100644 (file)
@@ -26,6 +26,9 @@ $(function() {
     cache: false
   } );
 
+  // define a container object with various datas
+  window.archivaModel = {};
+
   /**
    * reccord a cookie for session with the logged user
    * @param user see user.js
index 4b8b0df378447d692d680118b7ff377149a3ca3d..86ae953e797d33a0d7dc716bd26305448513fcda 100644 (file)
@@ -37,49 +37,50 @@ $(function() {
     //private String location;
     this.location=ko.observable(location);
 
-    //private boolean snapshots = false;
-    this.snapshots=ko.observable(snapshots);
-
-    //private boolean releases = true;
-    this.releases=ko.observable(releases);
-
-    //private boolean blockRedeployments = false;
-    this.blockRedeployments=ko.observable(blockRedeployments);
-
     //private String cronExpression = "0 0 * * * ?";
     this.cronExpression=ko.observable(cronExpression);
 
     //private ManagedRepository stagingRepository;
 
-    //private boolean scanned = false;
-    this.scanned=ko.observable(scanned);
-
     //private int daysOlder = 100;
     this.daysOlder=ko.observable(daysOlder);
 
     //private int retentionCount = 2;
     this.retentionCount=ko.observable(retentionCount);
 
+    //private boolean scanned = false;
+    this.scanned=ko.observable(scanned);
+
     //private boolean deleteReleasedSnapshots;
     this.deleteReleasedSnapshots=ko.observable(deleteReleasedSnapshots);
 
     //private boolean stageRepoNeeded;
     this.stageRepoNeeded=ko.observable(stageRepoNeeded);
 
+    //private boolean snapshots = false;
+    this.snapshots=ko.observable(snapshots);
+
+    //private boolean releases = true;
+    this.releases=ko.observable(releases);
+
+    //private boolean blockRedeployments = false;
+    this.blockRedeployments=ko.observable(blockRedeployments);
+
 
   }
 
   ManagedRepositoryViewModel=function(managedRepository, update, managedRepositoriesViewModel){
-    this.managedRepository=ko.observable(managedRepository);
+    this.managedRepository=managedRepository;
     this.managedRepositoriesViewModel = managedRepositoriesViewModel;
     this.update = update;
     var self = this;
+    var currentManagedRepository = this.managedRepository;
     save=function(){
       var valid = $("#main-content #managed-repository-edit-form").valid();
       if (valid==false) {
           return;
       }
-      $.log("save:"+this.managedRepository().name());
+      $.log("save:"+this.managedRepository.name());
       clearUserMessages();
       if (this.update){
         $.ajax("restServices/archivaServices/managedRepositoriesService/updateManagedRepository",
@@ -90,6 +91,7 @@ $(function() {
             dataType: 'json',
               success: function(data) {
                 displaySuccessMessage($.i18n.prop('managedrepository.updated'));
+                activateManagedRepositoriesGridTab();
               },
               error: function(data) {
                 var res = $.parseJSON(data.responseText);
@@ -99,20 +101,24 @@ $(function() {
         );
       } else {
         $.log("add managedRepo");
+
         $.ajax("restServices/archivaServices/managedRepositoriesService/addManagedRepository",
           {
             type: "POST",
             contentType: 'application/json',
-            data: "{\"managedRepository\": " +  ko.toJSON(this.managedRepository)+"}",
+            data: "{\"managedRepository\": " + ko.toJSON(currentManagedRepository)+"}",
             dataType: 'json',
-              success: function(data) {
-                self.managedRepositoriesViewModel.managedRepositories.push(mapManagedRepository(data));
-                displaySuccessMessage($.i18n.prop('managedrepository.added'));
-              },
-              error: function(data) {
-                var res = $.parseJSON(data.responseText);
-                displayRestError(res);
-              }
+            success: function(data) {
+              //var repo = mapManagedRepository(data);
+              //$.log("data:"+repo.name);
+              self.managedRepositoriesViewModel.managedRepositories.push(currentManagedRepository);
+              displaySuccessMessage($.i18n.prop('managedrepository.added'));
+              activateManagedRepositoriesGridTab();
+            },
+            error: function(data) {
+              var res = $.parseJSON(data.responseText);
+              displayRestError(res);
+            }
           }
         );
       }
@@ -141,7 +147,7 @@ $(function() {
   }
 
   ManagedRepositoriesViewModel=function(){
-    this.managedRepositories=ko.observableArray(new Array());
+    this.managedRepositories=ko.observableArray([]);
 
     this.gridViewModel = null;
     var self = this;
@@ -158,6 +164,7 @@ $(function() {
       clearUserMessages();
       openDialogConfirm(
           function(){
+            $("#dialog-confirm-modal #modal-login-footer").append(smallSpinnerImg());
             var url = "restServices/archivaServices/managedRepositoriesService/deleteManagedRepository?";
             url += "repositoryId="+encodeURIComponent(managedRepository.id());
 
@@ -177,6 +184,7 @@ $(function() {
                     displayRestError(res);
                   },
                   complete: function(){
+                    removeSmallSpinnerImg();
                     closeDialogConfirm();
                   }
               }
@@ -193,22 +201,6 @@ $(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");
-  }
-
-  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");
-  }
-
   displayRepositoriesGrid=function(){
     clearUserMessages();
     $("#main-content").html(mediumSpinnerImg());
@@ -218,14 +210,12 @@ $(function() {
     $("#main-content #managed-repositories-content").append(mediumSpinnerImg());
     $("#main-content #remote-repositories-content").append(mediumSpinnerImg());
 
-
+    var managedRepositoriesViewModel = new ManagedRepositoriesViewModel();
 
     $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", {
         type: "GET",
         dataType: 'json',
         success: function(data) {
-
-          var managedRepositoriesViewModel = new ManagedRepositoriesViewModel();
           managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data));
           managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({
             data: managedRepositoriesViewModel.managedRepositories,
@@ -253,22 +243,22 @@ $(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"));
-            }
-
-          });
         }
       }
     );
 
+    $("#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"));
+      }
+
+    });
+
   }
 
   mapManagedRepositories=function(data){
@@ -284,4 +274,21 @@ $(function() {
                                  data.scanned,data.daysOlder,data.retentionCount,data.deleteReleasedSnapshots,data.stageRepoNeeded);
   }
 
+  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"));
+  }
+
+  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");
+  }
+
 });
\ No newline at end of file
index d1c36dce0d0ae30666e9c5a167491e7f42dc5b5d..95375527edff90267feb9acc0d7fac1448b8b319 100644 (file)
               {{/if}}
             </td>
             <td><a href="#" data-bind="click: function(){ editManagedRepository(row) }">${$.i18n.prop('edit')}</a></td>
-            <td><a href="#" data-bind="click: function(){ removeManagedRepository(row) }">${$.i18n.prop('delete')}</a></td>
+            <td>
+              <a href="#" data-bind="click: function(){ removeManagedRepository(row) }">
+                <img src="images/delete.png" title="${$.i18n.prop('delete')}"/>
+              </a>
+            </td>
           </tr>
       {{/each}}
   </tbody>
           <label for="name">${$.i18n.prop('id')}</label>
           <div class="input">
             {{if update}}
-              <span class="uneditable-input">${$data.managedRepository().id}</span>
+              <span class="uneditable-input">${$data.managedRepository.id}</span>
             {{else}}
               <input type="text" class="xlarge required" id="id" name="id" size="50"
-                     data-bind="value: managedRepository().id,css:{'uneditable-input': update},readonly:update"/>
+                     data-bind="value: managedRepository.id,css:{'uneditable-input': update},readonly:update"/>
             {{/if}}
           </div>
         </div>
           <label for="name">${$.i18n.prop('name')}</label>
           <div class="input">
             <input type="text" class="xlarge required" id="name" name="name" size="50"
-                   data-bind="value: managedRepository().name"/>
+                   data-bind="value: managedRepository.name"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="location">${$.i18n.prop('directory')}</label>
           <div class="input">
-            <input type="text" class="xlarge required" id="location" name="location" size="50" data-bind="value: managedRepository().location"/>
+            <input type="text" class="xlarge required" id="location" name="location" size="50" data-bind="value: managedRepository.location"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="indexDirectory">${$.i18n.prop('index.directory')}</label>
           <div class="input">
-            <input type="text" class="xlarge" id="indexDirectory" name="indexDirectory" size="50" data-bind="value: managedRepository().indexDirectory"/>
+            <input type="text" class="xlarge" id="indexDirectory" name="indexDirectory" size="50" data-bind="value: managedRepository.indexDirectory"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="cronExpression">${$.i18n.prop('cronExpression')}</label>
           <div class="input">
-            <input type="text" id="cronExpression" class="required" name="cronExpression" size="40" data-bind="value: managedRepository().cronExpression"/>
+            <input type="text" id="cronExpression" class="required" name="cronExpression" size="40" data-bind="value: managedRepository.cronExpression"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="daysOlder">${$.i18n.prop('daysOlder')}</label>
           <div class="input">
-            <input type="text" id="daysOlder" class="digits" name="daysOlder" size="5" data-bind="value: managedRepository().daysOlder"/>
+            <input type="text" id="daysOlder" class="digits" name="daysOlder" size="5" data-bind="value: managedRepository.daysOlder"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="retentionCount">${$.i18n.prop('retentionCount')}</label>
           <div class="input">
-            <input type="text" id="retentionCount" name="retentionCount" size="5" data-bind="value: managedRepository().retentionCount"/>
+            <input type="text" id="retentionCount" name="retentionCount" size="5" data-bind="value: managedRepository.retentionCount"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="releases">${$.i18n.prop('releases')}</label>
           <div class="input">
-            <input type="checkbox" id="releases" name="releases" size="5" data-bind="checked: managedRepository().releases"/>
+            <input type="checkbox" id="releases" name="releases" size="5" data-bind="checked: managedRepository.releases"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="snapshots">${$.i18n.prop('snapshots')}</label>
           <div class="input">
-            <input type="checkbox" id="snapshots" name="snapshots" size="5" data-bind="checked: managedRepository().snapshots"/>
+            <input type="checkbox" id="snapshots" name="snapshots" size="5" data-bind="checked: managedRepository.snapshots"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="blockRedeployments">${$.i18n.prop('blockRedeployments')}</label>
           <div class="input">
-            <input type="checkbox" id="blockRedeployments" name="blockRedeployments" size="5" data-bind="checked: managedRepository().blockRedeployments"/>
+            <input type="checkbox" id="blockRedeployments" name="blockRedeployments" size="5" data-bind="checked: managedRepository.blockRedeployments"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="scanned">${$.i18n.prop('scanned')}</label>
           <div class="input">
-            <input type="checkbox" id="scanned" name="scanned" size="5" data-bind="checked: managedRepository().scanned"/>
+            <input type="checkbox" id="scanned" name="scanned" size="5" data-bind="checked: managedRepository.scanned"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="deleteReleasedSnapshots">${$.i18n.prop('deleteReleasedSnapshots')}</label>
           <div class="input">
-            <input type="checkbox" id="deleteReleasedSnapshots" name="deleteReleasedSnapshots" size="5" data-bind="checked: managedRepository().deleteReleasedSnapshots"/>
+            <input type="checkbox" id="deleteReleasedSnapshots" name="deleteReleasedSnapshots" size="5"
+                   data-bind="checked: managedRepository.deleteReleasedSnapshots"/>
           </div>
         </div>
         <div class="clearfix">
           <label for="stageRepoNeeded">${$.i18n.prop('stageRepoNeeded')}</label>
           <div class="input">
-            <input type="checkbox" id="stageRepoNeeded" name="stageRepoNeeded" size="5" data-bind="checked: managedRepository().stageRepoNeeded"/>
+            <input type="checkbox" id="stageRepoNeeded" name="stageRepoNeeded" size="5"
+                   data-bind="checked: managedRepository.stageRepoNeeded"/>
           </div>
         </div>
       </fieldset>