[richfaces-svn-commits] JBoss Rich Faces SVN: r11678 - in trunk/ui/fileUpload/src/main: flash/src and 3 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Dec 9 13:29:36 EST 2008


Author: pyaschenko
Date: 2008-12-09 13:29:36 -0500 (Tue, 09 Dec 2008)
New Revision: 11678

Added:
   trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as2proj
   trunk/ui/fileUpload/src/main/flash/bin/
   trunk/ui/fileUpload/src/main/flash/src/
   trunk/ui/fileUpload/src/main/flash/src/FileUploadComponent.as
Removed:
   trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as
Modified:
   trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
   trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/swf/fileUploadComponent.swf
   trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
Log:
https://jira.jboss.org/jira/browse/RF-4917

Deleted: trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as
===================================================================
--- trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as	2008-12-09 18:14:01 UTC (rev 11677)
+++ trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as	2008-12-09 18:29:36 UTC (rev 11678)
@@ -1,183 +0,0 @@
-/**
- * FlashUploadComponent for Richfaces.ui.flashupload
- */
-/**
- *
- */
-import flash.external.*;
-import flash.net.FileReference;
-import flash.net.FileReferenceList;
-
-// _root variables (from flashVars): 
-// fileUploadId:String
-
-class FileUploadComponent {
-
-		public static var app : FileUploadComponent;
-		
-		private var fileDataList: Array;
-		private var fileRefList: Array;
-		private var acceptedTypes: Object; 
-		private var noDuplicate: Boolean;
-		private var maxFiles: Number; 
-		private var fileTypes: Array;
-		private var uploadIndex: Number;
-	
-		public function FileUploadComponent() {
-			this.fileDataList = new Array();
-			this.fileRefList = new Array();
-			this.acceptedTypes = new Object(); 
-			this.noDuplicate = true;
-			this.maxFiles = 5;
-			this.fileTypes = null;
-			this.uploadIndex = -1;
-
-			ExternalInterface.addCallback("browse", this, browse);
-			ExternalInterface.addCallback("setProperties", this, setProperties);
-			ExternalInterface.addCallback("removeFile", this, removeFile);
-			ExternalInterface.addCallback("uploadFile", this, uploadFile);
-			ExternalInterface.addCallback("cancelUploadFile", this, cancelUploadFile);
-		}
-		
-		public function setProperties(properties:Object)
-		{
-			this.acceptedTypes = properties.acceptedTypes;
-			this.noDuplicate = properties.noDuplicate;
-			this.maxFiles = properties.maxFiles;
-			if (!this.acceptedTypes['*'])
-			{
-				var types:String = "";
-				for (var type in this.acceptedTypes)
-				{
-					types += "*."+type+";";
-				}
-				this.fileTypes = [{description: types, extension: types}];
-			}
-		}
-		
-		public function removeFile(index:Number)
-		{
-			if (index<this.uploadIndex) this.uploadIndex--;
-			this.fileRefList.splice(index, 1);
-			this.fileDataList.splice(index, 1);
-			return this.uploadIndex;
-		}
-		
-		public function uploadFile(index, actionURL, postData)
-		{
-			this.uploadIndex = index;
-			var item: FileReference = fileRefList[index];
-			if (item) 
-			{
-				if (postData) item["postData"] = postData;
-				item.upload(actionURL);
-				return item.size;
-			}
-			return -1;
-		}
-		
-		public function cancelUploadFile(index) {
-			var item: FileReference = fileRefList[index];
-			if (item)
-			{
-				item.cancel();
-			}
-		}
-		
-		
-		public function onSelect (frl: FileReferenceList) {
-
-		    var list: Array = frl.fileList;
-		    var item: FileReference;
-		    for (var i:Number = 0; i < list.length; i++) {
-		    	if (this.fileRefList.length==this.maxFiles) break;
-		        item = list[i];
-			    if (!this.checkFileType(item.name) || !this.checkDuplicated(item.name)) {
-					ExternalInterface.call(this.getComponentString()+"._flashFireEvent('ontyperejected', {})");
-					continue;  
-				}
-				item.addListener(this);
-		        this.fileRefList.push(item);
-		        this.fileDataList.push("{creationDate: "+this.getJSDateString(item.creationDate)+", creator: '"+item.creator+"', modificationDate: "+this.getJSDateString(item.modificationDate)+", name: '"+item.name+"', size: "+item.size+", type: '"+item.type+"'}");
-		    }
-		    ExternalInterface.call(this.getComponentString()+"._flashAdd(["+this.fileDataList.join(",")+"])");
-		}
-
-		public function onCancel() {
-		}
-	
-		public function onProgress (file:FileReference, bytesLoaded:Number, bytesTotal:Number) {
-			ExternalInterface.call(this.getComponentString()+"._flashOnProgress("+bytesLoaded+", "+bytesTotal+")");
-		}
-		
-		public function onComplete (file:FileReference) {
-			ExternalInterface.call(this.getComponentString()+"._flashOnComplete()");
-		}
-		
-		public function onHTTPError (file:FileReference, httpError:Number): Void {
-			ExternalInterface.call(this.getComponentString()+"._flashHTTPError("+httpError+")");
-		}
-		public function onIOError (file:FileReference) {
-			ExternalInterface.call(this.getComponentString()+"._flashIOError()");
-		}
-		public function onSecurityError (file:FileReference, errorString:String) {
-			ExternalInterface.call(this.getComponentString()+"._flashOnSecurityError('"+errorString+"')");
-		}
-		
-		public function browse() {
-			var fileRef:FileReferenceList = new FileReferenceList();
-			fileRef.addListener(this);
-			//[{description: "Image files", extension: "*.jpg;*.gif;*.png", macType: "JPEG;jp2_;GIFf;PNGf"}, {description: "Flash Movies", extension: "*.swf", macType: "SWFL"}]	
-			if (this.fileTypes) fileRef.browse(this.fileTypes); else fileRef.browse();
-		}
-
-		public function getComponentString()
-		{
-			return "FlashFileUpload.getComponent('"+_root.fileUploadId+"')";
-		}
-		
-		private function checkFileType (fileType) {
-			if (!this.acceptedTypes || this.acceptedTypes['*']) { return true; }
-			var p:Number = fileType.lastIndexOf('.');
-			if (p!=-1) fileType = fileType.substr(p+1); else fileType="";
-			if (this.acceptedTypes[fileType.toLowerCase()]) {
-				return true;
-			}
-			return false;
-		}
-	
-		private function checkDuplicated (fileName:String) {
-			if (!this.noDuplicate) return true;
-			for (var i = 0; i < this.fileRefList.length; i++) {
-				if (fileName == this.fileRefList[i].name) {
-					return false;
-				}
-			}
-			return true;
-		}
-		
-		private function getJSDateString(d:Date) {
-			var result:String = "new Date(";
-			result+=d.getFullYear()+","+d.getMonth()+","+d.getDate()+","+d.getHours()+","+d.getMinutes()+","+d.getSeconds()+","+d.getMilliseconds()+")";
-			return result; 
-		}
-		
-		private function jstrace (msg: String)
-		{
-			ExternalInterface.call("FlashFileUpload.ASTrace", msg);
-		}
-
-		private function jsalert (msg: String)
-		{
-			ExternalInterface.call("FlashFileUpload.ASAlert", msg);
-		}
-
-		public static function main(mc) {
-			app = new FileUploadComponent();
-			ExternalInterface.call(app.getComponentString()+"._flashSetComponent()");
-			mc.gotoAndStop(1);
-			mc.onEnterFrame = function ()
-			{
-			};
-		}
-}
\ No newline at end of file

