/* * $Id$ * * Copyright (c) 2001-2015 Avocent Corporation. All rights reserved. * * @file dataFunctions.js * The file defines functions for generating request URI from HTML elements, * sending POST request, getting response and saving the response value back to * HTML elements. */ var AJAXDebug = 0; var VAL_TRUE = "1"; var VAL_FALSE = "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 plsWaitMsg = "Please Wait"; // Please wait var unknowExcMsg = "Unknown exception occurred during this operation."; // Unknown exception occurred during this operation. var excMsg = "Unable to retrieve data. Please try again later."; // Unable to retrieve data. Please try again later. var securityExcMsg = "Security exception occurred during this operation."; // Security exception occurred during this operation. var badReqExcMsg = "Bad request format exception occurred during this operation."; // Bad request format exception occurred during this operation. var setErrorExcMsg = "Exception occurred while setting configurations." // Exception occurs while setting new configurations. var smbiosExcMsg = "Unable to retrieve SMBIOS data. Please wait for BIOS ready and try again."; var requestCtxt = new Object(); requestCtxt.m_fieldMapping = null; requestCtxt.updateComplete = null; var FieldMapping; FieldMapping.TYPE_HTML = 0; // Indicates the field ia a HTML element other than the following. FieldMapping.TYPE_TEXT = 1; // Indicates the field is a HTML input element of text type. FieldMapping.TYPE_TEXT_NUMERIC = 2; // Indicates the field is a HTML input element of text type, whose content is numeric. FieldMapping.TYPE_CHECKBOX = 3; // Indicates the field is a HTML input element of checkbox type. FieldMapping.TYPE_SELECT = 4; // Indicates the field ia a HTML select element. FieldMapping.TYPE_RADIO = 5; // Indicates the field is a HTML input element of radio type. FieldMapping.TYPE_CALLBACK = 6; // Indicates the field content is updated by the function dataCallback() in each page. var xmlRequestObject; var Cell; Cell.ICON = 0; Cell.CONTENT = 1; Cell.BLANK = 2; Cell.HIDDEN = 3; var MSG_TYPE_INFO = 0; // Indicates an info message var MSG_TYPE_ERROR = 1; // Indicates an error message // XML/HTML DOM Node Types named constants. Reference: http://www.w3schools.com/jsref/prop_node_nodetype.asp var ELEMENT_NODE = 1; var ATTRIBUTE_NODE = 2; var TEXT_NODE = 3; var CDATA_SECTION_NODE = 4; var ENTITY_REFERENCE_NODE = 5; var ENTITY_NODE = 6; var PROCESSING_INSTRUCTION_NODE = 7; var COMMENT_NODE = 8; var DOCUMENT_NODE = 9; var DOCUMENT_TYPE_NODE = 10; var DOCUMENT_FRAGMENT_NODE = 11; var NOTATION_NODE = 12; /* * Use the global variable to call setTimeout() method to execute an auto refresh triggered function, or call * clearTimeout() to stop the execution. */ var G_hAutoRefreshIntervalHandle = null; /* * Use the global variable to call setInterval() method to execute an auto refresh triggered function, or call * cleareInterval() to stop the execution. */ var G_hAutoRefreshTimeoutHandle = null; /** * Determines whether the HTTP request being sent out is from end user's action (if false) or a web page's automated * refresh (if true). It sets the value of HTTP header field "GUIAutoRefresh" to "false" or "true" likewise. */ var G_bIsAutoRefresh = false; /** * Sets the global variable G_bIsAutoRefresh. * * @param bIsAutoRefresh - the value to be set to G_bIsAutoRefresh. */ function setIsAutoRefresh(bIsAutoRefresh) { G_bIsAutoRefresh = bIsAutoRefresh; } /** * Returns the global variable G_bIsAutoRefresh. * * @return The value of G_bIsAutoRefresh. */ function getIsAutoRefresh() { return (G_bIsAutoRefresh); } /** * Defines a class named Cell which performs as an HTML table cell. * * @param type - The content type of the table cell. * @param value - The content of the table cell. * @param align - The alignment type of the content of the table cell. * @param bIsWrappable - Indicates whether the content of the table cell can be wrapped or not. * If not specified, bIsWrappable will be treated as false by default. * @param strCellStyle - The style of the table cell. * @param fnOnClickCallback - The callback function which is invoked when the cell element is clicked. */ function Cell(type, value, align, bIsWrappable, strCellStyle, fnOnClickCallback) { this.m_type = type; this.m_value = value; this.m_align = align; if (bIsWrappable != true) { this.m_bIsWrappable = false; } else { this.m_bIsWrappable = true; } this.m_strCellStyle = strCellStyle; this.m_fnOnClickCallback = fnOnClickCallback; } /** * Defines a class named FieldMapping. * Each field has a fieldName and a dataName. * * @param strElementId - the element id of field. * @param strGUIPropertyName - the GUI property name of field. * @param type - the type of the field. * @param encoder - a pointer to the function which can encode the field data. * @param decoder - a pointer to the function which can decode the field data. * * @note 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(strElementId, strGUIPropertyName, type, encoder, decoder) { // m_fieldName is used for displaying data. this.m_fieldName = strElementId; // m_fieldOriginalValue is used for saving value of HTML element when page is loaded. this.m_fieldOriginalValue = ""; // m_dataName is used for updating data. if (strGUIPropertyName == null) { this.m_dataName = strElementId; } else { this.m_dataName = strGUIPropertyName; } if (type == null) { this.m_type = FieldMapping.TYPE_HTML; } else { this.m_type = type; } if (encoder == null) { this.m_encoder = encodeText; } else { this.m_encoder = encoder; } if (decoder == null) { this.m_decoder = decodeText; } else { this.m_decoder = decoder; } } /** * Gets the FieldMapping object whose m_fieldName matches the specified field name. * * @param strFieldName - The specified field name. * @return The FieldMapping object whose m_fieldName matches the specified field name. * null if no FieldMapping objects matches the specified field name */ function getFieldMapByName(strFieldName) { if (strFieldName == null) { return (null); } for (var idx = 0; idx < fieldList.length; ++idx) { if (strFieldName == fieldList[idx].m_fieldName) { return (fieldList[idx]); } } return (null); } /** * Gets the value of a visible HTML element according to its element type. * * @param fieldMap - A pointer to the FieldMapping object. * @return The value of the visible HTML element. null if the visible HTML element is not found. * @note This function has dependency on validate.js because it uses some functions defined in validate.js. * Please include validate.js in the html page when this function is used. */ function getHTMLFieldValue(fieldMap) { if (fieldMap == null) { return (null); } var objVisibleElement = null; var iFieldType = fieldMap.m_type; if (iFieldType == FieldMapping.TYPE_RADIO) { objVisibleElement = document.getElementsByName(fieldMap.m_fieldName); if (objVisibleElement == null) { return (null); } for (var i = 0; i < objVisibleElement.length; i++) { if (objVisibleElement[i].checked == true) { return (objVisibleElement[i].value); } } } else { objVisibleElement = document.getElementById(fieldMap.m_fieldName); if (objVisibleElement == null) { return (null); } if (iFieldType == FieldMapping.TYPE_HTML) { return (objVisibleElement.innerHTML); } else if (iFieldType == FieldMapping.TYPE_TEXT) { return (objVisibleElement.value); } else if (iFieldType == FieldMapping.TYPE_TEXT_NUMERIC) { if (isAHexValue(objVisibleElement.value)) { return (convertHexToDec(objVisibleElement.value)); } return (objVisibleElement.value); } else if (iFieldType == FieldMapping.TYPE_CHECKBOX) { return (objVisibleElement.checked); } else if (iFieldType == FieldMapping.TYPE_SELECT) { if (objVisibleElement.options == null) { return (null); } for (var i = 0; i < objVisibleElement.options.length; i++) { if (objVisibleElement.options[i].selected == true) { return (objVisibleElement.options[i].value); } } } } return (null); } /** * Sets the HTML element value according to its element type. * * @param fieldMap - A pointer to the FieldMapping object. * @param strValue - The value which want to set. * @note This function is created for setting the value which stores at FieldMapping.m_fieldOriginalValue. */ function setHTMLFieldValue(fieldMap, strValue) { if (fieldMap == null) { return; } switch (fieldMap.m_type) { case FieldMapping.TYPE_RADIO: setRadio(fieldMap.m_fieldName, strValue); break; case FieldMapping.TYPE_HTML: setDiv(fieldMap.m_fieldName, strValue); break; case FieldMapping.TYPE_TEXT: case FieldMapping.TYPE_TEXT_NUMERIC: setTextField(fieldMap.m_fieldName, strValue); break; case FieldMapping.TYPE_CHECKBOX: setCheckbox(fieldMap.m_fieldName, strValue); break; case FieldMapping.TYPE_SELECT: setSelectedOption(fieldMap.m_fieldName, strValue); break; default: break; } } /** * Restores field value from its original setting. * * @param strFieldName - The id attribute of the HTML element, * or name attribute if its type is FieldMapping.TYPE_RADIO. */ function restoreHTMLFieldValue(strFieldName) { if (("" == strFieldName) || (strFieldName == null) || (strFieldName == undefined)) { return; } var objFieldMap = getFieldMapByName(strFieldName); if (objFieldMap == null) { return; } setHTMLFieldValue(objFieldMap, objFieldMap.m_fieldOriginalValue); } /** * Restores the value of the disabled fields to original setting. */ function restoreDisabledFieldValue() { for (var iIndex = 0; iIndex < fieldList.length; iIndex++) { var objField = myGetElementById(fieldList[iIndex].m_fieldName); if ((objField != null) && (true == objField.disabled)) { restoreHTMLFieldValue(fieldList[iIndex].m_fieldName); } } } /** * Sets original values of visible HTML elements. * * @note It seems to be more properly to save original values inside setFieldListFromXML(). * However in some pages such as Network Interface configuration, Services, some HTML elements are modified * after calling setFieldListFromXML() therefore this function is isolated from setFieldListFromXML() so that * we can make sure the settings saved are those displayed in WebGUI. * In addition, this function has dependency on validate.js because it calls getHTMLFieldValue(). * Please include validate.js in the html page when this function is used. */ function setOriginalSettings() { for (var i = 0; i < fieldList.length; i++) { fieldList[i].m_fieldOriginalValue = getHTMLFieldValue(fieldList[i]); } } /** * Gets original value of the specified visible HTML element. * * @param strFieldName - The id attribute of the visible HTML element, * or name attribute if its type is FieldMapping.TYPE_RADIO. * * @return Original value of the HTML element. * null if any error occurs. */ function getOriginalSetting(strFieldName) { if (("" == strFieldName) || (strFieldName == null) || (strFieldName == undefined)) { return (null); } for (var i = 0; i < fieldList.length; i++) { if (strFieldName == fieldList[i].m_fieldName) { return (fieldList[i].m_fieldOriginalValue); } } return (null); } /** * Checks if the values of visible HTML elements are changed. * * @param bIsToCompareDisabled - Indicate if to compare when the visible HTML element is disabled. * @return true - Changed. * @return false - Not changed. * @note This function has dependency on validate.js because it calls isVisibleFieldChanged(). * Please include validate.js in the html page when this function is used. */ function isVisibleFieldListChanged(bIsToCompareDisabled) { for (var i = 0; i < fieldList.length; i++) { if (isVisibleFieldChanged(fieldList[i].m_fieldName, bIsToCompareDisabled)) { return (true); } } return (false); } /** * Checks if the value of a visible HTML element is changed. * * @param strFieldName - The id of the visible HTML element to be checked. * @param bIsToCompareDisabled - Indicate if to compare when the visible HTML element is disabled. * @return true - The value is changed. * @return false - The value is not changed, or the parameters are null, * or the visible HTML element with id 'strFieldName' cannot be found. * @note This function has dependency on validate.js because it may call getHTMLFieldValue(). * Please include validate.js in the html page when this function is used. */ function isVisibleFieldChanged(strFieldName, bIsToCompareDisabled) { if ((strFieldName == null) || (bIsToCompareDisabled == null)) { return (false); } var objFieldMap = getFieldMapByName(strFieldName); if (objFieldMap == null) { return (false); } var objVisibleElement = null; var objVisibleValue = null; if (objFieldMap.m_type == FieldMapping.TYPE_RADIO) { objVisibleElement = document.getElementsByName(objFieldMap.m_fieldName)[0]; } else { objVisibleElement = document.getElementById(objFieldMap.m_fieldName); } if ((objVisibleElement.disabled) && (!bIsToCompareDisabled)) { return (false); } objVisibleValue = getHTMLFieldValue(objFieldMap); if (objFieldMap.m_fieldOriginalValue == objVisibleValue) { return (false); } return (true); } /** * Returns the textual content of the element. * * @param strElementId - The id of the element. * @return The textual content of the element, or an empty string if error occurred. */ function getElementValueById(strElementId) { if (strElementId == null) { return (""); } var objElement = document.getElementById(strElementId); if (objElement == null) { return (""); } if (objElement.textContent) { // All brosers except IE8 or earlier. return (objElement.textContent); } else if (objElement.innerText) { // IE only. return (objElement.innerText); } // Use innerHTML as fallback (but should never reach here). return (objElement.innerHTML); } /** * Returns the element of specified by the id. * * @param strElementId - The id of the element. * @return The reference to the element. * @note This function is a simple wrapper of document.getElementById(), which is used to shorten the code length. */ function myGetElementById(strElementId) { return (document.getElementById(strElementId)); } /** * Creates and returns an object of FieldMapping with specific checkbox behaviors pre-defined. * * @param strElementId - the element id of field. * @param strGUIPropertyName - the GUI property name of field. * * @return An object of FieldMapping with type of checkbox. * @note Convenience object that "extends" FieldMapping with specific checkbox behaviors pre-defined. */ function CheckboxMapping(strElementId, strGUIPropertyName) { return (new FieldMapping(strElementId, strGUIPropertyName, FieldMapping.TYPE_CHECKBOX, encodeCheckbox, decodeBoolean)); } /** * Creates and returns an object of FieldMapping with specific radio behaviors pre-defined. * * @param strElementId - the element id of field. * @param strGUIPropertyName - the GUI property name of field. * * @return An object of FieldMapping with type of radio. * @note Convenience object that "extends" FieldMapping with specific radio behaviors pre-defined. */ function RadioMapping(strElementId, strGUIPropertyName) { return (new FieldMapping(strElementId, strGUIPropertyName, FieldMapping.TYPE_RADIO, encodeRadio, decodeRadio)); } /** * Creates and returns an object of FieldMapping with specific select behaviors pre-defined. * * @param strElementId - the element id of field. * @param strGUIPropertyName - the GUI property name of field. * * @return An object of FieldMapping with type of select. * @note Convenience object that "extends" FieldMapping with specific select behaviors pre-defined. */ function SelectMapping(strElementId, strGUIPropertyName) { return (new FieldMapping(strElementId, strGUIPropertyName, FieldMapping.TYPE_SELECT, encodeSelect, decodeSelect)); } /** * Encodes a text to URL format. * * @param text - the specified text string to be encoded. * @return a string after URI encoded - the function succeeds. * an empty string - any error occurs. */ 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)); } } /** * Encodes the data of a text field. * * @param formElement - the field to be encoded. * @return a string after URI encoded - the function succeeds. * an empty string - any error occurs. */ function encodeText(formElement) { return (encodeSetValue(formElement.value)); } /** * Encodes the data of a checkbox field. * * @param formElement - the field to be encoded. * @return "1" (as true) - the checkbox is checked. * "0" (as false) - the checkbox is unchecked. */ function encodeCheckbox(formElement) { if (formElement.checked) { return ("1"); } else { return ("0"); } } /** * Encodes the data of a select field. * * @param formElement - the field to be encoded. * @return the value according to the index, or an empty string. */ function encodeSelect(formElement) { if (formElement.selectedIndex >= 0) { //alert("Encode select: " + formElement.options[ formElement.selectedIndex ].value); var objSelectedItem = formElement.options[ formElement.selectedIndex ]; return (encodeSetValue(objSelectedItem.value)); } else { return (''); } } /** * Encodes the data of a radio field. * * @param formElement - the field to be encoded. * @return the value of the checked radio item, or an empty string. */ function encodeRadio(formElement) { for (var i = 0 ; i < formElement.length ; ++i) { if (formElement[i].checked) { return (formElement[i].value); } } return (''); //return formElement.options[ formElement.selectedIndex ].value; } /** * Decodes the data of a select field. * * @param fieldMapping - the select field. * @param value - the value to indicates the selected index. */ function decodeSelect(fieldMapping, value) { var strValue = value; if (value == null) { strValue = ""; } setSelectedOption(fieldMapping.m_fieldName, strValue); } /** * Decodes the data of a text/html/select field. * * @param fieldMapping - the text/html/select field. * @param value - the value to be saved to the field. * @note The default decoder. */ function decodeText(fieldMapping, value) { var myVal = value; if (value == null) { myVal = ""; } if ((fieldMapping.m_type == FieldMapping.TYPE_TEXT) || (fieldMapping.m_type == FieldMapping.TYPE_TEXT_NUMERIC)) { setTextField(fieldMapping.m_fieldName, myVal); } else if (fieldMapping.m_type == FieldMapping.TYPE_HTML) { setDiv(fieldMapping.m_fieldName, myVal); //appendChild(fieldMapping.m_fieldName, myVal); } else if (fieldMapping.m_type == FieldMapping.TYPE_SELECT) { setSelectedOption(fieldMapping.m_fieldName, myVal); } } /** * Decodes Encryption string values. * * @param fieldMapping - the text/html/checkbox field. * @param value - the value to be saved to the field. */ function decodeEncryption(fieldMapping, value) { var myVal = value; if (value == null) { myVal = ""; } if ((fieldMapping.m_type == FieldMapping.TYPE_TEXT) || (fieldMapping.m_type == FieldMapping.TYPE_TEXT_NUMERIC)) { setTextField(fieldMapping.m_fieldName, myVal); } else if (fieldMapping.m_type == FieldMapping.TYPE_HTML) { setDiv(fieldMapping.m_fieldName, myVal); } else if (fieldMapping.m_type == FieldMapping.TYPE_CHECKBOX) { var bVal = "1"; // true if ((myVal == "NONE") || (myVal == "0") || (myVal == "")) { bVal = "0"; // false } setCheckbox(fieldMapping.m_fieldName, bVal); } } /** * Decodes boolean type value to either Yes or None. * * @param fieldMapping - the text/html/checkbox field. * @param value - the value to be decoded and saved to the field. * @note The default decoder. */ function decodeBooleanNoneYes(fieldMapping, value) { //alert("Decode bool yes/no: " + value); var strYesNone = ""; if (value == true) { strYesNone = TOP_YES; } else { strYesNone = TOP_NONE; } if ((fieldMapping.m_type == FieldMapping.TYPE_TEXT) || (fieldMapping.m_type == FieldMapping.TYPE_TEXT_NUMERIC)) { setTextField(fieldMapping.m_fieldName, strYesNone); } else if (fieldMapping.m_type == FieldMapping.TYPE_HTML) { setDiv(fieldMapping.m_fieldName, strYesNone); //appendChild(fieldMapping.m_fieldName, value == true ? "Yes" : "None"); } else if (fieldMapping.m_type == FieldMapping.TYPE_CHECKBOX) { setCheckbox(fieldMapping.m_fieldName, value); } } /** * Decodes boolean type value to either Yes or No. * * @param fieldMapping - the text/html/checkbox field. * @param value - the value to be decoded and saved to the field. */ function decodeBoolean(fieldMapping, value) { //alert("Decode bool yes/no: " + value); var strYesNo = ""; if (value == true) { strYesNo = TOP_YES; } else { strYesNo = TOP_NO; } if ((fieldMapping.m_type == FieldMapping.TYPE_TEXT) || (fieldMapping.m_type == FieldMapping.TYPE_TEXT_NUMERIC)) { setTextField(fieldMapping.m_fieldName, strYesNo); } else if (fieldMapping.m_type == FieldMapping.TYPE_HTML) { setDiv(fieldMapping.m_fieldName, strYesNo); //appendChild(fieldMapping.m_fieldName, strYesNo); } else if (fieldMapping.m_type == FieldMapping.TYPE_CHECKBOX) { setCheckbox(fieldMapping.m_fieldName, value); } } /** * Decodes boolean type value to either true or false. * * @param fieldMapping - the text/html/checkbox field. * @param value - the value to be decoded and saved to the field. */ function decodeBooleanTrueFalse(fieldMapping, value) { var strTrueFalse = ""; if (value == true) { strTrueFalse = TOP_TRUE; } else { strTrueFalse = TOP_FALSE; } if ((fieldMapping.m_type == FieldMapping.TYPE_TEXT) || (fieldMapping.m_type == FieldMapping.TYPE_TEXT_NUMERIC)) { setTextField(fieldMapping.m_fieldName, strTrueFalse); } else if (fieldMapping.m_type == FieldMapping.TYPE_HTML) { setDiv(fieldMapping.m_fieldName, strTrueFalse); //appendChild(fieldMapping.m_fieldName, strTrueFalse); } else if (fieldMapping.m_type == FieldMapping.TYPE_CHECKBOX) { setCheckbox(fieldMapping.m_fieldName, value); } } /** * Decodes boolean type value to either Enabled or Disabled. * * @param fieldMapping - the text/html/checkbox field. * @param value - the value to be decoded and saved to the field. */ function decodeBooleanEnabledDisabled(fieldMapping, value) { var strEnabledDisabled = ""; if (value == true) { strEnabledDisabled = TOP_ENA; } else { strEnabledDisabled = TOP_DIS; } if ((fieldMapping.m_type == FieldMapping.TYPE_TEXT) || (fieldMapping.m_type == FieldMapping.TYPE_TEXT_NUMERIC)) { setTextField(fieldMapping.m_fieldName, strEnabledDisabled); } else if (fieldMapping.m_type == FieldMapping.TYPE_HTML) { setDiv(fieldMapping.m_fieldName, strEnabledDisabled); //appendChild(fieldMapping.m_fieldName, strEnabledDisabled); } else if (fieldMapping.m_type == FieldMapping.TYPE_CHECKBOX) { setCheckbox(fieldMapping.m_fieldName, value); } } /** * Decodes radio field value. * * @param fieldMapping - the radio field. * @param value - the value to be decoded and saved to the field. */ function decodeRadio(fieldMapping, value) { if (value == null) { return; } var elemList = document.getElementsByName(fieldMapping.m_fieldName); if (elemList == null) { return; } for (var i = 0; i < elemList.length; ++i) { if (elemList[i].value == value) { elemList[i].checked = true; break; } } } /** * Saves the XML element value to the relating field. * * @param xmlDoc - a pointer to the XML Document object. * @note TODO: this can be refactored into waitWithCallback. */ function setFieldListFromXML(xmlDoc) { if (xmlDoc == null) { /* * Request failed * TODO: disable screen? */ } else { // Set the fields. for (var i = 0; i < fieldList.length; ++i) { var dataName = fieldList[i].m_dataName; var paramValue = getXMLValue(xmlDoc, dataName); if (fieldList[i].m_type == FieldMapping.TYPE_CALLBACK) { dataCallback(fieldList[i], paramValue, xmlDoc); } else { fieldList[i].m_decoder(fieldList[i], paramValue); } } } hideElement('progressScreen'); showInlineElement('contentArea'); } /** * Formats and displays progress panel. */ function formatProgressPanel() { var txt = '

