/**
* This file is a component of FREE SOFTWARE.
* Any entity with self-awareness, or organization are allowed to use, modify or
* redistribute this according to the second version of "GNU Public License".
* The goal of this distribution is that this software being useful and helpful,
* FOR A PARTICULAR PURPOSE.
*/
/**
* A pack of tool functions for AJAX Data Manager.
*
* @author Typhoon.Free.Wolf
* @version 2014-06-01_10-21.childrens_day
*/
/**
* Checks whether debug pre-AJAX.
*
* @author Typhoon.Free.Wolf
* @version 2014-02-12_13-00
* @return A boolean flag that indicates whether show debug information (true)
* or not (false).
*/
function debugPreAjax()
{
// Searched from http://www.duckduckgo.com .
return $('#chkDebug1').is(':checked');
}
/**
* Checks whether debug AJAX.
*
* @author Typhoon.Free.Wolf
* @version 2014-02-12_13-00
* @return A boolean flag that indicates whether show debug information (true)
* or not (false).
*/
function debugAjax()
{
// Searched from http://www.duckduckgo.com .
return $('#chkDebug2').is(':checked');
}
/**
* Checks whether debug after AJAX.
*
* @author Typhoon.Free.Wolf
* @version 2014-02-12_13-01
* @return A boolean flag that indicates whether show debug information (true)
* or not (false).
*/
function debugAfterAjax()
{
// Searched from http://www.duckduckgo.com .
return $('#chkDebug3').is(':checked');
}
/**
* Checks whether alert for write operation.
*
* @author Typhoon.Free.Wolf
* @version 2014-02-12_13-01
* @return A boolean flag that indicates whether
* show write operation result (true) or not (false).
*/
function debugAlertWrite()
{
// Searched from http://www.duckduckgo.com .
return $('#chkAlert').is(':checked');
}
/**
* Cleans previous result.
*
* @author Typhoon.Free.Wolf
* @version 2014-02-12_13-01
*/
function cleanResults()
{
var strFuncName = 'cleanResults()';
var blDebugFlag = debugPreAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var tbodyReports;
try
{
$('#result\\.tbodyResults').empty();
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] ' + strFuncName + ':\n' + e1);
}
}
/**
* Configures data selector of current session.
*
* @author Typhoon.Free.Wolf
* @version 2014-02-10_00-13
* @param strUrl
* - Controller URL.
*/
function configSelectorA(strControllerUrl)
{
_configSelector_(strControllerUrl, null, null, null, null, null);
}
/**
* Configures data selector of current session.
*
* @author Typhoon.Free.Wolf
* @version 2014-03-12_12-44
* @param strUrl
* - Controller URL.
*/
function configSelectorB(strControllerUrl)
{
var strFuncName = 'configSelectorB(\'' + strControllerUrl + '\')';
var blDebugFlag = debugPreAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var hashParams;
var strStartRowIdx;
var strSelectRowCount;
var str1dColumnNames;
var intColumnCount;
var intColIdx;
var strColumnName;
var strValueElementId;
var strValue;
var strFlagElementId;
var strFlag;
try
{
strStartRowIdx = getElementValueById('selector.start_row_idx');
strSelectRowCount = getElementValueById('selector.select_row_count');
hashParams = {
start_row_idx: strStartRowIdx,
select_row_count: strSelectRowCount
};
str1dColumnNames = [ 'id', 'name', 'stat', 'weight', 'remark' ];
intColumnCount = str1dColumnNames.length
for (intColIdx = 0; intColIdx < intColumnCount; intColIdx++)
{
strColumnName = str1dColumnNames[intColIdx];
strValueElementId = 'selector.' + strColumnName;
strValue = getElementValueById(strValueElementId);
strFlagElementId = strValueElementId + '_column_flag';
strFlag = getElementValueById(strFlagElementId);
hashParams[strColumnName + '_column_flag'] = strFlag;
hashParams[strColumnName] = strValue;
}
_configSelector_(strControllerUrl, strStartRowIdx, strSelectRowCount,
null, null, hashParams);
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] ' + strFuncName + ':\n' + e1);
}
}
/**
* Configures data selector of current session.
*
* @author Typhoon.Free.Wolf
* @version 2014-02-10_00-13
* @param strUrl
* - Controller URL.
* @param strOrderColName
* - Order column name.
* @param strOrderColFlag
* - Order column ascending / descending flag.
*/
function configSelectorC(strControllerUrl, strOrderColName, strOrderColFlag)
{
_configSelector_(strControllerUrl, null, null, strOrderColName,
strOrderColFlag, null);
}
/**
* Core operation of selector configure.
*
* @author Typhoon.Free.Wolf
* @version 2014-03-12_12-45
* @param strUrl
* - Controller URL.
* @param strStartRowIdx
* - Start row index.
* @param strSelectRowCount
* - Select row count.
* @param strOrderColName
* - Order column name.
* @param strOrderColFlag
* - Order column ascending / descending flag.
* @param hashParams
* - An associative array of http parameters.
*/
function _configSelector_(strControllerUrl, strStartRowIdx, strSelectRowCount,
strOrderColName, strOrderColFlag, hashParams)
{
var strFuncName = '_configSelector_(\'' + strControllerUrl + '\', '
+ strStartRowIdx + ', ' + strSelectRowCount + ', \''
+ strOrderColName + '\', \'' + strOrderColFlag + '\', hashParams)';
var blDebugFlag = debugPreAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
try
{
if (null == hashParams)
{
hashParams = new Object();
}
hashParams['type'] = 'xml';
hashParams['for'] = 'config_selector';
if (null != strStartRowIdx)
{
hashParams['start_row_idx'] = strStartRowIdx;
}
if (null != strSelectRowCount)
{
hashParams['select_row_count'] = strSelectRowCount;
}
if (null != strOrderColName)
{
hashParams['order_by_col'] = strOrderColName;
}
if (null != strOrderColFlag)
{
hashParams['col_' + strOrderColName + '_asc_desc_flag']
= strOrderColFlag;
}
// Type error in IE6!!!
// ----------------------------------------
// if (blDebugFlag) { alert('[01] hashParams count: '
// + Object.keys(hashParams).length ); }
// doAjax(debugAjax(), strControllerUrl, hashParams, 'post', true,
// afterAjax, [ afterConfig, [ strControllerUrl ]]);
$.ajax({ url: strControllerUrl, data: hashParams,
type: 'post', async: true,
dataType: 'xml',
success: function(objResponse)
{
// var xmlDomResponse = parseFromString(debugAfterAjax(),
// objResponse);
afterAjaxSuccess(objResponse,
[ afterConfig, [ strControllerUrl ]]);
}
});
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] [04] ' + strFuncName + ':\n' + e1);
}
}
/**
* Do list.
*
* @author Typhoon.Free.Wolf
* @version 2014-03-12_12-45
* @param strUrl
* - Controller URL.
*/
function doList(strControllerUrl)
{
var strFuncName = 'doList(\'' + strControllerUrl + '\')';
var blDebugFlag = debugPreAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var hashParams;
try
{
// "for" is a sensitive word in javascript, and can cause error in IE6!
// [X] hashParams = { ..., for: 'xml', ... };
// ----------------------------------------
// [X] hashParams.XXX = ...
// Also error in IE6.
// The ONLY safe way:
hashParams = new Object();
hashParams['type'] = 'xml';
hashParams['for'] = 'do_list';
// Type error in IE6!!!
// ----------------------------------------
// if (blDebugFlag) { alert('[01] hashParams count: '
// + Object.keys(hashParams).length ); }
// doAjax(debugAjax(), strControllerUrl, hashParams, 'post', true,
// afterAjax, [ afterList, [ strControllerUrl ]]);
$.ajax({ url: strControllerUrl, data: hashParams,
type: 'post', async: true,
dataType: 'xml',
success: function(objResponse)
{
// var xmlDomResponse = parseFromString(debugAfterAjax(),
// objResponse);
afterAjaxSuccess(objResponse,
[ afterList, [ strControllerUrl ]]);
}
});
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] ' + strFuncName + ':\n' + e1);
}
}
/**
* Do add.
*
* @author Typhoon.Free.Wolf
* @version 2014-03-12_12-46
* @param strUrl
* - Controller URL.
*/
function doAdd(strControllerUrl)
{
var strFuncName = 'doAdd(\'' + strControllerUrl + '\')';
var blDebugFlag = debugPreAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var strSeq;
var strRowId;
var strName;
var strStat;
var strWeight;
var strRemark;
var hashParams;
try
{
strSeq = $('#add\\.seq').val();
strRowId = $('#add\\.id_' + strSeq).val();
strName = $('#add\\.name_' + strSeq).val();
strStat = $('#add\\.stat_' + strSeq).val();
strWeight = $('#add\\.weight_' + strSeq).val();
strRemark = $('#add\\.remark_' + strSeq).val();
// "for" is a sensitive word in javascript, and can cause error in IE6!
// [X] hashParams = { ..., for: 'xml', ... };
// ----------------------------------------
// [X] hashParams.XXX = ...
// Also error in IE6.
// The ONLY safe way:
hashParams = new Object();
hashParams['type'] = 'xml';
hashParams['for'] = 'do_add';
hashParams['seq'] = strSeq;
hashParams[ 'id_' + strSeq] = strRowId;
hashParams[ 'name_' + strSeq] = strName;
hashParams[ 'stat_' + strSeq] = strStat;
hashParams[ 'weight_' + strSeq] = strWeight;
hashParams[ 'remark_' + strSeq] = strRemark;
// Type error in IE6!!!
// ----------------------------------------
// if (blDebugFlag) { alert('[01] hashParams count: '
// + Object.keys(hashParams).length ); }
// doAjax(debugAjax(), strControllerUrl, hashParams, 'post', true,
// afterAjax, [ afterAdd, [ strControllerUrl ]]);
$.ajax({ url: strControllerUrl, data: hashParams,
type: 'post', async: true,
dataType: 'xml',
success: function(objResponse)
{
// var xmlDomResponse = parseFromString(debugAfterAjax(),
// objResponse);
afterAjaxSuccess(objResponse,
[ afterAdd, [ strControllerUrl ]]);
}
});
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] ' + strFuncName + ':\n' + e1);
}
}
/**
* Do edit.
*
* @author Typhoon.Free.Wolf
* @version 2014-03-12_12-46
* @param strUrl
* - Controller URL.
* @param strRowId
* - Row ID.
*/
function doEdit(strControllerUrl, strRowId)
{
var strFuncName = 'doEdit(\'' + strControllerUrl + '\', ' + strRowId + ')';
var blDebugFlag = debugPreAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var strName;
var strStat;
var strWeight;
var strRemark;
var hashParams;
try
{
strName = $('#' + strRowId + '\\.name').val();
strStat = $('#' + strRowId + '\\.stat').val();
strWeight = $('#' + strRowId + '\\.weight').val();
strRemark = $('#' + strRowId + '\\.remark').val();
// "for" is a sensitive word in javascript, and can cause error in IE6!
// [X] hashParams = { ..., for: 'xml', ... };
// ----------------------------------------
// [X] hashParams.XXX = ...
// Also error in IE6.
// The ONLY safe way:
hashParams = new Object();
hashParams['type'] = 'xml';
hashParams['for'] = 'do_edit';
hashParams['id'] = strRowId;
hashParams['name_effect_flag'] = 'true';
hashParams['name'] = strName;
hashParams['stat_effect_flag'] = 'true';
hashParams['stat'] = strStat;
hashParams['weight_effect_flag'] = 'true';
hashParams['weight'] = strWeight;
hashParams['remark_effect_flag'] = 'true';
hashParams['remark'] = strRemark;
// Type error in IE6!!!
// ----------------------------------------
// if (blDebugFlag) { alert('[01] hashParams count: '
// + Object.keys(hashParams).length ); }
// doAjax(debugAjax(), strControllerUrl, hashParams, 'post', true,
// afterAjax, [ afterEdit, [ strControllerUrl ]]);
$.ajax({ url: strControllerUrl, data: hashParams,
type: 'post', async: true,
dataType: 'xml',
success: function(objResponse)
{
// var xmlDomResponse = parseFromString(debugAfterAjax(),
// objResponse);
afterAjaxSuccess(objResponse,
[ afterEdit, [ strControllerUrl ]]);
}
});
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] ' + strFuncName + ':\n' + e1);
}
}
/**
* Do remove.
*
* @author Typhoon.Free.Wolf
* @version 2014-03-12_12-47
* @param strUrl
* - Controller URL.
* @param strRowId
* - Row ID.
*/
function doRemove(strControllerUrl, strRowId)
{
var strFuncName = 'doRemove(\'' + strControllerUrl + '\', '
+ strRowId + ')';
var blDebugFlag = debugPreAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var hashParams;
try
{
// "for" is a sensitive word in javascript, and can cause error in IE6!
// [X] hashParams = { ..., for: 'xml', ... };
// ----------------------------------------
// [X] hashParams.XXX = ...
// Also error in IE6.
// The ONLY safe way:
hashParams = new Object();
hashParams['type'] = 'xml';
hashParams['for'] = 'do_remove';
hashParams['id'] = strRowId;
// Type error in IE6!!!
// ----------------------------------------
// if (blDebugFlag) { alert('[01] hashParams count: '
// + Object.keys(hashParams).length ); }
// doAjax(debugAjax(), strControllerUrl, hashParams, 'post', true,
// afterAjax, [ afterRemove, [ strControllerUrl ]]);
$.ajax({ url: strControllerUrl, data: hashParams,
type: 'post', async: true,
dataType: 'xml',
success: function(objResponse)
{
// var xmlDomResponse = parseFromString(debugAfterAjax(),
// objResponse);
afterAjaxSuccess(objResponse,
[ afterRemove, [ strControllerUrl ]]);
}
});
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] ' + strFuncName + ':\n' + e1);
}
}
/**
* Subsequent after AJAX.
*
* @author Typhoon.Free.Wolf
* @version 2014-03-12_12-47
* @param xhr
* - XML http request.
* @param o1dArgs
* - An array of arguments.
*/
function afterAjax(xhr, o1dArgs)
{
var strFuncName = 'afterAjax(' + xhr + ', ' + o1dArgs + ')';
var blDebugFlag = debugAfterAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var xmlDomResponse;
try
{
if (4 == xhr.readyState && 200 == xhr.status)
{
if (blDebugFlag)
{ alert('[01] xhr.responseText:\n--------\n' + xhr.responseText); }
xmlDomResponse = parseFromString(blDebugFlag, xhr.responseText);
afterAjaxSuccess(xmlDomResponse, o1dArgs);
}
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] [03] ' + strFuncName + ':\n' + e1);
}
}
/**
* Subsequent after AJAX.
*
* @author Typhoon.Free.Wolf
* @version 2014-03-12_12-48
* @param xmlDomResponse
* - XML DOM response.
* @param o1dArgs
* - An array of arguments.
*/
function afterAjaxSuccess(xmlDomResponse, o1dArgs)
{
var strFuncName = 'afterAjaxSuccess(' + xmlDomResponse + ', ' + o1dArgs
+ ')';
var blDebugFlag = debugAfterAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var xmlDomResult;
var xmlDomReport;
try
{
if (null != xmlDomResponse)
{
xmlDomResult = getElementByTagName(xmlDomResponse, 'result', 0);
if (null != xmlDomResult)
{
xmlDomReport = getElementByTagName(xmlDomResult, 'report',
0);
if (null != xmlDomReport)
{
if (blDebugFlag)
{ alert('[02] xmlDomReport:\n' + xmlDomReport); }
appendResult(xmlDomReport);
}
}
o1dArgs[0](xmlDomResult, o1dArgs[1]);
}
if (blDebugFlag) { alert('[E] ' + strFuncName); }
}
catch (e1)
{
alert('[!] [03] ' + strFuncName + ':\n' + e1);
}
}
/**
* Appends result.
*
* @author Typhoon.Free.Wolf
* @version 2014-05-30_22-18
* @param xmlDomReport
* - XML DOM element of report.
*/
function appendResult(xmlDomReport)
{
var strFuncName = 'appendResult(xmlDomReport)';
var blDebugFlag = debugAfterAjax();
if (blDebugFlag) { alert('[S] ' + strFuncName); }
var e1;
var tbodyReports;
var trResultStat;
var strResultStat;
var intProcStat;
var thResultStat;
var tdResultStat;
var thResultSummary;
var tdResultSummary;
var strResultSummary;
var trTimeCost;
var thTimeCost;
var tdTimeCost;
var thReport;
var tableTimeCost;
var tr_0;
var th_0;
var td_1;
var th_2;
var td_3;
var tr_1;
var tr_2;
var tr_3;
var trTitles;
var th;
var xmlDom1dRows;
var intRowIdx;
var xmlDomRow;
var tr;
var strContent;
try
{
tbodyReports = document.getElementById('result.tbodyResults');
{
// Attributes.
// ========================================
// Children.
trResultStat = document.createElement('tr');
tbodyReports.appendChild(trResultStat);
{
trResultStat.style.verticalAlign = 'top';
strResultStat = xmlDomReport.getAttribute('process_stat');
intProcStat = (null == strResultStat) ? -1
: parseInt(strResultStat);
if (0 == intProcStat)
{
// OK.
trResultStat.style.backgroundColor = COLOR_OK_BACKGROUND;
trResultStat.style.color = COLOR_OK;
}
else if (0 > intProcStat)
{
// Error.
trResultStat.style.backgroundColor = COLOR_EOORO_BACKGROUND;
trResultStat.style.color = COLOR_EOORO;
}
else if (10 < intProcStat)
{
// Failed.
trResultStat.style.backgroundColor
= COLOR_FAILED_BACKGROUND;
trResultStat.style.color = COLOR_FAILED;
}
else
{
// Partly.
trResultStat.style.backgroundColor
= COLOR_PARTLY_BACKGROUND;
trResultStat.style.color = COLOR_PARTLY;
}
// Attributes.
// =========xmlDomResult======================
// Children.
thResultStat = document.createElement('th');
trResultStat.appendChild(thResultStat);
{
thResultStat.innerHTML = 'Result
';
// Attributes.
// ========================================
// Children.
}
tdResultStat = document.createElement('td');
trResultStat.appendChild(tdResultStat);
{
tdResultStat.innerHTML = '
' + strResultStat + ''; tdResultStat.style.textAlign = 'center'; // Attributes. // ======================================== // Children. } thResultSummary = document.createElement('th'); trResultStat.appendChild(thResultSummary); { thResultSummary.innerHTML = 'Summary
'; // Attributes. // ======================================== // Children. } tdResultSummary = document.createElement('td'); trResultStat.appendChild(tdResultSummary); { tdResultSummary.colSpan = '2'; strResultSummary = xmlDomReport .getAttribute('process_summary'); tdResultSummary.innerHTML = '' + strResultSummary + ''; // Attributes. // ======================================== // Children. } } trTimeCost = document.createElement('tr'); tbodyReports.appendChild(trTimeCost); { // Attributes. // ======================================== // Children. thTimeCost = document.createElement('th'); trTimeCost.appendChild(thTimeCost); { thTimeCost.style.verticalAlign = 'top'; thTimeCost.innerHTML = 'Time'; // Attributes. // ======================================== // Children. } tdTimeCost = document.createElement('td'); trTimeCost.appendChild(tdTimeCost); { tdTimeCost.colSpan = '4'; // Attributes. // ======================================== // Children. tableTimeCost = document.createElement('table'); // This thing doesn't work correctly in IE!! // - - - - - - - - - - - - - - // tdTimeCost.appendChild(tableTimeCost); // tableTimeCost.style.width = '100%'; { // Attributes. // ======================================== // Children. tr_0 = document.createElement('tr'); tableTimeCost.appendChild(tr_0); { // Attributes. // ======================================== // Children. th_0 = document.createElement('th'); tr_0.appendChild(th_0); { th_0.style.textAlign = 'right'; th_0.style.width = '25%'; th_0.innerHTML = 'Request Came At:
'; // Attributes. // ======================================== // Children. } td_1 = document.createElement('td'); tr_0.appendChild(td_1); { td_1.style.textAlign = 'left'; td_1.style.width = '25%'; td_1.innerHTML = xmlDomReport .getAttribute('request_come_ts'); // Attributes. // ======================================== // Children. } th_2 = document.createElement('th'); tr_0.appendChild(th_2); { th_2.rowSpan = '2'; th_2.style.textAlign = 'right'; th_2.style.width = '25%'; th_2.innerHTML = 'Process Time Cost:
'; // Attributes. // ======================================== // Children. } td_3 = document.createElement('td'); tr_0.appendChild(td_3); { td_3.rowSpan = '2'; td_3.style.textAlign = 'left'; td_3.style.width = '25%'; td_3.innerHTML = xmlDomReport .getAttribute('process_time_cost'); // Attributes. // ======================================== // Children. } } tr_1 = document.createElement('tr'); tableTimeCost.appendChild(tr_1); { // Attributes. // ======================================== // Children. th_0 = document.createElement('th'); tr_1.appendChild(th_0); { th_0.rowSpan = '2'; th_0.style.textAlign = 'right'; th_0.innerHTML = 'Process Done At:
'; // Attributes. // ======================================== // Children. } td_1 = document.createElement('td'); tr_1.appendChild(td_1); { td_1.rowSpan = '2'; td_1.style.textAlign = 'left'; td_1.innerHTML = xmlDomReport .getAttribute('process_done_ts'); // Attributes. // ======================================== // Children. } } tr_2 = document.createElement('tr'); tableTimeCost.appendChild(tr_2); { // Attributes. // ======================================== // Children. th_2 = document.createElement('th'); tr_2.appendChild(th_2); { th_2.rowSpan = '2'; th_2.style.textAlign = 'right'; th_2.innerHTML = 'Forward Time Cost:
'; // Attributes. // ======================================== // Children. } td_3 = document.createElement('td'); tr_2.appendChild(td_3); { td_3.rowSpan = '2'; td_3.style.textAlign = 'left'; td_3.innerHTML = xmlDomReport .getAttribute('forward_time_cost'); // Attributes. // ======================================== // Children. } } tr_3 = document.createElement('tr'); tableTimeCost.appendChild(tr_3); { th_0 = document.createElement('th'); tr_3.appendChild(th_0); { th_0.style.textAlign = 'right'; th_0.innerHTML = 'Forward Done At:
'; // Attributes. // ======================================== // Children. } td_1 = document.createElement('td'); tr_3.appendChild(td_1); { td_1.style.textAlign = 'left'; td_1.innerHTML = xmlDomReport .getAttribute('forward_done_ts'); // Attributes. // ======================================== // Children. } } } // This ugly, magical thing works correctly // both in Firefox and IE. tdTimeCost.innerHTML = '
' + strContent + ''; } // Attributes. // ======================================== // Children. } td = document.createElement('td'); tr.appendChild(td); { strContent = xmlDomRow.getAttribute('exception'); if (null != strContent) { strContent = strContent.replace(/\\r/g, '\r'); strContent = strContent.replace(/\\n/g, '\n'); td.innerHTML = '
' + strContent + ''; } // Attributes. // ======================================== // Children. } } } } } if (blDebugFlag) { alert('[E] ' + strFuncName); } } catch (e1) { alert('[!] ' + strFuncName + ':\n' + e1); } } /** * Subsequent after configuring.