From 0c3fb79da91787c7e07b1014d32db0d6d53ffdbc Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Sun, 24 Sep 2017 14:53:42 -0400 Subject: [PATCH] Login and Add New updates Move the addNew method to the regClass View along with the events for when the .add-new-registrant class is clicked. Add Me button setup to only show when their logged in. --- js/frontRegApp.js | 30 +++++++-- js/models/front/regClass.js | 1 + js/views/front/newRegistrant.js | 2 +- js/views/front/regClass.js | 27 +++++++- models/admin/registrations/accounts.php | 72 ++++++++++----------- models/front/registrations/registration.php | 3 +- views/front/registrations/registration.html | 12 ++-- 7 files changed, 97 insertions(+), 50 deletions(-) diff --git a/js/frontRegApp.js b/js/frontRegApp.js index 23db71e..fe005d1 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -140,6 +140,7 @@ app.Models.Front.RegClass = Backbone.Model.extend({ reg_rate_base_price: '', reg_rate_per_reg: '', reg_count: 0, + loggedIn: false, }, initialize: function(){ @@ -540,7 +541,7 @@ app.Views.Front.NewRegistrant = Backbone.View.extend({ template: _.template( jQuery('#eventReg-registrant-add').html() ), events: { - 'click .add-new-registrant': 'addNew', + //'click .add-new-registrant': 'addNew', }, initialize: function(){ @@ -594,9 +595,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, render: function(){ - console.log( loginAccount ); if ( loginAccount === '' ) { - console.log( 'hide called for .glm-add-account' ); this.$('.glm-add-account').hide(); } this.model.set({ reg_count: this.model.registrants.length }); @@ -620,6 +619,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ 'click .addRegistrant': 'newEntry', 'click .glm-add-account': 'addAccount', 'click .glm-add-new-account': 'addNewAccount', + 'click .add-new-registrant': 'addNew', }, addAccount: function(){ @@ -642,9 +642,31 @@ app.Views.Front.RegClass = Backbone.View.extend({ } } }, + addNew: function(){ + console.log( 'called addNew in regClass view' ); + var fname = this.$('.reg_fname').val().trim(); + var lname = this.$('.reg_lname').val().trim(); + var email = this.$('.reg_email').val().trim(); + console.log( 'email: ' + email + ' fname: ' + fname + ' lname: ' + lname ); + var regRequest = cart.get( 'request' ); + this.model.registrants.create({ + option: 'add', + reg_request: regRequest.id, + reg_event: this.model.get( 'reg_event' ), + reg_class: this.model.get( 'id' ), + reg_rate: this.model.get( 'reg_rate_id' ), + email: email, + }); + this.newRegAccount.destroy(); + this.newRegAccountView.remove(); + }, addNewAccount: function(){ - console.log( 'Add New Account Called' ) + console.log( 'Add New Account Called' ); + // Create the new Registrant View + this.newRegAccount = new app.Models.Front.RegRequestRegistrant(); + this.newRegAccountView = new app.Views.Front.NewRegistrant({model: this.newRegAccount}); + this.$el.append( this.newRegAccountView.render().el ); }, toggleClassOpen: function(){ diff --git a/js/models/front/regClass.js b/js/models/front/regClass.js index 8b69693..515879f 100644 --- a/js/models/front/regClass.js +++ b/js/models/front/regClass.js @@ -15,6 +15,7 @@ app.Models.Front.RegClass = Backbone.Model.extend({ reg_rate_base_price: '', reg_rate_per_reg: '', reg_count: 0, + loggedIn: false, }, initialize: function(){ diff --git a/js/views/front/newRegistrant.js b/js/views/front/newRegistrant.js index 41aab89..e79d6fd 100644 --- a/js/views/front/newRegistrant.js +++ b/js/views/front/newRegistrant.js @@ -6,7 +6,7 @@ app.Views.Front.NewRegistrant = Backbone.View.extend({ template: _.template( jQuery('#eventReg-registrant-add').html() ), events: { - 'click .add-new-registrant': 'addNew', + //'click .add-new-registrant': 'addNew', }, initialize: function(){ diff --git a/js/views/front/regClass.js b/js/views/front/regClass.js index 6d00dd4..220032a 100644 --- a/js/views/front/regClass.js +++ b/js/views/front/regClass.js @@ -18,9 +18,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ }, render: function(){ - console.log( loginAccount ); if ( loginAccount === '' ) { - console.log( 'hide called for .glm-add-account' ); this.$('.glm-add-account').hide(); } this.model.set({ reg_count: this.model.registrants.length }); @@ -44,6 +42,7 @@ app.Views.Front.RegClass = Backbone.View.extend({ 'click .addRegistrant': 'newEntry', 'click .glm-add-account': 'addAccount', 'click .glm-add-new-account': 'addNewAccount', + 'click .add-new-registrant': 'addNew', }, addAccount: function(){ @@ -66,9 +65,31 @@ app.Views.Front.RegClass = Backbone.View.extend({ } } }, + addNew: function(){ + console.log( 'called addNew in regClass view' ); + var fname = this.$('.reg_fname').val().trim(); + var lname = this.$('.reg_lname').val().trim(); + var email = this.$('.reg_email').val().trim(); + console.log( 'email: ' + email + ' fname: ' + fname + ' lname: ' + lname ); + var regRequest = cart.get( 'request' ); + this.model.registrants.create({ + option: 'add', + reg_request: regRequest.id, + reg_event: this.model.get( 'reg_event' ), + reg_class: this.model.get( 'id' ), + reg_rate: this.model.get( 'reg_rate_id' ), + email: email, + }); + this.newRegAccount.destroy(); + this.newRegAccountView.remove(); + }, addNewAccount: function(){ - console.log( 'Add New Account Called' ) + console.log( 'Add New Account Called' ); + // Create the new Registrant View + this.newRegAccount = new app.Models.Front.RegRequestRegistrant(); + this.newRegAccountView = new app.Views.Front.NewRegistrant({model: this.newRegAccount}); + this.$el.append( this.newRegAccountView.render().el ); }, toggleClassOpen: function(){ diff --git a/models/admin/registrations/accounts.php b/models/admin/registrations/accounts.php index a479392..29d5958 100644 --- a/models/admin/registrations/accounts.php +++ b/models/admin/registrations/accounts.php @@ -116,7 +116,7 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount $haveRequests = false; $registered = false; $haveRegistered = false; - + // Get any provided option if (isset($_REQUEST['option'])) { $option = $_REQUEST['option']; @@ -129,26 +129,26 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount $accountID = ($_REQUEST['accountID'] - 0); } else { - + // Try to get saved $accountID = get_option('glmMembersDatabaseRegistrationsAccountID'); - + } - + if (!$accountID || $accountID <= 0) { $accountID = false; } - + switch ( $option ) { case 'add': - + $account = $this->newEntry(); $view = 'accountEdit'; - + break; case 'insert': - + $account = $this->insertEntry(); if ( $account['status'] ) { $accountAdded = true; @@ -157,11 +157,11 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount } $view = 'accountEdit'; - + break; case 'update': - + $account = $this->updateEntry( $accountID ); if ( $account['status'] ) { @@ -180,65 +180,65 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount break; case 'delete': - + echo "*** NEED TO CHECK IF IT'S SAVE TO DELETE THIS ACCOUNT ***"; - + // $oldAccount = $this->deleteEntry( $accountID, true ); - + $view = 'accountsDashboard'; - + break; - + case 'accountDashboard': - + // Load registration request and registration registrant data classes require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequest.php'; $RegRequest = new GlmDataRegistrationsRegRequest($this->wpdb, $this->config); require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestRegistrant.php'; $RegRequestRegistrant = new GlmDataRegistrationsRequestRegistrant($this->wpdb, $this->config); - + // Get account base data $account = $this->getEntry($accountID); if ($account) { - + $haveAccount = true; - + // Get any registrations submitted $requests = $RegRequest->getList("T.account = $accountID"); if (is_array($requests) && count($requests) > 0) { $haveRequests = true; } - + // Get any events registered $registered = $RegRequestRegistrant->getList("T.account = $accountID"); if (is_array($registered) && count($registered) > 0) { $haveRegistered = true; } - + } - + $view = 'accountDashboard'; - + break; - + case 'edit': - + $account = $this->editEntry( $accountID ); if ( $account['status'] ) { - + $haveAccount = true; $view = 'accountEdit'; - - } - + + } + break; - + default: case 'dashboard'; $option = 'dashboard'; $where = 'true'; - + // Check if we're doing paging if (isset($_REQUEST['pageSelect'])) { @@ -292,17 +292,17 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount $namesList = $this->getIdName( $where ); unset( $accountsResult ); - $view = 'accountsDashboard'; - + $view = 'accountsDashboard'; + break; - + } - + // If we have a valid account ID, save that for future use if ($accountID > 0) { update_option('glmMembersDatabaseRegistrationsAccountID', $accountID); } - + // Compile template data $templateData = array( 'hasAccounts' => $hasAccounts, diff --git a/models/front/registrations/registration.php b/models/front/registrations/registration.php index bf438a2..a417836 100644 --- a/models/front/registrations/registration.php +++ b/models/front/registrations/registration.php @@ -41,7 +41,7 @@ $scripts = array( //'backbone-local' => 'js/lib/backbone.localStorage.min.js', - 'regApp' => 'js/frontRegApp.js', + 'regApp' => 'js/frontRegApp.js', ); foreach ( $scripts as $scriptName => $scriptPath ) { wp_register_script( @@ -135,6 +135,7 @@ //echo '
$rates: ' . print_r( $rates, true ) . '
'; if ( isset( $rates ) && is_array( $rates ) ) { foreach ( $rates as $rate ) { + $rClass['loggedIn'] = ( isset($_SESSION['LoginAccount']) ) ? true : false; $rClass['reg_rate_id'] = $rate['id']; $rClass['reg_rate_name'] = $rate['name']; $rClass['reg_rate_base_price'] = $rate['base_rate']; diff --git a/views/front/registrations/registration.html b/views/front/registrations/registration.html index 81ac573..a2b35f7 100644 --- a/views/front/registrations/registration.html +++ b/views/front/registrations/registration.html @@ -28,7 +28,7 @@

<%= descr %>

<% if ( attendee_max > 0 ) { %> -

Maximum Registrants: <%- attendee_max %>

+

Maximum Registrants: <%- attendee_max %>

<% } %>

<%= terms %>

@@ -58,7 +58,9 @@
Current Rate: <%= reg_rate_name %>
Base Price: <%= reg_rate_base_price %>
Per Registrant: <%= reg_rate_per_reg %>
- + <% if ( loggedIn ) { %> + + <% } %>
@@ -77,7 +79,7 @@
- +
@@ -112,9 +114,9 @@ var cart = ''; var loginAccount = ''; jQuery(function($){ {if $loginAccount } - loginAccount = new app.Models.Front.Account( {$loginAccount} ); + loginAccount = new app.Models.Front.Account( {$loginAccount} ); {else} - loginAccount = ''; + loginAccount = ''; {/if} cart = new app.Models.Front.Cart( {$regCartJSON} ); cart.setRequest( {$regRequestJSON} ); -- 2.17.1