Added: trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as2proj
===================================================================
--- trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as2proj	                        (rev 0)
+++ trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as2proj	2008-12-09 18:29:36 UTC (rev 11678)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project>
+  <!-- Output SWF options -->
+  <output>
+    <movie disabled="False" />
+    <movie input="" />
+    <movie path="bin\FileUploadComponent.swf" />
+    <movie fps="10" />
+    <movie width="256" />
+    <movie height="256" />
+    <movie version="8" />
+    <movie background="#FFFFFF" />
+  </output>
+  <!-- Other classes to be compiled into your SWF -->
+  <classpaths>
+    <class path="src" />
+  </classpaths>
+  <!-- Build options -->
+  <build>
+    <option verbose="False" />
+    <option strict="False" />
+    <option infer="False" />
+    <option useMain="True" />
+    <option useMX="False" />
+    <option warnUnusedImports="False" />
+    <option traceMode="FlashConnectExtended" />
+    <option traceFunction="" />
+    <option libraryPrefix="" />
+    <option excludeFile="" />
+    <option groupClasses="False" />
+    <option frame="1" />
+    <option keep="True" />
+  </build>
+  <!-- Class files to compile (other referenced classes will automatically be included) -->
+  <compileTargets>
+    <compile path="src\FileUploadComponent.as" />
+  </compileTargets>
+  <!-- Assets to embed into the output SWF -->
+  <library>
+    <!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
+  </library>
+  <!-- Paths to exclude from the Project Explorer tree -->
+  <hiddenPaths>
+    <!-- example: <hidden path="..." /> -->
+  </hiddenPaths>
+  <!-- Executed before build -->
+  <preBuildCommand />
+  <!-- Executed after build -->
+  <postBuildCommand alwaysRun="False" />
+  <!-- Other project options -->
+  <options>
+    <option showHiddenPaths="False" />
+    <option testMovie="NewTab" />
+  </options>
+</project>
\ No newline at end of file

