Creating a reg_request so I can add the registrant.
Adding now model and view for the registrant.
.reg-class-accounts {
padding: 5px;
}
+.new-reg {
+ background-color: white;
+ border: 1px solid black;
+ padding: 30px;
+ position: absolute;
+ left: 10px;
+ top: 50px;
+}
app.Collections.Front.Accounts = Backbone.Collection.extend({
model: app.Models.Front.Account,
- initialize: function( parent ){
- this.parent = parent;
- },
+ // initialize: function( parent ){
+ // this.parent = parent;
+ // },
url: ajaxUrl+'&glm_action=regFront&collection=accounts',
// //this.add( model );
// },
- remove: function( model ){
- localStorage.removeItem( localStorage.key('Account-' + model.parent + '-'+ model.id ) );
- //console.log( 'Delete called in collection ' );
- },
+ // remove: function( model ){
+ // //localStorage.removeItem( localStorage.key('Account-' + model.parent + '-'+ model.id ) );
+ // //console.log( 'Delete called in collection ' );
+ // },
- read: function(){
- console.log( 'Read called' );
- },
+ // read: function(){
+ // console.log( 'Read called' );
+ // },
// save: function(){
// console.log('Update Called');
// },
- fetch: function(){
- var newModels = [];
- for ( var i = 0; i < localStorage.length; i++ ) {
- var curItem = JSON.parse( localStorage.getItem( localStorage.key( i ) ) );
- if ( curItem.parent === this.parent ) {
- // now add it to this collection
- newModels.push( new app.Models.Front.Account( curItem ) );
- }
- }
- this.reset( newModels );
- },
+ // fetch: function(){
+ // var newModels = [];
+ // for ( var i = 0; i < localStorage.length; i++ ) {
+ // var curItem = JSON.parse( localStorage.getItem( localStorage.key( i ) ) );
+ // if ( curItem.parent === this.parent ) {
+ // // now add it to this collection
+ // newModels.push( new app.Models.Front.Account( curItem ) );
+ // }
+ // }
+ // this.reset( newModels );
+ // },
});
--- /dev/null
+app.Collections.Front.RegRequestRegistrants = Backbone.Collection.extend({
+ model: app.Models.Front.RegRequestRegistrant,
+
+ url: ajaxUrl+'&glm_action=regFront&collection=registrant=',
+
+});
app.Models.Front.Cart = Backbone.Model.extend({
defaults: {
+ id: 0,
+ name: 'cart',
status: null,
errorMsg: '',
notes: [],
// Defaults
defaults: {
+ name: 'regClass',
id: 0,
reg_event: 0,
name: '',
descr: '',
+ reg_rate_id: 0,
reg_rate_name: '',
reg_rate_base_price: '',
reg_rate_per_reg: '',
},
initialize: function(){
- this.accounts = new app.Collections.Front.Accounts( this.id );
- //this.accounts.fetch();
+ this.registrants = new app.Collections.Front.RegRequestRegistrants( [] );
},
});
});
+app.Models.Front.RegRequestRegistrant = Backbone.Model.extend({
+ defaults: {
+ name: 'registrant',
+ id: 0,
+ account: 0,
+ reg_event: 0,
+ reg_class: 0,
+ event_name: '',
+ reg_time: 0,
+ event_datetime: '',
+ reg_request: 0,
+ reg_request_event: 0,
+ reg_request_class: 0,
+ reg_request_rate: 0,
+ reg_request_hold: false,
+ reg_request_hold_not_available: false,
+ email: '',
+ fname: '',
+ lname: '',
+ },
+
+ url: ajaxUrl+'&glm_action=regFront&collection=registrant'
+});
+
app.Models.Front.Request = Backbone.Model.extend({
defaults: {
+ name: 'request',
id: null,
account: null,
validated: false,
app.Collections.Front.Accounts = Backbone.Collection.extend({
model: app.Models.Front.Account,
- initialize: function( parent ){
- this.parent = parent;
- },
+ // initialize: function( parent ){
+ // this.parent = parent;
+ // },
url: ajaxUrl+'&glm_action=regFront&collection=accounts',
// //this.add( model );
// },
- remove: function( model ){
- localStorage.removeItem( localStorage.key('Account-' + model.parent + '-'+ model.id ) );
- //console.log( 'Delete called in collection ' );
- },
+ // remove: function( model ){
+ // //localStorage.removeItem( localStorage.key('Account-' + model.parent + '-'+ model.id ) );
+ // //console.log( 'Delete called in collection ' );
+ // },
- read: function(){
- console.log( 'Read called' );
- },
+ // read: function(){
+ // console.log( 'Read called' );
+ // },
// save: function(){
// console.log('Update Called');
// },
- fetch: function(){
- var newModels = [];
- for ( var i = 0; i < localStorage.length; i++ ) {
- var curItem = JSON.parse( localStorage.getItem( localStorage.key( i ) ) );
- if ( curItem.parent === this.parent ) {
- // now add it to this collection
- newModels.push( new app.Models.Front.Account( curItem ) );
- }
- }
- this.reset( newModels );
- },
+ // fetch: function(){
+ // var newModels = [];
+ // for ( var i = 0; i < localStorage.length; i++ ) {
+ // var curItem = JSON.parse( localStorage.getItem( localStorage.key( i ) ) );
+ // if ( curItem.parent === this.parent ) {
+ // // now add it to this collection
+ // newModels.push( new app.Models.Front.Account( curItem ) );
+ // }
+ // }
+ // this.reset( newModels );
+ // },
});
// localStorage
});
+app.Collections.Front.RegRequestRegistrants = Backbone.Collection.extend({
+ model: app.Models.Front.RegRequestRegistrant,
+
+ url: ajaxUrl+'&glm_action=regFront&collection=registrant=',
+
+});
+
// js/views/account.js
// Event Registrant View
});
+app.Views.Front.NewRegistrant = Backbone.View.extend({
+ tagName: 'div',
+
+ className: 'new-reg',
+
+ template: _.template( jQuery('#eventReg-registrant-add').html() ),
+
+ events: {
+ 'click .add-new-registrant': 'addNew',
+ },
+
+ initialize: function(){
+ return this;
+ },
+
+ addNew: function(){
+ console.log( 'called addNew in newReg 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 );
+
+ // Create a account
+ // this.model.set({
+ // fname: this.$('.reg_fname').val().trim(),
+ // lname: this.$('.reg_lname').val().trim(),
+ // email: this.$('.reg_email').val().trim(),
+ // });
+
+
+ // Destroy the model and view
+ this.model.destroy();
+ this.remove();
+ },
+
+ render: function(){
+ this.$el.html( this.template( this.model.toJSON() ) );
+ return this;
+ },
+
+});
+
// js/views/regClass.js
var newId = 0;
app.Views.Front.RegClass = Backbone.View.extend({
template: _.template( jQuery('#regClass-template').html() ),
initialize: function(){
- this.model.accounts.fetch();
- 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.listenTo( this.model.accounts, 'all', this.render );
+ this.listenTo( this.model.registrants, 'add', this.addOne );
+ this.listenTo( this.model.registrants, 'create', this.addOne );
+ this.listenTo( this.model.registrants, 'remove', this.deleteOne );
this.listenTo( this.model, 'change', this.render );
return this;
},
render: function(){
- this.model.set({ reg_count: this.model.accounts.length });
+ this.model.set({ reg_count: this.model.registrants.length });
this.$el.html( this.template( this.model.toJSON() ) );
// Need to see if this class has attendees and render them
- var view = this.model.accounts.map(function(item){
- return (new app.Views.Front.Account({ model: item })).render().el;
+ var view = this.model.registrants.map(function(item){
+ return (new app.Views.Front.RegRequestRegistrant({ model: item })).render().el;
});
var accountContainer = this.$('.reg-class-accounts');
accountContainer.append(view);
},
deleteOne: function( item ){
- console.log( item );
- console.log( 'Delete called in view' );
- console.log( this.model.accounts.length );
this.render();
},
data: 'email=' + this.$newEmail.val().trim()
})
.done(function(account){
- //console.log(account);
+ console.log(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,
+ } else if ( account.id !== undefined && account.email !== undefined ) {
+ console.log( cart.get( 'request' ) );
+ var regRequest = cart.get( 'request' );
+ this.model.registrants.create({
+ account: account.id,
+ reg_request: regRequest.id,
+ reg_event: this.model.get( 'reg_event' ),
+ reg_class: this.model.get( 'id' ),
+ reg_request_rate: this.model.get('reg_rate_id'),
email: account.email,
- parent: this.model.id
});
- //this.model.trigger('change');
this.$newEmail.val('');
} else if ( account.email !== undefined ) {
- // use the dummy id
- newId++;
- this.model.accounts.create({
- id: 'new_' + newId,
- email: account.email,
- parent: this.model.id
- });
- //this.model.trigger('change');
+ // Here we need to create a popup form for a new entry.
+ // Create the new Registrant View
+ var nModel = new app.Models.Front.RegRequestRegistrant({email: account.email});
+ var nrView = new app.Views.Front.NewRegistrant({model: nModel});
+ this.$el.append( nrView.render().el );
this.$newEmail.val('');
}
})
},
});
+
+app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
+ tagName: 'div',
+
+ className: 'glm-reg-level-registrant clearfix',
+
+ template: _.template( jQuery('#registrant-template').html() ),
+
+ initialize: function(){
+ this.listenTo( this.model, 'change', this.render );
+ return this;
+ },
+
+ events: {
+ 'click .glm-reg-level-registrant-delete': 'deleteOne',
+ },
+
+ render: function(){
+ this.$el.html( this.template( this.model.toJSON() ) );
+ this.$emailInput = this.$('.editEmail');
+ return this;
+ },
+
+ deleteOne: function(){
+ //console.log( this.model );
+ this.model.destroy();
+ this.remove();
+ },
+
+});
app.Models.Front.Cart = Backbone.Model.extend({
defaults: {
+ id: 0,
+ name: 'cart',
status: null,
errorMsg: '',
notes: [],
// Defaults
defaults: {
+ name: 'regClass',
id: 0,
reg_event: 0,
name: '',
descr: '',
+ reg_rate_id: 0,
reg_rate_name: '',
reg_rate_base_price: '',
reg_rate_per_reg: '',
},
initialize: function(){
- this.accounts = new app.Collections.Front.Accounts( this.id );
- //this.accounts.fetch();
+ this.registrants = new app.Collections.Front.RegRequestRegistrants( [] );
},
});
--- /dev/null
+app.Models.Front.RegRequestRegistrant = Backbone.Model.extend({
+ defaults: {
+ name: 'registrant',
+ id: 0,
+ account: 0,
+ reg_event: 0,
+ reg_class: 0,
+ event_name: '',
+ reg_time: 0,
+ event_datetime: '',
+ reg_request: 0,
+ reg_request_event: 0,
+ reg_request_class: 0,
+ reg_request_rate: 0,
+ reg_request_hold: false,
+ reg_request_hold_not_available: false,
+ email: '',
+ fname: '',
+ lname: '',
+ },
+
+ url: ajaxUrl+'&glm_action=regFront&collection=registrant'
+});
app.Models.Front.Request = Backbone.Model.extend({
defaults: {
+ name: 'request',
id: null,
account: null,
validated: false,
--- /dev/null
+app.Views.Front.NewRegistrant = Backbone.View.extend({
+ tagName: 'div',
+
+ className: 'new-reg',
+
+ template: _.template( jQuery('#eventReg-registrant-add').html() ),
+
+ events: {
+ 'click .add-new-registrant': 'addNew',
+ },
+
+ initialize: function(){
+ return this;
+ },
+
+ addNew: function(){
+ console.log( 'called addNew in newReg 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 );
+
+ // Create a account
+ // this.model.set({
+ // fname: this.$('.reg_fname').val().trim(),
+ // lname: this.$('.reg_lname').val().trim(),
+ // email: this.$('.reg_email').val().trim(),
+ // });
+
+
+ // Destroy the model and view
+ this.model.destroy();
+ this.remove();
+ },
+
+ render: function(){
+ this.$el.html( this.template( this.model.toJSON() ) );
+ return this;
+ },
+
+});
template: _.template( jQuery('#regClass-template').html() ),
initialize: function(){
- this.model.accounts.fetch();
- 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.listenTo( this.model.accounts, 'all', this.render );
+ this.listenTo( this.model.registrants, 'add', this.addOne );
+ this.listenTo( this.model.registrants, 'create', this.addOne );
+ this.listenTo( this.model.registrants, 'remove', this.deleteOne );
this.listenTo( this.model, 'change', this.render );
return this;
},
render: function(){
- this.model.set({ reg_count: this.model.accounts.length });
+ this.model.set({ reg_count: this.model.registrants.length });
this.$el.html( this.template( this.model.toJSON() ) );
// Need to see if this class has attendees and render them
- var view = this.model.accounts.map(function(item){
- return (new app.Views.Front.Account({ model: item })).render().el;
+ var view = this.model.registrants.map(function(item){
+ return (new app.Views.Front.RegRequestRegistrant({ model: item })).render().el;
});
var accountContainer = this.$('.reg-class-accounts');
accountContainer.append(view);
},
deleteOne: function( item ){
- console.log( item );
- console.log( 'Delete called in view' );
- console.log( this.model.accounts.length );
this.render();
},
data: 'email=' + this.$newEmail.val().trim()
})
.done(function(account){
- //console.log(account);
+ console.log(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,
+ } else if ( account.id !== undefined && account.email !== undefined ) {
+ console.log( cart.get( 'request' ) );
+ var regRequest = cart.get( 'request' );
+ this.model.registrants.create({
+ account: account.id,
+ reg_request: regRequest.id,
+ reg_event: this.model.get( 'reg_event' ),
+ reg_class: this.model.get( 'id' ),
+ reg_request_rate: this.model.get('reg_rate_id'),
email: account.email,
- parent: this.model.id
});
- //this.model.trigger('change');
this.$newEmail.val('');
} else if ( account.email !== undefined ) {
- // use the dummy id
- newId++;
- this.model.accounts.create({
- id: 'new_' + newId,
- email: account.email,
- parent: this.model.id
- });
- //this.model.trigger('change');
+ // Here we need to create a popup form for a new entry.
+ // Create the new Registrant View
+ var nModel = new app.Models.Front.RegRequestRegistrant({email: account.email});
+ var nrView = new app.Views.Front.NewRegistrant({model: nModel});
+ this.$el.append( nrView.render().el );
this.$newEmail.val('');
}
})
--- /dev/null
+app.Views.Front.RegRequestRegistrant = Backbone.View.extend({
+ tagName: 'div',
+
+ className: 'glm-reg-level-registrant clearfix',
+
+ template: _.template( jQuery('#registrant-template').html() ),
+
+ initialize: function(){
+ this.listenTo( this.model, 'change', this.render );
+ return this;
+ },
+
+ events: {
+ 'click .glm-reg-level-registrant-delete': 'deleteOne',
+ },
+
+ render: function(){
+ this.$el.html( this.template( this.model.toJSON() ) );
+ this.$emailInput = this.$('.editEmail');
+ return this;
+ },
+
+ deleteOne: function(){
+ //console.log( this.model );
+ this.model.destroy();
+ this.remove();
+ },
+
+});
);
} else {
$return = array(
- //'valid' => false,
- 'valid' => true,
+ 'valid' => false,
'validEmail' => true,
'email' => $email,
);
$collection = filter_var( $_REQUEST['collection'], FILTER_SANITIZE_STRING );
// If not a valid collection, die quietly
- if (!in_array($collection, array('regClasses', 'request', 'account'))) {
+ if (!in_array($collection, array('regClasses', 'request', 'account', 'registrant'))) {
wp_die();
}
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Registrations AJAX processing for Registration Request Events
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release regRequestEvent.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+// Load Registrations data abstract
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequest.php';
+
+class GlmMembersAdmin_registrations_ajax_registrant // extends GlmDataRegistrationsRegRequest
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ /**
+ * Constructor
+ *
+ * This contructor performs the work for this model. This model returns
+ * an array containing the following.
+ *
+ * 'status'
+ *
+ * True if successfull and false if there was a fatal failure.
+ *
+ * 'view'
+ *
+ * A suggested view name that the contoller should use instead of the
+ * default view for this model or false to indicate that the default view
+ * should be used.
+ *
+ * 'data'
+ *
+ * Data that the model is returning for use in merging with the view to
+ * produce output.
+ *
+ * @wpdb object WordPress database object
+ *
+ * @return array Array containing status, suggested view, and any data
+ */
+ public function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+ /*
+ * Run constructor for the REgistrations data class
+ *
+ * Note, the third parameter is a flag that indicates to the Contacts
+ * data class that it should flag a group of fields as 'view_only'.
+ */
+ //parent::__construct(false, false, true);
+
+ }
+
+ public function modelAction($modelData)
+ {
+
+ trigger_error(print_r($modelData,1));
+ dei();
+
+ if ( !isset( $modelData['option'] ) ) {
+ $option = null;
+ } else {
+ $option = $modelData['option'];
+ }
+
+ if ( $modelData['id'] == 0 ) {
+ $option = 'add';
+ }
+
+ // Perform specified action
+ switch ( $option ) {
+
+ case 'add':
+ // Check for or create reg_request_event
+ if ( $modelData['reg_event'] ) {
+ return false;
+ }
+ $regRegquestEventId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_event
+ WHERE reg_event = %d",
+ $modelData['reg_event']
+ )
+ );
+ if ( !$regRegquestEventId ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request_event',
+ array(
+ 'account' => 0,
+ 'reg_request' => $modelData['reg_request'],
+ 'reg_event' => $modelData['reg_event'],
+ 'event_name' => $modelData['event_name'],
+ 'reg_time' => $modelData['reg_time'],
+ 'event_datetime' => $modelData['event_datetime'],
+ ),
+ array(
+ '%d',
+ '%d',
+ '%d',
+ '%s',
+ '%d',
+ '%s',
+ )
+ );
+ $regRequestEvent = $this->wpdb->insert_id;
+ }
+ // Check for or create reg_request_class
+ $regRequestClassId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_class
+ WHERE reg_request_event = %d
+ AND class = %d",
+ $regRegquestEventId,
+ $modelData['reg_class']
+ )
+ );
+ $this->wpdb->insert(
+ GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request_registrant',
+ array(
+ 'account' => $modelData['account'],
+ 'reg_event' => $modelData['reg_event'],
+ 'reg_request_event' => $modelData['reg_request_event'],
+ ),
+ array()
+ );
+ break;
+
+ case 'get':
+ break;
+
+ case 'update':
+ break;
+
+ case 'delete':
+ break;
+
+ default:
+ // If the model has an id then add it to the registrant table
+ // Check to see if the registrant is there if not create one
+ // $registrantId = $this->wpdb->get_var(
+ // $this->wpdb->prepare(
+ // "SELECT id
+ // FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request_registrant"
+ // )
+ // );
+ die(); // should never get here
+ break;
+
+ }
+
+ wp_die();
+
+
+
+ }
+
+
+}
$rates = $RegRate->getList( "T.reg_class = " . $rClass['id'] );
//echo '<pre>$rates: ' . print_r( $rates, true ) . '</pre>';
foreach ( $rates as $rate ) {
+ $rClass['reg_rate_id'] = $rate['id'];
$rClass['reg_rate_name'] = $rate['name'];
$rClass['reg_rate_base_price'] = $rate['base_rate'];
$rClass['reg_rate_per_reg'] = $rate['per_registrant'];
</div>
</script>
+<script type="text/template" id="registrant-template">
+ <a class="glm-reg-level-registrant-delete">Delete</a>
+ <label class="registrant-label">
+ <span class="glm-reg-level-registrant-email"><%= email %></span>
+ </label>
+</script>
+
<script type="text/template" id="account-template">
<a class="glm-reg-level-registrant-delete">Delete</a>
<label class="registrant-label">
<input class="password">
<input type="submit" class="accountLogin" value="Login">
</script>
+
+<script type="text/template" id="eventReg-registrant-add">
+ <div>
+ <input class="reg_fname" placeholder="First Name">
+ <input class="reg_lname" placeholder="Last Name">
+ <input class="reg_email" value="<%- email %>" disabled>
+ <input class="add-new-registrant" value="Add Registrant" type="submit">
+ </div>
+</script>
{/literal}
<div class="glm-reg-event-list" id="regApp">
<div class="glm-reg-account">