' + '
' + plsWaitMsg + '...
' + 'Please wait' + '
'; document.write(txt); } /** * Formats message panel. */ function formatMsgPanel() { var strMsgHeader = "Message"; var strMsgFooterHide = "Hide Message"; var strHTMLMsgPanel = '
' + strMsgHeader + '
' + '
Information icon
' + '
' + '
' + '' + strMsgFooterHide + '
'; document.write(strHTMLMsgPanel); } /** * Formats embedded message table. * * @param strId - The string for generating the id of the table. * @param strMsg - The message to display in the table. * * @note The id of the table = strId + "MsgTable" * @note The id of the span = strId + "MsgSpan" */ function formatEmbeddedMsgTable(strId, strMsg) { if ((strId == null) || (strId == undefined)) { return; } var strMsgToShow = ""; if ((strMsg != null) && (strMsg != undefined)) { strMsgToShow = strMsg; } var strTableHTML = '' + ''+ '' + '' + '' + '' + '' + '' + '' + ''; document.write(strTableHTML); } /** * Displays progress image in place of the content panel. */ function showProgressPanel() { disableAllButtons(); hideElement('contentArea'); showProgressBlockElement('progressScreen'); } /** * Displays progress element even if form already loaded. * * @param elemName - the element name. */ function showProgressBlockElement(elemName) { var elem = document.getElementById(elemName); if ((elem == null) || (elem['style'] == null)) { //alert('Cannot find element!'); } else { var txt = '

