Getting the custom field for reg level working.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 17 Apr 2018 13:20:17 +0000 (09:20 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 17 Apr 2018 13:20:17 +0000 (09:20 -0400)
I have the custom fields being adding and updated within the registrant
forms.

js/frontRegApp.js
js/views/front/regRequestRegistrant.js
js/views/front/regTime.js
js/views/front/registrantForm.js
models/admin/ajax/regFront/registrant.php
views/front/registrations/registration.html

index b6d889e..aac3157 100644 (file)
@@ -774,6 +774,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
         // For some reason this is not available after the newRegistrant is added
         // to the collection.
         var customFieldData = this.$( 'form.attendee-cf-form-' + this.model.get('id') ).serialize();
+        var customFieldLevelData = this.$( 'form.attendee-cf-form-level-' + this.model.get('id') ).serialize();
 
         var modelId = this.model.get( 'id' );
         var fname   = this.$('.reg_fname').val().trim();
@@ -817,6 +818,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
             country: country,
             reg_time: this.model.get('reg_time'),
             customFields: customFieldData,
+            customFieldsLevel: customFieldLevelData,
         }, {wait: true});
         // this.model.save();
         if ( this.model.validationError ) {
@@ -830,7 +832,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
     resetCustomFields: function() {
         // Call the custom fields ajax
         app.setCustomFieldsForm(this.model.get('reg_event'), this.model.id, '.attendee-cf-' + this.model.id);
-        app.setCustomFieldsForLevelForm(this.model.get('reg_event'), this.model.get('class_id'),  this.model.id, '.attendee-cf-level-' + this.model.id);
+        app.setCustomFieldsForLevelForm(this.model.get('reg_event'), this.model.get('reg_class'),  this.model.id, '.attendee-cf-level-' + this.model.id);
         this.$('.reg-edit-form').hide();
     },
 
@@ -869,7 +871,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
 
         // Call the custom fields ajax
         app.setCustomFieldsForm(this.model.get('reg_event'), this.model.id, '.attendee-cf-' + this.model.id);
-        app.setCustomFieldsForLevelForm(this.model.get('reg_event'), this.model.get('class_id'), this.model.id, '.attendee-cf-level-' + this.model.id);
+        app.setCustomFieldsForLevelForm(this.model.get('reg_event'), this.model.get('reg_class'), this.model.id, '.attendee-cf-level-' + this.model.id);
         return this;
     },
 
