/* * JavaScript for operation customer/TIMCO note UI panel interaction. */ document.Operation = new Object(); // For the 'pop-down' notes DIVs. document.Operation.poplist = new Object(); document.Operation.poplist.expandos = new Array(); document.Operation.poplist.heights = new Array(); document.Operation.poplist.names = new Array(); // For the status radio buttons. var operationsModified = false; var operationsModifiedCount = 0; document.Operation.status = new Array(); var disapproveRadioElem; var disapproveRadioElemOperationId; // Read from the enum var NOT_REVIEWED = "NotReviewed"; var DISAPPROVED = "Disapproved"; // Row status previous to green hover var nonHoverRowStatus; // Application level flag whose value is whether or not page can be submitted, prevents double submit var canSubmit = true; /* Note: requires flags set in browsercheck.js */ function toggleUI(id) { // For IE 4+. if (is_ie4up){ if(document.all[id].style.display == 'none'){ document.all[id].style.display = 'block'; } else { document.all[id].style.display = 'none'; } return false; // For W3C-compliant browsers (Netscape,Firefox,Safari,etc.). } else if (is_getElementById){ if(document.getElementById(id).style.display == 'none'){ document.getElementById(id).style.display = 'table-row'; } else { document.getElementById(id).style.display = 'none'; } return false; // For Netscape 4. } else if (is_nav && is_layers) { if(parseInt(id + 1)){ ditem = id + 1; } else { ditem = document.Operation.poplist.names[id]; } if(document.Operation.poplist.expandos[ditem].clip.bottom == 0) { document.Operation.poplist.expandos[ditem].clip.bottom = document.Operation.poplist.heights[ditem]; } else { document.Operation.poplist.expandos[ditem].clip.bottom = 0; } alignToggle(); } } function toggleDiv(id) { // For IE 4+. if (is_ie4up){ if(document.all[id].style.display == 'none'){ document.all[id].style.display = 'block'; } else { document.all[id].style.display = 'none'; } return false; // For W3C-compliant browsers (Netscape,Firefox,Safari,etc.). } else if (is_getElementById){ if(document.getElementById(id).style.display == 'none'){ document.getElementById(id).style.display = 'block'; } else { document.getElementById(id).style.display = 'none'; } return false; // For Netscape 4. } else if (is_nav && is_layers) { if(parseInt(id + 1)){ ditem = id + 1; } else { ditem = document.Operation.poplist.names[id]; } if(document.Operation.poplist.expandos[ditem].clip.bottom == 0) { document.Operation.poplist.expandos[ditem].clip.bottom = document.Operation.poplist.heights[ditem]; } else { document.Operation.poplist.expandos[ditem].clip.bottom = 0; } alignToggle(); } } function toggleImage(img, src1, src2){ // For all JavaScript-compliant browsers. if(document.images){ // Check to make sure that images are supported in the DOM. myImage = document.images[img]; // Check to see whether you are using a name, number, or object if(myImage.src == src1.src){ myImage.src = src2.src; } else if(myImage.src == src2.src){ myImage.src = src1.src; } } } function setImage(img, src){ // For all JavaScript-compliant browsers. if(document.images){ // Check to make sure that images are supported in the DOM. myImage = document.images[img]; // If our src is null, then we can clear out the image if (src==null) { myImage.src = null; } else { // Otherwise set the image as requested myImage.src = src.src; } } } function showDiv(divId) { var divElem = getElem(divId); if (divElem) { if (divElem.style.display == 'none') { divElem.style.display = 'block'; } } } function hideDiv(divId) { var divElem = getElem(divId); if (divElem) { divElem.style.display = 'none'; } } function showButton(divId) { showDiv("button" + divId); var imgName = "icon" + divId; if (document.images) { myImage = document.images[imgName]; myImage.src = iconOn.src; } } function hideButton(divId) { hideDiv("button" + divId); var imgName = "icon" + divId; if (document.images) { myImage = document.images[imgName]; myImage.src = iconOff.src; } } function toggleLaborEstimateNoteTextarea(evt, id) { evt = (evt) ? evt : ((event) ? event : null); if (evt) { var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if (elem) { // Get value of clicked radio button element. var idNum = id; var name = elem.name; var checkedValue = getRadioValue("\"" + name + "\""); var panelId = "op-note" + idNum; var textAreaId = "note_" + idNum; var panelElem = getElem(panelId); var textAreaElem = getElem(textAreaId); // Enable the note textarea. if (checkedValue == NOT_REVIEWED) { // Disable and hide the note textarea. textAreaElem.disabled = true; textAreaElem.style.backgroundColor = "#CCCCCC"; if (panelElem.style.display != "none") { toggleUI(panelId); // Switch the expand/collapse icon, if present. if (document.images["icon"+idNum]) { if (hasNotes(idNum)) { setImage("icon"+idNum, iconOff); } else { // No notes are present, so hide the dropdown icon setImage("icon"+idNum, null); hideDiv("button"+idNum); } } } // hide row level error icon curErrorIcon = getElem("errorButton" + idNum); if (curErrorIcon) { curErrorIcon.style.display = 'none'; } } else { disapproveRadioElem = elem; disapproveRadioElemOperationId = id; textAreaElem.disabled = false; textAreaElem.style.backgroundColor = "#FFFFFF"; if (panelElem.style.display == "none") { toggleUI(panelId); // Switch the expand/collapse icon, if present. if (document.images["icon"+idNum]) { setImage("icon"+idNum, iconOn); } } textAreaElem.focus(); } // Update operation row if state changed. radioButtonOperationChanged(idNum, checkedValue, name); } } } function toggleNoteTextarea(evt, id) { evt = (evt) ? evt : ((event) ? event : null); if (evt) { var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if (elem) { // Get value of clicked radio button element. var idNum = id; var name = elem.name; var checkedValue = getRadioValue("\"" + name + "\""); var panelId = "op-note" + idNum; var textAreaId = "note_" + idNum; var panelElem = getElem(panelId); var textAreaElem = getElem(textAreaId); // Enable the note textarea. if (checkedValue == DISAPPROVED) { disapproveRadioElem = elem; disapproveRadioElemOperationId = id; textAreaElem.disabled = false; textAreaElem.style.backgroundColor = "#FFFFFF"; if (panelElem.style.display == "none") { toggleUI(panelId); // Switch the expand/collapse icon, if present. if (document.images["icon"+idNum]) { setImage("icon"+idNum, iconOn); } } textAreaElem.focus(); // Disable and hide the note textarea. } else { textAreaElem.disabled = true; textAreaElem.style.backgroundColor = "#CCCCCC"; if (panelElem.style.display != "none") { toggleUI(panelId); // Switch the expand/collapse icon, if present. if (document.images["icon"+idNum]) { if (hasNotes(idNum)) { setImage("icon"+idNum, iconOff); } else { // No notes are present, so hide the dropdown icon setImage("icon"+idNum, null); hideDiv("button"+idNum); } } } // hide row level error icon curErrorIcon = getElem("errorButton" + idNum); if (curErrorIcon) { curErrorIcon.style.display = 'none'; } } // Update operation row if state changed. radioButtonOperationChanged(idNum, checkedValue, name); } } } function hasNotes(rowId) { return ((document.getElementById("custNoteDiv" +rowId) != null) || (document.getElementById("timcoNoteDiv" +rowId) != null) ); } function alignToggle() { var i, j, infiniteLoopError; infiniteLoopError = document.Operation.poplist.expandos.length; for(i = 0; i < infiniteLoopError; i++) { j = i + 1; if(document.Operation.poplist.expandos[j]){ if(document.layers) { document.Operation.poplist.expandos[j].top = document.Operation.poplist.expandos[i].top + document.Operation.poplist.expandos[i].clip.bottom; } } } } // set operation changed status on radio button click and color changed row function radioButtonOperationChanged(idNum, checkedValue, name) { var dataRowId = "op-data" + idNum; var noteRowId = "op-note" + idNum; var dataRowElem = getElem(dataRowId); var noteRowElem = getElem(noteRowId); // Change background-color to RED, if state changed. opState = document.Operation.status[idNum]; if (opState != checkedValue) { operationsModified = true; operationsModifiedCount += 1; dataRowElem.className = "changed-row"; nonHoverRowStatus = "changed-row"; noteRowElem.style.backgroundColor = "#FF9999"; } // Check state for batch checkbox enable/disable in all cases. toggleCheckbox(idNum, name); } // set operation changed status on checkbox click and color changed row function checkboxOperationChanged(idNum) { var dataRowId = "op-data" + idNum; var noteRowId = "op-note" + idNum; var dataRowElem = getElem(dataRowId); var noteRowElem = getElem(noteRowId); dataRowElem.className = "changed-row"; nonHoverRowStatus = "changed-row"; noteRowElem.style.backgroundColor = "#FF9999"; operationsModified = true; operationsModifiedCount += 1; } function operationSaved(idNum) {} function confirmPage(nextPageUrl) { var goToUrl = false; // If operations were changed, force a confirmation before leaving the page. if (operationsModified) { var message = "You have made changes to one or more Operations.\n"; message += "Click OK to leave this page WITHOUT saving your changes."; goToUrl = confirm(message); } else { goToUrl = true; } if (goToUrl) { window.location = nextPageUrl; } } function confirmApproveAll(unreviewedCount) { var message = ""; if (operationsModified) { message = "You have made changes to one or more Operations.\n" + "All unsaved changes will be discarded if you continue."; if (!confirm(message)) { return false; } } message = "Clicking OK will mark " + unreviewedCount + " operation(s) as approved.\n" + "Any further changes to the affected operations\n" + "must be made individually."; return confirm(message) } function toggleCheckbox(idNum, name) { var checkboxElemId = "batch_" + idNum; var divElem = getElem("batch_div_" + idNum); var checkboxElem = getElem(checkboxElemId); var radioElemName = "\"" + name + "\""; var validValue = (getRadioValue(radioElemName) == NOT_REVIEWED) ? false : true; // Final attempt. if (!checkboxElem) { for (i = 0; i < document.forms[0].elements.length; i++) { if (document.forms[0].elements[i].name == checkboxElemId) { checkboxElem = document.forms[0].elements[i]; break; } } } if (checkboxElem) { checkboxElem.checked = validValue; //checkboxElem.disabled = !validValue; -- switched to flipping display on and off checkboxElem.style.display = validValue ? "inline" : "none"; // If there is an associated div that should be hidden/displayed if (divElem) { divElem.style.display = validValue ? "inline" : "none"; } } } function getRadioValue(name) { var radioGroup = eval("document.forms[0][" + name + "]"); var radioValue = ""; // no radioGroup means its already been submitted to majic if(radioGroup == null) { return radioValue; } for (i = 0; i < radioGroup.length; i++) { if (radioGroup[i].checked == true) { radioValue = radioGroup[i].value; break; } } return radioValue; } // Returns element by id based on browser type function getElem(id) { var elem; // For Netscape 4 if (is_nav && is_nav4) { elem = document.layers[id]; // For IE 4+ } else if (is_ie && is_ie4up) { elem = document.all[id]; // For W3C-compliant browsers (Netscape,Firefox,Safari,etc.) } else if (is_getElementsByTagName && is_getElementById) { elem = document.getElementById(id); } return elem; } // Shows error divs when Disapprovals are attempted to be saved without Notes/ // Returns true if all Disapprovals have Notes. function confirmNotes() { if(getElem("message") != null) { getElem("message").innerHTML = ""; } var typeName = getElem('typeName').value; var displayError = false; var regexPattern = /^\D+/gi; var tblRows = getElem("op-table").getElementsByTagName("tr"); var rowCount; var offset; var regExp = new RegExp("OperationDetail","i"); var name; var domTypeName = typeName; // if its the detail level page if(regExp.test(typeName)) { domTypeName = domTypeName.replace(regExp, ""); rowCount = 1; offset = 1; // detail level has one less initial tr than summary level name = "\"" + domTypeName + ".approval.status\""; } else { // summary level page rowCount = parseInt(getElem('rowCount').value); offset = 2; } for(row = 0; row < rowCount; row++) { if(!regExp.test(typeName)) { name = "\"operations[" + row + "]." + typeName + ".approval.status\""; } currRow = tblRows[(row*2)+offset]; currId = currRow.id.replace(regexPattern, ""); if(getRadioValue(name) == DISAPPROVED) { text = getElem("note_" + currId).value; trimmedText = text.replace(/^\s*|\s*$/g,""); if(trimmedText == null || trimmedText == "") { showDiv("errorButton" + currId); displayError = true; } else { hideDiv("errorButton" + currId); } } else { hideDiv("errorButton" + currId); } } if(displayError) { showDiv("errors-top"); return false; } else { hideDiv("errors-top"); // check for double click and return appropriate value return buttonDisabler(); } } function selectAllCheckBoxes(element) { var aForm = element.form; for(i = 0; i < aForm.length; i++) { if(aForm[i].type == "checkbox" && (!aForm[i].disabled || (aForm[i].disabled && !element.checked))) { aForm[i].checked = element.checked; } } } function resetOperationListForm() { var oddRowBgColor = "#DDDDFF"; var evenRowBgColor = "#FFFFFF"; var detailRowBgColor = "#EEEEEE"; // 1. Iterate over table rows and reset bgcolor + notes button (arrow). var tblRows = getElem("op-table").getElementsByTagName("tr"); var regexPattern = /^\D+/gi; var regexPatternData = new RegExp("data","i"); var pageRow = 0; for (i = 0; i < tblRows.length; i++) { curRow = tblRows[i]; // only process relevant rows (skip first and last tr) if(curRow.id == "" || !regexPatternData.test(curRow.id)) { continue; } else { // increment on every pair of "visible" rows pageRow++; } curClass = curRow.className; curId = curRow.id.replace(regexPattern, ""); curButton = getElem("button" + curId); curCheckbox = getElem("batch_" + curId); curNotesBox = getElem("op-note" + curId); curErrorIcon = getElem("errorButton" + curId); if (curClass == "changed-row") { if((pageRow % 2) == 0) { curRow.className = "even-row"; } else { curRow.className = "odd-row"; } } // Hide the button, based on original state. originalState = document.Operation.status[curId]; if (originalState != DISAPPROVED) { if (curButton && !hasNotes(curId)) { curButton.style.display = 'none'; } // Switch the expand/collapse icon, if present. if (document.images["icon"+curId]) { setImage("icon"+curId, iconOff); } if(curNotesBox) { curNotesBox.style.display = 'none'; } } // Already been submitted to majic, nothing to disable if (curCheckbox != null) { if (originalState == "" || originalState == null || originalState == NOT_REVIEWED) { curCheckbox.disabled = true; } else { curCheckbox.disabled = false; } } // hide row level error icon if (curErrorIcon) { curErrorIcon.style.display = 'none'; } } // hide the page level error icon and note hideDiv("errors-top"); // 2. Reset operationModified* flags. This gets rid of the modified data warning popup. operationsModified = false; operationsModifiedCount = 0; } // Library method for syncronizing a TARGET select to a SRC select index. function syncSelects(src, target) { var srcObj = getElem(src); var targetObj = getElem(target); targetObj.selectedIndex = srcObj.selectedIndex; } // sets a row classname (color) back to its original state when the cursor is moved off the row function setRowClassOut(idNum) { var row = getElem("op-data"+idNum); row.className = nonHoverRowStatus; } // temporarily saves a row classname (color) when the cursor is moved over the row for hover function setRowClassOver(idNum) { var row = getElem("op-data"+idNum); nonHoverRowStatus = row.className; row.className = "hover-row"; } // returns true and sets to false if first submit button click, otherwise just return false because user dbl clicked function buttonDisabler() { if(canSubmit) { canSubmit=false; return true; } else { return false; } }