Added: trunk/ui/fileUpload/src/main/flash/src/FileUploadComponent.as
===================================================================
--- trunk/ui/fileUpload/src/main/flash/src/FileUploadComponent.as	                        (rev 0)
+++ trunk/ui/fileUpload/src/main/flash/src/FileUploadComponent.as	2008-12-09 18:29:36 UTC (rev 11678)
@@ -0,0 +1,202 @@
+/**
+ * FlashUploadComponent for Richfaces.ui.flashupload
+ */
+/**
+ *
+ */
+import flash.external.*;
+import flash.net.FileReference;
+import flash.net.FileReferenceList;
+
+// _root variables (from flashVars): 
+// fileUploadId:String
+
+class FileUploadComponent {
+		
+		private var fileDataList: Array;
+		private var fileRefList: Array;
+		private var acceptedTypes: Object; 
+		private var noDuplicate: Boolean;
+		private var maxFiles: Number; 
+		private var fileTypes: Array;
+		private var uploadIndex: Number;
+		private var parent:MovieClip;
+	
+		public function FileUploadComponent(parent:MovieClip) {
+			this.parent = parent;
+			this.fileDataList = new Array();
+			this.fileRefList = new Array();
+			this.acceptedTypes = new Object(); 
+			this.noDuplicate = true;
+			this.maxFiles = 5;
+			this.fileTypes = null;
+			this.uploadIndex = -1;
+
+			//ExternalInterface.addCallback("browse", this, browse);
+			ExternalInterface.addCallback("setProperties", this, setProperties);
+			ExternalInterface.addCallback("removeFile", this, removeFile);
+			ExternalInterface.addCallback("uploadFile", this, uploadFile);
+			ExternalInterface.addCallback("cancelUploadFile", this, cancelUploadFile);
+		}
+		
+		public function setProperties(properties:Object)
+		{
+			this.acceptedTypes = properties.acceptedTypes;
+			this.noDuplicate = properties.noDuplicate;
+			this.maxFiles = properties.maxFiles;
+			if (!this.acceptedTypes['*'])
+			{
+				var types:String = "";
+				for (var type in this.acceptedTypes)
+				{
+					types += "*."+type+";";
+				}
+				this.fileTypes = [{description: types, extension: types}];
+			}			
+		}
+		
+		public function removeFile(index:Number)
+		{
+			if (index<this.uploadIndex) this.uploadIndex--;
+			this.fileRefList.splice(index, 1);
+			this.fileDataList.splice(index, 1);
+			return this.uploadIndex;
+		}
+		
+		public function uploadFile(index, actionURL, postData)
+		{
+			this.uploadIndex = index;
+			var item: FileReference = fileRefList[index];
+			if (item) 
+			{
+				if (postData) item["postData"] = postData;
+				item.upload(actionURL);
+				return item.size;
+			}
+			return -1;
+		}
+		
+		public function cancelUploadFile(index) {
+			var item: FileReference = fileRefList[index];
+			if (item)
+			{
+				item.cancel();
+			}
+		}
+		
+		
+		public function onSelect (frl: FileReferenceList) {
+
+		    var list: Array = frl.fileList;
+		    var item: FileReference;
+		    for (var i:Number = 0; i < list.length; i++) {
+		    	if (this.fileRefList.length==this.maxFiles) break;
+		        item = list[i];
+			    if (!this.checkFileType(item.name) || !this.checkDuplicated(item.name)) {
+					ExternalInterface.call(this.getComponentString()+"._flashFireEvent('ontyperejected', {})");
+					continue;  
+				}
+				item.addListener(this);
+		        this.fileRefList.push(item);
+		        this.fileDataList.push("{creationDate: "+this.getJSDateString(item.creationDate)+", creator: '"+item.creator+"', modificationDate: "+this.getJSDateString(item.modificationDate)+", name: '"+item.name+"', size: "+item.size+", type: '"+item.type+"'}");
+		    }
+		    ExternalInterface.call(this.getComponentString()+"._flashAdd(["+this.fileDataList.join(",")+"])");
+		}
+
+		public function onCancel() {
+		}
+	
+		public function onProgress (file:FileReference, bytesLoaded:Number, bytesTotal:Number) {
+			ExternalInterface.call(this.getComponentString()+"._flashOnProgress("+bytesLoaded+", "+bytesTotal+")");
+		}
+		
+		public function onComplete (file:FileReference) {
+			ExternalInterface.call(this.getComponentString()+"._flashOnComplete()");
+		}
+		
+		public function onHTTPError (file:FileReference, httpError:Number): Void {
+			ExternalInterface.call(this.getComponentString()+"._flashHTTPError("+httpError+")");
+		}
+		public function onIOError (file:FileReference) {
+			ExternalInterface.call(this.getComponentString()+"._flashIOError()");
+		}
+		public function onSecurityError (file:FileReference, errorString:String) {
+			ExternalInterface.call(this.getComponentString()+"._flashOnSecurityError('"+errorString+"')");
+		}
+		
+		public function browse() {
+			var fileRef:FileReferenceList = new FileReferenceList();
+			fileRef.addListener(this);
+			//[{description: "Image files", extension: "*.jpg;*.gif;*.png", macType: "JPEG;jp2_;GIFf;PNGf"}, {description: "Flash Movies", extension: "*.swf", macType: "SWFL"}]	
+			if (this.fileTypes) fileRef.browse(this.fileTypes); else fileRef.browse();
+		}
+
+		public function getComponentString()
+		{
+			return "FlashFileUpload.getComponent('"+_root.fileUploadId+"')";
+		}
+		
+		private function checkFileType (fileType) {
+			if (!this.acceptedTypes || this.acceptedTypes['*']) { return true; }
+			var p:Number = fileType.lastIndexOf('.');
+			if (p!=-1) fileType = fileType.substr(p+1); else fileType="";
+			if (this.acceptedTypes[fileType.toLowerCase()]) {
+				return true;
+			}
+			return false;
+		}
+	
+		private function checkDuplicated (fileName:String) {
+			if (!this.noDuplicate) return true;
+			for (var i = 0; i < this.fileRefList.length; i++) {
+				if (fileName == this.fileRefList[i].name) {
+					return false;
+				}
+			}
+			return true;
+		}
+		
+		private function getJSDateString(d:Date) {
+			var result:String = "new Date(";
+			result+=d.getFullYear()+","+d.getMonth()+","+d.getDate()+","+d.getHours()+","+d.getMinutes()+","+d.getSeconds()+","+d.getMilliseconds()+")";
+			return result; 
+		}
+		
+		private function jstrace (msg: String)
+		{
+			ExternalInterface.call("FlashFileUpload.ASTrace", msg);
+		}
+
+		private function jsalert (msg: String)
+		{
+			ExternalInterface.call("FlashFileUpload.ASAlert", msg);
+		}
+
+		public static function main(swfRoot:MovieClip):Void 
+		{
+			// entry point
+			swfRoot.app = new FileUploadComponent(swfRoot);
+			var mc = swfRoot.createEmptyMovieClip("mc", swfRoot.getNextHighestDepth());
+			mc.beginFill(0xffff80, 0);
+				mc.moveTo(0, 0);
+				mc.lineTo(2048, 0);
+				mc.lineTo(2048, 2048);
+				mc.lineTo(0, 2048);
+				mc.lineTo(0, 0);
+			mc.endFill();	
+			mc.onRelease = function () { }
+			
+			swfRoot.onMouseUp = function ()
+			{
+				swfRoot.app.browse();
+				ExternalInterface.call(swfRoot.app.getComponentString() + "._flashClearFocus()");
+			}
+			
+			ExternalInterface.call(swfRoot.app.getComponentString() + "._flashSetComponent()");
+			
+			swfRoot.gotoAndStop(1);
+			swfRoot.onEnterFrame = function ()
+			{
+			};
+		}		
+}
\ No newline at end of file

