// JScript 文件
//请求控件的前台逻辑处理对象
var FrameCallbackControl = {
HIDDEN_FRAME_ID : 'callbackFrame',
CallbackRegister : function (callbackConditions, requestPageUrl, isInitData) {
var idCount = callbackConditions.length;
for(var i=0;i<idCount;i++) {
if(callbackConditions[i].controlID.length = 0) continue;
var tmpControl = document.getElementById(callbackConditions[i].controlID);
if(tmpControl != null) {
tmpControl.setAttribute('dstControlID', callbackConditions[i].destineControlID);
if(tmpControl.attachEvent) {
tmpControl.attachEvent('onchange', new Function( 'FrameCallbackControl.RequestCallbackPage( "' + callbackConditions[i].conditionControlID + '","' + requestPageUrl + '" );' ) );
}
else if(tmpControl.addEventListener) {
tmpControl.addEventListener('change', new Function( 'FrameCallbackControl.RequestCallbackPage( "' + callbackConditions[i].conditionControlID + '","' + requestPageUrl + '" );' ), false );
}
//只有下拉控件才存在初始值
if(callbackConditions[i].destineControlInitValue.length != 0 && isInitData) {
tmpControl.setAttribute('dstInitValue', callbackConditions[i].destineControlInitValue);
}
}
}
if(isInitData) {
//保存处理请求异步请求对象
this._reqArray = callbackConditions;
this.isBusy = false;
this._requestCount = idCount;
this._processIndex = 0;
//开始异步初始化
this.asynRequestInternal();
}
},
asynRequestInternal : function () {
if(!this.isBusy) {
if(this._processIndex < this._requestCount) {
var tmpID = this._reqArray[this._processIndex].controlID;
var tmpObj = document.getElementById(tmpID);
if(tmpObj != null) {
this.fireEventInternal(tmpObj, 'change');
}
}
else {//处理完毕了
clearTimeout(this.__timmerID);
}
}
else {//繁忙的时候等待100毫秒后再请求
this.__timmerID = setTimeout('FrameCallbackControl.asynRequestInternal();', 100);
}
},
RequestCallbackPage : function (conditionControlID, pageUrl) {
var ev = this.getEventObject();
var srcObj = null;
if(ev.srcElement != null) {//IE
srcObj = ev.srcElement;
}
else if(ev.target != null) {//FireFox
srcObj = ev.target;
}
var reqUrl = this.getRequestUrlInternal(srcObj, conditionControlID, pageUrl);
try {
var reqFrame = document.getElementById(this.HIDDEN_FRAME_ID);
if(reqFrame != null) {
reqFrame.src = reqUrl;
this.isBusy = true;
}
}
catch(e) {
alert(e);
}
},
//回传函数
CallbackHandler : function (respObj) {
if(typeof(respObj) == 'number' || typeof(respObj) == 'string') {//错误的时候为字符串或数字类型
this.callbackErrorHandler(respObj);
}
else {
var objCount = respObj.length;
//一般只有初始化的时候objCount会大于1
for(var i=0; i < objCount; i++) {
var results = respObj[i].results;
var resultCount = results.length;
//处理收回来的结果
for(var j = 0; j < resultCount; j++) {
this.processSingleResultInternal(results[j], respObj[i].srcObjID);
}
}
}
this.isBusy = false;
this._processIndex++;
},
processSingleResultInternal : function (singleResult, srcObjID) {
if(singleResult == 'null') return;
var dstObj = document.getElementById(singleResult.dstObjID);
var srcObj = document.getElementById(srcObjID);
if(dstObj != null) {
if(singleResult.isComplexType) {
if(dstObj.tagName == 'SELECT') {
var source = singleResult.datasource;
var sourceCount = source.length;
//清空以往的下拉数据
dstObj.options.length = 0;
for(var i = 0; i < sourceCount; i++) {
var optionElement = document.createElement('option');
optionElement.innerHTML = source[i].text;
optionElement.setAttribute('value', source[i].value);
dstObj.appendChild(optionElement);
}
//设置下拉控件的初始值
if(srcObj != null) {
var initValue = srcObj.getAttribute('dstInitValue');
if(initValue != null) {
setTimeout('document.getElementById("' + dstObj.id + '").value = ' + initValue + ';', 0);
}
}
}
else {//非下拉选择则直接赋值一行一列的数据
dstObj.value = singleResult.datasource[0].text;
}
}
else {
if(dstObj.getAttribute('type') == 'checkbox' || dstObj.getAttribute('type') == 'radio') {
dstObj.checked = singleResult.datasource;
}
else {
dstObj.value = singleResult.datasource;
}
}
}
},
//错误处理
callbackErrorHandler : function (errMsg) {
if(typeof(this.ErrHandler) == 'undefined') {
alert(errMsg);
}
else {
this.ErrHandler(errMsg);
}
},
getRequestUrlInternal : function(srcObj, conditionControlID, pageUrl) {
if(pageUrl.indexOf('?') == -1) {
pageUrl += '?';
}
else {
pageUrl += '&';
}
pageUrl += 'srcObjID=' + srcObj.getAttribute('id');
pageUrl += '&srcObjValue=' + encodeURI(this.getObjectValue(srcObj));
pageUrl += '&dstControlID=' + encodeURI(srcObj.getAttribute('dstControlID'));
var conditionIDs = conditionControlID.split(',');
var idCount = conditionIDs.length;
for(var i = 0; i < idCount; i++) {
if(conditionIDs[i].length == 0) continue;
var tmpObj = document.getElementById(conditionIDs[i]);
if(tmpObj != null) {
pageUrl += '&' + tmpObj.getAttribute('id') + '=' + encodeURI(this.getObjectValue(tmpObj));
}
}
pageUrl += this.typesString;
return pageUrl;
},
getObjectValue : function(obj) {
if(obj.tagName == 'INPUT') {
if(obj.getAttribute('type') == 'checkbox' || obj.getAttribute('type') == 'radio') {
return obj.checked;
}
}
return obj.value;
},
getEventObject : function() {
if(typeof(event) != 'undefined') {
return event;//直接返回说明是IE
}
var func = this.getEventObject.caller;
while(func != null) {
var arg0=func.arguments[0];
if(arg0)
{
if(arg0.constructor == Event) // Event是FireFox的默认事件对象
评论0