Author: andrei_exadel
Date: 2008-02-08 13:10:37 -0500 (Fri, 08 Feb 2008)
New Revision: 5961
Modified:
trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
Log:
palet version provided
Modified: trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml 2008-02-08
17:50:25 UTC (rev 5960)
+++ trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml 2008-02-08
18:10:37 UTC (rev 5961)
@@ -66,7 +66,7 @@
<name>accept</name>
<classname>java.lang.String</classname>
<description>a comma-separated list of content types to accept, may not be
supported by the browser. E.g. "images/png,images/jpg",
"images/*".</description>
- </property>
+ </property>
<property elonly="true">
<name>data</name>
<classname>java.lang.Object</classname>
@@ -86,6 +86,46 @@
<name>fileSize</name>
<classname>java.lang.Integer</classname>
<description>this value binding receives the file size
(optional).</description>
+ </property>
+ <property>
+ <name>addStyle</name>
+ <classname>java.lang.String</classname>
+ <description>CSS style for add button</description>
+ </property>
+ <property>
+ <name>addStyleDisabled</name>
+ <classname>java.lang.String</classname>
+ <description>CSS style for add button disabled</description>
+ </property>
+ <property>
+ <name>uploadStyle</name>
+ <classname>java.lang.String</classname>
+ <description>CSS style for upload button</description>
+ </property>
+ <property>
+ <name>uploadStyleDisabled</name>
+ <classname>java.lang.String</classname>
+ <description>CSS style for upload button disabled</description>
+ </property>
+ <property>
+ <name>cancelStyle</name>
+ <classname>java.lang.String</classname>
+ <description>CSS style for cancel button</description>
+ </property>
+ <property>
+ <name>cancelStyleDisabled</name>
+ <classname>java.lang.String</classname>
+ <description>CSS style for cancel button disabled</description>
+ </property>
+ <property>
+ <name>cleanStyle</name>
+ <classname>java.lang.String</classname>
+ <description>CSS style for clean button</description>
+ </property>
+ <property>
+ <name>cleanStyleDisabled</name>
+ <classname>java.lang.String</classname>
+ <description>CSS style for clean button disabled</description>
</property>
</component>
</components>
Modified:
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java 2008-02-08
17:50:25 UTC (rev 5960)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java 2008-02-08
18:10:37 UTC (rev 5961)
@@ -21,10 +21,12 @@
*/
public abstract class UIFileUpload extends UIInput {
- public static final String READY = "ready";
+ public static final String READY = "1";
- public static final String UPLOADING = "uploading";
+ public static final String UNDER_UPLOAD = "2";
+ public static final String UPLOADING = "3";
+
private String uploadStatus = READY;
private String localContentType;
@@ -92,7 +94,20 @@
// }
// }
// }
+
+ public boolean isReady () {
+ return this.getUploadStatus() == READY;
+ }
+
+ public boolean isUploading () {
+ return (this.getUploadStatus() == UPLOADING || this.getUploadStatus() == UNDER_UPLOAD);
+ }
+
+ public boolean hasChildren () {
+ return this.getFileItems().size() > 0;
+ }
+
public String getLocalContentType() {
return localContentType;
}
Modified:
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java 2008-02-08
17:50:25 UTC (rev 5960)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java 2008-02-08
18:10:37 UTC (rev 5961)
@@ -17,6 +17,8 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.ajax4jsf.context.AjaxContext;
@@ -49,7 +51,7 @@
private static final String ACTION_UPLOAD_ALL = "uploadall";
/** Upload file action name */
- private static final String ACTION_UPLOAD = "upload";
+ private static final String ACTION_NEXT = "next";
/** Clear file action name */
private static final String ACTION_CLEAR_FILE = "clear";
@@ -59,12 +61,17 @@
/** Stop file uploading action name */
private static final String ACTION_STOP_FILE = "stop";
+
+ private static final String ACTION_STOP_ALL = "stopall";
/** File name parameter name */
private static final String FILE_NAME_PARAMETER = "fileName";
/** Session bean name to store the percent value of uploading process */
public static final String _percentBeanName = "__percentValue$";
+
+
+ private static final String _reRenderAllFlag = "reRenderAll";
/* (non-Javadoc)
* @see
org.ajax4jsf.renderkit.RendererBase#doDecode(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
@@ -108,6 +115,7 @@
fileUpload.setLocalFileSize(multipartRequest.getFileSize(clientId));
onUploadComplete(context, multipartRequest.getFileName(clientId),
fileUpload);
+
}
}
@@ -142,10 +150,10 @@
@Override
public void encodeBegin(FacesContext context, UIComponent component)
throws IOException {
- AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance();
- ajaxContext.removeRenderedArea(component.getClientId(context));
- ajaxContext.addRenderedArea(component.getClientId(context)
- + ":fileItems");
+ AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance();
+ ajaxContext.removeRenderedArea(component.getClientId(context));
+ ajaxContext.addRenderedArea(component.getClientId(context)
+ + ":fileItems");
}
public String encodeStatus(UIFileUpload fileUpload) {
@@ -164,6 +172,11 @@
}
fileUpload.setUploadStatus(UIFileUpload.READY);
storeData(context, fileUpload);
+ try {
+ context.responseComplete();
+ }catch (Exception e) {
+ e.getMessage();
+ }
}
private FileItem getFileByName(UIFileUpload fileUpload, String name) {
@@ -234,22 +247,27 @@
.getRequestParameterValuesMap();
UIFileUpload fileUpload = (UIFileUpload) component;
String action = params.get(getActionParameterName(clientId))[0];
+ boolean reRenderAll = false;
if (ACTION_ADD_FILE.equals(action)) {
processAddFileAction(context, fileUpload, params);
} else if (ACTION_UPLOAD_ALL.equals(action)) {
processUploadAllAction(context, fileUpload);
+ reRenderAll = true;
} else if (ACTION_CLEAR_ALL.equals(action)) {
processClearAllAction(fileUpload);
} else if (ACTION_CLEAR_FILE.equals(action)) {
processClearAction(context, fileUpload, params);
- } else if (ACTION_UPLOAD.equals(action)) {
- processUploadAction(context, fileUpload);
+ } else if (ACTION_NEXT.equals(action)) {
+ processNextAction(context, fileUpload);
} else if (ACTION_STOP_FILE.equals(action)) {
+ reRenderAll = true;
processStopFileAction(context, fileUpload, params);
+ } else if (ACTION_STOP_ALL.equals(action)) {
+ processStopAllAction(context, fileUpload, params);
+ reRenderAll = true;
}
-
}
-
+
private void processClearAction(FacesContext context,
UIFileUpload fileUpload, Map<String, String[]> params) {
if (params.containsKey(ACTION_CLEAR_FILE)) {
@@ -270,9 +288,21 @@
item.setStatus(FileItem.Status.CANCELLED);
}
}
- fileUpload.setUploadStatus(UIFileUpload.READY);
+ //fileUpload.setUploadStatus(UIFileUpload.READY);
+ processNextAction(context, fileUpload);
}
}
+
+
+ private void processStopAllAction(FacesContext context,
+ UIFileUpload fileUpload, Map<String, String[]> params) {
+ for (FileItem item : fileUpload.getFileItems()) {
+ if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
+ item.setStatus(FileItem.Status.CANCELLED);
+ }
+ }
+ fileUpload.setUploadStatus(UIFileUpload.READY);
+ }
private void processClearAllAction(UIFileUpload fileUpload) {
List<FileItem> toDelete = new ArrayList<FileItem>();
@@ -298,18 +328,22 @@
}
}
- private void processUploadAction(FacesContext context,
+ private void processNextAction(FacesContext context,
UIFileUpload fileUpload) {
- if (UIFileUpload.READY.equals(fileUpload.getUploadStatus())) {
+ if (UIFileUpload.UPLOADING.equals(fileUpload.getUploadStatus())) {
Iterator<FileItem> it = fileUpload.getFileItems().iterator();
+ boolean found = false;
while (it.hasNext()) {
FileItem item = it.next();
if (item.getStatus() == FileItem.Status.MARKED_4_UPLOAD) {
item.setStatus(FileItem.Status.IN_PROGRESS);
+ fileUpload.setUploadStatus(UIFileUpload.UNDER_UPLOAD);
+ getSession(context).setAttribute(_percentBeanName, 0);
+ found = true;
break;
}
}
- getSession(context).setAttribute(_percentBeanName, 0);
+ if (!found) fileUpload.setUploadStatus(UIFileUpload.READY);
}
}
@@ -321,14 +355,17 @@
FileItem toUpload = null;
while (it.hasNext()) {
FileItem item = it.next();
- item.setStatus(FileItem.Status.MARKED_4_UPLOAD);
- if (toUpload == null) {
- toUpload = item;
+ if (item.getStatus() == FileItem.Status.ADDED) {
+ item.setStatus(FileItem.Status.MARKED_4_UPLOAD);
+ if (toUpload == null) {
+ toUpload = item;
+ }
}
}
if (toUpload != null) {
toUpload.setStatus(FileItem.Status.IN_PROGRESS);
+ fileUpload.setUploadStatus(UIFileUpload.UNDER_UPLOAD);
getSession(context).setAttribute(_percentBeanName, 0);
}
@@ -350,16 +387,6 @@
return clientId + "_action";
}
- private String getProgressBarParameterName(UIComponent fileUpload) {
- UIComponent form = AjaxRendererUtils.getNestingForm(fileUpload);
- String formId = null;
- if (form != null) {
- formId = form.getId();
- return formId + ":progressBar_percent";
- }
- return "progressBar_percent";
- }
-
private HttpSession getSession(FacesContext context) {
if (context.getExternalContext() != null) {
return (HttpSession) context.getExternalContext().getSession(false);
@@ -381,11 +408,10 @@
throws IOException {
Writer writer = context.getResponseWriter();
String clientId = component.getClientId(context);
- StringBuffer current = new StringBuffer();
StringBuffer script = new StringBuffer("\n");
- current.append("FileUpload.Uploaders['");
- current.append(clientId);
- current.append("']");
+ script.append("new FileUpload('");
+ script.append(clientId);
+ script.append("','");
UIComponent container = (UIComponent) AjaxRendererUtils
.findAjaxContainer(context, component);
@@ -396,20 +422,51 @@
String actionUrl = AjaxContextImpl.getCurrentInstance(context)
.getAjaxActionURL(context);
- script.append(current);
- script.append(" = {};\n");
- script.append(current).append("['containerId'] = '")
- .append(containerId).append("';\n");
- script.append(current).append("['formId'] =
'").append(formId).append(
- "';\n");
- script.append(current).append("['actionUrl'] =
'").append(actionUrl)
- .append("';\n");
- script.append("new FileUpload().init('");
- script.append(clientId);
- script.append("');\n");
+ script.append(containerId).append("','");
+ script.append(formId).append("','");
+ script.append(actionUrl).append("',");
+ script.append(getUploadAllClick(context, component));
+ script.append(",");
+ script.append(getStopAllClick(context, component));
+ script.append(",'");
+ script.append(component.getAttributes().get("addStyle"));
+ script.append("','");
+ script.append(component.getAttributes().get("addStyleDisabled"));
+ script.append("','");
+ script.append(component.getAttributes().get("uploadStyle"));
+ script.append("','");
+ script.append(component.getAttributes().get("uploadStyleDisabled"));
+ script.append("','");
+ script.append(component.getAttributes().get("cancelStyle"));
+ script.append("','");
+ script.append(component.getAttributes().get("cancelStyleDisabled"));
+ script.append("','");
+ script.append(component.getAttributes().get("cleanStyle"));
+ script.append("','");
+ script.append(component.getAttributes().get("cleanStyleDisabled"));
+ script.append("');");
+
writer.write(script.toString());
}
+
+ public void encodeUpdateButtonScript(FacesContext context, UIComponent component)
+ throws IOException {
+ UIFileUpload fileUpload = (UIFileUpload) component;
+ String cliendId = fileUpload.getClientId(context);
+ Writer writer = context.getResponseWriter();
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(getJSScriptStart(cliendId));
+ buffer.append(".updateUploadButton(").append(fileUpload.isUploading() ?
"true," : "false,")
+ .append(fileUpload.hasChildren() ? "false" :
"true").append(");\n");
+
+ buffer.append(getJSScriptStart(cliendId)).append(".updateAddButton(false);\n");
+
+ buffer.append(getJSScriptStart(cliendId)).append(".updateCleanButton(")
+ .append(fileUpload.hasChildren() ? "false" :
"true").append(");\n");
+ writer.write(buffer.toString());
+ }
public void encodeUploadScript(FacesContext context, UIComponent component)
throws IOException {
@@ -427,19 +484,13 @@
StringBuffer buffer = getJSScriptStart(cliendId);
buffer.append(".upload('");
buffer.append(convertFileName(item.getFullFileName()));
- buffer.append("');");
+ buffer.append("');\n");
writer.write(buffer.toString());
fileUpload.setUploadStatus(UIFileUpload.UPLOADING);
return; // Only one file can be in progress status
}
}
- } else {
-// StringBuffer buffer = new StringBuffer();
-// buffer.append("A4J.AJAX.StopPoll(FileUpload.Uploaders['");
-// buffer.append(cliendId);
-// buffer.append("']['formId'] + ':progressBar');\n");
-// writer.write(buffer.toString());
- }
+ }
}
/**
@@ -503,7 +554,8 @@
public boolean isCanClear (FileItem item) {
return item.getStatus() != FileItem.Status.IN_PROGRESS;
}
-
+
+
private UIComponent findProgressBar(UIComponent fileUpload) {
UIComponent progressBar = null;
for (UIComponent child : fileUpload.getChildren()) {
@@ -550,16 +602,53 @@
}
private StringBuffer getJSScriptStart(String clientId) {
- StringBuffer buffer = new StringBuffer("new FileUpload('");
- buffer.append(clientId).append("')");
+ StringBuffer buffer = new StringBuffer("$('");
+ buffer.append(clientId).append("').component");
return buffer;
}
+
+ public String getControlLabel (FacesContext context, UIComponent component) {
+ UIFileUpload fileUpload = (UIFileUpload) component;
+ return (UIFileUpload.READY.equals(fileUpload.getUploadStatus()) ? "Upload" :
"Cancel");
+ }
- public String getUploadAllClick(FacesContext context, UIComponent component) {
+ public JSFunctionDefinition getUploadAllClick(FacesContext context, UIComponent
component) {
String clientId = component.getClientId(context);
+ JSFunctionDefinition definition = new JSFunctionDefinition();
+ StringBuffer script = new StringBuffer();
+ UIFileUpload fileUpload = (UIFileUpload) component;
+ if (UIFileUpload.READY.equals(fileUpload.getUploadStatus())) {
+ Map parameters = new HashMap();
+ parameters.put(getActionParameterName(clientId), ACTION_UPLOAD_ALL);
+ script.append(getOnClick(context, component, clientId, parameters,
+ null));
+ definition.addToBody(script);
+ }
+ return definition;
+ }
+
+ public String getUploadAllStyle(UIComponent component) {
+ UIFileUpload fileUpload = (UIFileUpload) component;
+ if (fileUpload.isReady()) {
+ return (String) component.getAttributes().get("uploadStyle");
+ }
+ return "";
+ }
+
+ public String getUploadAllDisabled (UIComponent component) {
+ UIFileUpload fileUpload = (UIFileUpload) component;
+ return fileUpload.hasChildren() ? "false" : "true";
+ }
+
+ public JSFunctionDefinition getStopAllClick(FacesContext context, UIComponent
component) {
+ String clientId = component.getClientId(context);
+ JSFunctionDefinition definition = new JSFunctionDefinition();
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(
+ this, component);
Map parameters = new HashMap();
- parameters.put(getActionParameterName(clientId), ACTION_UPLOAD_ALL);
- return getOnClick(context, component, clientId, parameters, null);
+ parameters.put(getActionParameterName(clientId), ACTION_STOP_ALL);
+ definition.addToBody(getOnClick(context, component, clientId, parameters, null));
+ return definition;
}
public String getStopFileClick(FacesContext context, UIComponent component) {
@@ -610,7 +699,6 @@
StringBuffer body = getJSScriptStart(clientId)
.append(".addFile();");
-
Object oncomplete = getOnComplete(context, component, body);
Map parameters = new HashMap();
parameters.put(getActionParameterName(clientId), ACTION_ADD_FILE);
Modified:
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss 2008-02-08
17:50:25 UTC (rev 5960)
+++
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss 2008-02-08
18:10:37 UTC (rev 5961)
@@ -39,11 +39,12 @@
cursor : pointer;
padding : 1px;
}
+
.upload_button_dis{
- background : #C0C0C0; /*tableBorderColor*/
- border : 1px solid #C0C0C0; /*tableBorderColor*/
- margin-bottom : 3px;
- padding : 1px}
+ background :#f1f1f1 /*trimColor*/ repeat-x;
+ cursor : pointer;
+ padding : 2px;
+}
.upload_button_press{
background-repeat: repeat x top left #EAF0F8;
@@ -69,9 +70,12 @@
.upload_ico{background-position : 0px 50%; background-repeat : no-repeat; padding-left :
19px}
.upload_ico_add{}
+.upload_ico_add_dis{color:#C0C0C0; /*tableBorderColor*/}
.upload_ico_start{}
+.upload_ico_start_dis{color:#C0C0C0; /*tableBorderColor*/}
.upload_ico_stop{}
.upload_ico_clear{}
+.upload_ico_clear_dis{color:#C0C0C0; /*tableBorderColor*/}
input.hidden {
Z-INDEX: 2;
@@ -108,12 +112,24 @@
</u:style>
</u:selector>
+<u:selector name=".upload_ico_add_dis">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/ico_add_dis.gif"
/>
+ </u:style>
+</u:selector>
+
<u:selector name=".upload_ico_start">
<u:style name="background-image">
<f:resource f:key="/org/richfaces/renderkit/html/images/ico_start.gif"
/>
</u:style>
</u:selector>
+<u:selector name=".upload_ico_start_dis">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/ico_start_dis.gif"
/>
+ </u:style>
+</u:selector>
+
<u:selector name=".upload_ico_stop">
<u:style name="background-image">
<f:resource f:key="/org/richfaces/renderkit/html/images/ico_stop.gif"
/>
@@ -125,5 +141,11 @@
<f:resource f:key="/org/richfaces/renderkit/html/images/ico_clear.gif"
/>
</u:style>
</u:selector>
+
+<u:selector name=".upload_ico_clear_dis">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/ico_clear_dis.gif"
/>
+ </u:style>
+</u:selector>
</f:template>
Modified:
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-02-08
17:50:25 UTC (rev 5960)
+++
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-02-08
18:10:37 UTC (rev 5961)
@@ -2,13 +2,26 @@
FileUpload = Class.create();
FileUpload.Uploaders = {};
Object.extend(FileUpload.prototype, {
- initialize: function() {
- if (arguments.length > 0) {
- var id = arguments[0];
- this.id = id;
- this.f = $(id + ":files");
- this.fm = $(id + ":f");
- }
+ initialize: function(id, containerId, formId, actionUrl, onUploadAllClick ,
onStopAllClick, addStyle, addStyleDisabled, uploadStyle, uploadStyleDisabled, cancelStyle,
cancelStyleDisabled, cleanStyle, cleanStyleDisabled) {
+ this.id = id;
+ this.containerId = containerId;
+ this.formId = formId;
+ this.actionUrl = actionUrl;
+ this.createForm();
+ this.f = $(id + ":files");
+ this.fm = $(id + ":f");
+ this.fr = $(id + ":fr");
+ this.onUploadAllClick = function () { onUploadAllClick(); }
+ this.onStopAllClick = function () { onStopAllClick(); }
+ this.addStyle = addStyle;
+ this.addStyleDisabled = addStyleDisabled;
+ this.uploadStyle = uploadStyle;
+ this.uploadStyleDisabled = uploadStyleDisabled;
+ this.cancelStyle = cancelStyle;
+ this.cancelStyleDisabled = cancelStyleDisabled;
+ this.cleanStyle = cleanStyle;
+ this.cleanStyleDisabled = cleanStyleDisabled;
+ $(this.id).component = this;
},
renderControl: function (template, context) {
if (!template) {
@@ -17,11 +30,46 @@
var html = template.invoke('getContent', context).join('');
$(this.id + ":header").innerHTML = html;
},
+ setClassName: function (o , className) {
+ o.className = className;
+ },
+ updateCleanButton: function(disabled) {
+
this.updateButton($(this.id+":clean1"),$(this.id+":clean2"),this.cleanStyle,this.cleanStyleDisabled,"clear",disabled);
+ },
+ updateAddButton: function(disabled) {
+
this.updateButton($(this.id+":add1"),$(this.id+":add2"),this.addStyle,this.addStyleDisabled,"add",disabled);
+ },
+ updateUploadButton: function (isCancel, disabled) {
+ var d = $(this.id + ":upload1");
+ var l = $(this.id + ":upload2");
+ if (d && l) {
+ var label = (isCancel) ? "<b>Cancel</b>" :
"<b>Upload</b>";
+ if (isCancel) {
+ l.innerHTML = label;
+
this.updateButton(d,l,this.cancelStyle,this.cancelStyleDisabled,"start",disabled);
+ d.onclick = function () { if (this.getFilesCount() > 0) { event = null;
this.stopAll(); this.onStopAllClick(); } }.bind(this);
+ }else {
+ l.innerHTML = label;
+
this.updateButton(d,l,this.uploadStyle,this.uploadStyleDisabled,"start",disabled);
+ d.onclick = function () { if (this.getFilesCount() > 0) { event = null;
this.onUploadAllClick(); } }.bind(this);
+ }
+
+ }
+ },
+ updateButton: function (o1,o2, style, styleDis, prefix ,disabled) {
+ if (disabled) {
+ this.setClassName(o1, "upload_button_dis upload_font "+ styleDis);
+ this.setClassName(o2, "upload_button_content upload_font upload_ico
upload_ico_"+prefix+"_dis "+styleDis);
+ }else {
+ this.setClassName(o1, "upload_button upload_font "+ style);
+ this.setClassName(o2, "upload_button_content upload_font upload_ico
upload_ico_"+prefix+" "+style);
+ }
+ },
init: function (id) {
this.id = id;
this.createForm();
},
- addFile: function (){
+ addFile: function (disabled){
var o = $(this.id + ":file");
var parent = o.parentNode;
@@ -50,6 +98,7 @@
upload: function (name) {
var v = this.findFileByName(name);
this.addViewState();
+ this.prepareUpload();
if (v) {
v.disabled = false;
v.name = this.id + ":1";
@@ -57,22 +106,34 @@
this.fm.submit();
}
},
+ next: function (ev) {
+ var f = {};
+ f[this.id] = this.id;
+ f[this.id + "_action"] = "next";
+ A4J.AJAX.Submit(this.containerId,this.formId,ev,{'parameters':f
,'actionUrl':this.actionUrl} );
+ },
onFileUploaded: function (ev) {
- var o = $(this.id + ":1");
- if (o) {
- o.disabled = true;
- o.name = "done";
- o.id = o.name;
+ var d = $(this.id).component;
+ if (d.canceled == true) {
+ d.canceled = false;
+ return;
}
- var formId = FileUpload.Uploaders[this.id]['formId'];
- var containerId = FileUpload.Uploaders[this.id]['containerId'];
- var actionUrl = FileUpload.Uploaders[this.id]['actionUrl'];
- var f = {};
- f[this.id] = this.id;
- f[this.id + "_action"] = "upload";
- new ProgressBar(formId + ":progressBar").disable();
- A4J.AJAX.Submit(containerId,formId,ev,{'parameters':f
,'actionUrl':actionUrl} );
+ var i = $(this.id + ":1");
+ if (i) {
+ this.finishProgressBar();
+ i.disabled = true;
+ i.id = "";
+ i.name = "";
+ this.next(ev);
+ }
},
+ finishProgressBar: function () {
+ var prBar = $(this.formId + ":progressBar");
+ if (prBar) {
+ prBar.component.disable();
+ prBar.component.setValue(100);
+ }
+ },
createForm: function () {
if ($(this.id + ":fr")) return;
var fr = document.createElement("iframe");
@@ -80,13 +141,17 @@
fr.name = fr.id;
fr.style.display="none";
fr.src = "about:blank";
- fr.onload = new Function ("event"," var f = new
FileUpload('"+this.id+"'); if (f.getFilesCount() == 0) return;
f.onFileUploaded(event);");
+ fr.onload = function(request, event, data) {
+ this.onFileUploaded(event);
+ }.bind(this);
+
+ //new Function ("event"," var f = new
FileUpload('"+this.id+"'); if (f.getFilesCount() == 0) return;
f.onFileUploaded(event);");
document.body.appendChild(fr);
var f = document.createElement("form");
f.enctype = "multipart/form-data";
- f.action = FileUpload.Uploaders[this.id]['actionUrl'];
+ f.action = this.actionUrl;
f.method = "post";
f.id = this.id + ":f";
f.target = this.id + ":fr";
@@ -99,7 +164,7 @@
//--
d = document.createElement("input");
d.type="hidden";
- d.name = FileUpload.Uploaders[this.id]['formId'];
+ d.name = this.formId;
d.value = d.name;
f.appendChild(d);
@@ -115,14 +180,25 @@
this.removeChilds(this.f);
},
stop: function () {
- new
ProgressBar(FileUpload.Uploaders[this.id]['formId']+":progressBar").disable();
+ this.canceled = true;
+ $(this.formId+":progressBar").component.disable();
var fr = $(this.id + ":fr");
fr.src = "about:blank";
var f = $(this.id + ":1");
if (f) {
- f.disable = true;
+ f.disabled = true;
f.id = "add";
f.name = f.id;
+ }
+ },
+ stopAll: function () {
+ this.stop();
+ },
+ prepareUpload: function () {
+ for (var i = 0; i < this.f.childNodes.length; i++) {
+ this.f.childNodes[i].disabled = true;
+ this.f.childNodes[i].name="";
+ this.f.childNodes[i].id="";
}
},
removeChilds: function (f) {
@@ -132,42 +208,21 @@
}
}
},
- reduceTimeout: function (id, label, style) {
- var o = $(id);
- if (o) {
- this.reduce(o, o.onclick, label, style );
- }
+ reduce: function (confirmId, id) {
+ var confirm = $(confirmId);
+ var d = $(id);
+ if (confirm)
+ Element.hide(confirm);
+ if (d)
+ Element.show(d);
+ return false;
},
- reduce: function (o, onclick, label , style) {
- var d = document.createElement("a");
- d.href = "#";
- d.innerHTML = label;
- d.style.cssText = style;
- d.onclick= onclick;
- d.onmousedown = function () { return new FileUpload().confirm(this, label, style); }
- var p = o.parentNode;
- this.removeChilds(p);
- p.appendChild(d);
+ confirm: function (confirmId, id) {
+ Element.show($(confirmId));
+ Element.hide($(id));
+ window.setTimeout("$('"+this.id+"').component.reduce('"+confirmId+"','"+id+"');",
3000);
+ return false;
},
- confirm: function (o, label, style, id) {
- var y = document.createElement("a");
- y.href = "#";
- y.innerHTML = "Yes";
- y.style.cssText = style;
- y.onclick= o.onclick;
- y.id = id;
- var n = document.createElement("a");
- n.href = "#";
- n.innerHTML = "No";
- n.style.cssText = style + "; padding-left: 10px;";
- n.onclick= function () { new FileUpload().reduce(this, o.onclick, label, style); } ;
- var p = o.parentNode;
- this.removeChilds(p);
- p.appendChild(y);
- p.appendChild(n);
- window.setTimeout("new
FileUpload().reduceTimeout('"+id+"','"+label+"','"+style+"');",3000);
- return false;
- },
findFileByName: function(name) {
for (var i = 0; i < this.getFilesCount(); i++) {
var d = this.f.childNodes[i];
Modified: trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-02-08
17:50:25 UTC (rev 5960)
+++
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-02-08
18:10:37 UTC (rev 5961)
@@ -24,13 +24,21 @@
<div class="upload_list_width upload_list_decor"
id="#{clientId}">
+<span style="display: none">
+ <script type="text/javascript">
+ <f:call name="encodeInitialScript" />
+ </script>
+</span>
+
<table class="upload_toolbar_decor">
<tr>
<td>
<div class="upload_button_border" style=" float:left;">
- <div class="upload_button upload_font"
onmouseover="this.className='upload_button_light upload_font'"
onmousedown="this.className='upload_button_press upload_font'"
onmouseup="this.className='upload_button upload_font'"
onmouseout="this.className='upload_button upload_font'"
- style="position: relative; overflow: hidden; direction: rtl;
width:70px">
- <div class="upload_button_content upload_font upload_ico
upload_ico_add" style="">Add...</div>
+ <div class="upload_button upload_font
#{component.attributes['addStyle']}"
onmouseover="this.className='upload_button_light upload_font'"
onmousedown="this.className='upload_button_press upload_font'"
onmouseup="this.className='upload_button upload_font'"
onmouseout="this.className='upload_button upload_font'"
+ style="position: relative; overflow: hidden; direction: rtl;
width:70px"
+ id="#{clientId}:add1">
+ <div class="upload_button_content upload_font upload_ico upload_ico_add
#{component.attributes['addStyle']}"
+ id="#{clientId}:add2">Add...</div>
<input type="file" style="cursor: pointer; z-index: 3; width:
0px; height: 22px; left: 0px; top: 0px; position: absolute"
class="hidden"
id="#{clientId}:file"
@@ -39,21 +47,25 @@
</div>
</div>
<div class="upload_button_border" style=" float:left;">
- <div class="upload_button upload_font"
onmouseover="this.className='upload_button_light upload_font'"
onmousedown="this.className='upload_button_press upload_font'"
onmouseup="this.className='upload_button upload_font'"
+ <div class="upload_button_dis upload_font
#{component.attributes['uploadStyleDisabled']}"
onmouseover="this.className='upload_button_light upload_font'"
onmousedown="this.className='upload_button_press upload_font'"
onmouseup="this.className='upload_button upload_font'"
onmouseout="this.className='upload_button upload_font'"
- onclick="javascript: if ((new
FileUpload('#{clientId}').getFilesCount()) > 0) {
#{this:getUploadAllClick(context, component)} }">
+ id="#{clientId}:upload1">
<a href="#" class="upload_button_selection">
- <div class="upload_button_content upload_font upload_ico
upload_ico_start"><b>Upload</b>
+ <div class="upload_button_content upload_font upload_ico
upload_ico_start_dis #{component.attributes['uploadStyleDisabled']}"
+ id="#{clientId}:upload2">
+ <b>Upload</b>
</div>
</a>
</div>
</div>
<div class="upload_button_border" style=" float:right">
- <div class="upload_button upload_font"
onmouseover="this.className='upload_button_light upload_font'"
onmousedown="this.className='upload_button_press upload_font'"
onmouseup="this.className='upload_button upload_font'"
+ <div class="upload_button_dis upload_font
#{component.attributes['cleanStyleDisabled']}"
onmouseover="this.className='upload_button_light upload_font'"
onmousedown="this.className='upload_button_press upload_font'"
onmouseup="this.className='upload_button upload_font'"
onmouseout="this.className='upload_button upload_font'"
- onclick="#{this:getClearAllClick(context, component)}">
+ onclick="if ($('#{clientId}').component.getFilesCount() > 0) {
#{this:getClearAllClick(context, component)} }"
+ id="#{clientId}:clean1">
<a href="#" class="upload_button_selection">
- <div class="upload_button_content upload_font upload_ico
upload_ico_clear">Clear All</div>
+ <div class="upload_button_content upload_font upload_ico
upload_ico_clear_dis #{component.attributes['cleanStyleDisabled']}"
+ id="#{clientId}:clean2">Clean All</div>
</a>
</div>
</div>
@@ -89,8 +101,8 @@
renderProgress(context, component, item);
]]>
</jsp:scriptlet>
- <br/>
+
<div class="upload_name_padding">
<b>
<jsp:scriptlet>
@@ -110,10 +122,13 @@
]]>
</jsp:scriptlet>
<div class="upload_font upload_del">
- <a href="#" class="upload_anc"
- onmousedown="return new
FileUpload().confirm(this,'Clear','text-decoration:none;
color:black','#{clientId}:clear#{n}');"
- onclick="#{this:getClearFileClick(context, component)}"
- style="text-decoration: none; color:black">Clear</a>
+ <a href="#" class="upload_anc"
id="#{clientId}:clear#{n}"
+ onclick="return
$('#{clientId}').component.confirm('#{clientId}:cconfirm#{n}','#{clientId}:clear#{n}');"
+ style="text-decoration: none; color:black">Clear</a>
+ <span id="#{clientId}:cconfirm#{n}"
style="display:none">
+ <a href="#" onclick="#{this:getClearFileClick(context,
component)}" style="text-decoration: none; color:black">Yes</a>
+ <a href="#"
onclick="$('#{clientId}').component.reduce('#{clientId}:cconfirm#{n}','#{clientId}:clear#{n}');"
style="text-decoration: none; padding-left: 10px; color:black">No</a>
+ </span>
</div>
<jsp:scriptlet>
<![CDATA[
@@ -121,10 +136,13 @@
]]>
</jsp:scriptlet>
<div class="upload_font upload_del">
- <a href="#" class="upload_anc"
- onmousedown="return new
FileUpload().confirm(this,'Stop','text-decoration:none;
color:black','#{clientId}:stop#{n}');"
- onclick="new FileUpload('#{clientId}').stop();
#{this:getStopFileClick(context, component)}"
+ <a href="#" class="upload_anc"
id="#{clientId}:stop#{n}"
+ onclick="return
$('#{clientId}').component.confirm('#{clientId}:sconfirm#{n}','#{clientId}:stop#{n}');"
style="text-decoration: none; color:black">Stop</a>
+ <span id="#{clientId}:sconfirm#{n}"
style="display:none">
+ <a href="#" onclick="$('#{clientId}').component.stop();
#{this:getStopFileClick(context, component)}" style="text-decoration: none;
color:black">Yes</a>
+ <a href="#"
onclick="$('#{clientId}').component.reduce('#{clientId}:sconfirm#{n}','#{clientId}:stop#{n}');"
style="text-decoration: none; padding-left: 10px; color:black">No</a>
+ </span>
</div>
<jsp:scriptlet>
@@ -148,17 +166,13 @@
<span>
<script type="text/javascript">
+ <f:call name="encodeUpdateButtonScript" />
<f:call name="encodeUploadScript" />
</script>
</span>
</div>
- <span>
- <script type="text/javascript">
- <f:call name="encodeInitialScript" />
- </script>
- </span>
</div>