function checkStatusColors() { for (let i=1; i<=4; i++) { //let val = jQuery("#field"+i).val(); //if (val.length<1) { // val = jQuery("#field"+i).attr("data-value"); //} //let selectedIndex = jQuery("#field"+i)[0].selectedIndex; //if (val && val.startsWith("1-")) { // indicator colors var indicatorColors = [ "#00b050", "yellow", "red", "gray", "#7f6000" ]; var bg="white"; for(s=0; s<indicatorColors.length; s++) { if (jQuery("#field"+i).val().startsWith((s+1)+"-") ) { // assuming top is blank, selectedIndex is index +1 bg = indicatorColors[s]; } } jQuery("#field"+i).css("background-color",bg); } //statusColors var statusValues = [ "", "Complete", "Phase Complete", "In Progress", "Minor Exception", "Major Exception", "Not Started", "Cancelled" ]; var statusColors = [ "initial", "#00b050", "#ffd965", "#92d050", "yellow", "red", "gray", "#7f6000" ]; for(i=0; i<statusValues.length; i++) { if (jQuery("#mStatus").val()==statusValues[i]) { jQuery("#mStatus").css("background-color",statusColors[i]); } } } var hideByStatusFlds = [ 1, 2, 3, 4, 5 ,6, 9, 10, 11 ]; var exceptionMandFlds = [ 10, 11 ]; var exceptionMandLabels = [ "Completion Forecast (Month-Year)", "Reason for Exception" ]; var statusIndicatorsFlds = [ 1, 2, 3, 4 ]; var statusIndicatorsLabels = [ "Cost/Resources", "Scope", "Schedule", "Risk" ]; function showFieldsBasedOnStatus() { let status = jQuery("[name=mStatus]").val(); let titleDiv = jQuery("#indicatorTitleDiv"); if (status && status.indexOf("Exception")>0 || status=="Cancelled") { if (titleDiv) titleDiv.show(); for (let i=0; i<hideByStatusFlds.length; i++) { showField("field"+hideByStatusFlds[i]); } if (jQuery("[name=field5]").length>0) addMandatory("field5", "Status Details"); if (jQuery("[name=field6]").length>0) addMandatory("field6", "Mitigation"); } else { if (titleDiv) titleDiv.hide(); for (let i=0; i<hideByStatusFlds.length; i++) { hideField("field"+hideByStatusFlds[i]); } if (jQuery("[name=field5]").length>0) removeMandatory("field5"); if (jQuery("[name=field6]").length>0) removeMandatory("field6"); } // exception mandatory fields if (status.indexOf("Exception")>=0) { for (let i=0;i<exceptionMandFlds.length;i++) { if (jQuery("[name=field"+exceptionMandFlds[i]+"]").length>0) addMandatory("field"+exceptionMandFlds[i],exceptionMandLabels[i]); } } else { for (let i=0;i<exceptionMandFlds.length;i++) { if (jQuery("[name=field"+exceptionMandFlds[i]+"]").length>0) removeMandatory("field"+exceptionMandFlds[i]); } } if (status.indexOf("Exception")>=0 || status.indexOf("Cancelled")>=0) { for (let i=0;i<statusIndicatorsFlds.length;i++) { if (jQuery("[name=field"+statusIndicatorsFlds[i]+"]").length>0) addMandatory("field"+statusIndicatorsFlds[i],statusIndicatorsLabels[i]); } } else { for (let i=0;i<statusIndicatorsFlds.length;i++) { if (jQuery("[name=field"+statusIndicatorsFlds[i]+"]").length>0) removeMandatory("field"+statusIndicatorsFlds[i]); } } // cancelled mandatory if (status.indexOf("Cancelled")>=0) { if (jQuery("[name=field9]").length>0) { addMandatory("field9","Select option if MS Cancelled"); // if option is carried forward, also need Expected Completion Date if (jQuery("[name=field9]").val()=="Carries Over") { if (jQuery("[name=field10]").length>0) addMandatory("field10", "Expected Completion Date"); } else { if (jQuery("[name=field10]").length>0) removeMandatory("field10"); } } } else { if (jQuery("[name=field9]").length>0) removeMandatory("field9"); } } function updateMilestoneFields() { checkStatusColors(); showFieldsBasedOnStatus(); setTimeout(updateMilestoneFields, 1000); } $( document ).ready(function() { updateMilestoneFields(); }); function otherFitSubmitChecks() { let status = jQuery("[name=mStatus]").val(); // cancelled Indicators must all be cancelled if (status.indexOf("Cancelled")>=0) { for (let i=0;i<statusIndicatorsFlds.length;i++) { let ind = jQuery("#field"+statusIndicatorsFlds[i]); if (i<5) { fitInfo(event, "Major Exception must value for all indicators"); return false; } } } // Minor Exception must have at least one indicator (major already handled by mand icons) let foundIndicator = false; if (status.indexOf("Minor Exception")>=0) { for (let i=0;i<statusIndicatorsFlds.length;i++) { let ind = jQuery("#field"+statusIndicatorsFlds[i]); if (ind && ind[0].selectedIndex>0) { foundIndicator=true; break; } } if (foundIndicator==false) { fitInfo(event, "Minor Exception must have at least one Indicator"); return false; } } return true; }