Author: ivaynberg
Date: Wed Dec 9 17:37:45 2009
New Revision: 888885
URL: http://svn.apache.org/viewvc?rev=888885&view=rev
Log:
WICKET-2602
Issue: WICKET-2602
Modified:
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js
Modified:
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java?rev=888885&r1=888884&r2=888885&view=diff
==============================================================================
---
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java
(original)
+++
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java
Wed Dec 9 17:37:45 2009
@@ -25,6 +25,7 @@
import org.apache.wicket.markup.html.JavascriptPackageResource;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
import org.slf4j.Logger;
@@ -77,14 +78,40 @@
private static final long serialVersionUID = 1L;
/**
+ * Constructor that will display the upload progress bar for every
submit of the given form.
+ *
* @param id
+ * component id (not null)
* @param form
+ * form that will be submitted (not null)
*/
public UploadProgressBar(String id, final Form<?> form)
{
+ this(id, form, null);
+ }
+
+ /**
+ * Constructor that will display the upload progress bar for
submissions of the given form, that
+ * include a file upload in the given file upload field; i.e. if the
user did not select a file
+ * in the given file upload field, the progess bar is not displayed.
+ *
+ * @param id
+ * component id (not null)
+ * @param form
+ * form that is submitted (not null)
+ * @param fileUploadField
+ * the file upload field to check for a file upload, or null
to display the upload
+ * field for every submit of the given form
+ */
+ public UploadProgressBar(String id, final Form<?> form, final
FileUploadField fileUploadField)
+ {
super(id);
setOutputMarkupId(true);
form.setOutputMarkupId(true);
+ if (fileUploadField != null)
+ {
+ fileUploadField.setOutputMarkupId(true);
+ }
setRenderBodyOnly(true);
add(JavascriptPackageResource.getHeaderContribution(JS));
@@ -119,9 +146,12 @@
{
ResourceReference ref = new
ResourceReference(RESOURCE_NAME);
+ String fileUploadFieldMarkupId =
fileUploadField == null ? ""
+ : fileUploadField.getMarkupId();
return "var def=new Wicket.WUPB.Def('" +
form.getMarkupId() + "', '" +
statusDiv.getMarkupId() + "', '" +
barDiv.getMarkupId() + "', '" +
- getPage().urlFor(ref) + "');
Wicket.WUPB.start(def);";
+ getPage().urlFor(ref) + "','" +
fileUploadFieldMarkupId +
+ "'); Wicket.WUPB.start(def);";
}
}));
}
Modified:
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js?rev=888885&r1=888884&r2=888885&view=diff
==============================================================================
---
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js
(original)
+++
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js
Wed Dec 9 17:37:45 2009
@@ -18,11 +18,12 @@
Wicket.WUPB= {
- Def : function(formid, statusid, barid, url) {
+ Def : function(formid, statusid, barid, url, fileid) {
this.formid=formid;
this.statusid=statusid;
this.barid=barid;
this.url=url;
+ this.fileid=fileid;
},
get : function(id) {
@@ -30,14 +31,21 @@
},
start : function(def) {
- //Wicket.WUPB.get(def.formid).submit();
- Wicket.WUPB.get(def.statusid).innerHTML='Upload starting...';
- Wicket.WUPB.get(def.barid).firstChild.firstChild.style.width='0%';
-
- Wicket.WUPB.get(def.statusid).style.display='block';
- Wicket.WUPB.get(def.barid).style.display='block';
-
- window.setTimeout(function() { Wicket.WUPB.ajax(def); }, 1000);
+ var displayprogress = true;
+ if (def.fileid) {
+ var fileupload = Wicket.WUPB.get(def.fileid);
+ displayprogress = fileupload && fileupload.value &&
fileupload.value != '';
+ }
+ if(displayprogress) {
+ //Wicket.WUPB.get(def.formid).submit();
+ Wicket.WUPB.get(def.statusid).innerHTML='Upload
starting...';
+
Wicket.WUPB.get(def.barid).firstChild.firstChild.style.width='0%';
+
+ Wicket.WUPB.get(def.statusid).style.display='block';
+ Wicket.WUPB.get(def.barid).style.display='block';
+
+ window.setTimeout(function() { Wicket.WUPB.ajax(def);
}, 1000);
+ }
},
ajax : function(def) {