Update to add attendee forms.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 5 Jan 2018 16:44:36 +0000 (11:44 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 5 Jan 2018 16:46:03 +0000 (11:46 -0500)
Separate out the email lookup part to form within the add attendee form
that allows someone to lookup account by email. If it finds the account
it hides that part and fills in the other form. If it doesn't find the
account it fills in the email address.

js/frontRegApp.js
js/views/front/regTime.js
js/views/front/registrantForm.js
views/front/registrations/registration.html

index 48b384e..fa30f42 100644 (file)
@@ -958,6 +958,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
 
     // insert new registrant
     insertNew: function(){
+        this.$('#loading-' + this.model.get('id') ).show();
         var findByEmail = [];
         var fname   = this.$('.add_reg_fname').val().trim();
         var lname   = this.$('.add_reg_lname').val().trim();
@@ -989,6 +990,10 @@ app.Views.Front.RegTime = Backbone.View.extend({
             }
         } else {
             findByEmail = this.model.registrants.where({email: email, fname: fname, lname: lname});
+            console.log( findByEmail.length );
+            if ( findByEmail.length > 0 ) {
+                this.$('#loading-' + this.model.get('id') ).hide();
+            }
         }
         var regRequest = cart.get( 'request' );
         var parent = this.model.get('parent');
@@ -1001,7 +1006,6 @@ app.Views.Front.RegTime = Backbone.View.extend({
         // to the collection.
         var customFieldData = this.$( 'form.attendee-cf-form-new' ).serialize();
 
-        this.$('#loading-' + this.model.get('id') ).show();
         var newRegistrant = this.model.registrants.create({
             option: 'add',
             reg_request: regRequest.id,
@@ -1032,8 +1036,8 @@ app.Views.Front.RegTime = Backbone.View.extend({
     },
 
     errorCallback: function( collection, response ){
-        // console.log( 'errorCallback Called' );
-        // console.log( response );
+        console.log( 'errorCallback Called' );
+        console.log( response );
     },
 
     // cancel add new registrant
@@ -1075,7 +1079,8 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
     // bind events to the view
     events: {
         'blur input.add_reg_email': 'verifyEmail',
-        'click .show-hide-address': 'toggleClass',
+        // 'click .show-hide-address': 'toggleClass',
+        'click .lookup-attendee': 'lookupEmail'
     },
 
     // setup the view
@@ -1095,16 +1100,26 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
         this.$('.ereg-addr').toggle();
     },
 
-    // verify the email address
     verifyEmail: function(){
         var email = this.$('.add_reg_email').val().trim();
+        var isValidEmail = app.isValidEmail( email );
+        if ( !isValidEmail ) {
+            alert( 'Email must be valid' );
+            this.$('.add_reg_email').val('');
+            return;
+        }
+    },
+
+    // verify the email address
+    lookupEmail: function(){
+        var email = this.$('.lookup_email').val().trim();
         if ( email == '' ) {
             return;
         }
         var isValidEmail = app.isValidEmail( email );
         if ( !isValidEmail ) {
             alert( 'Email must be valid' );
-            this.$('.add_reg_email').val('');
+            this.$('.lookup_email').val('');
             return;
         } else {
             // Check to see if this is a valid email.
@@ -1119,6 +1134,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
                 if ( account.id ) {
                     // This account already exists.
                     // They should not be able to edit the record.
+                    this.$('.add_reg_email').val(account.email);
                     this.$('.add_reg_fname').val(account.fname);
                     this.$('.add_reg_lname').val(account.lname);
                     this.$('.add_reg_addr1').val(account.addr1);
@@ -1127,12 +1143,12 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
                     this.$('.add_reg_state').val(account.state);
                     this.$('.add_reg_zip').val(account.zip);
                     this.$('.add_reg_country').val(account.country);
-
-                    // lock the form
-                    // this.lockForm();
+                    // alert( 'Account Found' );
+                    this.$('.account-lookup').hide();
                 } else {
-                    // They should be able to edit the form
-                    this.unLockForm();
+                    // Notify them nothing found
+                    alert( 'Could not find account' );
+                    this.$('.add_reg_email').val(email);
                 }
             })
             .fail(function(msg){
index 1177352..2ff5167 100644 (file)
@@ -68,6 +68,7 @@ app.Views.Front.RegTime = Backbone.View.extend({
 
     // insert new registrant
     insertNew: function(){
+        this.$('#loading-' + this.model.get('id') ).show();
         var findByEmail = [];
         var fname   = this.$('.add_reg_fname').val().trim();
         var lname   = this.$('.add_reg_lname').val().trim();
@@ -99,6 +100,10 @@ app.Views.Front.RegTime = Backbone.View.extend({
             }
         } else {
             findByEmail = this.model.registrants.where({email: email, fname: fname, lname: lname});
+            console.log( findByEmail.length );
+            if ( findByEmail.length > 0 ) {
+                this.$('#loading-' + this.model.get('id') ).hide();
+            }
         }
         var regRequest = cart.get( 'request' );
         var parent = this.model.get('parent');
@@ -111,7 +116,6 @@ app.Views.Front.RegTime = Backbone.View.extend({
         // to the collection.
         var customFieldData = this.$( 'form.attendee-cf-form-new' ).serialize();
 
-        this.$('#loading-' + this.model.get('id') ).show();
         var newRegistrant = this.model.registrants.create({
             option: 'add',
             reg_request: regRequest.id,
@@ -142,8 +146,8 @@ app.Views.Front.RegTime = Backbone.View.extend({
     },
 
     errorCallback: function( collection, response ){
-        // console.log( 'errorCallback Called' );
-        // console.log( response );
+        console.log( 'errorCallback Called' );
+        console.log( response );
     },
 
     // cancel add new registrant
index 85c9fb7..d1f8ee2 100644 (file)
@@ -14,7 +14,8 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
     // bind events to the view
     events: {
         'blur input.add_reg_email': 'verifyEmail',
-        'click .show-hide-address': 'toggleClass',
+        // 'click .show-hide-address': 'toggleClass',
+        'click .lookup-attendee': 'lookupEmail'
     },
 
     // setup the view
@@ -34,16 +35,26 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
         this.$('.ereg-addr').toggle();
     },
 
-    // verify the email address
     verifyEmail: function(){
         var email = this.$('.add_reg_email').val().trim();
+        var isValidEmail = app.isValidEmail( email );
+        if ( !isValidEmail ) {
+            alert( 'Email must be valid' );
+            this.$('.add_reg_email').val('');
+            return;
+        }
+    },
+
+    // verify the email address
+    lookupEmail: function(){
+        var email = this.$('.lookup_email').val().trim();
         if ( email == '' ) {
             return;
         }
         var isValidEmail = app.isValidEmail( email );
         if ( !isValidEmail ) {
             alert( 'Email must be valid' );
-            this.$('.add_reg_email').val('');
+            this.$('.lookup_email').val('');
             return;
         } else {
             // Check to see if this is a valid email.
@@ -58,6 +69,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
                 if ( account.id ) {
                     // This account already exists.
                     // They should not be able to edit the record.
+                    this.$('.add_reg_email').val(account.email);
                     this.$('.add_reg_fname').val(account.fname);
                     this.$('.add_reg_lname').val(account.lname);
                     this.$('.add_reg_addr1').val(account.addr1);
@@ -66,12 +78,12 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
                     this.$('.add_reg_state').val(account.state);
                     this.$('.add_reg_zip').val(account.zip);
                     this.$('.add_reg_country').val(account.country);
-
-                    // lock the form
-                    // this.lockForm();
+                    // alert( 'Account Found' );
+                    this.$('.account-lookup').hide();
                 } else {
-                    // They should be able to edit the form
-                    this.unLockForm();
+                    // Notify them nothing found
+                    alert( 'Could not find account' );
+                    this.$('.add_reg_email').val(email);
                 }
             })
             .fail(function(msg){
index ab92871..96da2a7 100644 (file)
     {/if}{literal}
         <div>
             <div>
+                <div class="row account-lookup">
+                    <div class="columns small-12">
+                        Search for existing Account
+                    </div>
+                </div>
+                <div class="row account-lookup">
+                    <div class="columns large-6 small-12"><input placeholder="Enter Email Address" class="lookup_email" value=""></div>
+                    <div class="columns large-6 small-12 text-right">
+                        <input class="lookup-attendee button" value="Search by Email" type="submit">
+                    </div>
+                </div>
                 <h4>{/literal}{$terms.reg_term_attendee_cap} Info{literal}</h4>
                 <div class="row">
                     <div class="columns small-12 text-right glm-reg-required">