file upload form validation

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1307531 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-03-30 16:47:54 +00:00
parent 8312f1e85a
commit 77a3cd98e6
3 changed files with 27 additions and 9 deletions

View File

@ -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();
}
}

View File

@ -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;
});

View File

@ -33,14 +33,14 @@
</div>
</div>
<div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('fileupload.version')}</label>
<label class="control-label" for="version">${$.i18n.prop('fileupload.version')}</label>
<div class="controls">
<input type="text" class="xlarge required" data-bind="value: version" id="version" name="version" size="10" />
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('fileupload.packaging')}</label>
<label class="control-label" for="packaging">${$.i18n.prop('fileupload.packaging')}</label>
<div class="controls">
<input type="text" class="xlarge required" data-bind="value: packaging" id="packaging" name="packaging" size="10" />
</div>
@ -49,7 +49,7 @@
<div class="control-group">
<label class="control-label" for="generatePom">${$.i18n.prop('fileupload.generatePom')}</label>
<div class="controls">
<input type="checkbox" class="xlarge required" data-bind="value: generatePom" id="generatePom" name="generatePom" />
<input type="checkbox" class="xlarge" data-bind="value: generatePom" id="generatePom" name="generatePom" />
</div>
</div>
</div>