Initial commit: Kimai TMS
Kimai time management system (PHP 5.6 / MySQL) with custom extensions: - Budget tracking (ki_budget) - Change request form (ki_changerequest) - Invoice generation (ki_invoice) - Expense tracking (ki_expenses) - Flexi time (ki_flexitime) - Export, admin panel, timesheets, tasks, summary Database: ~900K time entries, 2,000+ users, 439 projects. Config: includes/autoconf.php — localhost/kimai/kimai
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?
|
||||
|
||||
|
||||
if (false == class_exists('xajaxPlugin') || false == class_exists('xajaxPluginManager'))
|
||||
{
|
||||
$sBaseFolder = dirname(dirname(dirname(__FILE__)));
|
||||
$sXajaxCore = $sBaseFolder . '/xajax_core';
|
||||
|
||||
if (false == class_exists('xajaxPlugin'))
|
||||
require $sXajaxCore . '/xajaxPlugin.inc.php';
|
||||
if (false == class_exists('xajaxPluginManager'))
|
||||
require $sXajaxCore . '/xajaxPluginManager.inc.php';
|
||||
}
|
||||
|
||||
|
||||
//if (!defined ('XAJAX_UPLOAD_FUNCTION')) define ('XAJAX_UPLOAD_FUNCTION', 'upfunction');
|
||||
|
||||
//require_once dirname(__FILE__) . '/xajaxUploadFunction.inc.php';
|
||||
|
||||
class clsSession extends xajaxRequestPlugin
|
||||
{
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private $sCallName = "Session";
|
||||
private $sXajaxPrefix = "xajax_";
|
||||
|
||||
|
||||
private $sSessionCheck = "";
|
||||
private $sSessionExpired = "";
|
||||
|
||||
public function clsSession()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function configure($sName, $mValue)
|
||||
{
|
||||
switch ($sName)
|
||||
{
|
||||
case 'sessionCheck':
|
||||
if (is_string($mValue) || is_array($mValue))
|
||||
{
|
||||
$this->sSessionCheck = $mValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'sessionExpired':
|
||||
if (is_string($mValue) || is_array($mValue))
|
||||
{
|
||||
$this->sSessionExpired = $mValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
|
||||
$objPluginManager =& xajaxPluginManager::getInstance();
|
||||
$objPluginManager->registerPlugin(new clsSession(), 10);
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
if ( false == class_exists( 'xajaxPlugin' ) || false == class_exists( 'xajaxPluginManager' ) )
|
||||
{
|
||||
$sBaseFolder = dirname( dirname( dirname( __FILE__ ) ) );
|
||||
$sXajaxCore = $sBaseFolder.'/xajax_core';
|
||||
|
||||
if ( false == class_exists( 'xajaxPlugin' ) )
|
||||
require $sXajaxCore.'/xajaxPlugin.inc.php';
|
||||
|
||||
if ( false == class_exists( 'xajaxPluginManager' ) )
|
||||
require $sXajaxCore.'/xajaxPluginManager.inc.php';
|
||||
}
|
||||
|
||||
class clsSwfUpload
|
||||
extends xajaxResponsePlugin
|
||||
{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private $sCallName = "SWFUpload";
|
||||
private $sDefer;
|
||||
private $sJavascriptURI;
|
||||
private $bInlineScript;
|
||||
private $SWFupload_FadeTimeOut = 1500;
|
||||
private $sRequestedFunction = NULL;
|
||||
|
||||
private $sXajaxPrefix = "xajax_";
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function clsSwfUpload()
|
||||
{
|
||||
$this->sDefer = '';
|
||||
$this->sJavascriptURI = '';
|
||||
$this->bInlineScript = false;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function getName()
|
||||
{
|
||||
return get_class( $this );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
public function configure( $sName, $mValue )
|
||||
{
|
||||
switch ( $sName )
|
||||
{
|
||||
case 'scriptDeferral':
|
||||
if ( true === $mValue || false === $mValue )
|
||||
{
|
||||
if ( $mValue )
|
||||
$this->sDefer = 'defer ';
|
||||
else
|
||||
$this->sDefer = '';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'javascript URI':
|
||||
$this->sJavascriptURI = $mValue;
|
||||
break;
|
||||
|
||||
case 'inlineScript':
|
||||
if ( true === $mValue || false === $mValue )
|
||||
$this->bInlineScript = $mValue;
|
||||
break;
|
||||
|
||||
case 'SWFupload_FadeTimeOut':
|
||||
if ( is_numeric( $mValue ) )
|
||||
$this->SWFupload_FadeTimeOut = $mValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function generateClientScript()
|
||||
{
|
||||
echo "\n<script type='text/javascript' ".$this->sDefer."charset='UTF-8'>\n";
|
||||
echo "/* <![CDATA[ */\n";
|
||||
echo "if (undefined == xajax.ext) xajax.ext = {};\n";
|
||||
echo "xajax.ext.SWFupload = {};";
|
||||
echo "xajax.ext.SWFupload.config = {};\n";
|
||||
echo "xajax.ext.SWFupload.config.javascript_URI='".$this->sJavascriptURI."xajax_plugins/request/swfupload/';\n";
|
||||
echo "xajax.ext.SWFupload.config.FadeTimeOut = '".$this->SWFupload_FadeTimeOut."';\n";
|
||||
echo "/* ]]> */\n";
|
||||
echo "</script>\n";
|
||||
|
||||
if ( $this->bInlineScript )
|
||||
{
|
||||
echo "\n<script type='text/javascript' ".$this->sDefer."charset='UTF-8'>\n";
|
||||
echo "/* <![CDATA[ */\n";
|
||||
|
||||
include( dirname( __FILE__ ).'xajax_plugins/request/swfupload/swfupload.js' );
|
||||
include( dirname( __FILE__ ).'xajax_plugins/request/swfupload/swfupload.xajax.js' );
|
||||
|
||||
echo "/* ]]> */\n";
|
||||
echo "</script>\n";
|
||||
}else
|
||||
{
|
||||
echo "\n<script type='text/javascript' src='".$this->sJavascriptURI."xajax_plugins/request/swfupload/swfupload.js' ".$this->sDefer."charset='UTF-8'></script>\n";
|
||||
echo "\n<script type='text/javascript' src='".$this->sJavascriptURI."xajax_plugins/request/swfupload/swfupload.xajax3.js' ".$this->sDefer."charset='UTF-8'></script>\n";
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function transForm( $id, $config, $multi = false )
|
||||
{
|
||||
$command = array
|
||||
(
|
||||
'cmd' => 'SWFup_tfo',
|
||||
'id' => $id
|
||||
);
|
||||
|
||||
$this->addCommand( $command, array
|
||||
(
|
||||
"config" => $config,
|
||||
"multi" => $multi
|
||||
));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function transField( $id, $config, $multi = false )
|
||||
{
|
||||
$command = array
|
||||
(
|
||||
'cmd' => 'SWFup_tfi',
|
||||
'id' => $id
|
||||
);
|
||||
|
||||
$this->addCommand( $command, array
|
||||
(
|
||||
"config" => $config,
|
||||
"multi" => $multi
|
||||
));
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function destroyField( $id )
|
||||
{
|
||||
$command = array
|
||||
(
|
||||
'cmd' => 'SWFup_dfi',
|
||||
'id' => $id
|
||||
);
|
||||
|
||||
$this->addCommand( $command, array ());
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function destroyForm( $id )
|
||||
{
|
||||
$command = array
|
||||
(
|
||||
'cmd' => 'SWFup_dfo',
|
||||
'id' => $id
|
||||
);
|
||||
|
||||
$this->addCommand( $command, array ());
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
||||
|
||||
$objPluginManager = &xajaxPluginManager::getInstance();
|
||||
$objPluginManager->registerPlugin( new clsSwfUpload(), 100 );
|
||||
?>
|
||||
99
libraries/xajax/xajax_plugins/request/swfupload/swfupload.js
Normal file
99
libraries/xajax/xajax_plugins/request/swfupload/swfupload.js
Normal file
@@ -0,0 +1,99 @@
|
||||
|
||||
var SWFUpload=function(settings){this.initSWFUpload(settings);};SWFUpload.prototype.initSWFUpload=function(settings){try{this.customSettings={};this.settings=settings;this.eventQueue=[];this.movieName="SWFUpload_"+SWFUpload.movieCount++;this.movieElement=null;SWFUpload.instances[this.movieName]=this;this.initSettings();this.loadFlash();this.displayDebugInfo();}catch(ex){delete SWFUpload.instances[this.movieName];throw ex;}
|
||||
};SWFUpload.instances={};SWFUpload.movieCount=0;SWFUpload.version="2.1.0 beta 1";SWFUpload.QUEUE_ERROR={QUEUE_LIMIT_EXCEEDED:-100,
|
||||
FILE_EXCEEDS_SIZE_LIMIT:-110,
|
||||
ZERO_BYTE_FILE:-120,
|
||||
INVALID_FILETYPE:-130
|
||||
};SWFUpload.UPLOAD_ERROR={HTTP_ERROR:-200,
|
||||
MISSING_UPLOAD_URL:-210,
|
||||
IO_ERROR:-220,
|
||||
SECURITY_ERROR:-230,
|
||||
UPLOAD_LIMIT_EXCEEDED:-240,
|
||||
UPLOAD_FAILED:-250,
|
||||
SPECIFIED_FILE_ID_NOT_FOUND:-260,
|
||||
FILE_VALIDATION_FAILED:-270,
|
||||
FILE_CANCELLED:-280,
|
||||
UPLOAD_STOPPED:-290
|
||||
};SWFUpload.FILE_STATUS={QUEUED:-1,
|
||||
IN_PROGRESS:-2,
|
||||
ERROR:-3,
|
||||
COMPLETE:-4,
|
||||
CANCELLED:-5
|
||||
};SWFUpload.prototype.initSettings=function(){this.ensureDefault=function(settingName,defaultValue){this.settings[settingName]=(this.settings[settingName]==undefined)? defaultValue:this.settings[settingName];};this.ensureDefault("upload_url","");this.ensureDefault("file_post_name","Filedata");this.ensureDefault("post_params",{});this.ensureDefault("use_query_string",false);this.ensureDefault("requeue_on_error",false);this.ensureDefault("file_types","*.*");this.ensureDefault("file_types_description","All Files");this.ensureDefault("file_size_limit",0);this.ensureDefault("file_upload_limit",0);this.ensureDefault("file_queue_limit",0);this.ensureDefault("flash_url","swfupload_f9.swf");this.ensureDefault("flash_color","#FFFFFF");this.ensureDefault("debug",false);this.settings.debug_enabled=this.settings.debug;this.settings.return_upload_start_handler=this.returnUploadStart;this.ensureDefault("swfupload_loaded_handler",null);this.ensureDefault("file_dialog_start_handler",null);this.ensureDefault("file_queued_handler",null);this.ensureDefault("file_queue_error_handler",null);this.ensureDefault("file_dialog_complete_handler",null);this.ensureDefault("upload_start_handler",null);this.ensureDefault("upload_progress_handler",null);this.ensureDefault("upload_error_handler",null);this.ensureDefault("upload_success_handler",null);this.ensureDefault("upload_complete_handler",null);this.ensureDefault("debug_handler",this.debugMessage);this.ensureDefault("custom_settings",{});this.customSettings=this.settings.custom_settings;delete this.ensureDefault;};SWFUpload.prototype.loadFlash=function(){var targetElement,container;if(document.getElementById(this.movieName)!==null){throw "ID "+this.movieName+" is already in use. The Flash Object could not be added";}
|
||||
targetElement=document.getElementsByTagName("body")[0];if(targetElement==undefined){throw "Could not find the 'body' element.";}
|
||||
container=document.createElement("div");container.style.width="1px";container.style.height="1px";targetElement.appendChild(container);container.innerHTML=this.getFlashHTML();};SWFUpload.prototype.getFlashHTML=function(){return ['<object id="',this.movieName,'" type="application/x-shockwave-flash" data="',this.settings.flash_url,'" width="1" height="1" style="-moz-user-focus: ignore;">',
|
||||
'<param name="movie" value="',this.settings.flash_url,'" />',
|
||||
'<param name="bgcolor" value="',this.settings.flash_color,'" />',
|
||||
'<param name="quality" value="high" />',
|
||||
'<param name="menu" value="false" />',
|
||||
'<param name="allowScriptAccess" value="always" />',
|
||||
'<param name="flashvars" value="'+this.getFlashVars()+'" />',
|
||||
'</object>'].join("");};SWFUpload.prototype.getFlashVars=function(){var paramString=this.buildParamString();return ["movieName=",encodeURIComponent(this.movieName),
|
||||
"&uploadURL=",encodeURIComponent(this.settings.upload_url),
|
||||
"&useQueryString=",encodeURIComponent(this.settings.use_query_string),
|
||||
"&requeueOnError=",encodeURIComponent(this.settings.requeue_on_error),
|
||||
"&params=",encodeURIComponent(paramString),
|
||||
"&filePostName=",encodeURIComponent(this.settings.file_post_name),
|
||||
"&fileTypes=",encodeURIComponent(this.settings.file_types),
|
||||
"&fileTypesDescription=",encodeURIComponent(this.settings.file_types_description),
|
||||
"&fileSizeLimit=",encodeURIComponent(this.settings.file_size_limit),
|
||||
"&fileUploadLimit=",encodeURIComponent(this.settings.file_upload_limit),
|
||||
"&fileQueueLimit=",encodeURIComponent(this.settings.file_queue_limit),
|
||||
"&debugEnabled=",encodeURIComponent(this.settings.debug_enabled)].join("");};SWFUpload.prototype.getMovieElement=function(){if(this.movieElement==undefined){this.movieElement=document.getElementById(this.movieName);}
|
||||
if(this.movieElement===null){throw "Could not find Flash element";}
|
||||
return this.movieElement;};SWFUpload.prototype.buildParamString=function(){var postParams=this.settings.post_params;var paramStringPairs=[];if(typeof(postParams)==="object"){for(var name in postParams){if(postParams.hasOwnProperty(name)){paramStringPairs.push(encodeURIComponent(name.toString())+"="+encodeURIComponent(postParams[name].toString()));}
|
||||
}
|
||||
}
|
||||
return paramStringPairs.join("&");};SWFUpload.prototype.displayDebugInfo=function(){this.debug(
|
||||
[
|
||||
"---SWFUpload Instance Info---\n",
|
||||
"Version: ",SWFUpload.version,"\n",
|
||||
"Movie Name: ",this.movieName,"\n",
|
||||
"Settings:\n",
|
||||
"\t","upload_url: ",this.settings.upload_url,"\n",
|
||||
"\t","use_query_string: ",this.settings.use_query_string.toString(),"\n",
|
||||
"\t","file_post_name: ",this.settings.file_post_name,"\n",
|
||||
"\t","post_params: ",this.settings.post_params.toString(),"\n",
|
||||
"\t","file_types: ",this.settings.file_types,"\n",
|
||||
"\t","file_types_description: ",this.settings.file_types_description,"\n",
|
||||
"\t","file_size_limit: ",this.settings.file_size_limit,"\n",
|
||||
"\t","file_upload_limit: ",this.settings.file_upload_limit,"\n",
|
||||
"\t","file_queue_limit: ",this.settings.file_queue_limit,"\n",
|
||||
"\t","flash_url: ",this.settings.flash_url,"\n",
|
||||
"\t","flash_color: ",this.settings.flash_color,"\n",
|
||||
"\t","debug: ",this.settings.debug.toString(),"\n",
|
||||
"\t","custom_settings: ",this.settings.custom_settings.toString(),"\n",
|
||||
"Event Handlers:\n",
|
||||
"\t","swfupload_loaded_handler assigned: ",(typeof(this.settings.swfupload_loaded_handler)==="function").toString(),"\n",
|
||||
"\t","file_dialog_start_handler assigned: ",(typeof(this.settings.file_dialog_start_handler)==="function").toString(),"\n",
|
||||
"\t","file_queued_handler assigned: ",(typeof(this.settings.file_queued_handler)==="function").toString(),"\n",
|
||||
"\t","file_queue_error_handler assigned: ",(typeof(this.settings.file_queue_error_handler)==="function").toString(),"\n",
|
||||
"\t","upload_start_handler assigned: ",(typeof(this.settings.upload_start_handler)==="function").toString(),"\n",
|
||||
"\t","upload_progress_handler assigned: ",(typeof(this.settings.upload_progress_handler)==="function").toString(),"\n",
|
||||
"\t","upload_error_handler assigned: ",(typeof(this.settings.upload_error_handler)==="function").toString(),"\n",
|
||||
"\t","upload_success_handler assigned: ",(typeof(this.settings.upload_success_handler)==="function").toString(),"\n",
|
||||
"\t","upload_complete_handler assigned: ",(typeof(this.settings.upload_complete_handler)==="function").toString(),"\n",
|
||||
"\t","debug_handler assigned: ",(typeof(this.settings.debug_handler)==="function").toString(),"\n"
|
||||
].join("")
|
||||
);};SWFUpload.prototype.addSetting=function(name,value,default_value){if(value==undefined){return(this.settings[name]=default_value);}else{return(this.settings[name]=value);}
|
||||
};SWFUpload.prototype.getSetting=function(name){if(this.settings[name]!=undefined){return this.settings[name];}
|
||||
return "";};SWFUpload.prototype.callFlash=function(functionName,withTimeout,argumentArray){withTimeout=!!withTimeout||false;argumentArray=argumentArray||[];var self=this;var callFunction=function(){var movieElement=self.getMovieElement();var returnValue;if(typeof(movieElement[functionName])==="function"){if(argumentArray.length===0){returnValue=movieElement[functionName]();}else if(argumentArray.length===1){returnValue=movieElement[functionName](argumentArray[0]);}else if(argumentArray.length===2){returnValue=movieElement[functionName](argumentArray[0],argumentArray[1]);}else if(argumentArray.length===3){returnValue=movieElement[functionName](argumentArray[0],argumentArray[1],argumentArray[2]);}else{throw "Too many arguments";}
|
||||
if(returnValue!=undefined&&typeof(returnValue.post)==="object"){returnValue=self.unescapeFilePostParams(returnValue);}
|
||||
return returnValue;}else{throw "Invalid function name";}
|
||||
};if(withTimeout){setTimeout(callFunction,0);}else{return callFunction();}
|
||||
};SWFUpload.prototype.selectFile=function(){this.callFlash("SelectFile");};SWFUpload.prototype.selectFiles=function(){this.callFlash("SelectFiles");};SWFUpload.prototype.startUpload=function(fileID){this.callFlash("StartUpload",false,[fileID]);};SWFUpload.prototype.cancelUpload=function(fileID){this.callFlash("CancelUpload",false,[fileID]);};SWFUpload.prototype.stopUpload=function(){this.callFlash("StopUpload");};SWFUpload.prototype.getStats=function(){return this.callFlash("GetStats");};SWFUpload.prototype.setStats=function(statsObject){this.callFlash("SetStats",false,[statsObject]);};SWFUpload.prototype.setCredentials=function(name,password){this.callFlash("SetCrednetials",false,[name,password]);};SWFUpload.prototype.getFile=function(fileID){if(typeof(fileID)==="number"){return this.callFlash("GetFileByIndex",false,[fileID]);}else{return this.callFlash("GetFile",false,[fileID]);}
|
||||
};SWFUpload.prototype.addFileParam=function(fileID,name,value){return this.callFlash("AddFileParam",false,[fileID,name,value]);};SWFUpload.prototype.removeFileParam=function(fileID,name){this.callFlash("RemoveFileParam",false,[fileID,name]);};SWFUpload.prototype.setUploadURL=function(url){this.settings.upload_url=url.toString();this.callFlash("SetUploadURL",false,[url]);};SWFUpload.prototype.setPostParams=function(paramsObject){this.settings.post_params=paramsObject;this.callFlash("SetPostParams",false,[paramsObject]);};SWFUpload.prototype.addPostParam=function(name,value){this.settings.post_params[name]=value;this.callFlash("SetPostParams",false,[this.settings.post_params]);};SWFUpload.prototype.removePostParam=function(name){delete this.settings.post_params[name];this.callFlash("SetPostParams",false,[this.settings.post_params]);};SWFUpload.prototype.setFileTypes=function(types,description){this.settings.file_types=types;this.settings.file_types_description=description;this.callFlash("SetFileTypes",false,[types,description]);};SWFUpload.prototype.setFileSizeLimit=function(fileSizeLimit){this.settings.file_size_limit=fileSizeLimit;this.callFlash("SetFileSizeLimit",false,[fileSizeLimit]);};SWFUpload.prototype.setFileUploadLimit=function(fileUploadLimit){this.settings.file_upload_limit=fileUploadLimit;this.callFlash("SetFileUploadLimit",false,[fileUploadLimit]);};SWFUpload.prototype.setFileQueueLimit=function(fileQueueLimit){this.settings.file_queue_limit=fileQueueLimit;this.callFlash("SetFileQueueLimit",false,[fileQueueLimit]);};SWFUpload.prototype.setFilePostName=function(filePostName){this.settings.file_post_name=filePostName;this.callFlash("SetFilePostName",false,[filePostName]);};SWFUpload.prototype.setUseQueryString=function(useQueryString){this.settings.use_query_string=useQueryString;this.callFlash("SetUseQueryString",false,[useQueryString]);};SWFUpload.prototype.setRequeueOnError=function(requeueOnError){this.settings.requeue_on_error=requeueOnError;this.callFlash("SetRequeueOnError",false,[requeueOnError]);};SWFUpload.prototype.setDebugEnabled=function(debugEnabled){this.settings.debug_enabled=debugEnabled;this.callFlash("SetDebugEnabled",false,[debugEnabled]);};SWFUpload.prototype.queueEvent=function(handlerName,argumentArray){if(argumentArray==undefined){argumentArray=[];}else if(!(argumentArray instanceof Array)){argumentArray=[argumentArray];}
|
||||
var self=this;if(typeof(this.settings[handlerName])==="function"){this.eventQueue.push(function(){this.settings[handlerName].apply(this,argumentArray);});setTimeout(function(){self.executeNextEvent();},0);}else if(this.settings[handlerName]!==null){throw "Event handler "+handlerName+" is unknown or is not a function";}
|
||||
};SWFUpload.prototype.executeNextEvent=function(){var f=this.eventQueue.shift();f.apply(this);};SWFUpload.prototype.unescapeFilePostParams=function(file){var reg=/[$]([0-9a-f]{4})/i;var unescapedPost={};var uk;for(var k in file.post){if(file.post.hasOwnProperty(k)){uk=k;var match;while((match=reg.exec(uk))!==null){uk=uk.replace(match[0],String.fromCharCode(parseInt("0x"+match[1],16)));}
|
||||
unescapedPost[uk]=file.post[k];}
|
||||
}
|
||||
file.post=unescapedPost;return file;};SWFUpload.prototype.flashReady=function(){var movieElement=this.getMovieElement();if(typeof(movieElement.StartUpload)!=="function"){throw "ExternalInterface methods failed to initialize.";}
|
||||
this.queueEvent("swfupload_loaded_handler");};SWFUpload.prototype.fileDialogStart=function(){this.queueEvent("file_dialog_start_handler");};SWFUpload.prototype.fileQueued=function(file){file=this.unescapeFilePostParams(file);this.queueEvent("file_queued_handler",file);};SWFUpload.prototype.fileQueueError=function(file,errorCode,message){file=this.unescapeFilePostParams(file);this.queueEvent("file_queue_error_handler",[file,errorCode,message]);};SWFUpload.prototype.fileDialogComplete=function(numFilesSelected,numFilesQueued){this.queueEvent("file_dialog_complete_handler",[numFilesSelected,numFilesQueued]);};SWFUpload.prototype.uploadStart=function(file){file=this.unescapeFilePostParams(file);this.queueEvent("return_upload_start_handler",file);};SWFUpload.prototype.returnUploadStart=function(file){var returnValue;if(typeof(this.settings.upload_start_handler)==="function"){file=this.unescapeFilePostParams(file);returnValue=this.settings.upload_start_handler.call(this,file);}else if(this.settings.upload_start_handler!=undefined){throw "upload_start_handler must be a function";}
|
||||
if(returnValue===undefined){returnValue=true;}
|
||||
returnValue=!!returnValue;this.callFlash("ReturnUploadStart",false,[returnValue]);};SWFUpload.prototype.uploadProgress=function(file,bytesComplete,bytesTotal){file=this.unescapeFilePostParams(file);this.queueEvent("upload_progress_handler",[file,bytesComplete,bytesTotal]);};SWFUpload.prototype.uploadError=function(file,errorCode,message){file=this.unescapeFilePostParams(file);this.queueEvent("upload_error_handler",[file,errorCode,message]);};SWFUpload.prototype.uploadSuccess=function(file,serverData){file=this.unescapeFilePostParams(file);this.queueEvent("upload_success_handler",[file,serverData]);};SWFUpload.prototype.uploadComplete=function(file){file=this.unescapeFilePostParams(file);this.queueEvent("upload_complete_handler",file);};SWFUpload.prototype.debug=function(message){this.queueEvent("debug_handler",message);};SWFUpload.prototype.debugMessage=function(message){if(this.settings.debug){var exceptionMessage,exceptionValues=[];if(typeof(message)==="object"&&typeof(message.name)==="string"&&typeof(message.message)==="string"){for(var key in message){if(message.hasOwnProperty(key)){exceptionValues.push(key+": "+message[key]);}
|
||||
}
|
||||
exceptionMessage=exceptionValues.join("\n")||"";exceptionValues=exceptionMessage.split("\n");exceptionMessage="EXCEPTION: "+exceptionValues.join("\nEXCEPTION: ");SWFUpload.Console.writeLine(exceptionMessage);}else{SWFUpload.Console.writeLine(message);}
|
||||
}
|
||||
};SWFUpload.Console={};SWFUpload.Console.writeLine=function(message){var console,documentForm;try{console=document.getElementById("SWFUpload_Console");if(!console){documentForm=document.createElement("form");document.getElementsByTagName("body")[0].appendChild(documentForm);console=document.createElement("textarea");console.id="SWFUpload_Console";console.style.fontFamily="monospace";console.setAttribute("wrap","off");console.wrap="off";console.style.overflow="auto";console.style.width="700px";console.style.height="350px";console.style.margin="5px";documentForm.appendChild(console);}
|
||||
console.value+=message+"\n";console.scrollTop=console.scrollHeight-console.clientHeight;}catch(ex){alert("Exception: "+ex.name+" Message: "+ex.message);}
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
|
||||
xajax.ext.SWFupload.swf=null;xajax.ext.SWFupload.forms={};xajax.ext.SWFupload.fields={};xajax.ext.SWFupload.queues={};xajax.ext.SWFupload.tools={};xajax.ext.SWFupload.settings={flash_url:xajax.ext.SWFupload.config.javascript_URI+"swfupload_f9.swf",
|
||||
file_size_limit:"0",
|
||||
file_types:"*.*",
|
||||
file_types_description:"All Files",
|
||||
file_upload_limit:0,
|
||||
file_queue_limit:0,
|
||||
debug:false,
|
||||
post_params:{'test':'x'}
|
||||
}
|
||||
if('undefined'==typeof xajax.ext.SWFupload.lang){xajax.ext.SWFupload.lang={};xajax.ext.SWFupload.lang.browseFiles='Browse Files';xajax.ext.SWFupload.lang.browseFile='Browse File';}
|
||||
xajax.ext.SWFupload.configure=function(config){if("object"==typeof config)return xajax.ext.SWFupload.tools.mergeObj(this.settings,config);return this.settings;}
|
||||
xajax.ext.SWFupload.addQueue=function(child,parent,config,multiple){var id=xajax.ext.SWFupload.tools.getId();this.queues[id]=new xajax.ext.SWFupload.tools.fileQueue(id,child,parent,config,multiple);return id;}
|
||||
xajax.ext.SWFupload.applyConfig=function(oQueue){var conf=oQueue.getConfig();var swf=xajax.ext.SWFupload.getInstance();if('undefined'!=typeof conf.file_types)
|
||||
swf.setFileTypes(conf.file_types,conf.file_types_description);if('undefined'!=typeof conf.file_size_limit)
|
||||
swf.setFileSizeLimit(conf.file_size_limit);if('object'==typeof conf.post_params){for(a in conf.post_params)
|
||||
swf.addPostParam(a,conf.post_params[a]);}
|
||||
swf.settings.file_queued_handler=function(oFile){oQueue.addFile(oFile)};;}
|
||||
xajax.ext.SWFupload.selectFile=function(oQueue){this.applyConfig(oQueue);if(oQueue.getConfig().file_queue_limit > 0&&oQueue.getConfig().file_queue_limit <=oQueue.queued)return;xajax.ext.SWFupload.getInstance().selectFile();}
|
||||
xajax.ext.SWFupload.selectFiles=function(oQueue){this.applyConfig(oQueue);if(oQueue.getConfig().file_queue_limit > 0&&oQueue.getConfig().file_queue_limit <=oQueue.queued)return;xajax.ext.SWFupload.getInstance().selectFiles();}
|
||||
xajax.ext.SWFupload.getInstance=function(){if(null==this.swf)this.swf=new SWFUpload(this.settings);return this.swf;}
|
||||
xajax.ext.SWFupload.removeFile=function(QueueId,FileId,finished){this.queues[QueueId].removeFile(FileId,finished);}
|
||||
xajax.ext.SWFupload.request={};xajax.ext.SWFupload.request.getFileFromQueue=function(oRequest){var instances={};var queued=0;if("string"==typeof oRequest.SWFform){if('object'!=typeof xajax.ext.SWFupload.forms[oRequest.SWFform]){return false;}
|
||||
for(a in xajax.ext.SWFupload.forms[oRequest.SWFform]){var field=xajax.ext.SWFupload.forms[oRequest.SWFform][a];if(0 < xajax.ext.SWFupload.queues[field].queued){oRequest.currentFile=xajax.ext.SWFupload.queues[field].getFile();return true};}
|
||||
}else if("string"==typeof oRequest.SWFfield){if('string'!=typeof xajax.ext.SWFupload.fields[oRequest.SWFfield]){return false;}
|
||||
var qId=xajax.ext.SWFupload.fields[oRequest.SWFfield];if(0 < xajax.ext.SWFupload.queues[qId].queued){oRequest.currentFile=xajax.ext.SWFupload.queues[qId].getFile();return true};}else{for(a in xajax.ext.SWFupload.queues){if(0 < xajax.ext.SWFupload.queues[a].queued){oRequest.currentFile=xajax.ext.SWFupload.queues[a].getFile();return true};}
|
||||
}
|
||||
return false;}
|
||||
xajax.ext.SWFupload.request.processParameters=function(oRequest){if("SWFupload"==oRequest.mode){oRequest.currentFile=false;xajax.ext.SWFupload.request.getFileFromQueue(oRequest);if(oRequest.currentFile)oRequest.method='GET';}
|
||||
return xajax.ext.SWFupload.bak.processParameters(oRequest);}
|
||||
xajax.ext.SWFupload.request.prepareRequest=function(oRequest){if("SWFupload"==oRequest.mode&&false!=oRequest.currentFile)return;return xajax.ext.SWFupload.bak.prepareRequest(oRequest);}
|
||||
xajax.ext.SWFupload.request.submitRequest=function(oRequest){if("SWFupload"==oRequest.mode&&false!=oRequest.currentFile){var swf=xajax.ext.SWFupload.getInstance();var fileQueue=xajax.ext.SWFupload.queues[oRequest.currentFile.QueueId];xajax.ext.SWFupload.applyConfig(fileQueue);swf.customSettings.currentFile=oRequest.currentFile;swf.setFilePostName(swf.customSettings.currentFile.name);swf.customSettings.oRequest=oRequest;swf.setUploadURL(oRequest.requestURI);swf.settings.upload_success_handler=function(oFile,response){var FileId=swf.customSettings.currentFile;if('function'==typeof this.old_upload_success_handler)this.old_upload_success_handler(oFile);var xx=xajax;var xt=xx.tools;var xcb=xx.callback;var gcb=xcb.global;var lcb=oRequest.callback;var oRet=oRequest.returnValue;if(response){var cmd=(new DOMParser()).parseFromString(response,"text/xml");var seq=0;var child=cmd.documentElement.firstChild;xt.xml.processFragment(child,seq,oRequest);if(null==xx.response.timeout)
|
||||
xt.queue.process(xx.response);}
|
||||
}
|
||||
swf.settings.upload_complete_handler=function(oFile){var qFile=this.customSettings.currentFile;xajax.ext.SWFupload.removeFile(qFile.QueueId,qFile.id,true);if(!xajax.ext.SWFupload.request.getFileFromQueue(oRequest)){if('function'==typeof oRequest.onUploadComplete)oRequest.onUploadComplete();return;}
|
||||
swf.customSettings.currentFile=oRequest.currentFile;swf.setFilePostName(oRequest.currentFile.name);this.startUpload(oRequest.currentFile.id);}
|
||||
swf.settings.upload_start_handler=function(oFile){if('function'==typeof this.old_upload_start_handler)this.old_upload_start_handler(oFile);oRequest.startTime=new Date();}
|
||||
swf.settings.upload_progress_handler=function(oFile,bytesLoaded,bytesTotal){upload={};upload.received=bytesLoaded;upload.total=bytesTotal;upload.state="uploading";var reqTime=new Date();upload.lastbytes=oRequest.lastbytes;upload.now=reqTime.getTime()/1000;upload.start=oRequest.startTime.getTime()/1000;var step=upload.received/(upload.total/100);var progressbar=xajax.$('SWFup_progress_'+oFile.id);var w=Math.round(220*step/100);progressbar.style.width=w+'px';var progress=xajax.$("swf_queued_filesize_"+oFile.id);var elapsed=upload.now-upload.start;var rate=xajax.ext.SWFupload.tools.formatBytes(upload.received/elapsed).toString()+'/s';progress.innerHTML="<i>"+rate+"</i> "+xajax.ext.SWFupload.tools.formatBytes(upload.received)+"/"+xajax.ext.SWFupload.tools.formatBytes(upload.total);oRequest.lastbytes=upload.received;}
|
||||
swf.settings.upload_error_handler=function(file,errorCode,message){alert("Error Code: "+errorCode+", File name: "+file.name+", Message: "+message);};swf.startUpload(swf.customSettings.currentFile.id);return;}
|
||||
return xajax.ext.SWFupload.bak.submitRequest(oRequest);}
|
||||
xajax.ext.SWFupload.tools.queueFile=function(oFile,name,QueueId,QueueContainer){this.id=oFile.id;this.name=name;this.QueueId=QueueId;var container=document.createElement('div');container.id="SWFup_"+this.id;container.className="swf_queued_file";this.elm=container;var remove=document.createElement('div');remove.className="swf_queued_file_remove";remove.innerHTML=" ";var id=this.id;var QueueId=this.QueueId;remove.onclick=function(){xajax.ext.SWFupload.getInstance().cancelUpload(id);xajax.ext.SWFupload.removeFile(QueueId,id);}
|
||||
container.appendChild(remove);var label=document.createElement('div');label.className="swf_queued_filename";label.innerHTML=oFile.name;container.appendChild(label);var progress_container=document.createElement('div');progress_container.className="swf_queued_file_progress_container";container.appendChild(progress_container);var progress=document.createElement('div');progress.className="swf_queued_file_progress_bar";progress.style.width='1px';progress.id='SWFup_progress_'+oFile.id;progress_container.appendChild(progress);var fSize=document.createElement('div');fSize.className="swf_queued_filesize";fSize.id="swf_queued_filesize_"+this.id;fSize.innerHTML=xajax.ext.SWFupload.tools.formatBytes(oFile.size);container.appendChild(fSize);var fClear=document.createElement('div');fClear.style.clear='both';container.appendChild(fClear);QueueContainer.appendChild(container);this.container=container;this.oFile=oFile;this.destroy=function(){QueueContainer.removeChild(container);}
|
||||
return;}
|
||||
xajax.ext.SWFupload.tools.fileQueue=function(id,child,parent,config,multiple){var swf=xajax.ext.SWFupload.getInstance();this.id=id;var config='object'==typeof config ? xajax.ext.SWFupload.tools.mergeObj(xajax.ext.SWFupload.settings,config):xajax.ext.SWFupload.settings;this.queued=0;this.files={};this.queue=null;this.getConfig=function(){return config;}
|
||||
xajax.forms.insertInput({id:child,
|
||||
type:"button",
|
||||
prop:"SWFup_Btn_"+this.id,
|
||||
data:"SWFup_Btn_"+this.id
|
||||
});parent.removeChild(child);var BtnSelect=xajax.$("SWFup_Btn_"+this.id);BtnSelect.name=this.id;var oQueue=this;if(true===multiple){BtnSelect.value=xajax.ext.SWFupload.lang.browseFiles;BtnSelect.onclick=function(){xajax.ext.SWFupload.selectFiles(oQueue);}
|
||||
}else{BtnSelect.value=xajax.ext.SWFupload.lang.browseFile;BtnSelect.onclick=function(){xajax.ext.SWFupload.selectFile(oQueue);}
|
||||
}
|
||||
var QueueContainer=document.createElement('div');QueueContainer.id='SWFqueue_'+this.id;parent.appendChild(QueueContainer);var fieldname=child.name;this.addFile=function(oFile){this.files[oFile.id]=new xajax.ext.SWFupload.tools.queueFile(oFile,fieldname,this.id,QueueContainer);this.queued++;if(this.queued==config.file_queue_limit)BtnSelect.disabled=true;}
|
||||
this.getFile=function(FileId){if("undefined"!=typeof FileId)return this.files[FileId];for(a in this.files)return this.files[a];return false;}
|
||||
this.removeFile=function(FileId,finished){this.queued--;if(this.queued <=config.file_queue_limit)BtnSelect.disabled=false;var filediv=xajax.$("SWFup_"+this.files[FileId].id);filediv.className=true===finished ? 'swf_queued_file_finished':'swf_queued_file_removed';setTimeout(function(){xajax.ext.SWFupload.tools.FadeOut(filediv,100);},xajax.ext.SWFupload.config.FadeTimeOut);this.files[FileId]=null;delete this.files[FileId];}
|
||||
this.destroy=function(){for(a in this.files){this.files[a].destroy();delete(this.files[a]);}
|
||||
this.queued=0;}
|
||||
}
|
||||
xajax.ext.SWFupload.tools._parseFields=function(children,parent,config,multiple){var result={};var iLen=children.length;for(var i=0;i < iLen;++i){var child=children[i];if('undefined'!=typeof child.childNodes)
|
||||
var res2=xajax.ext.SWFupload.tools._parseFields(child.childNodes,child,config,multiple);result=xajax.ext.SWFupload.tools.mergeObj(result,res2);if(child.name){if('file'==child.type){result[child.name]=xajax.ext.SWFupload.addQueue(child,parent,config,multiple);}
|
||||
}
|
||||
}
|
||||
return result;}
|
||||
xajax.ext.SWFupload.tools.transForm=function(form_id,config,multiple){var oForm=xajax.$(form_id);if(oForm)
|
||||
if(oForm.childNodes){var fields=xajax.ext.SWFupload.tools._parseFields(oForm.childNodes,oForm,config,multiple);xajax.ext.SWFupload.forms[form_id]=fields;}
|
||||
return;}
|
||||
xajax.ext.SWFupload.tools.transField=function(field_id,config,multiple){try{var oField=xajax.$(field_id);if('undefined'!=typeof oField)return xajax.ext.SWFupload.fields[field_id]=xajax.ext.SWFupload.addQueue(oField,oField.parentNode,config,multiple);}catch(ex){}
|
||||
return;}
|
||||
xajax.ext.SWFupload.tools.destroyForm=function(form_id){if("undefined"==typeof xajax.ext.SWFupload.forms[form_id])return;for(a in xajax.ext.SWFupload.forms[form_id]){var key=xajax.ext.SWFupload.forms[form_id][a];xajax.ext.SWFupload.queues[key].destroy();delete xajax.ext.SWFupload.queues[key];delete xajax.ext.SWFupload.forms[form_id];}
|
||||
return;}
|
||||
xajax.ext.SWFupload.tools.destroyField=function(field_id){if("undefined"==typeof xajax.ext.SWFupload.fields[field_id])return;var key=xajax.ext.SWFupload.fields[field_id];xajax.ext.SWFupload.queues[key].destroy();delete(xajax.ext.SWFupload.queues[key]);delete xajax.ext.SWFupload.fields[field_id];return true;}
|
||||
xajax.ext.SWFupload.tools.FadeOut=function(elm,opacity){var reduceOpacityBy=15;var rate=40;if(opacity > 0){opacity-=reduceOpacityBy;if(opacity < 0){opacity=0;}
|
||||
if(elm.filters){try{elm.filters.item("DXImageTransform.Microsoft.Alpha").opacity=opacity;}catch(e){elm.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+opacity+")";}
|
||||
}else{elm.style.opacity=opacity/100;}
|
||||
}
|
||||
if(opacity > 0){var oSelf=this;setTimeout(function(){xajax.ext.SWFupload.tools.FadeOut(elm,opacity);},rate);}else{var parent=elm.parentNode;parent.removeChild(elm);}
|
||||
}
|
||||
xajax.ext.SWFupload.tools.formatBytes=function(bytes){var ret={};if(bytes/1204 < 1024){return(Math.round(bytes/1024*100)/100).toString()+" kB";}else{return(Math.round(bytes/1024/1024*100)/100).toString()+" MB";}
|
||||
return ret;}
|
||||
xajax.ext.SWFupload.tools.mergeObj=function(){if('object'!=typeof arguments)return;var res={};var len=arguments.length;for(var i=0;i<len;i++){var obj=arguments[i];for(a in obj){res[a]=obj[a];}
|
||||
}
|
||||
return res;}
|
||||
xajax.ext.SWFupload.tools.getId=function(){var pid_str="";for(i=0;i<=3;i++){var pid=0;pid=Math.random();while(Math.ceil(pid).toString().length<8){pid*=10;}
|
||||
pid=Math.ceil(pid).toString();pid_str=pid_str+pid.toString();}
|
||||
return pid_str;}
|
||||
xajax.command.handler.register('SWFup_dfi',function(args){args.cmdFullName='ext.SWFupload.tools.destroyField';xajax.ext.SWFupload.tools.destroyField(args.id);return true;});xajax.command.handler.register('SWFup_dfo',function(args){args.cmdFullName='ext.SWFupload.tools.destroyForm';xajax.ext.SWFupload.tools.destroyForm(args.id);return true;});xajax.command.handler.register('SWFup_tfi',function(args){args.cmdFullName='ext.SWFupload.tools.transField';if("string"==typeof args.data.config.upload_success_handler){try{eval("var foo = "+args.data.config.upload_success_handler);args.data.config.upload_success_handler=foo;}catch(ex){delete(args.data.config.upload_success_handler);}
|
||||
}
|
||||
xajax.ext.SWFupload.tools.transField(args.id,args.data.config,args.data.multi);return true;});xajax.command.handler.register('SWFup_tfo',function(args){try{args.cmdFullName='ext.SWFupload.tools.transForm';if("string"==typeof args.data.config.upload_success_handler){try{eval("var foo = "+args.data.config.upload_success_handler);args.data.config.upload_success_handler=foo;}catch(ex){delete(args.data.config.upload_success_handler);}
|
||||
}
|
||||
xajax.ext.SWFupload.tools.transForm(args.id,args.data.config,args.data.multi);}catch(ex){}
|
||||
return true;});xajax.ext.SWFupload.bak={};xajax.ext.SWFupload.bak.prepareRequest=xajax.prepareRequest;xajax.ext.SWFupload.bak.submitRequest=xajax.submitRequest;xajax.ext.SWFupload.bak.responseProcessor=xajax.responseProcessor;xajax.ext.SWFupload.bak.processParameters=xajax.processParameters;xajax.prepareRequest=xajax.ext.SWFupload.request.prepareRequest;xajax.submitRequest=xajax.ext.SWFupload.request.submitRequest;xajax.processParameters=xajax.ext.SWFupload.request.processParameters;if(typeof DOMParser=="undefined"){DOMParser=function(){}
|
||||
DOMParser.prototype.parseFromString=function(str,contentType){if(typeof ActiveXObject!="undefined"){var d=new ActiveXObject("Microsoft.XMLDOM");d.loadXML(str);return d;}else if(typeof XMLHttpRequest!="undefined"){var req=new XMLHttpRequest;req.open("GET","data:"+(contentType||"application/xml")+
|
||||
";charset=utf-8,"+encodeURIComponent(str),false);if(req.overrideMimeType){req.overrideMimeType(contentType);}
|
||||
req.send(null);return req.responseXML;}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,879 @@
|
||||
|
||||
//xjxSWFup = xajax.ext.SWFupload;
|
||||
|
||||
xajax.ext.SWFupload.swf = null;
|
||||
|
||||
xajax.ext.SWFupload.forms = {};
|
||||
xajax.ext.SWFupload.fields = {};
|
||||
xajax.ext.SWFupload.queues = {};
|
||||
xajax.ext.SWFupload.tools = {};
|
||||
|
||||
/* default upload settings */
|
||||
xajax.ext.SWFupload.settings = {
|
||||
flash_url : xajax.ext.SWFupload.config.javascript_URI+"swfupload_f9.swf",
|
||||
file_size_limit : "0",
|
||||
file_types : "*.*",
|
||||
file_types_description : "All Files",
|
||||
file_upload_limit : 0,
|
||||
file_queue_limit : 0,
|
||||
debug: false,
|
||||
post_params:{'test' : 'x'}
|
||||
}
|
||||
|
||||
if ('undefined' == typeof xajax.ext.SWFupload.lang)
|
||||
{
|
||||
xajax.ext.SWFupload.lang = {};
|
||||
xajax.ext.SWFupload.lang.browseFiles = 'Browse Files';
|
||||
xajax.ext.SWFupload.lang.browseFile = 'Browse File';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.init
|
||||
arguments: config [object]
|
||||
|
||||
Creates the SWFupload instance
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.configure = function (config)
|
||||
{
|
||||
if ("object" == typeof config) return xajax.ext.SWFupload.tools.mergeObj(this.settings,config);
|
||||
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.addQueue
|
||||
arguments: child [object], parent [object], config [objeect ,multiple [bool]
|
||||
|
||||
Creates a new a new file queue and stores the reference in this.queues
|
||||
*/
|
||||
xajax.ext.SWFupload.addQueue = function (child,parent,config,multiple)
|
||||
{
|
||||
var id = xajax.ext.SWFupload.tools.getId();
|
||||
this.queues[id] = new xajax.ext.SWFupload.tools.fileQueue(id,child,parent,config,multiple);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.applyConfig
|
||||
arguments: oQueue [object]
|
||||
|
||||
Applies the queue's config on the SWFupload instance
|
||||
*/
|
||||
xajax.ext.SWFupload.applyConfig = function(oQueue)
|
||||
{
|
||||
|
||||
var conf = oQueue.getConfig();
|
||||
var swf = xajax.ext.SWFupload.getInstance();
|
||||
|
||||
if ( 'undefined' != typeof conf.file_types )
|
||||
swf.setFileTypes(conf.file_types, conf.file_types_description);
|
||||
|
||||
if ( 'undefined' != typeof conf.file_size_limit )
|
||||
swf.setFileSizeLimit(conf.file_size_limit);
|
||||
|
||||
if ( 'object' == typeof conf.post_params)
|
||||
{
|
||||
for (a in conf.post_params)
|
||||
swf.addPostParam(a,conf.post_params[a]);
|
||||
}
|
||||
|
||||
swf.settings.file_queued_handler = function(oFile) {oQueue.addFile(oFile)};;
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.selectFile
|
||||
arguments: oQueue [object]
|
||||
|
||||
Onclick handler for selecting file
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.selectFile = function(oQueue)
|
||||
{
|
||||
this.applyConfig(oQueue);
|
||||
|
||||
if (oQueue.getConfig().file_queue_limit > 0 && oQueue.getConfig().file_queue_limit <= oQueue.queued) return;
|
||||
|
||||
xajax.ext.SWFupload.getInstance().selectFile();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.selectFiles
|
||||
arguments: oQueue [object]
|
||||
|
||||
Onclick handler for selecting files
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.selectFiles = function(oQueue)
|
||||
{
|
||||
this.applyConfig(oQueue);
|
||||
if (oQueue.getConfig().file_queue_limit > 0 && oQueue.getConfig().file_queue_limit <= oQueue.queued) return;
|
||||
xajax.ext.SWFupload.getInstance().selectFiles();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.getInstance
|
||||
arguments:
|
||||
|
||||
Return the SWFupload instace. If there's no instance available it creates a new one with default settings.
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.getInstance = function()
|
||||
{
|
||||
if (null == this.swf) this.swf = new SWFUpload(this.settings);
|
||||
|
||||
return this.swf;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.removeFile
|
||||
arguments: QueueId [integer] , FileId [integer]
|
||||
|
||||
Removes the file (FileID) from queue (QueueId)
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.removeFile = function(QueueId,FileId,finished)
|
||||
{
|
||||
this.queues[QueueId].removeFile(FileId,finished);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
xajax.ext.SWFupload.request = {};
|
||||
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.request.getFileFromQueue
|
||||
arguments: oRequest [object]
|
||||
|
||||
Returns the first file from first available queue.
|
||||
Returns false if no files were selected
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.request.getFileFromQueue = function(oRequest)
|
||||
{
|
||||
|
||||
var instances = {};
|
||||
var queued = 0;
|
||||
if ("string" == typeof oRequest.SWFform)
|
||||
{
|
||||
if ('object' != typeof xajax.ext.SWFupload.forms[oRequest.SWFform])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (a in xajax.ext.SWFupload.forms[oRequest.SWFform])
|
||||
{
|
||||
var field = xajax.ext.SWFupload.forms[oRequest.SWFform][a];
|
||||
if (0 < xajax.ext.SWFupload.queues[field].queued) { oRequest.currentFile = xajax.ext.SWFupload.queues[field].getFile();return true };
|
||||
}
|
||||
} else if ("string" == typeof oRequest.SWFfield)
|
||||
{
|
||||
if ('string' != typeof xajax.ext.SWFupload.fields[oRequest.SWFfield])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var qId = xajax.ext.SWFupload.fields[oRequest.SWFfield];
|
||||
if (0 < xajax.ext.SWFupload.queues[qId].queued) { oRequest.currentFile = xajax.ext.SWFupload.queues[qId].getFile();return true };
|
||||
} else
|
||||
{
|
||||
for (a in xajax.ext.SWFupload.queues)
|
||||
{
|
||||
if (0 < xajax.ext.SWFupload.queues[a].queued) { oRequest.currentFile = xajax.ext.SWFupload.queues[a].getFile();return true };
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.request. xajax.ext.SWFupload.request.processParameters = function(oRequest)
|
||||
|
||||
arguments: oRequest [object]
|
||||
|
||||
Processes the parameters
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.request.processParameters = function(oRequest)
|
||||
{
|
||||
if ("SWFupload" == oRequest.mode)
|
||||
{
|
||||
oRequest.currentFile = false;
|
||||
xajax.ext.SWFupload.request.getFileFromQueue(oRequest);
|
||||
if (oRequest.currentFile) oRequest.method='GET';
|
||||
}
|
||||
return xajax.ext.SWFupload.bak.processParameters(oRequest);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.request. xajax.ext.SWFupload.request.prepareRequest = function(oRequest)
|
||||
|
||||
arguments: oRequest [object]
|
||||
|
||||
doesn't to anything at all when a file for upload is selected
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.request.prepareRequest = function (oRequest)
|
||||
{
|
||||
if ("SWFupload" == oRequest.mode && false != oRequest.currentFile) return;
|
||||
return xajax.ext.SWFupload.bak.prepareRequest(oRequest);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.request. xajax.ext.SWFupload.request.submitRequest = function(oRequest)
|
||||
|
||||
arguments: oRequest [object]
|
||||
|
||||
Submits the request either via SWFupload or XHR
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.request.submitRequest = function(oRequest)
|
||||
{
|
||||
if ( "SWFupload" == oRequest.mode && false != oRequest.currentFile )
|
||||
{
|
||||
|
||||
var swf = xajax.ext.SWFupload.getInstance();
|
||||
|
||||
var fileQueue = xajax.ext.SWFupload.queues[oRequest.currentFile.QueueId];
|
||||
xajax.ext.SWFupload.applyConfig(fileQueue);
|
||||
|
||||
swf.customSettings.currentFile = oRequest.currentFile;
|
||||
swf.setFilePostName(swf.customSettings.currentFile.name);
|
||||
|
||||
swf.customSettings.oRequest = oRequest;
|
||||
swf.setUploadURL(oRequest.requestURI);
|
||||
|
||||
swf.settings.upload_success_handler = function ( oFile, response )
|
||||
{
|
||||
var FileId = swf.customSettings.currentFile;
|
||||
if ( 'function' == typeof this.old_upload_success_handler ) this.old_upload_success_handler( oFile );
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
if (response) {
|
||||
var cmd = (new DOMParser()).parseFromString(response, "text/xml");
|
||||
var seq=0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq,oRequest);
|
||||
|
||||
if (null == xx.response.timeout)
|
||||
xt.queue.process(xx.response);
|
||||
}
|
||||
}
|
||||
|
||||
swf.settings.upload_complete_handler = function(oFile)
|
||||
{
|
||||
//if ('function' == typeof this.old_upload_complete_handler) this.old_upload_complete_handler(oFile);
|
||||
|
||||
var qFile = this.customSettings.currentFile;
|
||||
xajax.ext.SWFupload.removeFile(qFile.QueueId,qFile.id,true);
|
||||
|
||||
if ( !xajax.ext.SWFupload.request.getFileFromQueue(oRequest) )
|
||||
{
|
||||
if ('function' == typeof oRequest.onUploadComplete) oRequest.onUploadComplete();
|
||||
return;
|
||||
}
|
||||
swf.customSettings.currentFile = oRequest.currentFile;
|
||||
swf.setFilePostName(oRequest.currentFile.name);
|
||||
|
||||
this.startUpload(oRequest.currentFile.id);
|
||||
}
|
||||
|
||||
|
||||
swf.settings.upload_start_handler = function(oFile)
|
||||
{
|
||||
if ('function' == typeof this.old_upload_start_handler) this.old_upload_start_handler(oFile);
|
||||
oRequest.startTime = new Date();
|
||||
|
||||
}
|
||||
swf.settings.upload_progress_handler = function (oFile, bytesLoaded, bytesTotal)
|
||||
{
|
||||
|
||||
upload = {};
|
||||
upload.received=bytesLoaded;
|
||||
upload.total=bytesTotal;
|
||||
upload.state="uploading";
|
||||
var reqTime = new Date();
|
||||
|
||||
upload.lastbytes = oRequest.lastbytes;
|
||||
upload.now = reqTime.getTime() / 1000;
|
||||
upload.start = oRequest.startTime.getTime()/ 1000;
|
||||
|
||||
var step = upload.received / (upload.total / 100);
|
||||
var progressbar = xajax.$('SWFup_progress_'+oFile.id);
|
||||
var w = Math.round(220 * step / 100);
|
||||
progressbar.style.width=w+'px';
|
||||
|
||||
var progress = xajax.$("swf_queued_filesize_"+oFile.id);
|
||||
var elapsed = upload.now-upload.start;
|
||||
var rate = xajax.ext.SWFupload.tools.formatBytes(upload.received/ elapsed).toString() + '/s';
|
||||
progress.innerHTML = "<i>"+rate + "</i> "+xajax.ext.SWFupload.tools.formatBytes(upload.received)+"/"+xajax.ext.SWFupload.tools.formatBytes(upload.total);
|
||||
oRequest.lastbytes = upload.received;
|
||||
|
||||
}
|
||||
|
||||
swf.settings.upload_error_handler = function(file, errorCode, message)
|
||||
{
|
||||
alert("Error Code: "+errorCode+", File name: " + file.name + ", Message: " + message);
|
||||
};
|
||||
swf.startUpload(swf.customSettings.currentFile.id);
|
||||
return;
|
||||
}
|
||||
return xajax.ext.SWFupload.bak.submitRequest(oRequest);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.queueFile
|
||||
arguments: oFile,QueueId,QueueContainer
|
||||
|
||||
*/
|
||||
xajax.ext.SWFupload.tools.queueFile = function(oFile,name,QueueId,QueueContainer) {
|
||||
|
||||
this.id = oFile.id;
|
||||
this.name = name;
|
||||
this.QueueId = QueueId;
|
||||
|
||||
var container = document.createElement('div');
|
||||
container.id = "SWFup_"+this.id;
|
||||
container.className="swf_queued_file";
|
||||
|
||||
this.elm = container;
|
||||
|
||||
var remove = document.createElement('div');
|
||||
remove.className="swf_queued_file_remove";
|
||||
remove.innerHTML=" ";
|
||||
|
||||
var id = this.id;
|
||||
var QueueId = this.QueueId;
|
||||
remove.onclick= function () {
|
||||
xajax.ext.SWFupload.getInstance().cancelUpload(id);
|
||||
xajax.ext.SWFupload.removeFile(QueueId,id);
|
||||
}
|
||||
container.appendChild(remove);
|
||||
|
||||
var label = document.createElement('div');
|
||||
label.className="swf_queued_filename";
|
||||
label.innerHTML = oFile.name;
|
||||
container.appendChild(label);
|
||||
|
||||
var progress_container = document.createElement('div');
|
||||
progress_container.className="swf_queued_file_progress_container";
|
||||
container.appendChild(progress_container);
|
||||
|
||||
|
||||
var progress = document.createElement('div');
|
||||
progress.className="swf_queued_file_progress_bar";
|
||||
progress.style.width='1px';
|
||||
progress.id='SWFup_progress_'+oFile.id;
|
||||
progress_container.appendChild(progress);
|
||||
|
||||
|
||||
var fSize = document.createElement('div');
|
||||
fSize.className="swf_queued_filesize";
|
||||
fSize.id="swf_queued_filesize_"+this.id;
|
||||
fSize.innerHTML = xajax.ext.SWFupload.tools.formatBytes(oFile.size);
|
||||
container.appendChild(fSize);
|
||||
|
||||
var fClear= document.createElement('div');
|
||||
fClear.style.clear='both';
|
||||
container.appendChild(fClear);
|
||||
QueueContainer.appendChild(container);
|
||||
|
||||
this.container = container;
|
||||
this.oFile = oFile;
|
||||
|
||||
this.destroy = function()
|
||||
{
|
||||
QueueContainer.removeChild(container);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.fileQueue
|
||||
arguments: id [integer],child [object], parent [object], multiple [bool]
|
||||
|
||||
parses the form for fields
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.fileQueue = function (id,child,parent,config,multiple)
|
||||
{
|
||||
|
||||
var swf = xajax.ext.SWFupload.getInstance();
|
||||
|
||||
this.id = id;
|
||||
var config = 'object' == typeof config ? xajax.ext.SWFupload.tools.mergeObj(xajax.ext.SWFupload.settings,config) : xajax.ext.SWFupload.settings;
|
||||
this.queued = 0;
|
||||
this.files = {};
|
||||
this.queue = null;
|
||||
|
||||
this.getConfig = function() {return config;}
|
||||
|
||||
|
||||
xajax.forms.insertInput({
|
||||
id:child,
|
||||
type:"button",
|
||||
prop:"SWFup_Btn_"+this.id,
|
||||
data:"SWFup_Btn_"+this.id
|
||||
});
|
||||
parent.removeChild(child);
|
||||
var BtnSelect = xajax.$("SWFup_Btn_"+this.id);
|
||||
BtnSelect.name = this.id;
|
||||
|
||||
var oQueue = this;
|
||||
if (true === multiple)
|
||||
{
|
||||
BtnSelect.value = xajax.ext.SWFupload.lang.browseFiles;
|
||||
BtnSelect.onclick = function ()
|
||||
{
|
||||
xajax.ext.SWFupload.selectFiles(oQueue);
|
||||
}
|
||||
} else {
|
||||
BtnSelect.value = xajax.ext.SWFupload.lang.browseFile;
|
||||
BtnSelect.onclick = function ()
|
||||
{
|
||||
xajax.ext.SWFupload.selectFile(oQueue);
|
||||
}
|
||||
}
|
||||
|
||||
var QueueContainer = document.createElement('div');
|
||||
QueueContainer.id = 'SWFqueue_'+ this.id;
|
||||
parent.appendChild(QueueContainer);
|
||||
|
||||
var fieldname = child.name;
|
||||
this.addFile = function (oFile)
|
||||
{
|
||||
this.files[oFile.id] = new xajax.ext.SWFupload.tools.queueFile(oFile,fieldname,this.id,QueueContainer);
|
||||
this.queued++;
|
||||
if (this.queued == config.file_queue_limit) BtnSelect.disabled=true;
|
||||
}
|
||||
|
||||
this.getFile = function (FileId)
|
||||
{
|
||||
if ("undefined" != typeof FileId) return this.files[FileId];
|
||||
for (a in this.files) return this.files[a];
|
||||
return false;
|
||||
}
|
||||
|
||||
this.removeFile = function(FileId,finished)
|
||||
{
|
||||
this.queued--;
|
||||
if (this.queued <= config.file_queue_limit) BtnSelect.disabled=false;
|
||||
var filediv = xajax.$("SWFup_"+this.files[FileId].id);
|
||||
filediv.className = true === finished ? 'swf_queued_file_finished' : 'swf_queued_file_removed';
|
||||
setTimeout(function ()
|
||||
{
|
||||
xajax.ext.SWFupload.tools.FadeOut(filediv,100);
|
||||
}, xajax.ext.SWFupload.config.FadeTimeOut);
|
||||
|
||||
this.files[FileId] = null;
|
||||
delete this.files[FileId];
|
||||
}
|
||||
this.destroy = function() {
|
||||
for (a in this.files) {
|
||||
this.files[a].destroy();
|
||||
delete (this.files[a]);
|
||||
}
|
||||
this.queued=0;
|
||||
}
|
||||
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools._parseFields
|
||||
arguments: children [array],parent [object], config [object], multiple [bool]
|
||||
|
||||
parses the form for fields
|
||||
*/
|
||||
|
||||
|
||||
xajax.ext.SWFupload.tools._parseFields = function(children,parent,config,multiple)
|
||||
{
|
||||
var result={};
|
||||
var iLen = children.length;
|
||||
for (var i = 0; i < iLen; ++i)
|
||||
{
|
||||
var child = children[i];
|
||||
if ('undefined' != typeof child.childNodes)
|
||||
var res2 = xajax.ext.SWFupload.tools._parseFields(child.childNodes,child,config,multiple);
|
||||
result = xajax.ext.SWFupload.tools.mergeObj(result,res2);
|
||||
if (child.name)
|
||||
{
|
||||
if ('file' == child.type)
|
||||
{
|
||||
result[child.name] = xajax.ext.SWFupload.addQueue(child,parent,config,multiple);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.transForm
|
||||
arguments: form_id [integer] ,config [object] ,multiple [bool]
|
||||
|
||||
transforms the all fields of the given form into fileQueue instances
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.transForm = function(form_id,config,multiple)
|
||||
{
|
||||
var oForm = xajax.$(form_id);
|
||||
if (oForm)
|
||||
if (oForm.childNodes) {
|
||||
var fields = xajax.ext.SWFupload.tools._parseFields(oForm.childNodes,oForm,config,multiple);
|
||||
xajax.ext.SWFupload.forms[form_id] = fields;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.transField
|
||||
arguments: field_id [integer] ,config [object] ,multiple [bool]
|
||||
|
||||
transforms the given field into a fileQueue instance
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.transField = function(field_id,config,multiple)
|
||||
{
|
||||
try {
|
||||
var oField = xajax.$(field_id);
|
||||
if ('undefined' != typeof oField) return xajax.ext.SWFupload.fields[field_id] = xajax.ext.SWFupload.addQueue(oField,oField.parentNode,config,multiple);
|
||||
|
||||
}catch(ex) {}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.destroyForm
|
||||
arguments: form_id [integer]
|
||||
|
||||
destroys the given form
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.destroyForm = function(form_id)
|
||||
{
|
||||
if ("undefined" == typeof xajax.ext.SWFupload.forms[form_id]) return;
|
||||
for (a in xajax.ext.SWFupload.forms[form_id])
|
||||
{
|
||||
var key = xajax.ext.SWFupload.forms[form_id][a];
|
||||
xajax.ext.SWFupload.queues[key].destroy();
|
||||
delete xajax.ext.SWFupload.queues[key];
|
||||
delete xajax.ext.SWFupload.forms[form_id];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.destroyField
|
||||
arguments: field_id [integer]
|
||||
|
||||
destroys the given field
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.destroyField = function(field_id)
|
||||
{
|
||||
if ("undefined" == typeof xajax.ext.SWFupload.fields[field_id]) return;
|
||||
|
||||
var key = xajax.ext.SWFupload.fields[field_id];
|
||||
xajax.ext.SWFupload.queues[key].destroy();
|
||||
delete(xajax.ext.SWFupload.queues[key]);
|
||||
delete xajax.ext.SWFupload.fields[field_id];
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.FadeOut
|
||||
arguments: elm [object], opacity [integer]
|
||||
|
||||
fades a div
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.FadeOut = function(elm,opacity)
|
||||
{
|
||||
var reduceOpacityBy = 15;
|
||||
var rate = 40;
|
||||
if (opacity > 0)
|
||||
{
|
||||
opacity -= reduceOpacityBy;
|
||||
if (opacity < 0)
|
||||
{
|
||||
opacity = 0;
|
||||
}
|
||||
|
||||
if (elm.filters)
|
||||
{
|
||||
try
|
||||
{
|
||||
elm.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
|
||||
} catch (e) {
|
||||
// If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
|
||||
elm.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
|
||||
}
|
||||
} else {
|
||||
elm.style.opacity = opacity / 100;
|
||||
}
|
||||
}
|
||||
|
||||
if ( opacity > 0)
|
||||
{
|
||||
var oSelf = this;
|
||||
setTimeout(function ()
|
||||
{
|
||||
xajax.ext.SWFupload.tools.FadeOut(elm,opacity);
|
||||
}, rate);
|
||||
} else {
|
||||
var parent = elm.parentNode;
|
||||
parent.removeChild(elm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.formatBytes
|
||||
arguments: bytes [integer]
|
||||
|
||||
returns string with formatted size (kB / MB)
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.formatBytes = function(bytes)
|
||||
{
|
||||
|
||||
var ret = {};
|
||||
if (bytes / 1204 < 1024)
|
||||
{
|
||||
return (Math.round(bytes / 1024 * 100)/100).toString()+ " kB";
|
||||
} else {
|
||||
return (Math.round(bytes / 1024 / 1024 * 100)/100).toString()+ " MB";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.mergeObj
|
||||
arguments: n objects
|
||||
|
||||
Merges all objects and returns a single object.
|
||||
Newrt keys override existing keys.
|
||||
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.mergeObj = function()
|
||||
{
|
||||
if ('object' != typeof arguments) return;
|
||||
|
||||
var res = {};
|
||||
var len = arguments.length;
|
||||
for (var i=0;i<len;i++)
|
||||
{
|
||||
var obj = arguments[i];
|
||||
for (a in obj)
|
||||
{
|
||||
res[a] = obj[a];
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.ext.SWFupload.tools.getId
|
||||
arguments:
|
||||
|
||||
returns a 'unique' (rand) id
|
||||
*/
|
||||
|
||||
xajax.ext.SWFupload.tools.getId = function()
|
||||
{
|
||||
var pid_str = "";
|
||||
for (i=0;i<=3;i++) {
|
||||
var pid = 0;
|
||||
pid = Math.random();
|
||||
while( Math.ceil(pid).toString().length<8)
|
||||
{
|
||||
pid *= 10;
|
||||
}
|
||||
pid = Math.ceil(pid).toString();
|
||||
pid_str = pid_str+pid.toString();
|
||||
}
|
||||
return pid_str;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.command.handler.register('SWFup_dfi')
|
||||
arguments: object
|
||||
|
||||
xajax response command for ext.SWFupload.tools.destroyField
|
||||
*/
|
||||
xajax.command.handler.register('SWFup_dfi', function(args)
|
||||
{
|
||||
args.cmdFullName = 'ext.SWFupload.tools.destroyField';
|
||||
xajax.ext.SWFupload.tools.destroyField(args.id);
|
||||
return true;
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.command.handler.register('SWFup_dfo')
|
||||
arguments: object
|
||||
|
||||
xajax response command for ext.SWFupload.tools.destroyForm
|
||||
*/
|
||||
|
||||
xajax.command.handler.register('SWFup_dfo', function(args)
|
||||
{
|
||||
args.cmdFullName = 'ext.SWFupload.tools.destroyForm';
|
||||
xajax.ext.SWFupload.tools.destroyForm(args.id);
|
||||
return true;
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.command.handler.register('SWFup_tfi'I
|
||||
arguments: object
|
||||
|
||||
xajax response command for ext.SWFupload.tools.transField
|
||||
*/
|
||||
|
||||
xajax.command.handler.register('SWFup_tfi', function(args)
|
||||
{
|
||||
args.cmdFullName = 'ext.SWFupload.tools.transField';
|
||||
|
||||
// if ("string" == typeof args.data.config.upload_complete_handler) {
|
||||
// try {
|
||||
// eval("var foo = "+args.data.config.upload_complete_handler);
|
||||
// args.data.config.upload_complete_handler = foo;
|
||||
// } catch(ex) {delete(args.data.config.upload_complete_handler);}
|
||||
// }
|
||||
|
||||
if ("string" == typeof args.data.config.upload_success_handler) {
|
||||
try {
|
||||
eval("var foo = "+args.data.config.upload_success_handler);
|
||||
args.data.config.upload_success_handler = foo;
|
||||
} catch(ex) {delete(args.data.config.upload_success_handler);}
|
||||
}
|
||||
|
||||
xajax.ext.SWFupload.tools.transField(args.id, args.data.config,args.data.multi);
|
||||
return true;
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
function: xajax.command.handler.register('SWFup_tfo']
|
||||
arguments: object
|
||||
|
||||
xajax response command for ext.SWFupload.tools.transForm
|
||||
*/
|
||||
xajax.command.handler.register('SWFup_tfo',function(args)
|
||||
{
|
||||
try {
|
||||
args.cmdFullName = 'ext.SWFupload.tools.transForm';
|
||||
// if ("string" == typeof args.data.config.upload_complete_handler)
|
||||
// {
|
||||
// try {
|
||||
// eval("var foo = "+args.data.config.upload_complete_handler);
|
||||
// args.data.config.upload_complete_handler = foo;
|
||||
// } catch(ex) {delete(args.data.config.upload_complete_handler);}
|
||||
// }
|
||||
|
||||
if ("string" == typeof args.data.config.upload_success_handler)
|
||||
{
|
||||
try
|
||||
{
|
||||
eval("var foo = "+args.data.config.upload_success_handler);
|
||||
args.data.config.upload_success_handler = foo;
|
||||
} catch(ex)
|
||||
{
|
||||
delete(args.data.config.upload_success_handler);
|
||||
}
|
||||
}
|
||||
xajax.ext.SWFupload.tools.transForm(args.id, args.data.config,args.data.multi);
|
||||
|
||||
} catch(ex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
});
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
xajax.ext.SWFupload.bak = {};
|
||||
xajax.ext.SWFupload.bak.prepareRequest = xajax.prepareRequest;
|
||||
xajax.ext.SWFupload.bak.submitRequest = xajax.submitRequest;
|
||||
xajax.ext.SWFupload.bak.responseProcessor = xajax.responseProcessor;
|
||||
xajax.ext.SWFupload.bak.processParameters = xajax.processParameters;
|
||||
|
||||
xajax.prepareRequest = xajax.ext.SWFupload.request.prepareRequest;
|
||||
xajax.submitRequest = xajax.ext.SWFupload.request.submitRequest;
|
||||
xajax.processParameters = xajax.ext.SWFupload.request.processParameters;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
Function: DOMParser
|
||||
|
||||
Prototype DomParser for IE/Opera
|
||||
|
||||
*/
|
||||
if (typeof DOMParser == "undefined") {
|
||||
DOMParser = function () {}
|
||||
|
||||
DOMParser.prototype.parseFromString = function (str, contentType) {
|
||||
if (typeof ActiveXObject != "undefined") {
|
||||
var d = new ActiveXObject("Microsoft.XMLDOM");
|
||||
d.loadXML(str);
|
||||
return d;
|
||||
} else if (typeof XMLHttpRequest != "undefined") {
|
||||
var req = new XMLHttpRequest;
|
||||
req.open("GET", "data:" + (contentType || "application/xml") +
|
||||
";charset=utf-8," + encodeURIComponent(str), false);
|
||||
if (req.overrideMimeType) {
|
||||
req.overrideMimeType(contentType);
|
||||
}
|
||||
req.send(null);
|
||||
return req.responseXML;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
libraries/xajax/xajax_plugins/request/swfupload/swfupload_f9.swf
Normal file
BIN
libraries/xajax/xajax_plugins/request/swfupload/swfupload_f9.swf
Normal file
Binary file not shown.
@@ -0,0 +1,725 @@
|
||||
/**
|
||||
* SWFUpload v2.1.0 by Jacob Roberts, Feb 2008, http://www.swfupload.org, http://swfupload.googlecode.com, http://www.swfupload.org
|
||||
* -------- -------- -------- -------- -------- -------- -------- --------
|
||||
* SWFUpload is (c) 2006 Lars Huring, Olov Nilz<6C>n and Mammon Media and is released under the MIT License:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* See Changelog.txt for version history
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* *********** */
|
||||
/* Constructor */
|
||||
/* *********** */
|
||||
|
||||
var SWFUpload = function (settings) {
|
||||
this.initSWFUpload(settings);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.initSWFUpload = function (settings) {
|
||||
try {
|
||||
this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
|
||||
this.settings = settings;
|
||||
this.eventQueue = [];
|
||||
this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
|
||||
this.movieElement = null;
|
||||
|
||||
// Setup global control tracking
|
||||
SWFUpload.instances[this.movieName] = this;
|
||||
|
||||
// Load the settings. Load the Flash movie.
|
||||
this.initSettings();
|
||||
this.loadFlash();
|
||||
this.displayDebugInfo();
|
||||
} catch (ex) {
|
||||
delete SWFUpload.instances[this.movieName];
|
||||
throw ex;
|
||||
}
|
||||
};
|
||||
|
||||
/* *************** */
|
||||
/* Static Members */
|
||||
/* *************** */
|
||||
SWFUpload.instances = {};
|
||||
SWFUpload.movieCount = 0;
|
||||
SWFUpload.version = "2.1.0 beta 1";
|
||||
SWFUpload.QUEUE_ERROR = {
|
||||
QUEUE_LIMIT_EXCEEDED : -100,
|
||||
FILE_EXCEEDS_SIZE_LIMIT : -110,
|
||||
ZERO_BYTE_FILE : -120,
|
||||
INVALID_FILETYPE : -130
|
||||
};
|
||||
SWFUpload.UPLOAD_ERROR = {
|
||||
HTTP_ERROR : -200,
|
||||
MISSING_UPLOAD_URL : -210,
|
||||
IO_ERROR : -220,
|
||||
SECURITY_ERROR : -230,
|
||||
UPLOAD_LIMIT_EXCEEDED : -240,
|
||||
UPLOAD_FAILED : -250,
|
||||
SPECIFIED_FILE_ID_NOT_FOUND : -260,
|
||||
FILE_VALIDATION_FAILED : -270,
|
||||
FILE_CANCELLED : -280,
|
||||
UPLOAD_STOPPED : -290
|
||||
};
|
||||
SWFUpload.FILE_STATUS = {
|
||||
QUEUED : -1,
|
||||
IN_PROGRESS : -2,
|
||||
ERROR : -3,
|
||||
COMPLETE : -4,
|
||||
CANCELLED : -5
|
||||
};
|
||||
|
||||
|
||||
/* ******************** */
|
||||
/* Instance Members */
|
||||
/* ******************** */
|
||||
|
||||
// Private: initSettings ensures that all the
|
||||
// settings are set, getting a default value if one was not assigned.
|
||||
SWFUpload.prototype.initSettings = function () {
|
||||
this.ensureDefault = function (settingName, defaultValue) {
|
||||
this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
|
||||
};
|
||||
|
||||
// Upload backend settings
|
||||
this.ensureDefault("upload_url", "");
|
||||
this.ensureDefault("file_post_name", "Filedata");
|
||||
this.ensureDefault("post_params", {});
|
||||
this.ensureDefault("use_query_string", false);
|
||||
this.ensureDefault("requeue_on_error", false);
|
||||
|
||||
// File Settings
|
||||
this.ensureDefault("file_types", "*.*");
|
||||
this.ensureDefault("file_types_description", "All Files");
|
||||
this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
|
||||
this.ensureDefault("file_upload_limit", 0);
|
||||
this.ensureDefault("file_queue_limit", 0);
|
||||
|
||||
// Flash Settings
|
||||
this.ensureDefault("flash_url", "swfupload_f9.swf");
|
||||
this.ensureDefault("flash_color", "#FFFFFF");
|
||||
|
||||
// Debug Settings
|
||||
this.ensureDefault("debug", false);
|
||||
this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
|
||||
|
||||
// Event Handlers
|
||||
this.settings.return_upload_start_handler = this.returnUploadStart;
|
||||
this.ensureDefault("swfupload_loaded_handler", null);
|
||||
this.ensureDefault("file_dialog_start_handler", null);
|
||||
this.ensureDefault("file_queued_handler", null);
|
||||
this.ensureDefault("file_queue_error_handler", null);
|
||||
this.ensureDefault("file_dialog_complete_handler", null);
|
||||
|
||||
this.ensureDefault("upload_start_handler", null);
|
||||
this.ensureDefault("upload_progress_handler", null);
|
||||
this.ensureDefault("upload_error_handler", null);
|
||||
this.ensureDefault("upload_success_handler", null);
|
||||
this.ensureDefault("upload_complete_handler", null);
|
||||
|
||||
this.ensureDefault("debug_handler", this.debugMessage);
|
||||
|
||||
this.ensureDefault("custom_settings", {});
|
||||
|
||||
// Other settings
|
||||
this.customSettings = this.settings.custom_settings;
|
||||
|
||||
delete this.ensureDefault;
|
||||
};
|
||||
|
||||
// Private: loadFlash generates the HTML tag for the Flash
|
||||
// It then adds the flash to the body
|
||||
SWFUpload.prototype.loadFlash = function () {
|
||||
var targetElement, container;
|
||||
|
||||
// Make sure an element with the ID we are going to use doesn't already exist
|
||||
if (document.getElementById(this.movieName) !== null) {
|
||||
throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
|
||||
}
|
||||
|
||||
// Get the body tag where we will be adding the flash movie
|
||||
targetElement = document.getElementsByTagName("body")[0];
|
||||
|
||||
if (targetElement == undefined) {
|
||||
throw "Could not find the 'body' element.";
|
||||
}
|
||||
|
||||
// Append the container and load the flash
|
||||
container = document.createElement("div");
|
||||
container.style.width = "1px";
|
||||
container.style.height = "1px";
|
||||
|
||||
targetElement.appendChild(container);
|
||||
container.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
|
||||
};
|
||||
|
||||
// Private: getFlashHTML generates the object tag needed to embed the flash in to the document
|
||||
SWFUpload.prototype.getFlashHTML = function () {
|
||||
// Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
|
||||
return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="1" height="1" style="-moz-user-focus: ignore;">',
|
||||
'<param name="movie" value="', this.settings.flash_url, '" />',
|
||||
'<param name="bgcolor" value="', this.settings.flash_color, '" />',
|
||||
'<param name="quality" value="high" />',
|
||||
'<param name="menu" value="false" />',
|
||||
'<param name="allowScriptAccess" value="always" />',
|
||||
'<param name="flashvars" value="' + this.getFlashVars() + '" />',
|
||||
'</object>'].join("");
|
||||
};
|
||||
|
||||
// Private: getFlashVars builds the parameter string that will be passed
|
||||
// to flash in the flashvars param.
|
||||
SWFUpload.prototype.getFlashVars = function () {
|
||||
// Build a string from the post param object
|
||||
var paramString = this.buildParamString();
|
||||
|
||||
// Build the parameter string
|
||||
return ["movieName=", encodeURIComponent(this.movieName),
|
||||
"&uploadURL=", encodeURIComponent(this.settings.upload_url),
|
||||
"&useQueryString=", encodeURIComponent(this.settings.use_query_string),
|
||||
"&requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
|
||||
"&params=", encodeURIComponent(paramString),
|
||||
"&filePostName=", encodeURIComponent(this.settings.file_post_name),
|
||||
"&fileTypes=", encodeURIComponent(this.settings.file_types),
|
||||
"&fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
|
||||
"&fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
|
||||
"&fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
|
||||
"&fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
|
||||
"&debugEnabled=", encodeURIComponent(this.settings.debug_enabled)].join("");
|
||||
};
|
||||
|
||||
// Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
|
||||
// The element is cached after the first lookup
|
||||
SWFUpload.prototype.getMovieElement = function () {
|
||||
if (this.movieElement == undefined) {
|
||||
this.movieElement = document.getElementById(this.movieName);
|
||||
}
|
||||
|
||||
if (this.movieElement === null) {
|
||||
throw "Could not find Flash element";
|
||||
}
|
||||
|
||||
return this.movieElement;
|
||||
};
|
||||
|
||||
// Private: buildParamString takes the name/value pairs in the post_params setting object
|
||||
// and joins them up in to a string formatted "name=value&name=value"
|
||||
SWFUpload.prototype.buildParamString = function () {
|
||||
var postParams = this.settings.post_params;
|
||||
var paramStringPairs = [];
|
||||
|
||||
if (typeof(postParams) === "object") {
|
||||
for (var name in postParams) {
|
||||
if (postParams.hasOwnProperty(name)) {
|
||||
paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return paramStringPairs.join("&");
|
||||
};
|
||||
|
||||
// Public: displayDebugInfo prints out settings and configuration
|
||||
// information about this SWFUpload instance.
|
||||
// This function (and any references to it) can be deleted when placing
|
||||
// SWFUpload in production.
|
||||
SWFUpload.prototype.displayDebugInfo = function () {
|
||||
this.debug(
|
||||
[
|
||||
"---SWFUpload Instance Info---\n",
|
||||
"Version: ", SWFUpload.version, "\n",
|
||||
"Movie Name: ", this.movieName, "\n",
|
||||
"Settings:\n",
|
||||
"\t", "upload_url: ", this.settings.upload_url, "\n",
|
||||
"\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
|
||||
"\t", "file_post_name: ", this.settings.file_post_name, "\n",
|
||||
"\t", "post_params: ", this.settings.post_params.toString(), "\n",
|
||||
"\t", "file_types: ", this.settings.file_types, "\n",
|
||||
"\t", "file_types_description: ", this.settings.file_types_description, "\n",
|
||||
"\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
|
||||
"\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
|
||||
"\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
|
||||
"\t", "flash_url: ", this.settings.flash_url, "\n",
|
||||
"\t", "flash_color: ", this.settings.flash_color, "\n",
|
||||
"\t", "debug: ", this.settings.debug.toString(), "\n",
|
||||
"\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
|
||||
"Event Handlers:\n",
|
||||
"\t", "swfupload_loaded_handler assigned: ", (typeof(this.settings.swfupload_loaded_handler) === "function").toString(), "\n",
|
||||
"\t", "file_dialog_start_handler assigned: ", (typeof(this.settings.file_dialog_start_handler) === "function").toString(), "\n",
|
||||
"\t", "file_queued_handler assigned: ", (typeof(this.settings.file_queued_handler) === "function").toString(), "\n",
|
||||
"\t", "file_queue_error_handler assigned: ", (typeof(this.settings.file_queue_error_handler) === "function").toString(), "\n",
|
||||
"\t", "upload_start_handler assigned: ", (typeof(this.settings.upload_start_handler) === "function").toString(), "\n",
|
||||
"\t", "upload_progress_handler assigned: ", (typeof(this.settings.upload_progress_handler) === "function").toString(), "\n",
|
||||
"\t", "upload_error_handler assigned: ", (typeof(this.settings.upload_error_handler) === "function").toString(), "\n",
|
||||
"\t", "upload_success_handler assigned: ", (typeof(this.settings.upload_success_handler) === "function").toString(), "\n",
|
||||
"\t", "upload_complete_handler assigned: ", (typeof(this.settings.upload_complete_handler) === "function").toString(), "\n",
|
||||
"\t", "debug_handler assigned: ", (typeof(this.settings.debug_handler) === "function").toString(), "\n"
|
||||
].join("")
|
||||
);
|
||||
};
|
||||
|
||||
/* Note: addSetting and getSetting are no longer used by SWFUpload but are included
|
||||
the maintain v2 API compatibility
|
||||
*/
|
||||
// Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
|
||||
SWFUpload.prototype.addSetting = function (name, value, default_value) {
|
||||
if (value == undefined) {
|
||||
return (this.settings[name] = default_value);
|
||||
} else {
|
||||
return (this.settings[name] = value);
|
||||
}
|
||||
};
|
||||
|
||||
// Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
|
||||
SWFUpload.prototype.getSetting = function (name) {
|
||||
if (this.settings[name] != undefined) {
|
||||
return this.settings[name];
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Private: callFlash handles function calls made to the Flash element.
|
||||
// Calls are made with a setTimeout for some functions to work around
|
||||
// bugs in the ExternalInterface library.
|
||||
|
||||
// NOTE: if we don't need to call StartUpload with a timeout anymore then we can simplify this
|
||||
// function and remove all the withTimeout stuff
|
||||
SWFUpload.prototype.callFlash = function (functionName, withTimeout, argumentArray) {
|
||||
withTimeout = !!withTimeout || false;
|
||||
argumentArray = argumentArray || [];
|
||||
|
||||
var self = this;
|
||||
var callFunction = function () {
|
||||
var movieElement = self.getMovieElement();
|
||||
var returnValue;
|
||||
if (typeof(movieElement[functionName]) === "function") {
|
||||
// We have to go through all this if/else stuff because the Flash functions don't have apply() and only accept the exact number of arguments.
|
||||
if (argumentArray.length === 0) {
|
||||
returnValue = movieElement[functionName]();
|
||||
} else if (argumentArray.length === 1) {
|
||||
returnValue = movieElement[functionName](argumentArray[0]);
|
||||
} else if (argumentArray.length === 2) {
|
||||
returnValue = movieElement[functionName](argumentArray[0], argumentArray[1]);
|
||||
} else if (argumentArray.length === 3) {
|
||||
returnValue = movieElement[functionName](argumentArray[0], argumentArray[1], argumentArray[2]);
|
||||
} else {
|
||||
throw "Too many arguments";
|
||||
}
|
||||
|
||||
// Unescape file post param values
|
||||
if (returnValue != undefined && typeof(returnValue.post) === "object") {
|
||||
returnValue = self.unescapeFilePostParams(returnValue);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
} else {
|
||||
throw "Invalid function name";
|
||||
}
|
||||
};
|
||||
|
||||
if (withTimeout) {
|
||||
setTimeout(callFunction, 0);
|
||||
} else {
|
||||
return callFunction();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* *****************************
|
||||
-- Flash control methods --
|
||||
Your UI should use these
|
||||
to operate SWFUpload
|
||||
***************************** */
|
||||
|
||||
// Public: selectFile causes a File Selection Dialog window to appear. This
|
||||
// dialog only allows 1 file to be selected.
|
||||
SWFUpload.prototype.selectFile = function () {
|
||||
this.callFlash("SelectFile");
|
||||
};
|
||||
|
||||
// Public: selectFiles causes a File Selection Dialog window to appear/ This
|
||||
// dialog allows the user to select any number of files
|
||||
// Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
|
||||
// If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
|
||||
// for this bug.
|
||||
SWFUpload.prototype.selectFiles = function () {
|
||||
this.callFlash("SelectFiles");
|
||||
};
|
||||
|
||||
|
||||
// Public: startUpload starts uploading the first file in the queue unless
|
||||
// the optional parameter 'fileID' specifies the ID
|
||||
SWFUpload.prototype.startUpload = function (fileID) {
|
||||
// NOTE: Testing this without using a setTimeout. Since StartUpload was reworked to use ReturnUploadStart
|
||||
// it might not be necessary anymore
|
||||
this.callFlash("StartUpload", false, [fileID]);
|
||||
};
|
||||
|
||||
/* Cancels a the file upload. You must specify a file_id */
|
||||
// Public: cancelUpload cancels any queued file. The fileID parameter
|
||||
// must be specified.
|
||||
SWFUpload.prototype.cancelUpload = function (fileID) {
|
||||
this.callFlash("CancelUpload", false, [fileID]);
|
||||
};
|
||||
|
||||
// Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
|
||||
// If nothing is currently uploading then nothing happens.
|
||||
SWFUpload.prototype.stopUpload = function () {
|
||||
this.callFlash("StopUpload");
|
||||
};
|
||||
|
||||
/* ************************
|
||||
* Settings methods
|
||||
* These methods change the SWFUpload settings.
|
||||
* SWFUpload settings should not be changed directly on the settings object
|
||||
* since many of the settings need to be passed to Flash in order to take
|
||||
* effect.
|
||||
* *********************** */
|
||||
|
||||
// Public: getStats gets the file statistics object. It looks like this (where n is a number):
|
||||
SWFUpload.prototype.getStats = function () {
|
||||
return this.callFlash("GetStats");
|
||||
};
|
||||
|
||||
// Public: setStats changes the SWFUpload statistics. You shouldn't need to
|
||||
// change the statistics but you can. Changing the statistics does not
|
||||
// affect SWFUpload accept for the successful_uploads count which is used
|
||||
// by the upload_limit setting to determine how many files the user may upload.
|
||||
SWFUpload.prototype.setStats = function (statsObject) {
|
||||
this.callFlash("SetStats", false, [statsObject]);
|
||||
};
|
||||
|
||||
// Public: setCredentials that will be used to authenticate to the upload_url.
|
||||
// Note: This feature does not work. It has been added in anticipation of
|
||||
// the Flex 3 SDK which has not been released yet.
|
||||
SWFUpload.prototype.setCredentials = function (name, password) {
|
||||
this.callFlash("SetCrednetials", false, [name, password]);
|
||||
};
|
||||
|
||||
// Public: getFile retrieves a File object by ID or Index. If the file is
|
||||
// not found then 'null' is returned.
|
||||
SWFUpload.prototype.getFile = function (fileID) {
|
||||
if (typeof(fileID) === "number") {
|
||||
return this.callFlash("GetFileByIndex", false, [fileID]);
|
||||
} else {
|
||||
return this.callFlash("GetFile", false, [fileID]);
|
||||
}
|
||||
};
|
||||
|
||||
// Public: addFileParam sets a name/value pair that will be posted with the
|
||||
// file specified by the Files ID. If the name already exists then the
|
||||
// exiting value will be overwritten.
|
||||
SWFUpload.prototype.addFileParam = function (fileID, name, value) {
|
||||
return this.callFlash("AddFileParam", false, [fileID, name, value]);
|
||||
};
|
||||
|
||||
// Public: removeFileParam removes a previously set (by addFileParam) name/value
|
||||
// pair from the specified file.
|
||||
SWFUpload.prototype.removeFileParam = function (fileID, name) {
|
||||
this.callFlash("RemoveFileParam", false, [fileID, name]);
|
||||
};
|
||||
|
||||
// Public: setUploadUrl changes the upload_url setting.
|
||||
SWFUpload.prototype.setUploadURL = function (url) {
|
||||
this.settings.upload_url = url.toString();
|
||||
this.callFlash("SetUploadURL", false, [url]);
|
||||
};
|
||||
|
||||
// Public: setPostParams changes the post_params setting
|
||||
SWFUpload.prototype.setPostParams = function (paramsObject) {
|
||||
this.settings.post_params = paramsObject;
|
||||
this.callFlash("SetPostParams", false, [paramsObject]);
|
||||
};
|
||||
|
||||
// Public: addPostParam adds post name/value pair. Each name can have only one value.
|
||||
SWFUpload.prototype.addPostParam = function (name, value) {
|
||||
this.settings.post_params[name] = value;
|
||||
this.callFlash("SetPostParams", false, [this.settings.post_params]);
|
||||
};
|
||||
|
||||
// Public: removePostParam deletes post name/value pair.
|
||||
SWFUpload.prototype.removePostParam = function (name) {
|
||||
delete this.settings.post_params[name];
|
||||
this.callFlash("SetPostParams", false, [this.settings.post_params]);
|
||||
};
|
||||
|
||||
// Public: setFileTypes changes the file_types setting and the file_types_description setting
|
||||
SWFUpload.prototype.setFileTypes = function (types, description) {
|
||||
this.settings.file_types = types;
|
||||
this.settings.file_types_description = description;
|
||||
this.callFlash("SetFileTypes", false, [types, description]);
|
||||
};
|
||||
|
||||
// Public: setFileSizeLimit changes the file_size_limit setting
|
||||
SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
|
||||
this.settings.file_size_limit = fileSizeLimit;
|
||||
this.callFlash("SetFileSizeLimit", false, [fileSizeLimit]);
|
||||
};
|
||||
|
||||
// Public: setFileUploadLimit changes the file_upload_limit setting
|
||||
SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
|
||||
this.settings.file_upload_limit = fileUploadLimit;
|
||||
this.callFlash("SetFileUploadLimit", false, [fileUploadLimit]);
|
||||
};
|
||||
|
||||
// Public: setFileQueueLimit changes the file_queue_limit setting
|
||||
SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
|
||||
this.settings.file_queue_limit = fileQueueLimit;
|
||||
this.callFlash("SetFileQueueLimit", false, [fileQueueLimit]);
|
||||
};
|
||||
|
||||
// Public: setFilePostName changes the file_post_name setting
|
||||
SWFUpload.prototype.setFilePostName = function (filePostName) {
|
||||
this.settings.file_post_name = filePostName;
|
||||
this.callFlash("SetFilePostName", false, [filePostName]);
|
||||
};
|
||||
|
||||
// Public: setUseQueryString changes the use_query_string setting
|
||||
SWFUpload.prototype.setUseQueryString = function (useQueryString) {
|
||||
this.settings.use_query_string = useQueryString;
|
||||
this.callFlash("SetUseQueryString", false, [useQueryString]);
|
||||
};
|
||||
|
||||
// Public: setRequeueOnError changes the requeue_on_error setting
|
||||
SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
|
||||
this.settings.requeue_on_error = requeueOnError;
|
||||
this.callFlash("SetRequeueOnError", false, [requeueOnError]);
|
||||
};
|
||||
|
||||
// Public: setDebugEnabled changes the debug_enabled setting
|
||||
SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
|
||||
this.settings.debug_enabled = debugEnabled;
|
||||
this.callFlash("SetDebugEnabled", false, [debugEnabled]);
|
||||
};
|
||||
|
||||
|
||||
/* *******************************
|
||||
Flash Event Interfaces
|
||||
These functions are used by Flash to trigger the various
|
||||
events.
|
||||
|
||||
All these functions a Private.
|
||||
|
||||
Because the ExternalInterface library is buggy the event calls
|
||||
are added to a queue and the queue then executed by a setTimeout.
|
||||
This ensures that events are executed in a determinate order and that
|
||||
the ExternalInterface bugs are avoided.
|
||||
******************************* */
|
||||
|
||||
SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
|
||||
// Warning: Don't call this.debug inside here or you'll create an infinite loop
|
||||
|
||||
if (argumentArray == undefined) {
|
||||
argumentArray = [];
|
||||
} else if (!(argumentArray instanceof Array)) {
|
||||
argumentArray = [argumentArray];
|
||||
}
|
||||
|
||||
var self = this;
|
||||
if (typeof(this.settings[handlerName]) === "function") {
|
||||
// Queue the event
|
||||
this.eventQueue.push(function () {
|
||||
this.settings[handlerName].apply(this, argumentArray);
|
||||
});
|
||||
|
||||
// Execute the next queued event
|
||||
setTimeout(function () {
|
||||
self.executeNextEvent();
|
||||
}, 0);
|
||||
|
||||
} else if (this.settings[handlerName] !== null) {
|
||||
throw "Event handler " + handlerName + " is unknown or is not a function";
|
||||
}
|
||||
};
|
||||
|
||||
SWFUpload.prototype.executeNextEvent = function () {
|
||||
// Warning: Don't call this.debug inside here or you'll create an infinite loop
|
||||
|
||||
var f = this.eventQueue.shift();
|
||||
f.apply(this);
|
||||
|
||||
};
|
||||
|
||||
// Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterfance cannot have
|
||||
// properties that contain characters that are not valid for JavaScript identifiers. To work around this
|
||||
// the Flash Component escapes the parameter names and we must unescape again before passing them along.
|
||||
SWFUpload.prototype.unescapeFilePostParams = function (file) {
|
||||
var reg = /[$]([0-9a-f]{4})/i;
|
||||
var unescapedPost = {};
|
||||
var uk;
|
||||
|
||||
for (var k in file.post) {
|
||||
if (file.post.hasOwnProperty(k)) {
|
||||
uk = k;
|
||||
var match;
|
||||
while ((match = reg.exec(uk)) !== null) {
|
||||
uk = uk.replace(match[0], String.fromCharCode(parseInt("0x"+match[1], 16)));
|
||||
}
|
||||
unescapedPost[uk] = file.post[k];
|
||||
}
|
||||
}
|
||||
|
||||
file.post = unescapedPost;
|
||||
return file;
|
||||
};
|
||||
|
||||
SWFUpload.prototype.flashReady = function () {
|
||||
// Check that the movie element is loaded correctly with its ExternalInterface methods defined
|
||||
var movieElement = this.getMovieElement();
|
||||
if (typeof(movieElement.StartUpload) !== "function") {
|
||||
throw "ExternalInterface methods failed to initialize.";
|
||||
}
|
||||
|
||||
this.queueEvent("swfupload_loaded_handler");
|
||||
};
|
||||
|
||||
|
||||
/* This is a chance to do something before the browse window opens */
|
||||
SWFUpload.prototype.fileDialogStart = function () {
|
||||
this.queueEvent("file_dialog_start_handler");
|
||||
};
|
||||
|
||||
|
||||
/* Called when a file is successfully added to the queue. */
|
||||
SWFUpload.prototype.fileQueued = function (file) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("file_queued_handler", file);
|
||||
};
|
||||
|
||||
|
||||
/* Handle errors that occur when an attempt to queue a file fails. */
|
||||
SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
|
||||
};
|
||||
|
||||
/* Called after the file dialog has closed and the selected files have been queued.
|
||||
You could call startUpload here if you want the queued files to begin uploading immediately. */
|
||||
SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued) {
|
||||
this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued]);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.uploadStart = function (file) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("return_upload_start_handler", file);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.returnUploadStart = function (file) {
|
||||
var returnValue;
|
||||
if (typeof(this.settings.upload_start_handler) === "function") {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
returnValue = this.settings.upload_start_handler.call(this, file);
|
||||
} else if (this.settings.upload_start_handler != undefined) {
|
||||
throw "upload_start_handler must be a function";
|
||||
}
|
||||
|
||||
// Convert undefined to true so if nothing is returned from the upload_start_handler it is
|
||||
// interpretted as 'true'.
|
||||
if (returnValue === undefined) {
|
||||
returnValue = true;
|
||||
}
|
||||
|
||||
returnValue = !!returnValue;
|
||||
|
||||
this.callFlash("ReturnUploadStart", false, [returnValue]);
|
||||
};
|
||||
|
||||
|
||||
|
||||
SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.uploadError = function (file, errorCode, message) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("upload_error_handler", [file, errorCode, message]);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.uploadSuccess = function (file, serverData) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("upload_success_handler", [file, serverData]);
|
||||
};
|
||||
|
||||
SWFUpload.prototype.uploadComplete = function (file) {
|
||||
file = this.unescapeFilePostParams(file);
|
||||
this.queueEvent("upload_complete_handler", file);
|
||||
};
|
||||
|
||||
/* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
|
||||
internal debug console. You can override this event and have messages written where you want. */
|
||||
SWFUpload.prototype.debug = function (message) {
|
||||
this.queueEvent("debug_handler", message);
|
||||
};
|
||||
|
||||
|
||||
/* **********************************
|
||||
Debug Console
|
||||
The debug console is a self contained, in page location
|
||||
for debug message to be sent. The Debug Console adds
|
||||
itself to the body if necessary.
|
||||
|
||||
The console is automatically scrolled as messages appear.
|
||||
|
||||
If you are using your own debug handler or when you deploy to production and
|
||||
have debug disabled you can remove these functions to reduce the file size
|
||||
and complexity.
|
||||
********************************** */
|
||||
|
||||
// Private: debugMessage is the default debug_handler. If you want to print debug messages
|
||||
// call the debug() function. When overriding the function your own function should
|
||||
// check to see if the debug setting is true before outputting debug information.
|
||||
SWFUpload.prototype.debugMessage = function (message) {
|
||||
if (this.settings.debug) {
|
||||
var exceptionMessage, exceptionValues = [];
|
||||
|
||||
// Check for an exception object and print it nicely
|
||||
if (typeof(message) === "object" && typeof(message.name) === "string" && typeof(message.message) === "string") {
|
||||
for (var key in message) {
|
||||
if (message.hasOwnProperty(key)) {
|
||||
exceptionValues.push(key + ": " + message[key]);
|
||||
}
|
||||
}
|
||||
exceptionMessage = exceptionValues.join("\n") || "";
|
||||
exceptionValues = exceptionMessage.split("\n");
|
||||
exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
|
||||
SWFUpload.Console.writeLine(exceptionMessage);
|
||||
} else {
|
||||
SWFUpload.Console.writeLine(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SWFUpload.Console = {};
|
||||
SWFUpload.Console.writeLine = function (message) {
|
||||
var console, documentForm;
|
||||
|
||||
try {
|
||||
console = document.getElementById("SWFUpload_Console");
|
||||
|
||||
if (!console) {
|
||||
documentForm = document.createElement("form");
|
||||
document.getElementsByTagName("body")[0].appendChild(documentForm);
|
||||
|
||||
console = document.createElement("textarea");
|
||||
console.id = "SWFUpload_Console";
|
||||
console.style.fontFamily = "monospace";
|
||||
console.setAttribute("wrap", "off");
|
||||
console.wrap = "off";
|
||||
console.style.overflow = "auto";
|
||||
console.style.width = "700px";
|
||||
console.style.height = "350px";
|
||||
console.style.margin = "5px";
|
||||
documentForm.appendChild(console);
|
||||
}
|
||||
|
||||
console.value += message + "\n";
|
||||
|
||||
console.scrollTop = console.scrollHeight - console.clientHeight;
|
||||
} catch (ex) {
|
||||
alert("Exception: " + ex.name + " Message: " + ex.message);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user