Author: andrei_exadel
Date: 2008-02-05 07:45:27 -0500 (Tue, 05 Feb 2008)
New Revision: 5814
Modified:
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/FileItem.java
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/fileUpload3.jspx
Log:
Modified:
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/FileItem.java
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/FileItem.java 2008-02-05
12:38:47 UTC (rev 5813)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/FileItem.java 2008-02-05
12:45:27 UTC (rev 5814)
@@ -17,7 +17,7 @@
public class FileItem {
/** Defines list of statuses available */
- public static enum Status {ADDED, MARKED_4_UPLOAD, IN_PROGRESS, UPLOADED};
+ public static enum Status {ADDED, MARKED_4_UPLOAD, IN_PROGRESS, UPLOADED,
CANCELLED};
/** Pattern to search file name in full file name string */
private static final Pattern pattern = Pattern.compile
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-05
12:38:47 UTC (rev 5813)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java 2008-02-05
12:45:27 UTC (rev 5814)
@@ -181,12 +181,12 @@
@Override
public Object saveState(FacesContext context) {
if (values == null) {
- values = new Object[4];
+ values = new Object[3];
}
values[0] = super.saveState(context);
values[1] = fileItems;
values[2] = uploadStatus;
- values[3] = progressBar;
+ //values[3] = this.getFacet("progress");
return values;
}
@@ -202,10 +202,9 @@
super.restoreState(context, values[0]);
fileItems = (List<FileItem>) values[1];
uploadStatus = (String) values[2];
- if (values[3] != null) {
- progressBar = (UIComponent)values[3];
- }
-
+// if (values[3] != null) {
+// this.getFacets().put("progress", (UIComponent)values[3]);
+// }
}
/**
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-05
12:38:47 UTC (rev 5813)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java 2008-02-05
12:45:27 UTC (rev 5814)
@@ -4,6 +4,7 @@
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -32,23 +33,41 @@
import org.richfaces.org.jboss.seam.web.MultipartRequest;
import org.richfaces.renderkit.TemplateEncoderRendererBase;
+/**
+ * Class provides base renderer for upload file component
+ * @author "Andrey Markavtsov"
+ *
+ */
public abstract class FileUploadRendererBase extends
TemplateEncoderRendererBase {
+ /** Add file action name */
private static final String ACTION_ADD_FILE = "add";
+ /** Upload all files action name */
private static final String ACTION_UPLOAD_ALL = "uploadall";
+ /** Upload file action name */
private static final String ACTION_UPLOAD = "upload";
+ /** Clear file action name */
private static final String ACTION_CLEAR_FILE = "clear";
+ /** Clear all files action name */
private static final String ACTION_CLEAR_ALL = "clearall";
+
+ /** Stop file uploading action name */
+ private static final String ACTION_STOP_FILE = "stop";
+ /** 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$";
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.renderkit.RendererBase#doDecode(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
+ */
@Override
protected void doDecode(FacesContext context, UIComponent component) {
UIFileUpload fileUpload = (UIFileUpload) component;
@@ -59,9 +78,8 @@
Map<String, String[]> params = context.getExternalContext()
.getRequestParameterValuesMap();
- if (params.containsKey(getProgressBarParameterName(fileUpload))) {
- new AjaxEvent(fileUpload.getProgressBar());
- }
+ new AjaxEvent(component).queue();
+
if (params.containsKey(getActionParameterName(clientId))) {
processEvents(context, component, clientId);
AjaxContext ajaxContext = AjaxContextImpl
@@ -104,42 +122,10 @@
@Override
public void encodeBegin(FacesContext context, UIComponent component)
throws IOException {
- // Map<String, String[]> params = context.getExternalContext()
- // .getRequestParameterValuesMap();
- // ServletRequest request = (ServletRequest)
- // context.getExternalContext()
- // .getRequest();
- //
- // if (!params.containsKey("action")
- // && !(request instanceof MultipartRequest)) {
- // return;
- // }
- //
- // super.encodeBegin(context, component);
- // UIFileUpload fileUpload = (UIFileUpload) component;
- // String status = fileUpload.getUploadStatus();
- // boolean isAll2reRender = true;
- // if ("ADD".equals(action)) {
- // isAll2reRender = false;
- // } else if ("CLEARALL".equals(action)) {
- // if (UIFileUpload.UPLOADING.equals(status)) {
- // isAll2reRender = true;
- // } else {
- // isAll2reRender = false;
- // }
- // } else if ("UPLOAD".equals(action)) {
- // isAll2reRender = false;
- // } else if ("CLEAR".equals(action)) {
- // isAll2reRender = false;
- // } else if ("UPDATE".equals(action)) {
- // isAll2reRender = false;
- // }
- //
AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance();
ajaxContext.removeRenderedArea(component.getClientId(context));
ajaxContext.addRenderedArea(component.getClientId(context)
+ ":fileItems");
-
}
public String encodeStatus(UIFileUpload fileUpload) {
@@ -163,28 +149,14 @@
Iterator<FileItem> it = fileUpload.getFileItems().iterator();
while (it.hasNext()) {
FileItem item = it.next();
- if (item.getFileName().equals(name)) {
+ if (item.getFullFileName().equals(name)) {
return item;
}
}
return null;
}
- // public String getFile2Upload(FacesContext context, UIComponent component)
- // {
- // UIFileUpload fileUpload = (UIFileUpload) component;
- // if (UIFileUpload.UPLOADING.equals(fileUpload.getUploadStatus())) {
- // Iterator<FileItem> it = fileUpload.getFileItems().iterator();
- // while (it.hasNext()) {
- // FileItem item = it.next();
- // if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
- // return item.getFullFileName();
- // }
- // }
- // }
- // return "";
- // }
-
+
public String getActionUrl(FacesContext context) {
AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance(context);
return ajaxContext.getAjaxActionURL(context);
@@ -246,11 +218,13 @@
} else if (ACTION_UPLOAD_ALL.equals(action)) {
processUploadAllAction(context, fileUpload);
} else if (ACTION_CLEAR_ALL.equals(action)) {
- fileUpload.getFileItems().clear();
+ 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_STOP_FILE.equals(action)) {
+ processStopFileAction(context, fileUpload, params);
}
}
@@ -264,22 +238,33 @@
}
}
}
+
+ private void processStopFileAction(FacesContext context,
+ UIFileUpload fileUpload, Map<String, String[]> params) {
+ if (params.containsKey(ACTION_STOP_FILE)) {
+ String[] fileNames = params.get(ACTION_STOP_FILE);
+ for (String name : fileNames) {
+ FileItem item = getFileByName(fileUpload, name);
+ if (item != null) {
+ item.setStatus(FileItem.Status.CANCELLED);
+ }
+ }
+ }
+ }
- // private UIComponent getProgressBar(FacesContext context,
- // UIComponent fileUpload) {
- // // return fileUpload.getFacet("progress");
- // UIComponent progressBar = fileUpload.getFacet("progress");
- // if (progressBar != null) {
- // String exprStr = "#{" + _percentBeanName + "}";
- // ValueExpression ex = context.getApplication()
- // .getExpressionFactory().createValueExpression(
- // context.getELContext(), exprStr, Integer.class);
- // progressBar.setValueExpression("value", ex);
- // progressBar.setId("progressBar");
- // }
- // return progressBar;
- // }
+ private void processClearAllAction(UIFileUpload fileUpload) {
+ List<FileItem> toDelete = new ArrayList<FileItem>();
+ for (FileItem item : fileUpload.getFileItems()) {
+ if (item.getStatus() != FileItem.Status.IN_PROGRESS) {
+ toDelete.add(item);
+ }
+ }
+ for (FileItem item : toDelete) {
+ fileUpload.getFileItems().remove(item);
+ }
+ }
+
private void removeFileItem(String name, UIFileUpload fileUpload) {
Iterator<FileItem> it = fileUpload.getFileItems().iterator();
while (it.hasNext()) {
@@ -303,7 +288,6 @@
}
}
getSession(context).setAttribute(_percentBeanName, 0);
- fileUpload.setUploadStatus(UIFileUpload.UPLOADING);
}
}
@@ -418,10 +402,8 @@
FileItem item = it.next();
if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
found = true;
- StringBuffer buffer = new StringBuffer();
- buffer.append("new FileUpload('");
- buffer.append(cliendId);
- buffer.append("').upload('");
+ StringBuffer buffer = getJSScriptStart(cliendId);
+ buffer.append(".upload('");
buffer.append(convertFileName(item.getFullFileName()));
buffer.append("');");
writer.write(buffer.toString());
@@ -430,11 +412,11 @@
}
}
} else {
- StringBuffer buffer = new StringBuffer();
- buffer.append("A4J.AJAX.StopPoll(FileUpload.Uploaders['");
- buffer.append(cliendId);
- buffer.append("']['formId'] + ':progressBar');\n");
- writer.write(buffer.toString());
+// StringBuffer buffer = new StringBuffer();
+// buffer.append("A4J.AJAX.StopPoll(FileUpload.Uploaders['");
+// buffer.append(cliendId);
+// buffer.append("']['formId'] + ':progressBar');\n");
+// writer.write(buffer.toString());
}
}
@@ -483,6 +465,8 @@
writer.write("Done");
} else if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
writer.write("In progress....");
+ } else if (item.getStatus() == FileItem.Status.CANCELLED) {
+ writer.write("Cancelled");
}
}
@@ -493,8 +477,12 @@
renderChild(context, progressBar);
}
}
+
+ public boolean isCanClear (FileItem item) {
+ return item.getStatus() != FileItem.Status.IN_PROGRESS;
+ }
- private UIComponent findProgressBar(UIFileUpload fileUpload) {
+ private UIComponent findProgressBar(UIComponent fileUpload) {
UIComponent progressBar = null;
for (UIComponent child : fileUpload.getChildren()) {
if (child instanceof UIFileUpload) {
@@ -504,73 +492,102 @@
}
return progressBar;
}
-
- private void addComponentToReRender(FacesContext context, UIComponent component) {
+
+ private void addComponentToReRender(FacesContext context,
+ UIComponent component) {
AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance(context);
ajaxContext.addComponentToAjaxRender(component);
}
+
+ private UIComponent createProgressBar(FacesContext context,
+ UIComponent fileUpload) {
+ UIComponent progressBar = fileUpload.getFacet("progress");
+ if (null == progressBar) {
+ progressBar = context.getApplication().createComponent(
+ UIProgressBar.COMPONENT_TYPE);
+ }
+ fileUpload.getFacets().put("progress", progressBar);
+ return progressBar;
+ }
private UIComponent getProgressBar(FacesContext context,
UIComponent component) {
- UIFileUpload fileUpload = (UIFileUpload) component;
- UIComponent progressBar = fileUpload.getProgressBar();
- if (progressBar == null) {
- progressBar = context.getApplication().createComponent(
- UIProgressBar.COMPONENT_TYPE);
- String exprStr = "#{" + _percentBeanName + "}";
- ValueExpression ex = context.getApplication()
- .getExpressionFactory().createValueExpression(
- context.getELContext(), exprStr, Integer.class);
- progressBar.setValueExpression("value", ex);
- progressBar.setId("progressBar");
- progressBar.setParent(fileUpload);
- fileUpload.setProgressBar(progressBar);
- /*fileUpload.getChildren().add(progressBar);
- addComponentToReRender(context, progressBar);*/
+ UIComponent progressBar = component.getFacet("progress");
+ if (null == progressBar) {
+ progressBar = createProgressBar(context, component);
}
+ String exprStr = "#{" + _percentBeanName + "}";
+ ValueExpression ex = context.getApplication().getExpressionFactory()
+ .createValueExpression(context.getELContext(), exprStr,
+ Integer.class);
+ progressBar.setValueExpression("value", ex);
+ progressBar.setId("progressBar");
+ progressBar.setTransient(false);
+
return progressBar;
}
+
+ private StringBuffer getJSScriptStart(String clientId) {
+ StringBuffer buffer = new StringBuffer("new FileUpload('");
+ buffer.append(clientId).append("')");
+ return buffer;
+ }
public String getUploadAllClick(FacesContext context, UIComponent component) {
String clientId = component.getClientId(context);
-
Map parameters = new HashMap();
parameters.put(getActionParameterName(clientId), ACTION_UPLOAD_ALL);
-
return getOnClick(context, component, clientId, parameters, null);
-
}
+
+ public String getStopFileClick(FacesContext context, UIComponent component) {
+ String clientId = component.getClientId(context);
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(
+ this, component);
+ String fileName = (String) variables.getVariable("fullFileName");
+ Map parameters = new HashMap();
+ parameters.put(getActionParameterName(clientId), ACTION_STOP_FILE);
+ parameters.put(ACTION_STOP_FILE, fileName);
+ return getOnClick(context, component, clientId, parameters, null);
+ }
public String getClearFileClick(FacesContext context, UIComponent component) {
String clientId = component.getClientId(context);
-
+ StringBuffer buffer = new StringBuffer();
ComponentVariables variables = ComponentsVariableResolver.getVariables(
this, component);
String fileName = (String) variables.getVariable("fullFileName");
- StringBuffer body = new StringBuffer();
- body.append("new FileUpload('");
- body.append(clientId);
- body.append("').clear('");
- body.append(convertFileName(fileName));
- body.append("');");
+ StringBuffer body = getJSScriptStart(clientId)
+ .append(".clear('")
+ .append(convertFileName(fileName))
+ .append("');");
Object oncomplete = getOnComplete(context, component, body);
Map parameters = new HashMap();
parameters.put(getActionParameterName(clientId), ACTION_CLEAR_FILE);
parameters.put(ACTION_CLEAR_FILE, fileName);
-
+
return getOnClick(context, component, clientId, parameters, oncomplete);
}
+
+ public String getClearAllClick(FacesContext context, UIComponent component) {
+ String clientId = component.getClientId(context);
+ StringBuffer body = getJSScriptStart(clientId)
+ .append(".clearAll();");
+ Object oncomplete = getOnComplete(context, component, body);
+ Map parameters = new HashMap();
+ parameters.put(getActionParameterName(clientId), ACTION_CLEAR_ALL);
+ return getOnClick(context, component, clientId, parameters, oncomplete);
+ }
+
public String getAddFileClick(FacesContext context, UIComponent component) {
String clientId = component.getClientId(context);
- StringBuffer body = new StringBuffer();
- body.append("new FileUpload('");
- body.append(clientId);
- body.append("').addFile();");
+ StringBuffer body = getJSScriptStart(clientId)
+ .append(".addFile();");
Object oncomplete = getOnComplete(context, component, body);
Map parameters = new HashMap();
@@ -599,7 +616,7 @@
return script.toString();
}
- public JSFunctionDefinition getOnComplete(FacesContext context,
+ private JSFunctionDefinition getOnComplete(FacesContext context,
UIComponent component, Object body) {
JSFunctionDefinition oncomplete = new JSFunctionDefinition();
oncomplete.addParameter("request");
@@ -609,80 +626,6 @@
return oncomplete;
}
- // public void encodeAddControl(FacesContext context, UIComponent component)
- // throws IOException {
- // ResponseWriter writer = context.getResponseWriter();
- // StringBuffer buffer = new StringBuffer();
- // buffer.append("<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'>Add...</div><input type='file' ");
- // buffer.append("onchange=\\\"");
- // buffer.append(getActionOnClick(context, component, "ADD",
"false"));
- // buffer.append("\\\"");
- // buffer.append(" style='cursor: pointer; z-index: 3; width: 0px; height:
- // 22px; left: 0px; top: 0px; position: absolute'
- // class='hidden'/></div></div>");
- // writer.write(buffer.toString());
- // }
- //
- // public void encodeUploadControl(FacesContext context, UIComponent
- // component)
- // throws IOException {
- // ResponseWriter writer = context.getResponseWriter();
- // StringBuffer buffer = new StringBuffer();
- // String clientId = component.getClientId(context);
- // buffer.append("<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'\\\"><a href='#'
- // class='upload_button_selection'><div
class='upload_button_content
- // upload_font upload_ico
- //
upload_ico_start'><b>Upload</b></div></a></div></div>");
- // writer.write(buffer.toString());
- // }
- //
- // public void encodeCleanControl(FacesContext context, UIComponent
- // component)
- // throws IOException {
- // ResponseWriter writer = context.getResponseWriter();
- // StringBuffer buffer = new StringBuffer();
- // String clientId = component.getClientId(context);
- // buffer.append("<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'\\\"
- // onmouseout=\\\"this.className='upload_button
upload_font'\\\"><a href='#'
- // class='upload_button_selection'><div
class='upload_button_content
- // upload_font upload_ico upload_ico_clear'>Clear
- // All</div></a></div></div>");
- // writer.write(buffer.toString());
- // }
-
- // private String convertToString(Object obj) {
- // return (obj == null ? "" : obj.toString());
- // }
- //
- // private String convertToString(boolean b) {
- // return String.valueOf(b);
- // }
- //
- // private String convertToString(int b) {
- // return b != Integer.MIN_VALUE ? String.valueOf(b) : "";
- // }
- //
- // private String convertToString(long b) {
- // return b != Long.MIN_VALUE ? String.valueOf(b) : "";
- // }
-
/*
* (non-Javadoc)
*
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-05
12:38:47 UTC (rev 5813)
+++
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss 2008-02-05
12:45:27 UTC (rev 5814)
@@ -11,7 +11,7 @@
.upload_font{font-family : verdana /*generalFamilyFont*/ ; font-size :
11px/*generalSizeFont*/;}
table{width : 100%}
-#upload_table td{border-bottom:1px solid #c0c0c0 /*tableBorderColor*/;white-space :
nowrap;}
+.upload_table_td{border-bottom:1px solid #c0c0c0 /*tableBorderColor*/;white-space :
nowrap;}
.upload_list_width{ width:400px;}
.upload_list_decor{ border:1px solid #c0c0c0 /*tableBorderColor*/; background : #FFFFFF
/*tableBackgroundColor*/;}
@@ -24,23 +24,17 @@
.upload_toolbar_decor{ background : #EAF0F8
/*additionalBackgroundColor*/;border-bottom:1px solid #c0c0c0
/*tableBorderColor*/;border-top:1px solid #FFFFFF /*tableBackgroundColor*/;border-left:1px
solid #FFFFFF /*tableBackgroundColor*/;padding : 2px}
-.upload_bar_exterior{height : 7px; border : 1px solid #c0c0c0 /*panelBorderColor*/;}
-.upload_bar_uploaded{height : 7px; width : 70%; height : 100%; background : #FF9409 /**/;
background-image : url(images/bg_ProgressBar_perm.gif);background-repeat : repeat-x;
font-size : 0px;}
-.upload_bar_deleted{height : 7px; width : 40%; height : 100%; background : #FF9409 /**/;
background-image : url(images/bg_RegressBar_perm.gif);background-repeat : repeat-x;
font-size : 0px;}
-.upload_bar_shell{height : 7px; width : 100%; height : 8; background :
#F1F1F1/*tableSubfooterBackgroundColor*/;}
-
-
.upload_button_border{
border : 1px solid #C0C0C0; /*tableBorderColor*/
margin : 2px;
}
.upload_button{
- background : url(images/bg_header.png) /*from additionalBackgroundColor to trimColor*/
top left #C6D6EA /*trimColor*/ repeat-x;
+ background-repeat: repeat x top left #C6D6EA;
cursor : pointer;
padding : 2px;
}
.upload_button_light{
- background : url(images/bg_header.png) /*from additionalBackgroundColor to
headerGradientColor*/ top left #C6D6EA /*trimColor*/ repeat-x;
+ background-repeat: repeat x top left #C6D6EA;
border : 1px solid #E79A00; /*selectControlColor*/
cursor : pointer;
padding : 1px;
@@ -50,8 +44,9 @@
border : 1px solid #C0C0C0; /*tableBorderColor*/
margin-bottom : 3px;
padding : 1px}
+
.upload_button_press{
- background : url(images/bg_press.png) /*from additionalBackgroundColor to trimColor*/
top left repeat-x #EAF0F8; /* additionalBackgroundColor*/
+ background-repeat: repeat x top left #EAF0F8;
border : 1px solid #E79A00; /*selectControlColor*/
padding : 2px 0px 0px 2px;
}
@@ -73,10 +68,10 @@
.upload_name_padding{padding : 2px 0px 2px 0px;}
.upload_ico{background-position : 0px 50%; background-repeat : no-repeat; padding-left :
19px}
-.upload_ico_add{background-image : url(images/ico_add.gif)}
-.upload_ico_start{background-image : url(images/ico_start.gif)}
-.upload_ico_stop{background-image : url(images/ico_stop.gif)}
-.upload_ico_clear{background-image : url(images/ico_clear.gif)}
+.upload_ico_add{}
+.upload_ico_start{}
+.upload_ico_stop{}
+.upload_ico_clear{}
input.hidden {
Z-INDEX: 2;
@@ -89,5 +84,46 @@
]]>
</f:verbatim>
+<u:selector name=".upload_button">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/bg_header.png"
/>
+ </u:style>
+</u:selector>
+
+<u:selector name=".upload_button_light">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/bg_header.png"
/>
+ </u:style>
+</u:selector>
+
+<u:selector name=".upload_button_press">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/bg_press.png"
/>
+ </u:style>
+</u:selector>
+
+<u:selector name=".upload_ico_add">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/ico_add.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_stop">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/ico_stop.gif"
/>
+ </u:style>
+</u:selector>
+
+<u:selector name=".upload_ico_clear">
+ <u:style name="background-image">
+ <f:resource f:key="/org/richfaces/renderkit/html/images/ico_clear.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-05
12:38:47 UTC (rev 5813)
+++
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-02-05
12:45:27 UTC (rev 5814)
@@ -11,9 +11,9 @@
}
},
renderControl: function (template, context) {
- if (!template) {
- return;
- }
+ if (!template) {
+ return;
+ }
var html = template.invoke('getContent', context).join('');
$(this.id + ":header").innerHTML = html;
},
@@ -21,15 +21,7 @@
this.id = id;
this.createForm();
},
- test: function (ev) {
- alert('Done;');
- },
- isUploading: function () {
- if ($(this.id + ":status").value == "uploading") return true;
- return false;
- },
addFile: function (){
- alert($(this.id + ":file"));
var o = $(this.id + ":file");
var parent = o.parentNode;
@@ -45,26 +37,16 @@
this.f.appendChild(o);
parent.appendChild(clon);
-
- $(this.id + ":fileName").value = o.value;
},
addViewState: function () {
- if (!this.fm['javax.faces.ViewState']) {
+ if (!this.fm['javax.faces.ViewState']) {
var d = document.createElement("input");
d.type="hidden";
d.name = "javax.faces.ViewState";
d.value = $("javax.faces.ViewState").value;
this.fm.appendChild(d);
- }
+ }
},
- beforeUploadFile: function(name) {
- $(this.id + ":fileName").value = name;
- },
- beforeUploadAll: function() {
- if (this.getFilesCount() > 0) {
- $(this.id + ":fileName").value = this.f.childNodes[0].value;
- }
- },
upload: function (name) {
var v = this.findFileByName(name);
this.addViewState();
@@ -75,39 +57,6 @@
this.fm.submit();
}
},
- uploadFile: function (name) {
- if (!this.isUploading()) {
- this.addViewState();
- var v = this.findFileByName(name);
- if (v) {
- v.disabled = false;
- v.name = this.id + ":1";
- v.id = v.name;
- this.fm.submit();
- }
- }
- },
- uploadAll: function (name) {
- if (!this.isUploading()) {
- this.addViewState();
- if (!$(this.id + ":1")) {
- this.mark4upload();
- if (name) {
- this.uploadFile(name);
- }
-
- }
- }else {
- this.mark4upload();
- }
- },
- findFileToUpload: function () {
- for (var i = 0; i < this.getFilesCount(); i++) {
- var v = this.f.childNodes[i];
- if (v.name == "4upload") return v;
- }
- return null;
- },
onFileUploaded: function (ev) {
var formId = FileUpload.Uploaders[this.id]['formId'];
var containerId = FileUpload.Uploaders[this.id]['containerId'];
@@ -116,29 +65,17 @@
f[this.id] = this.id;
f[this.id + "_action"] = "upload";
A4J.AJAX.StopPoll(formId + ":progressBar");
- new ProgressBar(this.id + ":progressBar").setValue(100);
+ //new ProgressBar(formId + ":progressBar").setValue(100);
A4J.AJAX.Submit(containerId,formId,ev,{'parameters':f
,'actionUrl':actionUrl} );
},
- getForm: function () {
- var p = $(this.id).parentNode;
- while (p) {
- if (p) {
- if (p.tagName.toUpperCase() == "FORM") {
- return p;
- }
- }
- p = p.parentNode;
- }
- return null;
- },
- createForm: function (){
- if ($(this.id + ":fr")) return;
+ createForm: function () {
+ if ($(this.id + ":fr")) return;
var fr = document.createElement("iframe");
fr.id = this.id + ":fr";
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;
alert('in onload'); f.onFileUploaded(event);");
+ fr.onload = new Function ("event"," var f = new
FileUpload('"+this.id+"'); if (f.getFilesCount() == 0) return;
f.onFileUploaded(event);");
document.body.appendChild(fr);
@@ -162,7 +99,6 @@
f.appendChild(d);
//--
-
},
getFilesCount: function () {
if (this.f.hasChildNodes()) {
@@ -171,12 +107,61 @@
return 0;
},
clearAll: function() {
- if (this.f && this.f.hasChildNodes && this.f.removeChild) {
- while (this.f.hasChildNodes()) {
- this.f.removeChild(this.f.firstChild);
+ this.removeChilds(this.f);
+ },
+ stop: function () {
+ new
ProgressBar(FileUpload.Uploaders[this.id]['formId']+":progressBar").disable();
+ this.fm.reset();
+ var f = $(this.id + ":1");
+ if (f) {
+ f.disable = true;
+ f.id = "add";
+ f.name = f.id;
+ }
+ },
+ removeChilds: function (f) {
+ if (f && f.hasChildNodes && f.removeChild) {
+ while (f.hasChildNodes()) {
+ f.removeChild(f.firstChild);
}
}
},
+ reduceTimeout: function (id, label, style) {
+ var o = $(id);
+ if (o) {
+ this.reduce(o, o.onclick, label, style );
+ }
+ },
+ 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 (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];
@@ -192,17 +177,5 @@
if (v) {
this.f.removeChild(v);
}
- $(this.id + ":fileName").value = name;
- },
- mark4upload: function() {
- if (this.f && this.f.hasChildNodes && this.f.removeChild) {
- for (var i = 0; i < this.getFilesCount(); i++) {
- var v = this.f.childNodes[i];
- if ((v.name != (this.id + ":1")) && (v.name != "done"))
{
- v.name = "4upload";
- v.id = "4upload";
- }
- }
- }
}
});
Modified: trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload3.jspx
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload3.jspx 2008-02-05
12:38:47 UTC (rev 5813)
+++
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload3.jspx 2008-02-05
12:45:27 UTC (rev 5814)
@@ -49,7 +49,9 @@
</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'"
onmouseout="this.className='upload_button upload_font'">
+ <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'"
+ onclick="#{this:getClearAllClick(context, component)}">
<a href="#" class="upload_button_selection">
<div class="upload_button_content upload_font upload_ico
upload_ico_clear">Clear All</div>
</a>
@@ -64,18 +66,20 @@
<jsp:scriptlet>
<![CDATA[
Iterator<org.richfaces.org.jboss.seam.ui.component.FileItem> it =
component.getFileItems().iterator();
+ Integer i = 0;
while (it.hasNext()) {
org.richfaces.org.jboss.seam.ui.component.FileItem item = it.next();
String fullFileName = item.getFullFileName();
String fileName = item.getFileName();
variables.setVariable("fileName",fileName);
variables.setVariable("fullFileName",fullFileName);
+ variables.setVariable("n",i);
]]>
</jsp:scriptlet>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
- <td class="upload_font upload_name">
+ <td class="upload_font upload_name upload_table_td">
<div class="upload_name_padding">
#{fileName}
</div>
@@ -85,8 +89,8 @@
renderProgress(context, component, item);
]]>
</jsp:scriptlet>
+ <br/>
-
<div class="upload_name_padding">
<b>
<jsp:scriptlet>
@@ -99,30 +103,54 @@
</td>
- <td>
- <div class="upload_font upload_del">
- <a href="#" class="upload_anc"
onclick="#{this:getClearFileClick(context, component)}">Clear</a>
- </div>
+ <td class="upload_table_td">
+ <jsp:scriptlet>
+ <![CDATA[
+ if (isCanClear(item)) {
+ ]]>
+ </jsp:scriptlet>
+ <div class="upload_font upload_del">
+ <a href="#" class="upload_anc"
+ onmousedown="return new
FileUpload().confirm(this,'Clear','text-decoration:none;
color:#EAF0F8','#{clientId}:clear#{n}');"
+ onclick="#{this:getClearFileClick(context, component)}"
+ style="text-decoration: none; color:#EAF0F8">Clear</a>
+ </div>
+ <jsp:scriptlet>
+ <![CDATA[
+ } else {
+ ]]>
+ </jsp:scriptlet>
+ <div class="upload_font upload_del">
+ <a href="#" class="upload_anc"
+ onclick="new FileUpload('#{clientId}').stop();
#{this:getStopFileClick(context, component)}">Stop</a>
+ </div>
+
+ <jsp:scriptlet>
+ <![CDATA[
+ }
+ ]]>
+ </jsp:scriptlet>
<div class="upload_font upload_del"><br /></div>
</td>
- <td>
+ <td class="upload_table_td">
<div class="upload_font upload_scroll"></div>
</td>
</tr>
</table>
+ <jsp:scriptlet>
+ <![CDATA[
+ i++;
+ }
+ ]]>
+ </jsp:scriptlet>
+
<span>
<script type="text/javascript">
<f:call name="encodeUploadScript" />
</script>
</span>
- <jsp:scriptlet>
- <![CDATA[
- }
- ]]>
- </jsp:scriptlet>
-
</div>
<span>