Update the regClass for if not time specific.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Nov 2017 21:54:41 +0000 (16:54 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Nov 2017 21:54:41 +0000 (16:54 -0500)
When not time Specific the event with class should just add the regTime
into the class.

js/frontRegApp.js
js/views/front/regClass.js

index 937caad..ce952e8 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 );
             }
         }
@@ -560,7 +534,9 @@ app.Views.Front.RegClass = Backbone.View.extend({
         //     this.$('.glm-add-account').hide();
         // }
         if ( !app.timeSpecific ) {
-            this.$('.glm-add-new-account').show();
+            console.log('Should be showing the add attendee part now');
+            // this.$('.glm-add-new-account').show();
+            this.updateTimeSelection();
         } else {
             var sTime = this.model.get( 'selectedTime' );
             if ( !sTime ) {
@@ -625,7 +601,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 +1025,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 7d5333c..3450a0f 100644 (file)
@@ -78,7 +78,9 @@ app.Views.Front.RegClass = Backbone.View.extend({
         //     this.$('.glm-add-account').hide();
         // }
         if ( !app.timeSpecific ) {
-            this.$('.glm-add-new-account').show();
+            console.log('Should be showing the add attendee part now');
+            // this.$('.glm-add-new-account').show();
+            this.updateTimeSelection();
         } else {
             var sTime = this.model.get( 'selectedTime' );
             if ( !sTime ) {