Author: konstantin.mishin
Date: 2010-12-03 15:08:40 -0500 (Fri, 03 Dec 2010)
New Revision: 20386
Added:
trunk/ui/misc/ui/src/main/java/org/richfaces/request/
trunk/ui/misc/ui/src/main/java/org/richfaces/view/
trunk/ui/misc/ui/src/main/java/org/richfaces/view/facelets/
trunk/ui/misc/ui/src/main/resources/META-INF/fileupload.faces-config.xml
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fu-add-dis.gif
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fu-add.gif
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fu-clr.gif
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fu-upl.gif
trunk/ui/misc/ui/src/main/resources/META-INF/richfaces/
Log:
RF-9921
Copied: trunk/ui/misc/ui/src/main/java/org/richfaces/request (from rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request)
Copied: trunk/ui/misc/ui/src/main/java/org/richfaces/view/facelets (from rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/view/facelets)
Copied: trunk/ui/misc/ui/src/main/resources/META-INF/fileupload.faces-config.xml (from rev
20384,
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/fileupload.faces-config.xml)
===================================================================
--- trunk/ui/misc/ui/src/main/resources/META-INF/fileupload.faces-config.xml
(rev 0)
+++ trunk/ui/misc/ui/src/main/resources/META-INF/fileupload.faces-config.xml 2010-12-03
20:08:40 UTC (rev 20386)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+JBoss, Home of Professional Open Source
+Copyright ${year}, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+-->
+<faces-config version="2.0"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <factory>
+ <partial-view-context-factory>org.richfaces.context.FileUploadPartialViewContextFactory</partial-view-context-factory>
+ </factory>
+</faces-config>
Copied:
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss (from
rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss)
===================================================================
--- trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss
(rev 0)
+++
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss 2010-12-03
20:08:40 UTC (rev 20386)
@@ -0,0 +1,176 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+.rf-fu {
+ background: '#{richSkin.generalBackgroundColor}';
+ border-color: '#{richSkin.panelBorderColor}';
+ border-style: solid;
+ border-width: 1px;
+ width: 400px; /*TODO Remove it*/
+}
+
+.rf-fu-hdr {
+ background-color: '#{richSkin.headerBackgroundColor}';
+ background-image:
url("#{resource['org.richfaces.renderkit.html.GradientA']}");
+ border-color: '#{richSkin.headerBackgroundColor}';
+ border-style: solid;
+ border-width: 1px;
+ margin-left: 1px;
+ margin-top: 1px;
+ white-space: nowrap;
+}
+
+.rf-fu-lst {
+ height: 210px; /*TODO Remove it*/
+ overflow-x: hidden;
+ overflow-y: auto;
+}
+
+.rf-fu-cntr-hdn {
+ display: none;
+}
+
+.rf-fu-btns-lft, .rf-fu-btns-rgh, .rf-fu-itm-lft, .rf-fu-itm-rgh {
+ display: inline-block;
+ overflow: hidden;
+}
+
+.rf-fu-btns-lft {
+ width: 66%;
+}
+
+.rf-fu-btns-rgh {
+ text-align: right;
+ width: 34%;
+}
+
+.rf-fu-btn-add, .rf-fu-btn-add-dis, .rf-fu-btn-upl, .rf-fu-btn-clr {
+ background-position:left top;
+ background-repeat:repeat-x;
+ border-style: solid;
+ border-width: 1px;
+ cursor: default;
+ display: inline-block;
+ margin: 4px;
+ vertical-align: top;
+}
+
+.rf-fu-btn-add, .rf-fu-btn-upl, .rf-fu-btn-clr {
+ background-color: '#{richSkin.trimColor}';
+ background-image:
url("#{resource['org.richfaces.images:fuBtnGrad.png']}");
+ border-color: '#{richSkin.panelBorderColor}';
+}
+
+.rf-fu-btn-add-dis {
+ background-color: '#{richSkin.tableFooterBackgroundColor}';
+ background-image:
url("#{resource['org.richfaces.images:fuBtnDisGrad.png']}");
+ border-color: '#{richSkin.tableFooterBackgroundColor}';
+}
+
+.rf-fu-btn-upl, .rf-fu-btn-clr {
+ display: none;
+}
+
+.rf-fu-btn-cnt-add, .rf-fu-btn-cnt-add-dis, .rf-fu-btn-cnt-upl, .rf-fu-btn-cnt-clr,
.rf-fu-itm-lbl, .rf-fu-itm-st, .rf-fu-itm-lnk {
+ font-family: '#{richSkin.generalFamilyFont}';
+ font-size: '#{richSkin.generalSizeFont}';
+}
+
+.rf-fu-btn-cnt-add, .rf-fu-btn-cnt-upl, .rf-fu-btn-cnt-clr, .rf-fu-itm-lbl, .rf-fu-itm-st
{
+ color: '#{richSkin.generalTextColor}';
+}
+
+.rf-fu-btn-cnt-add, .rf-fu-btn-cnt-add-dis, .rf-fu-btn-cnt-upl, .rf-fu-btn-cnt-clr {
+ background-position: 2px 2px;
+ background-repeat: no-repeat;
+ display: inline-block;
+ padding: 3px 5px 3px 21px;
+}
+
+.rf-fu-btn-cnt-add {
+ background-image: url("#{resource['org.richfaces:fu-add.gif']}");
+ overflow: hidden;
+ position: relative;
+}
+
+.rf-fu-btn-cnt-add-dis {
+ background-image: url("#{resource['org.richfaces:fu-add-dis.gif']}");
+ color: '#{richSkin.tabDisabledTextColor}';
+}
+
+.rf-fu-btn-cnt-upl, .rf-fu-itm-st {
+ font-weight: bold;
+}
+
+.rf-fu-btn-cnt-upl {
+ background-image: url("#{resource['org.richfaces:fu-upl.gif']}");
+}
+
+.rf-fu-btn-cnt-clr {
+ background-image: url("#{resource['org.richfaces:fu-clr.gif']}");
+}
+
+.rf-fu-inp-cntr {
+ display: block;
+ height: 1px;
+ position: absolute;
+ right: 0;
+ top: 0;
+}
+
+.rf-fu-inp {
+ filter: "alpha(opacity=0)";
+ font-size: 10em;
+ margin: 0;
+ opacity: 0;
+ position: absolute;
+ right: 0;
+ top: 0;
+}
+
+.rf-fu-itm {
+ border-bottom-color: '#{richSkin.panelBorderColor}';
+ border-bottom-style: solid;
+ border-bottom-width: 1px;
+ padding: 12px;
+ white-space: nowrap;
+}
+
+.rf-fu-itm-lft, .rf-fu-itm-rgh {
+ vertical-align: middle;
+}
+
+.rf-fu-itm-lft {
+ width: 85%;
+}
+
+.rf-fu-itm-rgh {
+ width: 14%;
+}
+
+.rf-fu-itm-lnk {
+ color: '#{richSkin.generalLinkColor}';
+}
+
+.rf-fu-itm-st {
+ display: none;
+ margin-top: 5px;
+}
\ No newline at end of file
Copied: trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
(from rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js)
===================================================================
--- trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
(rev 0)
+++
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2010-12-03
20:08:40 UTC (rev 20386)
@@ -0,0 +1,274 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+(function(richfaces, jQuery) {
+
+ var UID = "rf_fu_uid";
+
+ var ITEM_HTML = '<div class="rf-fu-itm">'
+ + '<span class="rf-fu-itm-lft"><span
class="rf-fu-itm-lbl"/><span
class="rf-fu-itm-st"/></span>'
+ + '<span class="rf-fu-itm-rgh"><a
href="javascript:void(0)"
class="rf-fu-itm-lnk"/></span></div>';
+
+ var ITEM_STATE = {
+ NEW: "new",
+ UPLOADING: "uploading",
+ DONE: "done",
+ SIZE_EXCEEDED: "sizeExceeded",
+ STOPPED: "stopped",
+ SERVER_ERROR: "serverError"
+ };
+
+ var pressButton = function(event) {
+ jQuery(this).children(":first").css("background-position",
"3px 3px").css("padding", "4px 4px 2px 22px");
+ };
+
+ var unpressButton = function(event) {
+ jQuery(this).children(":first").css("background-position",
"2px 2px").css("padding", "3px 5px 3px 21px");
+ };
+
+ richfaces.ui = richfaces.ui || {};
+
+ richfaces.ui.FileUpload = richfaces.BaseComponent.extendClass({
+
+ name: "FileUpload",
+
+ items: [],
+ submitedItems: [],
+
+ doneLabel: "Done",
+ sizeExceededLabel: "File size is exceeded",
+ stoppedLabel: "",
+ serverErrorLabel: "Server error",
+ clearLabel: "Clear",
+ deleteLabel: "Delete",
+
+ init: function(id, options) {
+ this.id = id;
+ jQuery.extend(this, options);
+ if (this.acceptedTypes) {
+ this.acceptedTypes = jQuery.trim(this.acceptedTypes).split(/\s*,\s*/);
+ }
+ this.element = jQuery(this.attachToDom());
+ this.form = this.element.parents("form:first");
+ var header = this.element.children(".rf-fu-hdr:first");
+ var leftButtons = header.children(".rf-fu-btns-lft:first");
+ this.addButton = leftButtons.children(".rf-fu-btn-add:first");
+ this.uploadButton = this.addButton.next();
+ this.clearButton =
leftButtons.next().children(".rf-fu-btn-clr:first");
+ this.inputContainer = this.addButton.find(".rf-fu-inp-cntr:first");
+ this.input = this.inputContainer.children("input");
+ this.list = header.next();
+ this.hiddenContainer = this.list.next();
+ this.iframe = this.hiddenContainer.children("iframe:first");
+ this.progressBarElement = this.iframe.next();
+ this.progressBar = richfaces.$(this.progressBarElement);
+ this.cleanInput = this.input.clone();
+ this.addProxy = jQuery.proxy(this.__addItem, this);
+ this.input.change(this.addProxy);
+
this.addButton.mousedown(pressButton).mouseup(unpressButton).mouseout(unpressButton);
+ this.uploadButton.click(jQuery.proxy(this.__startUpload,
this)).mousedown(pressButton)
+ .mouseup(unpressButton).mouseout(unpressButton);
+ this.clearButton.click(jQuery.proxy(this.__removeAllItems,
this)).mousedown(pressButton)
+ .mouseup(unpressButton).mouseout(unpressButton);
+ this.iframe.load(jQuery.proxy(this.__load, this));
+ if (this.onfilesubmit) {
+ richfaces.Event.bind(this.element, "onfilesubmit", new
Function("event", this.onfilesubmit));
+ }
+ if (this.onuploadcomplete) {
+ richfaces.Event.bind(this.element, "onuploadcomplete", new
Function("event", this.onuploadcomplete));
+ }
+ },
+
+ __addItem: function() {
+ var fileName = this.input.val();
+ if (this.__accept(fileName) && (!this.noDuplicate ||
!this.__isFileAlreadyAdded(fileName))) {
+ this.input.hide();
+ this.input.unbind("change", this.addProxy);
+ var item = new Item(this);
+ this.list.append(item.getJQuery());
+ this.items.push(item);
+ this.input = this.cleanInput.clone();
+ this.inputContainer.append(this.input);
+ this.input.change(this.addProxy);
+ this.__updateButtons();
+ }
+ },
+
+ __removeItem: function(item) {
+ this.items.splice(this.items.indexOf(item), 1);
+ this.submitedItems.splice(this.submitedItems.indexOf(item), 1);
+ this.__updateButtons();
+ },
+
+ __removeAllItems: function(item) {
+ this.inputContainer.children(":not(:visible)").remove();
+ this.list.empty();
+ this.items.splice(0);
+ this.submitedItems.splice(0);
+ this.__updateButtons();
+ },
+
+ __updateButtons: function() {
+ if (!this.loadableItem &&
this.list.children(".rf-fu-itm").size()) {
+ if (this.items.length) {
+ this.uploadButton.css("display", "inline-block");
+ } else {
+ this.uploadButton.hide();
+ }
+ this.clearButton.css("display", "inline-block");
+ } else {
+ this.uploadButton.hide();
+ this.clearButton.hide();
+ }
+ },
+
+ __startUpload: function() {
+ this.loadableItem = this.items.shift();
+ this.__updateButtons();
+ this.loadableItem.startUploading();
+ },
+
+ __submit: function() {
+ var originalAction = this.form.attr("action");
+ var originalEncoding = this.form.attr("encoding");
+ var originalEnctype = this.form.attr("enctype");
+ try {
+ this.form.attr("action", originalAction + "?" + UID +
"=" + this.loadableItem.uid);
+ this.form.attr("encoding", "multipart/form-data");
+ this.form.attr("enctype", "multipart/form-data");
+ richfaces.submitForm(this.form, {"org.richfaces.ajax.component":
this.id}, this.id);
+ richfaces.Event.fire(this.element, "onfilesubmit",
this.loadableItem.model);
+ } finally {
+ this.form.attr("action", originalAction);
+ this.form.attr("encoding", originalEncoding);
+ this.form.attr("enctype", originalEnctype);
+ this.loadableItem.input.removeAttr("name");
+ }
+ },
+
+ __load: function(event) {
+ if (this.loadableItem) {
+ var contentDocument = event.target.contentWindow.document;
+ contentDocument = contentDocument.XMLDocument || contentDocument;
+ var documentElement = contentDocument.documentElement;
+ var responseStatus, id;
+ if (documentElement.tagName.toUpperCase() == "PARTIAL-RESPONSE") {
+ responseStatus = ITEM_STATE.DONE;
+ } else if ((id = documentElement.id) && id.indexOf(UID +
this.loadableItem.uid + ":") == 0) {
+ responseStatus = id.split(":")[1];
+ }
+ if (responseStatus) {
+ responseStatus == ITEM_STATE.DONE && jsf.ajax.response({responseXML:
contentDocument}, {});
+ this.loadableItem.finishUploading(responseStatus);
+ this.submitedItems.push(this.loadableItem);
+ if (responseStatus == ITEM_STATE.DONE && this.items.length) {
+ this.__startUpload();
+ } else {
+ this.loadableItem = null;
+ this.__updateButtons();
+ var items = [];
+ for (var i in this.submitedItems) {
+ items.push(this.submitedItems[i].model);
+ }
+ for (var i in this.items) {
+ items.push(this.items[i].model);
+ }
+ richfaces.Event.fire(this.element, "onuploadcomplete", items);
+ }
+ }
+ }
+ },
+
+ __accept: function(fileName) {
+ var result = !this.acceptedTypes;
+ for (var i = 0; !result && i < this.acceptedTypes.length; i++) {
+ var extension = this.acceptedTypes[i];
+ result = fileName.indexOf(extension, fileName.length - extension.length) !== -1;
+ }
+ return result;
+ },
+
+ __isFileAlreadyAdded: function(fileName) {
+ var result = false;
+ for (var i = 0; !result && i < this.items.length; i++) {
+ result = this.items[i].model.name == fileName;
+ }
+ result = result || (this.loadableItem && this.loadableItem.model.name ==
fileName);
+ for (var i = 0; !result && i < this.submitedItems.length; i++) {
+ result = this.submitedItems[i].model.name == fileName;
+ }
+ return result;
+ }
+ });
+
+ var Item = function(fileUpload) {
+ this.fileUpload = fileUpload;
+ this.input = fileUpload.input;
+ this.model = {name: this.input.val(), state: ITEM_STATE.NEW};
+ };
+
+ jQuery.extend(Item.prototype, {
+ getJQuery: function() {
+ this.element = jQuery(ITEM_HTML);
+ var leftArea = this.element.children(".rf-fu-itm-lft:first");
+ this.label = leftArea.children(".rf-fu-itm-lbl:first");
+ this.state = this.label.nextAll(".rf-fu-itm-st:first");
+ this.link = leftArea.next().children("a");
+ this.label.html(this.model.name);
+ this.link.html(this.fileUpload["deleteLabel"]);
+ this.link.click(jQuery.proxy(this.removeOrStop, this));
+ return this.element;
+ },
+
+ removeOrStop: function() {
+ this.input.remove();
+ this.element.remove();
+ this.fileUpload.__removeItem(this);
+ },
+
+ startUploading: function() {
+ this.state.css("display", "block");
+ this.link.html("");
+ this.input.attr("name", this.fileUpload.id);
+ this.model.state = ITEM_STATE.UPLOADING;
+ this.uid = Math.random();
+ this.fileUpload.__submit();
+ var params = {};
+ params[UID] = this.uid;
+ if (this.fileUpload.progressBar) {
+ this.fileUpload.progressBar.setValue(0);
+ this.state.html(this.fileUpload.progressBarElement.detach());
+ this.fileUpload.progressBar.enable(params);
+ }
+ },
+
+ finishUploading: function(state) {
+ if (this.fileUpload.progressBar) {
+ this.fileUpload.progressBar.disable();
+
this.fileUpload.hiddenContainer.append(this.fileUpload.progressBarElement.detach());
+ }
+ this.input.remove();
+ this.state.html(this.fileUpload[state + "Label"]);
+ this.link.html(this.fileUpload["clearLabel"]);
+ this.model.state = state;
+ }
+ });
+}(window.RichFaces, jQuery));
Copied:
trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fu-add-dis.gif (from
rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fu-add-dis.gif)
===================================================================
(Binary files differ)
Copied: trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fu-add.gif
(from rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fu-add.gif)
===================================================================
(Binary files differ)
Copied: trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fu-clr.gif
(from rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fu-clr.gif)
===================================================================
(Binary files differ)
Copied: trunk/ui/misc/ui/src/main/resources/META-INF/resources/org.richfaces/fu-upl.gif
(from rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fu-upl.gif)
===================================================================
(Binary files differ)
Copied: trunk/ui/misc/ui/src/main/resources/META-INF/richfaces (from rev 20384,
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/richfaces)