From 1beb268a63e70974a25de6f08812575f7f11d778 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 25 Feb 2014 09:12:16 -0500 Subject: [PATCH] CRM-14270 - Fix UX & performance issues on backend participant form --- CRM/Event/Form/Participant.php | 90 +----- CRM/Event/Page/AJAX.php | 33 -- CRM/Event/xml/Menu/Event.xml | 5 - .../Campaign/Form/addCampaignToComponent.tpl | 4 +- templates/CRM/Event/Form/Participant.tpl | 293 +++++++----------- 5 files changed, 123 insertions(+), 302 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 7e4e20122a..d7424165a9 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -752,87 +752,21 @@ SELECT civicrm_custom_group.name as name, $this->assign('refreshURL', $url); - $this->add('hidden', 'past_event'); - - $events = array(); - if ( $this->_eID ) { - $eventEndDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID,'end_date'); - } - $this->assign('past', 0); - if ($this->_action & CRM_Core_Action::UPDATE) { - $events = CRM_Event_BAO_Event::getEvents(1, FALSE, FALSE); - } - elseif ($this->getElementValue('past_event') || (isset($eventEndDate) && (CRM_Utils_Date::currentDBDate() > CRM_Utils_Date::processDate($eventEndDate)))) { - $pastval = $this->getElementValue('past_event'); - $events = CRM_Event_BAO_Event::getEvents($pastval); - $this->assign('past', $pastval); - } - else { - $events = CRM_Event_BAO_Event::getEvents(); - } + $eventFieldParams = array( + 'entity' => 'event', + 'select' => array('minimumInputLength' => 0), + 'api' => array( + 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'), + ) + ); if ($this->_mode) { - //unset the event which are not monetary when credit card - //event registration is used - foreach ($events as $key => $val) { - $isPaid = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary'); - if (!$isPaid) { - unset($events[$key]); - } - } + // exclude events which are not monetary when credit card registration is used + $eventFieldParams['api']['params']['is_monetary'] = 1; $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE); } - // build array(event -> eventType) mapper - $query = " -SELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id -FROM civicrm_event -WHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0"; - $dao = CRM_Core_DAO::executeQuery($query); - $eventAndTypeMapping = array(); - while ($dao->fetch()) { - $eventAndTypeMapping[$dao->id] = $dao->event_type_id; - } - $eventAndTypeMapping = json_encode($eventAndTypeMapping); - // building of mapping ends -- - - //inherit the campaign from event. - $eventCampaigns = array(); - $allEventIds = array_keys($events); - if (!empty($allEventIds)) { - CRM_Core_PseudoConstant::populate($eventCampaigns, - 'CRM_Event_DAO_Event', - TRUE, 'campaign_id' - ); - } - $eventCampaigns = json_encode($eventCampaigns); - - $element = $this->add('select', 'event_id', ts('Event'), - array( - '' => ts('- select -')) + $events, - TRUE, - array('onchange' => "buildFeeBlock( this.value ); CRM.buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' ); loadCampaign( this.value, {$eventCampaigns} );", 'class' => 'huge') - ); - - // CRM-6111 - // note that embedding JS within PHP files is quite awful, IMO - // but we do the same for the onChange element and this form is complex - // and i did not want to break it late in the 3.2 cycle - $preloadJSSnippet = NULL; - if (!empty($_GET['reset']) && $this->_eID) { - $preloadJSSnippet = " -cj(function() { -cj('#event_id').val( '{$this->_eID}' ); -buildFeeBlock( {$this->_eID} ); -CRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} ); -buildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' ); -loadCampaign( {$this->_eID}, {$eventCampaigns} ); -}); -"; - } - - $this->assign('preloadJSSnippet', $preloadJSSnippet); - + $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE); //frozen the field fix for CRM-4171 if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { @@ -865,9 +799,7 @@ loadCampaign( {$this->_eID}, {$eventCampaigns} ); $roleids = CRM_Event_PseudoConstant::participantRole(); foreach ($roleids as $rolekey => $rolevalue) { - $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue, - array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );") - ); + $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue); } $this->addGroup($roleTypes, 'role_id', ts('Participant Role')); diff --git a/CRM/Event/Page/AJAX.php b/CRM/Event/Page/AJAX.php index 5f68dd0fa4..410c5e172f 100644 --- a/CRM/Event/Page/AJAX.php +++ b/CRM/Event/Page/AJAX.php @@ -66,38 +66,5 @@ GROUP BY cv.label"; CRM_Core_Page_AJAX::autocompleteResults($results); } - function eventList() { - $listparams = CRM_Utils_Array::value('listall', $_REQUEST, 1); - $events = CRM_Event_BAO_Event::getEvents($listparams); - - $elements = array(array('name' => ts('- select -'), - 'value' => '', - )); - foreach ($events as $id => $name) { - $elements[] = array( - 'name' => $name, - 'value' => $id, - ); - } - - echo json_encode($elements); - CRM_Utils_System::civiExit(); - } - - /** - * Function to get default participant role - */ - function participantRole() { - $eventID = $_GET['eventId']; - - $defaultRoleId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', - $eventID, - 'default_role_id', - 'id' - ); - $participantRole = array('role' => $defaultRoleId); - echo json_encode($participantRole); - CRM_Utils_System::civiExit(); - } } diff --git a/CRM/Event/xml/Menu/Event.xml b/CRM/Event/xml/Menu/Event.xml index c78095ed44..eedf0d2df6 100644 --- a/CRM/Event/xml/Menu/Event.xml +++ b/CRM/Event/xml/Menu/Event.xml @@ -270,11 +270,6 @@ CRM_Core_Page_AJAX_Location::getLocBlock access CiviEvent - - civicrm/ajax/eventlist - CRM_Event_Page_AJAX::eventList - access CiviCRM,access CiviEvent - civicrm/ajax/event/add_participant_to_cart CRM_Event_Cart_Page_CheckoutAJAX::add_participant_to_cart diff --git a/templates/CRM/Campaign/Form/addCampaignToComponent.tpl b/templates/CRM/Campaign/Form/addCampaignToComponent.tpl index a34c300251..39ac4e3a94 100644 --- a/templates/CRM/Campaign/Form/addCampaignToComponent.tpl +++ b/templates/CRM/Campaign/Form/addCampaignToComponent.tpl @@ -16,11 +16,11 @@ {if $campaignInfo.showAddCampaign} - {$form.campaign_id.label} + {$form.campaign_id.label} {help id="id-campaign_id" file="CRM/Campaign/Form/addCampaignToComponent.hlp"} {* lets take a call, either show campaign select drop-down or show add campaign link *} {if $campaignInfo.hasCampaigns} - {$form.campaign_id.html|crmAddClass:huge} {help id="id-campaign_id" file="CRM/Campaign/Form/addCampaignToComponent.hlp"} + {$form.campaign_id.html|crmAddClass:huge} {* show for add and edit actions *} {if ( $action eq 1 or $action eq 2 ) and !$campaignInfo.alreadyIncludedPastCampaigns and $campaignInfo.includePastCampaignURL} diff --git a/templates/CRM/Event/Form/Participant.tpl b/templates/CRM/Event/Form/Participant.tpl index a78d125d97..5908d7fc74 100644 --- a/templates/CRM/Event/Form/Participant.tpl +++ b/templates/CRM/Event/Form/Participant.tpl @@ -24,6 +24,8 @@ +--------------------------------------------------------------------+ *} {* This template is used for adding/editing/deleting offline Event Registrations *} + +{* Ajax callback for showing event fee snippet *} {if $showFeeBlock} {if $priceSet}
@@ -165,8 +167,12 @@ {/literal} {/if} {include file="CRM/Event/Form/EventFees.tpl"} + +{* Ajax callback for custom data snippet *} {elseif $cdType} {include file="CRM/Custom/Form/CustomData.tpl"} + +{* Main event form template *} {else} {if $participantMode == 'test' } {assign var=registerMode value="TEST"} @@ -251,19 +257,17 @@ {/if} - {$form.event_id.label}{$form.event_id.html}  - {if $action eq 1} -
» - {/if} - {if $is_test} - {ts}(test){/ts} - {/if} - + {$form.event_id.label} + + {$form.event_id.html} + {if $is_test} + {ts}(test){/ts} + {/if} + {* CRM-7362 --add campaign *} - {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" - campaignTrClass="crm-participant-form-block-campaign_id"} + {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" campaignTrClass="crm-participant-form-block-campaign_id"} {$form.role_id.label} @@ -324,171 +328,114 @@
{include file="CRM/common/formButtons.tpl" location="bottom"}
+ {* JS block for ADD or UPDATE actions only *} {if $action eq 1 or $action eq 2} {if $participantId} {include file="CRM/Contribute/Page/PaymentInfo.tpl" show='event-payment'} {/if} - {literal} - {/literal} + if (participantId) { + dataUrl += '&participantId=' + participantId; + } - {*include custom data js file*} - {include file="CRM/common/customData.tpl"} - {literal} - {/literal} + {*include custom data js file*} + {include file="CRM/common/customData.tpl"} + + {* jscript to warn if unsaved form field changes *} + {include file="CRM/common/formNavigate.tpl"} {/if} - {* include jscript to warn if unsaved form field changes *} - {include file="CRM/common/formNavigate.tpl"} -{literal} - -{/literal} {/if} {* end of main event block*} -- 2.25.1