From cb35be26bbba20af23f45ae971f4697de4fa0597 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 14 Nov 2017 15:24:19 -0500 Subject: [PATCH] Fixing issue with incorrect rate being used for adding registrants. Fixed the mix up when setting up the calendar and then the regTime. Was getting the incorrect time data. --- js/frontRegApp.js | 54 ++++++--------------- js/models/front/regClass.js | 20 -------- js/models/front/regEvent.js | 8 ++- js/views/front/regClass.js | 25 +++------- js/views/front/regTime.js | 1 + models/admin/ajax/regFront/registrant.php | 2 +- models/front/registrations/registration.php | 1 + 7 files changed, 30 insertions(+), 81 deletions(-) diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 937caad..bd22308 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -109,26 +109,6 @@ app.Models.Front.RegClass = Backbone.Model.extend({ this.regTimes = new app.Collections.Front.RegTimes( [] ); }, - // setRegistrants: function( registrants ) { - // this.registrants.reset( registrants ); - // }, - - // Check to see if the current login user in the list of registrants - // hasMe: function() { - // return false; - // if ( loginAccount ) { - // var foundMe = this.registrants.findWhere({ account: loginAccount.get( 'id' ) }); - // if ( foundMe ) { - // return true; - // } else { - // return false; - // } - // return true; - // } else { - // return false; - // } - // }, - }); // js/models/regEvent.js @@ -165,7 +145,13 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ var foundClass = this.classes.findWhere({ id: registrants[i].class_id }); // console.log(foundClass); if ( foundClass != undefined ) { - var foundRegTime = _.findWhere(app.Times, { id: registrants[i].reg_time }); + // Try looking through the class times + // console.log(foundClass); + // var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time}); + var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time }); + // console.log(foundRegTime); + // return; + // var foundRegTime = _.findWhere(app.Times, { id: registrants[i].reg_time }); // Now add the time if needed var hasRegTime = _.findWhere(foundClass, { reg_time: foundRegTime.id }); // console.log(hasRegTime); @@ -490,11 +476,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ events: { 'click .addRegistrant': 'newEntry', - // 'click .glm-add-account': 'addAccount', - // 'click .glm-add-new-account': 'addNewAccount', - // 'click .add-new-registrant': 'addNew', - // 'click .add-new-registrant-cancel': 'cancelAddNew', - // 'click .timeSelection': 'updateTimeSelection', 'click .fc-event-container': 'updateTimeSelection', 'click .show-hide-address': 'toggleClass', }, @@ -504,31 +485,24 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, updateTimeSelection: function(e){ - console.log('updateTimeSelection called'); var timeId = this.$('.timeSelection').val().trim(); - console.log( timeId ); // Check to see if the time is already in the collection // If it is then do nothing - console.log(this.model.regTimes.length); - var findRegTime = this.model.regTimes.where({ id: timeId }); - console.log(findRegTime.length); + if ( findRegTime.length == 0 ) { - console.log('regTime not found, creating one.'); this.model.set({ selectedTime: timeId }); // Add the RegTime model/view into this view - // console.log( app.Times ); - var targetTime = null; - for ( var i = 0; i < app.Times.length; i++ ) { - if ( app.Times[i].id == timeId ) { - targetTime = app.Times[i]; + var classTimes = this.model.get('times'); + var targetTime = {}; + for ( var key in classTimes ) { + if ( classTimes[key].id == timeId ) { + targetTime = classTimes[key]; } } if ( targetTime ) { var selectedTime = new app.Models.Front.RegTime( targetTime ); selectedTime.set({parent: this.model}); - console.log('creating time entry'); - console.log(selectedTime); this.model.regTimes.create( selectedTime ); } } @@ -625,7 +599,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ $('.fc-event').css( 'background-color', '#3a67ad' ); $(this).css( 'background-color', 'red' ); jQuery( '.timeSelection' ).val( calEvent.reg_time ); - // jQuery( '#add_reg-select-time-display' ).html( calEvent.start.format( 'L LT' ) ); }, }); }, @@ -1050,6 +1023,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ var times = this.model.get( 'times' ); } var rateId = this.model.get( 'rate_id' ); + console.log(rateId); if ( !rateId ) { // console.log( 'No rate id!' ); // console.log( sTime ); diff --git a/js/models/front/regClass.js b/js/models/front/regClass.js index a45cb02..b0e0bef 100644 --- a/js/models/front/regClass.js +++ b/js/models/front/regClass.js @@ -24,24 +24,4 @@ app.Models.Front.RegClass = Backbone.Model.extend({ this.regTimes = new app.Collections.Front.RegTimes( [] ); }, - // setRegistrants: function( registrants ) { - // this.registrants.reset( registrants ); - // }, - - // Check to see if the current login user in the list of registrants - // hasMe: function() { - // return false; - // if ( loginAccount ) { - // var foundMe = this.registrants.findWhere({ account: loginAccount.get( 'id' ) }); - // if ( foundMe ) { - // return true; - // } else { - // return false; - // } - // return true; - // } else { - // return false; - // } - // }, - }); diff --git a/js/models/front/regEvent.js b/js/models/front/regEvent.js index 195751c..20da9da 100644 --- a/js/models/front/regEvent.js +++ b/js/models/front/regEvent.js @@ -32,7 +32,13 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ var foundClass = this.classes.findWhere({ id: registrants[i].class_id }); // console.log(foundClass); if ( foundClass != undefined ) { - var foundRegTime = _.findWhere(app.Times, { id: registrants[i].reg_time }); + // Try looking through the class times + // console.log(foundClass); + // var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time}); + var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time }); + // console.log(foundRegTime); + // return; + // var foundRegTime = _.findWhere(app.Times, { id: registrants[i].reg_time }); // Now add the time if needed var hasRegTime = _.findWhere(foundClass, { reg_time: foundRegTime.id }); // console.log(hasRegTime); diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index 9b7a309..7d5333c 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -20,11 +20,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ events: { 'click .addRegistrant': 'newEntry', - // 'click .glm-add-account': 'addAccount', - // 'click .glm-add-new-account': 'addNewAccount', - // 'click .add-new-registrant': 'addNew', - // 'click .add-new-registrant-cancel': 'cancelAddNew', - // 'click .timeSelection': 'updateTimeSelection', 'click .fc-event-container': 'updateTimeSelection', 'click .show-hide-address': 'toggleClass', }, @@ -34,31 +29,24 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, updateTimeSelection: function(e){ - console.log('updateTimeSelection called'); var timeId = this.$('.timeSelection').val().trim(); - console.log( timeId ); // Check to see if the time is already in the collection // If it is then do nothing - console.log(this.model.regTimes.length); - var findRegTime = this.model.regTimes.where({ id: timeId }); - console.log(findRegTime.length); + if ( findRegTime.length == 0 ) { - console.log('regTime not found, creating one.'); this.model.set({ selectedTime: timeId }); // Add the RegTime model/view into this view - // console.log( app.Times ); - var targetTime = null; - for ( var i = 0; i < app.Times.length; i++ ) { - if ( app.Times[i].id == timeId ) { - targetTime = app.Times[i]; + var classTimes = this.model.get('times'); + var targetTime = {}; + for ( var key in classTimes ) { + if ( classTimes[key].id == timeId ) { + targetTime = classTimes[key]; } } if ( targetTime ) { var selectedTime = new app.Models.Front.RegTime( targetTime ); selectedTime.set({parent: this.model}); - console.log('creating time entry'); - console.log(selectedTime); this.model.regTimes.create( selectedTime ); } } @@ -155,7 +143,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ $('.fc-event').css( 'background-color', '#3a67ad' ); $(this).css( 'background-color', 'red' ); jQuery( '.timeSelection' ).val( calEvent.reg_time ); - // jQuery( '#add_reg-select-time-display' ).html( calEvent.start.format( 'L LT' ) ); }, }); }, diff --git a/js/views/front/regTime.js b/js/views/front/regTime.js index 4cd379d..00979a3 100644 --- a/js/views/front/regTime.js +++ b/js/views/front/regTime.js @@ -63,6 +63,7 @@ app.Views.Front.RegTime = Backbone.View.extend({ var times = this.model.get( 'times' ); } var rateId = this.model.get( 'rate_id' ); + console.log(rateId); if ( !rateId ) { // console.log( 'No rate id!' ); // console.log( sTime ); diff --git a/models/admin/ajax/regFront/registrant.php b/models/admin/ajax/regFront/registrant.php index c53744c..8e598ff 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; diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index c0958ba..97278f2 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -218,6 +218,7 @@ } } } + // echo '
$jsonClasses: ' . print_r( $jsonClasses, true ) . '
'; // echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; -- 2.17.1