Author: ivaynberg
Date: Wed Dec 9 17:39:05 2009
New Revision: 888887
URL: http://svn.apache.org/viewvc?rev=888887&view=rev
Log:
WICKET-2602
Issue: WICKET-2602
Modified:
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js
Modified:
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java?rev=888887&r1=888886&r2=888887&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/UploadProgressBar.java
Wed Dec 9 17:39:05 2009
@@ -24,6 +24,7 @@
import org.apache.wicket.behavior.HeaderContributor;
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;
@@ -76,10 +77,32 @@
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)
+ public UploadProgressBar(String id, final Form<?> form, final
FileUploadField fileUploadField)
{
super(id);
setOutputMarkupId(true);
@@ -118,9 +141,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/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js?rev=888887&r1=888886&r2=888887&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js
(original)
+++
wicket/branches/wicket-1.4.x/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js
Wed Dec 9 17:39:05 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) {