Created
August 15, 2011 17:44
-
-
Save bittersweetryan/1147295 to your computer and use it in GitHub Desktop.
cleaned up using literal pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var contractForm = { | |
init : function(){ | |
this.validate(); | |
this.mask(); | |
this.showPay(); | |
this.changePartyID(); | |
this.initValidator(); | |
this.validateCBA(); | |
this.setComboboxes(); | |
this.changeContractType(); | |
this.changeDBE(); | |
this.changeStatus(); | |
this.sumFields(); | |
this.changeSolicitation(); | |
this.newCAU(); | |
this.newProject(); | |
this.changeProjectAuthority(); | |
}, | |
validate : function(){ | |
$("#saveContract").validate({ | |
messages:{ | |
highwayName:{ | |
required: "Enter a highway name." | |
} | |
} | |
}); | |
}, | |
mask : function(){ | |
$("#projectNumber").mask("9999-99-99"); | |
//Project placeholder | |
$('input[name*="contract.consultantProjectID"]').mask('9999-99-99',{placeholder:' '}); | |
}, | |
//this is more of an init thing | |
showPay : function(){ | |
var party = { | |
value : parseInt($('#partyId').val(),10) | |
}; | |
if(party.value == "3"){ | |
$(".payclass").fadeIn(); | |
} | |
else{ | |
$(".payclass").fadeOut(); | |
} | |
}, | |
changePartyID : function(){ | |
$("#partyId").change(function(){ | |
var partyValue = Number($('#partyId').val()); | |
if(partyValue == "3"){ | |
$(".payclass").fadeIn(); | |
} | |
else{ | |
var payValue = Number($('#payId').val()); | |
$('#payId').val(""); | |
$(".payclass").fadeOut(); | |
} | |
}); | |
}, | |
validateCBA : function(){ | |
//CBA Validation | |
$("#cbReq").change(function(){ | |
(this.value == "true") ? $(".cb").fadeIn():$(".cb").fadeOut(); | |
(this.value == "true") ? $(".cb").fadeIn():$('#costBenefitAdminAmount,#costBenefitDotAmount,#costBenefitConsultantAmount,#costBenefitAdminHours,#costBenefitWorkHours').attr('value',''); | |
}).change(); | |
}, | |
initValidator : function(){ | |
$.validator.addMethod("NumberOnly", function(value, element) { | |
var regex = new Regex(/^[0-9]+$/i); | |
return this.optional(element) || regex.test(value); | |
}, "Please enter numbers only"); | |
$.validator.addMethod("FloatOnly", function(value, element) { | |
var regex = new Regex(/^[0-9\.]+$/i); | |
return this.optional(element) || regex.test(value); | |
}, "Please enter numbers only"); | |
$.validator.addClassRules("percentrange", {range:[0,100]}); | |
//Party pay validation | |
$.validator.addClassRules("partyrange", {range:[2,3]}); | |
}, | |
setComboboxes : function(){ | |
//turn the combobox inputs into comboboxes | |
$('.combobox').combobox(); | |
//now set the text to be selected on focus | |
$('.ui-autocomplete-input').focus(function(){this.select();}); | |
}, | |
changeContractType : function(){ | |
$('#contractType').change(function() { | |
var selectedText = $("#" + this.id + " option:selected").text().toLowerCase(); | |
$(this).children().each(function(){ | |
if($(this).text().toLowerCase() == selectedText && selectedText !== ''){ | |
$("p#" + selectedText).fadeIn(); | |
} | |
else if($(this).text() !== ""){ | |
$("p#" + $(this).text().toLowerCase()).fadeOut(); | |
} | |
}); | |
}).change(); | |
}, | |
changeDBE : function(){ | |
$("#dbe").change(function(){ | |
(this.value == "true") ? $(".dbe").fadeIn():$(".dbe").fadeOut(); | |
(this.value == "true") ? $(".waive").fadeIn():$(".waive").fadeOut(); | |
(this.value == "true") ? $(".dbe").fadeIn():$("#dbepctId").val(""); | |
}).change(); | |
}, | |
changeStatus : function(){ | |
var statusType = { | |
'' : $([]), | |
'110' : $('#solicitation'), | |
'120' : $('#selection, #solicitation'), | |
'130' : $('#selection, #contractdetail, #open, #budgetdetail, #solicitation'), | |
'140' : $('#open, #selection, #contractdetail, #budgetdetail, #solicitation'), | |
'150' : $('#closure, #selection, #contractdetail, #open,#budgetdetail, #solicitation'), | |
'160' : $('#closure, #selection, #contractdetail, #open,#budgetdetail, #solicitation, #evaluation'), | |
'310' : $('#wosolicitation, #selection, #contractdetail, #budgetdetail, #solicitation'), | |
'320' : $('#wobudget, #selection, #contractdetail, #budgetdetail, #solicitation'), | |
'330' : $('#wocontractdetail, #selection, #contractdetail, #budgetdetail, #solicitation, #evaluateion') | |
}; | |
//we need to make the required and unrequired fields into a smarter object | |
$('#status').change(function() { | |
// hide all | |
$.each(statusType, function() { this.hide(); }); | |
// show current | |
statusType[$(this).val()].show(); | |
if($(this).val()==110){ | |
$("input[name='contract.selectionDateString']").removeClass("required"); | |
$("select[name='contract.vendorID']").removeClass("required"); | |
$("select[name='contractDetail.totalAmount']").removeClass("required"); | |
} | |
if($(this).val() == 120){ | |
$("input[name='contract.selectionDateString']").addClass("required"); | |
$("select[name='contract.vendorID']").addClass("required"); | |
$("select[name='contractDetail.totalAmount']").removeClass("required"); | |
} | |
if($(this).val() == 160){ | |
$("select[name='contractDetail.totalAmount']").addClass("required"); | |
} | |
}).change(); | |
}, | |
sumFields : function(){ | |
//keyup triggers these events | |
$(".primeVendorCost").sumFields($("#totalPrimeVendorCosts")).keyup(); | |
$(".originalCost").sumFields($("#calcContractCosts")).keyup(); | |
$(".revisedCost").sumFields($("#totalRevisedCosts")).keyup(); | |
}, | |
calculateCosts : function(){ | |
Number($("#manHours").val()) > 0 ? $("#costPerHour").val((Number($("#totalRevisedCosts").val())/Number($("#manHours").val())).toFixed(2)):Number($("#costPerHour").val(0)); | |
var values1 = $('#directSalCostAmt,#overheadCostAmt,#fixedfeeAmt').change(function() { | |
Number($("#directSalCostAmt").val()) + Number($("#overheadCostAmt").val()) > 0 ? | |
$("#profitPercentage").val( (Number($("#fixedfeeAmt").val())/(Number($("#directSalCostAmt").val()) + Number($("#overheadCostAmt").val()))).toFixed(2)) : | |
$("#profitPercentage").val(0); | |
$("#manHours").change(function(){ | |
Number($("#manHours").val()) > 0 ? $("#costPerHour").val((Number($("#totalRevisedCosts").val())/Number($("#manHours").val())).toFixed(2)):Number($("#costPerHour").val(0)); | |
}).change(); | |
}); | |
}, | |
changeSolicitation : function(){ | |
//Solicitation dropdown change | |
$("#solicitationID").change(function(){ | |
var description = $("#solDescription"); | |
for(var i = 0; i < solicitationJSON.length; i++){ | |
if(solicitationJSON[i].solicitationID == $(this).val()){ | |
description.html('<span><label>Solicitation Type </label>' + solicitationJSON[i].solicitationTypLkupDesc + '</span>'); | |
return false; | |
} | |
} | |
}).change(); | |
}, | |
newCAU : function(){ | |
$("#newCAUForm").dialog({ | |
autoOpen: false, | |
height: 200, | |
width: 350, | |
modal: true, | |
buttons: { | |
"Create CAU": function() { | |
var cauNumber = $("#cauNumber").val(); | |
$.ajax({ | |
url: 'newCAU.do?method=newContractCAUAjax&cauNumber=' + cauNumber, | |
success: function(retData){ | |
retData = $.trim(retData); | |
var xmlDoc = $.parseXML(retData); | |
$xml = $(xmlDoc); | |
var cauNumber = $xml.find("cau").children("cauNumber").text(); | |
var cauID = $xml.find("cau").children("cauID").text(); | |
var option = $("<option value=" + cauID + " selcted='true'>" + cauNumber + "</option>"); | |
$("#cauID").prepend(option); | |
$("#cauContainer").find(".ui-autocomplete-input").val(cauNumber).animate({'color':'#009900'},'slow'); | |
$("select[name='contract.consultantContractID']").val(cauID); | |
}, | |
error: function(){ | |
alert("Error"); | |
} | |
}); | |
$( this ).dialog( "close" ); | |
}, | |
Cancel: function() { | |
$( this ).dialog( "close" ); | |
} | |
}, | |
close: function() { | |
} | |
}); | |
$("#newCAU").click(function() { | |
$( "#newCAUForm" ).dialog( "open" ); | |
}); | |
}, | |
newProject : function(){ | |
$("#newProjectForm").dialog({ | |
autoOpen: false, | |
height: 200, | |
width: 350, | |
modal: true, | |
buttons: { | |
"Create Project": function() { | |
var projectNumber = $("#projectNumber").val(); | |
$.ajax({ | |
url: 'newProject.do?method=newProjectAjax&projectNumber=' + projectNumber, | |
success: function(retData){ | |
retData = $.trim(retData); | |
var xmlDoc = $.parseXML(retData); | |
$xml = $(xmlDoc); | |
var projectID = $xml.find("project").children("projectID").text(); | |
var projectNumber = $xml.find("project").children("projectNumber").text(); | |
var option = $("<option value=" + projectID + " selcted='true'>" + projectNumber + "</option>"); | |
$("#projectID").prepend(option); | |
$("#projectContainer").find(".ui-autocomplete-input").val(projectNumber); | |
$("select[name='contract.consultantProjectID']").val(projectID); | |
}, | |
error: function(){ | |
alert("Error"); | |
} | |
}); | |
$( this ).dialog( "close" ); | |
}, | |
Cancel: function() { | |
$( this ).dialog( "close" ); | |
} | |
}, | |
close: function() { | |
} | |
}); | |
$("#newProject").click(function() { | |
$( "#newProjectForm" ).dialog( "open" ); | |
}); | |
}, | |
changeProjectAuthority : function(){ | |
$("select[name='contract.projectAuthorityID']").change(function(){ | |
var countyID = $(this).val(); | |
var regionID = 0; | |
for(i = 0; i < countyJSON.length; i++){ | |
if(countyID == countyJSON[i].projectAuthID) | |
regionID = countyJSON[i].regionID; | |
} | |
$("select[name='contract.dotRegionID'] option,select[name='_removed'] option").each(function(){ | |
if($(this).val() == regionID){ | |
regionID = $(this).val(); | |
$(this).attr("selected",true).parent().attr("disabled",false); | |
$(this).parent().attr("name","_removed"); | |
var hiddenInput = $("input[name='contract.dotRegionID']"); | |
if(hiddenInput.length == 0) | |
{ | |
var inputnew = $("<input type='hidden'>"); | |
inputnew.val(regionID); | |
inputnew.attr("name","contract.dotRegionID"); | |
$("#saveContract").append(inputnew); | |
} | |
else{ | |
hiddenInput.val(regionID); | |
} | |
} | |
return true; | |
}); | |
}); | |
} | |
}; | |
$(document).ready(function(){ | |
contractForm.init(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment