From 044805e2a4dca45ac47ff05b84af5f4dd0c4d658 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 19 Oct 2017 12:39:35 -0400 Subject: [PATCH] Add logic for hiding showing the Add Me button Don't show add me if not logged in. Don't show add me if already set as one of the registrants. --- js/frontRegApp.js | 37 ++++++++++++++++++++++++++++++++----- js/models/front/regClass.js | 15 +++++++++++++++ js/views/front/regClass.js | 22 +++++++++++++++++----- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/js/frontRegApp.js b/js/frontRegApp.js index c394bbc..28e43f7 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -153,6 +153,21 @@ app.Models.Front.RegClass = Backbone.Model.extend({ this.registrants.reset( registrants ); }, + // Check to see if the current login user in the list of registrants + hasMe: function() { + 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 @@ -708,9 +723,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, render: function(){ - if ( loginAccount === '' ) { - this.$('.glm-add-account').hide(); - } this.model.set({ reg_count: this.model.registrants.length }); this.$el.html( this.template( this.model.toJSON() ) ); // Need to see if this class has attendees and render them @@ -719,6 +731,12 @@ app.Views.Front.RegClass = Backbone.View.extend({ }); var accountContainer = this.$('.reg-class-accounts'); accountContainer.append(view); + if ( loginAccount === '' ) { + this.$('.glm-add-account').hide(); + } + if ( loginAccount != '' && this.model.hasMe() ) { + this.$('.glm-add-account').hide(); + } return this; }, @@ -765,6 +783,8 @@ app.Views.Front.RegClass = Backbone.View.extend({ addAccount: function(){ // 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' ); @@ -854,15 +874,22 @@ app.Views.Front.RegClass = Backbone.View.extend({ country: country, }); } - this.newRegAccount.destroy(); + // this.newRegAccount.destroy(); this.newRegAccountView.remove(); app.calendar = false; }, cancelAddNew: function(){ - this.newRegAccount.destroy(); + // 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(){ diff --git a/js/models/front/regClass.js b/js/models/front/regClass.js index 1198e82..2efbc32 100644 --- a/js/models/front/regClass.js +++ b/js/models/front/regClass.js @@ -25,4 +25,19 @@ app.Models.Front.RegClass = Backbone.Model.extend({ this.registrants.reset( registrants ); }, + // Check to see if the current login user in the list of registrants + hasMe: function() { + if ( loginAccount ) { + var foundMe = this.registrants.findWhere({ account: loginAccount.get( 'id' ) }); + if ( foundMe ) { + return true; + } else { + return false; + } + return true; + } else { + return false; + } + }, + }); diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index 66357a5..885ae93 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -18,9 +18,6 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, render: function(){ - if ( loginAccount === '' ) { - this.$('.glm-add-account').hide(); - } this.model.set({ reg_count: this.model.registrants.length }); this.$el.html( this.template( this.model.toJSON() ) ); // Need to see if this class has attendees and render them @@ -29,6 +26,12 @@ app.Views.Front.RegClass = Backbone.View.extend({ }); var accountContainer = this.$('.reg-class-accounts'); accountContainer.append(view); + if ( loginAccount === '' ) { + this.$('.glm-add-account').hide(); + } + if ( loginAccount != '' && this.model.hasMe() ) { + this.$('.glm-add-account').hide(); + } return this; }, @@ -75,6 +78,8 @@ app.Views.Front.RegClass = Backbone.View.extend({ addAccount: function(){ // 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' ); @@ -164,15 +169,22 @@ app.Views.Front.RegClass = Backbone.View.extend({ country: country, }); } - this.newRegAccount.destroy(); + // this.newRegAccount.destroy(); this.newRegAccountView.remove(); app.calendar = false; }, cancelAddNew: function(){ - this.newRegAccount.destroy(); + // 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(){ -- 2.17.1