{!REQUIRESCRIPT('/soap/ajax/35.0/connection.js')} {!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}; {!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}; {!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")}; var Opportunity = new sforce.SObject('Opportunity'); var result = sforce.connection.describeSObject("Opportunity"); Opportunity.Id = "{!Opportunity.Id}"; var EstimateType = "{!Opportunity.Estimate_Type1__c}"; var StageName1 = "{!Opportunity.StageName}"; var Loss_Reason = "{!Opportunity.Loss_Reason__c}"; var otherValext = "{!Opportunity.Loss_Reason_if_Other__c}"; var Estimate_Reason = "{!Opportunity.Estimate_Reason__c}"; var manual_amount = "{!Opportunity.Manual_amount__c}"; Opportunity.StageName = "Opportunity Lost"; jQuery(function() { jQuery('head').append(''); if(EstimateType == "Estimate Sent" || StageName1 == "Estimate Sent"){ var html ='

Move Opportunity to Lost

Loss Reason
'; }else{ var html ='

Move Opportunity to Lost

Estimate Type
Estimate Reason
Loss Reason
'; } if(!jQuery('[id=dialog]').size()){ jQuery('body').append(html); //estimate type="estimate sent" $("#00NG000000Dqee71 option[value='" + Loss_Reason + "']").attr("selected","selected"); //estimate type="other" $("#00N17000001WIjT1 option[value='" + EstimateType + "']").attr("selected","selected"); $("#00NG000000Dqee7 option[value='" + Loss_Reason + "']").attr("selected","selected"); $("#00N17000001cSmE option[value='" + Estimate_Reason + "']").attr("selected","selected"); manual_amount = manual_amount.substring(1); $('input[name="manualAmt"]').val(manual_amount); $(".lossrsnId1").val(otherValext); //alert("1"+EstimateType); if(EstimateType=="Phone Pricing Provided" || EstimateType=="Verbal Estimate Provided"){ jQuery("#manualAmt").show(); $('input[name="manualAmt"]').val(manual_amount);//*************** }else if(EstimateType=="Commercial Bid" || EstimateType=="Reassigned Opportunity" || EstimateType==""){ jQuery("#manualAmt").hide(); } } jQuery("p").css({"margin-top": "0px", "font-size": "91%","text-align":"center"}); jQuery(".linkclass").css({"padding": "14px", "color": "black","margin-right": "2px"}); jQuery(".btn-primary").css({"color": "#fff","background-color":"#337ab7","border-color":"#2e6da4","display":"inline-block","padding":"6px 12px","margin-bottom":"0","font-size":"14px","font-weight":"400","line-height":"1.42857143","text-align":"center","white-space":"nowrap","vertical-align":"middle","cursor":"pointer","background-image":"none","border":"1px solid transparent","border-radius":"4px"}); jQuery("select,.inputBox").css({"display":"block","width":"100%","height":"34px"," padding":" 6px 12px"," font-size": "14px", "line-height": "1.42857143","color": "#555","background-color": "#fff","background-image": "none","border": "1px solid #ccc","border-radius": "4px","box-shadow": "inset 0 1px 1px rgba(0,0,0,.075)", "transition": "border-color ease-in-out .15s,box-shadow ease-in-out .15s;})"}); jQuery(".footer").css({"padding": "15px 0px 0px","border-top": "1px solid #e5e5e5"}); jQuery(".pheader").css({"background": "#fff","border": "0px","text-align": "center","font-size": "18px","border-bottom": "1px solid #ccc","padding-bottom":"15px"}); jQuery(".ui-widget-header").css({"display": "none"}); //Estimate sent var value1 = "--None--"; if(EstimateType == "Estimate Sent" || StageName1 == "Estimate Sent"){ for (var i=0; i').val(oPicklistVals[b].value).html(oPicklistVals[b].value) ); }else{ mySelect.append( $('').val(oPicklistVals[b].value).html(oPicklistVals[b].value) ); } } if(Loss_Reason == ""){ mySelect.prepend(''); } } } }else{ for (var i=0; i').val(oPicklistVals[b].value).html(oPicklistVals[b].value) ); }else{ mySelect.append( $('').val(oPicklistVals[b].value).html(oPicklistVals[b].value) ); } } if(Loss_Reason == ""){ mySelect.prepend(''); } } else if(field.name == 'Estimate_Reason__c'){ $('#00N17000001cSmE').empty(); var oPicklistVals = field.picklistValues; for (var b=0; b').val(oPicklistVals[b].value).html(oPicklistVals[b].value) ); }else{ mySelectEstrsn.append( $('').val(oPicklistVals[b].value).html(oPicklistVals[b].value) ); } } if(Estimate_Reason == ""){ mySelectEstrsn.prepend(''); } }else if(field.name == 'Estimate_Type1__c'){ $('#00N17000001WIjT1').empty(); var oPicklistVals = field.picklistValues; for (var b=0; b').val(oPicklistVals[b].value).html(oPicklistVals[b].value) ); }else{ mySelectEsttype.append( $('').val(oPicklistVals[b].value).html(oPicklistVals[b].value) ); } } if(EstimateType == ""){ mySelectEsttype.prepend(''); } } } } var otherVal = jQuery("#00NG000000Dqee71 :selected").val(); var otherVal1 = jQuery("#00NG000000Dqee7 :selected").val(); if(otherVal == "Other" || otherVal1=="Other"){ $(".lossrsnId").show(); } /*Open the jQuery Dialog.*/ jQuery( "#dialog" ).dialog({ bgiframe: true, autoOpen: true, resizable: false, minWidth:420, Width:420, Height: 150, modal: true, }); }); jQuery(".ui-dialog-titlebar").hide(); jQuery(".ui-widget-overlay").css({"background": "#000"}); jQuery("#cancelBtn").click(function(){ jQuery('#dialog').dialog('close'); //window.location.reload(); if(EstimateType=="Phone Pricing Provided" || EstimateType=="Verbal Estimate Provided"){ jQuery("#manualAmt").show(); manual_amount = manual_amount.replace(/[^\d\.]/g, ''); $('input[name="manualAmt"]').val(manual_amount);//*************** }else if(EstimateType=="Commercial Bid" || EstimateType=="Reassigned Opportunity" || EstimateType==""){ jQuery("#manualAmt").hide(); } $(".lossrsnId").hide(); }); jQuery("#00NG000000Dqee71").change(function(){ var appCancelled = jQuery("#00NG000000Dqee71 :selected").val(); if(appCancelled == "Other"){ $(".lossrsnId").show(); }else{ $(".lossrsnId").hide(); } }); // jQuery("#00NG000000Dqee7").change(function(){ var appCancelledval = jQuery("#00NG000000Dqee7 :selected").val(); if(appCancelledval == "Other"){ $(".lossrsnId").show(); }else{ $(".lossrsnId").hide(); } }) //manual amt field hide/show jQuery("#00N17000001WIjT1").change(function(){ var EstimateType = jQuery("#00N17000001WIjT1 :selected").val(); //alert('2'+EstimateType); if(EstimateType=="Phone Pricing Provided" || EstimateType=="Verbal Estimate Provided"){ jQuery("#manualAmt").show(); manual_amount = manual_amount.replace(/[^\d\.]/g, ''); $('input[name="manualAmt"]').val(manual_amount);//*************** }else if(EstimateType=="Commercial Bid" || EstimateType=="Reassigned Opportunity" || EstimateType==""){ jQuery("#manualAmt").hide(); $('input[name="manualAmt"]').val(0.00); } //alert(EstimateType); }); jQuery("#btnSave").click(function(){ //alert("test"); var LossReason = jQuery("#00NG000000Dqee71 :selected").val(); var lossrsnId1 = jQuery(".lossrsnId1").val(); if(LossReason != "") { if(LossReason != "Other") { console.log(LossReason); $("#btnSave").attr("disabled",true).css("background","black"); $("#loading1").show("slow", function(){ Opportunity.Loss_Reason__c = LossReason; Opportunity.Loss_Reason_if_Other__c = " "; Opportunity.Estimate_Type1__c = "Estimate Sent"; var result=sforce.connection.update([Opportunity]); //alert(result[0]); if (result[0].getBoolean("success")){ window.location.reload(); }else{ console.log(result[0]); jQuery(".error").text(result[0].errors.message); } }); } }else{ //alert("Please select a value"); jQuery(".error").text("Please select a value"); if(LossReason==""){ jQuery("#00NG000000Dqee71").css("border","1px solid red"); } } //loss reason other value mandatory if(LossReason == "Other") { if(lossrsnId1 != "") { console.log(LossReason); $("#btnSave").attr("disabled",true).css("background","black"); $("#loading1").show("slow", function(){ Opportunity.Loss_Reason__c = LossReason; Opportunity.Loss_Reason_if_Other__c = lossrsnId1; Opportunity.Estimate_Type1__c = "Estimate Sent"; var result=sforce.connection.update([Opportunity]); //alert(result[0]); if (result[0].getBoolean("success")){ window.location.reload(); }else{ console.log(result[0]); jQuery(".error").text(result[0].errors.message); } }); } else{ //alert("Please enter loss reason value.Accepts 255 characters only"); jQuery(".error").text("Please enter loss reason value.Accepts 255 characters only"); if(lossrsnId1==""){ jQuery(".lossrsnId1").css("border","1px solid red"); jQuery("#00NG000000Dqee7").css("border","1px solid #ccc"); } } } }); jQuery("#submitBtn").click(function(){ //alert("test"); var EstimateType = jQuery("#00N17000001WIjT1 :selected").val(); var LossReason = jQuery("#00NG000000Dqee7 :selected").val(); var EstimateReason = jQuery("#00N17000001cSmE :selected").val(); var manualAmt = jQuery("#manualAmt1").val(); var lossrsnId1 = jQuery(".lossrsnId1").val(); var isValid = true; jQuery('input[type="text"]').each(function() { if (jQuery(this).val() == '') { isValid = false; jQuery(this).css({ "border": "1px solid red" }); } else { jQuery(this).css({ "border": "" }); } }); jQuery('select').each(function() { if (jQuery(this).val() == '') { isValid = false; jQuery(this).css({ "border": "1px solid red" }); } else { jQuery(this).css({ "border": "" }); } }); if(EstimateType != "" && LossReason != "" && EstimateReason != "" && manualAmt != "") { if(LossReason != "Other") { console.log(EstimateType); console.log(LossReason); console.log(EstimateReason); console.log(manualAmt); console.log(lossrsnId1); $("#submitBtn").attr("disabled",true).css("background","black"); $("#loading1").show("slow", function(){ Opportunity.StageName = "Opportunity Lost"; Opportunity.Estimate_Type1__c = EstimateType; Opportunity.Loss_Reason__c = LossReason; Opportunity.Estimate_Reason__c = EstimateReason; Opportunity.manual_amount__c = manualAmt; Opportunity.Loss_Reason_if_Other__c = " "; var result=sforce.connection.update([Opportunity]); //alert(result[0]); if (result[0].getBoolean("success")){ window.location.reload(); }else{ //alert("Error modifying Status"); jQuery(".error").text(result[0].errors.message); } }); }else if(LossReason == "Other"){ if(lossrsnId1 != "") { var lossrsnId1 = $(".lossrsnId1").val(); //alert('LossReason'+LossReason); //alert('LossReason-Other'+lossrsnId1); $("#submitBtn").attr("disabled",true).css("background","black"); $("#loading1").show("slow", function(){ Opportunity.StageName = "Opportunity Lost"; Opportunity.Estimate_Type1__c = EstimateType; Opportunity.Loss_Reason__c = LossReason; Opportunity.Estimate_Reason__c = EstimateReason; Opportunity.manual_amount__c = manualAmt; Opportunity.Loss_Reason_if_Other__c = lossrsnId1; var result=sforce.connection.update([Opportunity]); //alert(result[0]); if (result[0].getBoolean("success")){ window.location.reload(); }else{ console.log("result[0].11..."+result[0].errors.message); //var json = JSON.parse(result[0]); //console.log("result[0].22..."+json.message); //alert("Error modifying Status"); jQuery(".error").text(result[0].errors.message); } }); }else{ //alert("Please enter loss reason value.Accepts 255 characters only"); jQuery(".error").text("Please enter loss reason value.Accepts 255 characters only"); /*if(lossrsnId1==""){ jQuery(".lossrsnId1").css("border","1px solid red"); jQuery("#00N17000001cSmE").css("border","1px solid #ccc"); jQuery("#00NG000000Dqee7").css("border","1px solid #ccc"); jQuery("#00N17000001WIjT1").css("border","1px solid #ccc"); jQuery("#manualAmt1").css("border","1px solid #ccc"); }*/ } } }else{ //alert('Please enter/select values'); jQuery(".error").text("Please enter/select values"); /*if(EstimateType== ""){ //red jQuery("#00N17000001WIjT1").css("border","1px solid red"); //black jQuery("#00N17000001cSmE").css("border","1px solid #ccc"); jQuery("#00NG000000Dqee7").css("border","1px solid #ccc"); jQuery("#manualAmt1").css("border","1px solid #ccc"); }else if(EstimateReason==""){ //red jQuery("#00N17000001cSmE").css("border","1px solid red"); //black jQuery("#00NG000000Dqee7").css("border","1px solid #ccc"); jQuery("#00N17000001WIjT1").css("border","1px solid #ccc"); jQuery("#manualAmt1").css("border","1px solid #ccc"); }else if(LossReason==""){ //red jQuery("#00NG000000Dqee7").css("border","1px solid red"); //black jQuery("#00N17000001WIjT1").css("border","1px solid #ccc"); jQuery("#00N17000001cSmE").css("border","1px solid #ccc"); jQuery("#manualAmt1").css("border","1px solid #ccc"); }else if(manualAmt==""){ //red jQuery("#manualAmt1").css("border","1px solid red"); //black jQuery("#00N17000001cSmE").css("border","1px solid #ccc"); jQuery("#00NG000000Dqee7").css("border","1px solid #ccc"); jQuery("#00N17000001WIjT1").css("border","1px solid #ccc"); }*/ } });