working on getting custom field data to save. feature/steveCustomFields
authorSteve Sutton <ssutton@gmail.com>
Sun, 17 Dec 2017 20:03:30 +0000 (15:03 -0500)
committerSteve Sutton <ssutton@gmail.com>
Sun, 17 Dec 2017 20:03:30 +0000 (15:03 -0500)
so far not working using the apply_filters.

gulpfile.js
js/collections/front/regRequestRegistrants.js
js/frontRegApp.js
js/models/front/regClass.js
js/models/front/regEvent.js
js/views/front/regClass.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 9c8254f..17baa4d 100644 (file)
@@ -1,9 +1,9 @@
 var gulp    = require('gulp'),
     concat  = require('gulp-concat'),
     uglify  = require('gulp-uglify'),
-    jshint  = require('gulp-jshint'),
+    // jshint  = require('gulp-jshint'),
     plumber = require('gulp-plumber');
-//    notify  = require('gulp-notify');
+    // notify  = require('gulp-notify');
 
 gulp.task('adminscripts', function(){
     gulp.src([
@@ -26,6 +26,7 @@ gulp.task('frontscripts', function(){
         .pipe(plumber())
         .pipe(concat('frontRegApp.js'))
         //.pipe(uglify())
+        // .pipe(notify('frontscripts:', 'completed'))
         .pipe(jshint())
         .pipe(gulp.dest('js/'));
 });
index 6658715..530f370 100644 (file)
@@ -14,4 +14,5 @@ app.Collections.Front.RegRequestRegistrants = Backbone.Collection.extend({
             return 1;
         }
     },
+
 });
index 181fa19..af33b67 100644 (file)
@@ -109,7 +109,7 @@ app.Models.Front.RegClass = Backbone.Model.extend({
 
     initialize: function(){
         // this.registrants = new app.Collections.Front.RegRequestRegistrants( [] );
-        this.regTimes = new app.Collections.Front.RegTimes( [] );
+        this.regTimes = new app.Collections.Front.RegTimes( );
     },
 
 });
@@ -153,34 +153,39 @@ app.Models.Front.RegEvent = Backbone.Model.extend({
         for ( var i = 0; i < registrants.length; i++ ) {
             // Find the class that this registrant belongs to.
             var foundClass = this.classes.findWhere({ id: registrants[i].class_id });
-            // console.log( foundClass );
             if ( foundClass != undefined ) {
+                var foundClassTimes = foundClass.regTimes;
+                // console.log('total times: ' + foundClassTimes.length);
+                var regTimeId = parseInt( registrants[i].reg_time );
                 // Try looking through the class times
-                // console.log( registrants[i].reg_time );
-                // console.log( foundClass.get('times') );
                 // Using the registrants reg_time lookup the regTime
-                // var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time});
-                var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time });
-                console.log( 'find reg time' );
-                console.log( foundRegTime );
+                // class times are in JSON form under class.times
+                var foundRegTime = _.findWhere(foundClass.get('times'), { id: regTimeId });
                 if ( foundRegTime ) {
                     // Set the reg_event for this reg_time to the class we found for registrant
                     foundRegTime.reg_event = foundClass.get('reg_event');
 
                     // Now add the time if needed
                     // First check to see if there's not one added already (regTime).
-                    var hasRegTime = _.findWhere(foundClass, { reg_time: foundRegTime.id });
+                    var hasRegTime = foundClassTimes.findWhere({ id: foundRegTime.id });
                     if ( !hasRegTime ) {
+                        // console.log( 'no time found: creating time');
                         // Here we have to add the regTime into the class.
                         foundClass.regTimes.create( foundRegTime );
                         hasRegTime = foundClass.regTimes.findWhere({ id: foundRegTime.id });
                         hasRegTime.set({ parent: foundClass });
                     }
+                    // console.log(hasRegTime);
+                    //
+                    // console.log('total times: ' + foundClassTimes.length);
                     // Add the registrant to the regTime.
                     var nRegTime = foundClass.regTimes.findWhere({id: hasRegTime.get('id')});
-                    console.log( 'nRegTime' );
-                    console.log(nRegTime);
+                    // console.log('total registrants: ' + nRegTime.registrants.length);
                     nRegTime.registrants.create( registrants[i] );
+                    nRegTime.save();
+                    // console.log(nRegTime);
+                    // console.log('total registrants: ' + nRegTime.registrants.length);
+
                 }
 
             }
@@ -397,6 +402,7 @@ app.Collections.Front.RegRequestRegistrants = Backbone.Collection.extend({
             return 1;
         }
     },
+
 });
 
 // js/collections/regTimes.js
@@ -510,14 +516,14 @@ app.Views.Front.RegClass = Backbone.View.extend({
 
         // Add times into regTimes collection
         var classTimes = this.model.get('times');
-        var timeArs = [];
+        //var timeArs = [];
         for ( var key in classTimes ) {
             var newTime = new app.Models.Front.RegTime( classTimes[key] );
             newTime.set({reg_event: this.model.get('reg_event'), parent: this.model});
-            timeArs.push( newTime );
-            // this.model.regTimes.create( newTime );
+            //timeArs.push( newTime );
+            this.model.regTimes.create( newTime );
         }
-        this.model.regTimes.reset( timeArs );
+        //this.model.regTimes.reset( timeArs );
 
         // console.log( classTimes );
 
@@ -885,7 +891,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
         this.$el.html( this.template( this.model.toJSON() ) );
         this.$emailInput = this.$('.editEmail');
         this.$('.reg-edit-form').hide();
-        app.setCustomFieldsForm(this.model.get('reg_event'), '.attendee-cf-' + this.model.id);
+        app.setCustomFieldsForm(this.model.get('reg_event'), this.model.id, '.attendee-cf-' + this.model.id);
         return this;
     },
 
@@ -915,10 +921,11 @@ app.Views.Front.RegTime = Backbone.View.extend({
     // initialize the view
     initialize: function(){
         this.listenTo( this.model.registrants, 'add', this.addOne );
-        this.listenTo( this.model.registrants, 'create', this.addOne );
+        this.listenTo( this.model.registrants, 'create', this.render );
         this.listenTo( this.model.registrants, 'remove', this.deleteOne );
 
         this.listenTo( this.model, 'change', this.render );
+        // this.listenTo( this.model.registrants, 'change', this.render );
         return this;
     },
 
@@ -931,6 +938,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
 
     // render the view
     render: function(){
+        // console.log('render called from Views.Front.RegTime');
         this.model.set({ reg_count: this.model.registrants.length });
         this.$el.html( this.template( this.model.toJSON() ) );
         // Need to see if this has attendees and render them
@@ -1004,6 +1012,9 @@ app.Views.Front.RegTime = Backbone.View.extend({
             return;
         }
 
+        var customFieldData = this.$( 'form.attendee-cf-form-new' ).serialize();
+
+        // return false;
         if ( findByEmail.length === 0 ) {
             var newRegistrant = this.model.registrants.create({
                 option: 'add',
@@ -1021,18 +1032,12 @@ app.Views.Front.RegTime = Backbone.View.extend({
                 state: state,
                 zip: zip,
                 country: country,
+                customFields: customFieldData,
             });
-            // Now we have a new registrant let's save the custom field data.
-            var formData = jQuery( '#attendees-cf-form-new' ).serialize();
-            console.log( 'output form data' );
-            console.log( formData );
-            // app.saveCustomFieldsForm(
-                // jQuery('.attendee-cf-form').serialize()
-            // );
         }
 
-        this.newRegAccount.destroy();
-        this.newRegAccountView.remove();
+        // this.newRegAccount.destroy();
+        // this.newRegAccountView.remove();
         app.regEventLock = false;
     },
 
@@ -1046,14 +1051,16 @@ app.Views.Front.RegTime = Backbone.View.extend({
 
     // add a registrant to collection
     addOne: function( item ){
-        console.log( 'regTime: addOne called' );
+        // console.log( 'regTime: addOne called' );
+        // console.log( item.get('id') );
         this.model.set({selectedTime: item.get('reg_time') })
-        // this.render();
+        this.render();
     },
 
     // delete a registrant in collection
     deleteOne: function( item ){
-        // this.render();
+        // console.log( 'regTime: deleteOne called' );
+        this.render();
     },
 });
 
@@ -1084,7 +1091,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
     render: function(){
         this.$el.html( this.template( this.model.toJSON() ) );
         // console.log( this.model.get('reg_event') );
-        app.setCustomFieldsForm(this.model.get('reg_event'), '.attendee-cf-new');
+        app.setCustomFieldsForm(this.model.get('reg_event'), '', '.attendee-cf-new');
         return this;
     },
 
index b8e0fd8..d875e27 100644 (file)
@@ -22,7 +22,7 @@ app.Models.Front.RegClass = Backbone.Model.extend({
 
     initialize: function(){
         // this.registrants = new app.Collections.Front.RegRequestRegistrants( [] );
-        this.regTimes = new app.Collections.Front.RegTimes( [] );
+        this.regTimes = new app.Collections.Front.RegTimes( );
     },
 
 });
index e331743..e6d181d 100644 (file)
@@ -37,34 +37,39 @@ app.Models.Front.RegEvent = Backbone.Model.extend({
         for ( var i = 0; i < registrants.length; i++ ) {
             // Find the class that this registrant belongs to.
             var foundClass = this.classes.findWhere({ id: registrants[i].class_id });
-            // console.log( foundClass );
             if ( foundClass != undefined ) {
+                var foundClassTimes = foundClass.regTimes;
+                // console.log('total times: ' + foundClassTimes.length);
+                var regTimeId = parseInt( registrants[i].reg_time );
                 // Try looking through the class times
-                // console.log( registrants[i].reg_time );
-                // console.log( foundClass.get('times') );
                 // Using the registrants reg_time lookup the regTime
-                // var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time});
-                var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time });
-                console.log( 'find reg time' );
-                console.log( foundRegTime );
+                // class times are in JSON form under class.times
+                var foundRegTime = _.findWhere(foundClass.get('times'), { id: regTimeId });
                 if ( foundRegTime ) {
                     // Set the reg_event for this reg_time to the class we found for registrant
                     foundRegTime.reg_event = foundClass.get('reg_event');
 
                     // Now add the time if needed
                     // First check to see if there's not one added already (regTime).
-                    var hasRegTime = _.findWhere(foundClass, { reg_time: foundRegTime.id });
+                    var hasRegTime = foundClassTimes.findWhere({ id: foundRegTime.id });
                     if ( !hasRegTime ) {
+                        // console.log( 'no time found: creating time');
                         // Here we have to add the regTime into the class.
                         foundClass.regTimes.create( foundRegTime );
                         hasRegTime = foundClass.regTimes.findWhere({ id: foundRegTime.id });
                         hasRegTime.set({ parent: foundClass });
                     }
+                    // console.log(hasRegTime);
+                    //
+                    // console.log('total times: ' + foundClassTimes.length);
                     // Add the registrant to the regTime.
                     var nRegTime = foundClass.regTimes.findWhere({id: hasRegTime.get('id')});
-                    console.log( 'nRegTime' );
-                    console.log(nRegTime);
+                    // console.log('total registrants: ' + nRegTime.registrants.length);
                     nRegTime.registrants.create( registrants[i] );
+                    nRegTime.save();
+                    // console.log(nRegTime);
+                    // console.log('total registrants: ' + nRegTime.registrants.length);
+
                 }
 
             }
index a7e53b9..e85add5 100644 (file)
@@ -15,14 +15,14 @@ app.Views.Front.RegClass = Backbone.View.extend({
 
         // Add times into regTimes collection
         var classTimes = this.model.get('times');
-        var timeArs = [];
+        //var timeArs = [];
         for ( var key in classTimes ) {
             var newTime = new app.Models.Front.RegTime( classTimes[key] );
             newTime.set({reg_event: this.model.get('reg_event'), parent: this.model});
-            timeArs.push( newTime );
-            // this.model.regTimes.create( newTime );
+            //timeArs.push( newTime );
+            this.model.regTimes.create( newTime );
         }
-        this.model.regTimes.reset( timeArs );
+        //this.model.regTimes.reset( timeArs );
 
         // console.log( classTimes );
 
index 60617c7..783e4fe 100644 (file)
@@ -93,7 +93,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
         this.$el.html( this.template( this.model.toJSON() ) );
         this.$emailInput = this.$('.editEmail');
         this.$('.reg-edit-form').hide();
-        app.setCustomFieldsForm(this.model.get('reg_event'), '.attendee-cf-' + this.model.id);
+        app.setCustomFieldsForm(this.model.get('reg_event'), this.model.id, '.attendee-cf-' + this.model.id);
         return this;
     },
 
index 136f190..084449e 100644 (file)
@@ -10,10 +10,11 @@ app.Views.Front.RegTime = Backbone.View.extend({
     // initialize the view
     initialize: function(){
         this.listenTo( this.model.registrants, 'add', this.addOne );
-        this.listenTo( this.model.registrants, 'create', this.addOne );
+        this.listenTo( this.model.registrants, 'create', this.render );
         this.listenTo( this.model.registrants, 'remove', this.deleteOne );
 
         this.listenTo( this.model, 'change', this.render );
+        // this.listenTo( this.model.registrants, 'change', this.render );
         return this;
     },
 
@@ -26,6 +27,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
 
     // render the view
     render: function(){
+        // console.log('render called from Views.Front.RegTime');
         this.model.set({ reg_count: this.model.registrants.length });
         this.$el.html( this.template( this.model.toJSON() ) );
         // Need to see if this has attendees and render them
@@ -99,6 +101,9 @@ app.Views.Front.RegTime = Backbone.View.extend({
             return;
         }
 
+        var customFieldData = this.$( 'form.attendee-cf-form-new' ).serialize();
+
+        // return false;
         if ( findByEmail.length === 0 ) {
             var newRegistrant = this.model.registrants.create({
                 option: 'add',
@@ -116,18 +121,12 @@ app.Views.Front.RegTime = Backbone.View.extend({
                 state: state,
                 zip: zip,
                 country: country,
+                customFields: customFieldData,
             });
-            // Now we have a new registrant let's save the custom field data.
-            var formData = jQuery( '#attendees-cf-form-new' ).serialize();
-            console.log( 'output form data' );
-            console.log( formData );
-            // app.saveCustomFieldsForm(
-                // jQuery('.attendee-cf-form').serialize()
-            // );
         }
 
-        this.newRegAccount.destroy();
-        this.newRegAccountView.remove();
+        // this.newRegAccount.destroy();
+        // this.newRegAccountView.remove();
         app.regEventLock = false;
     },
 
@@ -141,13 +140,15 @@ app.Views.Front.RegTime = Backbone.View.extend({
 
     // add a registrant to collection
     addOne: function( item ){
-        console.log( 'regTime: addOne called' );
+        // console.log( 'regTime: addOne called' );
+        // console.log( item.get('id') );
         this.model.set({selectedTime: item.get('reg_time') })
-        // this.render();
+        this.render();
     },
 
     // delete a registrant in collection
     deleteOne: function( item ){
-        // this.render();
+        // console.log( 'regTime: deleteOne called' );
+        this.render();
     },
 });
index a43e982..5e0e702 100644 (file)
@@ -25,7 +25,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
     render: function(){
         this.$el.html( this.template( this.model.toJSON() ) );
         // console.log( this.model.get('reg_event') );
-        app.setCustomFieldsForm(this.model.get('reg_event'), '.attendee-cf-new');
+        app.setCustomFieldsForm(this.model.get('reg_event'), '', '.attendee-cf-new');
         return this;
     },
 
index d930388..12fa5b7 100644 (file)
@@ -82,7 +82,7 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations
     {
 
         $validated = false;
-        // trigger_error(print_r($modelData,1));
+        trigger_error(print_r($modelData,1));
 
         if ( !isset( $modelData['option'] ) ) {
             $option = null;
@@ -344,6 +344,11 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations
                     '%s'
                 );
                 $accountId = $this->wpdb->insert_id;
+                $queryParams = parse_url( $modelData['customFields'] );
+
+                // Store the custom field data
+                $_REQUEST = $queryParams;
+                apply_filters( 'glm-members-customfields-form-submit', '', 'glm_reg_customfields_reg_event_attendee_' . $modelData['reg_event'], $accountId, true);
                 // Here validated would be false.
                 // Because it is new account.
             }
index 648545b..e698e4c 100644 (file)
@@ -2,45 +2,7 @@
 {* Underscore Templates for the Event Registration App *}
 {* Template for Logged in Account *}
 
-<!-- *** TESTING ONLY *** -->
-<div id="test-form-request" class="button map-button">*** TEST FORM REQUEST ***</div>
-<div id="test-form-container">Test Form Container</div>
-<script type="text/javascript">
-jQuery(document).ready(function($) {
-
-    // Submit test form request
-    $('#test-form-request').click( function() {
-
-        // Collect the new field data
-        var formData = {
-            'action':       'glm_members_admin_ajax',
-            'glm_action':   'customFieldsFront',
-            'option':       'displayForm',
-            'fid':          'glm_reg_customfields_reg_event_61',
-            'recordId':     '123',
-            'parentFormId': 'abc-123',
-            'formData':     false
-        };
-
-        // Submit new field data - expect field new ID back
-        $.ajax({
-            type:       'POST',
-            url:        '{$ajaxUrl}',
-            data:       formData,
-            encode:     true,
-            dataType:   'text'
-        })
-        .done( function(formHtml) {
-            $('#test-form-container').html(formHtml);
-        });
-
-    });
-
-});
-</script>
-<!-- *** END OF TESTING *** -->
-
-<script src="//maps.googleapis.com/maps/api/js?sensor=true&key={$settings.google_maps_api_key}"></script>
+<script src="//maps.googleapis.com/maps/api/js?key={$settings.google_maps_api_key}"></script>
 {literal}
 <script type="text/template" id="account-template">
     <span>Logged in as <%= fname %><%= lname %></span>
@@ -223,7 +185,7 @@ jQuery(document).ready(function($) {
                     <div class="columns large-4 small-12">Email Address</div>
                     <div class="columns large-8 small-12"><input class="add_reg_email" value="<%- email %>"></div>
                 </div>
-                <form id="attendee-cf-form-new"><div class="attendee-cf-new"></div></form>
+                <form class="attendee-cf-form-new"><div class="attendee-cf-new"></div></form>
                 <div>
                     <a class="show-hide-address">Address (show/hide)</a>
                 </div>
@@ -286,7 +248,7 @@ jQuery(document).ready(function($) {
                         <div class="columns large-4 small-12">Email Address</div>
                         <div class="columns large-8 small-12"><input class="reg_email" value="<%- email %>"></div>
                     </div>
-                    <form class="attendee-cf-form"><div class="attendee-cf"></div></form>
+                    <form class="attendee-cf-form-<%= id %>"><div class="attendee-cf-<%= id %>"></div></form>
                     <div>
                         <a class="show-hide-address">Address (show/hide)</a>
                     </div>
@@ -385,14 +347,14 @@ var app = {
             return false;
         }
     },
-    setCustomFieldsForm: function(reg_event_id, target){
+    setCustomFieldsForm: function( reg_event_id, record_id, target ){
         var formData = {
             'action': 'glm_members_admin_ajax',
             'glm_action': 'customFieldsFront',
             'option': 'displayForm',
             'fid': 'glm_reg_customfields_reg_event_attendee_' + reg_event_id,
-            'recordId': '1',
-            'parentFormId': 'abc-123',
+            'recordId': record_id,
+            'parentFormId': '',
             'formData': false
         };
         $.ajax({
@@ -406,11 +368,6 @@ var app = {
             $(target).html( formHtml );
         });
     },
-    saveCustomFieldsForm: function( formData, reg_event_id ){
-        console.log( 'SAVING FORW DATA' );
-        console.log( formData );
-        console.log( reg_event_id );
-    },
     {if $regEvent.time_specific.value}
         timeSpecific: true,
     {else}