var AJAXDebug=0; var TOP_YES = "Yes";//Yes var TOP_NO = "No";//no var TOP_TRUE = "true";//true var TOP_FALSE = "false";//false var TOP_NONE = "None";//none var TOP_ENA = "Enabled";// enabled var TOP_DIS = "Disabled";// disabled var TOP_USR = "User";// user var TOP_OPR = "Operator";// operator var TOP_ADM = "Administrator";// admin var requestCtxt = new Object(); requestCtxt.m_fieldMapping = null; requestCtxt.updateComplete = null; // var FieldMapping; FieldMapping.TYPE_HTML = 0; FieldMapping.TYPE_TEXT = 1; FieldMapping.TYPE_CHECKBOX = 2; FieldMapping.TYPE_SELECT = 3; FieldMapping.TYPE_RADIO = 4; FieldMapping.TYPE_CALLBACK = 5; var xmlRequestObject; var Cell; Cell.ICON = 0; Cell.CONTENT = 1; Cell.BLANK = 2; Cell.HIDDEN = 3; function Cell(type, value, align) { this.m_type = type; this.m_value = value; this.m_align = align; } /////////////////////////////////////////////////////////////// // //Each field has a fieldName and a dataName. // The fieldName is used to map the field to the display value on a page, // if there is no field name then the field is only accessed on // edits. In this way a page can iterate through all values returned by // the server to populate data for the page, but still skip element that // have no display value that would otherwise cause a "field xxxx not found" // message to be displayed. function FieldMapping( n, d, type, encoder, decoder ) { //fieldName used for displaying data this.m_fieldName = n; //dataName used for updating data this.m_dataName = d == null ? n : d; this.m_type = type == null ? FieldMapping.TYPE_HTML : type; this.m_encoder = encoder == null ? encodeText : encoder; this.m_decoder = decoder == null ? decodeText : decoder; } //Convenience object that "extends" FieldMapping with specific checkbox behaviors pre-defined. function CheckboxMapping( n, d ) { return new FieldMapping(n, d, FieldMapping.TYPE_CHECKBOX, encodeCheckbox, decodeBoolean); } //Convenience object that "extends" FieldMapping with specific radio button behaviors pre-defined. function RadioMapping( n, d ) { return new FieldMapping(n, d, FieldMapping.TYPE_RADIO, encodeRadio, decodeRadio); } ///////////////////////////////////// // function encodeSetValue( text ) { if( text == null ) return ""; else { var newUrl = text.replace(/\\/g, "\\\\" ); newUrl = newUrl.replace(/:/g, "\\:" ); // ConnectionHandler's tokenizer uses: (),=&? newUrl = newUrl.replace(/,/g, "\\," ); newUrl = newUrl.replace(/\(/g, "\\(" ); newUrl = newUrl.replace(/\)/g, "\\)" ); newUrl = newUrl.replace(/\=/g, "\\=" ); newUrl = newUrl.replace(/&/g, "\\&" ); newUrl = newUrl.replace(/\?/g, "\\?" ); return encodeURIComponent(newUrl); } } //////////////////////////////////// // Function to encode text fields. function encodeText( formElement ) { return encodeSetValue( formElement.value ); } //////////////////////////////////// // Function to encode checkbox's as 1=true or 0=false. function encodeCheckbox( formElement ) { return formElement.checked ? "1" : "0"; } //////////////////////////////////// // Function to encode checkbox's as 1=true or 0=false. function encodeSelect( formElement ) { if( formElement.selectedIndex >= 0 ) { //alert("call to encodeSelect: " + formElement.options[ formElement.selectedIndex ].value); return formElement.options[ formElement.selectedIndex ].value; } else return ''; } //////////////////////////////////// // Function to encode checkbox's as 1=true or 0=false. function encodeRadio( formElement ) { for( var i=0 ; i 1 ) { var elem = formElement.elements[0]; req = elem.name + ":" + encodeSetValue( elem.value ); // for( var i=1 ; i 0 && elements[0].childNodes != null ) { if( elements[0].childNodes.length == 0 ) return null; else if( elements[0].childNodes[0].nodeType == 3){ var j = elements[0].childNodes.length; for (i = 0; i < j; i++){ rtn = rtn + elements[0].childNodes[i].nodeValue; } //Fix for FireFox. Long returns are broken up into 4096 byte child nodes. IE is all in one. //alert("rtn len=" + rtn.length + "ChildNode count=" + j + "\n" ); } else { rtn = elements[0]; } } } return rtn } ///////////////////////////////////////////////////////////////////////// // // Requests the XML document. // //Lets load the WebPage defined by url ( output should be xml )r //If we are using IE then we will use microsoft ActiveX Object, there are //two microsoft objects we can try. If the first fails, move to second one. //if not IE then we will use the defined JS object XMLHttpRequest(). // function loadXMLDocument( url, callback, postData ) { loadXMLDocument__( url, callback, postData, true ); } function loadXMLDocumentSynchronous( url ) { loadXMLDocument__( url, function (){}, null, false ); } function loadXMLDocument__( url, callback, postData, asynchronous ) { var xDoc; // if( window.XMLHttpRequest ) { xmlRequestObject = new XMLHttpRequest(); } else if( window.ActiveXObject ) // if( window.ActiveXObject ) { try { xmlRequestObject = new ActiveXObject("Msxml2.XMLHTTP"); // alert("XMLHttpRequest is executed"); } catch ( e ) { try { xmlRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); } catch ( E ) { } } } // if( xmlRequestObject ) { xmlRequestObject.onreadystatechange = callback; xmlRequestObject.open("POST", url, asynchronous ); if( postData == null ) postData = ''; xmlRequestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded" ); xmlRequestObject.send( postData ); } } function getXMLTagByName( xmlDoc, name ) { var tagList = xmlDoc.getElementsByTagName( name ); var rtn = null; // if( tagList.length > 0 ) rtn = tagList[0]; return rtn; } function setTextField( fieldId, value ) { var elem = document.getElementById( fieldId ); if( elem != null && elem.value != undefined ) { if (value == null) elem.value = ''; else elem.value = value; } } function setDiv( fieldId, value ) { var elem = document.getElementById(fieldId); //this is the element in the HTML page if (elem != null) { if ("innerText" in elem && "outerHTML" in elem) { elem.innerText= value; elem.textContent=value; } else { elem.innerHTML = value; } } } function setCheckbox( fieldId, value ) { var val = false; if( value != undefined ) val = my_trim(value) == "0" ? false : true; var elem = document.getElementById( fieldId ); if( elem != null && elem.checked != undefined ) elem.checked = val == "0" ? false : true; } function my_trim(str) { if (str == null || str==undefined ) { return ""; } str = str.replace(/^\s*/gi, ""); str = str.replace(/\s*$/gi, ""); return str; } function setRadio( formElement, fieldName, value ) { var val = false; if( value != null ) { for( var i=0 ; i 0 && portNum <= 65535 ? 0 : 1; } } //////////////////////////////////////////////////////////////////// // function ipmiPrivToName( type ) { var name = "Unknown"; if( type == 15 ) name = TOP_NONE;//None if( type == 2 ) name = TOP_USR;//User else if( type == 3 ) name = TOP_OPR//"Operator"; else if( type == 4 ) name = TOP_ADM//"Administrator"; return name; } function showUpdateArea() { hideElement( 'contentArea' ); hideElement('progressScreen'); showInlineElement('updateArea'); } /** * Callback used with loadXMLDocument. This function will * be called each time the xmlRequestObject's readyState changes. * When the readyState is 4, indicating that processing is * complete, the status is checked. If the status is ok then * the method document.chainedCallback will be called. document.chainedCallback * should be defined at the page level prior to calling loadXMLDocument. */ function waitWithCallback() { //Only execute for state "loaded", all other states have // no processing. if (xmlRequestObject.readyState == 4) { // only if "OK" if (xmlRequestObject.status == 200 ) { var xmlDoc = xmlRequestObject.responseXML; var reqStatus = getXMLValue( xmlDoc, 'status' ); if( reqStatus != 'ok' ) { var message = getXMLValue( xmlDoc, 'message' ); //alert(" Request failed: " + message ); //If we fail perform the callback with a null doc // to signal the chainedCallback that the server' // did not recognize the request document.chainedCallback(null); } else { //It might be wise at somepoint to implement // chainedCallback as a stack to avoid accidentally // stepping on a callback by overwriting it with // a value that hasn't been called back yet. This // would introduce substantial complexity though... document.chainedCallback(xmlDoc); if( requestCtxt.updateComplete != null) { requestCtxt.updateComplete( requestCtxt, xmlDoc ); } } } else if( xmlRequestObject.status == 401 ) { document.location = "/login.html"; } else { //showErrorMessage(" Could not retrieve data from server ( status=" + // xmlRequestObject.status + ", " + xmlRequestObject.statusText + ")" ); showContentPanel(); } } } //end of waitWithCallback /** * Rows alternate styles, this method provides a mechanism * for changing the style based on the row index. */ function getStyleForRow(tableRowIndex) { return (tableRowIndex % 2 == 0) ? 'data-area-canvas-odd' : 'data-area-canvas'; } function insertBlankCell(tr, cellIndex) { var cell = tr.insertCell(cellIndex); cell.className=getStyleForRow(tr.rowIndex); cell.innerHTML=''; } function populateCell(cell, tableRowIndex, innerHTML, align, cellType) { cell.className=getStyleForRow(tableRowIndex); cell.vAlign='middle'; if (align !=null) { cell.align=align; } if (cellType == null) { //Don't interpret no type as unknown, default to content. cellType = Cell.CONTENT; } switch (cellType) { case Cell.ICON: cell.innerHTML=""; break; case Cell.CONTENT: cell.innerHTML = (innerHTML == ' ') ? '[N/A]' : innerHTML; break case Cell.BLANK : cell.innerHTML=''; break; case Cell.HIDDEN : cell.innerHTML='' + innerHTML + '' break; default: showErrorMessage("Unknown type for cell, cell - " + celltype); break; } } /** * Submit a request for data to the server and call * refreshDataCallback when the response arrives. */ function refreshData(data) { document.chainedCallback = refreshDataCallback; loadXMLDocument('data?get=' + data, waitWithCallback); } function appendTableRow(table,row) { var aTable = document.getElementById(table); if (null == aTable) return; var newRowIndex = aTable.rows.length; //doesn't seem to be a way to set style="height: 1px;" for blank.gif rows... // but it also doesn't seem to affect table layout. var tr = aTable.insertRow(newRowIndex); for (i = 0; i < row.length; i++) { cell = tr.insertCell(i); populateCell(cell, newRowIndex, row[i].m_value, row[i].m_align, row[i].m_type); } } function clearTableRows(tableName, startRow, endRow) { aTable = document.getElementById(tableName); if (aTable == null || aTable.rows.length==0) { //Nothing to do. return; } if (startRow == null) { startRow = 0; } if (endRow == null || endRow > aTable.rows.length) { endRow = aTable.rows.length; } //Delete at the starting point until // the number of rows between start and end // are gone. for (var x=startRow; x < endRow; x++) { aTable.deleteRow(startRow); } } //Given a select control and a delimitted string convert the string into //options for the select control. function delimValueToOptions(selectControl, value, delim) { //Clear any existing options while (selectControl.options.length > 0) { selectControl.remove(0); } if (value == null) { return; } var valueArray = value.split(delim); for (var optionIndex=0; optionIndex/g, ">"); return text ; }