@@ -947,7 +949,6 @@ app.Views.Front.RegTime = Backbone.View.extend({
         if ( app.timeSpecific ) {
             this.newRegAccount = new app.Models.Front.RegRequestRegistrant({ reg_time: this.model.get( 'selectedTime' ) });
         } else {
-            // console.log(this.model);
             this.newRegAccount = new app.Models.Front.RegRequestRegistrant({
                 reg_event: this.model.get('reg_event'),
                 reg_class: this.model.get('parent')
@@ -999,7 +1000,6 @@ app.Views.Front.RegTime = Backbone.View.extend({
             }
         } else {
             findByEmail = this.model.registrants.where({email: email, fname: fname, lname: lname});
-            console.log( findByEmail.length );
             if ( findByEmail.length > 0 ) {
                 this.$('#loading-' + this.model.get('id') ).hide();
             }
@@ -1016,6 +1016,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
         // For some reason this is not available after the newRegistrant is added
         // to the collection.
         var customFieldData = this.$( 'form.attendee-cf-form-new' ).serialize();
+        var customFieldLevelData = this.$( 'form.attendee-cf-form-level-new' ).serialize();
 
         var newRegistrant = this.model.registrants.create({
             option: 'add',
@@ -1034,6 +1035,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
             zip: zip,
             country: country,
             customFields: customFieldData,
+            customFieldsLevel: customFieldLevelData,
         },{ wait: true, error: this.errorCallback });
 
         this.$('.glm-add-new-account').show();
@@ -1062,15 +1064,12 @@ app.Views.Front.RegTime = Backbone.View.extend({
 
     // add a registrant to collection
     addOne: function( item ){
-        // console.log( 'regTime: addOne called' );
-        // console.log( item.get('id') );
         this.model.set({selectedTime: item.get('reg_time') })
         this.render();
     },
 
     // delete a registrant in collection
     deleteOne: function( item ){
-        // console.log( 'regTime: deleteOne called' );
         // this.render();
     },
 });
@@ -1104,7 +1103,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
     render: function(){
         this.$el.html( this.template( this.model.toJSON() ) );
         var regClass = this.model.get('reg_class');
-        app.setCustomFieldsForLevelForm( this.model.get('reg_event'), regClass.get('id'), this.model.id, '.attendee-cf-level-' + this.model.id);
+        app.setCustomFieldsForLevelForm( this.model.get('reg_event'), regClass.get('id'), this.model.id, '.attendee-cf-level-new');
         return this;
     },
 
index 6e4e15b..296cbdf 100644 (file)
@@ -28,6 +28,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
         // For some reason this is not available after the newRegistrant is added
         // to the collection.
         var customFieldData = this.$( 'form.attendee-cf-form-' + this.model.get('id') ).serialize();
+        var customFieldLevelData = this.$( 'form.attendee-cf-form-level-' + this.model.get('id') ).serialize();
 
         var modelId = this.model.get( 'id' );
         var fname   = this.$('.reg_fname').val().trim();
@@ -71,6 +72,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
             country: country,
             reg_time: this.model.get('reg_time'),
             customFields: customFieldData,
+            customFieldsLevel: customFieldLevelData,
         }, {wait: true});
         // this.model.save();
         if ( this.model.validationError ) {
@@ -84,7 +86,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
     resetCustomFields: function() {
         // Call the custom fields ajax
         app.setCustomFieldsForm(this.model.get('reg_event'), this.model.id, '.attendee-cf-' + this.model.id);
-        app.setCustomFieldsForLevelForm(this.model.get('reg_event'), this.model.get('class_id'),  this.model.id, '.attendee-cf-level-' + this.model.id);
+        app.setCustomFieldsForLevelForm(this.model.get('reg_event'), this.model.get('reg_class'),  this.model.id, '.attendee-cf-level-' + this.model.id);
         this.$('.reg-edit-form').hide();
     },
 
@@ -123,7 +125,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
 
         // Call the custom fields ajax
         app.setCustomFieldsForm(this.model.get('reg_event'), this.model.id, '.attendee-cf-' + this.model.id);
-        app.setCustomFieldsForLevelForm(this.model.get('reg_event'), this.model.get('class_id'), this.model.id, '.attendee-cf-level-' + this.model.id);
+        app.setCustomFieldsForLevelForm(this.model.get('reg_event'), this.model.get('reg_class'), this.model.id, '.attendee-cf-level-' + this.model.id);
         return this;
     },
 
index db63325..f99dd87 100644 (file)
@@ -55,7 +55,6 @@ app.Views.Front.RegTime = Backbone.View.extend({
         if ( app.timeSpecific ) {
             this.newRegAccount = new app.Models.Front.RegRequestRegistrant({ reg_time: this.model.get( 'selectedTime' ) });
         } else {
-            // console.log(this.model);
             this.newRegAccount = new app.Models.Front.RegRequestRegistrant({
                 reg_event: this.model.get('reg_event'),
                 reg_class: this.model.get('parent')
@@ -107,7 +106,6 @@ app.Views.Front.RegTime = Backbone.View.extend({
             }
         } else {
             findByEmail = this.model.registrants.where({email: email, fname: fname, lname: lname});
-            console.log( findByEmail.length );
             if ( findByEmail.length > 0 ) {
                 this.$('#loading-' + this.model.get('id') ).hide();
             }
@@ -124,6 +122,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
         // For some reason this is not available after the newRegistrant is added
         // to the collection.
         var customFieldData = this.$( 'form.attendee-cf-form-new' ).serialize();
+        var customFieldLevelData = this.$( 'form.attendee-cf-form-level-new' ).serialize();
 
         var newRegistrant = this.model.registrants.create({
             option: 'add',
@@ -142,6 +141,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
             zip: zip,
             country: country,
             customFields: customFieldData,
+            customFieldsLevel: customFieldLevelData,
         },{ wait: true, error: this.errorCallback });
 
         this.$('.glm-add-new-account').show();
@@ -170,15 +170,12 @@ app.Views.Front.RegTime = Backbone.View.extend({
 
     // add a registrant to collection
     addOne: function( item ){
-        // console.log( 'regTime: addOne called' );
-        // console.log( item.get('id') );
         this.model.set({selectedTime: item.get('reg_time') })
         this.render();
     },
 
     // delete a registrant in collection
     deleteOne: function( item ){
-        // console.log( 'regTime: deleteOne called' );
         // this.render();
     },
 });
index 15af930..9aa17e6 100644 (file)
@@ -27,7 +27,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
     render: function(){
         this.$el.html( this.template( this.model.toJSON() ) );
         var regClass = this.model.get('reg_class');
-        app.setCustomFieldsForLevelForm( this.model.get('reg_event'), regClass.get('id'), this.model.id, '.attendee-cf-level-' + this.model.id);
+        app.setCustomFieldsForLevelForm( this.model.get('reg_event'), regClass.get('id'), this.model.id, '.attendee-cf-level-new');
         return this;
     },
 
index 132cb4f..cf20ec7 100644 (file)
@@ -150,6 +150,8 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations
      */
     public function addUpdateRegistrantToCart( $modelData, $action )
     {
+        // trigger_error( print_r($modelData, true) );
+
         $validated = false;
 
         if ( $action == 'add' ) {
@@ -521,6 +523,24 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations
         );
         $registrant['customFields'] = $modelData['customFields'];
 
+        // Parse str for the custom field data
+        parse_str( $modelData['customFieldsLevel'], $queryParams2 );
+
+        // Store the custom Level field data
+        $_REQUEST = $queryParams2;
+        // trigger_error(print_r($_REQUEST,1));
+        // trigger_error(print_r($regRequestRegistrantId,1));
+        // trigger_error(print_r($regRequestClassId,1));
+        apply_filters(
+            'glm-members-customfields-form-submit',
+            '',
+            'glm_reg_customfields_reg_event_' .  $modelData['reg_event'] .  '_level_' .  $modelData['reg_class'],
+            $regRequestRegistrantId,
+            true
+        );
+        $registrant['customFieldsLevel'] = $modelData['customFieldsLevel'];
+
+
         return $registrant;
 
     }
index db13409..0409c78 100644 (file)
@@ -323,8 +323,8 @@ glm_reg_customfields_reg_event_{$regEventId}_level_{literal}<%- reg_class.id %>{
                         {literal}
                     </div>
                 </form>
-                <form class="attendee-cf-level-form-<%= id %>">
-                    <div class="attendee-cf-level-<%= id %>"></div>
+                <form class="attendee-cf-form-level-new">
+                    <div class="attendee-cf-level-new"></div>
                 </form>
                 {/literal}{/if}{literal}
                 {/literal}{if $regEvent.time_specific.value}
@@ -420,7 +420,7 @@ glm_reg_customfields_reg_event_{$regEventId}_level_{literal}<%- reg_class.id %>{
                         <h4>Additional Info Needed</h4>
                     {/literal}{/if}{literal}
                         <form class="attendee-cf-form-<%= id %>"><div class="attendee-cf-<%= id %>"></div></form>
-                        <form class="attendee-cf-level-form-<%= id %>"><div class="attendee-cf-level-<%= id %>"></div></form>
+                        <form class="attendee-cf-form-level-<%= id %>"><div class="attendee-cf-level-<%= id %>"></div></form>
                     {/literal}{/if}{literal}
                 </div>
             {/literal}{if $regEvent.time_specific.value}
@@ -494,7 +494,6 @@ var app = {
         }
     },
     setCustomFieldsForLevelForm: function( reg_event_id, reg_level_id, record_id, target ){
-    console.log('record_id: ', record_id);
         if ( customFieldActive ) {
             var formData = {
                 'action': 'glm_members_admin_ajax',
@@ -515,7 +514,6 @@ var app = {
             })
             .done( function( formHtml ) {
                 if ( target === 'return' ) {
-                    console.log( formHtml );
                     return formHtml;
                 } else {
                     jQuery(target).html( formHtml );
@@ -546,7 +544,6 @@ var app = {
             })
             .done( function( formHtml ) {
                 if ( target === 'return' ) {
-                    console.log( formHtml );
                     return formHtml;
                 } else {
                     jQuery(target).html( formHtml );
@@ -646,7 +643,6 @@ jQuery(function($){
         var id = $(this).data('descr');
         var descr = $('body').find( $('#' + id) );
         var descr_length = descr.text().length;
-        console.log(descr_length);
         if( descr.height() < 47 && descr_length > 150 ){
             $(descr).animate({
                 height: '100%',