Added AJAX processrs for front and admin AJAX calls from backbone.
Added sample regRequestEvent.php AJAX method for handling backbone event requests.
* @release SVN: $Id: dataRegRequest.php,v 1.0 2011/01/25 19:31:47 cscott
* Exp $
*/
-class GlmDataRegistrationsRequest extends GlmDataAbstract
+class GlmDataRegistrationsRegRequest extends GlmDataAbstract
{
/**
// Defaults
defaults: {
id: null,
- parent: 0,
reg_event: 0,
name: '',
descr: '',
this.rates = new app.Collections.Admin.RegRates;
},
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses'
+
});
// js/models/regAdminEvent.js
// Default regEvent values
defaults: {
- name: 'regEvent',
event_name: '',
event_code: '',
notify_email: '',
setClasses: function( regClasses ){
this.classes.reset( regClasses );
- },
+ }
});
// Default regRate values
defaults: {
id: null,
- parent: 0,
reg_event: 0,
reg_class: '',
name: '',
},
initialize: function(){
- localStorage: new Backbone.LocalStorage( 'Rates' );
},
+
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regRates'
});
// Classes Collection
app.Collections.Admin.RegClasses = Backbone.Collection.extend({
model: app.Models.Admin.RegClass,
-
- localStorage: new Backbone.LocalStorage( 'Classes' ),
-
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses',
+ add:
});
// js/collections/regRates.js
// Registration Rate Collection
app.Collections.Admin.RegRates = Backbone.Collection.extend({
model: app.Models.Admin.RegRate,
-
- localStorage: new Backbone.LocalStorage( 'Rates' )
-
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regRates'
});
// js/views/app.js
'click .class-add-rate': 'addRate'
},
- update: function(){
- console.log('update called');
- var cName = this.$('.class-name').val().trim();
- var cDescr = this.$('.class-descr').val().trim();
-// this.model.save({ name: cName, descr: cDescr });
- this.$('.class-display-template').show();
- this.$('.class-edit-template').hide();
- glmSubmitRequired--;
- },
-
add: function(){
console.log('add called');
this.$('.class-display-template').show();
var cName = this.$('.class-name').val().trim();
var cDescr = this.$('.class-descr').val().trim();
this.model.set({ name: cName, descr: cDescr });
+
+ if (!this.model.save({ name: cName, descr: cDescr })) {
+ console.log('AJAX Save Error');
+ } else {
+ console.log('AJAX Save Successful');
+ }
// Add this new model to the collection.
var parentEvent = this.model.get( 'parent' ); // ????????
// parentEvent.classes.create( this.model );
},
deleteLevel: function(){
+ console.log('deleteLevel called');
if (this.newClass) {
alert('removing a new class. May have to avoid doing any ajax call if not updated yet.')
}
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
this.$('.class-name').focus();
- glmSubmitRequired++;
+ glmSubmitRequired += 1;
+ },
+
+ update: function(){
+ console.log('update called');
+ var cName = this.$('.class-name').val().trim();
+ var cDescr = this.$('.class-descr').val().trim();
+ if (!this.model.save({ name: cName, descr: cDescr })) {
+ console.log('AJAX Save Error');
+ } else {
+ console.log('AJAX Save Successful');
+ }
+ this.$('.class-display-template').show();
+ this.$('.class-edit-template').hide();
+ glmSubmitRequired -= 1;
},
render: function(addFlag){
this.$el.html( this.template( this.model.toJSON() ) );
// If addFlag set then we know the call to this is to add a class and not to initialize existing classes
- if (addFlag) {
+ if (addFlag == true) {
console.log('New level created');
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
this.$('.class-add').show();
this.$('.class-name').focus();
this.newClass = true;
- glmSubmitRequired++;
+ glmSubmitRequired += 1;
}
return this;
},
},
addAll: function(){
+ console.log('addAll called');
jQuery('.glm-reg-level').html('');
},
console.log( 'addLevel Called' );
// create a new view and model and add it to classes and call render.
// Create the model for the view and add it to the collection
- var regClass = new app.Models.Admin.RegClass({ parent: this.model });
+ var regClass = new app.Models.Admin.RegClass({ glmAction: 'regClass', parent: this.model });
//this.model.classes.add( regClass );
var view = new app.Views.Admin.RegClass({ model: regClass });
this.$el.append(view.render(true).el);
this.$('.rate-display-template').hide();
this.$('.rate-edit-template').show();
this.$('.rate-name').focus();
- glmSubmitRequired++;
+// glmSubmitRequired++;
},
update: function() {
// this.model.save({ name: cName });
this.$('.rate-display-template').show();
this.$('.rate-edit-template').hide();
- glmSubmitRequired--;
+// glmSubmitRequired--;
},
this.$('.rate-add').show();
this.$('.rate-name').focus();
this.newRate = true;
- glmSubmitRequired++;
+// glmSubmitRequired++;
}
return this;
}
// Classes Collection
app.Collections.Admin.RegClasses = Backbone.Collection.extend({
model: app.Models.Admin.RegClass,
-
- localStorage: new Backbone.LocalStorage( 'Classes' ),
-
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses',
+ add:
});
// Registration Rate Collection
app.Collections.Admin.RegRates = Backbone.Collection.extend({
model: app.Models.Admin.RegRate,
-
- localStorage: new Backbone.LocalStorage( 'Rates' )
-
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regRates'
});
// Defaults
defaults: {
id: null,
- parent: 0,
reg_event: 0,
name: '',
descr: '',
this.rates = new app.Collections.Admin.RegRates;
},
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses'
+
});
// Default regEvent values
defaults: {
- name: 'regEvent',
event_name: '',
event_code: '',
notify_email: '',
setClasses: function( regClasses ){
this.classes.reset( regClasses );
- },
+ }
});
// Default regRate values
defaults: {
id: null,
- parent: 0,
reg_event: 0,
reg_class: '',
name: '',
},
initialize: function(){
- localStorage: new Backbone.LocalStorage( 'Rates' );
},
+
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regRates'
});
'click .class-add-rate': 'addRate'
},
- update: function(){
- console.log('update called');
- var cName = this.$('.class-name').val().trim();
- var cDescr = this.$('.class-descr').val().trim();
-// this.model.save({ name: cName, descr: cDescr });
- this.$('.class-display-template').show();
- this.$('.class-edit-template').hide();
- glmSubmitRequired--;
- },
-
add: function(){
console.log('add called');
this.$('.class-display-template').show();
var cName = this.$('.class-name').val().trim();
var cDescr = this.$('.class-descr').val().trim();
this.model.set({ name: cName, descr: cDescr });
+
+ if (!this.model.save({ name: cName, descr: cDescr })) {
+ console.log('AJAX Save Error');
+ } else {
+ console.log('AJAX Save Successful');
+ }
// Add this new model to the collection.
var parentEvent = this.model.get( 'parent' ); // ????????
// parentEvent.classes.create( this.model );
},
deleteLevel: function(){
+ console.log('deleteLevel called');
if (this.newClass) {
alert('removing a new class. May have to avoid doing any ajax call if not updated yet.')
}
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
this.$('.class-name').focus();
- glmSubmitRequired++;
+ glmSubmitRequired += 1;
+ },
+
+ update: function(){
+ console.log('update called');
+ var cName = this.$('.class-name').val().trim();
+ var cDescr = this.$('.class-descr').val().trim();
+ if (!this.model.save({ name: cName, descr: cDescr })) {
+ console.log('AJAX Save Error');
+ } else {
+ console.log('AJAX Save Successful');
+ }
+ this.$('.class-display-template').show();
+ this.$('.class-edit-template').hide();
+ glmSubmitRequired -= 1;
},
render: function(addFlag){
this.$el.html( this.template( this.model.toJSON() ) );
// If addFlag set then we know the call to this is to add a class and not to initialize existing classes
- if (addFlag) {
+ if (addFlag == true) {
console.log('New level created');
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
this.$('.class-add').show();
this.$('.class-name').focus();
this.newClass = true;
- glmSubmitRequired++;
+ glmSubmitRequired += 1;
}
return this;
},
},
addAll: function(){
+ console.log('addAll called');
jQuery('.glm-reg-level').html('');
},
console.log( 'addLevel Called' );
// create a new view and model and add it to classes and call render.
// Create the model for the view and add it to the collection
- var regClass = new app.Models.Admin.RegClass({ parent: this.model });
+ var regClass = new app.Models.Admin.RegClass({ glmAction: 'regClass', parent: this.model });
//this.model.classes.add( regClass );
var view = new app.Views.Admin.RegClass({ model: regClass });
this.$el.append(view.render(true).el);
this.$('.rate-display-template').hide();
this.$('.rate-edit-template').show();
this.$('.rate-name').focus();
- glmSubmitRequired++;
+// glmSubmitRequired++;
},
update: function() {
// this.model.save({ name: cName });
this.$('.rate-display-template').show();
this.$('.rate-edit-template').hide();
- glmSubmitRequired--;
+// glmSubmitRequired--;
},
this.$('.rate-add').show();
this.$('.rate-name').focus();
this.newRate = true;
- glmSubmitRequired++;
+// glmSubmitRequired++;
}
return this;
}
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Registration add-on admin AJAX processor
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+/**
+ * This class processes AJAX requests from admin Backbone.js registrations interface
+ */
+class GlmMembersAdmin_ajax_regAdmin
+{
+
+ /**
+ * 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 wp_die();
+ *
+ * @param $actionData
+ *
+ * Echos JSON string as response and does not return
+ */
+ public function modelAction( $actionData = false )
+ {
+
+trigger_error(print_r($_REQUEST,1), E_USER_NOTICE);
+
+ // Get Backbone collection we're talking with
+ $collection = filter_var( $_REQUEST['collection'], FILTER_SANITIZE_STRING );
+
+ // Get the submission method
+ $method = filter_var( $_REQUEST['_method'], FILTER_SANITIZE_STRING );
+
+ // If not a valid collection, die quietly
+ if (!in_array($collection, array('regClasses', 'regRates'))) {
+ wp_die();
+ }
+
+ // If not a valid method, die quietly
+ if (!in_array($method, array('POST', 'GET', 'PUT', 'PATCH', 'DELETE'))) {
+ wp_die();
+ }
+
+ // Try to decode the JSON
+ $modelData = json_decode(stripslashes($_REQUEST['model']), true);
+
+ // Build model and path and class names
+ $modelName = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH.'/models/admin/ajax/regAdmin/'.$collection.'.php';
+ $className = 'GlmMembersAdmin_registrations_ajax_'.$collection;
+
+ // Check if model for this request exists
+ if (!file_exists($modelName)) {
+ trigger_error ( "ERROR: The specified model file doesn't exist. ($modelName)", E_USER_ERROR);
+ wp_die();
+ }
+
+ // Load the model file
+ require_once $modelName;
+
+ // check for an invalid model class name
+ if (!class_exists($className)) {
+ trigger_error ( "ERROR: The specified class name doesn't exist. ($className)", E_USER_ERROR);
+ wp_die();
+ }
+
+ // Instantiate the model and ask it to perform the work
+ $model = new $className($this->wpdb, $this->config);
+
+ $results = $model->modelAction($method, $modelData);
+
+
+ }
+}
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Registrations AJAX processing for Classes (registration levels)
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release regClasses.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/dataRegClass.php';
+
+class GlmMembersAdmin_registrations_ajax_regClasses extends GlmDataRegistrationsRegClass
+{
+
+ /**
+ * 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($method, $modelData)
+ {
+
+//trigger_error(print_r($modelData,1)."Method = $method");
+
+ // Perform specified action
+ switch ($method) {
+
+ // Create
+ case 'POST':
+ break;
+
+ // Read
+ case 'GET':
+ break;
+
+ // Update
+ case 'PUT':
+
+ // If we have a numeric class (level) ID
+ $classID = ($modelData['id'] - 0);
+ if ($classID > 0) {
+
+ // Try to update the class (level) data
+ $this->wpdb->update(
+ $this->table,
+ array(
+ 'name' => $modelData['name'],
+ 'descr' => $modelData['descr']
+ ),
+ array('id' => $classID),
+ array(
+ '%s',
+ '%s'
+ ),
+ array( '%d' )
+ );
+
+ }
+
+ break;
+
+ // Patch
+ case 'PATCH':
+ break;
+
+ // Delete
+ case 'DELETE':
+ break;
+
+ default:
+ die(); // should never get here
+ break;
+
+ }
+
+ wp_die();
+
+
+
+ }
+
+
+}
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Registration add-on front AJAX processor
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+/**
+ * This class processes AJAX requests from front-end Backbone.js registrations interface
+ */
+class GlmMembersAdmin_ajax_regFront
+{
+
+ /**
+ * 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 wp_die();
+ *
+ * @param $actionData
+ *
+ * Echos JSON string as response and does not return
+ */
+ public function modelAction( $actionData = false )
+ {
+
+ // Get Backbone collection we're talking with
+ $collection = filter_var( $_REQUEST['collection'], FILTER_SANITIZE_STRING );
+
+ // Get the submission method
+ $method = filter_var( $_REQUEST['_method'], FILTER_SANITIZE_STRING );
+
+ // If not a valid collection, die quietly
+ if (!in_array($collection, array('regClasses', 'regRates'))) {
+ wp_die();
+ }
+
+ // If not a valid method, die quietly
+ if (!in_array($method, array('POST', 'GET', 'PUT', 'PATCH', 'DELETE'))) {
+ wp_die();
+ }
+
+ // Try to decode the JSON
+ $modelData = json_decode(stripslashes($_REQUEST['model']), true);
+
+ // Build model and path and class names
+ $modelName = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH.'/models/admin/ajax/regFront/'.$collection.'.php';
+ $className = 'GlmMembersAdmin_registrations_ajax_'.$collection;
+
+ // Check if model for this request exists
+ if (!file_exists($modelName)) {
+ trigger_error ( "ERROR: The specified model file doesn't exist. ($modelName)", E_USER_ERROR);
+ wp_die();
+ }
+
+ // Load the model file
+ require_once $modelName;
+
+ // check for an invalid model class name
+ if (!class_exists($className)) {
+ trigger_error ( "ERROR: The specified class name doesn't exist. ($className)", E_USER_ERROR);
+ wp_die();
+ }
+
+ // Instantiate the model and ask it to perform the work
+ $model = new $className($this->wpdb, $this->config);
+
+ $results = $model->modelAction($method, $modelData);
+
+
+ }
+}
--- /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/dataRegEvent.php';
+
+class GlmMembersAdmin_registrations_ajax_regClasses extends GlmDataRegistrationsRequestEvent
+{
+
+ /**
+ * 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($method, $modelData)
+ {
+
+//trigger_error(print_r($modelData,1)."Method = $method");
+
+ // Perform specified action
+ switch ($method) {
+
+ // Create
+ case 'POST':
+ break;
+
+ // Read
+ case 'GET':
+ break;
+
+ // Update
+ case 'PUT':
+
+ break;
+
+ // Patch
+ case 'PATCH':
+ break;
+
+ // Delete
+ case 'DELETE':
+ break;
+
+ default:
+ die(); // should never get here
+ break;
+
+ }
+
+ wp_die();
+
+
+
+ }
+
+
+}
'adminActions' => array(
'ajax' => array(
'account' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+ 'regAdmin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG
),
'registrations' => array(
'index' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
var glmSubmitRequired = 0;
//var $=jQuery.noConflict();
- var ajaxUrl = '{$ajaxUrl}?action=glm_members_admin_ajax';
+ var ajaxUrl = '{$ajaxUrl}?action=glm_members_admin_ajax';
var app = {
Models: { Admin: {} },
Collections: { Admin: {} },