From 243e8ea354ef311515b1a4213f502145e3acdd35 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 1 Nov 2017 10:11:33 -0400 Subject: [PATCH] Working on the time selection Passing the selected time to the new registrant model being created. --- js/frontRegApp.js | 46 +++++++++++++++------ js/views/front/regClass.js | 46 +++++++++++++++------ models/front/registrations/registration.php | 4 +- views/front/registrations/registration.html | 15 +++++-- 4 files changed, 80 insertions(+), 31 deletions(-) diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 44aeca9..35120d0 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -426,7 +426,13 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, updateTimeSelection: function(){ - this.model.set({ selectedTime: this.$('.timeSelection:checked').val() }); + // Need to remove the newRegModal and views + if ( this.newRegAccount ) { + this.newRegAccount.destroy(); + this.newRegAccountView.remove(); + } + this.model.set({ selectedTime: parseInt( this.$('.timeSelection:checked').val() ) }); + console.log( this.$('.timeSelection:checked').val()); }, render: function(){ @@ -447,6 +453,16 @@ app.Views.Front.RegClass = Backbone.View.extend({ if ( loginAccount != '' && this.model.hasMe() ) { this.$('.glm-add-account').hide(); } + if ( !app.timeSpecific ) { + this.$('.glm-add-new-account').show(); + } else { + var sTime = this.model.get( 'selectedTime' ); + if ( !sTime ) { + this.$('.glm-add-new-account').hide(); + } else { + this.$('.glm-add-new-account').show(); + } + } return this; }, @@ -457,7 +473,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ var testDate = new Date( time.start_datetime.datetime ); timeParts.push( {id: time.id,date: testDate} ); }); - console.log( timeParts ); + // console.log( timeParts ); return timeParts; }, @@ -540,25 +556,28 @@ app.Views.Front.RegClass = Backbone.View.extend({ var state = this.$('.add_reg_state').val().trim(); var zip = this.$('.add_reg_zip').val().trim(); var country = this.$('.add_reg_country').val().trim(); + if ( app.timeSpecific ) { + var sTime = this.model.get( 'selectedTime' ); + } else { + var sTime = null; + } if ( this.$('#add_reg-select-time').length ) { - var rTime = this.$('#add_reg-select-time').val().trim(); var times = this.model.get( 'times' ); var rateId = null; // Setup the needed reg_rate _.each( times, function( time ){ - if ( time.id == rTime ) { + if ( time.id == sTime ) { rateId = time.rate_id; } } ); } else { - var rTime = null; var times = this.model.get( 'times' ); var rateId = null; _.each( times, function( time ){ rateId = time.rate_id; } ); } - if ( app.timeSpecific && !rTime ) { + if ( app.timeSpecific && !sTime ) { alert( 'You must select a time!' ); return; } @@ -579,7 +598,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ this.model.registrants.create({ option: 'add', reg_request: regRequest.id, - reg_time: rTime, + reg_time: sTime, reg_event: this.model.get( 'reg_event' ), reg_class: this.model.get( 'id' ), event_name: regEvent.get( 'event_name' ), @@ -597,13 +616,13 @@ app.Views.Front.RegClass = Backbone.View.extend({ } // this.newRegAccount.destroy(); this.newRegAccountView.remove(); - app.calendar = false; + // app.calendar = false; }, cancelAddNew: function(){ // this.newRegAccount.destroy(); this.newRegAccountView.remove(); - app.calendar = false; + // app.calendar = false; if ( loginAccount != '' && this.model.hasMe() ) { this.$('.glm-add-account').hide(); // console.log('hiding'); @@ -615,12 +634,13 @@ app.Views.Front.RegClass = Backbone.View.extend({ addNewAccount: function(){ // Create the new Registrant View - this.newRegAccount = new app.Models.Front.RegRequestRegistrant(); - this.newRegAccountView = new app.Views.Front.RegistrantForm({model: this.newRegAccount}); - this.$el.append( this.newRegAccountView.render().el ); if ( app.timeSpecific ) { - // this.setCalendar(); + this.newRegAccount = new app.Models.Front.RegRequestRegistrant({ reg_time: this.model.get( 'selectedTime' ) }); + } else { + this.newRegAccount = new app.Models.Front.RegRequestRegistrant(); } + this.newRegAccountView = new app.Views.Front.RegistrantForm({model: this.newRegAccount}); + this.$el.append( this.newRegAccountView.render().el ); }, toggleClassOpen: function(){ diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index 162fa0a..305954a 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -27,7 +27,13 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, updateTimeSelection: function(){ - this.model.set({ selectedTime: this.$('.timeSelection:checked').val() }); + // Need to remove the newRegModal and views + if ( this.newRegAccount ) { + this.newRegAccount.destroy(); + this.newRegAccountView.remove(); + } + this.model.set({ selectedTime: parseInt( this.$('.timeSelection:checked').val() ) }); + console.log( this.$('.timeSelection:checked').val()); }, render: function(){ @@ -48,6 +54,16 @@ app.Views.Front.RegClass = Backbone.View.extend({ if ( loginAccount != '' && this.model.hasMe() ) { this.$('.glm-add-account').hide(); } + if ( !app.timeSpecific ) { + this.$('.glm-add-new-account').show(); + } else { + var sTime = this.model.get( 'selectedTime' ); + if ( !sTime ) { + this.$('.glm-add-new-account').hide(); + } else { + this.$('.glm-add-new-account').show(); + } + } return this; }, @@ -58,7 +74,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ var testDate = new Date( time.start_datetime.datetime ); timeParts.push( {id: time.id,date: testDate} ); }); - console.log( timeParts ); + // console.log( timeParts ); return timeParts; }, @@ -141,25 +157,28 @@ app.Views.Front.RegClass = Backbone.View.extend({ var state = this.$('.add_reg_state').val().trim(); var zip = this.$('.add_reg_zip').val().trim(); var country = this.$('.add_reg_country').val().trim(); + if ( app.timeSpecific ) { + var sTime = this.model.get( 'selectedTime' ); + } else { + var sTime = null; + } if ( this.$('#add_reg-select-time').length ) { - var rTime = this.$('#add_reg-select-time').val().trim(); var times = this.model.get( 'times' ); var rateId = null; // Setup the needed reg_rate _.each( times, function( time ){ - if ( time.id == rTime ) { + if ( time.id == sTime ) { rateId = time.rate_id; } } ); } else { - var rTime = null; var times = this.model.get( 'times' ); var rateId = null; _.each( times, function( time ){ rateId = time.rate_id; } ); } - if ( app.timeSpecific && !rTime ) { + if ( app.timeSpecific && !sTime ) { alert( 'You must select a time!' ); return; } @@ -180,7 +199,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ this.model.registrants.create({ option: 'add', reg_request: regRequest.id, - reg_time: rTime, + reg_time: sTime, reg_event: this.model.get( 'reg_event' ), reg_class: this.model.get( 'id' ), event_name: regEvent.get( 'event_name' ), @@ -198,13 +217,13 @@ app.Views.Front.RegClass = Backbone.View.extend({ } // this.newRegAccount.destroy(); this.newRegAccountView.remove(); - app.calendar = false; + // app.calendar = false; }, cancelAddNew: function(){ // this.newRegAccount.destroy(); this.newRegAccountView.remove(); - app.calendar = false; + // app.calendar = false; if ( loginAccount != '' && this.model.hasMe() ) { this.$('.glm-add-account').hide(); // console.log('hiding'); @@ -216,12 +235,13 @@ app.Views.Front.RegClass = Backbone.View.extend({ addNewAccount: function(){ // Create the new Registrant View - this.newRegAccount = new app.Models.Front.RegRequestRegistrant(); - this.newRegAccountView = new app.Views.Front.RegistrantForm({model: this.newRegAccount}); - this.$el.append( this.newRegAccountView.render().el ); if ( app.timeSpecific ) { - // this.setCalendar(); + this.newRegAccount = new app.Models.Front.RegRequestRegistrant({ reg_time: this.model.get( 'selectedTime' ) }); + } else { + this.newRegAccount = new app.Models.Front.RegRequestRegistrant(); } + this.newRegAccountView = new app.Views.Front.RegistrantForm({model: this.newRegAccount}); + this.$el.append( this.newRegAccountView.render().el ); }, toggleClassOpen: function(){ diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index 613afea..5ac79ed 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -226,7 +226,7 @@ $registrants = array(); - // echo '
$cart: ' . print_r( $cart, true ) . '
'; + echo '
$cart: ' . print_r( $cart, true ) . '
'; // Looping through to grab out registrants from the cart. if ( isset( $cart['events'] ) && is_array( $cart['events'] ) ) { @@ -313,7 +313,7 @@ } // - End loop through events. } - // echo '
$registrants: ' . print_r( $registrants, true ) . '
'; + echo '
$registrants: ' . print_r( $registrants, true ) . '
'; // Compile template data $templateData = array( diff --git a/views/front/registrations/registration.html b/views/front/registrations/registration.html index d87b032..b556234 100644 --- a/views/front/registrations/registration.html +++ b/views/front/registrations/registration.html @@ -47,7 +47,13 @@
<%= name %> - <%= reg_count %> {/literal}{$terms.reg_term_attendee_plur_cap}{literal} + <%= reg_count %> + <% if ( reg_count == 1 ) { %> + {/literal}{$terms.reg_term_attendee_cap}{literal} + <% } else { %> + {/literal}{$terms.reg_term_attendee_plur_cap}{literal} + <% } %> +
<%- descr %>
@@ -58,7 +64,11 @@ Select a time <% _.each( this.getTimeArray(), function(time){ %> <% }); %>
@@ -215,7 +225,6 @@ var app = { {else} timeSpecific: false, {/if} - calendar: false, }; var regEvent = ''; var cart = ''; -- 2.17.1