From b81660a89b4d72ba233c7401e7f175b550cdd874 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 14 Dec 2017 16:20:33 -0500 Subject: [PATCH] Adding comments to front end method for setting up registrants. Commenting this so I know what the setRegistrant code is trying to do --- js/frontRegApp.js | 15 ++++++++++++--- js/models/front/regEvent.js | 13 +++++++++++-- js/views/front/regClass.js | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 415f81f..6cff1e7 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -147,25 +147,34 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ // setClassRegistrants // To setup the registrant // Has to create a regTime first for the class - // Then is can add the registrant into that regTime model. + // Then is can add the registrant into that regTime model collection. setClassRegistrants: function( registrants ){ for ( var i = 0; i < registrants.length; i++ ) { + // Find the class that this registrant belongs to. var foundClass = this.classes.findWhere({ id: registrants[i].class_id }); + // console.log( foundClass ); if ( foundClass != undefined ) { // Try looking through the class times + // console.log( registrants[i].reg_time ); + // console.log( foundClass.get('times') ); + // Using the registrants reg_time lookup the regTime // var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time}); var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time }); + // console.log( foundRegTime ); if ( foundRegTime ) { + // Set the reg_event for this reg_time to the class we found for registrant foundRegTime.reg_event = foundClass.get('reg_event'); // Now add the time if needed + // First check to see if there's not one added already (regTime). var hasRegTime = _.findWhere(foundClass, { reg_time: foundRegTime.id }); if ( !hasRegTime ) { + // Here we have to add the regTime into the class. foundClass.regTimes.create( foundRegTime ); hasRegTime = foundClass.regTimes.findWhere({ id: foundRegTime.id }); hasRegTime.set({ parent: foundClass }); } - // Add the registrant + // Add the registrant to the regTime. var nRegTime = foundClass.regTimes.findWhere({id: hasRegTime.get('id')}); nRegTime.registrants.create( registrants[i] ); } @@ -503,7 +512,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ this.model.regTimes.create( newTime ); } - console.log( classTimes ); + // console.log( classTimes ); return this; }, diff --git a/js/models/front/regEvent.js b/js/models/front/regEvent.js index 3ef61ae..4ca8e08 100644 --- a/js/models/front/regEvent.js +++ b/js/models/front/regEvent.js @@ -31,25 +31,34 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ // setClassRegistrants // To setup the registrant // Has to create a regTime first for the class - // Then is can add the registrant into that regTime model. + // Then is can add the registrant into that regTime model collection. setClassRegistrants: function( registrants ){ for ( var i = 0; i < registrants.length; i++ ) { + // Find the class that this registrant belongs to. var foundClass = this.classes.findWhere({ id: registrants[i].class_id }); + // console.log( foundClass ); if ( foundClass != undefined ) { // Try looking through the class times + // console.log( registrants[i].reg_time ); + // console.log( foundClass.get('times') ); + // Using the registrants reg_time lookup the regTime // var foundRegTime = foundClass.regTimes.findWhere({id: registrants[i].reg_time}); var foundRegTime = _.findWhere(foundClass.get('times'), { id: registrants[i].reg_time }); + // console.log( foundRegTime ); if ( foundRegTime ) { + // Set the reg_event for this reg_time to the class we found for registrant foundRegTime.reg_event = foundClass.get('reg_event'); // Now add the time if needed + // First check to see if there's not one added already (regTime). var hasRegTime = _.findWhere(foundClass, { reg_time: foundRegTime.id }); if ( !hasRegTime ) { + // Here we have to add the regTime into the class. foundClass.regTimes.create( foundRegTime ); hasRegTime = foundClass.regTimes.findWhere({ id: foundRegTime.id }); hasRegTime.set({ parent: foundClass }); } - // Add the registrant + // Add the registrant to the regTime. var nRegTime = foundClass.regTimes.findWhere({id: hasRegTime.get('id')}); nRegTime.registrants.create( registrants[i] ); } diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index f7b9097..5bfb2c4 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -21,7 +21,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ this.model.regTimes.create( newTime ); } - console.log( classTimes ); + // console.log( classTimes ); return this; }, -- 2.17.1