normalize js code & whitespace - move out of php, move into closure, remove use of...
authormzd <mzd@ginkgostreet.com>
Tue, 29 Apr 2014 00:22:06 +0000 (20:22 -0400)
committermzd <mzd@ginkgostreet.com>
Wed, 30 Apr 2014 15:23:01 +0000 (11:23 -0400)
CRM/Event/Form/ManageEvent/Registration.php
templates/CRM/Event/Form/ManageEvent/Registration.tpl

index e4dab12dd87cc5daf0e7d4e40635de67f6e036ed..2b23e765088f7eabd64466a0b0f8e65f745befad 100644 (file)
@@ -285,18 +285,12 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
 
     $this->addElement('checkbox',
       'is_multiple_registrations',
-      ts('Register multiple participants?'),
-      NULL,
-      array(
-        'onclick' => "return (showHideByValue('is_multiple_registrations', '', 'additional_profile_pre|additional_profile_post', 'table-row', 'radio', false) ||
-                                                      showRuleFields( " . json_encode($ruleFields) . " ));")
+      ts('Register multiple participants?')
     );
 
     $this->addElement('checkbox',
       'allow_same_participant_emails',
-      ts('Allow multiple registrations from the same email address?'),
-      NULL,
-      array('onclick' => "return showRuleFields( " . json_encode($ruleFields) . " );")
+      ts('Allow multiple registrations from the same email address?')
     );
     $this->assign('ruleFields', json_encode($ruleFields));
 
index 75b13c88da3908c554945d2ff5595a6e2e4be097..e2d5c371665f04dba2320c43af36a33f668d647d 100644 (file)
@@ -330,38 +330,43 @@ invert              = 0
 {include file="CRM/common/buildProfileLink.tpl"}
 
 <script type="text/javascript">
-    {literal}
-    cj("#is_multiple_registrations").change( function( ) {
-        if ( !cj(this).prop('checked') ) {
-            cj("#additional_custom_pre_id").val('');
-            cj("#additional_custom_post_id").val('');
-      cj(".crm-event-manage-registration-form-block-additional_custom_post_multiple").hide();
+    {literal}    (function($, _) { // Generic Closure
+
+    $("#is_multiple_registrations").change( function( ) {
+        if ( !$(this).prop('checked') ) {
+            $("#additional_custom_pre_id").val('');
+            $("#additional_custom_post_id").val('');
+            $(".crm-event-manage-registration-form-block-additional_custom_post_multiple").hide();
+            $('#additional_profile_pre,#additional_profile_post').hide();
         } else {
-      cj(".crm-event-manage-registration-form-block-additional_custom_post_multiple").show();
-  }
+            $(".crm-event-manage-registration-form-block-additional_custom_post_multiple").show();
+            $('#additional_profile_pre,#additional_profile_post').show();
+        }
+
+       showRuleFields({/literal}{$ruleFields}{literal});
     });
 
-    showRuleFields( {/literal}{$ruleFields}{literal} );
+    $('#allow_same_participant_emails').change( function() { showRuleFields({/literal}{$ruleFields}{literal}) });
 
-    function showRuleFields( ruleFields )
-    {
+    function showRuleFields( ruleFields ) {
         var msg1 = '{/literal}{ts 1="' + ruleFields + '"}Primary participants will be able to register additional participants using the same email address.  The configured "Supervised" Dedupe Rule will use the following fields to prevent duplicate registrations: %1.  First and Last Name will be used to check for matches among multiple participants.{/ts}{literal}';
         var msg2 = '{/literal}{ts escape='js'}Primary participants will be allowed to register for this event multiple times.  No duplicate registration checking will be performed.{/ts}{literal}';
         var msg3 = '{/literal}{ts escape='js'}Primary participants will be able to register additional participants during registration.{/ts}{literal}';
 
         // Display info
-        cj('.ui-notify-message .ui-notify-close').click();
-        if ( cj("#allow_same_participant_emails").prop('checked' ) && cj("#is_multiple_registrations").prop('checked' ) ) {
+        $('.ui-notify-message .ui-notify-close').click();
+        if ( $("#allow_same_participant_emails").prop('checked' ) && cj("#is_multiple_registrations").prop('checked' ) ) {
             CRM.alert( msg1, '', 'info', {expires:0} );
-        } else if ( cj("#allow_same_participant_emails").prop('checked' ) && !cj("#is_multiple_registrations").prop('checked' ) ) {
+        } else if ( $("#allow_same_participant_emails").prop('checked' ) && !cj("#is_multiple_registrations").prop('checked' ) ) {
             CRM.alert( msg2, '', 'info', {expires:0} );
-        } else if ( !cj("#allow_same_participant_emails").prop('checked' ) && cj("#is_multiple_registrations").prop('checked' ) ) {
+        } else if ( !$("#allow_same_participant_emails").prop('checked' ) && cj("#is_multiple_registrations").prop('checked' ) ) {
             CRM.alert( msg3, '', 'info', {expires:0} );
         }
     }
 
-      //show edit profile field links
-    CRM.$(function($) {
+    $(function($) {
+        showRuleFields( {/literal}{$ruleFields}{literal} );
+
         var profileBottomCount = Number({/literal}{$profilePostMultiple|@count}{literal});
         var profileBottomCountAdd = Number({/literal}{$profilePostMultipleAdd|@count}{literal});
 
@@ -386,14 +391,15 @@ invert              = 0
         function removeBottomProfile( e ) {
             e.preventDefault();
 
-            cj(e.target).parents('tr').find('.crm-profile-selector').val('');
-            cj(e.target).parents('tr').hide();
+            $(e.target).parents('tr').find('.crm-profile-selector').val('');
+            $(e.target).parents('tr').hide();
         }
 
         $('#registration_blocks').on('click', '.crm-button-add-profile', addBottomProfile);
         $('#registration_blocks').on('click', '.crm-button-rem-profile', removeBottomProfile);
     });
 
+    }(CRM.$, CRM._)); //Generic Closure
     {/literal}
 </script>
 {include file="CRM/common/formNavigate.tpl"}