Created
October 23, 2012 17:19
-
-
Save kenton/3940171 to your computer and use it in GitHub Desktop.
This file contains 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
.... | |
.... | |
promo_code_requires_logged_in_user: "You must <a href='#' id='promo_code_passenger_details_link' class='register_link'>enter your passenger details</a> or <a href='#' id='promo_code_login_link'>login to your account</a> in order to apply this promo code." |
This file contains 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 del_card_id = false; | |
var spinner = "<img src='/images/shared/blue_spinner.gif' alt='please wait' />"; | |
// cache the last checked email and status | |
var last_email_checked; | |
var last_email_checked_result; | |
// config settings for passenger phone number validation | |
var MIN_PHONE_NUM_LENGTH = 10; | |
var MAX_PHONE_NUM_LENGTH = 15; | |
var VALID_PHONE_NUMBER_FORMAT = /^[\d\s{1}\-()\.]*$/ | |
$(function(){ | |
$('.adjustable_ride_pricing #recalculate_adjustment_btn').live('click',function () { | |
admin_recalculate_total(); | |
}); | |
$('.ui-dialog #save_adjustment_btn').live('click',function () { | |
admin_save_adjusted_prices(); | |
}); | |
if( !$('#reservation_request_submit').is(':disabled') ) | |
$('#reservation_request_submit').addClass('enabled'); | |
cvv_tip(); | |
$('#add_alt_phone_num_btn').click(function(){ | |
$('#add_alt_phone_num_btn').hide(); | |
$('#alt_phone_num_label').css('visibility','visible'); | |
$('#passenger_phone_num_alt').show(); | |
}); | |
// Turns all the drop off input fields to in/active based on if the box is checked | |
$('#reservation_request_dropoff_same_as_pickup').click( function(){ | |
if($('#reservation_request_dropoff_same_as_pickup').is(':checked') ){ | |
//checked same-as | |
deactivate_dropoff_fields(); | |
}else{ | |
activate_dropoff_fields(); | |
} | |
}); | |
if($('#reservation_request_dropoff_same_as_pickup').is(':checked') ){ | |
//checked same-as | |
deactivate_dropoff_fields(); | |
} | |
// on an hourly ride set the drop-off street address to the pickup street address | |
// when the 'Same as pick-up address' is checked | |
$('#pickup_address_street1').change( function(){ | |
if($('#reservation_request_dropoff_same_as_pickup').is(':checked') ) { | |
$('#dropoff_address_street1').val($('#pickup_address_street1').val()); | |
} | |
}); | |
$('table#reservation_request_pricing_summary #orig_rate').click(function () { | |
var origValue = $('table#reservation_request_pricing_summary #orig_rate').html(); | |
$('table#reservation_request_pricing_summary #orig_rate').replaceWith('<input type="text" size="6" maxlength="6" id="new_value" style="width:50px" />'); | |
$('table#reservation_request_pricing_summary #new_value').val(origValue); | |
}); | |
// Wire up ajax | |
// Handles click for the search result vehicles and swaps out the details div. | |
$(".rr_vehicle_list_item").click(function(e) { | |
val=$(e.target).attr('href'); | |
if(val){ | |
// This is the reservation request uuid | |
var rid=$(e.target).attr('rel'); | |
// Find the dimensions of the link and set the spinner div to the right of that | |
var id='#'+$(e.target).attr('id'); | |
var offset=$(id).offset(); | |
var o_width=$(id).outerWidth(); | |
$('#vehicle_profile_spinner').css('top',offset.top); | |
$('#vehicle_profile_spinner').css('left',offset.left + o_width + 10); | |
$('#vehicle_profile_spinner').show(); | |
$("#vehicle_profile_details").load("/search/show_search_result_vehicle_details/"+val,{},function(){ | |
$('#vehicle_profile_spinner').hide(); | |
$(window).scrollTop(0); // forces the page to go back to the top, for big lists of vehicles | |
}); | |
} | |
return false; | |
}); | |
// Handles switching of form elements on the res req page for private charter flight | |
$('#reservation_request_is_private_charter_flight').click(function() { | |
if ($(this).is(':checked')) { | |
$('#tr_airline').hide(); | |
$('#flight_number_note').hide(); | |
$('#tr_terminal').show(); | |
$('#lbl_flight_no').html(rrq_air_flight_tailnumber).append('*'); | |
$('#tr_flight_no').append('<div id="tail_number_note" class="note">Terminal, FBO, Arrival Time</div>'); | |
$('#reservation_request_flight_number').val(''); | |
} else { | |
$('#tr_airline').show(); | |
$('#tr_terminal').hide(); | |
$('#flight_number_note').show(); | |
$('#tail_number_note').remove(); | |
$('#lbl_flight_no').html(rrq_flight_no).append('*'); | |
$('#reservation_request_flight_number').val('Flight Number and Departure City'); | |
} | |
}); | |
if ($('#dropoff_address_street1').val()=='' && $('#dropoff_address_city').val()=='' && $('#dropoff_address_state_province').val()=='' && | |
$('#dropoff_address_postal_code').val()=='' && $('#dropoff_address_country').val()=='') { | |
deactivate_dropoff_fields(); | |
} | |
//Hide passenger_email_text if no email is present (which occurs if you did not hit the CD page or log in) | |
if ($("#passenger_email_text").html() == '') { | |
$('#passenger_email_text').hide(); | |
} | |
$('#edit_reservation_request').submit(function(){ return validate_checkout_form({shield:true}) }); | |
// track 'How It Works' dialog | |
$('.howitworks').click(function(){ _gaq.push(['_trackEvent','reservation-request','how-works-overlay']) }); | |
// TA account logged in as someone else, set to primary passenger | |
if( is_travel_assistant ){ | |
$('.passenger_list').get(0).selectedIndex = 1; | |
$('.passenger_list').change(); | |
// $('#add_new_passenger').hide(); | |
// don't remove the option to create a new passenger in new TA UI | |
// $(".passenger_list option[value='new']").remove(); | |
} | |
$('#passenger_heading').css('display','none'); | |
$('.passenger_list').change(function() { set_passenger(); }); | |
$('#pick_passenger').click(function() { | |
$('#passenger_heading').hide(); | |
$('#label_full_name').html('Primary Passenger'); | |
$('#namefields').hide(); | |
$('.passenger_list').get(0).selectedIndex = 0; | |
$('.passenger_list').show(); | |
$('#add_new_passenger').show(); | |
$('#pick_passenger').hide(); | |
$('#passenger_email').hide(); | |
$('#passenger_email_text').show(); | |
set_passenger(); | |
return false; | |
}); | |
$('#add_new_passenger').click(function() { | |
if( save_pass_vals ){ | |
save_pass_vals = false; // only do it on the first run | |
} | |
else{ | |
$('#passenger_heading').show(); | |
$('#label_full_name').html('Full Name'); | |
$('#user_passenger_id').val(''); | |
$('#passenger_first_name').attr('value',''); | |
$('#passenger_last_name').attr('value',''); | |
$('#passenger_first_name').val('First name'); | |
$('#passenger_last_name').val('Last name'); | |
$('#passenger_email').val('').removeAttr('disabled'); | |
$('#passenger_phone_num').val(''); | |
$('#passenger_phone_num_alt').val(''); | |
$('#passenger_email_text').hide(); | |
$('#passenger_email').show(); | |
} | |
$('#passenger_first_name, #passenger_last_name').addClass('text-input-help'); | |
$('#edit-primary-email').hide(); | |
$('#namefields').show(); | |
$('.passenger_list').hide(); | |
$('#add_new_passenger').hide(); | |
$('#pick_passenger').show(); | |
$('.contact-li:hidden').show('blind','slow'); | |
$('#reservation_request_special_requests').attr('refid','Please provide additional ride details like apartment number, child seat request etc.'); | |
//highlight_phone(); | |
return false; | |
}); | |
//$('#passenger_phone_num').change(function(){highlight_phone()}); | |
$('#edit-primary-email').click(function(){ | |
$('#passenger_email').removeAttr('disabled'); | |
$(this).hide(); | |
return false; | |
}); | |
$('.payment_methods').click(function() { | |
var pmt_method_id = $(this).val(); | |
// hide/unhide the Edit card links | |
$("#payment-info a[class='edit_card']").each(function(i,o) { | |
if ($(this).attr('pmt_method_id')==pmt_method_id) { | |
$(this).show(); | |
} else { | |
$(this).hide(); | |
} | |
}); | |
if (pmt_method_id=='0') { // 0 means new payment method | |
$('#pmt_method_0').load('/my-account/payment_method/new/'+rrid, function(){ | |
update_fields(); | |
cvv_tip(); // need to re-run the tiptip setup since the fields were not there for the initial run | |
bind_billing_address_sameas(); //need to bind adress same as checkbox since fields were not there | |
}); | |
} | |
else { | |
$('#pmt_method_0').html(''); | |
} | |
}); | |
$('#address_country').live('change',function(){ | |
country = $(this).val(); | |
if( country == "US" || country == "CA" ) { | |
$('.ziplabel').addClass('required'); | |
$('.statelabel').addClass('required'); | |
$('#address_state_province').addClass('required'); | |
} | |
else { | |
$('.ziplabel').removeClass('required'); | |
$('.statelabel').removeClass('required'); | |
$('#address_state_province').removeClass('required'); | |
} | |
}); | |
$('.edit_card').live('click', function() { | |
var pmt_method_id = $(this).attr('pmt_method_id'); | |
//$('#pmt_method_'+pmt_method_id).load('/my-account/payment_method/'+pmt_method_id); | |
$('#pmt_method_'+pmt_method_id+' .edit_expir').show(); | |
$(this).hide(); | |
$('#expdate_'+pmt_method_id).hide(); | |
return false; | |
}); | |
$('.edit_card_cancel').live('click',function() { | |
var pmt_method_id = $(this).attr('pmt_method_id'); | |
$('#pmt_method_'+pmt_method_id+' .edit_expir').hide(); | |
$('#edit_card_'+pmt_method_id).show(); | |
$('#expdate_'+pmt_method_id).show(); | |
return false; | |
}); | |
$('.edit_card_save').live('click', function() { | |
var pmt_method_id = $(this).attr('pmt_method_id'); | |
// submit via ajax | |
toolBoxSpinner(); | |
var protocol = 'http://'; | |
if (!is_dev) protocol = 'https://'; | |
var url = protocol+host+'/my-account/payment_method/'+pmt_method_id; | |
var month = $('#saved_payment_method_'+pmt_method_id+'_expiration_month').val(); | |
var year = $('#saved_payment_method_'+pmt_method_id+'_expiration_year').val(); | |
var data = 'payment_method[expiration_month]='+month; | |
data = data + '&payment_method[expiration_year]='+year; | |
data = data + '&_method=PUT'; | |
$.post(url, data, function(r) { | |
toolBoxSpinner_remove(); | |
if (r.status=='success') { | |
$('#pmt_method_'+pmt_method_id+' .edit_expir').hide(); | |
$('#edit_card_'+pmt_method_id).show(); | |
$('#expdate_'+pmt_method_id).show(); | |
var msg = "<span class='msg saved'> Saved!</span>"; | |
$(msg).insertAfter( '#edit_card_'+pmt_method_id ).effect("highlight", {color:"#FEFFAF"}, 4500, function(){ $(this).fadeOut('slow') } ); | |
$('#expdate_'+pmt_method_id).html('exp '+month+'/'+year); | |
} else { | |
var validation_errors = ''; | |
for (i=0; i<r.errors.length; i++) { | |
validation_errors += (r.errors[i].attr + ': ' + r.errors[i].msg + '<br/>'); | |
} | |
$('<div>'+validation_errors+'</div>').insertAfter( '#pmt_method_'+pmt_method_id ).effect("highlight", {color:"#FEFFAF"}, 4500, function(){ $(this).fadeOut('slow') } ); | |
} | |
}, "json"); | |
return false; | |
}); | |
$('#pmt_delete_dialog').dialog({bgiframe:true, autoOpen:false, resizable:false, height:140, modal:true, width:400, | |
buttons: { | |
Cancel: function() { | |
$(this).dialog('close'); | |
}, | |
'Confirm': function() { | |
// submit via ajax | |
$(this).dialog('close'); | |
toolBoxSpinner(); | |
var protocol = 'http://'; | |
if (!is_dev) protocol = 'https://'; | |
var url = protocol+host+'/my-account/payment_method/'+del_card_id+'/destroy' | |
$.post(url, function(r) { | |
toolBoxSpinner_remove(); | |
$('#pmt_method_'+del_card_id+' .edit_expir').hide(); | |
$('#edit_card_'+del_card_id).show(); | |
var msg = "<span class='msg saved'> Deleted!</span>"; | |
var p = $('#card_payment_method_saved_id_'+del_card_id).parent(); | |
p.html(''); | |
$(msg).appendTo( p ).effect("highlight", {color:"#FEFFAF"}, 4500, function(){ $(this).fadeOut('slow') } ); | |
$('#card_payment_method_saved_id_0').trigger('click'); | |
}, "json"); | |
} | |
} | |
}); | |
$('.edit_card_delete').live('click', function() { | |
del_card_id = $(this).attr('pmt_method_id'); | |
var ending_in = $('#ending_'+del_card_id).html(); | |
$('#pmt_delete_dialog_msg').text('Are you sure you want to delete the card ending in '+ending_in+'?'); | |
$('#pmt_delete_dialog').dialog('open'); | |
ui_close_addclass(); | |
return false; | |
}); | |
$('#reservation_request_set_ride_purpose_as_business').change(function() { | |
if ($(this).val()=='false') { | |
$('#out_of_policy_table').hide(); | |
$('.extra_field_spec_form').hide(); | |
} else { | |
$('#out_of_policy_table').show(); | |
$('.extra_field_spec_form').show(); | |
} | |
}); | |
$('.optional_signin, #close_res_signin').click(function(){toggle_signin_link()}); | |
$('#promo_code_passenger_details_link').click(function(){ | |
window.scrollTo(0,0); // scroll to top | |
}); | |
$('#promo_code_validation_message .promo_code_login_link').click(function(){toggle_signin_link()}); | |
$('#user_diff_from_pass').change(function(){ | |
if( this.checked ){ | |
$('.optional_user').show('blind','slow'); | |
$('#user_first_name').val($('#passenger_first_name').val()); | |
$('#user_last_name').val($('#passenger_last_name').val()); | |
$('#user_email').val($('#passenger_email').val()); | |
} | |
else{ | |
$('.optional_user').hide('blind','slow'); | |
$('#user_first_name').val(''); | |
$('#user_last_name').val(''); | |
$('#user_email').val(''); | |
$('#optional_password').val(''); | |
} | |
}); | |
bind_billing_address_sameas(); | |
set_passenger(); | |
//only check corp email if not logged-in | |
//overrides the log-in and reserve buttons | |
if(!authed) check_for_corp_email(); | |
}); | |
// function highlight_phone() { | |
// if( $('#passenger_phone_num').val() == '' ) | |
// $('#passenger_phone_num').addClass('highlight'); | |
// else { | |
// $('#passenger_phone_num').removeClass('highlight'); | |
// $('#passenger_phone_num').removeClass('error-field'); | |
// } | |
// } | |
function toggle_signin_link() { | |
$('.optional_signin').toggle('blind', 300); | |
window.scrollTo(0,0); // scroll to top | |
$('#res_signin').toggle('blind', 500); | |
$('#signin_btn').removeAttr('disabled'); | |
return false; | |
} | |
function validate_checkout_form(options) { | |
var valid = true; | |
// clear out previous errors | |
$('div.error-msg').remove(); | |
$('.error-field').removeClass('error-field'); | |
if( !validateRequiredLabels() ){ | |
valid = false; | |
} | |
if (!validatePhoneNumber()) { | |
valid = false; | |
} | |
if( typeof(passengers) != 'undefined' ) { | |
if( !$('.passenger_list').val() && $('.passenger_list').is(':visible') ){ | |
$('.passenger_list').addClass('error-field'); | |
$('.passenger_list').focus(change_error_text_color); | |
$('<div id="passenger_list_error" class="error-msg">required</div>').insertBefore('.passenger_list'); | |
valid = false; | |
} | |
else $('.passenger_list').removeClass('error-field'); | |
} | |
if( $('#user_diff_from_pass').is(':checked') ){ | |
var p = jQuery.trim($('#optional_password').val()); | |
if( !p || p == '' ){ | |
$('#optional_password').addClass('error-field'); | |
$('#optional_password').focus(change_error_text_color); | |
$('#optional_password').parent().find('div.err-msg').remove(); // remove any previous error messages so we don't get dupes | |
$('<div id="optional_password_error" class="error-msg error-rel">Please enter a password when creating a new user account.</div>').insertAfter('#optional_password'); | |
valid = false; | |
} | |
else if ( p.length < 6 ){ | |
$('#optional_password').addClass('error-field'); | |
$('#optional_password').focus(change_error_text_color); | |
$('#optional_password').parent().find('div.err-msg').remove(); // remove any previous error messages so we don't get dupes | |
$('<div id="optional_password_error" class="error-msg error-rel">Please use at least 6 characters</div>').insertAfter('#optional_password'); | |
valid = false; | |
} | |
else if ( p.length > 40 ){ | |
$('#optional_password').addClass('error-field'); | |
$('#optional_password').focus(change_error_text_color); | |
$('#optional_password').parent().find('div.err-msg').remove(); // remove any previous error messages so we don't get dupes | |
$('<div id="optional_password_error" class="error-msg error-rel">Please use less than 40 characters</div>').insertAfter('#optional_password'); | |
valid = false; | |
} | |
} | |
if ($('#reservation_request_set_ride_purpose_as_business').val()=='true' && !validateExtraFieldSpecFields(2)) { | |
valid = false; | |
} | |
if (valid) { | |
// Remove 'disabled' attribute from the passenger email to make sure the browser sends it | |
$('#passenger_email').removeAttr('disabled'); | |
if( typeof reserving_text == 'undefined' ) | |
reserving = 'Reserving'; | |
else | |
reserving = reserving_text; | |
if( options && options["shield"] != false ) shield('reservation_request_submit', 'cancelreserve', reserving, reserving); | |
return true; | |
} else { | |
if( $('select.error-field, input.error-field').length > 0 ) $('select.error-field, input.error-field')[0].focus(); | |
return false; | |
} | |
} | |
function validatePhoneNumber() { | |
var phoneNum = jQuery.trim($('#passenger_phone_num').val()); | |
var phoneNumLength = phoneNum.replace(/\D/g, '').length; | |
var validPhoneNumberFormat = VALID_PHONE_NUMBER_FORMAT.test(phoneNum); | |
var msg = ""; | |
var isValid = true; | |
rmErrMsg('#passenger_phone_num', 'passenger_phone_num_error'); | |
if (!validPhoneNumberFormat) { | |
msg = invalid_phone_num_format_msg; | |
isValid = false; | |
} | |
if ((phoneNum == '') || (phoneNumLength > MAX_PHONE_NUM_LENGTH) || (phoneNumLength < MIN_PHONE_NUM_LENGTH)) { | |
if ((msg == "") && (isValid == true)) { | |
msg = invalid_phone_num_length_msg; | |
isValid = false; | |
} | |
} | |
if (isValid) { | |
rmErrMsg('#passenger_phone_num', 'passenger_phone_num_error'); | |
return isValid; | |
} else { | |
addCustomErrMsg('#passenger_phone_num', 'passenger_phone_num_error', msg); | |
//console.log(msg); | |
return isValid; | |
} | |
} | |
function set_passenger(){ | |
if( typeof(passengers) == 'undefined' ) return false; | |
if( $('.passenger_list').val() ) { | |
$('.contact-li:hidden').show('blind','slow'); | |
} | |
else { | |
$('.contact-li:visible').hide('blind'); | |
} | |
if( $('.passenger_list').val() == 'new' ) { | |
$('#add_new_passenger').trigger('click'); | |
$('#passenger_email').removeAttr('disabled'); | |
$('#passenger_email').show(); | |
$('#edit-primary-email').hide(); | |
} | |
else { | |
if( !$('.passenger_list').val() ) return false; | |
// $('.passenger_list').removeClass('error-field'); | |
var p = passengers.list[$('.passenger_list').val()]; | |
$('#user_passenger_id').val(p.id); | |
$('#passenger_first_name').val(p.first_name); | |
$('#passenger_last_name').val(p.last_name); | |
$('#passenger_email_text').text(p.email); | |
$('#passenger_email').val(p.email); | |
$('#passenger_phone_num').val(p.phone_num); | |
$('#passenger_phone_num_alt').val(p.phone_num_alt); | |
$('#passenger_email').hide(); | |
if (p.travel_preferences && p.travel_preferences!='') { | |
$('#reservation_request_special_requests').val(p.travel_preferences).removeClass('text-input-help'); | |
update_fields(); | |
} | |
if( p.id == myPassId && $("#bizuserfields").is(':hidden') ) { | |
$("#bizuserfields").show('blind','slow'); | |
} | |
else if( p.id != myPassId && $("#bizuserfields").is(':visible') ){ | |
$("#bizuserfields").hide('blind','slow'); | |
} | |
if( p.id == myPassId && authed ){ | |
$('#passenger_email').attr('disabled','disabled'); | |
$('#edit-primary-email').show(); | |
} | |
else { | |
$('#passenger_email').removeAttr('disabled'); | |
$('#edit-primary-email').hide(); | |
} | |
//highlight_phone(); | |
} | |
} | |
function deactivate_dropoff_fields() { | |
//copy address from pick-up address | |
$('#dropoff_address_description').val( $('#pickup_address_description').val()); | |
$('#dropoff_address_street1').val( $('#pickup_address_street1').val()); | |
$('#dropoff_address_city').val( $('#pickup_address_city').html()); | |
$('#dropoff_address_state_province').val( $('#pickup_address_state_province').html()); | |
$('#dropoff_address_postal_code').val( $('#pickup_address_postal_code').html()); | |
$('#dropoff_address_country').val( $('#pickup_address_country').html()); | |
$('#dropoff_address_description').attr("disabled", "disabled"); | |
$('#dropoff_address_street1').attr("disabled", "disabled"); | |
$('#dropoff_address_street1').removeClass("required"); | |
$('#dropoff_address_city').attr("disabled", "disabled"); | |
$('#dropoff_address_city').removeClass("required"); | |
$('#dropoff_address_state_province').attr("disabled", "disabled"); | |
$('#dropoff_address_state_province').removeClass("required"); | |
$('#dropoff_address_postal_code').attr("disabled", "disabled"); | |
$('#dropoff_address_postal_code').removeClass("required"); | |
$('#dropoff_address_country').attr("disabled", "disabled"); | |
} | |
function activate_dropoff_fields() { | |
// activate | |
$('#dropoff_address_description').removeAttr("disabled"); | |
$('#dropoff_address_street1').removeAttr("disabled"); | |
$('#dropoff_address_street1').addClass("required"); | |
$('#dropoff_address_city').removeAttr("disabled"); | |
$('#dropoff_address_city').addClass("required"); | |
$('#dropoff_address_state_province').removeAttr("disabled"); | |
$('#dropoff_address_state_province').addClass("required"); | |
$('#dropoff_address_postal_code').removeAttr("disabled"); | |
$('#dropoff_address_postal_code').addClass("required"); | |
$('#dropoff_address_country').removeAttr("disabled"); | |
} | |
function bind_billing_address_sameas(){ | |
$('#billing_address_sameas').bind('click', function(){ | |
if( $(this).is(':checked') ) { | |
if( $('#pickup_address_street1').length ) { | |
$('#card_payment_method_address_street1').val( $('#pickup_address_street1').val() ); | |
$('#address_postal_code').val( $('#pickup_address_postal_code').val() ); | |
$('#address_city').val( $('#pickup_address_city').val() ); | |
$('#address_state_province').val( $('#pickup_address_state_province').val() ); | |
} | |
else { | |
$('#card_payment_method_address_street1').val( $('#dropoff_address_street1').val() ); | |
$('#address_postal_code').val( $('#dropoff_address_postal_code').val() ); | |
$('#address_city').val( $('#dropoff_address_city').val() ); | |
$('#address_state_province').val( $('#dropoff_address_state_province').val() ); | |
} | |
//create hidden cloned input fields because disabled fields are not submitted with an HTML form submit | |
$('#card_payment_method_address_street1').clone().insertAfter('#card_payment_method_address_street1').attr("id", "card_payment_method_address_street1_clone").hide(); | |
$('#address_postal_code').clone().insertAfter('#address_postal_code').attr("id", "address_postal_code_clone").hide(); | |
$('#address_city').clone().insertAfter('#address_city').attr("id", "address_city_clone").hide(); | |
$('#address_state_province').clone().insertAfter('#address_state_province').attr("id", "address_state_province_clone").hide(); | |
$('#address_country').clone().insertAfter('#address_country').attr("id", "address_country_clone").hide(); | |
$('#card_payment_method_address_street1').attr("disabled", "disabled"); | |
$('#address_postal_code').attr("disabled", "disabled"); | |
$('#address_city').attr("disabled", "disabled"); | |
$('#address_state_province').attr("disabled", "disabled"); | |
$('#address_country').attr("disabled", "disabled"); | |
} | |
else { | |
$('#card_payment_method_address_street1').removeAttr("disabled"); | |
$('#address_postal_code').removeAttr("disabled"); | |
$('#address_city').removeAttr("disabled"); | |
$('#address_state_province').removeAttr("disabled"); | |
$('#address_country').removeAttr("disabled"); | |
//remove hidden cloned input fields because disabled fields are not submitted with an HTML form submit | |
$('#card_payment_method_address_street1_clone').remove(); | |
$('#address_postal_code_clone').remove(); | |
$('#address_city_clone').remove(); | |
$('#address_state_province_clone').remove(); | |
$('#address_country_clone').remove(); | |
} | |
$('#address_postal_code').trigger('keyup'); | |
}); | |
} | |
function cvv_tip() { | |
$('.cvv_tiptipb').each(function(){ | |
$(this).attr('title', $(this).find('div.tip_content').html() ); | |
}); | |
$(".cvv_tiptipb").tipTip({hold:2000, extraClass:'big', maxWidth:'630px', fixedWidth:'630px'}); | |
} | |
//these will only be called on un-authed users on reservation request page. | |
function check_for_corp_email(){ | |
$('#btn_login_corp_diag').click(function(){ btn_login_corp_account_holder_dialog() }); | |
$('#btn_cancel_corp_diag').click(function(){ btn_cancel_corp_account_holder_dialog() }); | |
function btn_login_corp_account_holder_dialog() { | |
$('#corp_account_holder_dialog').dialog('close'); | |
signin_and_corp_research(); | |
} | |
function btn_cancel_corp_account_holder_dialog() { | |
$('#corp_account_holder_dialog').dialog('close'); | |
//clear out old login info | |
$('#res_signin #email').val(""); | |
$('#res_signin #password').val(""); | |
var div_to_focus = $('#corp_account_holder_dialog #div_to_focus').val(); | |
$(div_to_focus).focus(); | |
} | |
// displays the dialog, or else attemps to log-in the user or reserve if they had clicked reserve button | |
function open_corp_account_dialog_if_true(open_dialog,action){ | |
if(open_dialog == 'true' || open_dialog == true ){ | |
$('#signin_btn').removeAttr('disabled'); | |
$('#signin_btn').attr('value','Sign-in'); | |
$('#reservation_request_submit').addClass('enabled'); | |
$('#reservation_request_submit').removeAttr('disabled'); | |
$('#reservation_request_submit').attr('value','Reserve'); | |
$('#searchspinner').remove(); | |
if(action!='signin') { | |
$('#btn_login_corp_diag').html(biz_login_btn_txt); | |
$('#corp_account_holder_dialog_msg').show(); // swap the text of the message | |
$('#corp_account_holder_dialog_signin_msg').hide(); | |
} else { | |
$('#btn_login_corp_diag').html(biz_login_btn_txt_alt); | |
$('#corp_account_holder_dialog_msg').hide(); // swap the text of the message back | |
$('#corp_account_holder_dialog_signin_msg').show(); | |
} | |
$('#corp_account_holder_dialog').dialog('open'); | |
} else { | |
if(action=='signin'){ | |
signin_and_corp_research(); | |
} else { | |
// double-check the form is valid then unbind any handlers so we don't get caught in a loop, then submit | |
if( action=='submit' && validate_checkout_form() ){ | |
interval = shield('reservation_request_submit', null, 'Reserving', 'Reserving'); | |
$('#edit_reservation_request').unbind(); | |
clear_all_text_default_fields(); //need to manually call clear all default text because all form event handles were unbind. | |
$('#edit_reservation_request').submit(); | |
} | |
} | |
} | |
} | |
// Reg Removal: Need to overide the global sign-in link in the nav on registration checkout page!! | |
$('#bannerNav a.signin').attr("href", "javascript:void(0);").click(function(){toggle_signin_link()}); | |
function check_for_corp_acct(action){ | |
var email_field = '#user_email'; | |
var email = jQuery.trim($(email_field).val()); | |
// if user field is blank, use the passenger email instead | |
if( email == '' ){ | |
email_field = '#passenger_email'; | |
email = jQuery.trim($(email_field).val()); | |
} | |
// if email is still blank, then stop | |
if( action == 'submit' ){ | |
// a second validation is run later after the corp check is done, but having this one here | |
// without blocking anything based on outcome still gives the user some visual feedback if there are fields | |
// to fix while the corp account is getting checked | |
validate_checkout_form(); | |
} | |
if( email == '' ) return false; | |
var optional_password = jQuery.trim($('#optional_password').val()); | |
// if the email we checked last is the same now, no need to re-run the ajax call | |
if( email == last_email_checked ){ | |
open_corp_account_dialog_if_true(last_email_checked_result, action); | |
} | |
else { | |
$('#searchspinner').remove(); // remove any previous spinners, just in case | |
$('<img id="searchspinner" src="/images/shared/blue_spinner.gif">').insertBefore(email_field); | |
$.getJSON('/users/corp_account_holder', {"user_email": email, "format": "json"} , function(data) { | |
$('#searchspinner').remove(); | |
if(typeof(interval) != 'undefined' ) clearInterval(interval); | |
$('#res_signin #email').val(email); | |
$('#res_signin #password').val(optional_password); | |
$('#corp_account_holder_dialog #div_to_focus').val(email_field); | |
last_email_checked = email; | |
last_email_checked_result = data.result; | |
open_corp_account_dialog_if_true(data.result == 'true', action); | |
}); | |
} | |
return false; // alwasy return false because open_corp_account_dialog_if_true will unbind handlers and resubmit | |
} | |
function check_for_registered_user(action){ | |
var email_field = '#user_email'; | |
var email = jQuery.trim($(email_field).val()); | |
// if email is still blank, then stop | |
if( action == 'submit' ){ | |
// a second validation is run later after the corp check is done, but having this one here | |
// without blocking anything based on outcome still gives the user some visual feedback if there are fields | |
// to fix while the corp account is getting checked | |
validate_checkout_form(); | |
} | |
if( email == '' ) return false; | |
var optional_password = jQuery.trim($('#optional_password').val()); | |
// if the email we checked last is the same now, no need to re-run the ajax call | |
if( email == last_email_checked ){ | |
} else { | |
$('#searchspinner').remove(); // remove any previous spinners, just in case | |
$('<img id="searchspinner" src="/images/shared/blue_spinner.gif">').insertBefore(email_field); | |
$('.savepw div.msg').slideUp('fast'); | |
$.getJSON('/users/registered_user', {"user_email": email, "format": "json"} , function(data) { | |
$('#searchspinner').remove(); | |
if(typeof(interval) != 'undefined' ) clearInterval(interval); | |
last_email_checked = email; | |
last_email_checked_result = data.result; | |
if(data.result == 'true') { | |
$('.savepw div.msg').show(); | |
$('.savepw div.msg .taken').show(); | |
$('.optional_user #user_email').addClass('error-field'); | |
$('.optional_user #user_email').focus(change_error_text_color); | |
} | |
else { | |
$('.optional_user #user_email').removeClass('error-field'); | |
} | |
}); | |
} | |
return false; // alwasy return false because open_corp_account_dialog_if_true will unbind handlers and resubmit | |
} | |
//Reg Removal: check corp email before reservation submit & when fields are updated | |
$('#edit_reservation_request').unbind(); | |
$('#edit_reservation_request').submit(function(){ return check_for_corp_acct('submit') }); | |
$('.optional_user #user_email').change(function(){check_for_registered_user(false)}); | |
//For the #passenger_email, which is the first email field on the page, we need to check for a corp account | |
$('#passenger_email').change(function(){check_for_corp_acct(false)}); | |
/* | |
* ----------------------------------------------- | |
* SIGN-IN LOGIC | |
* ----------------------------------------------- | |
*/ | |
// Reg Removal: check corp email before login | |
function signin_validate_and_check_corp(){ | |
$('#searchspinner').remove(); | |
var e = jQuery.trim($('#res_signin #email').val()); | |
var p = $('#res_signin #password').val(); | |
if (e=='') { addErrMsg( '#email', 'emerror' ); } | |
else { rmErrMsg( '#email', 'emerror' ); } | |
if (p.length<6) { addErrMsg( '#res_signin #password', 'pwerror' ); } | |
else { rmErrMsg( '#res_signin #password', 'pwerror' ); } | |
if (e!='' && p.length > 5) { | |
interval = shield('signin_btn', null, 'Working', 'Working'); | |
// if we've already checked the email AND it is a corp, then we know | |
// the user wanted to sign in as a corp, so we can skip straight to part 2 | |
if( e == last_email_checked && last_email_checked_result == 'true' ){ | |
signin_and_corp_research(); | |
} | |
else{ | |
$.getJSON('/users/corp_account_holder', {"user_email": e, "format": "json"} , function(data) { | |
$('#corp_account_holder_dialog #div_to_focus').val('#res_signin #email') | |
clearInterval(interval); | |
open_corp_account_dialog_if_true(data.result == 'true', 'signin'); | |
}); | |
} | |
} | |
return false; | |
} | |
$('#signin_form').unbind(); | |
$('.signin_form').unbind(); | |
$('#signin_form').submit( function(e) { | |
e.preventDefault(); | |
signin_validate_and_check_corp(); | |
return false; | |
}); | |
// At this point, corp user wants to do a search under the corp account | |
// submits the special form that lives inside corp_account_holder_dialog div inside reservation_request.html.erb. | |
// expects /users/login to return a '/search/corprerun/:uuid' URL to be redirected | |
function signin_and_corp_research(){ | |
//show the login area on top of res req page | |
if( $('#res_signin').is(':hidden') ) { | |
$('.optional_signin').hide(); | |
$('#res_signin').show(); | |
} | |
//check the email/password in login area | |
var e = jQuery.trim($('#res_signin #email').val()); | |
if (e=='') { | |
addErrMsg( '#res_signin #email', 'emerror' ); | |
} else { rmErrMsg( '#res_signin #email', 'emerror' ); } | |
var p = jQuery.trim($('#res_signin #password').val()); | |
if (p=='') { addErrMsg( '#res_signin #password', 'pwerror' ); } | |
else { rmErrMsg( '#res_signin #password', 'pwerror' ); } | |
$('#res_signin #email').focus(); | |
$('#signin_and_corp_search_form #corp_email').val(e); | |
$('#signin_and_corp_search_form #corp_password').val(p); | |
if (e!='' && p!='') { | |
var form = $('#signin_and_corp_search_form').serialize(); | |
interval = shield('signin_btn', null, 'Working', 'Working'); | |
$.post( '/users/login', $('#signin_and_corp_search_form').serialize(), function(d) { | |
var resp = eval('('+d+')'); | |
if (resp.result=='success') { | |
parent.window.location.href = resp.redirect_url; | |
} else { | |
clearInterval(interval); $('#searchspinner').remove(); | |
$('#signin_btn').removeAttr('disabled'); | |
$('#signin_btn').attr('value','Sign-in'); | |
$('#errors_signin').html(resp.error_text); | |
$('#errors_signin').fadeIn('fast'); | |
} | |
}); | |
} | |
return false; | |
} | |
$('#corp_account_holder_dialog').dialog({autoOpen:false, resizable:true, height:220, modal:true, width:500 }); | |
} | |
function update_reservation_price(uuid, is_tc, cancel_type, spinspot, spotafter, apply_promo_code){ | |
//console.log("apply_promo_code value: " + apply_promo_code); | |
var stops = 0; | |
var meetinside = 0; | |
var return_date = false; | |
var return_pickup_time = 0; | |
var return_num_stops = 0; | |
var return_meetinside = 0; | |
var promo_code_name = null; | |
var apply_promo_code = apply_promo_code || false | |
var user_first_name = null; | |
var user_last_name = null; | |
var user_phone_num = null; | |
var user_email = null; | |
if( $('#ride_pricing_number_of_stops').length > 0 ) stops = $('#ride_pricing_number_of_stops').val(); | |
if( $('#ride_pricing_meet_inside').length > 0 ) meetinside = $('#ride_pricing_meet_inside').val(); | |
if( $('#return_date').length > 0 && $('#return_date').val() ){ | |
return_date = $('#return_date').val(); | |
return_pickup_time = $('#return_pickup_time').val(); | |
if( $('#return_number_of_stops').length > 0 ) return_num_stops = $('#return_number_of_stops').val(); | |
if( $('#return_ride_pricing_meet_inside').length > 0 ) return_meetinside = $('#return_ride_pricing_meet_inside').val(); | |
} | |
if( $('#promo_code_name').length > 0 ) promo_code_name = $('#promo_code_name').val(); | |
// get the passenger info for checking promo code per_user_limit if passenger info is filled in | |
if( $('#passenger_first_name').length > 0 ) user_first_name = $('#passenger_first_name').val(); | |
if( $('#passenger_last_name').length > 0 ) user_last_name = $('#passenger_last_name').val(); | |
if( $('#passenger_phone_num').length > 0 ) user_phone_num = $('#passenger_phone_num').val(); | |
if( $('#passenger_email').length > 0 ) user_email = $('#passenger_email').val(); | |
var post_data = { 'ride_pricing[number_of_stops]': stops, | |
'ride_pricing[meet_inside]': meetinside, | |
'return[date]': return_date, | |
'return[pickup_time]': return_pickup_time, | |
'return[number_of_stops]': return_num_stops, | |
'return[meet_inside]': return_meetinside, | |
'promo_code[name]': promo_code_name, | |
'promo_code[should_be_applied]': apply_promo_code, | |
'user[first_name]': user_first_name, | |
'user[last_name]': user_last_name, | |
'user[phone_num]': user_phone_num, | |
'user[email]': user_email | |
}; | |
$("span.msg").remove(); | |
if( spotafter ) | |
$("<span class='msg'> "+spinner+"</span>").insertAfter( spinspot ); | |
else | |
$("<span class='msg'> "+spinner+"</span>").appendTo( spinspot ); | |
$.ajax({ | |
type: "POST", | |
dataType: "json", | |
url: '/reservation_request/'+uuid+'/recalc_price', | |
data: post_data, | |
success: function(d, ts){ | |
$("span.msg").remove(); | |
// update total for the stops | |
$('#stops_to').html("= $"+d.additional_stops_amt); | |
//$('#stops_from').html(d.stops_from); // return trip: not used for now | |
// update the grand total (x3) | |
// everywhere that needs an update should have a class of 'gt' | |
$('.gt, .total .right').html("<span class='grand_total'>"+format_currency(d.grand_total)+"</span>"); | |
// update the amount due now (x6) | |
$('.duenow').html(format_currency(d.initial_deposit_charge_amt)); | |
// update amount due @ service time (x3) | |
if (is_tc) | |
$('.duelater').html(format_currency(d.grand_total)); | |
else | |
$('.duelater').html(format_currency(d.balance_due_amt)); | |
// update service fee amount | |
$('.servicefeerow .right').html(format_currency(d.service_fees_rollup)); | |
// add line item for stops in right column | |
$('.stopsrow').show(); | |
$('.stopsrow .right').html(format_currency(d.additional_stops_amt)); | |
var numstops = parseInt(d.number_of_stops); | |
if( numstops <= 0 ){ $('.stopsrow').hide(); } | |
else { | |
$('.stopsrow .ns').html(numstops); | |
} | |
// TODO: add a line item for meet inside fee in right column | |
$('.meetrow').show(); | |
$('.meetrow .right').html(format_currency(d.meet_inside_amt)); | |
if( d.has_meet_inside != true ) $('.meetrow').hide(); | |
// Update base rate when a return trip is booked | |
$('.base_rate .right').html(format_currency(d.base_amt)); | |
// Update tax amt | |
$('.tax_amt .right').html(format_currency(d.tax_amt)); | |
$('.taxes_surcharges_rollup .right').html(format_currency(d.taxes_surcharges_rollup)); | |
var cancel_charge = is_tc ? d.grand_total : d.balance_due_amt; | |
if (cancel_type == 2) // 50% of balance due | |
cancel_charge = d.balance_due_amt * 0.5; | |
$('.cancel_charge').html(format_currency(cancel_charge)); | |
if( $('.adjustable_ride_pricing').length > 0 ) admin_recalculate_total(); | |
// show and update promo_code_discount row | |
if (d.promo_discount_amt > 0) { | |
$('.promo_code_discount').show(); | |
// if it's a flat discount, don't show a percentage in the row | |
if (d.promo_discount_flat_amt != null) { | |
$('.promo_code_discount .left').html("Promo Discount"); | |
} | |
// if it's a percentage discount, show the percentage discount in the row | |
else if (d.promo_discount_pct != null) { | |
$('.promo_code_discount .left').html("Promo Discount (" + d.promo_discount_pct + "%)"); | |
} | |
$('.promo_code_discount .center').html("="); | |
// show the dollar amount of the discount | |
$('.promo_code_discount .right .inner').html(format_currency(d.promo_discount_amt)); | |
} | |
if (d.promo_discount_amt <= 0) { | |
$('.promo_code_discount').hide(); | |
} | |
// show promo discount validation message | |
if (d.promo_code_validation_message != null) { | |
$('#promo_code_validation_message .content').html(d.promo_code_validation_message); | |
} | |
} | |
}); | |
} | |
function goToByScroll(id){ | |
$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow'); | |
} | |
$('#promo_code_login_link').click(function(){ | |
goToByScroll('container'); | |
toggle_signin_link(); | |
}); | |
$(window).unload(function() { | |
$('#reservation_request_submit').removeAttr('disabled'); | |
$('#reservation_request_submit').attr('value','Reserve'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment