From 9f76230ab2cf6f815873907bd85a66c0a5189fef Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 6 Oct 2017 16:53:03 -0400 Subject: [PATCH] Add check email for adding attendee form Checking email and if it returns then lock the form otherwise unlock the form. --- js/frontRegApp.js | 67 +++++++++++++++++++++ js/views/front/regClass.js | 4 ++ js/views/front/registrantForm.js | 63 +++++++++++++++++++ models/admin/ajax/account.php | 12 +++- views/front/registrations/registration.html | 4 ++ 5 files changed, 147 insertions(+), 3 deletions(-) diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 8159b58..a7c6e09 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -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); + }, + }); diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index f4dface..3fe7afe 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -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; diff --git a/js/views/front/registrantForm.js b/js/views/front/registrantForm.js index 82d930d..aa86821 100644 --- a/js/views/front/registrantForm.js +++ b/js/views/front/registrantForm.js @@ -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); + }, + }); diff --git a/models/admin/ajax/account.php b/models/admin/ajax/account.php index a0621e9..23742fc 100644 --- a/models/admin/ajax/account.php +++ b/models/admin/ajax/account.php @@ -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( diff --git a/views/front/registrations/registration.html b/views/front/registrations/registration.html index 7d3c694..c4ec06b 100644 --- a/views/front/registrations/registration.html +++ b/views/front/registrations/registration.html @@ -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({ -- 2.17.1