function _load(argExtraArray){ msg('_load:' + this.datasetName); // Current page get args need to be passed as well var curLocation = window.location.href; var splitResult = curLocation.split('#'); // Remove anything after the # var splitResult = splitResult[0].split('?'); if (typeof(splitResult[1]) != 'undefined') var getStr = splitResult[1]; else getStr = ''; msg('_load: getStr: ' + getStr); if (typeof(this._setArgs) == 'function') { this._setArgs(); // Sets this.request.argArray } if (typeof(this.request.argArray) != 'undefined') { if (getStr.length) getStr += '&'; getStr += serializeArray(this.request.argArray); } if (typeof(argExtraArray) != 'undefined') { if (getStr.length) getStr += '&'; getStr += serializeArray(argExtraArray); } //var url = 'http://myvrzone.myvrzone.com/Data/Rates?cid=4-1' + getStr; //var url = 'http://myvrzone.myvrzone.com/Admin/Setup?' + getStr; this.request.url = gDataUrlBase + '/?' + getStr; this.request.method = 'GET'; msg('--->' + this.request.method + ' ' + this.request.url); this.request.callback = { success: this._connectionHandleLoadSuccess, failure: this._connectionHandleLoadFailure, scope: this, argument: this.request, timeout: 30000 } this.request.connectionObject = YAHOO.util.Connect.asyncRequest(this.request.method, this.request.url, this.request.callback); if (typeof(this.request.connectionObject) == 'object') { gConnectionArray[this.datasetName] = this.request.connectionObject; return true; } else return false; } function _connect(action, p_getArgArray, p_postArgArray, aSuccess, aFailure){ msg('_connect:' + this.datasetName); var ret = false; if(this.connectStatus==CONNECT_STATUS_STOP) return ret; // Current page get args need to be passed as well var curLocation = window.location.href; var splitResult = curLocation.split('#'); // Remove anything after the # var splitResult = splitResult[0].split('?'); if (typeof(splitResult[1]) != 'undefined') var getStr = splitResult[1]; else getStr = ''; msg('_connect: getStr: ' + getStr); var oRequest = new Object(); /* if (typeof(this._setArgs) == 'function') { this._setArgs(action, oRequest); // Returns request with argArray filled } else { var oRequest = this.request; } if (typeof(oRequest.argArray) != 'undefined') { if (getStr.length) getStr += '&'; getStr += serializeArray(oRequest.argArray,'',2); } */ oRequest[ARG_GETS] = p_getArgArray; oRequest[ARG_POST] = p_postArgArray; this._setArgs(action, oRequest); // Returns request with argArray filled oRequest.aSuccess = aSuccess; oRequest.aFailure = aFailure; var getArgArray = oRequest[ARG_GETS]; var postArgArray = oRequest[ARG_POST]; var postStr = ''; if (this.datasetName == DATASET_NONE) { if (typeof(getArgArray) != 'undefined') { postStr += "&" + getStr; // Copy URL arguments postStr += "&" + serializeArray(getArgArray,'',2); oRequest.method = 'POST'; } else { oRequest.method = 'GET'; } var fnSuccess = this._connectionHandleSuccess; var fnFailure = this._connectionHandleFailure; } else { if (typeof(getArgArray) != 'undefined') { if (getStr.length) getStr += '&'; getStr += serializeArray(getArgArray,'',2); } switch(action) { case(YUI_ACTION_SAVE): if(this.saveStatus==SAVE_STATUS_STOP) return ret; postStr += "&" + getStr; // Copy URL arguments postStr += "&" + serializeArray(postArgArray); oRequest.method = 'POST'; var fnSuccess = this._connectionHandleSaveSuccess; var fnFailure = this._connectionHandleSaveFailure; break case(YUI_ACTION_DELETE): oRequest.method = 'GET'; var fnSuccess = this._connectionHandleDelSuccess; var fnFailure = this._connectionHandleDelFailure; break; case(YUI_ACTION_LOAD): if(this.loadStatus==LOAD_STATUS_STOP) return ret; oRequest.method = 'GET'; var fnSuccess = this._connectionHandleLoadSuccess; var fnFailure = this._connectionHandleLoadFailure; break default: if(!isEmpty(postArgArray)) { postStr += "&" + getStr; // Copy URL arguments postStr += "&" + serializeArray(postArgArray); oRequest.method = 'POST'; } else { oRequest.method = 'GET'; } var fnSuccess = this._connectionHandleSuccess; var fnFailure = this._connectionHandleFailure; } } //var url = 'http://myvrzone.myvrzone.com/Data/Rates?cid=4-1' + getStr; //var url = 'http://myvrzone.myvrzone.com/Admin/Setup?' + getStr; oRequest.url = gDataUrlBase + '/?' + getStr; msg('--->' + oRequest.method + ' ' + oRequest.url); oRequest.callback = { success: fnSuccess, failure: fnFailure, scope: this, argument: oRequest, timeout: 60000 } oRequest.connectionObject = YAHOO.util.Connect.asyncRequest(oRequest.method, oRequest.url, oRequest.callback, postStr); if (typeof(oRequest.connectionObject) == 'object') { gConnectionArray[this.datasetName] = oRequest.connectionObject; ret = true; } setActive(); return ret; } function _doCallback(callbackFunctionName, callbackArg, callbackObject) { var ret = true; if (typeof(callbackObject) == 'object' && callbackObject != null) { msg('Doing callbackStack for: ' + callbackObject.datasetName); if (typeof(callbackObject[callbackFunctionName]) == 'function') { msg('Calling callbackObject function'); ret = callbackObject[callbackFunctionName](callbackArg); } else { msg('callbackObject not a function, trying stright function'); return _doCallback(callbackFunctionName, callbackArg) } } else { msg('callbackObject not an object - trying function'); //if(typeof(callbackObject) == 'undefined') { if (typeof(callbackFunctionName) == 'function') { msg('Calling direct function'); ret = callbackFunctionName(callbackArg); } else { msg('Not a direct function'); } } return ret; } function connect(action, argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName){ msg('connect:' + this.datasetName + ',' + action); var doConnect = true; // Only prevent multiple loads from happening at once if(action == YUI_ACTION_LOAD && this.loadStatus == LOAD_STATUS_INPROGRESS) { // Load in progress already this.connectStatus = LOAD_STATUS_INPROGRESS; doConnect = false; } else { // Connect /* var postArgArray = this.request.saveArgArray; if(typeof(postArgArray)=='undefined') { postArgArray = argArray[ARG_POST]; if(typeof(postArgArray)!='undefined') delete(argArray[ARG_POST]); } */ var postArgArray = argArray[ARG_POST]; var getArgArray = argArray[ARG_GETS]; if (typeof(successCallbackFunctionName) != 'undefined') { msg('== successCallback: ' + this.datasetName + '/' + successCallbackFunctionName); var aSuccess = new Array(); //aSuccess[CALLBACK_OBJECT_INDEX] = callbackObj; //aSuccess[CALLBACK_ARG_INDEX] = callbackArg; //aSuccess[CALLBACK_FUNCTIONNAME_INDEX] = successCallbackFunctionName; } if (typeof(failureCallbackFunctionName) != 'undefined') { msg('== failureCallback: ' + this.datasetName + '/' + failureCallbackFunctionName); var aFailure = new Array(); //aFailure[CALLBACK_OBJECT_INDEX] = callbackObj; //aFailure[CALLBACK_ARG_INDEX] = callbackArg; //aFailure[CALLBACK_FUNCTIONNAME_INDEX] = failureCallbackFunctionName; } } // Call back stacks if(typeof(this.successCallbackStack[action])=='undefined') this.successCallbackStack[action] = new Array(); if(typeof(this.failureCallbackStack[action])=='undefined') this.failureCallbackStack[action] = new Array(); if (typeof(successCallbackFunctionName) != 'undefined') { msg('== Adding to successCallbackStack: ' + this.datasetName + '/' + successCallbackFunctionName); //popup(POPUP_TYPE_INFO, '== Adding to successCallbackStack: '+this.datasetName); var aTmp = new Array(); aTmp[CALLBACK_OBJECT_INDEX] = callbackObj; aTmp[CALLBACK_ARG_INDEX] = callbackArg; aTmp[CALLBACK_FUNCTIONNAME_INDEX] = successCallbackFunctionName; this.successCallbackStack[action].push(aTmp); } if (typeof(failureCallbackFunctionName) != 'undefined') { msg('== Adding to failureCallbackStack: ' + this.datasetName + '/' + failureCallbackFunctionName); var aTmp = new Array(); aTmp[CALLBACK_OBJECT_INDEX] = callbackObj; aTmp[CALLBACK_ARG_INDEX] = callbackArg; aTmp[CALLBACK_FUNCTIONNAME_INDEX] = failureCallbackFunctionName; this.failureCallbackStack[action].push(aTmp); } if(doConnect) { msg("Connecting..."); if (this._connect(action, getArgArray, postArgArray, aSuccess, aFailure)) { msg("...connected"); this.connectStatus = CONNECT_STATUS_INPROGRESS; } } msg('successCallbackStack['+action+'] length=' + this.successCallbackStack[action].length); msg('failureCallbackStack['+action+'] length=' + this.failureCallbackStack[action].length); return this.connectStatus; } function postConnect(action, oRequest) { switch(action) { case(YUI_ACTION_LOAD): msg('postConnect: LOAD'); this.postload(oRequest); break; case(YUI_ACTION_SAVE): // Save if(typeof(oRequest)=='undefined') { dbgp("postConnect(): No oRequest arg"); oRequest = this.request; } msg('postConnect: SAVE - ' + typeof(oRequest.saveArgArray)); var saveArgArray = oRequest[ARG_POST]; if (typeof(saveArgArray) != 'undefined') { msg('_connectionParseResponse: saveArgArray :: ' + serializeArray(saveArgArray)); var sMainNvps = saveArgArray[GET_NVPS]; var id = String(saveArgArray[GET_ID]); var sId = saveArgArray[GET_INPUTID]; msg('_connectionParseResponse: id = ' + id); if (typeof(id) != 'undefined' && id != null && id.length) { var aId = id.split(":"); if (aId.length > 1) { var aMainNvps = deserializeArray(saveArgArray[GET_NVPS]); } else { var aMainNvps = new Array(); aMainNvps[aId[0]] = saveArgArray[GET_NVPS]; } msg('_connectionParseResponse: aId:: ' + serializeArray(aId)); for (id in aId) { // Update the data-store with the saved values var datasetRowIndex = saveArgArray['datasetRowIndex']; var curId = aId[id]; var nvps = aMainNvps[curId]; // Save the new value //MVRZ.data.object[dataIndex][JSON_RESPONSE_INDEX_DATA][dataRow][input] = value; var newId = this.dataset[JSON_RESPONSE_INDEX_LASTINSERTEDID]; if (newId) { // It was an insertion of a new record if (!this._connectionHandleSaveInsert(oRequest, curId, newId)) { MVRZ.util.event.disableTimer("connectionHandleSaveInsert() failed"); } } else { // Not an insert - just an update // Find the right record to update var savedArray = deserializeArray(nvps); msg('_connectionParseResponse doing insert updates (' + datasetRowIndex + '): ' + nvps); var found = true; if (typeof(datasetRowIndex) == 'undefined') { // Find the dataset row index var idIndex = this.inputs.uniqueField; found = false; msg('_connectionParseResponse looking for index from curId ' + curId); for (var rowIndex in this.dataset[JSON_RESPONSE_INDEX_DATA]) { //if(this.dataset[JSON_RESPONSE_INDEX_DATA][rowIndex][idIndex] == curId) { if (this.get(rowIndex, idIndex) == curId) { found = true; break; } } if (found) datasetRowIndex = rowIndex; msg('_connectionParseResponse found=' + found + ', datasetRowIndex=' + datasetRowIndex); } else { if (typeof(this.dataset[JSON_RESPONSE_INDEX_DATA][datasetRowIndex]) == 'undefined') { this.dataset[JSON_RESPONSE_INDEX_DATA][datasetRowIndex] = new Object(); } } if(found) { for (var input in savedArray) { this.set(datasetRowIndex, input, savedArray[input]); } } } } // For loop } } else { msg('_connectionParseResponse: No saveArgArray'); } break; case(YUI_ACTION_DELETE): msg('_connectionParseResponse: DELETE'); //MVRZ.data.object[this.datasetName] = jsonObj; //this.dataset = MVRZ.data.object[this.datasetName]; //this.datasetData = this.dataset[JSON_RESPONSE_INDEX_DATA]; var argArray = oRequest[ARG_GETS]; // Delete id from dataset var idArray = argArray[GET_ID].split(":"); // May be mutliple IDs for(id in idArray) { if(!this.remove(idArray[id])) { popupErr("Deleted ["+idArray[id]+"] on server but could not delete local copy - please reload content"); } } break; default: } } function load(p_argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName){ msg('load:' + this.datasetName + ',' + successCallbackFunctionName); if(!this.preload()) return this.loadStatus; // Save args for reload this.reloadArgs = { argArray: p_argArray, callbackObj: callbackObj, callbackArg: callbackArg, successCallbackFunctionName: successCallbackFunctionName, failureCallbackFunctionName: failureCallbackFunctionName } if (!this.localOnly && (!this.loadStatus || typeof(this.dataset) == 'undefined' || typeof(this.dataset[JSON_RESPONSE_INDEX_RAW]) == 'undefined')) { var raw = MVRZ.storage.getItem(this.datasetName); raw = null; // TODO - just for making it work, need to remove if(raw != null && raw.length>0) { msg("load() loading from Storage, calling connect()..."); alert("load() loading " + this.datasetName + " from Storage, calling connect()..."); if(this._connectionHandleLoadSuccess(this.request)) { this.loadStatus = LOAD_STATUS_LOADED; } } else { //if(this.loadStatus != LOAD_STATUS_UNLOADED) return this.loadStatus; // This stops calling connect and no callbacks are called if(this.loadStatus == LOAD_STATUS_LOADED) return this.loadStatus; // This stops calling connect and no callbacks are called var argArray = {}; if(typeof(p_argArray)!=='undefined') { if(typeof(argArray[ARG_GETS])=='undefined') argArray[ARG_GETS] = new Object(); argArray[ARG_GETS][GET_NVPS] = p_argArray[ARG_GETS]; } //args[ARG_POST] = argArray[ARG_POST]; msg("load() calling connect()..."); this.loadStatus = this.connect(YUI_ACTION_LOAD, argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName); } } else if(this.localOnly || this.isLoaded()){ // Run the callback assuming success this.loadStatus = LOAD_STATUS_LOADED; _doCallback(successCallbackFunctionName, callbackArg, callbackObj); } return this.loadStatus; } function reload(){ msg('reload:' + this.datasetName); if (typeof(this.reloadArgs) != 'undefined') { this.dataset = new Object();// Reset with (this.reloadArgs) { return this.load(argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName); } } return this.loadStatus; } function _connectionHandleDelSuccess(oRequestCallback){ msg('_connectionHandleDelSuccess:' + this.datasetName); var oRequest = oRequestCallback.argument; msg('--<' + this.datasetName + "::" + oRequestCallback.responseText); var ret = this.connectionParseResponse(oRequestCallback); return ret; } function _connectionHandleDelFailure(oRequestCallback){ msg('_connectionHandleDelFailure:' + this.datasetName); var oRequest = oRequestCallback.argument; this.requestStatus = REQUEST_STATUS_UNLOADED; MVRZ.util.errorHandler('', YUI_ERR_SOURCE_CONNECTION, oRequestCallback); this._processCallbackStack(true, oRequest); } function _connectionHandleLoadFailure(oRequestCallback){ msg('_connectionHandleLoadFailure:' + this.datasetName); var oRequest = oRequestCallback.argument; this.requestStatus = REQUEST_STATUS_UNLOADED; MVRZ.util.errorHandler('', YUI_ERR_SOURCE_CONNECTION, oRequestCallback); this._processCallbackStack(true, oRequest); } function connectionParseResponse(oRequestCallback, paction){ //msg('connectionParseResponse:' + this.datasetName); //popup('', 'connectionParseResponse()'); if(typeof(oRequestCallback)!='undefined') { var oRequest = oRequestCallback.argument; if(typeof(oRequest)!='undefined' && typeof(oRequest[ARG_GETS])!='undefined') { var action = oRequest[ARG_GETS][GET_ACTION]; } ////this.request = oRequest; ////this.oRequestCallback = oRequestCallback; } else { dbgp('connectionParseResponse(): No oRequestCallback object'); var oRequest = this.request; oRequestCallback = this.oRequestCallback; } if(typeof(action)=='undefined' || action.length==0) { action = paction; } msg('--<' + this.datasetName + "::" + oRequestCallback.responseText); var ret = true; var status; // Assume JSON here // - use loaded or stored data if(this.isStored){ var responseText = MVRZ.storage.getItem(this.datasetName); msg("connectionParseResponse() - processing stored string"); } else { var responseText = oRequestCallback.responseText; } var jsonObj = responseText; if(typeof(jsonObj) != 'object') { gLastJsonUnparsed = ''; try { //var data = YAHOO.lang.JSON.parse(o.responseText); gLastJsonObj = jsonObj = YAHOO.lang.JSON.parse(responseText); status = jsonObj[JSON_RESPONSE_INDEX_STATUS]; //delete this.dataset[JSON_RESPONSE_INDEX_UNPARSED]; } catch (e) { msg('Failed to parse response'); MVRZ.util.errorHandler('Failed to parse response'); this.connectStatus = CONNECT_STATUS_UNLOADED; switch(action) { case(YUI_ACTION_LOAD): this.dataset = MVRZ.data.object[this.datasetName] = new Object(); this.loadStatus = LOAD_STATUS_UNLOADED; break; case(YUI_ACTION_DELETE): case(YUI_ACTION_UPDATE): break; case(YUI_ACTION_SAVE): this.saveStatus = SAVE_STATUS_UNLOADED; // This should not be needed break; // Do nothing so save can be tried again default: break; // Do nothing } gLastJsonUnparsed = responseText; ////this.dataset[JSON_RESPONSE_INDEX_UNPARSED] = responseText; //msg(dataObject.responseText); ret = false; } } else gLastJsonObj = jsonObj; // Output any notices if(typeof(jsonObj)!='undefined') displayResponseMessages(jsonObj); if (ret) { //if(typeof(MVRZ.data.object[this.datasetName])=='undefined') MVRZ.data.object[this.datasetName] = new Object(); //var parsedResponse = YAHOO.lang.JSON.parse(oRequestCallback.responseText); this.connectStatus = CONNECT_STATUS_LOADED; var dataArray = {}; if(typeof(jsonObj[JSON_RESPONSE_INDEX_PAYLOAD])!='undefined') { // Multiple datasets for(var datasetName in jsonObj[JSON_RESPONSE_INDEX_PAYLOAD]) { dataArray[datasetName] = jsonObj[JSON_RESPONSE_INDEX_PAYLOAD][datasetName]; } } if(typeof(jsonObj[JSON_RESPONSE_INDEX_PAYLOAD])=='undefined' || typeof(jsonObj[JSON_RESPONSE_INDEX_DATA])!='undefined') { dataArray[this.datasetName] = jsonObj; } for(var datasetName in dataArray) { var payload = dataArray[datasetName]; var affectedRows = payload[JSON_RESPONSE_INDEX_ROWSAFFECTED]; //dbgp('connectionParseResponse(), datasetName='+datasetName+', action='+action); if (status == JSON_RESPONSE_INDEX_STATUS_OK) { switch(action) { case(YUI_ACTION_LOGIN): case(YUI_ACTION_LOAD): msg('_connectionParseResponse: LOAD'); ////MVRZ.data.object[this.datasetName] = jsonObj; // Replaces all data if(typeof(payload[JSON_RESPONSE_INDEX_DATA])=='object') { MY[datasetName].dataset[JSON_RESPONSE_INDEX_DATA] = payload[JSON_RESPONSE_INDEX_DATA]; } else { MY[datasetName].dataset[JSON_RESPONSE_INDEX_DATA] = []; } MY[datasetName].datasetData = MY[datasetName].dataset[JSON_RESPONSE_INDEX_DATA]; MY[datasetName].loadStatus = LOAD_STATUS_LOADED; if(action==YUI_ACTION_LOGIN) { // Reload the pages fnPageInit(); } ////this.dataset[JSON_RESPONSE_INDEX_RAW] = responseText; ////if(!this.isStored) MVRZ.storage.setItem(this.datasetName, responseText); break; case(YUI_ACTION_UPDATE): msg('_connectionParseResponse: UPDATE'); var data = payload[JSON_RESPONSE_INDEX_DATA]; var oDataset = MY[datasetName]; var idField = oDataset.getUniqueField(); for(var index in data) { var datasetRowIndex = oDataset.getDatasetRowIndex(data[index][idField]); //if(datasetName===DATASET_QUOTES) dbgp("UPDATE: "+datasetName+", "+datasetRowIndex+": discountAmount="+data[index]['discountAmount']); //if(datasetName===DATASET_QUOTEOPTIONS) dbgp("UPDATE: "+datasetName+", "+datasetRowIndex+": quoteID="+data[index]['quoteID']+", isIncluded="+data[index]['isIncluded']); if(datasetRowIndex> -1) { oDataset.setRow(datasetRowIndex, data[index]); } else { // Append new row var idValue = data[index][idField]; oDataset.append(idValue, data[index]); } } oDataset.loadStatus = LOAD_STATUS_LOADED; break; case(YUI_ACTION_SAVE): // Save msg('_connectionParseResponse: SAVE - ' + typeof(oRequest.saveArgArray)); MY[datasetName].saveStatus = SAVE_STATUS_LOADED; if (typeof(MY[datasetName].handleSaveSuccess) == 'function') { msg('_connectionParseResponse: Calling handleSaveSuccess()'); MY[datasetName].handleSaveSuccess(oRequestCallback); } break; case(YUI_ACTION_DELETE): msg('_connectionParseResponse: DELETE'); // Check that the affected rows is as expected var delArgArray = oRequest[ARG_GETS]; var idArray = delArgArray[GET_ID].split(':'); if(idArray.length!=affectedRows) { //popupInfo("Deletion error: " + affectedRows + " deletions, " + idArray.length + " requested"); popupErr('Failed to delete all '+idArray.length+' items on server.
Please refresh this page.'); } break; default: if (typeof(MY[datasetName].dataset) == 'undefined') { if (typeof(MVRZ.data.object[datasetName]) == 'undefined') { MVRZ.data.object[datasetName] = new Object(); } MY[datasetName].dataset = MVRZ.data.object[datasetName]; } } } for(var item in payload) { if(item == JSON_RESPONSE_INDEX_DATA) continue; // Skip this MY[datasetName].dataset[item] = payload[item]; } }// End for // Update the info in the dataset // - any data is also overwritten if there's a data object entry in the json response /* for(var item in jsonObj) { if(item == JSON_RESPONSE_INDEX_DATA) continue; // Skip this this.dataset[item] = jsonObj[item]; } */ if (typeof(jsonObj[JSON_RESPONSE_INDEX_INFO]) != 'undefined') { gUserId = parseInt(jsonObj[JSON_RESPONSE_INDEX_INFO][JSON_RESPONSE_INDEX_INFO_USERID]); gRealIsAdmin = Boolean(jsonObj[JSON_RESPONSE_INDEX_INFO][JSON_RESPONSE_INDEX_INFO_REALISADMIN]); } else gRealIsAdmin = 0; } /* // Write info on errors and oks ///if (typeof(this.dataset) != 'undefined') { if (typeof(gLastJsonUnparsed) != 'undefined') { if (gIsAdmin) { gRemoteInfoPanel.setBody(gLastJsonUnparsed); gRemoteInfoPanel.show(); } else { notifyAdmin(gLastJsonUnparsed); popup(POPUP_TYPE_ERROR, MSG_SYSTEM_ERROR); } } ///} */ this.postConnect(action, oRequest); if (ret) { // Valid response if (!status) { // No issues msg('connectionParseResponse::_processCallbackStack(false)'); this._processCallbackStack(false, oRequest); } else { // Issues //this.connectStatus = CONNECT_STATUS_UNLOADED; //this.loadStatus = LOAD_STATUS_UNLOADED; //this.saveStatus = SAVE_STATUS_UNLOADED; //this.successCallbackStack = new Array(); //this.failureCallbackStack = new Array(); this._processCallbackStack(true, oRequest); msg('connectionParseResponse:: status error ' + status); switch (status) { case (JSON_RESPONSE_INDEX_STATUS_NOTLOGGEDIN): msg("Redirect for login"); renderLogin(); break; case (JSON_RESPONSE_INDEX_STATUS_DBERR): msg("Server error"); break; default: msg("Unknown error response code: " + status); } } } else { msg('connectionParseResponse::_processCallbackStack(true)'); this._processCallbackStack(true); } //popup('', 'connectionParseResponse() END'); //setActivity(false); return ret; } function _connectionHandleSuccess(oRequestCallback){ msg('_connectionHandleSuccess:' + this.datasetName); //var oRequest = oRequestCallback.argument; msg('--<' + this.datasetName + "::" + typeof(oRequestCallback)); var ret = this.connectionParseResponse(oRequestCallback); return ret; } function _connectionHandleFailure(oRequestCallback){ msg('_connectionHandleFailure:' + this.datasetName); var oRequest = oRequestCallback.argument; MVRZ.util.errorHandler('', YUI_ERR_SOURCE_CONNECTION, oRequestCallback); this._processCallbackStack(true, oRequest); } function _connectionHandleLoadSuccess(oRequestCallback){ msg('_connectionHandleLoadSuccess:' + this.datasetName); //var oRequest = oRequestCallback.argument; msg('--<' + this.datasetName + "::" + typeof(oRequestCallback)); var ret = this.connectionParseResponse(oRequestCallback, YUI_ACTION_LOAD); return ret; } function _connectionHandleSaveFailure(oRequestCallback){ msg('_connectionHandleSaveFailure:' + this.datasetName); var oRequest = oRequestCallback.argument; this.requestStatus = REQUEST_STATUS_UNLOADED; MVRZ.util.errorHandler('', YUI_ERR_SOURCE_CONNECTION, oRequestCallback); this._processCallbackStack(true, oRequest); } function _connectionHandleSaveInsert(oRequestCallback, origId, newId){ msg('_connectionHandleSaveInsert:' + this.datasetName); msg('connectionHandleSaveInsert(dataObject, ' + origId + ', ' + newId + ')'); var status; var oRequest = oRequestCallback.argument; if(typeof(oRequest)=='undefined') oRequest = oRequestCallback; var saveArgArray = oRequest[ARG_POST]; var datasetRowIndex = saveArgArray[GET_DATASETROWINDEX]; var displayRowIndex = saveArgArray[GET_DISPLAYROWINDEX]; var id = saveArgArray[GET_ID]; if (typeof(newId) == 'undefined' || newId == null) { msg('connectionHandleSaveInsert: newId is invalid: ' + newId); return false; } if (id != origId && !this.doSaveFor[origId]) { msg('connectionHandleSaveInsert: id mismatch: ' + id + ',' + origId); return false; } // Change everything to match the new id var ret = MVRZ.util.setAllInputIds(this, displayRowIndex, origId, newId); // Update any select box that needs it this.setDatasetId(newId); ////this.currentDatasetIdValue = newId; if (typeof(this.updateMainSelect) == 'function') this.updateMainSelect('', this); return ret; } function _connectionHandleSaveSuccess(oRequestCallback){ msg('_connectionHandleSaveSuccess:' + this.datasetName); //popup('', '_connectionHandleSaveSuccess()'); /* * This does NOT work for multiple saves yet */ var oRequest = oRequestCallback.argument; msg('--<' + this.datasetName + "::" + oRequestCallback.responseText); var ret = this.connectionParseResponse(oRequestCallback); this.saveStatus = SAVE_STATUS_UNLOADED; // Do post-save stuff if (ret) { msg('_connectionHandleSaveSuccess - parsed OK'); if (typeof(oRequest) == 'undefined') { return ret; } var dataObjectIndex = this.datasetName; var id, sId; var saveArgArray = oRequest[ARG_POST]; if(typeof(saveArgArray)!='undefined') { sId = saveArgArray[GET_INPUTID]; id = saveArgArray[GET_ID]; id = sId; // TODO - make work for multple saves, assume sone just now } msg('_connectionHandleSaveSuccess : clean up dirty inputs: ' + dataObjectIndex + ', ' + id); if (typeof(id) != 'undefined' && id.length) { msg("_connectionHandleSaveSuccess(" + dataObjectIndex + ', ' + id + ')'); if (typeof(oRequest.idArray) == 'undefined') oRequest.idArray = new Object(); oRequest.idArray[id] = 1; /* var oInputTarget = MVRZ.util.getInput(sId); msg("_connectionHandleSaveSuccess dirty? cur/old:" + oInputTarget.curVal + '/' + oInputTarget.oldVal); if (typeof(oInputTarget) == 'undefined' || oInputTarget.curVal == oInputTarget.oldVal) { YAHOO.util.Dom.removeClass(sId, NAME_CLASS_DIRTYINPUT); } */ } if (typeof(oRequest.idArray) != 'undefined') { //popup('', 'Request.idArray'); for (id in oRequest.idArray) { //var sId = MVRZ.util.encodeInputId(this.datasetName, datasetRowIndex, id, input)(); msg("_connectionHandleSaveSuccess::" + dataObjectIndex + ', array ID=' + id); var oInputTarget = MVRZ.util.getInput(id); if (typeof(oInputTarget) == 'undefined' || oInputTarget == null || oInputTarget.curVal == oInputTarget.oldVal) { YAHOO.util.Dom.removeClass(id, NAME_CLASS_DIRTYINPUT); } else { // Any special change function if (oInputTarget.displayRowIndex == 'select') { oInput = gInputs[dataObjectIndex].inputs.selectField; msg('_connectionHandleSaveSuccess, ' + dataObjectIndex + ', ' + typeof(oInput.fnOnSave) + ' :: ' + oInput.name); } else { oRequest.currentDatasetRowIndex = oInputTarget.datasetRowIndex; oRequest.currentDisplayRowIndex = oInputTarget.displayRowIndex; oInput = this.inputs.fields[oInputTarget.input]; } if (typeof(oInput) != 'undefined') { if (typeof(oInput.fnOnSave) != 'undefined') { msg('_connectionHandleSaveSuccess, calling fnOnChange::' + oInput.name); oInput.fnOnSave(null, this); } } } } } } else { msg('_connectionHandleSaveSuccess - failed to parse'); } //popup('', '_connectionHandleSaveSuccess() end'); return ret; } function _processCallbackStack(isFailed, oRequest){ msg('_processCallbackStack(' + isFailed + '):' + this.datasetName); //popup('', '_processCallbackStack()'); if (isFailed) { var aCallback = oRequest.aFailure; } else { var aCallback = oRequest.aSuccess; } if(typeof(aCallback)!='undefined') { var callbackObject = aCallback[CALLBACK_OBJECT_INDEX]; var callbackArg = aCallback[CALLBACK_ARG_INDEX]; var callbackFunctionName = aCallback[CALLBACK_FUNCTIONNAME_INDEX]; _doCallback(callbackFunctionName, callbackArg, callbackObject); } if(typeof(oRequest[ARG_GETS])=='undefined') return; var action = oRequest[ARG_GETS][GET_ACTION]; var callbackStack = []; if (isFailed) { if(typeof(this.failureCallbackStack[action])!='undefined') callbackStack = this.failureCallbackStack[action]; } else { if(typeof(this.successCallbackStack[action])!='undefined') callbackStack = this.successCallbackStack[action]; } // Go through list of action functions msg('Checking callbackStack:'); if (typeof(callbackStack) != 'undefined' && callbackStack.length > 0) { msg('Checking callbackStack:' + callbackStack[0][CALLBACK_FUNCTIONNAME_INDEX] + '::' + callbackStack[0][CALLBACK_OBJECT_INDEX]); var count = 0; var callbackArray = callbackStack.shift(); while (typeof(callbackArray) != 'undefined') { callbackObject = callbackArray[CALLBACK_OBJECT_INDEX]; callbackArg = callbackArray[CALLBACK_ARG_INDEX]; callbackFunctionName = callbackArray[CALLBACK_FUNCTIONNAME_INDEX]; msg('callbackStack:' + callbackObject); _doCallback(callbackFunctionName, callbackArg, callbackObject); callbackArray = callbackStack.shift(); // Next element, reduced array size too } } else { // No handlers if (isFailed) { } } // Call the load event handler, if present if (typeof(MVRZ.util.event.handlers[EVENT_CONNECTION_PROCESSED]) != 'undefined') { msg('_processCallbackStack() event handler: status=' + this.connectStatus); msg('_processCallbackStack() handlers: ' + serializeArray(MVRZ.util.event.handlers[EVENT_CONNECTION_PROCESSED])); for (var eventId in MVRZ.util.event.handlers[EVENT_CONNECTION_PROCESSED]) { msg('_processCallbackStack() event handler for id: ' + eventId); //popup('','_processCallbackStack() event handler for type: ' + type); with (MVRZ.util.event.handlers[EVENT_CONNECTION_PROCESSED][eventId]) { if (typeof(fn) == 'function') { msg('_processCallbackStack() calling handler. callback= ' + fnCallback); fn(fnCallback, fnArg); } } } } else { msg('_processCallbackStack() NO event handler: '); } //popup('', '_processCallbackStack() END'); } function save(p_argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName){ msg('save: ' + this.datasetName); if (typeof(this.request.saveArgArray) == 'undefined') { msg('save: no argument to save, skipping save'); } var argArray = new Object(); argArray[ARG_POST] = p_argArray; ////if(typeof(argArray[ARG_POST])!='undefined') argArray[ARG_POST] = this.request.saveArgArray; // Should this be saved to the server? var noSave = argArray.noSave; if(typeof(noSave)=='undefined') noSave = this.noSave; if(noSave) { // Just save to the local dataset this.postConnect(YUI_ACTION_SAVE, argArray); // Just as if we'd saved to the DB // ... strictly, argArray should be oRequest but this will work } else { // Cancel any auto-save timer MVRZ.util.event.clearTimer(TIMER_SAVE); msg('save: saveStatus=' + this.saveStatus); //if (!this.saveStatus) { this.saveStatus = this.connect(YUI_ACTION_SAVE, argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName); //} } return this.saveStatus; } function del(p_argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName){ msg('del: ' + this.datasetName); var argArray = new Object(); argArray[ARG_GETS] = p_argArray; msg('del: delStatus=' + this.delStatus); ////if(typeof(this.request)=='undefined') this.request = new Object(); ////if(typeof(this.request.delArgArray)=='undefined') this.request.delArgArray = new Array(); ////this.request.delArgArray = argArray; this.delStatus = this.connect(YUI_ACTION_DELETE, argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName); return this.delStatus; } function preload(argArray, callbackObj, callbackArg, successCallbackFunctionName, failureCallbackFunctionName){ //Override this return true; } function postload(oRequest){ //Override this return true; }