Fixing issue with incorrect rate being used for adding registrants.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Nov 2017 20:24:19 +0000 (15:24 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Nov 2017 20:24:44 +0000 (15:24 -0500)
Fixed the mix up when setting up the calendar and then the regTime.
Was getting the incorrect time data.

js/frontRegApp.js
js/models/front/regClass.js
js/models/front/regEvent.js
js/views/front/regClass.js
js/views/front/regTime.js
models/admin/ajax/regFront/registrant.php
models/front/registrations/registration.php

index 937caad..bd22308 100644 (file)
@@ -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 );
index a45cb02..b0e0bef 100644 (file)
@@ -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;
-    //     }
-    // },
-
 });
index 195751c..20da9da 100644 (file)
@@ -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);
index 9b7a309..7d5333c 100644 (file)
@@ -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' ) );
             },
         });
     },
index 4cd379d..00979a3 100644 (file)
@@ -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 );
index c53744c..8e598ff 100644 (file)
@@ -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;
index c0958ba..97278f2 100644 (file)
                 }
             }
         }
+        // echo '<pre>$jsonClasses: ' . print_r( $jsonClasses, true ) . '</pre>';
 
         // echo '<pre>$regEvent: ' . print_r( $regEvent, true ) . '</pre>';