Add logic for hiding showing the Add Me button
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 19 Oct 2017 16:39:35 +0000 (12:39 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 19 Oct 2017 16:39:35 +0000 (12:39 -0400)
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
js/models/front/regClass.js
js/views/front/regClass.js

index c394bbc..28e43f7 100644 (file)
@@ -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(){
index 1198e82..2efbc32 100644 (file)
@@ -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;
+        }
+    },
+
 });
index 66357a5..885ae93 100644 (file)
@@ -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(){