Author: konstantin.mishin
Date: 2009-06-16 12:22:11 -0400 (Tue, 16 Jun 2009)
New Revision: 14629
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
branches/community/3.3.X/ui/fileUpload/src/test/java/org/richfaces/component/FileUploadComponentTest.java
Log:
RF-7370
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-16
15:31:04 UTC (rev 14628)
+++
branches/community/3.3.X/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2009-06-16
16:22:11 UTC (rev 14629)
@@ -486,12 +486,9 @@
for (String type : types) {
accepted.put(type.toLowerCase(), true);
}
- return ScriptUtils.toScript(accepted);
}
- }else {
- accepted.put("*", true);
}
- return ScriptUtils.toScript(accepted);
+ return accepted;
}
/**
@@ -575,7 +572,7 @@
}
return (result != null) ? new JSLiteral(result.toString())
- : JSReference.NULL;
+ : null;
}
/**
@@ -715,7 +712,7 @@
parameters.putAll(commonAjaxParameters);
}
- return ((parameters.size() > 0) ? ScriptUtils.toScript(parameters) :
JSReference.NULL);
+ return parameters;
}
public String getSessionId(FacesContext context, UIComponent component) {
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-16
15:31:04 UTC (rev 14628)
+++
branches/community/3.3.X/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2009-06-16
16:22:11 UTC (rev 14629)
@@ -418,56 +418,102 @@
options: null,
runUpload: false,
-
- classes: null,
-
- events: null,
- maxFileBatchSize: null,
+ maxFileBatchSize: 1,
uploadedCount: 0,
-
- initialize: function(id, formId, actionUrl, stopScript, getFileSizeScript,
progressBarId, classes, label, maxFiles, events, disabled, acceptedTypes, options, labels,
parameters, sessionId) {
+
+ acceptedTypes: {"*" : true},
+
+ initialize: function(id, actionUrl, stopScript, getFileSizeScript, progressBarId,
sessionId, options) {
+ //default values of classes
+ this.classes = {
+ ADD : {
+ ENABLED : 'rich-fileupload-button rich-fileupload-font ',
+ DISABLED : 'rich-fileupload-button-dis rich-file-upload-font '
+ },
+ ADD_CONTENT : {
+ ENABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-add ',
+ DISABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-add-dis '
+ },
+ UPDATE : {
+ ENABLED : 'rich-fileupload-button rich-fileupload-font ',
+ DISABLED : 'rich-fileupload-button-dis rich-fileupload-font '
+ },
+ UPDATE_CONTENT : {
+ ENABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-start ',
+ DISABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-start-dis '
+ },
+ STOP : {
+ ENABLED : 'rich-fileupload-button rich-fileupload-font ',
+ DISABLED : 'rich-fileupload-button-dis rich-fileupload-font '
+ },
+ STOP_CONTENT : {
+ ENABLED : 'rich-fileupload-button-content rich-file-upload-font
rich-fileupload-ico rich-fileupload-ico-stop ',
+ DISABLED : 'rich-fileupload-button-content rich-file-upload-font
rich-fileupload-ico rich-fileupload-ico-stop-dis '
+ },
+ CLEAN : {
+ ENABLED : 'rich-fileupload-button rich-fileupload-font ',
+ DISABLED : 'rich-fileupload-button-dis rich-fileupload-font '
+ },
+ CLEAN_CONTENT : {
+ ENABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-clear ',
+ DISABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-clear-dis '
+ },
+ FILE_ENTRY : {
+ ENABLED : '',
+ DISABLED : ''
+ },
+ FILE_ENTRY_CONTROL : {
+ ENABLED : '',
+ DISABLED : ''
+ },
+ UPLOAD_LIST : {
+ ENABLED : '',
+ DISABLED : ''
+ }
+ };
+ this.events = {};
+ this.options = {};
+
+ var classes = options.classes;
+ for (var obj in classes) {
+ var value = classes[obj];
+ for (var property in value) {
+ this.classes[obj][property] += value[property];
+ if (this.classes[obj + "_CONTENT"]) {
+ this.classes[obj + "_CONTENT"][property] += value[property];
+ }
+ }
+ }
+ Object.extend(this, options.fields);
+
this.id = id;
this.element = $(this.id);
- if (formId != '') {
- this.formId = formId;
- this.form = $(formId);
- }else {
- var f = this._getForm();
- this.formId = (f) ? f.id : null;
- this.form = f;
- }
+ var f = this.element.up("form");
+ this.formId = (f) ? f.id : null;
+ this.form = f;
this._progressBar = $(progressBarId);
this.progressBar = this._progressBar.component;
this.entries = new Array();
- this.labelMarkup = label;
- this.disabled = disabled;
-
this.element.component = this;
- this.acceptedTypes = acceptedTypes;
-
this.stopScript = stopScript;
this.getFileSizeScript = getFileSizeScript;
this.items = $(this.id + ":fileItems");
- this.classes = classes;
- this.events = events;
- this.parameters = parameters;
this.sessionId = sessionId;
- this.maxFileBatchSize = maxFiles;
this.currentInput = $(this.id + ":file");
this.actionUrl = actionUrl;
- this.options = options || {};
+ this.options = {allowFlash : "false"};
this.initFlashModule();
this.initEvents();
this.setupAutoUpload();
this.checkFrame();
//this.initFileEntryWidth();
- this.initLabels(labels);
+ this.initLabels(options.labels);
this.processButtons();
this.initFileInput();
},
@@ -645,7 +691,7 @@
},
setupAutoUpload: function() {
- this.runUpload = this.options.autoUpload;
+ this.runUpload = this.options.immediateUpload;
},
checkFileType: function (fileName) {
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-16
15:31:04 UTC (rev 14628)
+++
branches/community/3.3.X/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2009-06-16
16:22:11 UTC (rev 14629)
@@ -139,67 +139,67 @@
</jsp:scriptlet>
<span>
+ <c:scriptObject var="ADD">
+ <c:scriptOption name="ENABLED"
value="#{component.attributes['addButtonClass']}" />
+ <c:scriptOption name="DISABLED"
value="#{component.attributes['addButtonClassDisabled']}" />
+ </c:scriptObject>
+ <c:scriptObject var="UPDATE">
+ <c:scriptOption name="ENABLED"
value="#{component.attributes['uploadButtonClass']}" />
+ <c:scriptOption name="DISABLED"
value="#{component.attributes['uploadButtonClassDisabled']}" />
+ </c:scriptObject>
+ <c:scriptObject var="STOP">
+ <c:scriptOption name="ENABLED"
value="#{component.attributes['stopButtonClass']}" />
+ <c:scriptOption name="DISABLED"
value="#{component.attributes['stopButtonClassDisabled']}" />
+ </c:scriptObject>
+ <c:scriptObject var="CLEAN">
+ <c:scriptOption name="ENABLED"
value="#{component.attributes['cleanButtonClass']}" />
+ <c:scriptOption name="DISABLED"
value="#{component.attributes['cleanButtonClassDisabled']}" />
+ </c:scriptObject>
+ <c:scriptObject var="FILE_ENTRY">
+ <c:scriptOption name="ENABLED"
value="#{component.attributes['fileEntryClass']}" />
+ <c:scriptOption name="DISABLED"
value="#{component.attributes['fileEntryClassDisabled']}" />
+ </c:scriptObject>
+ <c:scriptObject var="FILE_ENTRY_CONTROL">
+ <c:scriptOption name="ENABLED"
value="#{component.attributes['fileEntryControlClass']}" />
+ <c:scriptOption name="DISABLED"
value="#{component.attributes['fileEntryControlClassDisabled']}" />
+ </c:scriptObject>
+ <c:scriptObject var="UPLOAD_LIST">
+ <c:scriptOption name="ENABLED"
value="#{component.attributes['uploadListClass']}" />
+ <c:scriptOption name="DISABLED"
value="#{component.attributes['uploadListClassDisabled']}" />
+ </c:scriptObject>
+ <c:scriptObject var="classes">
+ <c:scriptOption variables="ADD, UPDATE, STOP, CLEAN, FILE_ENTRY,
FILE_ENTRY_CONTROL, UPLOAD_LIST" />
+ </c:scriptObject>
+ <c:scriptObject var="events">
+ <c:scriptOption attributes="onupload, onuploadcomplete, onuploadcanceled,
onerror, ontyperejected, onsizerejected, onclear, onadd, onfileuploadcomplete"
wrapper="eventHandler"/>
+ </c:scriptObject>
+ <c:scriptObject var="internalOptions">
+ <c:scriptOption attributes="autoclear, noDuplicate, immediateUpload"
/>
+ <c:scriptOption name="allowFlash" value="#{allowFlash}"
defaultValue="false" />
+ <c:scriptOption name="flashComponentUrl"
value="#{flashComponent}" />
+ </c:scriptObject>
+ <c:scriptObject var="fields">
+ <c:scriptOption name="labelMarkup"
value="#{this:getLabelMarkup(context, component)}" />
+ <c:scriptOption name="maxFileBatchSize" value="#{maxCount}"
defaultValue="1" />
+ <c:scriptOption attributes="disabled" />
+ <c:scriptOption name="maxFileBatchSize" value="#{maxCount}"
defaultValue="1" />
+ <c:scriptOption name="acceptedTypes"
value="#{this:getAcceptedTypes(context, component)}" />
+ <c:scriptOption variables="events" />
+ <c:scriptOption name="options" value="#{internalOptions}"
/>
+ <c:scriptOption name="parameters"
value="#{this:getChildrenParams(context, component)}" />
+ </c:scriptObject>
+ <c:scriptObject var="options">
+ <c:scriptOption variables="classes, fields" />
+ <c:scriptOption name="labels" value="#{labels}" />
+ </c:scriptObject>
<script type="text/javascript">
- FileUpload.CLASSES = {
- ADD : {
- ENABLED : 'rich-fileupload-button rich-fileupload-font
#{component.attributes["addButtonClass"]}',
- DISABLED : 'rich-fileupload-button-dis rich-file-upload-font
#{component.attributes["addButtonClassDisabled"]}'
- },
- ADD_CONTENT : {
- ENABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-add
#{component.attributes["addButtonClass"]}',
- DISABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-add-dis
#{component.attributes["addButtonClassDisabled"]}'
- },
- UPDATE : {
- ENABLED : 'rich-fileupload-button rich-fileupload-font
#{component.attributes["uploadButtonClass"]}',
- DISABLED : 'rich-fileupload-button-dis rich-fileupload-font
#{component.attributes["uploadButtonClassDisabled"]}'
- },
- UPDATE_CONTENT : {
- ENABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-start
#{component.attributes["uploadButtonClass"]}',
- DISABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-start-dis
#{component.attributes["uploadButtonClassDisabled"]}'
- },
- STOP : {
- ENABLED : 'rich-fileupload-button rich-fileupload-font
#{component.attributes["stopButtonClass"]}',
- DISABLED : 'rich-fileupload-button-dis rich-fileupload-font
#{component.attributes["stopButtonClassDisabled"]}'
- },
- STOP_CONTENT : {
- ENABLED : 'rich-fileupload-button-content rich-file-upload-font
rich-fileupload-ico rich-fileupload-ico-stop
#{component.attributes["stopButtonClass"]}',
- DISABLED : 'rich-fileupload-button-content rich-file-upload-font
rich-fileupload-ico rich-fileupload-ico-stop-dis
#{component.attributes["stopButtonClassDisabled"]}'
- },
- CLEAN : {
- ENABLED : 'rich-fileupload-button rich-fileupload-font
#{component.attributes["cleanButtonClass"]}',
- DISABLED : 'rich-fileupload-button-dis rich-fileupload-font
#{component.attributes["cleanButtonClassDisabled"]}'
- },
- CLEAN_CONTENT : {
- ENABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-clear
#{component.attributes["cleanButtonClass"]}',
- DISABLED : 'rich-fileupload-button-content rich-fileupload-font
rich-fileupload-ico rich-fileupload-ico-clear-dis
#{component.attributes["cleanButtonClassDisabled"]}'
- },
- FILE_ENTRY : {
- ENABLED : '#{component.attributes["fileEntryClass"]}',
- DISABLED : '#{component.attributes["fileEntryClassDisabled"]}'
- },
- FILE_ENTRY_CONTROL : {
- ENABLED : '#{component.attributes["fileEntryControlClass"]}',
- DISABLED :
'#{component.attributes["fileEntryControlClassDisabled"]}'
- },
- UPLOAD_LIST : {
- ENABLED : '#{component.attributes["uploadListClass"]}',
- DISABLED : '#{component.attributes["uploadListClassDisabled"]}'
- }
- };
-
- var events = {
- onupload : #{this:getAsEventHandler(context, component, "onupload")},
- onuploadcomplete : #{this:getAsEventHandler(context, component,
"onuploadcomplete")},
- onuploadcanceled : #{this:getAsEventHandler(context, component,
"onuploadcanceled")},
- onerror : #{this:getAsEventHandler(context, component, "onerror")},
- ontyperejected : #{this:getAsEventHandler(context, component,
"ontyperejected")},
- onsizerejected : #{this:getAsEventHandler(context, component,
"onsizerejected")},
- onclear : #{this:getAsEventHandler(context, component, "onclear")},
- onadd : #{this:getAsEventHandler(context, component, "onadd")},
- onfileuploadcomplete : #{this:getAsEventHandler(context, component,
"onfileuploadcomplete")}
- };
-
- new
FileUpload('#{clientId}','#{formId}','#{actionUrl}',#{this:getStopScript(context,
component)}, #{this:getFileSizeScript(context, component)}
,'#{this:getProgressBarId(context, component)}', FileUpload.CLASSES,
#{this:getLabelMarkup(context, component)}, #{maxCount}, events,
#{component.attributes["disabled"]}, #{this:getAcceptedTypes(context,
component)},
{'autoclear':#{component.attributes["autoclear"]},'autoUpload':#{component.attributes["immediateUpload"]},'noDuplicate':#{component.attributes["noDuplicate"]},
'allowFlash':'#{allowFlash}',
'flashComponentUrl':'#{flashComponent}'},#{this:_getLabels(labels)},#{this:getChildrenParams(context,
component)},'#{this:getSessionId(context, component)}');
+ new
FileUpload('#{clientId}','#{actionUrl}',#{this:getStopScript(context,
component)},
+ #{this:getFileSizeScript(context, component)} ,'#{this:getProgressBarId(context,
component)}',
+ '#{this:getSessionId(context, component)}'
+ <c:if test="#{not empty options}">
+ , <f:writeAsScript value="#{options}" />
+ </c:if>
+ );
</script>
</span>
<f:call name="utils.encodeEndFormIfNessesary" />
Modified:
branches/community/3.3.X/ui/fileUpload/src/test/java/org/richfaces/component/FileUploadComponentTest.java
===================================================================
---
branches/community/3.3.X/ui/fileUpload/src/test/java/org/richfaces/component/FileUploadComponentTest.java 2009-06-16
15:31:04 UTC (rev 14628)
+++
branches/community/3.3.X/ui/fileUpload/src/test/java/org/richfaces/component/FileUploadComponentTest.java 2009-06-16
16:22:11 UTC (rev 14629)
@@ -109,7 +109,6 @@
assertTrue(scriptBodyString.contains("image/jpeg"));
assertTrue(scriptBodyString.contains("video/mpeg"));
assertFalse(scriptBodyString.contains("image/png"));
-
assertTrue(scriptBodyString.contains("FileUpload.CLASSES"));
}
}
}