;APPLYFORSOBJECT = {
setValidateAttestation: function() {
APPLYFORSOBJECT.validateAttestation = 'yes';
console.log('setValidateAttestation:APPLYFORSOBJECT.validateAttestation:'+APPLYFORSOBJECT.validateAttestation);
},
isValidateAttestation: function() {
console.log('isValidateAttestation:APPLYFORSOBJECT.validateAttestation:'+APPLYFORSOBJECT.validateAttestation);
if(APPLYFORSOBJECT.validateAttestation == 'yes'){
return true;
} else {
return false;
}
},
setFeeEstimation: function() {
APPLYFORSOBJECT.validateFeeEstimation = 'yes';
console.log('setFeeEstimation:APPLYFORSOBJECT.validateFeeEstimation:'+APPLYFORSOBJECT.validateFeeEstimation);
},
isFeeEstimation: function() {
//console.log('isFeeEstimation:APPLYFORSOBJECT.validateFeeEstimation:'+APPLYFORSOBJECT.validateFeeEstimation);
if(APPLYFORSOBJECT.validateFeeEstimation != null && APPLYFORSOBJECT.validateFeeEstimation != ''
&& APPLYFORSOBJECT.validateFeeEstimation != undefined && APPLYFORSOBJECT.validateFeeEstimation == 'yes'){
return true;
} else {
return false;
}
},
loadEvents: function() {
var validateAttestation = 'no';
var validateFeeEstimation = 'no';
// Continue button
$("#saveAndContinue").on("click", function() {
var groupCategory = $('input[id^="grpCategory"]').val().trim();
var formSubtype = $('input[id^="frmSubtype"]').val();
var frmPageName = $('input[id^="formPageName"]').val().trim();
var varLocation = document.querySelector('[title="Location Type - Chosen"]');
// var varApplicationType = document.querySelector('[title="Application Type - Chosen"]');
var varApplicationType = $("select[title='Application Type - Chosen']");
var varComplaintType = document.querySelector('[title="Reported Complaint Type - Chosen"]');
if(!isEmpty(grpCategory) && grpCategory == 'Complaint') {
APPLYFORSOBJECT.buildValidationObject();
}
console.log('saveAndContinue==current Section='+progressBarWidget.progressbar("getActiveSection"));
var currSection = progressBarWidget.progressbar("getActiveSection");
if(currSection != '' && currSection == '1'){
if(APPLYFORSOBJECT.validateProjectInfo()){
var errorMessage = '';
if(varLocation != null && varLocation.length <= 0){
errorMessage = '
Location Type cannot be empty ';
}
if(groupCategory == 'Planning Application' && formSubtype!= null && frmSubtype != 'Pre-Planning Application' && varApplicationType != null && varApplicationType!= undefined && varApplicationType.find('Option').length <= 0){
errorMessage = 'Permit/Application Subtype cannot be empty ';
//varApplicationType.classList.add("errorElement");
}
else
{
//varApplicationType.classList.remove("errorElement");
}
if(groupCategory == 'Permit Application' && formSubtype!='Solar APP+ Roof-mounted Solar'){
//alert(formSubtype);
var addlocationInfo = $("[title$='Additional_Notes__c']").val();
console.log('additionalLocInfo --->'+addlocationInfo);
/*validate Parcel Location is not empty*/
var location = $("[id$='sMapViewerLocationJSON']").val();
console.log('location is : '+location.length);
if(frmPageName == 'Water Discharge Flood Permit Application' && (location==undefined || null==location || location=='' || location.length < 3)) {
errorMessage = errorMessage + ' Please provide a location using the map viewer (Step 2).';
}
else if((location==undefined || null==location || location=='' || location.length < 3) && (addlocationInfo==null || addlocationInfo=='' || addlocationInfo==undefined)) {
errorMessage = errorMessage + ' Please either provide a location using the map viewer (Step 2) OR enter an address in the "Additional Location Information" box (Step 3).';
}
}
if(varComplaintType != null && varComplaintType.length <= 0){
errorMessage = errorMessage + ' Reported Complaint Type cannot be empty ';
}
if(validationMapper.applicationFields.validator.errors().length <= 0 && errorMessage.length <=0) {
OC_NOTIFICATIONS.spinnerStart();
var currentSection = 0;
currentSection = progressBarWidget.progressbar("getActiveSection");
var nextSection1 = progressBarWidget.progressbar("getNextSection");
saveAndContinue(currentSection, nextSection1);
isFirstInsert = false;
}
else {
OC_MODAL_UTILITY.errorMessageModal(''+ validationMapper.applicationFields.validator.errorHtml());
}
}
}else {
var errorMessage = '';
if(groupCategory == 'Map Application' && currSection != '' && currSection == '3'){
var crQuery = "select Id, No_of_portal_CRS__c, Number_of_Corner_requests__c from MUSW__Application2__c where id='"+licGlobalObj.currentRecId+"' AND MUSW__Type__c='Corner Records'";
var resultQuery = sforce.connection.query(crQuery);
var records = resultQuery.getArray("records");
//console.log( records[0].Number_of_Corner_requests__c+'.0' +'-----'+ records[0].No_of_portal_CRS__c);
if(records != '' && records.length > 0 && records[0].Number_of_Corner_requests__c != records[0].No_of_portal_CRS__c+'.0'){
errorMessage = ' Number of Corner records entered is not equal to Submitted Corner Records ';
//OC_MODAL_UTILITY.errorMessageModal(errorMessage);
}
}
if(validationMapper.applicationFields.validator.errors().length <= 0 && errorMessage.length <=0) {
OC_NOTIFICATIONS.spinnerStart();
var currentSection = 0;
currentSection = progressBarWidget.progressbar("getActiveSection");
var nextSection1 = progressBarWidget.progressbar("getNextSection");
saveAndContinue(currentSection, nextSection1);
isFirstInsert = false;
}
else {
OC_MODAL_UTILITY.errorMessageModal(''+validationMapper.applicationFields.validator.errorHtml());
}
}
});
// Cancel button
$("#cancelButton").on("click", function() {
ACTIONS.displayCancelDialog();
});
// Save button
$(".saveAndLater").on("click", function() {
OC_NOTIFICATIONS.spinnerStart();
OC_APPLYFORLICENSE.quickSave();
});
//Prev button
$("#prevButton").on("click", function() {
OC_NOTIFICATIONS.spinnerStart();
if(!isEmpty(grpCategory) && grpCategory == 'Complaint'){
validationMapper.applicationFields.validator = null;
}
var currentSection = 0;
currentSection = progressBarWidget.progressbar("getActiveSection");
var nextSection1 = progressBarWidget.progressbar("getNextSection");
navPrevious(currentSection,nextSection1);
});
// submit button
//$("#submitPage").on("click", function() {
$(".submitPageClass").on("click", function() {
if(APPLYFORSOBJECT.isValidateAttestation()) {
if(APPLYFORSOBJECT.validateAttestationFields()){
OC_NOTIFICATIONS.spinnerStart();
var currentSection = 0;
currentSection = progressBarWidget.progressbar("getActiveSection");
var nextSection1 = progressBarWidget.progressbar("getNextSection");
console.log('currentSection=='+currentSection+'==nextSection1=='+nextSection1);
submitApplication(currentSection, nextSection1);
console.log('currentSection==after submit===');
}
}else {
OC_NOTIFICATIONS.spinnerStart();
var currentSection = 0;
currentSection = progressBarWidget.progressbar("getActiveSection");
var nextSection1 = progressBarWidget.progressbar("getNextSection");
submitApplication(currentSection, nextSection1);
}
//return false;
});
$("#viewPackage").on("click", function() {
OC_NOTIFICATIONS.spinnerStart();
redirectPackage();
});
// Map Ok Button
/* $("#mapAssignAndContinue").on("click", function() {
mapAssignAndContinue();
});*/
//$(".lmsRelatedAddrSummary").append(lmsRelatedAddrSummaryHTML);
var validateAttestation = 'no';
},
//If any exception in first page it will stop user to navigate next page.
validateExceptionInfo: function(){
var exceptionInfo = '';
var exceptionInfo = $("#saveErrorMsgString").text().trim();
if(null != exceptionInfo && exceptionInfo != undefined && exceptionInfo != '') {
OC_NOTIFICATIONS.spinnerStop();
OC_MODAL_UTILITY.errorMessageModal(exceptionInfo);
}else{
return true;
}
},
validateProjectInfo: function(){
console.log('validateProjectInfo===');
var projInfoVldMsg = '';
var groupCategoryVal = $('input[id^="grpCategory"]').val().trim();
var isYesExistingProjOpt = $("[id$='isExistingProject_id:0']").prop("checked");
var isNoExistingProjOpt = $("[id$='isExistingProject_id:1']").prop("checked");
if(isYesExistingProjOpt != undefined && isNoExistingProjOpt != undefined){
if(isYesExistingProjOpt == false && isNoExistingProjOpt == false){
projInfoVldMsg = projInfoVldMsg+'Please specify if this is for an existing project. Please complete all fields before continuing.
';
}else if(isYesExistingProjOpt == true){
var selectProj = $("[id$='selectProject_input']").find(":selected").text();
//var selectProj = $("[id$='selectProject_input']").val();
if(selectProj==null || selectProj=='' || selectProj == undefined || selectProj =='-- None --'){
projInfoVldMsg = projInfoVldMsg+'Select Project cannot be empty.
';
}
}else if(isNoExistingProjOpt == true){
var projName = $("[id$='newProjectName_input']").val();
projName = projName.replace(/'/g, "\\'");
if(projName != null && projName != '' && projName != undefined
&& (licGlobalObj.currentRecId == undefined || licGlobalObj.currentRecId == '' || licGlobalObj.currentRecId == null)){
var userQuery = "SELECT ContactId FROM User where Id = '"+window.UserContext.userId+"'";
var userQueryResult = sforce.connection.query(userQuery);
var userQueryRecords = userQueryResult.getArray("records");
if(userQueryRecords != null && userQueryRecords.length > 0){
//if(groupCategoryVal != null && groupCategoryVal != '' && groupCategoryVal == 'Permit Application'){
var projectQuery = "select Id, Name, MUSW__Description__c from MUSW__Project2__c where Name='"+projName+"' AND MUSW__Parcel_Owner__c IN('"+userQueryRecords[0].ContactId+"')";
var projectQueryResult = sforce.connection.query(projectQuery);
var projectQueryRecords = projectQueryResult.getArray("records");
if(projectQueryRecords != '' && projectQueryRecords.length > 0){
projInfoVldMsg = projInfoVldMsg+'Project Name already exist. Please type different name for project.
';
}
//}
}
}
if(projName==null || projName=='' || projName == undefined){
projInfoVldMsg = projInfoVldMsg+'Project Name cannot be empty.
';
}
var projDesc = $("[id$='projectDescription_input']").val();
if(projDesc==null || projDesc=='' || projDesc == undefined){
projInfoVldMsg = projInfoVldMsg+'Project Description cannot be empty.';
}
}
}
if(null!=projInfoVldMsg && projInfoVldMsg!=undefined && projInfoVldMsg!='') {
OC_NOTIFICATIONS.spinnerStop();
OC_MODAL_UTILITY.errorMessageModal(projInfoVldMsg);
}else{
return true;
}
console.log('submitVldMsg======='+projInfoVldMsg);
},
validateAttestationFields: function(){
var submitVldMsg = '';
var attFullName = $("[id$='attFullName']").val();
if(attFullName==null || attFullName=='' || attFullName==undefined) {
submitVldMsg = submitVldMsg+'Full Name cannot be empty
';
}
var attDate = $("[id$='attDate']").val();
if(attDate==null || attDate=='' || attDate==undefined) {
submitVldMsg = submitVldMsg+'Date cannot be empty
';
}
//var isAgreeTrue = $('input[name="{!$Component.attIsAgree}"]:checked').val();
var isAgreeTrue = $("[id$='attIsAgree']").prop("checked");
console.log('isAgreeTrue==='+isAgreeTrue);
if(isAgreeTrue==null || isAgreeTrue==undefined || isAgreeTrue=='' || isAgreeTrue == 'false') {
submitVldMsg = submitVldMsg+'I agree that everything in this application is true? cannot be empty
';
}
if(null!=submitVldMsg && submitVldMsg!=undefined && submitVldMsg!='') {
OC_MODAL_UTILITY.errorMessageModal(submitVldMsg);
}else{
return true;
}
console.log('submitVldMsg======='+submitVldMsg);
},
buildValidationObject: function() {
validationMapper.applicationFields = {};
validationMapper.applicationFields.validationObject = {};
validationMapper.applicationFields.validationObject.fields = [];
$.each(validationObj, function(i, val1) {
console.log('val1=='+val1+i);
if(progressBarWidget.progressbar("getActiveSection") == val1.orderNumber) {
console.log('val1.orderNumber=='+val1.orderNumber);
$.each(val1.subSectionObjMap, function(j, val2) {
console.log('val2=='+val2);
console.log('fieldObjMap --->',val2.fieldObjMap);
var fieldObjArr = [];
$.each(val2.fieldObjMap, function(k, valz) {
if(grpCategory=="Complaint"){
if(valz.name=='FirstName' || valz.name == 'LastName')
{
valz.required = true;
}
}
fieldObjArr.push({ id: valz.id, sType: valz.sType, displayName: valz.displayName, required: valz.required, validator: valz.validator, orderNumber: valz.orderNumber });
});
console.log('fieldObjArr1 --->',fieldObjArr);
fieldObjArr.sort(function(a, b) {
return a.orderNumber-b.orderNumber;
});
console.log('fieldObjArr2 --->',fieldObjArr);
$.each(fieldObjArr, function(k, val3) {
var elementValue ='';
console.log('==buildValidationObject====='+val3.sType+'==val3.id==='+val3.id+'val3.required=='+val3.required+'validator=='+val3.validator);
if(val3.sType == 'Text' || val3.sType == 'Phone' || val3.sType == 'Email' || val3.sType == 'Number'){
elementValue = $("#vald" + val3.id + " input");
}else if(val3.sType == 'TextArea'){
//elementValue = $("#vald" + val3.id + " input");
//TextArea is formed with