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:
TMS
2026-06-18 21:20:26 +00:00
commit eb299c9131
1099 changed files with 359817 additions and 0 deletions

View File

@@ -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);

View File

@@ -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 );
?>

View 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),
"&amp;uploadURL=",encodeURIComponent(this.settings.upload_url),
"&amp;useQueryString=",encodeURIComponent(this.settings.use_query_string),
"&amp;requeueOnError=",encodeURIComponent(this.settings.requeue_on_error),
"&amp;params=",encodeURIComponent(paramString),
"&amp;filePostName=",encodeURIComponent(this.settings.file_post_name),
"&amp;fileTypes=",encodeURIComponent(this.settings.file_types),
"&amp;fileTypesDescription=",encodeURIComponent(this.settings.file_types_description),
"&amp;fileSizeLimit=",encodeURIComponent(this.settings.file_size_limit),
"&amp;fileUploadLimit=",encodeURIComponent(this.settings.file_upload_limit),
"&amp;fileQueueLimit=",encodeURIComponent(this.settings.file_queue_limit),
"&amp;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("&amp;");};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);}
};

View File

@@ -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="&nbsp;";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;}
}
}

View File

@@ -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="&nbsp;";
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;
}
}
}

View File

@@ -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),
"&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
"&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
"&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
"&amp;params=", encodeURIComponent(paramString),
"&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
"&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
"&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
"&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
"&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
"&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
"&amp;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&amp;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("&amp;");
};
// 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);
}
};

View File

@@ -0,0 +1,226 @@
<?php
/*
File: TabManager.inc.php
Contains a class that can be used to invoke DOM calls on the browser which
will create or update an HTML table.
Title: clsTabManager class
Please see <copyright.inc.php> for a detailed description, copyright
and license information.
*/
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: clsTabManager
*/
class clsTabManager
extends xajaxResponsePlugin
{
/*
String: sDefer
Used to store the state of the scriptDeferral configuration setting. When
script deferral is desired, this member contains 'defer' which will request
that the browser defer loading of the javascript until the rest of the page
has been loaded.
*/
var $sDefer;
/*
String: sJavascriptURI
Used to store the base URI for where the javascript files are located. This
enables the plugin to generate a script reference to it's javascript file
if the javascript code is NOT inlined.
*/
var $sJavascriptURI;
/*
Boolean: bInlineScript
Used to store the value of the inlineScript configuration option. When true,
the plugin will return it's javascript code as part of the javascript header
for the page, else, it will generate a script tag referencing the file by
using the <clsTabManager->sJavascriptURI>.
*/
var $bInlineScript;
/*
Function: clsTabManager
Constructs and initializes an instance of the table updater class.
*/
function clsTabManager()
{
$this->sDefer = '';
$this->sJavascriptURI = '';
$this->bInlineScript = false;
}
/*
Function: configure
Receives configuration settings set by <xajax> or user script calls to
<xajax->configure>.
sName - (string): The name of the configuration option being set.
mValue - (mixed): The value being associated with the configuration option.
*/
function configure( $sName, $mValue )
{
if ( 'scriptDeferral' == $sName )
{
if ( true === $mValue || false === $mValue )
{
if ( $mValue )
$this->sDefer = 'defer ';
else
$this->sDefer = '';
}
}
else if ( 'javascript URI' == $sName )
{
$this->sJavascriptURI = $mValue;
}else if ( 'inlineScript' == $sName )
{
if ( true === $mValue || false === $mValue )
$this->bInlineScript = $mValue;
}
}
/*
Function: generateClientScript
Called by the <xajaxPluginManager> during the script generation phase. This
will either inline the script or insert a script tag which references the
<TabManager.js> file based on the value of the <clsTabManager->bInlineScript>
configuration option.
*/
function generateClientScript()
{
if ( $this->bInlineScript )
{
echo "\n<script type='text/javascript' ".$this->sDefer."charset='UTF-8'>\n";
echo "/* <![CDATA[ */\n";
include( dirname( __FILE__ ).'/TabManager.js' );
echo "/* ]]> */\n";
echo "</script>\n";
}else
{
echo "\n<script type='text/javascript' src='".$this->sJavascriptURI."xajax_plugins/response/TabManager/TabManager.js' ".$this->sDefer."charset='UTF-8'></script>\n";
}
}
function getName()
{
return get_class( $this );
}
function create( $id, $config )
{
$command = array
(
'cmd' => 'tm_create',
'id' => $id
);
$this->addCommand( $command, $config );
}
function addPanel( $id, $config )
{
$command = array
(
'cmd' => 'tm_at',
'id' => $id
);
$this->addCommand( $command, $config );
}
function on( $eventName, $target, $panel, $event )
{
$command = array
(
'cmd' => 'tm_on',
'id' => $target
);
$this->addCommand( $command, array
(
"n" => $eventName,
"p" => $panel,
"e" => $event,
"key" => crc32($event)
));
}
function close( $id, $panel )
{
$command = array
(
'cmd' => 'tm_cl',
'id' => $id
);
$this->addCommand( $command, $panel );
}
function showPanel( $id, $panel )
{
$command = array
(
'cmd' => 'tm_sp',
'id' => $id
);
$this->addCommand( $command, $panel );
}
function setTitle( $id, $panel, $title )
{
$command = array
(
'cmd' => 'tm_st',
'id' => $id
);
$this->addCommand( $command, array
(
"panel" => $panel,
"title" => $title
));
}
function destroy( $id )
{
$command = array
(
'cmd' => 'tm_de',
'id' => $id
);
$this->addCommand( $command, array ());
}
}
$objPluginManager = &xajaxPluginManager::getInstance();
$objPluginManager->registerPlugin( new clsTabManager() );
?>

View File