' + '
'+plsWaitMsg+'...
' + 'Please wait' + '
'; } elem.innerHTML = txt; elem.style.display = 'block'; } /** * Displays the content panel in place of the progress panel. */ function showContentPanel() { hideElement('progressScreen'); showInlineElement('contentArea'); enableAllButtons(); hideElement('msgPanel'); } /** * Sends POST GET request got from the fields pre-defined. * * @param renderPageCallback - a pointer to the callback function. */ function loadData(renderPageCallback) { var reqUrl = 'data?get='; for (var i = 0; i < fieldList.length; ++i) { reqUrl += fieldList[i].m_dataName + ','; } loadDataURL(reqUrl, renderPageCallback); } /** * Sends POST request. * * @param reqUrl - the request URL. * @param postData - the properties to request. * @param renderPageCallback - a pointer to the callback function. */ function sendPost(reqUrl, postData, renderPageCallback) { if (renderPageCallback != null) { document.chainedCallback = renderPageCallback; } else { document.chainedCallback = setFieldListFromXML; } loadXMLDocument(reqUrl, waitWithCallback, postData); } /** * Sends POST request. * * @param reqUrl - the request URL. * @param renderPageCallback - a pointer to the callback function. */ function loadDataURL(reqUrl, renderPageCallback) { if (renderPageCallback != null) { document.chainedCallback = renderPageCallback; } else { document.chainedCallback = setFieldListFromXML; } loadXMLDocument(reqUrl, waitWithCallback); } /** * Requests a text resource , and specifies the callback when getting response from server. * * @param strUrl - The url to the text file. * @param loadTextCallback - The callback function which will be invoked when the text file is got from server. */ function loadTextFile(strUrl, loadTextCallback) { if (loadTextCallback != null) { document.chainedCallback = loadTextCallback; } else { // Add a default callback function for text document in the future. document.chainedCallback = function() {}; } loadTextDocument(strUrl, waitTextWithCallback, true); } /** * Formats the POST SET request according to the pre-defined fields. * * @param formElement - the name-value set for the SET request. * @return A string representing the request URI. */ function formatPostRequest(formElement) { var req = ""; if (formElement.elements.length > 1) { var elem = formElement.elements[0]; req = elem.name + ":" + encodeSetValue(elem.value); for (var i = 1; i < formElement.elements.length; ++i) { elem = formElement.elements[i]; req += ',' + elem.name + ":" + encodeSetValue(elem.value); } } return (req); } /** * Formats the POST SET request according to the pre-defined fields. * * @param formElement - the name-value set for the SET request. * @param fieldList - the fields. * @param bIsToAddDisabled - indicates whether to add disabled HTML elements to the SET request. * If bIsToAddDisabled is false and an HTML element is disabled, * its value won't be added to the SET request string. * * @return A string representing the request URI. */ function formatPostRequestForFields(formElement, fieldList, bIsToAddDisabled) { var req = ""; var count = 0; for (var i = 0; i < fieldList.length; ++i) { if (fieldList[i] == null) { continue; } var field = fieldList[i]; var encoder = fieldList[i].m_encoder; var formElem = formElement[field.m_fieldName]; if ((formElem != null) && (encoder != null)) { if ((false == bIsToAddDisabled) && (formElem.disabled)) { continue; } if ((formElem.disabled == undefined) && (formElem[0].type == "radio")) { if (isToAddRadioElementToRequestString(formElem, bIsToAddDisabled) == false) { continue; } } if (count != 0) { req += ","; } count ++; req += field.m_dataName + ":" + encoder(formElem); } } return (req); } /** * Updates value for field to the format POST SET request. * * @param strRequestUri - a string representing the request URI. * @param strFieldName - the id attribute of field. * @param strFieldValue - the value for strFieldName. * * @return A string representing the request URI. */ function updateFieldValueToPostRequest(strRequestUri, strFieldName, strFieldValue) { var astrField = strRequestUri.split(","); var iFieldIndex = 0; for (iFieldIndex = 0; iFieldIndex < astrField.length; iFieldIndex++) { if (astrField[iFieldIndex].indexOf(strFieldName) != -1) { break; } } astrField[iFieldIndex] = strFieldName + ":" + strFieldValue; return (astrField.join(",")); } /** * Returns an XML node value. * * @param xmlDoc - a pointer to the XML Document object. * @param elementName - the node name. * @return A string representing the node value of a text node, or a non-text node. * null when the XML node is an empty element. (ex: ) * An empty string when any error occurs. */ function getXMLValue(xmlDoc, elementName) { var strValue = ""; if ((xmlDoc == null) || (xmlDoc.childNodes.length == 0)) { //alert("Received bad XML document."); return (strValue); } var elements = xmlDoc.getElementsByTagName(elementName); if ((elements != null) && (elements.length > 0) && (elements[0].childNodes != null)) { if (elements[0].childNodes.length == 0) { return (null); } if (elements[0].childNodes[0].nodeType == 3) { strValue = getTextNodeValue(elements[0].childNodes); } else { strValue = elements[0]; } } return (strValue); } /** * Gets the value of a text node array. * * @param arrXMLTextNode - The text node array. * @return The value of the text node array. An empty string when any error occurs. * @note Some browsers (FireFox) splits long texts (more than 4096 bytes) into multiple text nodes. * Use this function to combine the text node vaule. */ function getTextNodeValue(arrXMLTextNode) { if ((arrXMLTextNode == null) || (arrXMLTextNode.length == 0) || (arrXMLTextNode[0].nodeType != 3)) { return (""); } var strNodeValue = ""; for (var idx = 0; idx < arrXMLTextNode.length; idx++) { strNodeValue += arrXMLTextNode[idx].nodeValue; } return (strNodeValue); } /** * Requests the XML document asynchronously. * * @param url - the request URL. * @param callback - a pointer to the callback function. * @param postData - the data used to POST. * @note Lets load the WebPage defined by url ( output should be xml ) * 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); } /** * Requests the XML document synchronously. * * @param strURL - the request URL. * @param fCallback - a pointer to the callback function. * @param strPostData - the data used to POST. */ function loadXMLDocumentSynchronous(strURL, fCallback, strPostData) { if (strPostData == undefined) { strPostData = null; } if (fCallback == null) { loadXMLDocument__(strURL, function (){}, strPostData, false); } else { loadXMLDocument__(strURL, fCallback, strPostData, false); } } /** * Requests the XML document. * * @param url - the request URL. * @param callback - a pointer to the callback function. * @param postData - the data used to POST. * @param asynchronous - indicates whether synchronous or asynchronous. * @note Lets load the WebPage defined by url ( output should be xml ) */ function loadXMLDocument__(url, callback, postData, asynchronous) { xmlRequestObject = getXMLHttpRequestObject(); if (xmlRequestObject) { xmlRequestObject.onreadystatechange = callback; xmlRequestObject.open("POST", url, asynchronous); if (postData == null) { postData = ''; } xmlRequestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if (top.G_objCSRFHandler) { top.G_objCSRFHandler.addCSRFTokenToRequestHeader(xmlRequestObject); } setAutoRefreshToRequestHeader(); xmlRequestObject.send(postData); } } /** * Requests the text document. * * @param url - the request URL. * @param callback - a pointer to the callback function. * @param asynchronous - indicates whether synchronous or asynchronous. * @note Load the text file defined by url (output should be text). HTTP GET, rather than POST, should be used to * retrieve a static resource from server successfully. */ function loadTextDocument(url, callback, asynchronous) { xmlRequestObject = getXMLHttpRequestObject(); if (xmlRequestObject) { var strUrl = url; if (top.G_objCSRFHandler) { strUrl = top.G_objCSRFHandler.getACSRFProtectedUri(url); } xmlRequestObject.onreadystatechange = callback; xmlRequestObject.open("GET", strUrl, asynchronous ); setAutoRefreshToRequestHeader(); xmlRequestObject.send(); } } /** * Gets XMLHttpRequest Instance. * * @retval objXmlRequest - the XMLHttpRequest object. * @retval null - get XMLHttpRequest object failed. * @note 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 getXMLHttpRequestObject() { var objXmlRequest = null; if (window.XMLHttpRequest) { objXmlRequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { objXmlRequest = new ActiveXObject("Msxml2.XMLHTTP"); // alert("XMLHttpRequest is executed"); } catch (e) { try { objXmlRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { } } } return (objXmlRequest); } /** * Gets an XML node by the node name. * * @param xmlDoc - a pointer to the XML Document object. * @param name - the node name. * @return an XML node - the function succeeds. * null - any error occurs. */ function getXMLTagByName(xmlDoc, name) { var tagList = xmlDoc.getElementsByTagName(name); var rtn = null; if (tagList.length > 0) { rtn = tagList[0]; } return (rtn); } /** * Saves the value to the text field. * * @param fieldId - indicates the field's id. * @param value - the value to save. */ function setTextField(fieldId, value) { var elem = document.getElementById(fieldId); if ((elem != null) && (elem.value != undefined)) { if (value == null) { elem.value = ''; } else { elem.value = value; } } } /** * Saves the value to the HTML div element. * * @param fieldId - indicates the element's id. * @param value - the value to save. */ 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; } } } /** * Saves the value to the HTML checkbox element. * * @param fieldId - indicates the element's id. * @param value - the value to save. */ function setCheckbox(fieldId, value) { var val = false; if (value != undefined) { if (typeof value == "boolean") { val = value; } else { if (value.trim() == "0") { val = false; } else { val = true; } } } var elem = document.getElementById(fieldId); if ((elem != null) && (elem.checked != undefined)) { elem.checked = val; } } /** * Saves the value to the HTML radio element. * * @param fieldName - the field name. * @param value - the value. */ function setRadio(fieldName, value) { if (value == null) { return; } var arrRadioElements = document.getElementsByName(fieldName); if (arrRadioElements == null) { return; } for (var i = 0; i < arrRadioElements.length; ++i) { if (arrRadioElements[i].value == value) { arrRadioElements[i].checked = true; break; } } } /** * Saves the value to the HTML select element. * * @param strElementId - the HTML select element's id. * @param value - the value. */ function setSelectedOption(strElementId, value) { var elemSelect = document.getElementById(strElementId); if ((elemSelect == null) || (elemSelect.options == null)) { return; } for (var i = 0; i < elemSelect.options.length; ++i) { if (elemSelect.options[i].value == value) { elemSelect.options[i].selected = true; break; } } } /** * Gets the selected item of the HTML select element. * * @param formElement - the HTML select element. * @param fieldName - the field name. * @return the selected item - the function succeeds. * null - any error occurs. */ function getSelectedRadio(formElement, fieldName) { for (var i = 0; i < formElement.elements.length; ++i) { var elem = formElement.elements[i]; if (elem.name == fieldName && elem.checked) { return (elem); } } return (null); } /** * Gets the selected option value of the HTML select element. * * @param strElementId - the id attribute value of the select element. * @return The value of selected option on sucess, or an empty string on error. */ function getSelectedOption(strElementId) { if (strElementId == null) { return (""); } var objSelectElement = document.getElementById(strElementId); try { return (objSelectElement.options[objSelectElement.selectedIndex].value); } catch (err) { return (""); } } /** * Shows a prompted window with error message. * * @param msg - the error message. */ function showErrorMessage(msg) { alert(" Error: " + msg); } /** * Sets the innterHtml of a message element and displays it. * * @param elementName - the name of the message element. * @param msg - the error message. * @note Set the style display to block. */ function showBlockMessage(elementName, msg) { var elem = document.getElementById(elementName); if (elem != null) { elem.innerHTML = msg; elem.style.display = 'block'; } else { alert('Cannot find element!'); } } /** * Sets the innterHtml of a message element and displays it. * * @param elementName - the name of the message element. * @param msg - the error message. * @note Set the style display to inline. */ function showInlineMessage(elementName, msg) { var elem = document.getElementById(elementName); if (elem != null) { elem.innerHTML = msg; elem.style.display = 'inline'; } else { alert('Cannot find element!'); } } /** * Hides an HTML element (such as error message). * * @param elemName - the name of the element. */ function hideElement(elemName) { setDisplayStyle(elemName, 'none'); } /** * Shows an HTML element. * * @param elemName - the name of the element. * @note Set the style display to block. */ function showBlockElement(elemName) { setDisplayStyle(elemName, 'block'); } /** * Shows an HTML element. * * @param elemName - the name of the element. * @note Set the style display to inline. */ function showInlineElement(elemName) { setDisplayStyle(elemName, 'inline'); } /** * Shows an HTML element. * * @param strElementName - the name of the element. * @note Set the style display to ''. */ function showElement(strElementName) { setDisplayStyle(strElementName, ''); } /** * Shows or hides an HTML element. * * @param strElementName - the name of the element. * @param strStyle - the display style. */ function setDisplayStyle(strElementName, strStyle) { var objElement = document.getElementById(strElementName); if ((strStyle == null) || (objElement == null) || (objElement['style'] == null)) { //alert('Cannot find element!'); } else { objElement.style.display = strStyle; } } /** * Checks whether the element is hidden or not found. * * @param objElement - the element object. * @retval true - the element is hidden or not found. * @retval false - the element is not hidden. */ function isElementHiddenOrNotFound(objElement) { if ((objElement == null) || (typeof objElement != "object") || (objElement["style"] == null)) { return (true); } // Check style attribute. try { if (objElement.style.display == "none") { return (true); } else { return (false); } } catch (err) { } return (true); } /** * Converts the privilege level to a string. * * @param type - the privilege level. * @return The privilege name. */ function ipmiPrivToName(type) { var name = "Unknown"; if (type == 15) { name = TOP_NONE; // None. } else 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); } /** * Displays the update area in place of the content panel and progress panel. */ function showUpdateArea() { hideElement('contentArea'); hideElement('progressScreen'); showInlineElement('updateArea'); } /** * Processes the XML document that Server responds. * * @note 1. 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. * 2. Rarely that header.html (represented by top.frames.3) is not loaded completely while this function is in * use. A try-catch statement is used to prevent the error of top.frames[3].hideErrorPanel being undefined * from occurring. */ 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') { if (xmlDoc != null) { var message = getXMLValue(xmlDoc, 'status'); // alert(" Request failed: " + message); errorHandler(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... */ if (top.frames.length >= 3) { /* * A successful login on WebGUI will redirect the browser to index.html and then load * index.html's six frames. * Rarely top.frames.3 (header.html) has not been loaded completely when top.frames.4 * (which has been loaded completely of course) receives a POST response, as a result, * top.frames.hideErrorPanel is undefined. * A try-catch statement is used to prevent the error from occurring. */ try { top.frames[3].hideErrorPanel(); top.frames[3].hideInformationPanel(); } catch (err) { //alert("Unable to hide error panel."); } } document.chainedCallback(xmlDoc); if (requestCtxt.updateComplete != null) { requestCtxt.updateComplete(requestCtxt, xmlDoc); } } } else if (xmlRequestObject.status == 401) { if (true == xmlRequestObject.bIsAutoRefresh) { if (document.sessionTimeoutCallback != undefined) { document.sessionTimeoutCallback(); showContentPanel(); } } else { if (document.sessionTimeoutCallback != undefined) { document.sessionTimeoutCallback(); } top.location.replace("/login.html"); } } else { // showErrorMessage(" Could not retrieve data from server (status=" + // xmlRequestObject.status + ", " + xmlRequestObject.statusText + ")"); showContentPanel(); } } } //end of waitWithCallback /** * Processes the text document that Server responds. * * @note 1. 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 loadTextDocument. * 2. Rarely that header.html (represented by top.frames.3) is not loaded completely while this function is in * use. A try-catch statement is used to prevent the error of top.frames[3].hideErrorPanel being undefined * from occurring. */ function waitTextWithCallback() { // Only execute for state "loaded", all other states have no processing. if (xmlRequestObject.readyState == 4) { // only if "OK" if (xmlRequestObject.status == 200) { var objTextDoc = xmlRequestObject.responseText; if (objTextDoc != null) { if (top.frames.length >= 3) { try { top.frames[3].hideErrorPanel(); } catch (err) { } } document.chainedCallback(objTextDoc); } } else { errorHandler(); // Also pass null to callback function to inform it response is unavailable. document.chainedCallback(null); } } } /** * Displays error message panel. * * @param errorMsg - the error message. * @note Rarely that header.html (represented by top.frames.3) is not loaded completely * while this function is in use. A try-catch statement is used to prevent the error of * top.frames[3].showErrorPanel being undefined from occurring. */ function errorHandler(errorMsg) { var displayErrorMsg = unknowExcMsg; if (errorMsg != null) { if ((errorMsg == "ProcessingError") || (errorMsg == "GeneralError")) { displayErrorMsg = excMsg; } else if (errorMsg == "SecurityException") { displayErrorMsg = securityExcMsg; } else if (errorMsg == "RequestFormatException") { displayErrorMsg = badReqExcMsg; } else if (errorMsg == "ExceptionUnknown") { displayErrorMsg = unknowExcMsg; } else if (errorMsg == "SetError") { displayErrorMsg = setErrorExcMsg; } else if (errorMsg == "SMBIOSError") { displayErrorMsg = smbiosExcMsg; } // Print the message directly. else { displayErrorMsg = errorMsg; } } if (top.frames.length >= 3) { /* * A successful login on WebGUI will redirect the browser to index.html and then load * index.html's six frames. * Rarely top.frames.3 (header.html) has not been loaded completely when top.frames.4 * (which has been loaded completely of course) receives a POST response, as a result, * top.frames.showErrorPanel is undefined. */ try { top.frames[3].showErrorPanel(displayErrorMsg); } catch (err) { } } } /** * Hides error message panel in header. * * @note Rarely that header.html (represented by top.frames.3) is not loaded completely * while this function is in use. A try-catch statement is used to prevent the error of * top.frames[3].hideErrorPanel being undefined from occurring. */ function hideErrorPanel() { try { top.frames[3].hideErrorPanel(); } catch (e) { } } /** * Displays error message panel. * * @param strMsg - the information message. * @note Rarely that header.html (represented by top.frames.3) is not loaded completely * while this function is in use. A try-catch statement is used to prevent the error of * top.frames[3].showInformationPanel being undefined from occurring. */ function showInformationPanel(strMsg) { if (top.frames.length >= 3) { /* * A successful login on WebGUI will redirect the browser to index.html and then load * index.html's six frames. * Rarely top.frames.3 (header.html) has not been loaded completely when top.frames.4 * (which has been loaded completely of course) receives a POST response, as a result, * top.frames.showInformationPanel is undefined. */ try { top.frames[3].showInformationPanel(strMsg); } catch (err) { } } } /** * Hides information message panel in header. * * @note Rarely that header.html (represented by top.frames.3) is not loaded completely * while this function is in use. A try-catch statement is used to prevent the error of * top.frames[3].hideInformationPanel being undefined from occurring. */ function hideInformationPanel() { try { top.frames[3].hideInformationPanel(); } catch (e) { } } /** * Changes the style based on the row index. * * @param iTableRowIndex - The row index. * @param bIsWrappable - Indicateds whether the content can be warpped or not. * If not specified, bIsWrappable will be treated as false by default. * @return the style according to the row index. */ function getStyleForRow(iTableRowIndex, bIsWrappable) { if ((isNaN(iTableRowIndex) == true) || (iTableRowIndex < 0)) { return (''); } var strStyle = ''; // The first row is header, so even index leads to data-area-canvas-odd. if ((iTableRowIndex % 2) == 0) { strStyle = 'data-area-canvas-odd'; } else { strStyle = 'data-area-canvas'; } if (bIsWrappable != true) { return (strStyle); } return (strStyle + ' data-area-wrappable'); } /** * Inserts a blank cell to the row. * * @param tr - the table row. * @return cellIndex - the index of the cell to insert. */ function insertBlankCell(tr, cellIndex) { var cell = tr.insertCell(cellIndex); cell.className = getStyleForRow(tr.rowIndex); cell.innerHTML = ''; } /** * Displays a table cell. * * @param objCell - the table cell. * @param iTableRowIndex - the table row index. * @param objCellData - the data of the cell. */ function populateCell(objCell, iTableRowIndex, objCellData) { var iCellType = objCellData.m_type; var strCellValue = objCellData.m_value; var strAlign = objCellData.m_align; var bIsWrappable = objCellData.m_bIsWrappable; var strCellStyle = objCellData.m_strCellStyle; var fnOnClickCallback = objCellData.m_fnOnClickCallback; if (strCellStyle == null) { objCell.className = getStyleForRow(iTableRowIndex, bIsWrappable); } else { objCell.className = strCellStyle; } objCell.vAlign = 'middle'; if (strAlign != null) { objCell.align = strAlign; } if (fnOnClickCallback != null) { setHtmlElementEvent(objCell, "onclick", fnOnClickCallback); } if (iCellType == null) { // Don't interpret no type as unknown, default to content. iCellType = Cell.CONTENT; } switch (iCellType) { case Cell.ICON: objCell.innerHTML=""; break; case Cell.CONTENT: if (strCellValue == ' ') { objCell.innerHTML = '[N/A]'; } else { objCell.innerHTML = strCellValue; } break; case Cell.BLANK : objCell.innerHTML=''; break; case Cell.HIDDEN : objCell.innerHTML='' + strCellValue + ''; break; default: showErrorMessage("Unknown type for cell, cell - " + celltype); break; } } /** * Submits a request for data to the server and call refreshDataCallback when the response arrives. * * @param data - the request data. */ function refreshData(data) { document.chainedCallback = refreshDataCallback; loadXMLDocument('data?get=' + data, waitWithCallback); } /** * Adds the strings seperated by the delimiters as options to the given select control. * * @param selectControl - the select control. * @param value - the delimited string. * @param delim - the delimiter. */ 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 < valueArray.length; optionIndex++) { var oneOption = new Option(); oneOption.text = valueArray[optionIndex]; try { selectControl.add(oneOption, null); } catch (ex) { // IE only selectControl.add(oneOption); } } } /** * Converts the given select control's options to a delimited string. * * @param selectControl - the select control. * @param delim - the delimiter. * @return A delimited string. */ function optionsToDelimValue(selectControl, delim) { var options = selectControl.options; var delimString = ""; if (options == null) { return (""); } for (var optionIndex = 0; optionIndex < options.length; optionIndex++) { delimString = delimString + options[optionIndex].text + delim; } // Drop the last delimiter delimString = delimString.substring(0, (delimString.length - 1)); return (delimString); } /** * Pauses the program according to the given time value. * * @param s - The time value in seconds. */ function SleepInSeconds(s) { s = s * 1000; var a = true; var n = new Date(); var w = null; var sMS = n.getTime(); while (a) { w = new Date(); wMS = w.getTime(); if ((wMS - sMS) > s) { a = false; } } } /** * Makes the tooltips displayed on FireFox. * * @note FireFox doesn't support the alt attribute in img tags, * need to use title attribute. This function help to convert * tooltips from alt attribute to title attribute. */ function ShowTooltipsOnFireFox() { for (var i = 0; i < document.images.length; i++) { if (document.images[i].title == "") { document.images[i].title = document.images[i].alt; } } } /** * Encodes special symbols '\','@','(',')',',',':','?','=','&'. * * @param username - A string which needs to be checked and encoded the special symbol. * @return A string has encoded. */ function escapeUserName(username) { var tmp = new Array(); var i = 0; var escstr = ""; var dec = ""; username = username.replace(/\\/g, "\\\\"); tmp = username.split(""); for (i = 0; i < tmp.length; i++) { switch(tmp[i]) { case '@': case '(': case ')': case ',': case ':': case '?': case '=': case '&': dec = (tmp[i]+'').charCodeAt(0); escstr+= "@0"+ dec.toString(16); break; default: escstr+=tmp[i]; } } return (escstr); } /** * Converts a version string to ODM-specified format. * * @param strVersion - A version string. * @return Formatted version string. */ function convertToODMFwVerFormat(strVersion) { /* * BTS 69939: change firmware format from major.minor(.release) to major.minor, * where major should be a value between 0~127, and minor should be * a value between 0~99. The restraint is imposed because for this * ODM customization, major and minor values should be in accordance * with the revision values obtained from the IPMI Get Device ID command. */ var strODMFwVer = ""; var aFwVersion = strVersion.split("."); if ((aFwVersion.length < 2) || (aFwVersion.length > 3)) { strODMFwVer = "Error. Invalid firmware version format."; } else { var strMajor = aFwVersion[0]; var strMinor = aFwVersion[1]; var iMajor = parseInt(strMajor); var iMinor = parseInt(strMinor); if ((iMajor == NaN) || (iMajor < 0) || (iMajor > 127)) { // major is out of range strODMFwVer = "Error. Firmware major version is invalid. Expected range: [0-127]."; } else if ((iMinor == NaN) || (iMinor < 0) || (iMinor > 99)) { // minor is out of range strODMFwVer = "Error. Firmware minor version is invalid. Expected range: [0-99]."; } else if (strMinor.length == 1) { // minor: "1" -> "01" strMinor = "0" + strMinor; strODMFwVer = strMajor + "." + strMinor; } else { strODMFwVer = strMajor + "." + strMinor; } } return (strODMFwVer); } /** * Resets table row style. * * @param strTableID - The id attribute of the HTML table element. * @note The function rearranges the background color of visible table rows. * Even-index visible rows, the className attribute is "data-area-canvas-odd", set background color to blue. * Odd-indexed visible rows, the className attribute is "data-area-canvas", set background color to gray. * The row index is 0-based. */ function resetTableRowStyle(strTableID) { if ((strTableID == null) || (strTableID == "")) { return; } var objRows = document.getElementById(strTableID).rows; var objCells = null; var iVisibleRowIndex = 0; for (var iRowIndex = 0; iRowIndex < objRows.length; iRowIndex++) { if (isElementHiddenOrNotFound(objRows[iRowIndex])) { continue; } objCells = objRows[iRowIndex].cells; // Set background color. for (var iCellIndex = 0; iCellIndex < objCells.length; iCellIndex++) { objCells[iCellIndex].className = getStyleForRow(iVisibleRowIndex); } iVisibleRowIndex++; } } /** * Passes a given sequence of arguments preceding any provided when the new function was called. * * @param obj - A generic object that will become 'this' of the function whose function.bind() is called. * @note Creates a new function that, when called, itself calls this * function in the context of the provided this value, with a given * sequence of arguments preceding any provided when the new function was called. */ Function.prototype.bind = function(obj) { var objMethod = this, objFunction = function() { return objMethod.apply(obj, arguments); }; return (objFunction); } /** * Checks the result of changing field settings. * * @param xmlDoc - A pointer to the XML document. * * @return true - changing field settings are successful. * @return false - changing field settings are falied. */ function isRequestSubmittedOK(xmlDoc) { // status != ok, an inline message is displayed on header frame. if (xmlDoc == null) { return (false); } // OSINET return code. var STATUS_OK = 0; // OK var STATUS_DUPLICATE_IPV6_IP = 327725; // Duplicate IPv6 IP addresses. var STATUS_INVALID_IPV6_IP = 327716; // Invalid IPv6 address. var STATUS_PEF_LIST_FULL = 1; // Unable to retrieve platform event filter because list is full. var strSeeOnlineHelp = "Please see the online help for more information."; var astrErrMsg = new Array(); astrErrMsg[STATUS_DUPLICATE_IPV6_IP] = "IP Address 1 and IP Address 2 can not be duplicate." + "
" + strSeeOnlineHelp; astrErrMsg[STATUS_INVALID_IPV6_IP] = "Invalid IPv6 address." + "
" + strSeeOnlineHelp; astrErrMsg[STATUS_PEF_LIST_FULL] = "Unable to retrieve platform event filter because list is full."; var iResult = parseInt(getXMLValue(xmlDoc, "statusCode")); // OK. if ((isNaN(iResult)) || (STATUS_OK == iResult)) { return (true); } // Failed. var strMsg = astrErrMsg[iResult]; if (strMsg == undefined) { // Display default error. errorHandler(null); } else { errorHandler(strMsg); } return (false); } /** * Terminiates all sessions. * It's the callback function called when changes to network settings are updated. * * @param xmlDoc - A pointer to the XML document. * * @note The function closes the other sessions and force the user to log out. This function has dependency on * doLogout() in designFunctions.js. */ function terminateAllSessions(xmlDoc) { if (!isRequestSubmittedOK(xmlDoc)) { showContentPanel(); return; } // Force the user to log out. document.chainedCallback = doLogout; // Kill all other sessions. loadXMLDocument("data?set=killOtherSessions("+this.strSessionId+")", waitWithCallback); } /** * Updates the content of message panel and displays it. * * @param strMsg - The message to be displayed. * @param iMsgType - Indicates the message is an info or an error. */ function updateMessage(strMsg, iMsgType) { if ((strMsg == null) || (iMsgType == null)) { return; } // Roll back message panel and use the original alert() function. alert(strMsg); return; var objMsgIcon = document.getElementById("msgIcon"); if (objMsgIcon == null) { return; } if (iMsgType == MSG_TYPE_INFO) { objMsgIcon.src = "images/information.gif"; } else if (iMsgType == MSG_TYPE_ERROR) { objMsgIcon.src = "images/error.gif"; } var strHtmlMsg = strMsg.replace(/\n/g, "
"); showInlineMessage("msgContent", strHtmlMsg); showBlockElement("msgPanel"); resizeMessagePanel(); } /** * Resizes the message panel to fit window size, and displays it in the center of the window. */ function resizeMessagePanel() { var objMsgContent = document.getElementById("msgContent"); var objMsgPanel = document.getElementById("msgPanel"); if ((objMsgContent == null) || (objMsgPanel == null)) { return; } // There's no need to resize message panel if it is not visible. if ((objMsgPanel.style.display == null) || (objMsgPanel.style.display == undefined) || (objMsgPanel.style.display != "block")) { return; } /** * Reset the inline style of message content
and message panel
. * This does not affect the style settings from CSS file. */ objMsgContent.removeAttribute("style"); objMsgPanel.setAttribute("style", "display: block"); // Get width and height of current frame (i.e., width and height of dataPage). var iWindowWidth = getWindowWidth(window); var iWindowHeight = getWindowHeight(window); // Define max width for message content
. var iMaxContentWidth = (iWindowWidth * 0.5); // Get width of current message content
. var objMsgContentRect = objMsgContent.getBoundingClientRect(); var iMsgContentWidth = (objMsgContentRect.right - objMsgContentRect.left); // Define variable for final width. var iContentWidthToSet = iMsgContentWidth; if (iMsgContentWidth > iMaxContentWidth) { iContentWidthToSet = iMaxContentWidth; objMsgContent.setAttribute("style", "width: " + iContentWidthToSet + "px;"); } // Define max height for message panel. var iMaxPanelHeight = (iWindowHeight * 0.6); // Get width/height of current message panel element. var objMsgPanelRect = objMsgPanel.getBoundingClientRect(); var iMsgPanelWidth = (objMsgPanelRect.right - objMsgPanelRect.left); var iMsgPanelHeight = (objMsgPanelRect.bottom - objMsgPanelRect.top); // Define variables for final width/height. var iPanelWidthToSet = iMsgPanelWidth; var iPanelHeightToSet = iMsgPanelHeight; if (iMsgPanelHeight > iMaxPanelHeight) { iPanelHeightToSet = iMaxPanelHeight; // Panel width ~= content width + icon width (16px) + margin and padding (50px) + vertical scroll bar (30px) iPanelWidthToSet = iContentWidthToSet + 100; objMsgPanel.setAttribute("style", "display: block; overflow: auto;" + "height: " + iPanelHeightToSet + "px;" + "width: " + iPanelWidthToSet + "px;"); } // Get position of current frame relative to the entire browser window. var iWindowX = getWindowWidth(parent.bmcTree); var iWindowY = getWindowHeight(parent.globalnav) + getWindowHeight(parent.Title) + getWindowHeight(parent.headerFrame); /** * The position of message panel is relative to the current frame, not browser window. * Shift the message panel so that it looks in the center of browser window. */ var iMsgPanelLeft = ((iWindowX + iWindowWidth - iPanelWidthToSet) / 2) - iWindowX; var iMsgPanelTop = ((iWindowY + iWindowHeight - iPanelHeightToSet) / 2) - iWindowY; if (iMsgPanelLeft < 0) { iMsgPanelLeft = 0; } if (iMsgPanelTop < 0) { iMsgPanelTop = 0; } objMsgPanel.style.left = iMsgPanelLeft + "px"; objMsgPanel.style.top = iMsgPanelTop + "px"; } /** * Gets the width of window. * * @param objWindow - The window object whose width will be got. * * @return The width of the input window. 0 if the input object is null. */ function getWindowWidth(objWindow) { if (objWindow == null) { return (0); } /** * Different browsers use different properties to get the width of the browser window. * Internet Explorer, Chrome, Firefox, Opera, and Safari uses 'objWindow.innerWidth'. * IE 5-8 use 'objWindow.document.documentElement.clientWidth' or 'objWindow.document.body.clientWidth'. */ return (objWindow.innerWidth || objWindow.document.documentElement.clientWidth || objWindow.document.body.clientWidth); } /** * Gets the height of window. * * @param objWindow - The window object whose height will be got. * * @return The height of the input window. 0 if the input object is null. */ function getWindowHeight(objWindow) { if (objWindow == null) { return (0); } /** * Different browsers use different properties to get the height of the browser window. * Internet Explorer, Chrome, Firefox, Opera, and Safari uses 'objWindow.innerHeight'. * IE 5-8 use 'objWindow.document.documentElement.clientHeight' or 'objWindow.document.body.clientHeight'. */ return (objWindow.innerHeight || objWindow.document.documentElement.clientHeight || objWindow.document.body.clientHeight); } /** * Sets auto refresh field to request header. */ function setAutoRefreshToRequestHeader() { var bIsAutoRefresh = getIsAutoRefresh(); // Avoid the circumstance that the variable was undefined, or set to a non-boolean value. if (bIsAutoRefresh != true) { bIsAutoRefresh = false; } if (xmlRequestObject) { xmlRequestObject.setRequestHeader("GUIAutoRefresh", (bIsAutoRefresh + "")); xmlRequestObject.bIsAutoRefresh = bIsAutoRefresh; } } /** * Fires a function by setTimeout() with the global variable G_hAutoRefreshTimeoutHandle. * * @param strFunction - the function to be executed. * @param iTimeIntervalInMs - indicates how many milliseconds to be waited before executing the function. */ function startTimeoutEvent(strFunction, iTimeIntervalInMs) { cancelTimeoutEvent(); if ((strFunction != null) && (iTimeIntervalInMs != null)) { G_hAutoRefreshTimeoutHandle = setTimeout(strFunction, iTimeIntervalInMs); } } /** * Fires a function by setInterval() with the global variable G_hAutoRefreshIntervalHandle. * * @param strFunction - the function to be executed. * @param iTimeIntervalInMs - indicates the length of the time-interval in milliseconds between each execution. */ function startIntervalEvent(strFunction, iTimeIntervalInMs) { cancelIntervalEvent(); if ((strFunction != null) && (iTimeIntervalInMs != null)) { G_hAutoRefreshIntervalHandle = setInterval(strFunction, iTimeIntervalInMs); } } /** * Cancels the execution fired by setTimeout() with the global variable G_hAutoRefreshTimeoutHandle. */ function cancelTimeoutEvent() { if (G_hAutoRefreshTimeoutHandle != null) { clearTimeout(G_hAutoRefreshTimeoutHandle); G_hAutoRefreshTimeoutHandle = null; } } /** * Cancels the further executions specified in the setInterval() with the global variable G_hAutoRefreshIntervalHandle. */ function cancelIntervalEvent() { if (G_hAutoRefreshIntervalHandle != null) { clearInterval(G_hAutoRefreshIntervalHandle); G_hAutoRefreshIntervalHandle = null; } } /** * Sets the event callback function for element. * * @param objElement - the HTML element object. * @param strEventName - the event name. (ex: onclick, onload...) * @param fnCallback - the event callback function for the event handler of strEventName of objElement. * * @note This is a cross-browser solution for setting event. IE 8 doesn't support to set event with * "HtmlEelement.onload" after page loaded. The callback function doesn't be invoked. To fix the issue, * IE 8 allows to use attachEvent to set event. Each event can have only one callback function. */ function setHtmlElementEvent(objElement, strEventName, fnCallback) { if ((objElement == null) || (strEventName == null)) { return; } if (objElement.attachEvent) // For IE before version 9. { if (objElement.handleEvent != null) { // Explicitly detach the previously set function with the detachEvent() method. objElement.detachEvent(strEventName, objElement.handleEvent); } // Register the target event with objElement.handleEvent which is referenced to fnCallback. objElement.handleEvent = fnCallback; objElement.attachEvent(strEventName, objElement.handleEvent); } else // addEventListener: For all browsers except IE before version 9. { strEventName = strEventName.replace(/^on/, ""); // If start with "on", remove "on" (ex: onclick->click). if (objElement.handleEvent == null) { /* * The behavior of addEventListener() is different from attachEvent() and can take an object as a second * argument that will look for a method called handleEvent. It is not necessary to detach the previously * set function explicitly. */ objElement.handleEvent = fnCallback; objElement.addEventListener(strEventName, objElement, false); } else { objElement.handleEvent = fnCallback; } } } /** * Adds an iframe element dynamically for form target. * * @param strFormId - the id attribute of the form element. * @param strIframeId - the id attribute of an iframe element. * @param fnOnloadCallback - the callback function for for the onload event handler of the iframe. * @param bIsToOverride - indicates whether to override the existing iframe element with the same id attribute. * * @note (1) Create an iframe element with strIframeId, and make it invisible by setting its className * property to "hidden". * (2) Call setHtmlElementEvent() to give the iframe a callback function for onload event. * (3) Set the form's target property to strIframeId. */ function addIframeToForm(strFormId, strIframeId, fnOnloadCallback, bIsToOverride) { var objExistingIframe = document.getElementById(strIframeId); if (objExistingIframe != null) { if (true != bIsToOverride) { // If not explicitly specifying to override the existing iframe, exit this function. return; } document.body.removeChild(objExistingIframe); } // Create a hidden iframe element. var objIframeElement = document.createElement("iframe"); objIframeElement.id = strIframeId; objIframeElement.name = strIframeId; objIframeElement.className = "hidden"; document.body.appendChild(objIframeElement); setHtmlElementEvent(objIframeElement, "onload", fnOnloadCallback); // Get form element. var objFormElement = document.getElementById(strFormId); if (objFormElement == null) { //alert('Cannot find element!'); return; } objFormElement.target = strIframeId; } /** * Opens the about page. */ function openAbout() { window.open("/public/about.html", "About", "height=320,width=600,scrollbars=no,toolbar=no,menubar=no,resizable=yes,location=no,directories=no,status=no"); } /** * Opens the support page. */ function openSupport() { window.open("/public/support.html", "Support", "height=320,width=600,scrollbars=no,toolbar=no,menubar=no,resizable=yes,location=no,directories=no,status=no"); } /** * Opens the specific help page. * * @param strLanguage - [IN] specifies the language of help page. * @param strHelpPageURL - [IN] specifies the URL of the help page. */ function openHelp(strLanguage, strHelpPageURL) { if ((strLanguage == null) || (strHelpPageURL == null)) { return; } window.open("/help/" + strLanguage + "/" + strHelpPageURL, "Help", "height=500,width=600,scrollbars=yes,toolbar=no,menubar=no,resizable=yes,location=no,directories=no,status=no"); } /** * Logs out user when page is unloaded. */ function unloadHandler() { if (true == top.G_bIsLogoutFired) { return; } top.G_bIsLogoutFired = true; loadXMLDocumentSynchronous(top.G_objCSRFHandler.getACSRFProtectedUri("/data/logout")); } /** * Sends a logout request when event onbeforeunload is received. */ function beforeUnloadHandler() { unloadHandler(); } /** * Caches the URL of the current page and redirect to where the given URL specifies. * * @param pageURL - the given URL. It would be, for example, https://[IP]/fans.html. * @note 1. WebGUI will log out if the user clicks back after firmware update started. * 2. Rarely that index.html (represented by top) is not loaded completely * while this function is in use. A try-catch statement is used to prevent the error of, * for example, top.prvPageURL or parent.dataPage being undefined from occurring. */ function redirectDataPageLocation(pageURL) { if ((!IsTopTheIndexHtml()) || (!IsParentTheIndexHtml())) { return; } try { parent.dataPage.location = top.G_objCSRFHandler.getACSRFProtectedUri(pageURL); } catch (err) { } } /** * Decides whether to add radio element to request string. * * @param radioNodeList - the collection of radio input elements. * @param bIsToAddDisabled - indicates whether to add disabled HTML elements to the SET request. * If bIsToAddDisabled is false and an HTML element is disabled, * its value won't be added to the SET request string. * * @return true - Disabled radio element can be added to request string or one of the radio buttons is enabled and checked. * false - All the radio buttons are disabled or unchecked. Radio button doesn't exist. */ function isToAddRadioElementToRequestString(radioNodeList, bIsToAddDisabled) { if ((radioNodeList == null) || (radioNodeList.length == 0)) { return (false); } if (true == bIsToAddDisabled) { return (true); } for (var i = 0 ; i < radioNodeList.length ; ++i) { if ((radioNodeList[i].disabled != true) && (radioNodeList[i].checked == true)) { return (true); } } return (false); } function expandCollapseTable(strId) { var objBranch = document.getElementById(strId).style; if (objBranch.display == "none") { showElement(strId); } else { hideElement(strId); } } // End of code