From: Steve Sutton Date: Tue, 14 Nov 2017 17:21:44 +0000 (-0500) Subject: Another bug fix for rebuilding registrants in the app X-Git-Tag: v1.0.0^2~275 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=a144d3578fcb2d9972499840ca2dea7d89a36349;p=WP-Plugins%2Fglm-member-db-registrations.git Another bug fix for rebuilding registrants in the app When searching for and adding in the registrants. using findWhere now to return the object and not just an array. --- diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 5bc2da4..937caad 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -161,23 +161,24 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ setClassRegistrants: function( registrants ){ for ( var i = 0; i < registrants.length; i++ ) { + // console.log(registrants[i]); var foundClass = this.classes.findWhere({ id: registrants[i].class_id }); + // console.log(foundClass); if ( foundClass != undefined ) { - var foundRegTime = _.where(app.Times, { id: registrants[i].reg_time }); + 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); if ( !hasRegTime ) { - foundClass.regTimes.create( foundRegTime[0] ); + foundClass.regTimes.create( foundRegTime ); hasRegTime = foundClass.regTimes.findWhere({ id: foundRegTime.id }); + // console.log(hasRegTime); hasRegTime.set({ parent: foundClass }); } // Add the registrant var nRegTime = foundClass.regTimes.findWhere({id: hasRegTime.get('id')}); - // console.log( nRegTime ); nRegTime.registrants.create( registrants[i] ); - // var newReg = foundClass.registrants.pop(); - // foundClass.set({selectedTime: newReg.get( 'reg_time' ) }); } } }, @@ -599,11 +600,9 @@ app.Views.Front.RegClass = Backbone.View.extend({ if ( app.timeSpecific ) { this.setCalendar(); } - // console.log('called onRenderComplete'); }, setCalendar: function(){ - console.log( 'setting calendar' ); var times = this.model.get( 'times' ); $('#eventCalendar-' + this.model.get('id')).fullCalendar({ events: function(start, end, timezone, callback) { @@ -639,7 +638,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ // Check to make sure the loginAccount is not empty if ( loginAccount !== '' ) { this.$('.glm-add-account').hide(); - // console.log('hiding'); var regRequest = cart.get( 'request' ); var accountEmail = loginAccount.get( 'email' ); var accountId = loginAccount.get( 'id' ); @@ -741,16 +739,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ cancelAddNew: function(){ this.$('.glm-add-new-account').show(); - // this.newRegAccount.destroy(); this.newRegAccountView.remove(); - // app.calendar = false; - // if ( loginAccount != '' && this.model.hasMe() ) { - // this.$('.glm-add-account').hide(); - // // console.log('hiding'); - // } else if ( loginAccount != '' ) { - // this.$('.glm-add-account').show(); - // // console.log('showing'); - // } }, addNewAccount: function(){ @@ -798,7 +787,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ // If not found then nothing was found for that email. alert('Must be a valid email address!'); } else if ( account.id !== undefined && account.email !== undefined ) { - //console.log( cart.get( 'request' ) ); var regRequest = cart.get( 'request' ); this.model.registrants.create({ option: 'add', @@ -889,7 +877,6 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ update: function(){ var modelId = this.model.get( 'id' ); - console.log( 'updating model' ); var fname = this.$('.reg_fname').val().trim(); var lname = this.$('.reg_lname').val().trim(); var email = this.$('.reg_email').val().trim(); @@ -929,7 +916,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ }); this.model.save(); if ( this.model.validationError ) { - console.log( this.model.validationError ); + // console.log( this.model.validationError ); } this.$('.reg-edit-form').hide(); @@ -940,7 +927,6 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ // 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) { @@ -968,7 +954,6 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ }); }, cancelEdit: function(){ - console.log( 'cancel edit' ); this.$('.reg-edit-form').hide(); }, @@ -976,7 +961,6 @@ 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' ) ); - console.log( 'this.setCalendar called' ); this.setCalendar(); } }, @@ -1067,8 +1051,8 @@ app.Views.Front.RegTime = Backbone.View.extend({ } var rateId = this.model.get( 'rate_id' ); if ( !rateId ) { - console.log( 'No rate id!' ); - console.log( sTime ); + // console.log( 'No rate id!' ); + // console.log( sTime ); return; } if ( fname === '' || lname === '' ) { @@ -1085,9 +1069,9 @@ app.Views.Front.RegTime = Backbone.View.extend({ } var regRequest = cart.get( 'request' ); var parent = this.model.get('parent'); - console.log( parent ); + // console.log( parent ); if ( !parent ) { - console.log( 'Parent not there!' ); + // console.log( 'Parent not there!' ); return; } if ( findByEmail.length === 0 ) { @@ -1119,14 +1103,6 @@ app.Views.Front.RegTime = Backbone.View.extend({ this.$('.glm-add-new-account').show(); // this.newRegAccount.destroy(); this.newRegAccountView.remove(); - // app.calendar = false; - // if ( loginAccount != '' && this.model.hasMe() ) { - // this.$('.glm-add-account').hide(); - // // console.log('hiding'); - // } else if ( loginAccount != '' ) { - // this.$('.glm-add-account').show(); - // // console.log('showing'); - // } }, addOne: function( item ){ @@ -1170,7 +1146,6 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ if ( email == '' ) { return; } - console.log( 'Verify Email called' ); var isValidEmail = app.isValidEmail( email ); if ( !isValidEmail ) { alert( 'Email must be valid' ); @@ -1183,12 +1158,10 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ data: { email: email } }) .done(function(account){ - console.log(account); // Check for id and email if ( account.id ) { // This account already exists. // They should not be able to edit the record. - console.log( 'Record exists not able to edit!' ); this.$('.add_reg_fname').val(account.fname); this.$('.add_reg_lname').val(account.lname); diff --git a/js/models/front/regEvent.js b/js/models/front/regEvent.js index 23cdf74..195751c 100644 --- a/js/models/front/regEvent.js +++ b/js/models/front/regEvent.js @@ -28,23 +28,24 @@ app.Models.Front.RegEvent = Backbone.Model.extend({ setClassRegistrants: function( registrants ){ for ( var i = 0; i < registrants.length; i++ ) { + // console.log(registrants[i]); var foundClass = this.classes.findWhere({ id: registrants[i].class_id }); + // console.log(foundClass); if ( foundClass != undefined ) { - var foundRegTime = _.where(app.Times, { id: registrants[i].reg_time }); + 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); if ( !hasRegTime ) { - foundClass.regTimes.create( foundRegTime[0] ); + foundClass.regTimes.create( foundRegTime ); hasRegTime = foundClass.regTimes.findWhere({ id: foundRegTime.id }); + // console.log(hasRegTime); hasRegTime.set({ parent: foundClass }); } // Add the registrant var nRegTime = foundClass.regTimes.findWhere({id: hasRegTime.get('id')}); - // console.log( nRegTime ); nRegTime.registrants.create( registrants[i] ); - // var newReg = foundClass.registrants.pop(); - // foundClass.set({selectedTime: newReg.get( 'reg_time' ) }); } } }, diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index dc9858e..9b7a309 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -130,11 +130,9 @@ app.Views.Front.RegClass = Backbone.View.extend({ if ( app.timeSpecific ) { this.setCalendar(); } - // console.log('called onRenderComplete'); }, setCalendar: function(){ - console.log( 'setting calendar' ); var times = this.model.get( 'times' ); $('#eventCalendar-' + this.model.get('id')).fullCalendar({ events: function(start, end, timezone, callback) { @@ -170,7 +168,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ // Check to make sure the loginAccount is not empty if ( loginAccount !== '' ) { this.$('.glm-add-account').hide(); - // console.log('hiding'); var regRequest = cart.get( 'request' ); var accountEmail = loginAccount.get( 'email' ); var accountId = loginAccount.get( 'id' ); @@ -272,16 +269,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ cancelAddNew: function(){ this.$('.glm-add-new-account').show(); - // this.newRegAccount.destroy(); this.newRegAccountView.remove(); - // app.calendar = false; - // if ( loginAccount != '' && this.model.hasMe() ) { - // this.$('.glm-add-account').hide(); - // // console.log('hiding'); - // } else if ( loginAccount != '' ) { - // this.$('.glm-add-account').show(); - // // console.log('showing'); - // } }, addNewAccount: function(){ @@ -329,7 +317,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ // If not found then nothing was found for that email. alert('Must be a valid email address!'); } else if ( account.id !== undefined && account.email !== undefined ) { - //console.log( cart.get( 'request' ) ); var regRequest = cart.get( 'request' ); this.model.registrants.create({ option: 'add', diff --git a/js/views/front/regRequestRegistrant.js b/js/views/front/regRequestRegistrant.js index 055c3eb..262fb73 100644 --- a/js/views/front/regRequestRegistrant.js +++ b/js/views/front/regRequestRegistrant.js @@ -19,7 +19,6 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ update: function(){ var modelId = this.model.get( 'id' ); - console.log( 'updating model' ); var fname = this.$('.reg_fname').val().trim(); var lname = this.$('.reg_lname').val().trim(); var email = this.$('.reg_email').val().trim(); @@ -59,7 +58,7 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ }); this.model.save(); if ( this.model.validationError ) { - console.log( this.model.validationError ); + // console.log( this.model.validationError ); } this.$('.reg-edit-form').hide(); @@ -70,7 +69,6 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ // 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) { @@ -98,7 +96,6 @@ app.Views.Front.RegRequestRegistrant = Backbone.View.extend({ }); }, cancelEdit: function(){ - console.log( 'cancel edit' ); this.$('.reg-edit-form').hide(); }, @@ -106,7 +103,6 @@ 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' ) ); - console.log( 'this.setCalendar called' ); this.setCalendar(); } }, diff --git a/js/views/front/regTime.js b/js/views/front/regTime.js index 7f4e5fb..4cd379d 100644 --- a/js/views/front/regTime.js +++ b/js/views/front/regTime.js @@ -64,8 +64,8 @@ app.Views.Front.RegTime = Backbone.View.extend({ } var rateId = this.model.get( 'rate_id' ); if ( !rateId ) { - console.log( 'No rate id!' ); - console.log( sTime ); + // console.log( 'No rate id!' ); + // console.log( sTime ); return; } if ( fname === '' || lname === '' ) { @@ -82,9 +82,9 @@ app.Views.Front.RegTime = Backbone.View.extend({ } var regRequest = cart.get( 'request' ); var parent = this.model.get('parent'); - console.log( parent ); + // console.log( parent ); if ( !parent ) { - console.log( 'Parent not there!' ); + // console.log( 'Parent not there!' ); return; } if ( findByEmail.length === 0 ) { @@ -116,14 +116,6 @@ app.Views.Front.RegTime = Backbone.View.extend({ this.$('.glm-add-new-account').show(); // this.newRegAccount.destroy(); this.newRegAccountView.remove(); - // app.calendar = false; - // if ( loginAccount != '' && this.model.hasMe() ) { - // this.$('.glm-add-account').hide(); - // // console.log('hiding'); - // } else if ( loginAccount != '' ) { - // this.$('.glm-add-account').show(); - // // console.log('showing'); - // } }, addOne: function( item ){ diff --git a/js/views/front/registrantForm.js b/js/views/front/registrantForm.js index 5e9e4e1..72793a9 100644 --- a/js/views/front/registrantForm.js +++ b/js/views/front/registrantForm.js @@ -29,7 +29,6 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ if ( email == '' ) { return; } - console.log( 'Verify Email called' ); var isValidEmail = app.isValidEmail( email ); if ( !isValidEmail ) { alert( 'Email must be valid' ); @@ -42,12 +41,10 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({ data: { email: email } }) .done(function(account){ - console.log(account); // Check for id and email if ( account.id ) { // This account already exists. // They should not be able to edit the record. - console.log( 'Record exists not able to edit!' ); this.$('.add_reg_fname').val(account.fname); this.$('.add_reg_lname').val(account.lname);