@@ -0,0 +1,73 @@
installtabManager=function(){var xjxReady=false;try{if(xajax)
xjxReady=true;}
catch(e){}
if(false==xjxReady){setTimeout('installtabManager();',1000);return;}
try{if(undefined==xajax.ext.tabManager)
xajax.ext.tabManager={};xajax.ext.tabManager.instances={};}
catch(e){xajax.ext={};xajax.ext.tabManager={};xajax.ext.tabManager.instances={};}
xajax.ext.tabPanel=function(config){this.config=config;this._parent=config._parent;this.id=config.id;var element=this;this.events={};this.tabWidth=0;if('undefined'!=typeof config.closeable){this.closeable=config.closeable;}
else{this.closeable=true;}
var parPanel=this._parent.tabPanel;this.tab_item=document.createElement('div');this.tab_item.id="tabPanel_"+this.id;this.tab_item.className="tabPanelItem";this.tab_item.onclick=function(){element._parent.show(element.id);return false;};var tab_item_left=document.createElement('div');tab_item_left.className='tabLeft';tab_item_left.innerHTML='&nbsp;';this.tab_item.appendChild(tab_item_left);var tab_title=document.createElement('div');tab_title.id="tabPanelTitel_"+this.id;tab_title.innerHTML=config.title;tab_title.className='title';this.tab_title=tab_title;this.tab_item.appendChild(tab_title);if(this.closeable){var foo=this;var tab_close=document.createElement('div');tab_close.id="tabPanelClose_"+this.id;tab_close.innerHTML="&nbsp;";tab_close.className='close';tab_close.onclick=function(){foo.fire("close");element._parent.closePanel(element.id);return false;}
this.tab_item.appendChild(tab_close);}
var tab_item_right=document.createElement('div');tab_item_right.className='tabRight';tab_item_right.innerHTML='&nbsp;';this.tab_item.appendChild(tab_item_right);var tab_clear=document.createElement('div');tab_clear.style.clear='both';this.tab_item.appendChild(tab_clear);var tmp_width=$(parPanel).outerWidth();parPanel.appendChild(this.tab_item);var parContent=this._parent.tabContent;this.tab_content=document.createElement('div');this.tab_content.id="tabContent_"+this.id;this.tab_content.className="tabPanelContent";this.tab_content.innerHTML=config.content;this.tab_content.style.display='none';parContent.appendChild(this.tab_content);this.tabWidth=$(this.tab_item).outerWidth()+2;this.getWidth=function(){this.tabWidth=$(this.tab_item).outerWidth()+2;return this.tabWidth;};this.show=function(){this.tab_item.className='tabPanelItemActive';this.tab_content.style.display='block';this.fire("show");};this.hide=function(){this.tab_item.className='tabPanelItem';this.tab_content.style.display='none';this.fire("hide");};this.setTitle=function(title){this.tab_title.innerHTML=title;};this.setContent=function(content){this.tab_content.innerHTML=content;};this.destroy=function(){this.fire("destroy");parPanel.removeChild(this.tab_item);parContent.removeChild(this.tab_content);};this.fire=function(EventName){if('object'==typeof this.events[EventName]){for(a in this.events[EventName])
this.events[EventName][a]();}
}
this.on=function(EventName,EventFunction,EventFunctionId){if('object'!=typeof this.events[EventName])
this.events[EventName]=new Object();if('undefined'==typeof this.events[EventName][EventFunctionId])
this.events[EventName][EventFunctionId]=EventFunction;}
};xajax.ext.tabManager.tabBar=function(config){this.config=config;this.tabBar=xajax.$(config.tabPanel);this.tabContent=xajax.$(config.tabContent);this.tabs={};this.activeTab=null;this.lastActiveTab=null;this.interval=null;this.maxWidth=$(this.tabBar).innerWidth();this.tabWidth=0;this.tabHeight=$(this.tabBar).innerHeight();var leftHandle=document.createElement('div');leftHandle.className="leftHandle";var rightHandle=document.createElement('div');rightHandle.className="rightHandle";var foo=this;leftHandle.onmouseover=function(){foo.scroll(4);}
rightHandle.onmouseover=function(){foo.scroll(-4);}
leftHandle.onmouseout=function(){foo.scrollStop();}
rightHandle.onmouseout=function(){foo.scrollStop();}
leftHandle.style.display='none';rightHandle.style.display='none';this.leftHandle=leftHandle;this.rightHandle=rightHandle;var tabContainer=document.createElement('div');tabContainer.id="tabManager_Container_"+config.tabPanel;tabContainer.style.position="absolute";tabContainer.style.top="0px";tabContainer.style.left="0px";tabContainer.style.right="0px";tabContainer.style.height=this.tabHeight+"px";tabContainer.style.overflow="hidden";var tabPanel=document.createElement('div');tabPanel.style.position="absolute";tabPanel.style.height=this.tabHeight+"px";this.tabBar.appendChild(leftHandle);this.tabBar.appendChild(tabContainer);this.tabBar.appendChild(rightHandle);tabContainer.appendChild(tabPanel);this.tabPanel=tabPanel;this.tabContainer=tabContainer;if('undefined'!=typeof config.cssClass){this.tabPanel.className=this.tabBar.className+" "+config.cssClass;}
this.addPanel=function(config){if('undefined'!=typeof this.tabs[config.id]){if(config.hide)
return;this.tabs[config.id].fire("destroy");this.show(config.id);return;};config._parent=this;this.tabs[config.id]=new xajax.ext.tabPanel(config);if(true!=config.hide)
this.show(config.id);this.tabWidth+=this.tabs[config.id].getWidth();if(this.tabWidth > this.maxWidth){this.leftHandle.style.display='block';this.rightHandle.style.display='block';var lspace=$(this.leftHandle).outerWidth()+1;var rspace=$(this.rightHandle).outerWidth()+1;this.tabContainer.style.left=lspace+"px";this.tabContainer.style.right=rspace+"px";}
};this.show=function(id){if('undefined'==typeof this.tabs[id])
return;if(null!=this.activeTab)
this.activeTab.hide();this.tabs[id].show();this.lastActiveTab=this.activeTab;this.activeTab=this.tabs[id];var pos=$('#tabPanel_'+id).position();var elm_left=pos.left;var elm_max=pos.left+parseInt(this.tabs[id].tabWidth);var container_width=$(this.tabContainer).innerWidth();var panel_pos=$(this.tabPanel).position();var scroll_left=panel_pos.left;var visible_left=0-scroll_left;var visible_right=visible_left+container_width;if(elm_left < visible_left){$(this.tabPanel).animate({left:(0-elm_left)+"px"
});}
else if(elm_max > visible_right){$(this.tabPanel).animate({left:(container_width-elm_max-22)+"px"
});}
};this.setContent=function(id,content){if('undefined'!=typeof this.tabs[id])
return;this.tabs[id].setContent(content);};this.setTitle=function(id,title){if('undefined'==typeof this.tabs[id])
return;this.tabs[id].setTitle(title);};this.updateInnerWidth=function(){var tmpwidth=0;for(a in this.tabs){tmpwidth+=this.tabs[a].getWidth();}
this.tabWidth=tmpwidth+22;};this.closePanel=function(id){if('undefined'==typeof this.tabs[id])
return;if(null!=this.lastActiveTab){if(this.activeTab.id==id)
this.show(this.lastActiveTab.id);}
this.tabs[id].destroy();delete(this.tabs[id]);this.updateInnerWidth();if(this.tabWidth < this.maxWidth){this.leftHandle.style.display='none';this.rightHandle.style.display='none';this.tabContainer.style.left="0px";this.tabContainer.style.right="0px";this.tabPanel.style.left="0px";}
};this.on=function(EventName,id,EventFunction,EventFunctionId){this.tabs[id].on(EventName,EventFunction,EventFunctionId);}
this.scroll=function(value){if(null!=this.interval)
return;var tab=this;var i=value;this.interval=setInterval(function(){var lspace=$(tab.leftHandle).innerWidth()+1;var rspace=$(tab.rightHandle).innerWidth()+1;var sLeft=tab.tabPanel.style.left;var iLeft=sLeft.replace("px","");if(""==iLeft)
iLeft=0;iLeft=parseInt(iLeft);iLeft+=i;var iMin=tab.maxWidth-tab.tabWidth-rspace-lspace;if((iLeft > 0)||((iLeft < iMin)&&(i < 0))){tab.scrollStop();return;}
tab.tabPanel.style.left=iLeft+"px";},25);}
this.scrollStop=function(){if(null==this.interval)
return;clearInterval(this.interval);this.interval=null;}
this.destroy=function(){for(a in this.tabs){this.tabs[a].destroy();delete(this.tabs[a]);}
};};xajax.ext.tabManager.create=function(id,config){if("undefined"==typeof xajax.ext.tabManager.instances[id]){try{xajax.ext.tabManager.instances[id]=new xajax.ext.tabManager.tabBar(config);}
catch(ex){}
}
}
xajax.ext.tabManager.addPanel=function(id,config){try{xajax.ext.tabManager.instances[id].addPanel(config);}
catch(ex){}
}
xajax.ext.tabManager.showPanel=function(id,sPanel){try{xajax.ext.tabManager.instances[id].show(sPanel);}
catch(ex){}
}
xajax.ext.tabManager.setTitle=function(id,sPanel,title){try{xajax.ext.tabManager.instances[id].setTitle(sPanel,title);}
catch(ex){}
}
xajax.ext.tabManager.on=function(id,sEventName,sTarget,sEventFunc,sEventId){xajax.ext.tabManager.instances[id].on(sEventName,sTarget,sEventFunc,sEventId);}
xajax.ext.tabManager.closePanel=function(id,sPanel){xajax.ext.tabManager.instances[id].closePanel(sPanel);}
xajax.ext.tabManager.destroy=function(id){xajax.ext.tabManager.instances[id].destroy();delete(xajax.ext.tabManager.instances[id]);}
xajax.command.handler.register('tm_create',function(args){args.cmdFullName='ext.tabManager.create';xajax.ext.tabManager.create(args.id,args.data);return true;});xajax.command.handler.register('tm_at',function(args){args.cmdFullName='ext.tabManager.addPanel';xajax.ext.tabManager.addPanel(args.id,args.data);return true;});xajax.command.handler.register('tm_on',function(args){try{args.cmdFullName='ext.tabManager.on';eval("var sEvent = "+args.data.e+";");xajax.ext.tabManager.on(args.id,args.data.n,args.data.p,sEvent,args.data.key);}
catch(ex){}
return true;});xajax.command.handler.register('tm_cl',function(args){try{args.cmdFullName='ext.tabManager.closePanel';xajax.ext.tabManager.closePanel(args.id,args.data);}
catch(ex){debugObj(ex);}
return true;});xajax.command.handler.register('tm_sp',function(args){args.cmdFullName='ext.tabManager.showPanel';xajax.ext.tabManager.showPanel(args.id,args.data);return true;});xajax.command.handler.register('tm_st',function(args){try{args.cmdFullName='ext.tabManager.setTitle';xajax.ext.tabManager.setTitle(args.id,args.data.panel,args.data.title);}
catch(ex){}
return true;});xajax.command.handler.register('tm_de',function(args){try{args.cmdFullName='ext.tabManager.destroy';xajax.ext.tabManager.destroy(args.id);}
catch(ex){debugObj(ex);}
return true;});}
installtabManager();

View File

