Author: pyaschenko
Date: 2008-06-26 11:10:52 -0400 (Thu, 26 Jun 2008)
New Revision: 9248
Added:
trunk/ui/fileUpload/build.properties.template
trunk/ui/fileUpload/build.xml
trunk/ui/fileUpload/src/main/flash/
trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as
Modified:
trunk/ui/fileUpload/
Log:
http://jira.jboss.com/jira/browse/RF-3549
flash src files added
Property changes on: trunk/ui/fileUpload
___________________________________________________________________
Name: svn:ignore
- .settings
target
.project
.classpath
.clover
+ .settings
target
.project
.classpath
.clover
build.properties
Added: trunk/ui/fileUpload/build.properties.template
===================================================================
--- trunk/ui/fileUpload/build.properties.template (rev 0)
+++ trunk/ui/fileUpload/build.properties.template 2008-06-26 15:10:52 UTC (rev 9248)
@@ -0,0 +1 @@
+mtasc.path=D:/eclipse/plugins/org.asdt.mtasc_1.0.0/dist
\ No newline at end of file
Added: trunk/ui/fileUpload/build.xml
===================================================================
--- trunk/ui/fileUpload/build.xml (rev 0)
+++ trunk/ui/fileUpload/build.xml 2008-06-26 15:10:52 UTC (rev 9248)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ======================================================================
+ 26.06.2008 15:33:20
+
+ project
+ description
+
+ pyaschenko
+ ====================================================================== -->
+<project name="FlashFileUploadComponent" default="default">
+ <description>
+ description
+ </description>
+
+ <property file="build.properties" />
+ <!-- =================================
+ target: default
+ ================================= -->
+ <target name="default" description="--> description">
+ <exec executable="${mtasc.path}\mtasc" dir="">
+ <arg line="-cp ${basedir}\src\main\flash -cp ${mtasc.path}\std8 -swf
${basedir}\src\main\resources\org\richfaces\renderkit\html\swf\fileUploadComponent.swf
-trace no -header 640:480:12:0080c0 -version 8 -main FileUploadComponent"/>
+ </exec>
+ </target>
+</project>
Added: trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as
===================================================================
--- trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as (rev
0)
+++ trunk/ui/fileUpload/src/main/flash/FileUploadComponent.as 2008-06-26 15:10:52 UTC (rev
9248)
@@ -0,0 +1,180 @@
+/**
+ * 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;
+
+ public function FileUploadComponent() {
+ this.fileDataList = new Array();
+ this.fileRefList = new Array();
+ this.acceptedTypes = new Object();
+ this.noDuplicate = true;
+ this.maxFiles = 5;
+ this.fileTypes = null;
+
+ 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)
+ {
+ this.fileRefList.splice(index, 1);
+ this.fileDataList.splice(index, 1);
+ }
+
+ public function uploadFile(index, actionURL)
+ {
+ var item: FileReference = fileRefList[index];
+ if (item)
+ {
+ 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.type) || !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 (fileRef:FileReference, httpError:Number) {
+ ExternalInterface.call(this.getComponentString()+"._flashHTTPError("+httpError+")");
+ }
+ public function onIOError (file:FileReference) {
+ ExternalInterface.call(this.getComponentString()+"._flashIOError()");
+ }
+ public function onSecurityError (fileRef: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 (fileType.charAt(0)=='.') fileType = fileType.substr(1);
+ if (!this.acceptedTypes || this.acceptedTypes['*']) { return true; }
+ var type = fileType.toLowerCase();
+ if (this.acceptedTypes[type]) {
+ return true;
+ }
+ return false;
+ }
+
+ private function checkDuplicated (fileName) {
+ if (!this.noDuplicate) return true;
+ for (var i = 0; i < this.fileDataList.length; i++) {
+ if (fileName == this.fileDataList[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