[Checkins] SVN: z3c.widget/trunk/ prepare version 0.1.1 -
refactoring flash upload widget for better skinnability. fix
bug with wrong url for flash upload vars and cleanup of
folderstructure
Manfred Schwendinger
manfred.schwendiger at lovelysystems.com
Sun Aug 5 15:14:17 EDT 2007
Log message for revision 78600:
prepare version 0.1.1 - refactoring flash upload widget for better skinnability. fix bug with wrong url for flash upload vars and cleanup of folderstructure
Changed:
U z3c.widget/trunk/CHANGES.txt
A z3c.widget/trunk/flash/
A z3c.widget/trunk/flash/fla/
A z3c.widget/trunk/flash/fla/debug.as
A z3c.widget/trunk/flash/fla/upload.fla
A z3c.widget/trunk/flash/src/
A z3c.widget/trunk/flash/src/z3c/
A z3c.widget/trunk/flash/src/z3c/widget/
A z3c.widget/trunk/flash/src/z3c/widget/flashupload/
A z3c.widget/trunk/flash/src/z3c/widget/flashupload/Upload.as
U z3c.widget/trunk/setup.py
U z3c.widget/trunk/src/z3c/widget/flashupload/configure.zcml
D z3c.widget/trunk/src/z3c/widget/flashupload/resources/Upload.as
D z3c.widget/trunk/src/z3c/widget/flashupload/resources/debug.as
D z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.fla
D z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.html
U z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.js
U z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.swf
U z3c.widget/trunk/src/z3c/widget/flashupload/upload.py
U z3c.widget/trunk/src/z3c/widget/flashupload/uploadform.pt
-=-
Modified: z3c.widget/trunk/CHANGES.txt
===================================================================
--- z3c.widget/trunk/CHANGES.txt 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/CHANGES.txt 2007-08-05 19:14:17 UTC (rev 78600)
@@ -2,6 +2,17 @@
Changes for z3c.widget
======================
+
+After:
+======
+
+2007/08/06 0.1.1
+================
+
+- flashupload: better skinnability for upload.swf. cleanup folder
+ structure for flash stuff.
+
+
2007/06/14 0.1.0:
=================
Added: z3c.widget/trunk/flash/fla/debug.as
===================================================================
--- z3c.widget/trunk/flash/fla/debug.as (rev 0)
+++ z3c.widget/trunk/flash/fla/debug.as 2007-08-05 19:14:17 UTC (rev 78600)
@@ -0,0 +1,23 @@
+/*
+ this small script allows you to see the log if you press
+ SHIFT + F12
+
+ very nice for debugging :)
+ */
+_root.listener = new Object();
+_root.listener.onKeyUp = function(){
+ trace(Key.getCode());
+ if (Key.getCode() == 123 && Key.isDown(Key.SHIFT)){
+
+ _root.debug_txt._visible = !_root.debug_txt._visible;
+
+ _root.debug_txt._x = 0;
+ _root.debug_txt._y = 0;
+ _root.debug_txt._width = Stage.width - 1;
+ _root.debug_txt._height = Stage.height - 1;
+ }
+
+}
+Key.addListener(_root.listener);
+
+_root.debug_txt._visible = false;
\ No newline at end of file
Added: z3c.widget/trunk/flash/fla/upload.fla
===================================================================
(Binary files differ)
Property changes on: z3c.widget/trunk/flash/fla/upload.fla
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: z3c.widget/trunk/flash/src/z3c/widget/flashupload/Upload.as
===================================================================
--- z3c.widget/trunk/flash/src/z3c/widget/flashupload/Upload.as (rev 0)
+++ z3c.widget/trunk/flash/src/z3c/widget/flashupload/Upload.as 2007-08-05 19:14:17 UTC (rev 78600)
@@ -0,0 +1,398 @@
+/**
+ Widget for uploading one or more Files to a Zope3 Server.
+
+ for autentication we need to get a ticket id befor sending the post request.
+
+ step1: get the ticket:
+
+ ./ticket.html/filename=myfile.jpg
+ this returns us a target path:
+ targeturl=http://......
+ this is the target where we post the file
+
+ step2: send file to the given url
+
+ configuration:
+ on _level0 we receive the information about where to get the ticket - inside
+ the ticket we receive the url where to upload.
+
+ _level0.target_path -> where to get the ticket
+ _level0.allowed_types -> space seperated files of allowed types.
+
+ _level0.allowed_types = "Images (all jpgs and pngs); jpg jpeg png gif|
+
+ @author <manfred.schwendinger at lovelysystems.com>
+*/
+
+
+import flash.net.FileReferenceList;
+import flash.net.FileReference;
+
+class z3c.widget.flashupload.Upload extends MovieClip{
+
+
+ private var info_mc:MovieClip;
+
+ private var file_array:Array;
+ private var fileref:FileReferenceList;
+ private var file:FileReference; // currently active file for upload
+
+ private var allowed_types:Array;
+ private var debug_txt:TextField;
+
+ private var upload_complete_str:String;
+
+ private var load_vars:LoadVars;
+
+ private var overall_total:Number;
+ private var overall_loaded:Number;
+
+ private var file_counter:Number;
+ private var file_amount:Number;
+
+ private var data_xml:XML;
+
+ private var error_msg:String;
+
+ private var js_command_queue:Array; // only one getURL can be called inside one frame. so lets make a queue to avoid troubles.
+
+ public function Upload(){
+
+
+ allowed_types = new Array();
+ js_command_queue = new Array();
+
+ overall_total = 0;
+ overall_loaded = 0;
+ file_counter = 0;
+
+ log("initialize. target: "+_level0.target_path);
+
+ // allow upload from the local host
+ System.security.allowDomain("http://localhost/");
+
+ fileref = new FileReferenceList();
+ fileref.addListener(this);
+
+ // we do not want to have an overall info if there is only 1 file uploading...
+ info_mc.overallinfo_mc._visible = false;
+
+ info_mc.fileinfo_mc.progress_mc.bar_mc.gotoAndStop(1);
+ info_mc.overallinfo_mc.progress_mc.bar_mc.gotoAndStop(1);
+
+ info_mc._visible = false;
+
+ this.onResize();
+ Stage.addListener(this)
+
+ var xml_url:String = _level0.site_path+"/@@flashuploadvars.xml";
+
+ data_xml = new XML();
+ data_xml["ptr"] = this;
+ data_xml.ignoreWhite = true;
+ data_xml.onLoad = function(){ this.ptr.parseDataXML(this); }
+ data_xml.load(xml_url);
+ //log("vars url: "+xml_url);
+
+
+ }
+
+ private function onResize(){
+
+ var margin:Number = 5;
+ var width:Number = Stage.width - 2*margin;
+
+ // position of the file info (current file name + number)
+ info_mc.filenum_txt._x = width - info_mc.filenum_txt._width;
+ info_mc.filename_txt._width = info_mc.filenum_txt._x - info_mc.filename_txt._x;
+ info_mc.progress_txt.text = "";
+ info_mc.progress_txt._x = width - info_mc.progress_txt._width;
+
+ // file progress positions
+ this.setProgressSize(info_mc.fileinfo_mc, width);
+ // overall progress positions
+ this.setProgressSize(info_mc.overallinfo_mc, width);
+ }
+
+ /*
+ sets the size of a bar line (overall and file bars)
+ */
+ private function setProgressSize(mc:MovieClip, width:Number):Void{
+ mc.label_txt._width = width - mc.progress_txt._width;
+ mc.progress_txt._x = width - mc.progress_txt._width;
+ mc.progress_mc._width = width;
+ }
+
+
+ /**
+ parses the language dependend strings.
+ */
+ private function parseDataXML(obj_xml:XML):Void{
+ log("xml loaded: "+obj_xml.firstChild);
+ var nodes = obj_xml.firstChild.childNodes;
+ for (var i=0; i<nodes.length; i++){
+ var nodeval:String = nodes[i].firstChild.nodeValue;
+ switch(nodes[i].attributes.name){
+ case "file_progress" :
+ info_mc.fileinfo_mc.label_txt.text = nodeval;
+ break;
+ case "overall_progress" :
+ info_mc.overallinfo_mc.label_txt.text = nodeval;
+ break;
+ case "error" :
+ error_msg = nodeval;
+ break;
+ case "uploadcomplete" :
+ upload_complete_str = nodeval;
+ break;
+ case "allowedFileType":
+ var allowedType = nodeval;
+ if (allowedType.charAt(0) == "."){
+ allowedType = "*"+allowedType;
+ }
+ allowed_types.push(allowedType);
+ log("add allowed type: "+allowedType+" ("+allowed_types.length+")");
+ break;
+ default:
+ log("error: unexpected attribute: "+nodes[i].attributes.name);
+ break;
+ }
+ }
+ }
+
+
+ /**
+ creates an array with all allowed types
+ the data gets parsed from the variable of _level0.allowed_types
+
+ var file:FileReference;
+
+ var allTypes:Array = new Array();
+ var imageTypes:Object = new Object();
+ imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
+ imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
+ allTypes.push(imageTypes);
+
+ var textTypes:Object = new Object();
+ textTypes.description = "Text Files (*.txt, *.rtf)";
+ textTypes.extension = "*.txt;*.rtf";
+ allTypes.push(textTypes);
+
+ arr = [{description:'a description', extension:'*.jpg'}, .....]
+ */
+ public function saveAllowedTypes(arr:Array):Void{
+ allowed_types = arr;
+ }
+
+ /**
+ starts the browsing process for uploading files
+ */
+ public function browse():Void{
+ js_command_queue.push("javascript:z3cFlashUploadDisableBrowseButton()");
+
+ if (allowed_types.length>0){
+ log("browse with limited filetypes: "+allowed_types);
+ var allTypes:Array = new Array();
+ var t:Object = new Object();
+ t.description = "Files";
+ t.extension = "";
+ for (var i=0; i<allowed_types.length; i++){
+ t.extension += allowed_types[i];
+ if (i<allowed_types.length - 1) t.extension+=";";
+ }
+ log("ALLOWED: "+t.extension);
+ allTypes.push(t);
+ fileref.browse(allTypes);
+ }
+ else{
+ log("browse");
+ fileref.browse();
+ }
+
+ }
+
+ /**
+ starts the upload queue
+ */
+ public function onSelect(fileRefList:FileReferenceList):Void{
+
+ file_array = fileRefList.fileList;
+ log("uploadFiles: "+file_array.length);
+
+ // overall progress should be visible on mutliple fileupload only.
+ info_mc.overallinfo_mc._visible = (file_array.length > 1);
+
+ for (var i=0; i<file_array.length; i++){
+ overall_total+=file_array[i].size;
+ }
+
+ if (file_array.length>0){
+ info_mc._visible = true;
+ file_counter = 0;
+ file_amount = file_array.length;
+ loadNextTicket();
+ }
+ }
+
+ /**
+ loads the next upload ticket via loadvars
+ the ticket holds some security information which
+ are required for the upload
+ */
+ public function loadNextTicket():Void{
+
+ // we want to have a 100% bar, even if onProgress was never
+ // fired because the file was so small that onProgress was
+ // never fired
+ this.updateFileProgress(100);
+
+ if (file_array.length == 0){
+ log("all files uploaded.");
+ // all files uploaded. Fire JavaScript Event
+ js_command_queue.push("javascript:z3cFlashUploadOnUploadCompleteFEvent()");
+
+ info_mc.filename_txt.text = upload_complete_str;
+ this.updateOverallProgress(100);
+ return;
+ }
+
+ load_vars = new LoadVars();
+ load_vars["ptr"] = this;
+ load_vars.onData = function(d:String){
+ this["ptr"].log("load data: "+d);
+ this["ptr"].loadNextFile(d);
+ }
+ load_vars.load(_level0.target_path+"/@@ticket");
+ }
+
+
+ /**
+ loads the next file inside the file_array
+ */
+ public function loadNextFile(ticket:String):Void{
+ file = FileReference(file_array.pop());
+
+ var url:String = _level0.target_path+"?ticket="+ticket;
+
+ log("uploadNextFile: "+url);
+
+ file.addListener(this);
+ file.upload(url);
+ }
+
+
+ public function log(msg:String):Void{
+ trace(msg);
+
+ if (msg.length>500) msg = msg.substring(msg.length-100, msg.length);
+
+ _level0.debug_txt.text+=msg+"\n";
+ _level0.debug_txt.scroll = _level0.debug_mc.debug_txt.maxscroll;
+ }
+
+
+
+ /**
+ FileReference Listeners....
+ */
+ public function onProgress(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void{
+
+ var percent:Number = Math.round(bytesLoaded/bytesTotal * 100);
+ if (percent>100) percent=100; // for any strange reason, the totalbytes can be smaller then the loade bytes :)
+ log("onProgress " + bytesLoaded + " bytesTotal: " + bytesTotal+" = "+percent+"%");
+
+ this.updateFileProgress(percent);
+
+ var percent_complete:Number = Math.round((overall_loaded+bytesLoaded) / overall_total * 100);
+
+ // hack for waiting time after last upload is done
+ // 100% should only be displayed when the LAST object fired his READY event.
+ if (percent_complete > 95) percent_complete = 95;
+ this.updateOverallProgress(percent_complete);
+
+ info_mc.progress_txt.text = getByteString(overall_loaded + bytesLoaded) + "/" + getByteString(overall_total);
+ }
+
+ public function updateFileProgress(percent:Number):Void{
+ if (percent>100) percent = 100;
+ info_mc.fileinfo_mc.progress_mc.bar_mc.gotoAndStop(percent);
+ info_mc.fileinfo_mc.progress_txt.text = percent+"%";
+ }
+
+ public function updateOverallProgress(percent:Number):Void{
+ if (percent>100) percent = 100;
+ info_mc.overallinfo_mc.progress_mc.bar_mc.gotoAndStop(percent);
+ info_mc.overallinfo_mc.progress_txt.text = percent+"%";
+ }
+
+ /**
+ returns a nice prepared string
+ */
+ public function getByteString(bytes:Number):String{
+ if (bytes<1024){
+ // bytes
+ return String(Math.round(bytes)+"B");
+ }
+ else if (bytes>(1024*1024)){
+ // MB
+ return String(Math.round(bytes/(1024*1024))+"MB");
+ }
+ else{
+ // KB
+ return String(Math.round(bytes/1024)+"KB");
+ }
+ }
+
+ public function onComplete(file:FileReference):Void{
+ log("file upload complete");
+
+ overall_loaded+=file.size;
+ this.loadNextTicket();
+
+ // tell javascript that the file is uploaded.
+ js_command_queue.push("javascript:z3cFlashUploadOnFileCompleteFEvent('"+file.name+"')");
+ }
+
+ public function onCancel(file:FileReference):Void{
+ log("onCancel");
+ js_command_queue.push("javascript:z3cFlashUploadOnCancelFEvent()");
+ }
+
+ public function onOpen(file:FileReference):Void{
+ log("onOpen: "+file.name+" : "+file.size);
+ file_counter++;
+
+ info_mc.filename_txt.text = file.name +" ("+Math.round(file.size/1024)+"kb)";
+ info_mc.filenum_txt.text = file_counter+"/"+file_amount;
+ }
+
+ public function onHTTPError(file:FileReference):Void {
+ log("onHTTPError: " + file.name);
+ js_command_queue.push("javascript:z3cFlashUploadOnErrorFEvent('"+this.error_msg+"')");
+ }
+
+ public function onIOError(file:FileReference):Void {
+ log("onIOError: " + file.name);
+ js_command_queue.push("javascript:z3cFlashUploadOnErrorFEvent('"+this.error_msg+"')");
+ }
+
+ public function onSecurityError(file:FileReference, errorString:String):Void {
+ log("onSecurityError: " + file.name + " errorString: " + errorString);
+ js_command_queue.push("javascript:z3cFlashUploadOnErrorFEvent('"+this.error_msg+"')");
+ }
+
+ public function onEnterFrame():Void{
+ if (_level0.startBrowse=="go"){
+ log("go event was fired");
+ _level0.startBrowse = "";
+ this.browse();
+ }
+
+ if (js_command_queue.length>0){
+ var command = js_command_queue.shift();
+ getURL(command);
+ }
+
+ }
+
+}
Modified: z3c.widget/trunk/setup.py
===================================================================
--- z3c.widget/trunk/setup.py 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/setup.py 2007-08-05 19:14:17 UTC (rev 78600)
@@ -2,7 +2,7 @@
from setuptools import setup, find_packages
setup(name='z3c.widget',
- version='0.1.0',
+ version='0.1.1',
author = "Zope Community",
author_email = "zope3-dev at zope.org",
description = "Additional Zope3 Widgets",
Modified: z3c.widget/trunk/src/z3c/widget/flashupload/configure.zcml
===================================================================
--- z3c.widget/trunk/src/z3c/widget/flashupload/configure.zcml 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/src/z3c/widget/flashupload/configure.zcml 2007-08-05 19:14:17 UTC (rev 78600)
@@ -22,6 +22,12 @@
</resourceLibrary>
</configure>
+
+ <browser:resource
+ name="upload.swf"
+ file="resources/upload.swf"
+ />
+
<!-- Flashdetection View -->
<browser:page
for="*"
Deleted: z3c.widget/trunk/src/z3c/widget/flashupload/resources/Upload.as
===================================================================
--- z3c.widget/trunk/src/z3c/widget/flashupload/resources/Upload.as 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/src/z3c/widget/flashupload/resources/Upload.as 2007-08-05 19:14:17 UTC (rev 78600)
@@ -1,398 +0,0 @@
-/**
- Widget for uploading one or more Files to a Zope3 Server.
-
- for autentication we need to get a ticket id befor sending the post request.
-
- step1: get the ticket:
-
- ./ticket.html/filename=myfile.jpg
- this returns us a target path:
- targeturl=http://......
- this is the target where we post the file
-
- step2: send file to the given url
-
- configuration:
- on _level0 we receive the information about where to get the ticket - inside
- the ticket we receive the url where to upload.
-
- _level0.target_path -> where to get the ticket
- _level0.allowed_types -> space seperated files of allowed types.
-
- _level0.allowed_types = "Images (all jpgs and pngs); jpg jpeg png gif|
-
- @author <manfred.schwendinger at lovelysystems.com>
-*/
-
-
-import flash.net.FileReferenceList;
-import flash.net.FileReference;
-
-class Upload extends MovieClip{
-
-
- private var info_mc:MovieClip;
-
- private var file_array:Array;
- private var fileref:FileReferenceList;
- private var file:FileReference; // currently active file for upload
-
- private var allowed_types:Array;
- private var debug_txt:TextField;
-
- private var upload_complete_str:String;
-
- private var load_vars:LoadVars;
-
- private var overall_total:Number;
- private var overall_loaded:Number;
-
- private var file_counter:Number;
- private var file_amount:Number;
-
- private var data_xml:XML;
-
- private var error_msg:String;
-
- private var js_command_queue:Array; // only one getURL can be called inside one frame. so lets make a queue to avoid troubles.
-
- public function Upload(){
-
-
- allowed_types = new Array();
- js_command_queue = new Array();
-
- overall_total = 0;
- overall_loaded = 0;
- file_counter = 0;
-
- log("initialize. target: "+_level0.target_path);
-
- // allow upload from the local host
- System.security.allowDomain("http://localhost/");
-
- fileref = new FileReferenceList();
- fileref.addListener(this);
-
- // we do not want to have an overall info if there is only 1 file uploading...
- info_mc.overallinfo_mc._visible = false;
-
- info_mc.fileinfo_mc.progress_mc.bar_mc.gotoAndStop(1);
- info_mc.overallinfo_mc.progress_mc.bar_mc.gotoAndStop(1);
-
- info_mc._visible = false;
-
- this.onResize();
- Stage.addListener(this)
-
- var xml_url:String = _level0.base_path+"/@@flashuploadvars.xml";
-
- data_xml = new XML();
- data_xml["ptr"] = this;
- data_xml.ignoreWhite = true;
- data_xml.onLoad = function(){ this.ptr.parseDataXML(this); }
- data_xml.load(xml_url);
- //log("vars url: "+xml_url);
-
-
- }
-
- private function onResize(){
-
- var margin:Number = 5;
- var width:Number = Stage.width - 2*margin;
-
- // position of the file info (current file name + number)
- info_mc.filenum_txt._x = width - info_mc.filenum_txt._width;
- info_mc.filename_txt._width = info_mc.filenum_txt._x - info_mc.filename_txt._x;
- info_mc.progress_txt.text = "";
- info_mc.progress_txt._x = width - info_mc.progress_txt._width;
-
- // file progress positions
- this.setProgressSize(info_mc.fileinfo_mc, width);
- // overall progress positions
- this.setProgressSize(info_mc.overallinfo_mc, width);
- }
-
- /*
- sets the size of a bar line (overall and file bars)
- */
- private function setProgressSize(mc:MovieClip, width:Number):Void{
- mc.label_txt._width = width - mc.progress_txt._width;
- mc.progress_txt._x = width - mc.progress_txt._width;
- mc.progress_mc._width = width;
- }
-
-
- /**
- parses the language dependend strings.
- */
- private function parseDataXML(obj_xml:XML):Void{
- log("xml loaded: "+obj_xml.firstChild);
- var nodes = obj_xml.firstChild.childNodes;
- for (var i=0; i<nodes.length; i++){
- var nodeval:String = nodes[i].firstChild.nodeValue;
- switch(nodes[i].attributes.name){
- case "file_progress" :
- info_mc.fileinfo_mc.label_txt.text = nodeval;
- break;
- case "overall_progress" :
- info_mc.overallinfo_mc.label_txt.text = nodeval;
- break;
- case "error" :
- error_msg = nodeval;
- break;
- case "uploadcomplete" :
- upload_complete_str = nodeval;
- break;
- case "allowedFileType":
- var allowedType = nodeval;
- if (allowedType.charAt(0) == "."){
- allowedType = "*"+allowedType;
- }
- allowed_types.push(allowedType);
- log("add allowed type: "+allowedType+" ("+allowed_types.length+")");
- break;
- default:
- log("error: unexpected attribute: "+nodes[i].attributes.name);
- break;
- }
- }
- }
-
-
- /**
- creates an array with all allowed types
- the data gets parsed from the variable of _level0.allowed_types
-
- var file:FileReference;
-
- var allTypes:Array = new Array();
- var imageTypes:Object = new Object();
- imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
- imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
- allTypes.push(imageTypes);
-
- var textTypes:Object = new Object();
- textTypes.description = "Text Files (*.txt, *.rtf)";
- textTypes.extension = "*.txt;*.rtf";
- allTypes.push(textTypes);
-
- arr = [{description:'a description', extension:'*.jpg'}, .....]
- */
- public function saveAllowedTypes(arr:Array):Void{
- allowed_types = arr;
- }
-
- /**
- starts the browsing process for uploading files
- */
- public function browse():Void{
- js_command_queue.push("javascript:z3cFlashUploadDisableBrowseButton()");
-
- if (allowed_types.length>0){
- log("browse with limited filetypes: "+allowed_types);
- var allTypes:Array = new Array();
- var t:Object = new Object();
- t.description = "Files";
- t.extension = "";
- for (var i=0; i<allowed_types.length; i++){
- t.extension += allowed_types[i];
- if (i<allowed_types.length - 1) t.extension+=";";
- }
- log("ALLOWED: "+t.extension);
- allTypes.push(t);
- fileref.browse(allTypes);
- }
- else{
- log("browse");
- fileref.browse();
- }
-
- }
-
- /**
- starts the upload queue
- */
- public function onSelect(fileRefList:FileReferenceList):Void{
-
- file_array = fileRefList.fileList;
- log("uploadFiles: "+file_array.length);
-
- // overall progress should be visible on mutliple fileupload only.
- info_mc.overallinfo_mc._visible = (file_array.length > 1);
-
- for (var i=0; i<file_array.length; i++){
- overall_total+=file_array[i].size;
- }
-
- if (file_array.length>0){
- info_mc._visible = true;
- file_counter = 0;
- file_amount = file_array.length;
- loadNextTicket();
- }
- }
-
- /**
- loads the next upload ticket via loadvars
- the ticket holds some security information which
- are required for the upload
- */
- public function loadNextTicket():Void{
-
- // we want to have a 100% bar, even if onProgress was never
- // fired because the file was so small that onProgress was
- // never fired
- this.updateFileProgress(100);
-
- if (file_array.length == 0){
- log("all files uploaded.");
- // all files uploaded. Fire JavaScript Event
- js_command_queue.push("javascript:z3cFlashUploadOnUploadCompleteFEvent()");
-
- info_mc.filename_txt.text = upload_complete_str;
- this.updateOverallProgress(100);
- return;
- }
-
- load_vars = new LoadVars();
- load_vars["ptr"] = this;
- load_vars.onData = function(d:String){
- this["ptr"].log("load data: "+d);
- this["ptr"].loadNextFile(d);
- }
- load_vars.load(_level0.target_path+"/@@ticket");
- }
-
-
- /**
- loads the next file inside the file_array
- */
- public function loadNextFile(ticket:String):Void{
- file = FileReference(file_array.pop());
-
- var url:String = _level0.target_path+"?ticket="+ticket;
-
- log("uploadNextFile: "+url);
-
- file.addListener(this);
- file.upload(url);
- }
-
-
- public function log(msg:String):Void{
- trace(msg);
-
- if (msg.length>500) msg = msg.substring(msg.length-100, msg.length);
-
- _level0.debug_txt.text+=msg+"\n";
- _level0.debug_txt.scroll = _level0.debug_mc.debug_txt.maxscroll;
- }
-
-
-
- /**
- FileReference Listeners....
- */
- public function onProgress(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void{
-
- var percent:Number = Math.round(bytesLoaded/bytesTotal * 100);
- if (percent>100) percent=100; // for any strange reason, the totalbytes can be smaller then the loade bytes :)
- log("onProgress " + bytesLoaded + " bytesTotal: " + bytesTotal+" = "+percent+"%");
-
- this.updateFileProgress(percent);
-
- var percent_complete:Number = Math.round((overall_loaded+bytesLoaded) / overall_total * 100);
-
- // hack for waiting time after last upload is done
- // 100% should only be displayed when the LAST object fired his READY event.
- if (percent_complete > 95) percent_complete = 95;
- this.updateOverallProgress(percent_complete);
-
- info_mc.progress_txt.text = getByteString(overall_loaded + bytesLoaded) + "/" + getByteString(overall_total);
- }
-
- public function updateFileProgress(percent:Number):Void{
- if (percent>100) percent = 100;
- info_mc.fileinfo_mc.progress_mc.bar_mc.gotoAndStop(percent);
- info_mc.fileinfo_mc.progress_txt.text = percent+"%";
- }
-
- public function updateOverallProgress(percent:Number):Void{
- if (percent>100) percent = 100;
- info_mc.overallinfo_mc.progress_mc.bar_mc.gotoAndStop(percent);
- info_mc.overallinfo_mc.progress_txt.text = percent+"%";
- }
-
- /**
- returns a nice prepared string
- */
- public function getByteString(bytes:Number):String{
- if (bytes<1024){
- // bytes
- return String(Math.round(bytes)+"B");
- }
- else if (bytes>(1024*1024)){
- // MB
- return String(Math.round(bytes/(1024*1024))+"MB");
- }
- else{
- // KB
- return String(Math.round(bytes/1024)+"KB");
- }
- }
-
- public function onComplete(file:FileReference):Void{
- log("file upload complete");
-
- overall_loaded+=file.size;
- this.loadNextTicket();
-
- // tell javascript that the file is uploaded.
- js_command_queue.push("javascript:z3cFlashUploadOnFileCompleteFEvent('"+file.name+"')");
- }
-
- public function onCancel(file:FileReference):Void{
- log("onCancel");
- js_command_queue.push("javascript:z3cFlashUploadOnCancelFEvent()");
- }
-
- public function onOpen(file:FileReference):Void{
- log("onOpen: "+file.name+" : "+file.size);
- file_counter++;
-
- info_mc.filename_txt.text = file.name +" ("+Math.round(file.size/1024)+"kb)";
- info_mc.filenum_txt.text = file_counter+"/"+file_amount;
- }
-
- public function onHTTPError(file:FileReference):Void {
- log("onHTTPError: " + file.name);
- js_command_queue.push("javascript:z3cFlashUploadOnErrorFEvent('"+this.error_msg+"')");
- }
-
- public function onIOError(file:FileReference):Void {
- log("onIOError: " + file.name);
- js_command_queue.push("javascript:z3cFlashUploadOnErrorFEvent('"+this.error_msg+"')");
- }
-
- public function onSecurityError(file:FileReference, errorString:String):Void {
- log("onSecurityError: " + file.name + " errorString: " + errorString);
- js_command_queue.push("javascript:z3cFlashUploadOnErrorFEvent('"+this.error_msg+"')");
- }
-
- public function onEnterFrame():Void{
- if (_level0.startBrowse=="go"){
- log("go event was fired");
- _level0.startBrowse = "";
- this.browse();
- }
-
- if (js_command_queue.length>0){
- var command = js_command_queue.shift();
- getURL(command);
- }
-
- }
-
-}
Deleted: z3c.widget/trunk/src/z3c/widget/flashupload/resources/debug.as
===================================================================
--- z3c.widget/trunk/src/z3c/widget/flashupload/resources/debug.as 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/src/z3c/widget/flashupload/resources/debug.as 2007-08-05 19:14:17 UTC (rev 78600)
@@ -1,23 +0,0 @@
-/*
- this small script allows you to see the log if you press
- SHIFT + F12
-
- very nice for debugging :)
- */
-_root.listener = new Object();
-_root.listener.onKeyUp = function(){
- trace(Key.getCode());
- if (Key.getCode() == 123 && Key.isDown(Key.SHIFT)){
-
- _root.debug_txt._visible = !_root.debug_txt._visible;
-
- _root.debug_txt._x = 0;
- _root.debug_txt._y = 0;
- _root.debug_txt._width = Stage.width - 1;
- _root.debug_txt._height = Stage.height - 1;
- }
-
-}
-Key.addListener(_root.listener);
-
-_root.debug_txt._visible = false;
\ No newline at end of file
Deleted: z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.fla
===================================================================
(Binary files differ)
Deleted: z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.html
===================================================================
--- z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.html 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.html 2007-08-05 19:14:17 UTC (rev 78600)
@@ -1,15 +0,0 @@
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-<title>upload</title>
-</head>
-<body bgcolor="#f8f8f8">
-<!--Im Film verwendete URLs-->
-<!--Im Film verwendeter Text-->
-<!-- saved from url=(0013)about:internet -->
-<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="220" height="300" id="upload" align="middle">
-<param name="allowScriptAccess" value="sameDomain" />
-<param name="movie" value="upload.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#f8f8f8" /><embed src="upload.swf" quality="high" wmode="transparent" bgcolor="#f8f8f8" width="220" height="300" name="upload" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
-</object>
-</body>
-</html>
Modified: z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.js
===================================================================
--- z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.js 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.js 2007-08-05 19:14:17 UTC (rev 78600)
@@ -48,28 +48,23 @@
insidde the target div.
Required global variable: swf_upload_target_path
*/
-function createFlashUpload(){
- var so = new SWFObject(swf_upload_url, "fuploader", "300", "100", "8.0.33", "#f8f8f8");
+function createFlashUpload()
+{
+ var so = new SWFObject(swf_upload_url, "fuploader", "100%", "100%", "8.0.33", "#f8f8f8");
so.addParam("allowScriptAccess", "sameDomain");
so.addParam("wmode", "transparent");
-
- // we need to manually quote the "+" signs to make shure they do not
+
+ // we need to manually quote the "+" signs to make sure they do not
// result in a " " sign inside flash
- var quoted_location_url = escape(window.location.href).split("+").join("%2B");
+ var quoted_location_url = escape(window.location.href).split("+").join("%2B");
so.addVariable("target_path", swf_upload_target_path);
so.addVariable("base_path", quoted_location_url);
-
+ so.addVariable("site_path", swf_upload_site_url);
+
var success = so.write("flashuploadtarget");
- if (!success){
+ if (!success){
$("#flashuploadtarget").load("noflashupload.html")
- /*var ajaxUpdater = new Ajax.Updater(
- "flashuploadtarget",
- 'noflashupload.html',
- {
- method: 'get'
- });*/
-
}
}
Modified: z3c.widget/trunk/src/z3c/widget/flashupload/resources/upload.swf
===================================================================
(Binary files differ)
Modified: z3c.widget/trunk/src/z3c/widget/flashupload/upload.py
===================================================================
--- z3c.widget/trunk/src/z3c/widget/flashupload/upload.py 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/src/z3c/widget/flashupload/upload.py 2007-08-05 19:14:17 UTC (rev 78600)
@@ -9,6 +9,7 @@
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.app.container.constraints import checkObject
from zope import event
+from zope.app.component.interfaces import ISite
from z3c.widget.flashupload.interfaces import (IFlashUploadForm,
IUploadFileView,
@@ -84,6 +85,12 @@
template = ViewPageTemplateFile('uploadform.pt')
interface.implements(IFlashUploadForm)
+
+ @property
+ def siteUrl(self):
+ import pdb; pdb.set_trace()
+
+ return absoluteURL(ISite(None), self.request)
def __call__(self, *args, **kw):
if haveResourceLibrary:
Modified: z3c.widget/trunk/src/z3c/widget/flashupload/uploadform.pt
===================================================================
--- z3c.widget/trunk/src/z3c/widget/flashupload/uploadform.pt 2007-08-05 16:22:04 UTC (rev 78599)
+++ z3c.widget/trunk/src/z3c/widget/flashupload/uploadform.pt 2007-08-05 19:14:17 UTC (rev 78600)
@@ -7,14 +7,18 @@
<input type="button" id="flash.start.browsing" value="Browse"
i18n:attributes="value"
onClick="JavaScript:z3cFlashUploadStartBrowsing()" />
+
<script type="text/javascript" tal:content="string:
- var swf_upload_url='${context/++resource++z3c.widget.flashupload/upload.swf}';
+ var swf_upload_url='${context/++resource++upload.swf}';
var swf_upload_target_path='${context/@@absolute_url/url:quote}/uploadfile';
+ var swf_upload_site_url='${view/siteUrl}';
">
</script>
<div id="flashuploadtarget">
- <!-- inside this div, the flash upload swf will be injected -->
+ <!-- inside this div, the flash upload swf will be injected
+ resize this div depending to your needs - the swf will
+ take use of the full size of this div -->
</div>
</metal:block>
More information about the Checkins
mailing list