From 1ed170148da26bdc91e1240464c8312457f638a8 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 18 Oct 2017 15:06:58 -0400 Subject: [PATCH] Updating the regEvent page with new additions. Restructured how the regEvent form is adding registrants per data changes from the cart. --- js/frontRegApp.js | 75 ++++++++++++++++++--- js/views/front/regClass.js | 39 ++++++++--- js/views/front/regRequestRegistrant.js | 36 +++++++++- models/admin/ajax/regFront/registrant.php | 6 -- models/front/registrations/registration.php | 29 +++++--- views/front/registrations/registration.html | 8 ++- 6 files changed, 151 insertions(+), 42 deletions(-) diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 6699f4f..d946689 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -722,9 +722,35 @@ app.Views.Front.RegClass = Backbone.View.extend({ return this; }, + setCalendar: function(){ + var times = this.model.get( 'times' ); + $('#eventCalendar').fullCalendar({ + events: function(start, end, timezone, callback) { + var events = []; + _.each( times, function( time ){ + events.push({ + title: time.name, + start: time.start_datetime.datetime, + end: time.end_datetime.datetime, + allday: time.all_day.value, + reg_time: time.id, + }); + }); + callback( events ); + }, + defaultDate: startTime, + timeFormat: 'h:mma', + fixedWeekCount: false, + eventClick: function( calEvent, jsEvent, view ){ + $('.fc-event').css( 'background-color', '#3a67ad' ); + $(this).css( 'background-color', 'red' ); + jQuery( '#add_reg-select-time' ).val( calEvent.reg_time ); + jQuery( '#add_reg-select-time-display' ).html( calEvent.start.format( 'L LT' ) ); + }, + }); + }, + deleteOne: function( item ){ - console.log('Delete on regClass registrant called'); - // this.model.registrants.remove( item ); this.render(); }, @@ -746,7 +772,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ // If the model is already there then don't add var findById = this.model.registrants.where({account: accountId}); if ( findById.length === 0 ) { - console.log( findById.length ); // create the regRequestRegistrant for the account registrant = new app.Models.Front.RegRequestRegistrant({ account: accountId, @@ -762,8 +787,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ this.newRegAccountView = new app.Views.Front.RegistrantForm({model: registrant}); this.$el.append( this.newRegAccountView.render().el ); if ( app.timeSpecific ) { - app.calendar = app.initFullCalendar( true, false ); - // console.log('called app.initFullCalendar()'); + this.setCalendar(); } } } @@ -834,14 +858,12 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, addNewAccount: function(){ - console.log( 'Add New Account Called' ); // 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 ) { - app.calendar = app.initFullCalendar( true, false ); - console.log('called app.initFullCalendar()'); + this.setCalendar(); } }, @@ -873,7 +895,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ data: 'email=' + this.$newEmail.val().trim() }) .done(function(account){ - //console.log(account); // Check for id and email if ( account.validEmail !== true ) { // If not found then nothing was found for that email. @@ -1005,6 +1026,38 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ }, + setCalendar: function(){ + var modelId = this.model.get( 'id' ); + // Find the class for this registrant + // Use findWhere to get the correct regClass + var regLevel = regEvent.classes.findWhere({ id: this.model.get( 'reg_class' ) }); + // console.log( regLevel ); + var times = regLevel.get( 'times' ); + $( '#eventCalendar-' + modelId ).fullCalendar({ + events: function(start, end, timezone, callback) { + var events = []; + _.each( times, function( time ){ + events.push({ + title: time.name, + start: time.start_datetime.datetime, + end: time.end_datetime.datetime, + allday: time.all_day.value, + reg_time: time.id, + }); + }); + callback( events ); + }, + defaultDate: startTime, + timeFormat: 'h:mma', + fixedWeekCount: false, + eventClick: function( calEvent, jsEvent, view ){ + $('.fc-event').css( 'background-color', '#3a67ad' ); + $(this).css( 'background-color', 'red' ); + jQuery( '#reg-time-' + modelId ).val( calEvent.reg_time ); + jQuery( '#reg-time-display-' + modelId ).html( calEvent.start.format( 'L LT' ) ); + }, + }); + }, cancelEdit: function(){ console.log( 'cancel edit' ); this.$('.reg-edit-form').hide(); @@ -1014,8 +1067,8 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ this.$('.reg-edit-form').show(); if ( app.timeSpecific === true ) { this.$('#reg-select-time').val( this.model.get( 'reg_time' ) ); - app.initFullCalendar( false, this.model.get( 'id' ) ); - console.log( this.model.get( 'reg_time' ) ); + console.log( 'this.setCalendar called' ); + this.setCalendar(); } }, diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index 0f15aa6..ab545cd 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -32,9 +32,35 @@ app.Views.Front.RegClass = Backbone.View.extend({ return this; }, + setCalendar: function(){ + var times = this.model.get( 'times' ); + $('#eventCalendar').fullCalendar({ + events: function(start, end, timezone, callback) { + var events = []; + _.each( times, function( time ){ + events.push({ + title: time.name, + start: time.start_datetime.datetime, + end: time.end_datetime.datetime, + allday: time.all_day.value, + reg_time: time.id, + }); + }); + callback( events ); + }, + defaultDate: startTime, + timeFormat: 'h:mma', + fixedWeekCount: false, + eventClick: function( calEvent, jsEvent, view ){ + $('.fc-event').css( 'background-color', '#3a67ad' ); + $(this).css( 'background-color', 'red' ); + jQuery( '#add_reg-select-time' ).val( calEvent.reg_time ); + jQuery( '#add_reg-select-time-display' ).html( calEvent.start.format( 'L LT' ) ); + }, + }); + }, + deleteOne: function( item ){ - console.log('Delete on regClass registrant called'); - // this.model.registrants.remove( item ); this.render(); }, @@ -56,7 +82,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ // If the model is already there then don't add var findById = this.model.registrants.where({account: accountId}); if ( findById.length === 0 ) { - console.log( findById.length ); // create the regRequestRegistrant for the account registrant = new app.Models.Front.RegRequestRegistrant({ account: accountId, @@ -72,8 +97,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ this.newRegAccountView = new app.Views.Front.RegistrantForm({model: registrant}); this.$el.append( this.newRegAccountView.render().el ); if ( app.timeSpecific ) { - app.calendar = app.initFullCalendar( true, false ); - // console.log('called app.initFullCalendar()'); + this.setCalendar(); } } } @@ -144,14 +168,12 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, addNewAccount: function(){ - console.log( 'Add New Account Called' ); // 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 ) { - app.calendar = app.initFullCalendar( true, false ); - console.log('called app.initFullCalendar()'); + this.setCalendar(); } }, @@ -183,7 +205,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ data: 'email=' + this.$newEmail.val().trim() }) .done(function(account){ - //console.log(account); // Check for id and email if ( account.validEmail !== true ) { // If not found then nothing was found for that email. diff --git a/js/views/front/regRequestRegistrant.js b/js/views/front/regRequestRegistrant.js index 2b8596e..adcfb1e 100644 --- a/js/views/front/regRequestRegistrant.js +++ b/js/views/front/regRequestRegistrant.js @@ -60,6 +60,38 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ }, + setCalendar: function(){ + var modelId = this.model.get( 'id' ); + // Find the class for this registrant + // Use findWhere to get the correct regClass + var regLevel = regEvent.classes.findWhere({ id: this.model.get( 'reg_class' ) }); + // console.log( regLevel ); + var times = regLevel.get( 'times' ); + $( '#eventCalendar-' + modelId ).fullCalendar({ + events: function(start, end, timezone, callback) { + var events = []; + _.each( times, function( time ){ + events.push({ + title: time.name, + start: time.start_datetime.datetime, + end: time.end_datetime.datetime, + allday: time.all_day.value, + reg_time: time.id, + }); + }); + callback( events ); + }, + defaultDate: startTime, + timeFormat: 'h:mma', + fixedWeekCount: false, + eventClick: function( calEvent, jsEvent, view ){ + $('.fc-event').css( 'background-color', '#3a67ad' ); + $(this).css( 'background-color', 'red' ); + jQuery( '#reg-time-' + modelId ).val( calEvent.reg_time ); + jQuery( '#reg-time-display-' + modelId ).html( calEvent.start.format( 'L LT' ) ); + }, + }); + }, cancelEdit: function(){ console.log( 'cancel edit' ); this.$('.reg-edit-form').hide(); @@ -69,8 +101,8 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ this.$('.reg-edit-form').show(); if ( app.timeSpecific === true ) { this.$('#reg-select-time').val( this.model.get( 'reg_time' ) ); - app.initFullCalendar( false, this.model.get( 'id' ) ); - console.log( this.model.get( 'reg_time' ) ); + console.log( 'this.setCalendar called' ); + this.setCalendar(); } }, diff --git a/models/admin/ajax/regFront/registrant.php b/models/admin/ajax/regFront/registrant.php index 92b3d6e..5b48354 100644 --- a/models/admin/ajax/regFront/registrant.php +++ b/models/admin/ajax/regFront/registrant.php @@ -158,7 +158,6 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations ); $data = array( 'reg_event' => $modelData['reg_event'], - 'event_name' => $modelData['event_name'], 'event_datetime' => $modelData['event_datetime'], 'reg_request' => $modelData['reg_request'], 'reg_request_event' => $regRequestEventId, @@ -166,7 +165,6 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations ); $dataFormat = array( '%d', // reg_event - '%s', // event_name '%s', // event_datetime '%d', // reg_request '%d', // reg_request_event @@ -214,7 +212,6 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations ); $data = array( 'reg_event' => $modelData['reg_event'], - 'event_name' => $modelData['event_name'], 'event_datetime' => $modelData['event_datetime'], 'reg_request' => $modelData['reg_request'], 'reg_request_event' => $regRequestEventId, @@ -227,7 +224,6 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations ) ; $dataFormat = array( '%d', // reg_event - '%s', // event_name '%s', // event_datetime '%d', // reg_request '%d', // reg_request_event @@ -341,7 +337,6 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations $data = array( 'account' => $accountId, 'reg_event' => $modelData['reg_event'], - 'event_name' => $modelData['event_name'], 'reg_time' => $modelData['reg_time'], // 'event_datetime' => $modelData['event_datetime'], 'reg_request' => $modelData['reg_request'], @@ -354,7 +349,6 @@ class GlmMembersAdmin_registrations_ajax_registrant extends GlmDataRegistrations $dataFormat = array( '%d', // account '%d', // reg_event - '%s', // event_name '%s', // reg_time // '%s', // event_datetime '%d', // reg_request diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index 1ea17e0..dd3c027 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -141,7 +141,6 @@ // Need to refresh the page } - // echo '
$cart: ' . print_r( $cart, true ) . '
'; // If we have a good cart, convert to JSON for view if ($haveCart) { @@ -155,7 +154,7 @@ $this->postProcAddedEventData = true; $regEvent = $this->getEventForRegistration($eventRegID); -//echo "
".print_r($regEvent,1)."
"; + // echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; // Create an $event array with the event data. $event = array( @@ -165,7 +164,7 @@ 'event_code' => $regEvent['event_code'], 'descr' => $regEvent['descr'], 'time_specific' => $regEvent['time_specific']['value'], - 'reg_time' => $regEvent['reg_time'], + 'reg_time' => null, //$regEvent['reg_time'], 'attendee_max' => $regEvent['attendee_max'], 'attendee_max_per_reg' => $regEvent['attendee_max_per_reg'], 'reg_hold_minutes' => $regEvent['reg_hold_minutes'], @@ -179,24 +178,28 @@ $eventData = array(); - // Build the Class array of json objects for the classes. + // Build the Class array of JSON objects for the classes. $jsonClasses = array(); + $regClasses = array(); if ( isset( $regEvent['reg_class'] ) && is_array( $regEvent['reg_class'] ) ) { // Loop through the $regEvent['reg_class'] array to build $rClass array + // If the event is Time Specific then the reg_class need to have + // times array. If it doesn't then there's no current registration + // allowed for that event. foreach ( $regEvent['reg_class'] as $rClass ) { // Pull the rate data - if ( isset( $rClass['reg_rate'] ) && is_array( $rClass['reg_rate'] ) ) { - foreach ( $rClass['reg_rate'] as &$rate ) { + if ( isset( $rClass['times'] ) && is_array( $rClass['times'] ) ) { + foreach ( $rClass['times'] as &$time ) { $rClass['loggedIn'] = ( isset($_SESSION['LoginAccount']) ) ? true : false; - $rClass['reg_rate_id'] = $rate['id']; - $rClass['reg_rate_name'] = $rate['name']; - $rClass['reg_rate_base_price'] = $rate['base_rate']; - $rClass['reg_rate_per_reg'] = $rate['per_registrant']; + $rClass['reg_rate_id'] = $time['id']; + $rClass['reg_rate_name'] = $time['name']; + $rClass['reg_rate_base_price'] = $time['base_rate']; + $rClass['reg_rate_per_reg'] = $time['per_registrant']; } + $jsonClasses[] = json_encode( $rClass, JSON_NUMERIC_CHECK ); } - $jsonClasses[] = json_encode( $rClass, JSON_NUMERIC_CHECK ); } } @@ -219,6 +222,7 @@ $registrants = array(); + echo '
$cart: ' . print_r( $cart, true ) . '
'; // Looping through to grab out registrants from the cart. if ( isset( $cart['events'] ) && is_array( $cart['events'] ) ) { @@ -282,6 +286,7 @@ // Setup the registrant for this level. $registrant['class_id'] = $classId; + $registrant['reg_class'] = $classId; $registrant['email'] = $email; $registrant['validated'] = $accountData['validated']; $registrant['addr1'] = $accountData['addr1']; @@ -303,6 +308,8 @@ } // - End loop through events. } + // echo '
$registrants: ' . print_r( $registrants, true ) . '
'; + // echo '
$regEvent: ' . print_r( $regEvent, true ) . '
'; // Compile template data diff --git a/views/front/registrations/registration.html b/views/front/registrations/registration.html index 12940fe..baf75a4 100644 --- a/views/front/registrations/registration.html +++ b/views/front/registrations/registration.html @@ -167,7 +167,7 @@
{/literal}{if $regEvent.time_specific.value}
-
+
{/if}{literal} {/literal}{if $regEvent.time_specific.value} @@ -201,7 +201,7 @@ {/literal}{if $regEvent.time_specific.value}
Selected Time: {literal}<%= reg_time_text %>{/literal} - +
{/if}{literal}
@@ -235,12 +235,13 @@ var app = { }, {if $regEvent.time_specific.value} initFullCalendar: function( isNew, idVal ){ + return false; if ({$regEvent.time_specific.value}) { var calendar = $('#eventCalendar').fullCalendar({ {if $regEvent} events: [ {$sep = ''} - {foreach $regEvent.reg_time as $t} + {foreach $regEvent.reg_class.times as $t} {$sep}{ {if $t.attendee_max == 0} title : 'unlimited', @@ -283,6 +284,7 @@ var app = { var regEvent = ''; var cart = ''; var loginAccount = ''; +var startTime = '{$regEvent.firstTime.start_time.datetime}'; jQuery(function($){ {if $isNewCart} location.reload( true ); -- 2.17.1