@@ -0,0 +1,614 @@
// if xajax has not yet been initialized, wait a second and try again
// once xajax has been initialized, install the table command handlers.
installtabManager = function()
{
var xjxReady = false;
try
{
if (xajax)
xjxReady = true;
}
catch (e)
{
}
if (false == xjxReady)
{
setTimeout('installtabManager();', 1000);
return;
}
try
{
if (undefined == xajax.ext.tabManager)
xajax.ext.tabManager = {
};
xajax.ext.tabManager.instances = {
};
}
catch (e)
{
xajax.ext = {
};
xajax.ext.tabManager = {
};
xajax.ext.tabManager.instances = {
};
}
xajax.ext.tabPanel = function(config)
{
this.config = config;
this._parent = config._parent;
this.id = config.id;
var element = this;
this.events = {
};
this.tabWidth = 0;
if ('undefined' != typeof config.closeable)
{
this.closeable = config.closeable;
}
else
{
this.closeable = true;
}
var parPanel = this._parent.tabPanel;
this.tab_item = document.createElement('div');
this.tab_item.id = "tabPanel_" + this.id;
this.tab_item.className = "tabPanelItem";
this.tab_item.onclick = function()
{
element._parent.show(element.id);
return false;
};
var tab_item_left = document.createElement('div');
tab_item_left.className = 'tabLeft';
tab_item_left.innerHTML = '&nbsp;';
this.tab_item.appendChild(tab_item_left);
var tab_title = document.createElement('div');
tab_title.id = "tabPanelTitel_" + this.id;
tab_title.innerHTML = config.title;
tab_title.className = 'title';
this.tab_title = tab_title;
this.tab_item.appendChild(tab_title);
if (this.closeable)
{
var foo = this;
var tab_close = document.createElement('div');
tab_close.id = "tabPanelClose_" + this.id;
tab_close.innerHTML = "&nbsp;";
tab_close.className = 'close';
tab_close.onclick = function()
{
foo.fire("close");
element._parent.closePanel(element.id);
return false;
}
this.tab_item.appendChild(tab_close);
}
var tab_item_right = document.createElement('div');
tab_item_right.className = 'tabRight';
tab_item_right.innerHTML = '&nbsp;';
this.tab_item.appendChild(tab_item_right);
var tab_clear = document.createElement('div');
tab_clear.style.clear = 'both';
this.tab_item.appendChild(tab_clear);
var tmp_width = $(parPanel).outerWidth();
//parPanel.style.width=(tmp_width+300)+"px";
parPanel.appendChild(this.tab_item);
var parContent = this._parent.tabContent;
this.tab_content = document.createElement('div');
this.tab_content.id = "tabContent_" + this.id;
this.tab_content.className = "tabPanelContent";
this.tab_content.innerHTML = config.content;
this.tab_content.style.display = 'none';
parContent.appendChild(this.tab_content);
//this.getWidth();
this.tabWidth = $(this.tab_item).outerWidth() + 2;
this.getWidth = function()
{
this.tabWidth = $(this.tab_item).outerWidth() + 2;
return this.tabWidth;
};
this.show = function()
{
this.tab_item.className = 'tabPanelItemActive';
this.tab_content.style.display = 'block';
this.fire("show");
};
this.hide = function()
{
this.tab_item.className = 'tabPanelItem';
this.tab_content.style.display = 'none';
this.fire("hide");
};
this.setTitle = function(title)
{
this.tab_title.innerHTML = title;
};
this.setContent = function(content)
{
this.tab_content.innerHTML = content;
};
this.destroy = function()
{
this.fire("destroy");
parPanel.removeChild(this.tab_item);
parContent.removeChild(this.tab_content);
};
this.fire = function(EventName)
{
if ('object' == typeof this.events[EventName])
{
for (a in this.events[EventName])
this.events[EventName][a]();
}
}
this.on = function(EventName, EventFunction, EventFunctionId)
{
if ('object' != typeof this.events[EventName])
this.events[EventName] = new Object();
if ('undefined' == typeof this.events[EventName][EventFunctionId])
this.events[EventName][EventFunctionId] = EventFunction;
}
};
/* ---------------------------------------------------------------------------------------------------------------------------- */
xajax.ext.tabManager.tabBar = function(config)
{
this.config = config;
this.tabBar = xajax.$(config.tabPanel);
this.tabContent = xajax.$(config.tabContent);
this.tabs = {
};
this.activeTab = null;
this.lastActiveTab = null;
this.interval = null;
this.maxWidth = $(this.tabBar).innerWidth();
this.tabWidth = 0;
this.tabHeight = $(this.tabBar).innerHeight();
var leftHandle = document.createElement('div');
leftHandle.className = "leftHandle";
var rightHandle = document.createElement('div');
rightHandle.className = "rightHandle";
var foo = this;
leftHandle.onmouseover = function()
{
foo.scroll(4);
}
rightHandle.onmouseover = function()
{
foo.scroll(-4);
}
leftHandle.onmouseout = function()
{
foo.scrollStop();
}
rightHandle.onmouseout = function()
{
foo.scrollStop();
}
leftHandle.style.display = 'none';
rightHandle.style.display = 'none';
this.leftHandle = leftHandle;
this.rightHandle = rightHandle;
var tabContainer = document.createElement('div');
tabContainer.id = "tabManager_Container_" + config.tabPanel;
tabContainer.style.position = "absolute";
tabContainer.style.top = "0px";
tabContainer.style.left = "0px";
tabContainer.style.right = "0px";
// possible IE abs pos fix
//tabContainer.style.width = this.maxWidth + "px";
tabContainer.style.height = this.tabHeight + "px";
tabContainer.style.overflow = "hidden";
var tabPanel = document.createElement('div');
tabPanel.style.position = "absolute";
tabPanel.style.height = this.tabHeight + "px";
this.tabBar.appendChild(leftHandle);
this.tabBar.appendChild(tabContainer);
this.tabBar.appendChild(rightHandle);
tabContainer.appendChild(tabPanel);
this.tabPanel = tabPanel;
this.tabContainer = tabContainer;
if ('undefined' != typeof config.cssClass)
{
this.tabPanel.className = this.tabBar.className + " " + config.cssClass;
}
this.addPanel = function(config)
{
if ('undefined' != typeof this.tabs[config.id])
{
if (config.hide)
return;
this.tabs[config.id].fire("destroy");
this.show(config.id);
return;
};
config._parent = this;
this.tabs[config.id] = new xajax.ext.tabPanel(config);
if (true != config.hide)
this.show(config.id);
this.tabWidth += this.tabs[config.id].getWidth();
// possible IE abs pos fix
//this.tabPanel.style.width=this.tabWidth+"px";
if (this.tabWidth > this.maxWidth)
{
this.leftHandle.style.display = 'block';
this.rightHandle.style.display = 'block';
var lspace = $(this.leftHandle).outerWidth() + 1;
var rspace = $(this.rightHandle).outerWidth() + 1;
this.tabContainer.style.left = lspace + "px";
this.tabContainer.style.right = rspace + "px";
}
};
this.show = function(id)
{
if ('undefined' == typeof this.tabs[id])
return;
if (null != this.activeTab)
this.activeTab.hide();
this.tabs[id].show();
this.lastActiveTab = this.activeTab;
this.activeTab = this.tabs[id];
var pos = $('#tabPanel_' + id).position();
var elm_left = pos.left;
var elm_max = pos.left + parseInt(this.tabs[id].tabWidth);
var container_width = $(this.tabContainer).innerWidth();
var panel_pos = $(this.tabPanel).position();
var scroll_left = panel_pos.left;
var visible_left = 0 - scroll_left;
var visible_right = visible_left + container_width;
if (elm_left < visible_left)
{
$(this.tabPanel).animate(
{
left: (0 - elm_left) + "px"
});
}
else if (elm_max > visible_right)
{
$(this.tabPanel).animate(
{
left: (container_width - elm_max - 22) + "px"
});
}
};
this.setContent = function(id, content)
{
if ('undefined' != typeof this.tabs[id])
return;
this.tabs[id].setContent(content);
};
this.setTitle = function(id, title)
{
if ('undefined' == typeof this.tabs[id])
return;
this.tabs[id].setTitle(title);
};
this.updateInnerWidth = function()
{
var tmpwidth = 0;
for (a in this.tabs)
{
tmpwidth += this.tabs[a].getWidth();
}
this.tabWidth = tmpwidth + 22;
};
this.closePanel = function(id)
{
if ('undefined' == typeof this.tabs[id])
return;
if (null != this.lastActiveTab)
{
if (this.activeTab.id == id)
this.show(this.lastActiveTab.id);
}
this.tabs[id].destroy();
delete (this.tabs[id]);
this.updateInnerWidth();
if (this.tabWidth < this.maxWidth)
{
this.leftHandle.style.display = 'none';
this.rightHandle.style.display = 'none';
this.tabContainer.style.left = "0px";
this.tabContainer.style.right = "0px";
// possible IE fix
//this.tabContainer.style.width = this.maxWidth + "px";
this.tabPanel.style.left = "0px";
}
};
this.on = function(EventName, id, EventFunction, EventFunctionId)
{
this.tabs[id].on(EventName, EventFunction, EventFunctionId);
}
this.scroll = function(value)
{
if (null != this.interval)
return;
var tab = this;
var i = value;
this.interval = setInterval(function()
{
var lspace = $(tab.leftHandle).innerWidth() + 1;
var rspace = $(tab.rightHandle).innerWidth() + 1;
var sLeft = tab.tabPanel.style.left;
var iLeft = sLeft.replace("px", "");
if ("" == iLeft)
iLeft = 0;
iLeft = parseInt(iLeft);
iLeft += i;
var iMin = tab.maxWidth - tab.tabWidth - rspace - lspace;
if ((iLeft > 0) || ((iLeft < iMin) && (i < 0)))
{
tab.scrollStop();
return;
}
tab.tabPanel.style.left = iLeft + "px";
}, 25);
}
this.scrollStop = function()
{
if (null == this.interval)
return;
clearInterval(this.interval);
this.interval = null;
}
this.destroy = function()
{
for (a in this.tabs)
{
this.tabs[a].destroy();
delete (this.tabs[a]);
}
};
};
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.ext.tabManager.create = function(id, config)
{
if ("undefined" == typeof xajax.ext.tabManager.instances[id])
{
try
{
xajax.ext.tabManager.instances[id] = new xajax.ext.tabManager.tabBar(config);
}
catch (ex)
{
}
}
}
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.ext.tabManager.addPanel = function(id, config)
{
try
{
xajax.ext.tabManager.instances[id].addPanel(config);
}
catch (ex)
{
}
}
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.ext.tabManager.showPanel = function(id, sPanel)
{
try
{
xajax.ext.tabManager.instances[id].show(sPanel);
}
catch (ex)
{
}
}
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.ext.tabManager.setTitle = function(id, sPanel, title)
{
try
{
xajax.ext.tabManager.instances[id].setTitle(sPanel, title);
}
catch (ex)
{
}
}
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.ext.tabManager.on = function(id, sEventName, sTarget, sEventFunc, sEventId)
{
xajax.ext.tabManager.instances[id].on(sEventName, sTarget, sEventFunc, sEventId);
}
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.ext.tabManager.closePanel = function(id, sPanel)
{
xajax.ext.tabManager.instances[id].closePanel(sPanel);
}
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.ext.tabManager.destroy = function(id)
{
xajax.ext.tabManager.instances[id].destroy();
delete (xajax.ext.tabManager.instances[id]);
}
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.command.handler.register('tm_create', function(args)
{
args.cmdFullName = 'ext.tabManager.create';
xajax.ext.tabManager.create(args.id, args.data);
return true;
});
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.command.handler.register('tm_at', function(args)
{
args.cmdFullName = 'ext.tabManager.addPanel';
xajax.ext.tabManager.addPanel(args.id, args.data);
return true;
});
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.command.handler.register('tm_on', function(args)
{
try
{
args.cmdFullName = 'ext.tabManager.on';
eval("var sEvent = " + args.data.e + ";");
xajax.ext.tabManager.on(args.id, args.data.n, args.data.p, sEvent, args.data.key);
}
catch (ex)
{
//console.log(ex);
}
return true;
});
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.command.handler.register('tm_cl', function(args)
{
try
{
args.cmdFullName = 'ext.tabManager.closePanel';
xajax.ext.tabManager.closePanel(args.id, args.data);
}
catch (ex)
{
debugObj(ex);
}
return true;
});
/* ------------------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.command.handler.register('tm_sp', function(args)
{
args.cmdFullName = 'ext.tabManager.showPanel';
xajax.ext.tabManager.showPanel(args.id, args.data);
return true;
});
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.command.handler.register('tm_st', function(args)
{
try
{
args.cmdFullName = 'ext.tabManager.setTitle';
xajax.ext.tabManager.setTitle(args.id, args.data.panel, args.data.title);
}
catch (ex)
{
//console.log(ex);
}
return true;
});
/* ------------------------------------------------------------------------------------------------------------------------------ */
xajax.command.handler.register('tm_de', function(args)
{
try
{
args.cmdFullName = 'ext.tabManager.destroy';
xajax.ext.tabManager.destroy(args.id);
}
catch (ex)
{
debugObj(ex);
}
return true;
});
/* ------------------------------------------------------------------------------------------------------------------------------ */
}
installtabManager();

View File

