From 77a3cd98e61d7b6af6e32bb69a8ae9c8f34a1918 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 30 Mar 2012 16:47:54 +0000 Subject: [PATCH] file upload form validation git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1307531 13f79535-47bb-0310-9956-ffa450edef68 --- .../ui/services/model/FileMetadata.java | 2 +- .../webapp/js/archiva/artifacts-management.js | 28 +++++++++++++++---- .../archiva/artifacts-management.html | 6 ++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java index ad5502b23..8bdee6823 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/java/org/apache/archiva/webapp/ui/services/model/FileMetadata.java @@ -113,7 +113,6 @@ public class FileMetadata return deleteUrl; } - public void setDeleteUrl( String deleteUrl ) { this.deleteUrl = deleteUrl; @@ -279,4 +278,5 @@ public class FileMetadata sb.append( '}' ); return sb.toString(); } + } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js index ff0dcbd48..f09dec80c 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/artifacts-management.js @@ -26,6 +26,7 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque } ArtifactUploadViewModel=function(managedRepositories){ + var self=this; this.managedRepositories=ko.observableArray(managedRepositories); this.repositoryId=ko.observable(); this.groupId=ko.observable(); @@ -34,8 +35,17 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque this.packaging=ko.observable(); this.generatePom=ko.observable(); + this.artifactUploads=[]; + saveArtifacts=function(){ - $.log("saveArtifacts"); + + if(!$("#main-content #fileupload" ).valid()){ + return; + } + if(this.artifactUploads.length<1){ + displayErrorMessage( $.i18n.prop("fileupload.upload.required")); + return; + } } } @@ -50,7 +60,11 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque success: function(data) { var artifactUploadViewModel=new ArtifactUploadViewModel(data); ko.applyBindings(artifactUploadViewModel,mainContent.find("#file-upload-main" ).get(0)); - + var validator = $("#main-content #fileupload" ).validate({ + showErrors: function(validator, errorMap, errorList) { + customShowError("#main-content #fileupload",validator,errorMap,errorMap); + } + }); $('#fileupload').fileupload({ add: function (e, data) { data.formData = { @@ -61,16 +75,20 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque generatePom: artifactUploadViewModel.generatePom(), repositoryId: artifactUploadViewModel.repositoryId() }; - $.log("fileupload add file"); $.blueimpUI.fileupload.prototype.options.add.call(this, e, data); + }, + submit: function (e, data) { + var $this = $(this); + + $this.fileupload('send', data); + artifactUploadViewModel.artifactUploads.push(new ArtifactUpload(data.formData.classifier,data.formData.pomFile)); + return false; } } ); $('#fileupload').bind('fileuploadsubmit', function (e, data) { var pomFile = data.context.find('#pomFile' ).val(); var classifier = data.context.find('#classifier' ).val(); - - $.log("pomFile:"+pomFile+",classifier:"+classifier); data.formData.pomFile = pomFile; data.formData.classifier = classifier; }); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/artifacts-management.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/artifacts-management.html index a759f0ff6..3625ad8f1 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/artifacts-management.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/artifacts-management.html @@ -33,14 +33,14 @@
- +
- +
@@ -49,7 +49,7 @@
- +