From d15e704cc77c9ad7383128c6cc956c45d4a3a120 Mon Sep 17 00:00:00 2001 From: mzd Date: Mon, 28 Apr 2014 19:02:31 -0400 Subject: [PATCH] CRM-11864 add/remove multiple profiles to event registrations: refactor add/remove js to use classes instead of identifiers and move into a closure ---------------------------------------- * CRM-11864: Embed form-designer in event and contribution UIs https://issues.civicrm.org/jira/browse/CRM-11864 --- .../Event/Form/ManageEvent/Registration.tpl | 128 +++++++----------- 1 file changed, 51 insertions(+), 77 deletions(-) diff --git a/templates/CRM/Event/Form/ManageEvent/Registration.tpl b/templates/CRM/Event/Form/ManageEvent/Registration.tpl index 99caf268b7..0fb0b8447a 100644 --- a/templates/CRM/Event/Form/ManageEvent/Registration.tpl +++ b/templates/CRM/Event/Form/ManageEvent/Registration.tpl @@ -24,28 +24,20 @@ +--------------------------------------------------------------------+ *} {if $addProfileBottomAdd OR $addProfileBottom} - {if $addProfileBottomAdd} - - {$form.additional_custom_post_id_multiple[$profileBottomNumAdd].label} - {$form.additional_custom_post_id_multiple[$profileBottomNumAdd].html} -  {ts}remove profile{/ts}   {ts}add profile{/ts} + + {if $addProfileBottomAdd }{$form.additional_custom_post_id_multiple[$profileBottomNumAdd].label} + {else}{$form.custom_post_id[$profileBottomNum].label}{/if} + {if $addProfileBottomAdd }{$form.additional_custom_post_id_multiple[$profileBottomNumAdd].html}{else}{$form.custom_post_id_multiple[$profileBottomNum].html}{/if} +  {ts}remove profile{/ts}   {ts}add profile{/ts}
- {ts}Change this if you want to use a different profile for additional participants.{/ts} + {if $addProfileBottomAdd } + {ts}Change this if you want to use a different profile for additional participants.{/ts} + {else} + {ts}Include additional fields on this registration form by configuring and selecting a CiviCRM Profile to be included at the bottom of the page.{/ts} + {/if}
- - {/if} - {if $addProfileBottom} - - {$form.custom_post_id_multiple[$profileBottomNum].label} - {$form.custom_post_id_multiple[$profileBottomNum].html} -  {ts}remove profile{/ts}  {ts}add profile{/ts} -
- {ts}Include additional fields on this registration form by configuring and selecting a CiviCRM Profile to be included at the bottom of the page.{/ts} -
- - - {/if} + {else} {assign var=eventID value=$id}
@@ -138,7 +130,7 @@ {$form.custom_post_id.label} {$form.custom_post_id.html} -   {ts}add profile{/ts} +   {ts}add profile{/ts}
{ts}Include additional fields on this registration form by configuring and selecting a CiviCRM Profile to be included at the bottom of the page.{/ts} @@ -149,9 +141,9 @@ {$form.custom_post_id_multiple.$profilePostNum.label} {$form.custom_post_id_multiple.$profilePostNum.html} -  {ts}remove profile{/ts} +  {ts}remove profile{/ts} {if $smarty.foreach.profilePostIdName.last} -   {ts}add profile{/ts} +   {ts}add profile{/ts} {/if}
@@ -170,7 +162,7 @@ {$form.additional_custom_post_id.label} {$form.additional_custom_post_id.html} -  {ts}add profile{/ts} +  {ts}add profile{/ts}
{ts}Change this if you want to use a different profile for additional participants.{/ts}
@@ -181,9 +173,9 @@ {$form.additional_custom_post_id_multiple.$profilePostNumA.label} {$form.additional_custom_post_id_multiple.$profilePostNumA.html} -  {ts}remove profile{/ts} +  {ts}remove profile{/ts} {if $smarty.foreach.profilePostIdAName.last} -   {ts}add profile{/ts} +   {ts}add profile{/ts} {/if}
@@ -368,58 +360,7 @@ invert = 0 } } - var profileBottomCount = Number({/literal}{$profilePostMultiple|@count}{literal}); - - function addProfileBottom( ) { - profileBottomCount++; - cj('.profile_bottom_link').remove( ); - cj('.profile_bottom_link_main').hide( ); - var urlPath = {/literal}"{crmURL p='civicrm/event/manage/registration' h=0 q=$addProfileParams}"{literal}; - urlPath = urlPath + '&snippet=4&addProfileNum=' + profileBottomCount; - cj.ajax({ url : urlPath, - async : false, - global : false, - success : function ( content ) { - cj( "#profile_post" ).parent().append( content ); - cj('#crm-container').trigger('crmLoad'); - } - }); - } - - - var profileBottomCountAdd = Number({/literal}{$profilePostMultipleAdd|@count}{literal}); - function addProfileBottomAdd( ) { - profileBottomCountAdd++; - cj('.profile_bottom_add_link').remove( ); - cj('.profile_bottom_add_link_main').hide( ); - var urlPathAdd = {/literal}"{crmURL p='civicrm/event/manage/registration' h=0 q=$addProfileParamsAdd}"{literal}; - urlPathAdd = urlPathAdd + '&snippet=4&addProfileNumAdd=' + profileBottomCountAdd; - cj.ajax({ url : urlPathAdd, - async : false, - global : false, - success : function ( contentAdd ) { - cj( "#additional_profile_post" ).parent().append( contentAdd ); - } - }); - } - - function removeProfile( profileID ) { - cj('#custom_post_id_multiple_' + profileID).val(''); - cj('#custom_post_id_multiple_' + profileID + '_wrapper').remove( ); - if ( cj('.profile_bottom_link').length < 1 ) { - cj('.profile_bottom_link_main').show( ); - } - } - - function removeProfileAdd( profileID ) { - cj('#additional_custom_post_id_multiple_' + profileID).val(''); - cj('#additional_custom_post_id_multiple_' + profileID + '_wrapper').remove( ); - if ( cj('.profile_bottom_add_link').length < 1 ) { - cj('.profile_bottom_add_link_main').show( ); - } - } - - //show edit profile field links + //show edit profile field links CRM.$(function($) { // show edit for main profile cj(document).on('change', 'select[id^="custom_p"]', function( event ) { @@ -440,6 +381,39 @@ invert = 0 cj('select[id^="additional_custom_p"]').each( function(e) { buildLinks( cj(this), cj(this).val()); }); + + var profileBottomCount = Number({/literal}{$profilePostMultiple|@count}{literal}); + var profileBottomCountAdd = Number({/literal}{$profilePostMultipleAdd|@count}{literal}); + + function addBottomProfile( e ) { + e.preventDefault(); + + var addtlPartc = $(this).data('addtlPartc'); + + if (addtlPartc) { + profileBottomCount++; + urlPath = CRM.url('civicrm/event/manage/registration', { addProfileBottomAdd: 1, addProfileNumAdd: profileBottomCountAdd, snippet: 4 } ) ; + } else { + profileBottomCountAdd++; + urlPath = CRM.url('civicrm/event/manage/registration', { addProfileBottom: 1 , addProfileNum : profileBottomCount, snippet: 4 } ) ; + } + + $(this).closest('tbody').append(''); + var $el = $(this).closest('tbody').find('tr:last'); + +// CRM.loadPage(urlPath, { target: $el } ); + $el.load(urlPath, function() { $(this).trigger('crmLoad') }); + } + + function removeBottomProfile( e ) { + e.preventDefault(); + + cj(e.target).parents('tr').find('.crm-profile-selector').val(''); + cj(e.target).parents('tr').hide(); + } + + $('#registration_blocks').on('click', '.crm-button-add-profile', addBottomProfile); + $('#registration_blocks').on('click', '.crm-button-rem-profile', removeBottomProfile); }); {/literal} -- 2.25.1