KW Real Estate Planner - Individual Membership

KW Real Estate Planner - Individual Membership

/** * ======================================================================================================================================== * CUSTOM.JS * * Custom JS to be copied into the Chargify custom JS field. * * NOTE: For this script to work properly you must create custom fields in Chargify, then enable them on the Public Signup Page where this * script is used. * * CUSTOM FIELDS: 'kwuid', 'associate-id' * ======================================================================================================================================== */ // Move the Contact Information fields above Billing Information function moveContactInformation() { 'use strict' //// Move contact info div directly below the billing total //$('#signup_form').detach().insertAfter('#summary') //// Move the Contact Information header above the contact info div //$('h2').filter(function() { // return $(this).text() === 'Contact Information:' //}).detach().insertBefore('#signup_form') } // Create HTML structure function createStructure() { 'use strict' // The HTML structure var htmlStructure = ' ' + '
' + '
' + '

* Are you a KW associate?

' + '



' + '
' + ' ' + '
' // Add HTML structure before contact info box $('.form__section--coupon').before(htmlStructure) } // Initialize DataTables function initDataTables() { 'use strict' $('#kw-data-table').dataTable({ 'iDisplayLength': 5, 'bServerSide': true, 'sAjaxSource': '//etouchesws.kw.com/v2/ws.php', 'aoColumns': [{ 'mData': 'name', 'bSearchable': true, 'bSortable': false }, { 'mData': 'office_city', 'bSearchable': false, 'bSortable': false }, { 'mData': 'office_state_prov', 'bSearchable': false, 'bSortable': false }, { 'aTargets': [4], 'mData': null, 'sClass': 'share', 'bSearchable': false, 'bSortable': false, 'mRender': function(data, type, full) { // Render the select button // Create the element and append data attributes var kwSelectBtn = $('
').append($('').attr('href', '#').addClass('kw-btn-select').text('Select').attr({ 'data-kwuid': encodeURI(full.kw_uid), 'data-associate-id': encodeURI(full.person_id), 'data-first-name': encodeURI(full.first_name), 'data-last-name': encodeURI(full.last_name), })) // Return the select button HTML return kwSelectBtn.html() } } ], 'oLanguage': { 'sProcessing': 'Wait please...', 'sZeroRecords': 'No users found.', 'sInfo': 'Users from _START_ to _END_ of _TOTAL_ total', 'sInfoEmpty': 'Users from 0 to 0 of 0 total', 'sInfoFiltered': '(filtered from _MAX_ total)', 'sInfoPostFix': '', 'sSearch': '', 'sUrl': '', 'oPaginate': { 'sFirst': '<<', 'sLast': '>>', 'sNext': '>', 'sPrevious': '<' } } }) // Set placeholder text for search input $('#kw-data-table_filter input').attr('placeholder', 'Enter your first and last name here.') } // Hide the selected metafield inputs, if everything is hidden then hide the entire block function hideInputRows(inputsArray) { 'use strict' // Hide rows of passed inputs $.each(inputsArray, function(index, value) { value.closest('.row').attr('hidden', '') }) // If all metafield rows are hidden, hide block if ($('.metafield_configuration .row:not([hidden])').length <= 0) { $('.metafield_configuration').attr('hidden', '') $('.metafield_configuration').prev('h2').attr('hidden', '') } } // On jQuery $(document).ready(function() { 'use strict' // Find inputs based on label text var kwuidInput = $('#' + $('.metafield_configuration label').filter(function() { return $(this).text() === 'kwuid' }).attr('for')) var associateInput = $('#' + $('.metafield_configuration label').filter(function() { return $(this).text() === 'associate-id' }).attr('for')) // Hide these input rows hideInputRows([kwuidInput, associateInput, $('#subscription_customer_attributes_organization')]) // Load DataTables CSS $('', { rel: 'stylesheet', type: 'text/css', href: '//cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css' }).appendTo('head') // Load Cardswipe JS // https://github.com/CarlRaymond/jquery.cardswipe $.getScript('//s3-us-west-2.amazonaws.com/kw-sites/static/cardswipe/dist/jquery.cardswipe.min.js', function() { // Called on a successful scan, where one of the parsers recognizes the card data. var success = function(data) { // Populate payment fields from card data $('#subscription_payment_profile_attributes_first_name').val(data.firstName) $('#subscription_payment_profile_attributes_last_name').val(data.lastName) $('#subscription_payment_profile_attributes_full_number').val(data.account) // Set expiration month, strip leading 0 if there is one $('#subscription_payment_profile_attributes_expiration_month').val(data.expMonth.replace(/^0+/, '')) // Set expiration year, add starting '20--' $('#subscription_payment_profile_attributes_expiration_year').val('20' + data.expYear) } // Card reader failed var error = function() { alert('Card failed to read. Please try again or type in card number.') } // Initialize the card reader plugin $.cardswipe({ firstLineOnly: true, success: success, parsers: ['visa', 'mastercard', 'amex', 'generic'], error: error }) }) // Load DataTables JS $.getScript('//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js', function() { // When DataTables has loaded // Move Contact Information above Billing Information moveContactInformation() // Create the structure createStructure() // Create DataTable initDataTables() // Hide the DataTable when search input is empty $('#kw-data-table_filter input').on('input', function() { if ($(this).val()) { $('#kw-data-table').removeAttr('hidden') $('#kw-data-table_paginate').removeAttr('hidden') } else { $('#kw-data-table').attr('hidden', '') $('#kw-data-table_paginate').attr('hidden', '') } }) $('#kw-data-table_filter input').trigger('input') // When select button is clicked, populate information $('#kw-data-table').on('click', '.kw-btn-select', function(event) { event.preventDefault() // Set values of inputs kwuidInput.val(decodeURI($(this).attr('data-kwuid'))) associateInput.val(decodeURI($(this).attr('data-associate-id'))) $('#subscription_customer_attributes_first_name').val(decodeURI($(this).attr('data-first-name'))) $('#subscription_customer_attributes_last_name').val(decodeURI($(this).attr('data-last-name'))) }) // Defaults $('#contact_info').attr('hidden', '') $('#subscription_customer_attributes_first_name').attr('readonly', '') $('#subscription_customer_attributes_last_name').attr('readonly', '') // Handle is KW toggle $('input[name="is-kw"]').on('change', function(event, clearInputs) { clearInputs = typeof clearInputs !== 'undefined' ? clearInputs : true // On change, show contact info forms $('#contact_info').removeAttr('hidden') // Clear all inputs if (clearInputs) { kwuidInput.val('') associateInput.val('') $('#subscription_customer_attributes_first_name').val('') $('#subscription_customer_attributes_last_name').val('') $('#subscription_customer_attributes_phone').val('') } // Get is KW status var isKW = $(this).val() if (isKW === 'yes') { // Is KW member, show search form and disable name fields $('#kw-data-table').closest('.row').removeAttr('hidden') $('#subscription_customer_attributes_first_name').attr('readonly', '') $('#subscription_customer_attributes_last_name').attr('readonly', '') } else { // Is not a KW member, hide search form and enable name fields $('#kw-data-table').closest('.row').attr('hidden', '') $('#subscription_customer_attributes_first_name').removeAttr('readonly') $('#subscription_customer_attributes_last_name').removeAttr('readonly') } }) // Set defaults, if kwuid is already set we know they're a KW member, if other inputs are set but kwuid is not we know they're not a KW member if (kwuidInput.val()) { $('#is-kw-yes').attr('checked', '') $('#is-kw-yes').trigger('change', [false]) } else if (!kwuidInput.val() && ($('#subscription_customer_attributes_first_name').val() || $('#subscription_customer_attributes_last_name').val() || $('#subscription_customer_attributes_email').val())) { $('#is-kw-no').attr('checked', '') $('#is-kw-no').trigger('change', [false]) } }) }) $(document).ready(function() { var customLabel1 = $("label[for='metafield_15122']"); customLabel1.text("* " + customLabel1.text()); }); var customobj1 = $("#metafield_15122"); var form = $("#hosted-payment-form"); var submitbtn = $("#subscription_submit") submitbtn.click(function() { if (customobj1.val() === "") { customobj1.addClass("field-error"); return false; } }); form.change(function() { if (customobj1.val() != "") { customobj1.removeClass("field-error"); submitbtn.click(function() { return true; }); } else { return false; } }); $(document).ready(function() { var customLabel2 = $("label[for='metafield_15123']"); customLabel2.text("* " + customLabel2.text()); }); var customobj2 = $("#metafield_15123"); var form = $("#hosted-payment-form"); var submitbtn = $("#subscription_submit") submitbtn.click(function() { if (customobj2.val() === "") { customobj2.addClass("field-error"); return false; } }); form.change(function() { if (customobj2.val() != "") { customobj2.removeClass("field-error"); submitbtn.click(function() { return true; }); } else { return false; } }); $(document).ready(function() { var customLabel3 = $("label[for='metafield_15117']"); customLabel3.text("* " + customLabel3.text()); }); var customobj3 = $("#metafield_15117"); var form = $("#hosted-payment-form"); var submitbtn = $("#subscription_submit") submitbtn.click(function() { if (customobj3.val() === "") { customobj3.addClass("field-error"); return false; } }); form.change(function() { if (customobj3.val() != "") { customobj3.removeClass("field-error"); submitbtn.click(function() { return true; }); } else { return false; } }); //]]]]> //]]>