Login and Add New updates
authorSteve Sutton <ssutton@gmail.com>
Sun, 24 Sep 2017 18:53:42 +0000 (14:53 -0400)
committerSteve Sutton <ssutton@gmail.com>
Sun, 24 Sep 2017 18:53:42 +0000 (14:53 -0400)
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
js/models/front/regClass.js
js/views/front/newRegistrant.js
js/views/front/regClass.js
models/admin/registrations/accounts.php
models/front/registrations/registration.php
views/front/registrations/registration.html

index 23db71e..fe005d1 100644 (file)
@@ -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(){
index 8b69693..515879f 100644 (file)
@@ -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(){
index 41aab89..e79d6fd 100644 (file)
@@ -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(){
index 6d00dd4..220032a 100644 (file)
@@ -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(){
index a479392..29d5958 100644 (file)
@@ -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,
index bf438a2..a417836 100644 (file)
@@ -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(
                     //echo '<pre>$rates: ' . print_r( $rates, true ) . '</pre>';
                     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'];
index 81ac573..a2b35f7 100644 (file)
@@ -28,7 +28,7 @@
     <div>
         <p><%= descr %></p>
         <% if ( attendee_max > 0 ) { %>
-        <p>Maximum Registrants: <%- attendee_max %></p>
+            <p>Maximum Registrants: <%- attendee_max %></p>
         <% } %>
         <p><%= terms %></p>
     </div>
@@ -58,7 +58,9 @@
         <div>Current Rate: <%= reg_rate_name %></div>
         <div>Base Price: <%= reg_rate_base_price %></div>
         <div>Per Registrant: <%= reg_rate_per_reg %></div>
-        <button class="glm-add-account tiny">Add Me</button>
+        <% if ( loggedIn ) { %>
+            <button class="glm-add-account tiny">Add Me</button>
+        <% } %>
         <button class="glm-add-new-account tiny">Add New</button>
         <div class="registrant-add clearfix glm-hidden">
             <input type="text" class="addFname" placeholder="First Name">
@@ -77,7 +79,7 @@
     <div>
         <input class="reg_fname" placeholder="First Name">
         <input class="reg_lname" placeholder="Last Name">
-        <input class="reg_email" value="<%- email %>" disabled>
+        <input class="reg_email" placeholder="Email Address" value="<%- email %>">
         <input class="add-new-registrant" value="Add Registrant" type="submit">
     </div>
 </script>
@@ -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} );