Modified: trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
--- trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js	2008-12-09 18:14:01 UTC (rev 11677)
+++ trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js	2008-12-09 18:29:36 UTC (rev 11678)
@@ -1108,50 +1108,51 @@
 		var allowFlash = this.options.allowFlash;
 		if (allowFlash=="auto" || allowFlash=="true")
 		{
-			var object = document.createElement('div');
-			object.innerHTML = '<a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>';
+			var div = document.createElement('div');
+			div.innerHTML = '<a href="http://www.adobe.com/go/getflashplayer"><img style="border:0px; margin:2px" src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>';
 			var oid = this.id+":flashContainer";
-			object.style.display = allowFlash=="true" ? "" : "none";
-			object.id = oid;
-			this.items.appendChild(object);
+			var object = document.getElementById(oid);
 			this.isFlash = swfobject.hasFlashPlayerVersion("9.0.28");
 			if (this.isFlash)
 			{
 				this.disable();
 				var flashvars = {fileUploadId:this.id};
-				var params = {allowscriptaccess:true};
-				var attributes = {};
-				swfobject.embedSWF(this.options.flashComponentUrl, oid, "0", "0", "9.0.28", false, flashvars, params, attributes);
+				var params = {allowscriptaccess:true, menu: "false", wmode: "transparent", salign: "TL", scale: "noscale"};
 				
+				var attributes = {style:"position:absolute; top:0px; left:0px;"};
+				swfobject.embedSWF(this.options.flashComponentUrl, oid, "100%", "100%", "9.0.28", false, flashvars, params, attributes);
+				
 				this.currentInput.parentNode.innerHTML = '<input type="text" style="cursor: pointer; right: 0px; top: 0px; font-size: 10em; position: absolute; padding: 0px" class="rich-fileupload-hidden" id="'+this.id+':file" name="'+this.id+':file"></input>'
 				this.currentInput = $(this.id + ":file");
 
-				//this.currentInput.type="text";
-				//this.currentInput.onchange = null;
+				this.currentInput.style.display = "none";
 				this.currentInput.onmousedown=(function (){this.createFrame();}).bind(this);
-				this.currentInput.onclick = this._flashOnOpenFileDialog.bind(this);
-			} else if (allowFlash=="true")
+			} if (allowFlash=="true")
 			{
+				this.items.appendChild(div);
 				this.disable();
 			}
