// Putting these functions directly in template so they are available for standalone forms
function useAmountOther() {
var priceset = 0;
for( i=0; i < document.Main.elements.length; i++ ) {
element = document.Main.elements[i];
if ( element.type == 'radio' && element.name == priceset ) {
if (element.value == '0' ) {
element.click();
}
else {
element.checked = false;
}
}
}
}
function clearAmountOther() {
var priceset = 0
if( priceset ){
cj(priceset).val('');
cj(priceset).blur();
}
if (document.Main.amount_other == null) return; // other_amt field not present; do nothing
document.Main.amount_other.value = "";
}
You are completing this form on behalf of someone else. Please enter their details.
var thousandMarker = ',';
var separator = '.';
var symbol = '$';
var optionSep = '|';
// Recalculate the total fees based on user selection
cj("#priceset [price]").each(function () {
var elementType = cj(this).attr('type');
if (this.tagName == 'SELECT') {
elementType = 'select-one';
}
switch(elementType) {
case 'checkbox':
cj(this).click(function(){
calculateCheckboxLineItemValue(this);
display(calculateTotalFee());
});
calculateCheckboxLineItemValue(this);
break;
case 'radio':
cj(this).click( function(){
calculateRadioLineItemValue(this);
display(calculateTotalFee());
});
calculateRadioLineItemValue(this);
break;
case 'text':
cj(this).bind( 'keyup', function() {
calculateText(this);
}).bind( 'blur' , function() {
calculateText(this);
});
//default calculation of element.
calculateText(this);
break;
case 'select-one':
calculateSelectLineItemValue(this);
cj(this).change(function() {
calculateSelectLineItemValue(this);
display(calculateTotalFee());
});
break;
}
display(calculateTotalFee());
});
/**
* Calculate the value of the line item for a radio value.
*/
function calculateCheckboxLineItemValue(priceElement) {
eval( 'var option = ' + cj(priceElement).attr('price') ) ;
optionPart = option[1].split(optionSep);
price = parseFloat(0);
if (cj(priceElement).prop('checked')) {
price = parseFloat(optionPart[0]);
}
cj(priceElement).data('line_raw_total', price);
}
/**
* Calculate the value of the line item for a radio value.
*/
function calculateRadioLineItemValue(priceElement) {
eval( 'var option = ' + cj(priceElement).attr('price') );
optionPart = option[1].split(optionSep);
var lineTotal = parseFloat(optionPart[0]);
cj(priceElement).data('line_raw_total', lineTotal);
var radionGroupName = cj(priceElement).attr("name");
// Reset all unchecked options to having a data value of 0.
cj('input[name=' + radionGroupName + ']:radio:unchecked').each(
function () {
cj(this).data('line_raw_total', 0);
}
);
}
/**
* Calculate the value of the line item for a select value.
*/
function calculateSelectLineItemValue(priceElement) {
eval( 'var selectedText = ' + cj(priceElement).attr('price') );
var price = parseFloat('0');
var option = cj(priceElement).val();
if (option) {
optionPart = selectedText[option].split(optionSep);
price = parseFloat(optionPart[0]);
}
cj(priceElement).data('line_raw_total', price);
}
/**
* Calculate the value of the line item for a text box.
*/
function calculateText(priceElement) {
//CRM-16034 - comma acts as decimal in price set text pricing
//CRM-19937 - dollar sign easy mistake to make by users.
var textval = parseFloat(cj(priceElement).val().replace(thousandMarker, '').replace(symbol, ''));
if (isNaN(textval)) {
textval = parseFloat(0);
}
eval('var option = '+ cj(priceElement).attr('price'));
optionPart = option[1].split(optionSep);
addprice = parseFloat(optionPart[0]);
var curval = textval * addprice;
cj(priceElement).data('line_raw_total', curval);
display(calculateTotalFee());
}
/**
* Calculate the total fee for the visible priceset.
*/
function calculateTotalFee() {
var totalFee = 0;
cj("#priceset [price]").each(function () {
totalFee = totalFee + cj(this).data('line_raw_total');
});
return totalFee;
}
/**
* Display calculated amount.
*/
function display(totalfee) {
// totalfee is monetary, round it to 2 decimal points so it can
// go as a float - CRM-13491
totalfee = Math.round(totalfee*100)/100;
var totalFormattedFee = symbol + ' ' + CRM.formatMoney(totalfee, true);
cj('#pricevalue').html(totalFormattedFee);
cj('#total_amount').val( totalfee );
cj('#pricevalue').data('raw-total', totalfee).trigger('change');
if (totalfee < 0) {
cj('table#pricelabel').addClass('disabled');
}
else {
cj('table#pricelabel').removeClass('disabled');
}
if (typeof skipPaymentMethod == 'function') {
// Advice to anyone who, like me, feels hatred towards this if construct ... if you remove the if you
// get an error on participant 2 of a event that requires approval & permits multiple registrants.
skipPaymentMethod();
}
}
CRM.$(function($) {
var orgOption = $("input:radio[name=org_option]:checked").attr('id');
var onBehalfRequired = '$onBehalfRequired';
var onbehalfof_id = $('#onbehalfof_id');
var is_for_organization = $('#is_for_organization');
selectCreateOrg(orgOption, false);
if (is_for_organization.length) {
showHideOnBehalfOfBlock();
is_for_organization.on('change', function() {
showHideOnBehalfOfBlock();
});
}
function showHideOnBehalfOfBlock() {
$('#on-behalf-block').toggle(is_for_organization.is(':checked'));
if (is_for_organization.is(':checked')) {
$('#onBehalfOfOrg select.crm-select2').removeClass('crm-no-validate');
}
else {
$('#onBehalfOfOrg select.crm-select2').addClass('crm-no-validate');
}
}
$("input:radio[name='org_option']").click( function( ) {
var orgOption = $(this).attr('id');
selectCreateOrg(orgOption, true);
});
onbehalfof_id.change(function() {
setLocationDetails($(this).val());
}).change();
if (onbehalfof_id.length) {
setLocationDetails(onbehalfof_id.val());
}
function resetValues() {
// Don't trip chain-select when clearing values
$('.crm-chain-select-control', "#select_org div").select2('val', '');
$('input[type=text], select, textarea', "#select_org div").not('.crm-chain-select-control, #onbehalfof_id').val('').change();
$('input[type=radio], input[type=checkbox]', "#select_org div").prop('checked', false).change();
$('#on-behalf-block input').not('input[type=checkbox], input[type=radio], #onbehalfof_id').val('');
// clear checkboxes and radio
$('#on-behalf-block')
.find('input[type=checkbox], input[type=radio]')
.not('input[name=org_option]')
.attr('checked', false);
}
function selectCreateOrg( orgOption, reset ) {
if (orgOption == 'CIVICRM_QFID_0_org_option') {
$("#onbehalfof_id").show().change();
$("input#onbehalf_organization_name").hide();
}
else if (orgOption == 'CIVICRM_QFID_1_org_option') {
$("input#onbehalf_organization_name").show();
$("#onbehalfof_id").hide();
reset = true;
}
if ( reset ) {
resetValues();
}
}
function setLocationDetails(contactID , reset) {
resetValues();
var locationUrl = '' + contactID;
var submittedOnBehalfInfo = '';
var submittedCID = "";
if (submittedOnBehalfInfo) {
submittedOnBehalfInfo = $.parseJSON(submittedOnBehalfInfo);
if (submittedCID == contactID) {
$.each(submittedOnBehalfInfo, function(key, value) {
//handle checkboxes
if (typeof value === 'object') {
$.each(value, function(k, v) {
$('#onbehalf_' + key + '_' + k).prop('checked', v);
});
}
else if ($('#onbehalf_' + key).length) {
$('#onbehalf_' + key ).val(value);
}
//radio buttons
else if ($("input[name='onbehalf[" + key + "]']").length) {
$("input[name='onbehalf[" + key + "]']").val([value]);
}
});
return;
}
}
$.ajax({
url : locationUrl,
dataType : "json",
success : function(data, status) {
for (var ele in data) {
if ($("#"+ ele).hasClass('crm-chain-select-target')) {
$("#"+ ele).data('newVal', data[ele].value).off('.autofill').on('crmOptionsUpdated.autofill', function() {
$(this).off('.autofill').val($(this).data('newVal')).change();
});
}
else if ($('#' + ele).data('select2')) {
$('#' + ele).select2('val', data[ele].value);
}
if (data[ele].type == 'Radio') {
if (data[ele].value) {
var fldName = ele.replace('onbehalf_', '');
$("input[name='onbehalf["+ fldName +"]']").filter("[value='" + data[ele].value + "']").prop('checked', true);
}
}
else if (data[ele].type == 'CheckBox') {
for (var selectedOption in data[ele].value) {
var fldName = ele.replace('onbehalf_', '');
$("input[name='onbehalf["+ fldName+"]["+ selectedOption +"]']").prop('checked','checked');
}
}
else if (data[ele].type == 'AdvMulti-Select') {
var customFld = ele.replace('onbehalf_', '');
// remove empty value if any
$('#onbehalf\\['+ customFld +'\\]-f option[value=""]').remove();
$('#onbehalf\\['+ customFld +'\\]-t option[value=""]').remove();
for (var selectedOption in data[ele].value) {
// remove selected values from left and selected values to right
$('#onbehalf\\['+ customFld +'\\]-f option[value="' + selectedOption + '"]').remove()
.appendTo('#onbehalf\\['+ customFld +'\\]-t');
$('#onbehalf_'+ customFld).val(selectedOption);
}
}
else {
// do not set defaults to file type fields
if ($('#' + ele).attr('type') != 'file') {
$('#' + ele ).val(data[ele].value).change();
}
}
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
CRM.console('error', "HTTP error status: ", textStatus);
}
});
}
});
CRM.$(function ($) {
// build list of ids to track changes on
var address_fields = {"country":"Primary","street_address":"Primary","postal_code":"Primary","city":"Primary","state_province":"Primary"};
var input_ids = {};
var select_ids = {};
var orig_id, field, field_name;
// build input ids
$('.billing_name_address-section input').each(function (i) {
orig_id = $(this).attr('id');
field = orig_id.split('-');
field_name = field[0].replace('billing_', '');
if (field[1]) {
if (address_fields[field_name]) {
input_ids['#' + field_name + '-' + address_fields[field_name]] = '#' + orig_id;
}
}
});
if ($('#first_name').length)
input_ids['#first_name'] = '#billing_first_name';
if ($('#middle_name').length)
input_ids['#middle_name'] = '#billing_middle_name';
if ($('#last_name').length)
input_ids['#last_name'] = '#billing_last_name';
// build select ids
$('.billing_name_address-section select').each(function (i) {
orig_id = $(this).attr('id');
field = orig_id.split('-');
field_name = field[0].replace('billing_', '').replace('_id', '');
if (field[1]) {
if (address_fields[field_name]) {
select_ids['#' + field_name + '-' + address_fields[field_name]] = '#' + orig_id;
}
}
});
// detect if billing checkbox should default to checked
var checked = true;
for (var id in input_ids) {
orig_id = input_ids[id];
if ($(id).val() != $(orig_id).val()) {
checked = false;
break;
}
}
for (var id in select_ids) {
orig_id = select_ids[id];
if ($(id).val() != $(orig_id).val()) {
checked = false;
break;
}
}
if (checked) {
$('#billingcheckbox').prop('checked', true).data('crm-initial-value', true);
if (!CRM.billing || CRM.billing.billingProfileIsHideable) {
$('.billing_name_address-group').hide();
}
}
// onchange handlers for non-billing fields
for (var id in input_ids) {
orig_id = input_ids[id];
$(id).change(function () {
var id = '#' + $(this).attr('id');
var orig_id = input_ids[id];
// if billing checkbox is active, copy other field into billing field
if ($('#billingcheckbox').prop('checked')) {
$(orig_id).val($(id).val());
}
});
}
for (var id in select_ids) {
orig_id = select_ids[id];
$(id).change(function () {
var id = '#' + $(this).attr('id');
var orig_id = select_ids[id];
// if billing checkbox is active, copy other field into billing field
if ($('#billingcheckbox').prop('checked')) {
$(orig_id + ' option').prop('selected', false);
$(orig_id + ' option[value="' + $(id).val() + '"]').prop('selected', true);
$(orig_id).change();
}
});
}
// toggle show/hide
var billingCheckboxElement = $('#billingcheckbox');
billingCheckboxElement.click(function() {
billingCheckboxChanged(billingCheckboxElement);
});
billingCheckboxElement.change(function() {
billingCheckboxChanged(billingCheckboxElement);
});
function billingCheckboxChanged(billingCheckbox) {
if (billingCheckbox.prop('checked')) {
if (!CRM.billing || CRM.billing.billingProfileIsHideable) {
$('.billing_name_address-group').hide(200);
}
// copy all values
for (var id in input_ids) {
orig_id = input_ids[id];
$(orig_id).val($(id).val());
}
for (var id in select_ids) {
orig_id = select_ids[id];
$(orig_id + ' option').prop('selected', false);
$(orig_id + ' option[value="' + $(id).val() + '"]').prop('selected', true);
$(orig_id).change();
}
} else {
$('.billing_name_address-group').show(200);
}
}
// remove spaces, dashes from credit card number
$('#credit_card_number').change(function () {
var cc = $('#credit_card_number').val()
.replace(/ /g, '')
.replace(/-/g, '');
$('#credit_card_number').val(cc);
});
});
cj('input[name="soft_credit_type_id"]').on('change', function() {
enableHonorType();
});
function enableHonorType() {
var selectedValue = cj('input[name="soft_credit_type_id"]:checked');
if ( selectedValue.val() > 0) {
cj('#honorType').show();
}
else {
cj('#honorType').hide();
}
}
cj('input[id="is_recur"]').on('change', function() {
toggleRecur();
});
function toggleRecur() {
var isRecur = cj('input[id="is_recur"]:checked');
var allowAutoRenew = '';
var quickConfig = 1;
if (allowAutoRenew && cj("#auto_renew") && quickConfig) {
showHideAutoRenew(null);
}
var frequencyUnit = cj('#frequency_unit');
var frequencyInerval = cj('#frequency_interval');
var installments = cj('#installments');
isDisabled = false;
if (isRecur.val() > 0) {
cj('#recurHelp').show();
frequencyUnit.prop('disabled', false).addClass('required');
frequencyInerval.prop('disabled', false).addClass('required');
installments.prop('disabled', false);
cj('#amount_sum_label').text('Regular amount');
}
else {
cj('#recurHelp').hide();
frequencyUnit.prop('disabled', true).removeClass('required');
frequencyInerval.prop('disabled', true).removeClass('required');
installments.prop('disabled', true);
cj('#amount_sum_label').text('Total Amount');
}
}
function pcpAnonymous() {
// clear nickname field if anonymous is true
if (document.getElementsByName("pcp_is_anonymous")[1].checked) {
document.getElementById('pcp_roll_nickname').value = '';
}
if (!document.getElementsByName("pcp_display_in_roll")[0].checked) {
cj('#nickID').hide();
cj('#nameID').hide();
cj('#personalNoteID').hide();
}
else {
if (document.getElementsByName("pcp_is_anonymous")[0].checked) {
cj('#nameID').show();
cj('#nickID').show();
cj('#personalNoteID').show();
}
else {
cj('#nameID').show();
cj('#nickID').hide();
cj('#personalNoteID').hide();
}
}
}
CRM.$(function($) {
enableHonorType();
toggleRecur();
skipPaymentMethod();
});
CRM.$(function($) {
// highlight price sets
function updatePriceSetHighlight() {
$('#priceset .price-set-row span').removeClass('highlight');
$('#priceset .price-set-row input:checked').parent().addClass('highlight');
}
$('#priceset input[type="radio"]').change(updatePriceSetHighlight);
updatePriceSetHighlight();
// Update pledge contribution amount when pledge checkboxes change
$("input[name^='pledge_amount']").on('change', function() {
var total = 0;
$("input[name^='pledge_amount']:checked").each(function() {
total += Number($(this).attr('amount'));
});
$("input[name^='price_']").val(total.toFixed(2));
});
});