From 674924f92dcebe4cfc159c67e3e2832ab9447375 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Sun, 17 Dec 2017 15:03:30 -0500 Subject: [PATCH] working on getting custom field data to save. so far not working using the apply_filters. --- gulpfile.js | 5 +- js/collections/front/regRequestRegistrants.js | 1 + js/frontRegApp.js | 67 ++++++++++--------- js/models/front/regClass.js | 2 +- js/models/front/regEvent.js | 25 ++++--- js/views/front/regClass.js | 8 +-- js/views/front/regRequestRegistrant.js | 2 +- js/views/front/regTime.js | 27 ++++---- js/views/front/registrantForm.js | 2 +- models/admin/ajax/regFront/registrant.php | 7 +- views/front/registrations/registration.html | 55 ++------------- 11 files changed, 89 insertions(+), 112 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9c8254f..17baa4d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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/')); }); diff --git a/js/collections/front/regRequestRegistrants.js b/js/collections/front/regRequestRegistrants.js index 6658715..530f370 100644 --- a/js/collections/front/regRequestRegistrants.js +++ b/js/collections/front/regRequestRegistrants.js @@ -14,4 +14,5 @@ app.Collections.Front.RegRequestRegistrants = Backbone.Collection.extend({ return 1; } }, + }); diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 181fa19..af33b67 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -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; }, diff --git a/js/models/front/regClass.js b/js/models/front/regClass.js index b8e0fd8..d875e27 100644 --- a/js/models/front/regClass.js +++ b/js/models/front/regClass.js @@ -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( ); }, }); diff --git a/js/models/front/regEvent.js b/js/models/front/regEvent.js index e331743..e6d181d 100644 --- a/js/models/front/regEvent.js +++ b/js/models/front/regEvent.js @@ -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); + } } diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index a7e53b9..e85add5 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -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 ); diff --git a/js/views/front/regRequestRegistrant.js b/js/views/front/regRequestRegistrant.js index 60617c7..783e4fe 100644 --- a/js/views/front/regRequestRegistrant.js +++ b/js/views/front/regRequestRegistrant.js @@ -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; }, diff --git a/js/views/front/regTime.js b/js/views/front/regTime.js index 136f190..084449e 100644 --- a/js/views/front/regTime.js +++ b/js/views/front/regTime.js @@ -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(); }, }); diff --git a/js/views/front/registrantForm.js b/js/views/front/registrantForm.js index a43e982..5e0e702 100644 --- a/js/views/front/registrantForm.js +++ b/js/views/front/registrantForm.js @@ -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; }, diff --git a/models/admin/ajax/regFront/registrant.php b/models/admin/ajax/regFront/registrant.php index d930388..12fa5b7 100644 --- a/models/admin/ajax/regFront/registrant.php +++ b/models/admin/ajax/regFront/registrant.php @@ -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. } diff --git a/views/front/registrations/registration.html b/views/front/registrations/registration.html index 648545b..e698e4c 100644 --- a/views/front/registrations/registration.html +++ b/views/front/registrations/registration.html @@ -2,45 +2,7 @@ {* Underscore Templates for the Event Registration App *} {* Template for Logged in Account *} - -
*** TEST FORM REQUEST ***
-
Test Form Container
- - - - + {literal}