File: //home/arjun/projects/buyercall_new/buyercall/buyercall/assets/scripts/form_leads_backend_edit.js
var $ = require('jquery');
import * as autopay from '../components/forms/autopay';
import * as sectionInvalidator from '../components/forms/sectionInvalidator';
$(function () {
var csrfToken = $('meta[name=csrf-token]').attr('content');
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrfToken);
}
}
});
autopay.wireButton($('.btn-holder'), '.autopay.btn'
, {
willBeDisabled: false,
sentBtnText: 'Resend to Autopay',
createErrorPopup: true
});
sectionInvalidator.wire($('.lead-form'), $('.btn-holder'), 'Please save your changes by clicking the update button at the bottom of the form or your changes will not be saved.');
});
$(function() {
$('.btnSSN').on('click', function() {
if ($('.input-ssn').attr('ssn-shown') == 'false') {
$('.input-ssn').removeAttr('type');
$('.input-ssn').attr('type', 'text');
$('.input-ssn').removeAttr('ssn-shown');
$('.input-ssn').attr('ssn-shown', 'true');
$('.btnSSN').html('HIDE');
}else {
$('.input-ssn').removeAttr('type');
$('.input-ssn').attr('type', 'password');
$('.input-ssn').removeAttr('ssn-shown');
$('.input-ssn').attr('ssn-shown', 'false');
$('.btnSSN').html('SHOW');
}
});
});
// Hide & Show SSN field button
$(function() {
$('.toggle').attr('style', 'margin-right:5px !important;');
$('#chkViewType').on('click', function() {
if ($(this).is(":checked")) {
$('.panel-heading, .no-fields-for-category').hide();
$('.panel-collapse').removeClass('in').addClass('in');
$('.panel').attr('style', 'margin-bottom:0px !important');
$('.panel-body').attr('style', 'padding: 0px 0px 5px !important;');
$('.panel-heading a').removeAttr('aria-expanded');
} else {
$('.panel-heading, .no-fields-for-category').show();
$('.panel-collapse').removeClass('in');
$('.panel').attr('style', 'margin-bottom:20px');
$('.panel-body').attr('style', 'padding: 15px 0px 5px;');
$('#headingPersonal a').attr('aria-expanded', 'true');
$('#collapsePersonal').addClass('in');
}
});
});
// Co signer SSN field protection
$(function() {
$('.btnCoSSN').on('click', function() {
if ($('.input-co-ssn').attr('co-ssn-shown') == 'false') {
$('.input-co-ssn').removeAttr('type');
$('.input-co-ssn').attr('type', 'text');
$('.input-co-ssn').removeAttr('co-ssn-shown');
$('.input-co-ssn').attr('co-ssn-shown', 'true');
$('.btnCoSSN').html('HIDE');
}else {
$('.input-co-ssn').removeAttr('type');
$('.input-co-ssn').attr('type', 'password');
$('.input-co-ssn').removeAttr('co-ssn-shown');
$('.input-co-ssn').attr('co-ssn-shown', 'false');
$('.btnCoSSN').html('SHOW');
}
});
});
// Hide & Show Birth Date field button
$(function() {
$('.btnDOB').on('click', function() {
if ($('.input-dob').attr('dob-shown') == 'false') {
$('.input-dob').removeAttr('type');
$('.input-dob').attr('type', 'text');
$('.input-dob').removeAttr('dob-shown');
$('.input-dob').attr('dob-shown', 'true');
$('.btnDOB').html('HIDE');
}else {
$('.input-dob').removeAttr('type');
$('.input-dob').attr('type', 'password');
$('.input-dob').removeAttr('dob-shown');
$('.input-dob').attr('dob-shown', 'false');
$('.btnDOB').html('SHOW');
}
});
});
// Hide & Show Cosigner Birth Date field button
$(function() {
$('.btnCoDOB').on('click', function() {
if ($('.input-co-dob').attr('co-dob-shown') == 'false') {
$('.input-co-dob').removeAttr('type');
$('.input-co-dob').attr('type', 'text');
$('.input-co-dob').removeAttr('co-dob-shown');
$('.input-co-dob').attr('co-dob-shown', 'true');
$('.btnCoDOB').html('HIDE');
}else {
$('.input-co-dob').removeAttr('type');
$('.input-co-dob').attr('type', 'password');
$('.input-co-dob').removeAttr('co-dob-shown');
$('.input-co-dob').attr('co-dob-shown', 'false');
$('.btnCoDOB').html('SHOW');
}
});
});
// Hide & Show Drivers licence field
$(function() {
$('.btnDL').on('click', function() {
if ($('.input-dl').attr('dl-shown') == 'false') {
$('.input-dl').removeAttr('type').attr('type', 'text').removeAttr('dl-shown').attr('dl-shown', 'true');
$('.btnDL').html('HIDE');
}else {
$('.input-dl').removeAttr('type').attr('type', 'password').removeAttr('dl-shown').attr('dl-shown', 'false');
$('.btnDL').html('SHOW');
}
});
});
// Hide & Show Co Signer Drivers licence field
$(function() {
$('.btnCoDL').on('click', function() {
if ($('.input-co-dl').attr('co-dl-shown') == 'false') {
$('.input-co-dl').removeAttr('type');
$('.input-co-dl').attr('type', 'text');
$('.input-co-dl').removeAttr('co-dl-shown');
$('.input-co-dl').attr('co-dl-shown', 'true');
$('.btnCoDL').html('HIDE');
}else {
$('.input-co-dl').removeAttr('type');
$('.input-co-dl').attr('type', 'password');
$('.input-co-dl').removeAttr('co-dl-shown');
$('.input-co-dl').attr('co-dl-shown', 'false');
$('.btnCoDL').html('SHOW');
}
});
});
$(function() {
var loadFirstName = $("#field-firstnamefield").val().length;
var loadLastName = $("#field-lastnamefield").val().length;
var loadEmail = $("#field-emailfield").val().length;
var loadPhone = $("#field-phonefield").val().length;
var firstNameCanSave = true;
var lastNameCanSave = true;
var emailCanSave = true;
var phoneCanSave = true;
function enableSave() {
var saveButton = $('#btnSaveFormLead');
if (firstNameCanSave && lastNameCanSave && emailCanSave && phoneCanSave) {
saveButton.removeAttr('disabled');
} else {
saveButton.attr('disabled', 'disabled');
}
}
$("#field-firstnamefield").change(function(){
if (loadFirstName != 0 && $(this).val().length == 0) {
firstNameCanSave = false;
} else {
firstNameCanSave = true;
}
enableSave();
});
$("#field-lastnamefield").change(function(){
if (loadLastName != 0 && $(this).val().length == 0) {
lastNameCanSave = false;
} else {
lastNameCanSave = true;
}
enableSave();
});
$("#field-phonefield").change(function(){
if (loadPhone != 0 && $(this).val().length == 0) {
phoneCanSave = false;
} else {
phoneCanSave = true;
}
enableSave();
});
$("#field-emailfield").change(function(){
if (loadEmail != 0 && $(this).val().length == 0) {
emailCanSave = false;
} else {
emailCanSave = true;
}
enableSave();
});
});