git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@160 97e9348a-65ac-dc4b-aefc-98561f571b83
137 lines
4.0 KiB
JavaScript
137 lines
4.0 KiB
JavaScript
/**
|
|
* Function : dump()
|
|
* Arguments: The data - array,hash(associative array),object
|
|
* The level - OPTIONAL
|
|
* Returns : The textual representation of the array.
|
|
* This function was inspired by the print_r function of PHP.
|
|
* This will accept some data as the argument and return a
|
|
* text that will be a more readable version of the
|
|
* array/hash/object that is given.
|
|
* Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
|
|
*/
|
|
function dump(arr,level) {
|
|
var dumped_text = "";
|
|
if(!level) level = 0;
|
|
|
|
//The padding given at the beginning of the line.
|
|
var level_padding = "";
|
|
for(var j=0;j<level+1;j++) level_padding += " ";
|
|
|
|
if(typeof(arr) == 'object') { //Array/Hashes/Objects
|
|
for(var item in arr) {
|
|
var value = arr[item];
|
|
|
|
if(typeof(value) == 'object') { //If it is an array,
|
|
dumped_text += level_padding + "'" + item + "' ...\n";
|
|
dumped_text += dump(value,level+1);
|
|
} else {
|
|
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
|
|
}
|
|
}
|
|
} else { //Stings/Chars/Numbers etc.
|
|
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
|
|
}
|
|
return dumped_text;
|
|
}
|
|
|
|
|
|
function var_dump(element, limit, depth)
|
|
{
|
|
depth = depth?depth:0;
|
|
limit = limit?limit:1;
|
|
|
|
returnString = '<ol>';
|
|
|
|
for(property in element)
|
|
{
|
|
//Property domConfig isn't accessable
|
|
if (property != 'domConfig')
|
|
{
|
|
returnString += '<li><strong>'+ property + '</strong> <small>(' + (typeof element[property]) +')</small>';
|
|
|
|
if (typeof element[property] == 'number' || typeof element[property] == 'boolean')
|
|
returnString += ' : <em>' + element[property] + '</em>';
|
|
if (typeof element[property] == 'string' && element[property])
|
|
returnString += ': <div style="background:#C9C9C9;border:1px solid black; overflow:auto;"><code>' +
|
|
element[property].replace(/</g, '&lt;').replace(/>/g, '&gt;') + '</code></div>';
|
|
|
|
if ((typeof element[property] == 'object') && (depth < limit))
|
|
returnString += var_dump(element[property], limit, (depth + 1));
|
|
|
|
returnString += '</li>';
|
|
}
|
|
}
|
|
returnString += '</ol>';
|
|
|
|
if(depth == 0)
|
|
{
|
|
winpop = window.open("", "","width=800,height=600,scrollbars,resizable");
|
|
winpop.document.write('<pre>'+returnString+ '</pre>');
|
|
winpop.document.close();
|
|
}
|
|
|
|
return returnString;
|
|
}
|
|
|
|
|
|
function htmlEncode(s)
|
|
{
|
|
//return s;
|
|
return s.replace(/&(?!\w+([;\s]|$))/g, "&")
|
|
.replace(/</g, "<").replace(/>/g, ">");
|
|
}
|
|
|
|
function addDiv(id_name, div_name, into_div_name, flash, html, script) {
|
|
var id = $('#'+id_name).val();
|
|
|
|
html = '<DIV class="added-div" id="'+div_name+'-'+id+'">' +
|
|
html.replace(/%{id}/g, id)
|
|
.replace(/%{remove(:([^}]*))?}/g,
|
|
'<SPAN class="remove-div-link">' +
|
|
'<A HREF="#" onClick="removeElement' + "('"+div_name+"-"+id+"')" + '; return false;">' +
|
|
("$2" == "" ? "$2" : 'remove') + '</A>' + '</SPAN>') +
|
|
'</DIV>';
|
|
|
|
if (script) {
|
|
html += '<SCRIPT TYPE="text/javascript">';
|
|
html += script.replace(/%{id}/g, id);
|
|
html += '</SCRIPT>';
|
|
}
|
|
|
|
//$("#debug").append(htmlEncode(html));
|
|
$("#"+into_div_name).append(html);
|
|
|
|
if (flash) {
|
|
$('#'+div_name+'-'+id)
|
|
.animate({ backgroundColor: "yellow" }, 300)
|
|
.animate({ backgroundColor: "white" }, 500);
|
|
}
|
|
|
|
id = id - 0 + 1;
|
|
$('#'+id_name).val(id);
|
|
}
|
|
|
|
function removeElement(elem_id) {
|
|
$('#'+elem_id).remove();
|
|
}
|
|
|
|
|
|
function fmtCurrency(amount) {
|
|
if (amount == null || isNaN(amount))
|
|
return '-';
|
|
|
|
// Get rid of any extraneous characters, determine
|
|
// the sign, and round to the nearest cent.
|
|
amount = amount.toString().replace(/\$|\,/g,'');
|
|
sign = (amount == (amount = Math.abs(amount)));
|
|
amount = (amount+0.0000000001).toFixed(2);
|
|
|
|
// Insert thousands separator
|
|
while (amount != (amount = amount.replace(/(\d)(\d\d\d[.,])/, "$1,$2")));
|
|
|
|
// Return formatted amount
|
|
return (sign?'$':'($') + amount + (sign?'':')');
|
|
}
|
|
|
|
|