@@ -0,0 +1,312 @@
<?php
define('FILE_APPEND', 1);
/*
File: tableUpdater.inc.php
Contains a class that can be used to invoke DOM calls on the browser which
will create or update an HTML table.
Title: clsTableUpdater class
Please see <copyright.inc.php> for a detailed description, copyright
and license information.
*/
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';
}
//require_once dirname(__FILE__) . '/xajaxCometPlugin.inc.php';
/*
Class: clsTableUpdater
*/
class clsCometStreaming extends xajaxResponsePlugin
{
/*
String: sDefer
Used to store the state of the scriptDeferral configuration setting. When
script deferral is desired, this member contains 'defer' which will request
that the browser defer loading of the javascript until the rest of the page
has been loaded.
*/
var $sDefer;
/*
String: sJavascriptURI
Used to store the base URI for where the javascript files are located. This
enables the plugin to generate a script reference to it's javascript file
if the javascript code is NOT inlined.
*/
var $sJavascriptURI;
/*
Boolean: bInlineScript
Used to store the value of the inlineScript configuration option. When true,
the plugin will return it's javascript code as part of the javascript header
for the page, else, it will generate a script tag referencing the file by
using the <clsTableUpdater->sJavascriptURI>.
*/
var $bInlineScript;
/*
Function: clsTableUpdater
Constructs and initializes an instance of the table updater class.
*/
function clsCometStreaming()
{
$this->sDefer = '';
$this->sJavascriptURI = '';
$this->bInlineScript = false;
}
/*
Function: configure
Receives configuration settings set by <xajax> or user script calls to
<xajax->configure>.
sName - (string): The name of the configuration option being set.
mValue - (mixed): The value being associated with the configuration option.
*/
function configure($sName, $mValue)
{
if ('scriptDeferral' == $sName) {
if (true === $mValue || false === $mValue) {
if ($mValue) $this->sDefer = 'defer ';
else $this->sDefer = '';
}
} else if ('javascript URI' == $sName) {
$this->sJavascriptURI = $mValue;
} else if ('inlineScript' == $sName) {
if (true === $mValue || false === $mValue)
$this->bInlineScript = $mValue;
}
}
/*
Function: generateClientScript
Called by the <xajaxPluginManager> during the script generation phase. This
will either inline the script or insert a script tag which references the
<tableUpdater.js> file based on the value of the <clsTableUpdater->bInlineScript>
configuration option.
*/
function generateClientScript()
{
if ($this->bInlineScript)
{
echo "\n<script type='text/javascript' " . $this->sDefer . "charset='UTF-8'>\n";
echo "/* <![CDATA[ */\n";
include(dirname(__FILE__) . 'xajax_plugins/response/comet/comet.js');
echo "/* ]]> */\n";
echo "</script>\n";
} else {
echo "\n<script type='text/javascript' src='" . $this->sJavascriptURI . "xajax_plugins/response/comet/comet.js' " . $this->sDefer . "charset='UTF-8'></script>\n";
}
}
}
class xajaxCometResponse extends xajaxResponse
{
var $bHeaderSent = false;
/*
Function: xajaxCometResponse
calls parent function xajaxResponse();
*/
function xajaxCometResponse()
{
parent::xajaxResponse();
}
/*
Function: printOutput
override the original printOutput function. It's no longer needed since the output is already sent.
*/
function printOutput()
{
if ( "HTML5DRAFT" == $_GET['xjxstreaming']) {
$response = "";
$response .= "Event: xjxendstream\n";
$response .= "data: done\n";
$response .= "\n";
print $response;
}
}
/*
Function: flush_XHR
Flushes the command queue for comet browsers.
*/
function flush_XHR()
{
if (!$this->bHeaderSent)
{
$this->_sendHeaders();
$this->bHeaderSent=true;
}
ob_start();
$this->_printResponse_XML();
$c = ob_get_contents();
ob_get_clean();
$c = str_replace(chr(1)," ",$c);
$c = str_replace(chr(2)," ",$c);
$c = str_replace(chr(31)," ",$c);
$c = str_replace(""," ",$c);
if ($c == "<xjx></xjx>") return false;
print $c;
ob_flush();
flush();
$this->sleep(1.1);
}
/*
Function: flush_activeX
Flushes the command queue for ActiveX browsers.
*/
function flush_activeX()
{
ob_start();
$this->_printResponse_XML();
$c = ob_get_contents();
ob_get_clean();
$c = '<?xml version="1.0" ?>'.$c;
$c = str_replace('"','\"',$c);
$c = str_replace("\n",'\n',$c);
$c = str_replace("\r",'\r',$c);
$response = "";
$response .= "<script>top.document.callback(\"";
$response .= $c;
$response .= "\");</script>";
print $response;
ob_flush();
flush();
$this->sleep(0.99);
}
/*
Function: flush_HTML5DRAFT
Flushes the command queue for HTML5DRAFT browsers.
*/
function flush_HTML5DRAFT()
{
if (!$this->bHeaderSent)
{
header("Content-Type: application/x-dom-event-stream");
$this->bHeaderSent=1;
}
ob_start();
$this->_printResponse_XML();
$c = ob_get_contents();
ob_get_clean();
$c = str_replace("\n",'\n',$c);
$c = str_replace("\r",'\r',$c);
$response = "";
$response .= "Event: xjxstream\n";
$response .= "data: $c\n";
$response .= "\n";
print $response;
ob_flush();
flush();
$this->sleep(1);
}
/*
Function: flush
Determines which browser is wating for a response and calls the according flush function.
*/
function flush()
{
if (0 == count($this->aCommands)) return false;
if ("xhr" == $_SERVER['HTTP_STREAMING'])
{
$this->flush_XHR();
}
elseif ( "HTML5DRAFT" == $_GET['xjxstreaming'])
{
$this->flush_HTML5DRAFT();
}
else
{
$this->flush_activeX();
}
$this->aCommands=array();
}
/*
Function: sleep
Very accurate sleep function.
*/
function sleep($seconds)
{
usleep(floor($seconds*1000000));
}
function file_put_contents($n, $d, $flag = false)
{
$mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
$f = @fopen($n, $mode);
if ($f === false)
{
return 0;
} else
{
if (is_array($d)) $d = implode($d);
$bytes_written = fwrite($f, $d);
fclose($f);
return $bytes_written;
}
}
}
$objPluginManager =& xajaxPluginManager::getInstance();
$objPluginManager->registerPlugin(new clsCometStreaming());

View File

