Re-organize ajax files
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 31 Aug 2017 19:38:29 +0000 (15:38 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 31 Aug 2017 19:38:29 +0000 (15:38 -0400)
Working on the ajax files. Calling it account.php and having it response
to any ajax request that deals with the account.

13 files changed:
data/event_setup.php
js/models/account.js
js/models/accountDetail.js [new file with mode: 0644]
js/models/regClass.js
js/regApp.js
js/views/login.js
js/views/regClass.js
models/admin/ajax/account.php [new file with mode: 0644]
models/admin/ajax/checkEmail.php [new file with mode: 0644]
models/admin/ajax/login.php [deleted file]
models/front/registrations/registration.php
setup/validActions.php
views/front/registrations/registration.html

index 3cc3ab6..a92e29c 100644 (file)
@@ -9,6 +9,7 @@ $regEventSample = array(
     'reg_event' =>  array
     (
         'id'                            => 1000,
+        'event'                         => 1,
         'event_name'                    => 'GLM Sample Event',
         'event_code'                    => 'glm-sample-event',
         'notify_email'                  => '',
@@ -63,6 +64,9 @@ $regEventSample = array(
             'reg_event'             => 1000,
             'name'                  => 'Standard',
             'descr'                 => 'Standard registration for this event. Provides all standard attendee privileges.',
+            'reg_rate_name'         => 'Early Bird',
+            'reg_rate_base_price'   => 100.00,
+            'reg_rate_per_reg'      => 10.00,
             'reg_rate'  => array
             (
                 1 => array
index 100625d..979d9d2 100644 (file)
@@ -5,7 +5,7 @@ app.Models.Account = Backbone.Model.extend({
 
     // Default registrant values
     defaults: {
-        name: '',
+        id: '',
         email: '',
         parent: '',
     },
@@ -17,9 +17,6 @@ app.Models.Account = Backbone.Model.extend({
     },
 
     validate: function( attribs, options ){
-        if ( attribs.name === undefined || attribs.name === '' ) {
-            return 'Need a name!';
-        }
         if ( attribs.email === undefined || attribs.email === '' ) {
             return 'Need an email address!';
         }
diff --git a/js/models/accountDetail.js b/js/models/accountDetail.js
new file mode 100644 (file)
index 0000000..e07c243
--- /dev/null
@@ -0,0 +1,26 @@
+// js/models/accountDetail.js
+
+// Event Registrant Detail Model
+app.Models.AccountDetail = app.Models.Account.extend({
+    // Default registrant values
+    defaults: {
+        id: '',
+        fname: '',
+        lname: '',
+        org: '',
+        title: '',
+        addr1: '',
+        addr2: '',
+        city: '',
+        state: '',
+        zip: '',
+        country: '',
+        phone: '',
+        fax: '',
+        email_ok: false,
+        is_member: false,
+        date_created: '',
+        email: '',
+        parent: '',
+    }
+});
index f5b24ce..6de34a6 100644 (file)
@@ -7,7 +7,10 @@ app.Models.RegClass = Backbone.Model.extend({
     defaults: {
         reg_event: 0,
         name: '',
-        descr: ''
+        descr: '',
+        reg_rate_name: '',
+        reg_rate_base_price: '',
+        reg_rate_per_reg: '',
     },
 
     initialize: function(){
index f17e4a4..38969d1 100644 (file)
@@ -1 +1 @@
-app.Models.Account=Backbone.Model.extend({defaults:{name:"",email:"",parent:""},initialize:function(){this.on("invalid",function(e,t){console.log(t)})},validate:function(e,t){return void 0===e.name||""===e.name?"Need a name!":void 0===e.email||""===e.email?"Need an email address!":void 0}}),app.Models.Login=Backbone.Model.extend({defaults:{username:"",password:""},urlRoot:appLoginUrl,initialize:function(){this.on("invalid",function(e,t){console.log(t)})},validate:function(e,t){return void 0===e.username||""===e.username?"Username required!":void 0===e.password||""===e.password?"Password required!":void 0}}),app.Models.RegClass=Backbone.Model.extend({defaults:{reg_event:0,name:"",descr:""},initialize:function(){this.accounts=new app.Collections.Accounts,this.accounts.fetch()}}),app.Models.RegEvent=Backbone.Model.extend({defaults:{name:"regEvent",event_name:"",event_code:"",notify_email:"",attendees_max:0,attendees_max_per_reg:0,reg_hold_minutes:0,cart_hold_days:0,terms:""},initialize:function(){this.classes=new app.Collections.RegClasses},setClasses:function(e){this.classes.reset(e)}}),app.Models.regRate=Backbone.Model.extend({defaults:{reg_event:0,reg_class:"",name:"",start_days:0,end_days:0,base_rate:0,per_registrant:0,registrant_credits:0},initialize:function(){}}),app.Collections.Accounts=Backbone.Collection.extend({model:app.Models.Account,localStorage:new Backbone.LocalStorage("Accounts"),sync:function(e,t,n){console.log("sync called on collection. method: "+e)}}),app.Collections.RegClasses=Backbone.Collection.extend({model:app.Models.RegClass}),app.Collections.RegRates=Backbone.Collection.extend({model:app.Models.RegRate}),app.Views.Account=Backbone.View.extend({tagName:"div",className:"glm-reg-level-registrant clearfix",template:_.template($("#account-template").html()),events:{"click label":"edit","click .glm-reg-level-registrant-delete":"deleteOne","click .saveRegistrant":"close"},initialize:function(){return this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"destroy",this.remove),this},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.$nameInput=this.$(".editName"),this.$emailInput=this.$(".editEmail"),this},deleteOne:function(){this.model.destroy()},edit:function(){this.$el.addClass("editing"),this.$nameInput.focus()},close:function(){var e=this.$nameInput.val().trim(),t=this.$emailInput.val().trim();e&&t?this.model.save({name:e,email:t}):this.clear(),this.$el.removeClass("editing")}}),Backbone.emulateJSON=!0,Backbone.emulateHTTP=!0,app.Views.App=Backbone.View.extend({el:"#regApp",initialize:function(){this.event=new app.Views.RegEvent({model:app.Models.regEvent}),this.render()},render:function(){return this.$el.append(this.event.render().el),this},events:{"click #appLogin":"login"},login:function(){this.loginView=new app.Views.Login({model:new app.Models.Login}),this.$el.append(this.loginView.render().el),$("#appLogin").hide()},start:function(e){app.Models.regEvent=new app.Models.RegEvent(e.regEvent),app.Models.regEvent.setClasses(e.regEventClasses)}}),app.Views.Login=Backbone.View.extend({tagName:"div",className:"glm-reg-login",template:_.template($("#eventReg-account-login").html()),events:{"click .accountLogin":"loginToAccount","click #loginCancel":"closeLoginForm"},initialize:function(){return this},closeLoginForm:function(){this.remove(),$("#appLogin").show()},loginToAccount:function(){this.model.set({username:this.$userInput.val().trim(),password:this.$pwdInput.val().trim()}),this.model.save(null,{error:function(){return console.log({error:"message"}),{error:"message"}},success:function(){}})},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.$userInput=this.$(".login"),this.$pwdInput=this.$(".password"),this}}),app.Views.RegClass=Backbone.View.extend({tagName:"div",className:"glm-reg-level",template:_.template($("#regClass-template").html()),initialize:function(){return this.listenTo(this.model.accounts,"add",this.addOne),this.listenTo(this.model.accounts,"create",this.addOne),this.listenTo(this.model.accounts,"reset",this.addAll),this},events:{"click .addRegistrant":"newEntry"},newEntry:function(){this.$newName=this.$(".addName"),this.$newEmail=this.$(".addEmail"),this.$newName.val().trim()&&this.$newEmail.val().trim()&&(this.model.accounts.create({name:this.$newName.val().trim(),email:this.$newEmail.val().trim(),parent:this.model.id}),this.$newName.val(""),this.$newEmail.val(""))},render:function(){return this.$el.html(this.template(this.model.toJSON())),this},addOne:function(e){if(e.isValid()){var t=new app.Views.Account({model:e});this.$el.append(t.render().el)}},addAll:function(){this.$(".glm-reg-level").html("")}}),app.Views.RegEvent=Backbone.View.extend({tagName:"div",className:"glm-reg-event-item clearfix",template:_.template($("#regEvent-template").html()),initialize:function(){this.listenTo(this.model,"change",this.render)},render:function(){this.$el.html(this.template(this.model.toJSON()));var e=app.Models.regEvent.classes.map(function(e){return new app.Views.RegClass({model:e}).render().el});return this.$el.append(e),this}});
\ No newline at end of file
+app.Models.Account=Backbone.Model.extend({defaults:{id:"",email:"",parent:""},initialize:function(){this.on("invalid",function(e,t){console.log(t)})},validate:function(e,t){if(void 0===e.email||""===e.email)return"Need an email address!"}}),app.Models.AccountDetail=app.Models.Account.extend({defaults:{id:"",fname:"",lname:"",org:"",title:"",addr1:"",addr2:"",city:"",state:"",zip:"",country:"",phone:"",fax:"",email_ok:!1,is_member:!1,date_created:"",email:"",parent:""}}),app.Models.Login=Backbone.Model.extend({defaults:{username:"",password:""},urlRoot:appLoginUrl,initialize:function(){this.on("invalid",function(e,t){console.log(t)})},validate:function(e,t){return void 0===e.username||""===e.username?"Username required!":void 0===e.password||""===e.password?"Password required!":void 0}}),app.Models.RegClass=Backbone.Model.extend({defaults:{reg_event:0,name:"",descr:"",reg_rate_name:"",reg_rate_base_price:"",reg_rate_per_reg:""},initialize:function(){this.accounts=new app.Collections.Accounts,this.accounts.fetch()}}),app.Models.RegEvent=Backbone.Model.extend({defaults:{name:"regEvent",event_name:"",event_code:"",notify_email:"",attendees_max:0,attendees_max_per_reg:0,reg_hold_minutes:0,cart_hold_days:0,terms:""},initialize:function(){this.classes=new app.Collections.RegClasses},setClasses:function(e){this.classes.reset(e)}}),app.Models.regRate=Backbone.Model.extend({defaults:{reg_event:0,reg_class:"",name:"",start_days:0,end_days:0,base_rate:0,per_registrant:0,registrant_credits:0},initialize:function(){}}),app.Collections.Accounts=Backbone.Collection.extend({model:app.Models.Account,localStorage:new Backbone.LocalStorage("Accounts"),sync:function(e,t,i){console.log("sync called on collection. method: "+e)}}),app.Collections.RegClasses=Backbone.Collection.extend({model:app.Models.RegClass}),app.Collections.RegRates=Backbone.Collection.extend({model:app.Models.RegRate}),app.Views.Account=Backbone.View.extend({tagName:"div",className:"glm-reg-level-registrant clearfix",template:_.template($("#account-template").html()),events:{"click label":"edit","click .glm-reg-level-registrant-delete":"deleteOne","click .saveRegistrant":"close"},initialize:function(){return this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"destroy",this.remove),this},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.$nameInput=this.$(".editName"),this.$emailInput=this.$(".editEmail"),this},deleteOne:function(){this.model.destroy()},edit:function(){this.$el.addClass("editing"),this.$nameInput.focus()},close:function(){var e=this.$nameInput.val().trim(),t=this.$emailInput.val().trim();e&&t?this.model.save({name:e,email:t}):this.clear(),this.$el.removeClass("editing")}}),Backbone.emulateJSON=!0,Backbone.emulateHTTP=!0,app.Views.App=Backbone.View.extend({el:"#regApp",initialize:function(){this.event=new app.Views.RegEvent({model:app.Models.regEvent}),this.render()},render:function(){return this.$el.append(this.event.render().el),this},events:{"click #appLogin":"login"},login:function(){this.loginView=new app.Views.Login({model:new app.Models.Login}),this.$el.append(this.loginView.render().el),$("#appLogin").hide()},start:function(e){app.Models.regEvent=new app.Models.RegEvent(e.regEvent),app.Models.regEvent.setClasses(e.regEventClasses)}}),app.Views.Login=Backbone.View.extend({tagName:"div",className:"glm-reg-login",template:_.template($("#eventReg-account-login").html()),events:{"click .accountLogin":"loginToAccount","click #loginCancel":"closeLoginForm"},initialize:function(){return this},closeLoginForm:function(){this.remove(),$("#appLogin").show()},loginToAccount:function(){$.ajax({url:ajaxUrl})},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.$userInput=this.$(".login"),this.$pwdInput=this.$(".password"),this}}),app.Views.RegClass=Backbone.View.extend({tagName:"div",className:"glm-reg-level",template:_.template($("#regClass-template").html()),initialize:function(){return this.listenTo(this.model.accounts,"add",this.addOne),this.listenTo(this.model.accounts,"create",this.addOne),this.listenTo(this.model.accounts,"reset",this.addAll),this},events:{"click .addRegistrant":"newEntry"},newEntry:function(){this.$newEmail=this.$(".addEmail"),this.$newEmail.val().trim()&&$.ajax({context:this,url:ajaxUrl+"&glm_action=account&option=checkEmail",dataType:"json",data:"email="+this.$newEmail.val().trim()}).done(function(e){!0!==e.validEmail?alert("Must be a valid email address!"):!0!==e.valid?alert("No account matched that email address!"):void 0!==e.id&&void 0!==e.email&&(this.model.accounts.create({id:e.id,email:e.email}),this.$newEmail.val(""))}).fail(function(e){console.log("Fail: "+e)})},render:function(){return this.$el.html(this.template(this.model.toJSON())),this},addOne:function(e){if(e.isValid()){var t=new app.Views.Account({model:e});this.$el.append(t.render().el)}},addAll:function(){this.$(".glm-reg-level").html("")}}),app.Views.RegEvent=Backbone.View.extend({tagName:"div",className:"glm-reg-event-item clearfix",template:_.template($("#regEvent-template").html()),initialize:function(){this.listenTo(this.model,"change",this.render)},render:function(){this.$el.html(this.template(this.model.toJSON()));var e=app.Models.regEvent.classes.map(function(e){return new app.Views.RegClass({model:e}).render().el});return this.$el.append(e),this}});
\ No newline at end of file
index 797a79e..2a07efc 100644 (file)
@@ -24,21 +24,10 @@ app.Views.Login = Backbone.View.extend({
     },
 
     loginToAccount: function(){
-        // console.log( 'user: ' + this.$userInput.val().trim() );
-        // console.log( 'password: ' + this.$pwdInput.val().trim() );
-        this.model.set({ username: this.$userInput.val().trim(), password: this.$pwdInput.val().trim()});
-        //console.log( this.model.url() );
-        this.model.save(null, {
-            error: function() {
-                console.log( {error: 'message'} );
-                return {error: 'message'};
-            },
-            success: function() {
-                //console.log( 'success login' );
-                // somehow call the view to remove
-            },
-        });
         // Send data to login ajax and verify user login
+        $.ajax({
+            url: ajaxUrl
+        });
     },
 
     render: function(){
index f7b47ee..8bc88e1 100644 (file)
@@ -20,20 +20,39 @@ app.Views.RegClass = Backbone.View.extend({
         'click .addRegistrant': 'newEntry',
     },
 
+    // For the new entry check the email from the server and see
+    // if there's already an account setup.
     newEntry: function(){
-        this.$newName  = this.$('.addName');
         this.$newEmail = this.$('.addEmail');
 
-        if ( !this.$newName.val().trim() || !this.$newEmail.val().trim() ) {
+        if ( !this.$newEmail.val().trim() ) {
              return;
         }
-        this.model.accounts.create({
-            name: this.$newName.val().trim(),
-            email: this.$newEmail.val().trim(),
-            parent: this.model.id
+        // Check for this email address
+        $.ajax({
+            context: this,
+            url: ajaxUrl + '&glm_action=account&option=checkEmail',
+            dataType: 'json',
+            data: 'email=' + this.$newEmail.val().trim()
+        })
+        .done(function(account){
+            // Check for id and email
+            if ( account.validEmail !== true ) {
+                // If not found then nothing was found for that email.
+                alert('Must be a valid email address!');
+            } else if ( account.valid !== true ) {
+                alert( 'No account matched that email address!' );
+            } else if ( account.id !== undefined && account.email !== undefined ) {
+                this.model.accounts.create({
+                    id: account.id,
+                    email: account.email
+                });
+                this.$newEmail.val('');
+            }
+        })
+        .fail(function(msg){
+            console.log('Fail: ' + msg);
         });
-        this.$newName.val('');
-        this.$newEmail.val('');
     },
 
     render: function(){
diff --git a/models/admin/ajax/account.php b/models/admin/ajax/account.php
new file mode 100644 (file)
index 0000000..e8203ea
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load Members data abstract
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH . '/data/dataAccount.php';
+
+/**
+ * Steve Note...
+ *
+ * You can get to this using the following URL.
+ *
+ * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=login
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+/**
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_account extends GLMDataRegistrationsAccount
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for data class
+        parent::__construct(false, false);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This model checks to see if the creditials passed in are correct.
+     *
+     * This model action does not return, it simply does it's work then calls die();
+     *
+     * @param $actionData
+     *
+     * Echos JSON string as response and does not return
+     */
+    public function modelAction( $actionData = false )
+    {
+        $return = false;
+
+        $option = filter_var( ~_REQUEST['option'], FILTER_SANITIZE_STRING );
+
+        switch ( $option ) {
+        case 'login':
+            // Check accounts for ones that match
+            $returnPassword = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT password
+                       FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX .  "account
+                      WHERE email = %s",
+                    $jsonData->username
+                )
+            );
+            if ( $returnPassword == crypt( $jsonData->password, $returnPassword ) ) {
+                $return = array( 'valid' => true );
+            } else {
+                $return = array( 'valid' => false );
+            }
+            break;
+        case 'checkEmail':
+            break;
+        }
+        if ( $email = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ) ) {
+            $accountId = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT id
+                      FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "account
+                     WHERE email = %s",
+                    $email
+                )
+            );
+            if ( $accountId ) {
+                $return = array(
+                    'valid'      => true,
+                    'validEmail' => true,
+                    'id'         => (int)$accountId,
+                    'email'      => $email,
+                );
+            } else {
+                $return = array(
+                    'valid'      => false,
+                    'validEmail' => true,
+                );
+            }
+        } else {
+            $return = array(
+                'valid'      => false,
+                'validEmail' => false,
+            );
+        }
+        header('Content-type:application/json;charset=utf-8', true);
+        echo json_encode( $return );
+        exit();
+    }
+}
diff --git a/models/admin/ajax/checkEmail.php b/models/admin/ajax/checkEmail.php
new file mode 100644 (file)
index 0000000..1722ed6
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+/**
+ * Steve Note...
+ *
+ * You can get to this using the following URL.
+ *
+ * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=login
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+/**
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_checkEmail
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for data class
+        //parent::__construct(false, false);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This model checks to see if the creditials passed in are correct.
+     *
+     * This model action does not return, it simply does it's work then calls die();
+     *
+     * @param $actionData
+     *
+     * Echos JSON string as response and does not return
+     */
+    public function modelAction( $actionData = false )
+    {
+        $return = false;
+
+        if ( $email = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ) ) {
+            $accountId = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT id
+                      FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "account
+                     WHERE email = %s",
+                    $email
+                )
+            );
+            if ( $accountId ) {
+                $return = array(
+                    'valid'      => true,
+                    'validEmail' => true,
+                    'id'         => (int)$accountId,
+                    'email'      => $email,
+                );
+            } else {
+                $return = array(
+                    'valid'      => false,
+                    'validEmail' => true,
+                );
+            }
+        } else {
+            $return = array(
+                'valid'      => false,
+                'validEmail' => false,
+            );
+        }
+        header('Content-type:application/json;charset=utf-8', true);
+        echo json_encode( $return );
+        exit();
+    }
+}
diff --git a/models/admin/ajax/login.php b/models/admin/ajax/login.php
deleted file mode 100644 (file)
index f38bb5e..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-
-/**
- * Gaslight Media Members Database
- * PDF Output by admin-ajax
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * @author   Chuck Scott <cscott@gaslightmedia.com>
- * @license  http://www.gaslightmedia.com Gaslightmedia
- * @version  0.1
- */
-
-/**
- * Steve Note...
- *
- * You can get to this using the following URL.
- *
- * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=login
- *
- * You should be able to do this as POST or GET and should be able to add and read additional parameters.
- * I added a "mystuff" parameter to the URL above and it does output from the code in the
- * modelAction() function below.
- *
- * To add another model under models/admin/ajax all you need to do is create it and add it to the
- * setup/validActions.php file.
- *
- */
-
-// Load Members data abstract
-// require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php';
-
-/**
- * This class performs the work of handling images passed to it via
- * an AJAX call that goes through the WorPress AJAX Handler.
- *
- */
-class GlmMembersAdmin_ajax_login
-{
-
-    /**
-     * WordPress Database Object
-     *
-     * @var $wpdb
-     * @access public
-     */
-    public $wpdb;
-    /**
-     * Plugin Configuration Data
-     *
-     * @var $config
-     * @access public
-     */
-    public $config;
-
-    /*
-     * Constructor
-     *
-     * This contructor sets up this model. At this time that only includes
-     * storing away the WordPress data object.
-     *
-     * @return object Class object
-     *
-     */
-    public function __construct ($wpdb, $config)
-    {
-
-        // Save WordPress Database object
-        $this->wpdb = $wpdb;
-
-        // Save plugin configuration object
-        $this->config = $config;
-
-        // Run constructor for data class
-        //parent::__construct(false, false);
-
-    }
-
-    /*
-     * Perform Model Action
-     *
-     * This model checks to see if the creditials passed in are correct.
-     *
-     * This model action does not return, it simply does it's work then calls die();
-     *
-     * @param $actionData
-     *
-     * Echos JSON string as response and does not return
-     */
-    public function modelAction( $actionData = false )
-    {
-        $return = false;
-
-        // Get the model from $_REQUEST
-        $jsonData = json_decode( stripslashes( $_REQUEST['model'] ) );
-
-        // Check accounts for ones that match
-        $returnPassword = $this->wpdb->get_var(
-            $this->wpdb->prepare(
-                "SELECT password
-                   FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX .  "account
-                  WHERE email = %s",
-                $jsonData->username
-            )
-        );
-
-        if ( $returnPassword == crypt( $jsonData->password, $returnPassword ) ) {
-            header('Content-type:application/json;charset=utf-8', true);
-            json_encode( array( true ) );
-        } else {
-            echo 'error message';
-            exit();
-        }
-        wp_die();
-
-    }
-}
index cfd2d3a..7f01cc5 100644 (file)
         $scripts = array(
             'backbone-local' => 'js/lib/backbone.localStorage.min.js',
             'regApp'         => 'js/regApp.js',
-            // 'account'        => 'js/models/account.js',
-            // 'regClass'       => 'js/models/regClass.js',
-            // 'regEvent'       => 'js/models/regEvent.js',
-            // 'regRate'        => 'js/models/regRate.js',
-            // 'login'          => 'js/models/login.js',
-            // 'accounts'       => 'js/collections/accounts.js',
-            // 'regClasses'     => 'js/collections/regClasses.js',
-            // 'regRates'       => 'js/collections/regRates.js',
-            // 'registrantView' => 'js/views/account.js',
-            // 'regEventView'   => 'js/views/regEvent.js',
-            // 'regClassView'   => 'js/views/regClass.js',
-            // 'regLoginView'   => 'js/views/login.js',
-            // 'appView'        => 'js/views/app.js',
         );
         foreach ( $scripts as $scriptName => $scriptPath ) {
             wp_register_script(
         // including test data for now
         include GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . '/data/event_setup.php';
 
-        // if ( isset( $eventData[$eventRegID] ) ) {
-        //     $regEvent[] = $eventData[$eventRegID];
-        // } else {
-        //     $regEvent = array();
-        // }
-
         $regClass = $regEventSample['reg_class'][1];
 
+        // Find the regClass rate to be used
+        // There will only be one as this is based on the date.
+        //$regClassRate
+
+        $eventData = array();
+
         unset($regClass['reg_rate']);
 
         // Compile template data
             'entry'          => $regEventSample,
             'thisJsUrl'      => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js',
             'regEventJSON'   => json_encode( $regEventSample['reg_event'] ),
-            'regClassesJSON' => json_encode( $regClass )
+            'regClassesJSON' => json_encode( $regClass ),
+            'eventData'      => $eventData,
         );
              // Return status, any suggested view, and any data to controller
         return array(
index b974033..ac9f491 100644 (file)
@@ -60,7 +60,7 @@
 $glmMembersRegistrationsAddOnValidActions = array(
     'adminActions' => array(
         'ajax' => array(
-            'login'                      => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+            'account'                   => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
         ),
         'registrations' => array(
             'index'                     => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
index 19d7645..9fa0866 100644 (file)
 <script type="text/template" id="account-template">
     <a class="glm-reg-level-registrant-delete">Delete</a>
     <label class="registrant-label">
-        <span class="glm-reg-level-registrant-name"><%= name %></span>
         <span class="glm-reg-level-registrant-email"><%= email %></span>
     </label>
     <div class="registrant-edit">
-        <input type="text" class="editName" value="<%- name %>">
         <input type="text" class="editEmail" value="<%- email %>">
         <input type="submit" class="saveRegistrant" value="Save">
     </div>
 <script type="text/template" id="regClass-template">
     <h3><%= name %></h3>
     <p><%= descr %></p>
+    <div>
+        <div>Current Rate: <%= reg_rate_name %></div>
+        <div>Base Price: $<%= reg_rate_base_price %></div>
+        <div>Per Registrant: $<%= reg_rate_per_reg %></div>
+    </div>
     <div class="registrant-add clearfix">
-        <input type="text" class="addName" placeholder="Enter Name">
         <input type="text" class="addEmail" placeholder="Enter Email Address">
         <input type="submit" class="addRegistrant" value="Add">
     </div>
@@ -61,6 +63,7 @@
 {* And create the RegClasses collection *}
 <script>
 var appLoginUrl = '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=login';
+var ajaxUrl = '{$ajaxUrl}?action=glm_members_admin_ajax';
 var app = {
     Models: {},
     Collections: {},