]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1577] rewrite legacy path admin page
authorOlivier Lamy <olamy@apache.org>
Tue, 6 Mar 2012 18:32:06 +0000 (18:32 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 6 Mar 2012 18:32:06 +0000 (18:32 +0000)
add ok.

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

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js

index 495be22a8b7fbce60d2e6d56924fe64dd7031419..0d5a821721114bfda6b12d3b4d2c084b41aa2636 100644 (file)
@@ -72,7 +72,7 @@ public class DefaultArchivaAdministrationService
         throws ArchivaRestServiceException
     {
 
-        // Check the proposed Artifact macthes the path
+        // Check the proposed Artifact matches the path
         ArtifactReference artifact = new ArtifactReference();
 
         artifact.setGroupId( legacyArtifactPath.getGroupId() );
index 53907404cded054636d795c11974b196c4d6e669..b74afdf94b578ab87d9d239ae0ac284abcd2157b 100644 (file)
@@ -22,7 +22,7 @@ $(function() {
   // legacy path part
   //-------------------------
 
-  LegacyArtifactPath=function(path,groupId,artifactId,version,classifier,type){
+  LegacyArtifactPath=function(path,groupId,artifactId,version,classifier,type,update){
     //private String path;
     this.path=ko.observable(path);
 
@@ -32,7 +32,7 @@ $(function() {
      */
     //private String artifact;
     //this.artifact=ko.observable(artifact);
-
+    this.update=update;
     //private String groupId;
     this.groupId=ko.observable(groupId);
 
@@ -84,7 +84,97 @@ $(function() {
     return data?new LegacyArtifactPath(data.path,data.groupId,data.artifactId,data.version,data.classifier,data.type):null;
   }
 
-  LegacyPathViewModel=function(){
+  activateLegacyArtifactPathFormValidation=function(){
+    var theForm=$("#main-content #legacy-artifact-paths-edit-form");
+    var validator = theForm.validate({
+      showErrors: function(validator, errorMap, errorList) {
+       customShowError("#main-content #legacy-artifact-paths-edit-form",validator,errorMap,errorMap);
+      }
+    });
+  }
+
+  LegacyArtifactPathViewModel=function(legacyArtifactPath,update,legacyArtifactPathsViewModel){
+    var self=this;
+    this.update=update;
+    this.legacyArtifactPath=legacyArtifactPath;
+    this.legacyArtifactPathsViewModel=legacyArtifactPathsViewModel;
+
+    this.display=function(){
+      var mainContent=$("#main-content");
+      ko.applyBindings(self,mainContent.find("#legacy-artifact-paths-edit" ).get(0));
+      mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("edit"));
+      activateLegacyArtifactPathFormValidation();
+      activateLegacyArtifactPathsEditTab();
+    }
+
+    displayGrid=function(){
+      activateLegacyArtifactPathsGridTab();
+    }
+
+    calculatePath=function(){
+      var path="";
+      if (self.legacyArtifactPath.groupId()){
+        path+=self.legacyArtifactPath.groupId()+"/jars/";
+      }
+      if (self.legacyArtifactPath.artifactId()){
+        path+=self.legacyArtifactPath.artifactId();
+      }
+      if (self.legacyArtifactPath.version()){
+        path+="-"+self.legacyArtifactPath.version();
+      }
+      if (self.legacyArtifactPath.classifier()){
+        path+="-"+self.legacyArtifactPath.classifier();
+      }
+      if (self.legacyArtifactPath.type()){
+        path+="."+self.legacyArtifactPath.type();
+      }
+      self.legacyArtifactPath.path(path);
+    }
+
+    this.save=function(){
+      var theForm=$("#main-content #legacy-artifact-paths-edit-form");
+      if (!theForm.valid()){
+        return;
+      }
+      // do that on server side
+      /*if (theForm.find("#artifact" ).val()
+          !=theForm.find("#path" ).val()){
+        var errorList=[{
+          message: $.i18n.prop("path must match artifact"),
+                 element: theForm.find("#path" ).get(0)
+        }];
+        customShowError("#main-content #legacy-artifact-paths-edit-form", null, null, errorList);
+        return;
+      }*/
+      // TODO call id exists if add ?
+      clearUserMessages();
+      $.log("save ok");
+      if (self.update){
+        $.log("update");
+      }else {
+        $.ajax("restServices/archivaServices/archivaAdministrationService/addLegacyArtifactPath",
+          {
+            type: "POST",
+            contentType: 'application/json',
+            data: ko.toJSON(self.legacyArtifactPath),
+            dataType: 'json',
+            success: function(data) {
+              self.legacyArtifactPath.modified(false);
+              self.legacyArtifactPathsViewModel.legacyArtifactPaths.push(self.legacyArtifactPath);
+              displaySuccessMessage($.i18n.prop('legacy-artifact-path.added',self.legacyArtifactPath.path()));
+              activateLegacyArtifactPathsGridTab();
+            },
+            error: function(data) {
+              var res = $.parseJSON(data.responseText);
+              displayRestError(res);
+            }
+          }
+        );
+      }
+    }
+  }
+
+  LegacyArtifactPathsViewModel=function(){
     var self=this;
     this.legacyArtifactPaths=ko.observableArray([]);
 
@@ -108,7 +198,8 @@ $(function() {
 
 
     editLegacyArtifactPath=function(legacyArtifactPath){
-
+      var legacyArtifactPathViewModel=new LegacyArtifactPathViewModel(legacyArtifactPath,true);
+      legacyArtifactPathViewModel.display();
     }
 
     removeLegacyArtifactPath=function(legacyArtifactPath){
@@ -131,11 +222,27 @@ $(function() {
         type: "GET",
         dataType: 'json',
         success: function(data){
-          var legacyPathViewModel=new LegacyPathViewModel();
+          var legacyArtifactPathsViewModel=new LegacyArtifactPathsViewModel();
           var legacyPaths=mapLegacyArtifactPaths(data);
           $.log("legacyPaths:"+legacyPaths.length);
-          legacyPathViewModel.legacyArtifactPaths(legacyPaths);
-          ko.applyBindings(legacyPathViewModel,mainContent.find("#legacy-artifact-paths-view" ).get(0));
+          legacyArtifactPathsViewModel.legacyArtifactPaths(legacyPaths);
+          ko.applyBindings(legacyArtifactPathsViewModel,mainContent.find("#legacy-artifact-paths-view" ).get(0));
+
+          mainContent.find("#legacy-artifact-paths-view-tabs").on('show', function (e) {
+            if ($(e.target).attr("href")=="#legacy-artifact-paths-edit") {
+              var viewModel = new LegacyArtifactPathViewModel(new LegacyArtifactPath(),false,legacyArtifactPathsViewModel);
+              viewModel.display();
+              activateLegacyArtifactPathFormValidation();
+              clearUserMessages();
+            }
+            if ($(e.target).attr("href")=="#legacy-artifact-paths-view") {
+              mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("add"));
+              clearUserMessages();
+            }
+
+          });
+
+
           activateLegacyArtifactPathsGridTab();
         }
     });
index 9ebecb04e737784a8f3f98f2c51906c8043c48ff..9a39acc8d571bb0b6e3c180c794802f05acc5644 100644 (file)
@@ -37,7 +37,7 @@
            </table>
            <div id="legacy-artifact-pathsPagination"></div>
        </div>
-       <div id="network-proxies-edit" class="tab-pane" data-bind='template: {name:"legacy-artifact-paths-edit-tmpl"}'></div>
+       <div id="legacy-artifact-paths-edit" class="tab-pane" data-bind='template: {name:"legacy-artifact-paths-edit-tmpl"}'></div>
      </div>
  </div>
 </script>
 
 </script>
 
+<script id="legacy-artifact-paths-edit-tmpl" type="text/html">
+    <form id="legacy-artifact-paths-edit-form" class="well form-horizontal">
+      <fieldset id="legacy-artifact-paths-edit-fieldset">
+        <div class="control-group">
+          <label class="control-label" for="groupId">${$.i18n.prop('legacy-artifact-paths.groupId')}</label>
+          <div class="controls">
+            <input type="text" class="xlarge required" id="groupId" name="groupId" size="8"
+                   data-bind="value: legacyArtifactPath.groupId"/>
+          </div>
+        </div>
+        <div class="control-group">
+          <label class="control-label" for="artifactId">${$.i18n.prop('legacy-artifact-paths.artifactId')}</label>
+          <div class="controls">
+            <input type="text" class="xlarge required" id="artifactId" name="artifactId" size="8"
+                   data-bind="value: legacyArtifactPath.artifactId"/>
+          </div>
+        </div>
+        <div class="control-group">
+          <label class="control-label" for="version">${$.i18n.prop('legacy-artifact-paths.version')}</label>
+          <div class="controls">
+            <input type="text" class="xlarge required" id="version" name="version" size="8"
+                   data-bind="value: legacyArtifactPath.version"/>
+          </div>
+        </div>
+        <div class="control-group">
+          <label class="control-label" for="classifier">${$.i18n.prop('legacy-artifact-paths.classifier')}</label>
+          <div class="controls">
+            <input type="text" class="xlarge" id="classifier" name="classifier" size="8"
+                   data-bind="value: legacyArtifactPath.classifier"/>
+          </div>
+        </div>
+        <div class="control-group">
+          <label class="control-label" for="type">${$.i18n.prop('legacy-artifact-paths.type')}</label>
+          <div class="controls">
+            <input type="text" class="xlarge required" id="type" name="type" size="8"
+                   data-bind="value: legacyArtifactPath.type"/>
+          </div>
+        </div>
+        <div class="control-group">
+          <label class="control-label" for="path">${$.i18n.prop('legacy-artifact-paths.path')}</label>
+          <div class="controls">
+            <input type="text" class="xlarge required" id="path" name="path" size="8"
+                   data-bind="value: legacyArtifactPath.path"/>
+          </div>
+        </div>
+        <div class="control-group">
+          <label class="control-label" for="artifact">${$.i18n.prop('legacy-artifact-paths.artifact')}</label>
+          <div class="controls">
+            <span title="calculated from values" class="uneditable-input"
+                  id="artifact" data-bind="text: legacyArtifactPath.artifact"></span>
+          </div>
+        </div>
+
+      </fieldset>
+      <button id="network-proxy-btn-save" data-bind="click: save" class="btn">${$.i18n.prop('save')}</button>
+      <button id="network-proxy-btn-cancel" data-bind="click: displayGrid" class="btn">${$.i18n.prop('cancel')}</button>
+      <button id="network-proxy-btn-calculate-path" data-bind="click: calculatePath" class="btn btn-success">${$.i18n.prop('legacy-artifact-paths.calculatePath')}</button>
+    </form>
+</script>
+
index 242654a9c63977e138e82c1ece5875dd9c63c996..08ec9fd9ba9a0cf00b1cc8dced002c5eacfb2c61 100644 (file)
@@ -224,17 +224,17 @@ mapStringArray=function(data){
  * @param idToAppend
  */
 displayRedbackError=function(obj,idToAppend) {
-  if ($.isArray(obj.redbackRestError.errorMessages)) {
+  if ($.isArray(obj.errorMessages)) {
     $.log("displayRedbackError with array");
-    for(var i=0; i<obj.redbackRestError.errorMessages.length; i++ ) {
-      if(obj.redbackRestError.errorMessages[i].errorKey) {
+    for(var i=0; i<obj.errorMessages.length; i++ ) {
+      if(obj.errorMessages[i].errorKey) {
         $.log("displayRedbackError with array loop");
-        displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages[i].errorKey, obj.redbackRestError.errorMessages[i].args ),idToAppend);
+        displayErrorMessage($.i18n.prop( obj.errorMessages[i].errorKey, obj.errorMessages[i].args ),idToAppend);
       }
     }
   } else {
     $.log("displayRedbackError no array");
-    displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages.errorKey, obj.redbackRestError.errorMessages.args ),idToAppend);
+    displayErrorMessage($.i18n.prop( obj.errorMessages.errorKey, obj.errorMessages.args ),idToAppend);
   }
 }
 
@@ -249,29 +249,30 @@ displayRestError=function(data,idToAppend){
     displayRedbackError(archivaRestError,idToAppend)
   }
   // if we have the fieldName display error on it
-  if (data.archivaRestError && data.archivaRestError.fieldName){
-    if ($("#main-content #"+data.archivaRestError.fieldName)){
+  if (data && data.fieldName){
+    var mainContent=$("#main-content");
+
+    if (mainContent.find("#"+data.fieldName)){
       var message=null;
-      if (data.archivaRestError.errorKey) {
-        message=$.i18n.prop('data.archivaRestError.errorKey');
+      if (data.errorKey) {
+        message=$.i18n.prop('data.errorKey');
       } else {
-        message=data.archivaRestError.errorMessage;
+        message=data.errorMessage;
       }
-      $( "#main-content div.clearfix" ).removeClass( "error" );
-      $( "#main-content span.help-inline" ).remove();
-      $("#main-content #"+data.archivaRestError.fieldName).parents( "div.clearfix" ).addClass( "error" );
-      $("#main-content #"+data.archivaRestError.fieldName).parent().append( "<span class=\"help-inline\">" + message + "</span>" );
+      mainContent.find("div.clearfix" ).removeClass( "error" );
+      mainContent.find("span.help-inline" ).remove();
+      mainContent.find("#"+data.fieldName).parents( "div.clearfix" ).addClass( "error" );
+      mainContent.find("#"+data.fieldName).parent().append( "<span class=\"help-inline\">" + message + "</span>" );
       return;
     }
     // we don't have any id with this fieldName so continue
   }
 
-  if (data.archivaRestError && data.archivaRestError.errorKey && data.archivaRestError.errorKey.length>0){
-      $.log("with errorKey:"+dataarchivaRestError.errorKey);
-      displayErrorMessage($.i18n.prop( data.archivaRestError.errorKey ),idToAppend);
+  if (data.errorKey && data.errorKey.length>0){
+      displayErrorMessage($.i18n.prop( data.errorKey ),idToAppend);
     } else {
-      $.log("data.errorMessage:"+data.archivaRestError.errorMessage);
-      displayErrorMessage(data.archivaRestError.errorMessage,idToAppend);
+      $.log("data.errorMessage:"+data.errorMessage);
+      displayErrorMessage(data.errorMessage,idToAppend);
   }
 
 }