@@ -0,0 +1,516 @@
/*
File: comet.js
Title: Comet plugin for xajax
*/
/*
@package comet plugin
@version $Id:
@copyright Copyright (c) 2007 by Steffen Konerow (IE)
@license http://www.xajaxproject.org/bsd_license.txt BSD License
*/
/*
Class: xajax.ext.comet
This class contains all functions for using comet streaming with xajax.
*/
try {
if (undefined == xajax.ext)
xajax.ext = {};
} catch (e) {
}
try {
if (undefined == xajax.ext.comet)
xajax.ext.comet = {};
} catch (e) {
alert("Could not create xajax.ext.comet namespace");
}
// create Shorthand for xajax.ext.comet
xjxEc = xajax.ext.comet;
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: detectSupport
Detects browser for using fallback methods instead of multipart XHR responses.
*/
xjxEc.detectSupport = function()
{
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1)
{
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla')
{
return navigator.userAgent.substr(0,agt.indexOf('\/'));
}
else return 'Netscape';
}
else if (agt.indexOf(' ') != -1) return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
// if (navigator.appVersion.indexOf("MSIE")!=-1)
// {
// var version,temp;
// temp=navigator.appVersion.split("MSIE")
// version=parseFloat(temp[1])
// if (version>=5.5) return "MSIE";
// }
// if ( "undefined" != typeof window.opera )
// {
// return "OPERA";
// }
// if ( "undefined" != typeof window.Iterator )
// {
// return "FF2";
// }
return false;
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: prepareRequestXHR
Prepares the XMLHttpRequest object for this xajax request in FF/Safari browsers.
*/
xjxEc.prepareRequestXHR = function (oRequest)
{
if (true == oRequest.comet)
{
var xx = xajax;
var xt = xx.tools;
oRequest.request = xt.getRequestObject();
oRequest.setRequestHeaders = function(headers) {
if ('object' == typeof headers) {
for (var optionName in headers)
this.request.setRequestHeader(optionName, headers[optionName]);
}
}
oRequest.setCommonRequestHeaders = function() {
this.setRequestHeaders(this.commonHeaders);
}
oRequest.setPostRequestHeaders = function() {
this.setRequestHeaders(this.postHeaders);
}
oRequest.setGetRequestHeaders = function() {
this.setRequestHeaders(this.getHeaders);
}
oRequest.applyRequestHeaders = function() {
}
oRequest.setCommonRequestHeaders = function() {
this.request.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
this.request.setRequestHeader('streaming', 'xhr');
if (typeof(oRequest.header) == "object")
{
for (a in oRequest.header)
this.request.setRequestHeader(a, oRequest.header[a]);
}
}
oRequest.comet = {};
oRequest.comet.LastPosition = 0;
var pollLatestResponse = function() {
xjxEc.responseProcessor.XHR(oRequest);
}
oRequest.pollTimer = setInterval(pollLatestResponse, 80);
oRequest.request.onreadystatechange = function()
{
if (oRequest.request.readyState < 3)
return;
if (oRequest.request.readyState == 4)
{
clearInterval(oRequest.pollTimer);
xjxEc.responseProcessor.XHR(oRequest);
//xajax.responseReceived(oRequest);
xajax.completeResponse(oRequest);
return;
}
}
oRequest.finishRequest = function()
{
return this.returnValue;
}
if ('undefined' != typeof oRequest.userName && 'undefined' != typeof oRequest.password)
{
oRequest.open = function()
{
this.request.open(
this.method,
this.requestURI,
true,
oRequest.userName,
oRequest.password);
}
} else
{
oRequest.open = function()
{
this.request.open(
this.method,
this.requestURI,
true);
}
}
if ('POST' == oRequest.method) { // W3C: Method is case sensitive
oRequest.applyRequestHeaders = function() {
this.setCommonRequestHeaders();
try {
this.setPostRequestHeaders();
} catch (e) {
this.method = 'GET';
this.requestURI += this.requestURI.indexOf('?')== -1 ? '?' : '&';
this.requestURI += this.requestData;
this.requestData = '';
if (0 == this.requestRetry) this.requestRetry = 1;
throw e;
}
}
} else {
oRequest.applyRequestHeaders = function() {
this.setCommonRequestHeaders();
this.setGetRequestHeaders();
}
}
return;
}
return xjxEc.prepareRequest(oRequest);
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: connect_htmlfile
Create a hidden iframe for IE
*/
xjxEc.connect_htmlfile = function (url, callback,oRequest)
{
try {
xjxEc.transferDoc = new ActiveXObject("htmlfile");
xjxEc.transferDoc.open();
xjxEc.transferDoc.write("<html>");
xjxEc.transferDoc.write("<script>document.domain='http://192.168.1.21/';</script>");
xjxEc.transferDoc.write("</html>");
xjxEc.transferDoc.close();
xjxEc.ifrDiv = xjxEc.transferDoc.createElement("div");
xjxEc.transferDoc.body.appendChild(xjxEc.ifrDiv);
xjxEc.ifrDiv.innerHTML = "<iframe src='" + url + "'></iframe>";
xjxEc.transferDoc.callback = function (response) {
callback(response,oRequest);
};
} catch (ex) {
}
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: prepareRequestActiveX
Prepares the Iframe for streaming with active X
*/
xjxEc.prepareRequestActiveX = function(oRequest) {
if (true == oRequest.comet) {
var xx = xajax;
var xt = xx.tools;
oRequest.requestURI += oRequest.requestURI.indexOf('?')== -1 ? '?' : '&';
oRequest.requestURI += oRequest.requestData;
oRequest.requestData = '';
try {
xjxEc.connect_htmlfile(oRequest.requestURI,xjxEc.responseProcessor.ActiveX,oRequest);
if (0 < oRequest.requestRetry) oRequest.requestRetry = 0;
} catch (ex) {
}
return;
}
return xjxEc.prepareRequest(oRequest);
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: prepareRequestHTMLDRAFT
Prepares streaming with HTML 5 Draft
*/
xjxEc.prepareRequestHTMLDRAFT = function(oRequest) {
if (true == oRequest.comet) {
var xx = xajax;
var xt = xx.tools;
oRequest.requestURI += oRequest.requestURI.indexOf('?')== -1 ? '?' : '&';
oRequest.requestURI += oRequest.requestData;
oRequest.requestURI += "&xjxstreaming=HTML5DRAFT";
try {
var uri = oRequest.requestURI;
var es = document.createElement("event-source");
es.setAttribute("src", uri);
es.setAttribute("width", 200);
es.setAttribute("height", 200);
es.style.display="block";
callback = function(event)
{
xjxEc.responseProcessor.HTMLDRAFT(event.data,oRequest);
};
remove = function() {
es.removeEventListener("xjxstream",callback,false);
es.removeEventListener("xjxendstream",remove,false);
//document.body.removeChild(es);
}
es.addEventListener("xjxstream",callback,false);
es.addEventListener("xjxendstream",remove,false);
document.body.appendChild(es);
if (0 < oRequest.requestRetry) oRequest.requestRetry = 0;
}
catch (ex)
{
}
return;
}
return xjxEc.prepareRequest(oRequest);
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: responseProcessor.XHR
Processes the streaming response for FF/Safari
*/
xajax.debug={};
xajax.debug.prepareDebugText = function(text) {
try {
text = text.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\n/g, '<br />');
return text;
} catch (e) {
xajax.debug.stringReplace = function(haystack, needle, newNeedle) {
var segments = haystack.split(needle);
haystack = '';
for (var i = 0; i < segments.length; ++i) {
if (0 != i)
haystack += newNeedle;
haystack += segments[i];
}
return haystack;
}
xajax.debug.prepareDebugText = function(text) {
text = xajax.debug.stringReplace(text, '&', '&amp;');
text = xajax.debug.stringReplace(text, '<', '&lt;');
text = xajax.debug.stringReplace(text, '>', '&gt;');
text = xajax.debug.stringReplace(text, '\n', '<br />');
return text;
}
xajax.debug.prepareDebugText(text);
}
}
xjxEc.responseProcessor={}
xjxEc.responseProcessor.XHR = function(oRequest) {
var xx = xajax;
var xt = xx.tools;
var xcb = xx.callback;
var gcb = xcb.global;
var lcb = oRequest.callback;
var oRet = oRequest.returnValue;
if ("" == oRequest.request.responseText) return;
var allMessages = oRequest.request.responseText;
do {
var unprocessed = allMessages.substring(oRequest.comet.LastPosition);
var messageXMLEndIndex = unprocessed.indexOf("</xjx>");
if (messageXMLEndIndex!=-1) {
var endOfFirstMessageIndex = messageXMLEndIndex + "</xjx>".length;
var anUpdate = unprocessed.substring(0, endOfFirstMessageIndex);
var cmd = (new DOMParser()).parseFromString(anUpdate, "text/xml");
try {
var seq = 0;
var child = cmd.documentElement.firstChild;
xt.xml.processFragment(child, seq, oRequest);
} catch (ex) {
}
xt.queue.process(xx.response);
oRequest.comet.LastPosition += endOfFirstMessageIndex;
}
} while (messageXMLEndIndex != -1);
return oRet;
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: responseProcessor.ActiveX
Processes the streaming response for IE
*/
xjxEc.responseProcessor.ActiveX = function(response,oRequest) {
response.replace('\"','"');
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);
}
return oRet;
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: responseProcessor.HTMLDRAFT
Processes the streaming response for HTML 5 Draft Browsers (Opera 9+)
*/
xjxEc.responseProcessor.HTMLDRAFT = function(response,oRequest) {
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);
}
return oRet;
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
Function: submitRequestActiveX
Supresses the xajax.submitRequest() function call for IE in streaming calls.
*/
xjxEc.submitRequestActiveX = function(oRequest) {
if (true == oRequest.comet) return;
xjxEc.submitRequest(oRequest);
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
variable setup. Detects IE and replaces the according functions
*/
xjxEc.prepareRequest = xajax.prepareRequest;
xjxEc.stream_support = xjxEc.detectSupport();
switch (xjxEc.stream_support)
{
case "Internet Explorer" :
xajax.prepareRequest = xjxEc.prepareRequestActiveX;
xjxEc.submitRequest=xajax.submitRequest;
xajax.submitRequest=xjxEc.submitRequestActiveX;
break;
case "Firefox" :
case "Safari" :
xajax.prepareRequest = xjxEc.prepareRequestXHR;
break;
case "Opera" :
xajax.prepareRequest = xjxEc.prepareRequestHTMLDRAFT;
xjxEc.submitRequest=xajax.submitRequest;
xajax.submitRequest=xjxEc.submitRequestActiveX;
break;
default : alert("Xajax.Ext.Comet: Your browser does not support comet streaming or is not yet supported by this plugin!");
}
// -------------------------------------------------------------------------------------------------------------------------------------
/*
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;
}
}
}
// -------------------------------------------------------------------------------------------------------------------------------------

View File

@@ -0,0 +1,232 @@
<?php
/*
File: xajaxCometFunction.inc.php
Contains the xajaxCometFunction class
Title: xajaxCometFunction class
Please see <copyright.inc.php> for a detailed description, copyright
and license information.
*/
/*
@package xajax
@version $Id: xajaxCometFunction.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $
@copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson
@license http://www.xajaxproject.org/bsd_license.txt BSD License
*/
/*
Class: xajaxCometFunction
Construct instances of this class to define functions that will be registered
with the <xajax> request processor. This class defines the parameters that
are needed for the definition of a xajax enabled function. While you can
still specify functions by name during registration, it is advised that you
convert to using this class when you wish to register external functions or
to specify call options as well.
*/
class xajaxCometFunction
{
/*
String: sAlias
An alias to use for this function. This is useful when you want
to call the same xajax enabled function with a different set of
call options from what was already registered.
*/
var $sAlias;
/*
Object: uf
A string or array which defines the function to be registered.
*/
var $uf;
/*
String: sInclude
The path and file name of the include file that contains the function.
*/
var $sInclude;
/*
Array: aConfiguration
An associative array containing call options that will be sent to the
browser curing client script generation.
*/
var $aConfiguration;
/*
Function: xajaxCometFunction
Constructs and initializes the <xajaxCometFunction> object.
$uf - (mixed): A function specification in one of the following formats:
- a three element array:
(string) Alternate function name: when a method of a class has the same
name as another function in the system, you can provide an alias to
help avoid collisions.
(object or class name) Class: the name of the class or an instance of
the object which contains the function to be called.
(string) Method: the name of the method that will be called.
- a two element array:
(object or class name) Class: the name of the class or an instance of
the object which contains the function to be called.
(string) Method: the name of the method that will be called.
- a string:
the name of the function that is available at global scope (not in a
class.
$sInclude - (string, optional): The path and file name of the include file
that contains the class or function to be called.
$aConfiguration - (array, optional): An associative array of call options
that will be used when sending the request from the client.
Examples:
$myFunction = array('alias', 'myClass', 'myMethod');
$myFunction = array('alias', &$myObject, 'myMethod');
$myFunction = array('myClass', 'myMethod');
$myFunction = array(&$myObject, 'myMethod');
$myFunction = 'myFunction';
$myUserFunction = new xajaxCometFunction($myFunction, 'myFile.inc.php', array(
'method' => 'get',
'mode' => 'synchronous'
));
$xajax->register(XAJAX_FUNCTION, $myUserFunction);
*/
function xajaxCometFunction($uf, $sInclude=NULL, $aConfiguration=array())
{
$this->sAlias = '';
$this->uf =& $uf;
$this->sInclude = $sInclude;
$this->aConfiguration = array();
foreach ($aConfiguration as $sKey => $sValue)
$this->configure($sKey, $sValue);
if (is_array($this->uf) && 2 < count($this->uf))
{
$this->sAlias = $this->uf[0];
$this->uf = array_slice($this->uf, 1);
}
//SkipDebug
if (is_array($this->uf) && 2 != count($this->uf))
trigger_error(
'Invalid function declaration for xajaxCometFunction.',
E_USER_ERROR
);
//EndSkipDebug
}
/*
Function: getName
Get the name of the function being referenced.
Returns:
string - the name of the function contained within this object.
*/
function getName()
{
// Do not use sAlias here!
if (is_array($this->uf))
return $this->uf[1];
return $this->uf;
}
/*
Function: configure
Call this to set call options for this instance.
*/
function configure($sName, $sValue)
{
if ('alias' == $sName)
$this->sAlias = $sValue;
else
$this->aConfiguration[$sName] = $sValue;
}
/*
Function: generateRequest
Constructs and returns a <xajaxRequest> object which is capable
of generating the javascript call to invoke this xajax enabled
function.
*/
function generateRequest($sXajaxPrefix)
{
$sAlias = $this->getName();
if (0 < strlen($this->sAlias))
$sAlias = $this->sAlias;
return new xajaxRequest("{$sXajaxPrefix}{$sAlias}");
}
/*
Function: generateClientScript
Called by the <xajaxPlugin> that is referencing this function
reference during the client script generation phase. This function
will generate the javascript function stub that is sent to the
browser on initial page load.
*/
function generateClientScript($sXajaxPrefix)
{
$sFunction = $this->getName();
$sAlias = $sFunction;
if (0 < strlen($this->sAlias))
$sAlias = $this->sAlias;
echo "{$sXajaxPrefix}{$sAlias} = function() { ";
echo "return xajax.request( ";
echo "{ xjxcomet: '{$sFunction}' }, ";
echo "{ parameters: arguments, mode:'comet'";
$sSeparator = ", ";
foreach ($this->aConfiguration as $sKey => $sValue)
echo "{$sSeparator}{$sKey}: {$sValue}";
echo " } ); ";
echo "};\n";
}
/*
Function: call
Called by the <xajaxPlugin> that references this function during the
request processing phase. This function will call the specified
function, including an external file if needed and passing along
the specified arguments.
*/
function call($aArgs=array())
{
$objResponseManager =& xajaxResponseManager::getInstance();
if (NULL != $this->sInclude)
{
ob_start();
require_once $this->sInclude;
$sOutput = ob_get_clean();
//SkipDebug
if (0 < strlen($sOutput))
{
$sOutput = 'From include file: ' . $this->sInclude . ' => ' . $sOutput;
$objResponseManager->debug($sOutput);
}
//EndSkipDebug
}
$mFunction = $this->uf;
$objResponseManager->append(call_user_func_array($mFunction, $aArgs));
}
}
?>

View File

@@ -0,0 +1,165 @@
<?php
/*
File: googleMap.inc.php
Contains a class that can be used to invoke DOM calls on the browser which
will create or update a google map.
Title: clsGoogleMap class
Please see <copyright.inc.php> for a detailed description, copyright
and license information.
*/
//$sBaseFolder = dirname(dirname(dirname(__FILE__)));
//$sXajaxCore = $sBaseFolder . '/xajax_core';
//require $sXajaxCore . '/xajaxPlugin.inc.php';
//require $sXajaxCore . '/xajaxPluginManager.inc.php';
/*
Class: clsGoogleMap
*/
class clsGoogleMap extends xajaxResponsePlugin
{
/*
String: sJavascriptURI
Used to store the base URI for where the javascript files are located. This
enables the plugin to generate a script reference to it's javascript file
if the javascript code is NOT inlined.
*/
var $sJavascriptURI;
/*
Boolean: bInlineScript
Used to store the value of the inlineScript configuration option. When true,
the plugin will return it's javascript code as part of the javascript header
for the page, else, it will generate a script tag referencing the file by
using the <clsTableUpdater->sJavascriptURI>.
*/
var $bInlineScript;
/*
String: sGoogleSiteKey
The key that google has assigned to your site. Set this with <clsGoogleMap->setKey>
*/
/*
Function: clsTableUpdater
Constructs and initializes an instance of the table updater class.
*/
function clsGoogleMap()
{
$this->sJavascriptURI = '';
$this->bInlineScript = true;
}
/*
Function: configure
Receives configuration settings set by <xajax> or user script calls to
<xajax->configure>.
sName - (string): The name of the configuration option being set.
mValue - (mixed): The value being associated with the configuration option.
*/
function configure($sName, $mValue)
{
if ('javascript URI' == $sName) {
$this->sJavascriptURI = $mValue;
} else if ('inlineScript' == $sName) {
if (true === $mValue || false === $mValue)
$this->bInlineScript = $mValue;
}
}
/*
Function: generateClientScript
Called by the <xajaxPluginManager> during the script generation phase. This
will either inline the script or insert a script tag which references the
<tableUpdater.js> file based on the value of the <clsTableUpdater->bInlineScript>
configuration option.
*/
function generateClientScript()
{
echo "\n<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=";
echo $this->sGoogleSiteKey;
echo "' type='text/javascript'>\n</script>\n";
echo "\n<script type='text/javascript' charset='UTF-8'>\n";
echo "/* <![CDATA[ */\n";
echo "maps = {};\n";
echo "xajax.commands['gm:cr'] = function(args) {\n";
echo "\tmaps[args.data] = new GMap2(args.objElement);\n";
echo "\tvar ptCenter = new GLatLng(0, 10);\n";
echo "\tmaps[args.data].setCenter(ptCenter, 10);\n";
echo "\tmaps[args.data].addControl(new GSmallMapControl());\n";
echo "\tmaps[args.data].addControl(new GMapTypeControl());\n";
echo "\tmaps[args.data].setMapType(maps[args.data].getMapTypes()[2]);\n";
echo "}\n";
echo "xajax.commands['gm:zm'] = function(args) {\n";
echo "\tmaps[args.id].setZoom(parseInt(args.data));\n";
echo "}\n";
echo "xajax.commands['gm:sm'] = function(args) {\n";
echo "\tvar ptCenter = new GLatLng(args.data[0], args.data[1]);\n";
echo "\tvar markerNew = new GMarker(ptCenter);\n";
echo "\tmarkerNew.text = args.data[2];\n";
echo "\tmaps[args.id].addOverlay(markerNew);\n";
echo "\tGEvent.addListener(maps[args.id], 'click', function(marker, point) {\n";
echo "\t\tif (marker && undefined != marker.openInfoWindowHtml) {\n";
echo "\t\t\tmarker.openInfoWindowHtml(marker.text);\n";
echo "\t\t}\n";
echo "\t} );\n";
echo "}\n";
echo "/* ]]> */\n";
echo "</script>\n";
}
function getName()
{
return get_class($this);
}
function setGoogleSiteKey($sKey)
{
$this->sGoogleSiteKey = $sKey;
}
function create($sMap, $sParentId)
{
$command = array('n'=>'gm:cr', 't'=>$sParentId);
$this->addCommand($command, $sMap);
}
function zoom($sMap, $nZoom) {
$command = array('n'=>'gm:zm', 't'=>$sMap);
$this->addCommand($command, $nZoom);
}
function setMarker($sMap, $nLat, $nLon, $sText) {
$this->addCommand(
array('n'=>'gm:sm', 't'=>$sMap),
array($nLat, $nLon, $sText)
);
}
function moveTo($sMap, $nLat, $nLon) {
// 39.928005,
// -82.70784,
// 15);
$command = array('n'=>'et_ar', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, $row);
}
}
$objPluginManager =& xajaxPluginManager::getInstance();
$objPluginManager->registerPlugin(new clsGoogleMap());

View File

@@ -0,0 +1,151 @@
<?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';
}
//require_once dirname(__FILE__) . '/xajaxCometPlugin.inc.php';
/*
Class: clsTableUpdater
*/
class clsPreloader extends xajaxResponsePlugin
{
/*
String: sDefer
Used to store the state of the scriptDeferral configuration setting. When
script deferral is desired, this member contains 'defer' which will request
that the browser defer loading of the javascript until the rest of the page
has been loaded.
*/
var $sDefer;
/*
String: sJavascriptURI
Used to store the base URI for where the javascript files are located. This
enables the plugin to generate a script reference to it's javascript file
if the javascript code is NOT inlined.
*/
var $sJavascriptURI;
/*
Boolean: bInlineScript
Used to store the value of the inlineScript configuration option. When true,
the plugin will return it's javascript code as part of the javascript header
for the page, else, it will generate a script tag referencing the file by
using the <clsTableUpdater->sJavascriptURI>.
*/
var $bInlineScript;
var $aScripts = array();
var $aImages = array();
var $aStyles = array();
/*
Function: clsTableUpdater
Constructs and initializes an instance of the table updater class.
*/
function clsPreloader()
{
$this->sDefer = '';
$this->sJavascriptURI = '';
$this->bInlineScript = false;
}
/*
Function: configure
Receives configuration settings set by <xajax> or user script calls to
<xajax->configure>.
sName - (string): The name of the configuration option being set.
mValue - (mixed): The value being associated with the configuration option.
*/
function configure($sName, $mValue)
{
if ('scriptDeferral' == $sName) {
if (true === $mValue || false === $mValue) {
if ($mValue) $this->sDefer = 'defer ';
else $this->sDefer = '';
}
} else if ('javascript URI' == $sName) {
$this->sJavascriptURI = $mValue;
} else if ('inlineScript' == $sName) {
if (true === $mValue || false === $mValue)
$this->bInlineScript = $mValue;
}
}
/*
Function: generateClientScript
Called by the <xajaxPluginManager> during the script generation phase. This
will either inline the script or insert a script tag which references the
<tableUpdater.js> file based on the value of the <clsTableUpdater->bInlineScript>
configuration option.
*/
function generateClientScript()
{
if ($this->bInlineScript)
{
echo "\n<script type='text/javascript' " . $this->sDefer . "charset='UTF-8'>\n";
echo "/* <![CDATA[ */\n";
include(dirname(__FILE__) . 'xajax_plugins/response/preloader/preload.js');
echo "/* ]]> */\n";
echo "</script>\n";
} else {
echo "\n<script type='text/javascript' src='" . $this->sJavascriptURI . "xajax_plugins/response/preloader/preload.js' " . $this->sDefer . "charset='UTF-8'></script>\n";
echo "\n<script type='text/javascript'>";
print "try {";
echo "
try {
if (undefined == xajax.ext)
xajax.ext = {};
} catch (e) {
}
try {
if (undefined == xajax.ext.preloader)
xajax.ext.preloader = {};
} catch (e) {
alert('Could not create xajax.ext.preloader namespace');
}
";
echo "xajax.ext.preloader.aScripts = ".json_encode($this->aScripts).";\n";
echo "xajax.ext.preloader.aStyles = ".json_encode($this->aStyles).";\n";
echo "xajax.ext.preloader.aImages = ".json_encode($this->aImages).";\n";
echo "xajax.ext.preloader.ready=true;";
echo "} catch(ex) { alert(ex);}";
echo "</script>";
}
}
function addScript($uri) {
$this->aScripts[] = $uri;
}
function addImages($uri) {
$this->aImages[] = $uri;
}
function addStyleSheet($uri) {
$this->aStyles[] = $uri;
}
}
$objPluginManager =& xajaxPluginManager::getInstance();
$objPluginManager->registerPlugin(new clsPreloader());

View File

@@ -0,0 +1,46 @@
try {
if (undefined == xajax.ext)
xajax.ext = {};
} catch (e) {
}
try {
if (undefined == xajax.ext.preloader)
xajax.ext.preloader = {};
} catch (e) {
alert("Could not create xajax.ext.preloader namespace");
}
xajax.ext.preloader.aScripts = [];
xajax.ext.preloader.aImages = [];
xajax.ext.preloader.aStyles = [];
xajax.ext.preloader.ready = false;
xajax.ext.preloader.run = function() {
if (!xajax.ext.preloader.ready)
{
window.setTimout(xajax.ext.preloader.run,200);
return;
}
var splash = document.createElement("div");
splash.id = "inhalt";
document.body.appendChild(splash);
var l = xajax.ext.preloader.aScripts.length;
for (i=0;i<l;++i)
{
var command =
{
data : xajax.ext.preloader.aScripts[i],
onload : function() {alert(aScripts[i]+ " loaded");}
}
xajax.js.includeScript(command);
splash.innerHTML += xajax.ext.preloader.aScripts[i]+"\n<br />\n";
}
}
window.onload=xajax.ext.preloader.run;

View File

@@ -0,0 +1,227 @@
<?php
/*
File: tableUpdater.inc.php
Contains a class that can be used to invoke DOM calls on the browser which
will create or update an HTML table.
Title: clsTableUpdater class
Please see <copyright.inc.php> for a detailed description, copyright
and license information.
*/
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: clsTableUpdater
*/
class clsTableUpdater extends xajaxResponsePlugin
{
/*
String: sDefer
Used to store the state of the scriptDeferral configuration setting. When
script deferral is desired, this member contains 'defer' which will request
that the browser defer loading of the javascript until the rest of the page
has been loaded.
*/
var $sDefer;
/*
String: sJavascriptURI
Used to store the base URI for where the javascript files are located. This
enables the plugin to generate a script reference to it's javascript file
if the javascript code is NOT inlined.
*/
var $sJavascriptURI;
/*
Boolean: bInlineScript
Used to store the value of the inlineScript configuration option. When true,
the plugin will return it's javascript code as part of the javascript header
for the page, else, it will generate a script tag referencing the file by
using the <clsTableUpdater->sJavascriptURI>.
*/
var $bInlineScript;
/*
Function: clsTableUpdater
Constructs and initializes an instance of the table updater class.
*/
function clsTableUpdater()
{
$this->sDefer = '';
$this->sJavascriptURI = '';
$this->bInlineScript = true;
}
/*
Function: configure
Receives configuration settings set by <xajax> or user script calls to
<xajax->configure>.
sName - (string): The name of the configuration option being set.
mValue - (mixed): The value being associated with the configuration option.
*/
function configure($sName, $mValue)
{
if ('scriptDeferral' == $sName) {
if (true === $mValue || false === $mValue) {
if ($mValue) $this->sDefer = 'defer ';
else $this->sDefer = '';
}
} else if ('javascript URI' == $sName) {
$this->sJavascriptURI = $mValue;
} else if ('inlineScript' == $sName) {
if (true === $mValue || false === $mValue)
$this->bInlineScript = $mValue;
}
}
/*
Function: generateClientScript
Called by the <xajaxPluginManager> during the script generation phase. This
will either inline the script or insert a script tag which references the
<tableUpdater.js> file based on the value of the <clsTableUpdater->bInlineScript>
configuration option.
*/
function generateClientScript()
{
if ($this->bInlineScript)
{
echo "\n<script type='text/javascript' " . $this->sDefer . "charset='UTF-8'>\n";
echo "/* <![CDATA[ */\n";
include(dirname(__FILE__) . '/tableUpdater.js');
echo "/* ]]> */\n";
echo "</script>\n";
} else {
echo "\n<script type='text/javascript' src='" . $this->sJavascriptURI . "tableUpdater.js' " . $this->sDefer . "charset='UTF-8'>\n";
}
}
function getName()
{
return get_class($this);
}
// tables
function appendTable($table, $parent) {
$command = array('n'=>'et_at', 't'=>$parent);
$this->addCommand($command, $table);
}
function insertTable($table, $parent, $position) {
$command = array('n'=>'et_it', 't'=>$parent, 'p'=>$position);
$this->addCommand($command, $table);
}
function deleteTable($table) {
$this->addCommand(array('n'=>'et_dt'), $table);
}
// rows
function appendRow($row, $parent, $position = null) {
$command = array('n'=>'et_ar', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, $row);
}
function insertRow($row, $parent, $position = null, $before = null) {
$command = array('n'=>'et_ir', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
if (null != $before)
$command['c'] = $before;
$this->addCommand($command, $row);
}
function replaceRow($row, $parent, $position = null, $before = null) {
$command = array('n'=>'et_rr', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
if (null != $before)
$command['c'] = $before;
$this->addCommand($command, $row);
}
function deleteRow($parent, $position = null) {
$command = array('n'=>'et_dr', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, null);
}
function assignRow($values, $parent, $position = null, $start_column = null) {
$command = array('n'=>'et_asr', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
if (null != $start_column)
$command['c'] = $start_column;
$this->addCommand($command, $values);
}
function assignRowProperty($property, $value, $parent, $position = null) {
$command = array('n'=>'et_asr', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, array('p'=>$property, 'v'=>$value));
}
// columns
function appendColumn($column, $parent, $position = null) {
$command = array('n'=>'et_acol', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, $column);
}
function insertColumn($column, $parent, $position = null) {
$command = array('n'=>'et_icol', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, $column);
}
function replaceColumn($column, $parent, $position = null) {
$command = array('n'=>'et_rcol', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, $column);
}
function deleteColumn($parent, $position = null) {
$command = array('n'=>'et_dcol', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, null);
}
function assignColumn($values, $parent, $position = null, $start_row = null) {
$command = array('n'=>'et_ascol', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
if (null != $start_row)
$command['c'] = $start_row;
$this->addCommand($command, $values);
}
function assignColumnProperty($property, $value, $parent, $position = null) {
$command = array('n'=>'et_ascol', 't'=>$parent);
if (null != $position)
$command['p'] = $position;
$this->addCommand($command, array('p'=>$property, 'v'=>$value));
}
function assignCell($row, $column, $value) {
$this->addCommand(array('n'=>'et_asc', 't'=>$row, 'p'=>$column), $value);
}
function assignCellProperty($row, $column, $property, $value) {
$this->addCommand(array('n'=>'et_asc', 't'=>$row, 'p'=>$column), array('p'=>$property, 'v'=>$value));
}
}
$objPluginManager =& xajaxPluginManager::getInstance();
$objPluginManager->registerPlugin(new clsTableUpdater());

View File

@@ -0,0 +1,499 @@
// if xajax has not yet been initialized, wait a second and try again
// once xajax has been initialized, then install the table command
// handlers.
installTableUpdater = function() {
var xjxReady = false;
try {
if (xajax) xjxReady = true;
} catch (e) {
}
if (false == xjxReady) {
setTimeout('installTableUpdater();', 1000);
return;
}
try {
if (undefined == xajax.ext.tables)
xajax.ext.tables = {};
} catch (e) {
xajax.ext = {};
xajax.ext.tables = {};
}
// internal helper functions
xajax.ext.tables.internal = {};
xajax.ext.tables.internal.createTable = function(table) {
if ('string' != typeof (table))
throw { name: 'TableError', message: 'Invalid table name specified.' }
var newTable = document.createElement('table');
newTable.id = table;
// save the column configuration
xajax.ext.tables.appendHeader(table + '_header', newTable);
xajax.ext.tables.appendBody(table + '_body', newTable);
xajax.ext.tables.appendFooter(table + '_footer', newTable);
return newTable;
}
xajax.ext.tables.internal.createRow = function(objects, id) {
var row = document.createElement('tr');
if (null != id)
row.id = id;
return row;
}
xajax.ext.tables.internal.createCell = function(objects, id) {
var cell = document.createElement('td');
if (null != id)
cell.id = id;
cell.innerHTML = '...';
return cell;
}
xajax.ext.tables.internal.getColumnNumber = function(objects, cell) {
var position;
var columns = objects.header.getElementsByTagName('td');
for (var column = 0; column < columns.length; ++column)
if (columns[column].id == cell)
return column;
throw { name: 'TableError', message: 'Column not found. (getColumnNumber)' }
return undefined;
}
xajax.ext.tables.internal.objectify = function(params, required) {
if (undefined == params.source)
return false;
var source = params.source;
if ('string' == typeof (source))
source = xajax.$(source);
if ('TBODY' == source.nodeName) {
params.table = source.parentNode;
} else if ('TABLE' == source.nodeName) {
params.table = source;
} else if ('TR' == source.nodeName) {
params.row = source;
params.body = source.parentNode;
params.table = source.parentNode.parentNode;
} else if ('TD' == source.nodeName) {
params.cell = source;
params.row = source.parentNode;
params.columns = params.row.getElementsByTagName('TD');
for (var column = 0; undefined == params.column && column < params.columns.length; ++column)
if (params.cell.id == params.columns[column].id)
params.column = column;
params.table = source.parentNode.parentNode.parentNode;
} else if ('THEAD' == source.nodeName) {
params.table = source.parentNode;
} else if ('TFOOT' == source.nodeName) {
params.table = source.parentNode;
} else
params.source = source;
var bodies = params.table.getElementsByTagName('TBODY');
if (0 < bodies.length)
params.body = bodies[0];
var headers = params.table.getElementsByTagName('THEAD');
if (0 < headers.length)
params.header = headers[0];
var feet = params.table.getElementsByTagName('TFOOT');
if (0 < feet.length)
params.footer = feet[0];
if (undefined != params.body)
params.rows = params.body.getElementsByTagName('TR');
if (undefined != params.row)
params.cells = params.row.getElementsByTagName('TD');
if (undefined != params.header)
params.columns = params.header.getElementsByTagName('TD');
if (undefined == required)
return true;
for (var index = 0; index < required.length; ++index) {
var require = required[index];
var is_defined = false;
eval('is_defined = (undefined != params.' + require + ');');
if (false == is_defined)
throw { name: 'TableError', message: 'Unable to locate required object [' + require + '].' };
}
return true;
}
// table
xajax.ext.tables.append = function(table, parent) {
if ('string' == typeof (parent))
parent = xajax.$(parent);
parent.appendChild(xajax.ext.tables.internal.createTable(table));
}
xajax.ext.tables.insert = function(table, parent, before) {
if ('string' == typeof (parent))
parent = xajax.$(parent);
if ('string' == typeof (before))
before = xajax.$(before);
parent.insertBefore(xajax.ext.tables.internal.createTable(table), before);
}
xajax.ext.tables.remove = function(table) {
var objects = { source: table };
xajax.ext.tables.internal.objectify(objects, ['table']);
objects.table.parentNode.removeChild(objects.table);
}
xajax.ext.tables.appendHeader = function(id, table) {
var objects = { source: table };
xajax.ext.tables.internal.objectify(objects, ['table']);
if (undefined == objects.header) {
var thead = document.createElement('thead');
if (null != id)
thead.id = id;
objects.header = thead;
thead.appendChild(xajax.ext.tables.internal.createRow(objects, null));
if (undefined == objects.table.firstChild)
table.appendChild(thead);
else
table.insertBefore(thead, table.firstChild);
}
}
xajax.ext.tables.appendBody = function(id, table) {
var objects = { source: table };
xajax.ext.tables.internal.objectify(objects, ['table']);
if (undefined == objects.body) {
var tbody = document.createElement('tbody');
if (null != id)
tbody.id = id;
objects.body = tbody;
}
if (undefined != objects.rows) {
for (var rn = 0; rn < objects.rows.length; ++rn) {
var row = objects.rows[rn];
objects.table.removeChild(row);
objects.body.appendChild(row);
}
}
if (undefined != objects.footer)
objects.table.insertBefore(objects.body, objects.footer);
else
objects.table.appendChild(objects.body);
}
xajax.ext.tables.appendFooter = function(id, table) {
var objects = { source: table }
xajax.ext.tables.internal.objectify(objects, ['table']);
if (undefined == objects.footer) {
var tfoot = document.createElement('tfoot');
if (null != id)
tfoot.id = id;
objects.footer = tfoot;
tfoot.appendChild(xajax.ext.tables.internal.createRow(objects, null));
objects.table.appendChild(tfoot);
}
}
// rows
xajax.ext.tables.rows = {}
xajax.ext.tables.rows.internal = {}
xajax.ext.tables.rows.internal.calculateRow = function(objects, position) {
if (undefined == position)
throw { name: 'TableError', message: 'Missing row number / id.' }
if (undefined == objects.row)
if (undefined != objects.rows)
if (undefined != objects.rows[position])
objects.row = objects.rows[position];
if (undefined == objects.row)
objects.row = xajax.$(position);
if (undefined == objects.row)
throw { name: 'TableError', message: 'Invalid row number / row id specified.' }
}
xajax.ext.tables.rows.append = function(id, table) {
var objects = { source: table }
xajax.ext.tables.internal.objectify(objects, ['table', 'body']);
var row = xajax.ext.tables.internal.createRow(objects, id);
if (undefined != objects.columns) {
for (var column = 0; column < objects.columns.length; ++column) {
var cell = xajax.ext.tables.internal.createCell(objects, null);
cell.innerHTML = '...';
row.appendChild(cell);
}
}
objects.body.appendChild(row);
}
xajax.ext.tables.rows.insert = function(id, source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'body']);
if (undefined == objects.row)
xajax.ext.tables.rows.internal.calculateRow(objects, position);
var row = xajax.ext.tables.internal.createRow(objects, id);
if (undefined != objects.columns) {
for (var column = 0; column < objects.columns.length; ++column) {
var cell = xajax.ext.tables.internal.createCell(objects, null);
cell.innerHTML = '...';
row.appendChild(cell);
}
}
objects.body.insertBefore(row, objects.row);
}
xajax.ext.tables.rows.replace = function(id, source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'body']);
if (undefined == objects.row)
xajax.ext.tables.rows.internal.calculateRow(objects, position);
var row = xajax.ext.tables.internal.createRow(objects, id);
if (undefined != objects.columns) {
for (var column = 0; column < objects.columns.length; ++column) {
var cell = xajax.ext.tables.internal.createCell(objects, null);
cell.innerHTML = '...';
row.appendChild(cell);
}
}
objects.body.insertBefore(row, objects.row);
objects.body.removeChild(objects.row);
}
xajax.ext.tables.rows.remove = function(source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'body']);
if (undefined == objects.row)
xajax.ext.tables.rows.internal.calculateRow(objects, position);
objects.body.removeChild(objects.row);
}
xajax.ext.tables.rows.assign = function(values, source, position, start_column) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'body', 'header']);
if (undefined == objects.row)
xajax.ext.tables.rows.internal.calculateRow(objects, position);
if (undefined == start_column)
start_column = 0;
if ('object' == typeof (values) && undefined != values['p'] && undefined != values['v'])
eval('objects.row.' + values['p'] + ' = values["v"];');
else for (var column = 0; column < values.length; ++column)
xajax.ext.tables.cells.assign(values[column], objects.row, start_column + column);
}
// columns
xajax.ext.tables.columns = {}
xajax.ext.tables.columns.internal = {}
xajax.ext.tables.columns.internal.calculateColumn = function(objects, position) {
if (undefined == position)
throw { name: 'TableError', message: 'Missing column number / id.' }
if (undefined == objects.column)
if (undefined != objects.columns)
if (undefined != objects.columns[position])
objects.column = position;
if (undefined == objects.column)
for (var column = 0; undefined == objects.column && column < objects.columns.length; ++column)
if (objects.columns[column].id == position)
objects.column = column;
if (undefined == objects.column)
throw { name: 'TableError', message: 'Invalid column number / row id specified.' }
}
xajax.ext.tables.columns.append = function(column_definition, table) {
var objects = { source: table }
xajax.ext.tables.internal.objectify(objects, ['table', 'header', 'body']);
var cell = xajax.ext.tables.internal.createCell(objects, column_definition.id);
if (undefined != column_definition.name)
cell.innerHTML = column_definition.name;
objects.header.firstChild.appendChild(cell);
if (undefined != objects.rows)
for (var i = 0; i < objects.rows.length; ++i)
xajax.ext.tables.cells.append({id: null}, objects.rows[i]);
}
xajax.ext.tables.columns.insert = function(column_definition, source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'header']);
if (undefined == objects.column)
xajax.ext.tables.columns.internal.calculateColumn(objects, position);
var column = xajax.ext.tables.internal.createCell(objects, column_definition.id);
if (undefined != column_definition.name)
column.innerHTML = column_definition.name;
objects.header.firstChild.insertBefore(column, objects.columns[objects.column]);
if (undefined != objects.rows)
for (var i = 0; i < objects.rows.length; ++i)
xajax.ext.tables.cells.insert({id: null}, objects.rows[i], objects.column);
}
xajax.ext.tables.columns.replace = function(column_definition, source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'header', 'columns']);
if (undefined == objects.column)
xajax.ext.tables.columns.internal.calculateColumn(objects, position);
var before = objects.columns[objects.column];
var column = xajax.ext.tables.internal.createCell(objects, column_definition.id);
if (undefined != column_definition.name)
column.innerHTML = column_definition.name;
objects.header.firstChild.insertBefore(column, before);
objects.header.firstChild.removeChild(before);
if (undefined != objects.rows)
for (var i = 0; i < objects.rows.length; ++i)
xajax.ext.tables.cells.replace({id: null}, objects.rows[i], objects.column);
}
xajax.ext.tables.columns.remove = function(source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'header']);
if (undefined == objects.column)
xajax.ext.tables.columns.internal.calculateColumn(objects, position);
objects.header.firstChild.removeChild(objects.columns[objects.column]);
if (undefined != objects.rows)
for (var i = 0; i < objects.rows.length; ++i)
xajax.ext.tables.cells.remove(objects.rows[i], objects.column);
}
xajax.ext.tables.columns.assign = function(values, source, position, start_row) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'cell']);
if (undefined == objects.column)
xajax.ext.tables.columns.internal.calculateColumn(objects, position);
if ('object' == typeof(values) && undefined != values['p'] && undefined != values['v'])
for (var row = 0; row < objects.rows.length; ++row)
xajax.ext.tables.cells.assign(values, objects.rows[row], objects.column);
else for (var row = 0; row < values.length; ++row)
xajax.ext.tables.cells.assign(values[row], objects.rows[start_row + row], objects.column);
}
// cells
xajax.ext.tables.cells = {}
xajax.ext.tables.cells.internal = {}
xajax.ext.tables.cells.internal.calculateCell = function(objects, position) {
if (undefined == position)
throw { name: 'TableError', message: 'Missing cell number / id.' }
if (undefined == objects.cell)
if (undefined != objects.cells)
if (undefined != objects.cells[position])
objects.cell = objects.cells[position];
if (undefined == objects.cell)
if (undefined != objects.columns)
for (var column = 0; undefined == objects.cell && column < objects.columns.length; ++column)
if (objects.columns[column].id == position)
objects.cell = objects.cells[column];
if (undefined == objects.cell)
throw { name: 'TableError', message: 'Invalid cell number / id specified.' }
}
xajax.ext.tables.cells.append = function(cell_definition, source) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'row']);
var cell = xajax.ext.tables.internal.createCell(objects, cell_definition.id);
if (undefined != cell_definition.name)
cell.innerHTML = cell_definition.name;
objects.row.appendChild(cell);
}
xajax.ext.tables.cells.insert = function(cell_definition, source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'row']);
if (undefined == objects.cell)
xajax.ext.tables.cells.internal.calculateCell(objects, position);
var cell = xajax.ext.tables.internal.createCell(objects, cell_definition.id);
if (undefined != cell_definition.name)
cell.innerHTML = cell_definition.name;
objects.row.insertBefore(cell, objects.cell);
}
xajax.ext.tables.cells.replace = function(cell_definition, source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'row']);
if (undefined == objects.cell)
xajax.ext.tables.cells.internal.calculateCell(objects, position);
var cell = xajax.ext.tables.internal.createCell(objects, cell_definition.id);
if (undefined != cell_definition.name)
cell.innerHTML = cell_definition.name;
objects.row.insertBefore(cell, objects.cell);
objects.row.removeChild(objects.cell);
}
xajax.ext.tables.cells.remove = function(source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'row']);
if (undefined == objects.cell)
xajax.ext.tables.cells.internal.calculateCell(objects, position);
objects.row.removeChild(objects.cell);
}
xajax.ext.tables.cells.assign = function(value, source, position) {
var objects = { source: source }
xajax.ext.tables.internal.objectify(objects, ['table', 'row']);
if (undefined == objects.cell)
xajax.ext.tables.cells.internal.calculateCell(objects, position);
if ('object' == typeof (value) && undefined != value['p'] && undefined != value['v']) {
eval('objects.cell.' + value['p'] + ' = value["v"];');
} else
objects.cell.innerHTML = value;
}
// command handlers
// tables
xajax.commands['et_at'] = function(args) {
args.cmdFullName = 'ext.tables.append';
xajax.ext.tables.append(args.data, args.id);
return true;
}
xajax.commands['et_it'] = function(args) {
args.cmdFullName = 'ext.tables.insert';
xajax.ext.tables.insert(args.data, args.id, args.property);
return true;
}
xajax.commands['et_dt'] = function(args) {
args.cmdFullName = 'ext.tables.remove';
xajax.ext.tables.remove(args.data);
return true;
}
// rows
xajax.commands['et_ar'] = function(args) {
args.cmdFullName = 'ext.tables.rows.append';
xajax.ext.tables.rows.append(args.data, args.id);
return true;
}
xajax.commands['et_ir'] = function(args) {
args.cmdFullName = 'ext.tables.rows.insert';
xajax.ext.tables.rows.insert(args.data, args.id, args.property);
return true;
}
xajax.commands['et_rr'] = function(args) {
args.cmdFullName = 'ext.tables.rows.replace';
xajax.ext.tables.rows.replace(args.data, args.id, args.property);
return true;
}
xajax.commands['et_dr'] = function(args) {
args.cmdFullName = 'ext.tables.rows.remove';
xajax.ext.tables.rows.remove(args.id, args.property);
return true;
}
xajax.commands['et_asr'] = function(args) {
args.cmdFullName = 'ext.tables.rows.assign';
xajax.ext.tables.rows.assign(args.data, args.id, args.property);
return true;
}
// columns
xajax.commands['et_acol'] = function(args) {
args.cmdFullName = 'ext.tables.columns.append';
xajax.ext.tables.columns.append(args.data, args.id);
return true;
}
xajax.commands['et_icol'] = function(args) {
args.cmdFullName = 'ext.tables.columns.insert';
xajax.ext.tables.columns.insert(args.data, args.id, args.property);
return true;
}
xajax.commands['et_rcol'] = function(args) {
args.cmdFullName = 'ext.tables.columns.replace';
xajax.ext.tables.columns.replace(args.data, args.id, args.property);
return true;
}
xajax.commands['et_dcol'] = function(args) {
args.cmdFullName = 'ext.tables.columns.remove';
xajax.ext.tables.columns.remove(args.id, args.property);
return true;
}
xajax.commands['et_ascol'] = function(args) {
args.cmdFullName = 'ext.tables.columns.assign';
xajax.ext.tables.columns.assign(args.data, args.id, args.property, args.type);
return true;
}
// cells
xajax.commands['et_ac'] = function(args) {
args.cmdFullName = 'ext.tables.cells.append';
xajax.ext.tables.cells.append(args.data, args.id);
return true;
}
xajax.commands['et_ic'] = function(args) {
args.cmdFullName = 'ext.tables.cells.insert';
xajax.ext.tables.cells.insert(args.data, args.id, args.property);
return true;
}
xajax.commands['et_rc'] = function(args) {
args.cmdFullName = 'ext.tables.cells.replace';
xajax.ext.tables.cells.replace(args.data, args.id, args.property);
}
xajax.commands['et_dc'] = function(args) {
args.cmdFullName = 'ext.tables.cells.remove';
xajax.ext.tables.cells.remove(args.id, args.property);
return true;
}
xajax.commands['et_asc'] = function(args) {
args.cmdFullName = 'ext.tables.cells.assign';
xajax.ext.tables.cells.assign(args.data, args.id, args.property);
return true;
}
}
installTableUpdater();