-
 		}
 	},
 	
-	_flashOnOpenFileDialog: function (event) {
-		// call flash
-		this.flashComponent.browse();
-		return false;
+	_flashClearFocus: function()
+	{
+		//this.flashComponent.style.display = "none";
+		//this.flashComponent.style.display = "";
 	},
 	
 	_flashSetComponent: function() {
 		var flashId = this.id+":flashContainer";
 		this.flashComponent = (document[flashId]) ? document[flashId] : (window[flashId] ? window[flashId] : $(flashId));
-		this.flashComponent.style.display = 'none';
 		this.flashComponent.setProperties({
 											acceptedTypes: this.acceptedTypes,
 			 								noDuplicate: this.options.noDuplicate,
 			 								maxFiles: this.maxFileBatchSize });
+		if (Richfaces.browser.isIE) 
+		{
+			this.flashComponent.style.width = this.currentInput.parentNode.style.width;
+			this.flashComponent.style.height = this.currentInput.parentNode.style.height;
+		}
 		this.enable();
 	},
 	
@@ -1176,8 +1177,6 @@
 			}
 	
 			var newUpload = this.currentInput.cloneNode(true);
-			newUpload.onclick = this._flashOnOpenFileDialog.bind(this);			
-			//this.currentInput.onchange = null;
 			this.currentInput.style.cssText = "position: absolute; right: 0px; top: 0px; display: none; visibility: hidden;";
 			newUpload.id = this.id + ":file" + (this.idCounter++);
 			newUpload.value = '';

Modified: trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/swf/fileUploadComponent.swf
===================================================================
(Binary files differ)

Modified: trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
===================================================================
--- trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx	2008-12-09 18:14:01 UTC (rev 11677)
+++ trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx	2008-12-09 18:29:36 UTC (rev 11678)
@@ -24,7 +24,7 @@
 	
 	<f:clientId var="clientId" />
 	
-	<f:resource var="flashComponent" name="/org/richfaces/renderkit/html/swf/fileUploadComponent.swf"/>
+	<f:resource var="flashComponent" name="/org/richfaces/renderkit/html/swf/FileUploadComponent.swf"/>
 	
 	<jsp:scriptlet>
 		<![CDATA[
@@ -94,6 +94,7 @@
 							       name="#{clientId}:file"
 							       onchange="return $('#{clientId}').component.add(this);"/>
 						</div>
+						<div id="#{clientId}:flashContainer" style="display:none"></div>
 					</div>
 				</div>
 				<div class="rich-fileupload-button-border" style=" float:left; display: none;">




More information about the richfaces-svn-commits mailing list