Add check email for adding attendee form
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 6 Oct 2017 20:53:03 +0000 (16:53 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 6 Oct 2017 20:53:03 +0000 (16:53 -0400)
Checking email and if it returns then lock the form otherwise unlock the
form.

js/frontRegApp.js
js/views/front/regClass.js
js/views/front/registrantForm.js
models/admin/ajax/account.php
views/front/registrations/registration.html

index 8159b58..a7c6e09 100644 (file)
@@ -770,6 +770,10 @@ app.Views.Front.RegClass = Backbone.View.extend({
         var zip     = this.$('.reg_zip').val().trim();
         var country = this.$('.reg_country').val().trim();
         var rTime   = this.$('#reg-select-time').val().trim();
+        if ( !rTime ) {
+            alert( 'You must select a time!' );
+            return;
+        }
         if ( fname === '' || lname === '' ) {
             alert( 'First and Last name required!' );
             return;
@@ -1079,6 +1083,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
     template: _.template( jQuery('#eventReg-registrant-add').html() ),
 
     events: {
+        'focusout .reg_email': 'verifyEmail'
     },
 
     initialize: function(){
@@ -1090,4 +1095,66 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
         return this;
     },
 
+    verifyEmail: function(){
+        var email = this.$('.reg_email').val().trim();
+        if ( email == '' ) {
+            return;
+        }
+        console.log( 'Verify Email called' );
+        var isValidEmail = app.isValidEmail( email );
+        if ( !isValidEmail ) {
+            alert( 'Email must be valid' );
+        } else {
+            // Check to see if this is a valid email.
+            jQuery.ajax({
+                context: this,
+                url: ajaxUrl + '&glm_action=account&option=checkEmail',
+                dataType: 'json',
+                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.$('.reg_fname').val(account.fname);
+                    this.$('.reg_lname').val(account.lname);
+
+                    // lock the form
+                    this.lockForm();
+                } else {
+                    // They should be able to edit the form
+                    this.unLockForm();
+                }
+            })
+            .fail(function(msg){
+                console.log('Fail: ' + msg);
+            });
+        }
+    },
+
+    lockForm: function(){
+        this.$('.reg_fname').prop('disabled', true);
+        this.$('.reg_lname').prop('disabled', true);
+        this.$('.reg_addr1').prop('disabled', true);
+        this.$('.reg_addr2').prop('disabled', true);
+        this.$('.reg_city').prop('disabled', true);
+        this.$('.reg_state').prop('disabled', true);
+        this.$('.reg_zip').prop('disabled', true);
+        this.$('.reg_country').prop('disabled', true);
+    },
+
+    unLockForm: function(){
+        this.$('.reg_fname').prop('disabled', false);
+        this.$('.reg_lname').prop('disabled', false);
+        this.$('.reg_addr1').prop('disabled', false);
+        this.$('.reg_addr2').prop('disabled', false);
+        this.$('.reg_city').prop('disabled', false);
+        this.$('.reg_state').prop('disabled', false);
+        this.$('.reg_zip').prop('disabled', false);
+        this.$('.reg_country').prop('disabled', false);
+    },
+
 });
index f4dface..3fe7afe 100644 (file)
@@ -84,6 +84,10 @@ app.Views.Front.RegClass = Backbone.View.extend({
         var zip     = this.$('.reg_zip').val().trim();
         var country = this.$('.reg_country').val().trim();
         var rTime   = this.$('#reg-select-time').val().trim();
+        if ( !rTime ) {
+            alert( 'You must select a time!' );
+            return;
+        }
         if ( fname === '' || lname === '' ) {
             alert( 'First and Last name required!' );
             return;
index 82d930d..aa86821 100644 (file)
@@ -6,6 +6,7 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
     template: _.template( jQuery('#eventReg-registrant-add').html() ),
 
     events: {
+        'focusout .reg_email': 'verifyEmail'
     },
 
     initialize: function(){
@@ -17,4 +18,66 @@ app.Views.Front.RegistrantForm = Backbone.View.extend({
         return this;
     },
 
+    verifyEmail: function(){
+        var email = this.$('.reg_email').val().trim();
+        if ( email == '' ) {
+            return;
+        }
+        console.log( 'Verify Email called' );
+        var isValidEmail = app.isValidEmail( email );
+        if ( !isValidEmail ) {
+            alert( 'Email must be valid' );
+        } else {
+            // Check to see if this is a valid email.
+            jQuery.ajax({
+                context: this,
+                url: ajaxUrl + '&glm_action=account&option=checkEmail',
+                dataType: 'json',
+                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.$('.reg_fname').val(account.fname);
+                    this.$('.reg_lname').val(account.lname);
+
+                    // lock the form
+                    this.lockForm();
+                } else {
+                    // They should be able to edit the form
+                    this.unLockForm();
+                }
+            })
+            .fail(function(msg){
+                console.log('Fail: ' + msg);
+            });
+        }
+    },
+
+    lockForm: function(){
+        this.$('.reg_fname').prop('disabled', true);
+        this.$('.reg_lname').prop('disabled', true);
+        this.$('.reg_addr1').prop('disabled', true);
+        this.$('.reg_addr2').prop('disabled', true);
+        this.$('.reg_city').prop('disabled', true);
+        this.$('.reg_state').prop('disabled', true);
+        this.$('.reg_zip').prop('disabled', true);
+        this.$('.reg_country').prop('disabled', true);
+    },
+
+    unLockForm: function(){
+        this.$('.reg_fname').prop('disabled', false);
+        this.$('.reg_lname').prop('disabled', false);
+        this.$('.reg_addr1').prop('disabled', false);
+        this.$('.reg_addr2').prop('disabled', false);
+        this.$('.reg_city').prop('disabled', false);
+        this.$('.reg_state').prop('disabled', false);
+        this.$('.reg_zip').prop('disabled', false);
+        this.$('.reg_country').prop('disabled', false);
+    },
+
 });
index a0621e9..23742fc 100644 (file)
@@ -224,20 +224,26 @@ class GlmMembersAdmin_ajax_account extends GlmDataRegistrationsAccount
 
         case 'checkEmail':
             if ( $email = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ) ) {
-                $accountId = $this->wpdb->get_var(
+                $accountData = $this->wpdb->get_row(
                     $this->wpdb->prepare(
-                        "SELECT id
+                        "SELECT id,fname,lname
                           FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "account
                          WHERE email = %s",
                         $email
-                    )
+                    ),
+                    ARRAY_A
                 );
+                $accountId = $accountData['id'];
+                $fname     = $accountData['fname'];
+                $lname     = $accountData['lname'];
                 if ( $accountId ) {
                     $return = array(
                         'valid'      => true,
                         'validEmail' => true,
                         'id'         => (int)$accountId,
                         'email'      => $email,
+                        'fname'      => $fname,
+                        'lname'      => $lname,
                     );
                 } else {
                     $return = array(
index 7d3c694..c4ec06b 100644 (file)
@@ -201,6 +201,10 @@ var app = {
     Models: { Front: {}, Admin: {} },
     Collections: { Front: {}, Admin: {} },
     Views: { Front: {}, Admin: {} },
+    isValidEmail: function( email ){
+        var regex = {literal}/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;{/literal}
+        return regex.test(email);
+    },
     initFullCalendar: function(){
         if ({$regEvent.time_specific.value}) {
             $('#eventCalendar').fullCalendar({