Updating the regEvent page with new additions.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 18 Oct 2017 19:06:58 +0000 (15:06 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 18 Oct 2017 19:06:58 +0000 (15:06 -0400)
Restructured how the regEvent form is adding registrants per data
changes from the cart.

js/frontRegApp.js
js/views/front/regClass.js
js/views/front/regRequestRegistrant.js
models/admin/ajax/regFront/registrant.php
models/front/registrations/registration.php
views/front/registrations/registration.html

index 6699f4f..d946689 100644 (file)
@@ -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();
         }
     },
 
index 0f15aa6..ab545cd 100644 (file)
@@ -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.
index 2b8596e..adcfb1e 100644 (file)
@@ -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();
         }
     },
 
index 92b3d6e..5b48354 100644 (file)
@@ -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
index 1ea17e0..dd3c027 100644 (file)
             // Need to refresh the page
 
         }
-        // echo '<pre>$cart: ' . print_r( $cart, true ) . '</pre>';
 
         // If we have a good cart, convert to JSON for view
         if ($haveCart) {
             $this->postProcAddedEventData = true;
             $regEvent = $this->getEventForRegistration($eventRegID);
 
-//echo "<pre>".print_r($regEvent,1)."</pre>";
+            // echo '<pre>$regEvent: ' . print_r( $regEvent, true ) . '</pre>';
 
             // Create an $event array with the event data.
             $event = array(
                 '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'],
 
         $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 );
             }
         }
 
 
         $registrants = array();
 
+        echo '<pre>$cart: ' . print_r( $cart, true ) . '</pre>';
         // Looping through to grab out registrants from the cart.
         if ( isset( $cart['events'] ) && is_array( $cart['events'] ) ) {
 
 
                                         // 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'];
             } // - End loop through events.
         }
 
+        // echo '<pre>$registrants: ' . print_r( $registrants, true ) . '</pre>';
+
         // echo '<pre>$regEvent: ' . print_r( $regEvent, true ) . '</pre>';
 
         // Compile template data
index 12940fe..baf75a4 100644 (file)
         <div class="reg-edit-form">
             {/literal}{if $regEvent.time_specific.value}
                 <div style="float: right; width: 48%;">
-                    <div id="eventCalendar" style="width: 90%;"></div>
+                    <div id="eventCalendar-{literal}<%- id %>{/literal}" style="width: 90%;"></div>
                 </div>
             {/if}{literal}
             {/literal}{if $regEvent.time_specific.value}
             {/literal}{if $regEvent.time_specific.value}
                 <div>
                     Selected Time: <span id="reg-time-display-{literal}<%= id %>{/literal}">{literal}<%= reg_time_text %>{/literal}</span>
-                    <input type="hidden" id="reg-time-{literal}<%= id %>{/literal}">
+                    <input type="hidden" id="reg-time-{literal}<%= id %>{/literal}" value="{literal}<%- reg_time %>{/literal}">
                 </div>
             {/if}{literal}
             <div>
@@ -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 );