Author: nbelaevski
Date: 2009-06-21 11:25:46 -0400 (Sun, 21 Jun 2009)
New Revision: 14686
Modified:
branches/community/3.3.X/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java
branches/community/3.3.X/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
branches/community/3.3.X/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
Log:
https://jira.jboss.org/jira/browse/RF-7375
Modified:
branches/community/3.3.X/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java
===================================================================
---
branches/community/3.3.X/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2009-06-21
13:57:33 UTC (rev 14685)
+++
branches/community/3.3.X/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2009-06-21
15:25:46 UTC (rev 14686)
@@ -415,23 +415,21 @@
* @throws IOException
*/
@SuppressWarnings("unchecked")
- private String getActionScript(FacesContext context, UIComponent component,
- String action, Object oncomplete) throws IOException {
+ public String getActionScript(FacesContext context, UIComponent component) throws
IOException {
String clientId = component.getClientId(context);
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(component, context);
Map<String, Object> parameters = new HashMap<String, Object>();
- parameters.put(FileUploadConstants.FILE_UPLOAD_ACTION, action);
+ parameters.put(FileUploadConstants.FILE_UPLOAD_ACTION, new
JSReference("action"));
parameters.put(FileUploadConstants.UPLOAD_FILES_ID, new JSReference("uid"));
parameters.put(AjaxRendererUtils.AJAX_SINGLE_ATTR, clientId);
Map options = AjaxRendererUtils.buildEventOptions(context, component, parameters,
true);
- if (oncomplete != null) {
- options.put("onbeforedomupdate", oncomplete);
- }
+ options.put("onbeforedomupdate", new JSReference("callback"));
+
ajaxFunction.addParameter(options);
- JSFunctionDefinition function = new JSFunctionDefinition("uid");
+ JSFunctionDefinition function = new JSFunctionDefinition("uid",
"action", "callback");
function.addParameter("event");
function.addToBody(ajaxFunction.toScript());
@@ -462,49 +460,6 @@
}
/**
- * Generates JS script for stopping uploading process
- *
- * @param context
- * @param component
- * @return
- * @throws IOException
- */
- public String getStopScript(FacesContext context, UIComponent component)
- throws IOException {
- JSFunctionDefinition oncomplete = new JSFunctionDefinition();
- oncomplete.addParameter("request");
- oncomplete.addParameter("event");
- oncomplete.addParameter("data");
- StringBuffer body = new StringBuffer("$('");
- body.append(component.getClientId(context));
- body.append("').component.cancelUpload(data);");
- oncomplete.addToBody(body);
- return getActionScript(context, component, FileUploadConstants.FILE_UPLOAD_ACTION_STOP,
oncomplete);
- }
-
- /**
- * Generates JS script for getting file size from server
- *
- * @param context
- * @param component
- * @return
- * @throws IOException
- */
- public String getFileSizeScript(FacesContext context, UIComponent component)
- throws IOException {
- JSFunctionDefinition oncomplete = new JSFunctionDefinition();
- oncomplete.addParameter("request");
- oncomplete.addParameter("event");
- oncomplete.addParameter("data");
- StringBuffer body = new StringBuffer("$('");
- body.append(component.getClientId(context));
- body.append("').component.getFileSize(data);");
- oncomplete.addToBody(body);
- return getActionScript(context, component,
FileUploadConstants.FILE_UPLOAD_ACTION_PROGRESS, oncomplete);
-
- }
-
- /**
* Generates progress label markup
*
* @param context
Modified:
branches/community/3.3.X/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
---
branches/community/3.3.X/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2009-06-21
13:57:33 UTC (rev 14685)
+++
branches/community/3.3.X/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2009-06-21
15:25:46 UTC (rev 14686)
@@ -184,7 +184,7 @@
},
stop: function() {
- this.uploadObject.stopScript(this.uid);
+ this.uploadObject.executeStopScript(this.uid);
},
_clearInput: function() {
@@ -425,7 +425,7 @@
acceptedTypes: {"*" : true},
- initialize: function(id, actionUrl, stopScript, getFileSizeScript, progressBarId,
sessionId, options) {
+ initialize: function(id, actionUrl, actionScript, progressBarId, sessionId, options) {
if(!options) {
options = {};
}
@@ -501,8 +501,7 @@
this.entries = new Array();
this.element.component = this;
- this.stopScript = stopScript;
- this.getFileSizeScript = getFileSizeScript;
+ this.actionScript = actionScript;
this.items = $(this.id + ":fileItems");
this.sessionId = sessionId;
@@ -521,7 +520,13 @@
this.initFileInput();
},
- cancelUpload: function(uid) {
+ executeStopScript: function (uid) {
+ this.actionScript(uid, "richfaces_file_upload_action_stop",
this.cancelUpload.bind(this));
+ },
+
+ cancelUpload: function(request, event, data) {
+ var uid = data;
+
if (this.activeEntry && this.activeEntry.uid == uid) {
if (this.watcher) {
this.watcher.oncancel();
@@ -641,9 +646,12 @@
}
},
- getFileSize: function (data) {
+ executeFileSizeScript: function(uid) {
+ this.actionScript(uid, "progress", this.getFileSize.bind(this));
+ },
+
+ getFileSize: function(request, event, data) {
if (data) {
-
if (!this.isFlash) {
this.progressBar.enable();
}
@@ -655,11 +663,11 @@
this.activeEntry.setupLabelUpdate();
}
}
- }else {
+ } else {
if (this.activeEntry) {
this._fileSizeScriptTimeoutId = setTimeout(function() {
this._fileSizeScriptTimeoutId = undefined;
- this.getFileSizeScript(this.activeEntry.uid);
+ this.executeFileSizeScript(this.activeEntry.uid);
}.bind(this), this.progressBar.options['pollinterval'] || 500);
}
}
@@ -1184,7 +1192,7 @@
this.currentInput.disabled = true;
}else {
Richfaces.writeAttribute(parentForm, "target", oldTarget);
- this.getFileSizeScript(entry.uid)
+ this.executeFileSizeScript(entry.uid)
}
}
},
Modified:
branches/community/3.3.X/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
===================================================================
---
branches/community/3.3.X/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2009-06-21
13:57:33 UTC (rev 14685)
+++
branches/community/3.3.X/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2009-06-21
15:25:46 UTC (rev 14686)
@@ -191,8 +191,7 @@
<c:scriptOption name="labels" value="#{labels}" />
</c:scriptObject>
<script type="text/javascript">
- new
FileUpload('#{clientId}','#{actionUrl}',#{this:getStopScript(context,
component)},
- #{this:getFileSizeScript(context, component)} ,'#{this:getProgressBarId(context,
component)}',
+ new FileUpload('#{clientId}','#{actionUrl}',
#{this:getActionScript(context, component)}, '#{this:getProgressBarId(context,
component)}',
'#{this:getSessionId(context, component)}'
<c:if test="#{not empty options}">
, <f:writeAsScript value="#{options}" />