From 9f10af9942eed771227b60c4b0be3f99a45870fa Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 19 Sep 2017 20:05:53 -0400 Subject: [PATCH] Adding ajax class for handling save for the request. Setting up an ajax class following Chuck setup for the admin one. --- js/frontRegApp.js | 4 + js/models/front/cart.js | 1 + js/models/front/request.js | 3 + models/admin/ajax/regFront.php | 24 +++--- models/admin/ajax/regFront/request.php | 114 +++++++++++++++++++++++++ 5 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 models/admin/ajax/regFront/request.php diff --git a/js/frontRegApp.js b/js/frontRegApp.js index a6d4458..ff44eb0 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -96,6 +96,7 @@ app.Models.Front.Cart = Backbone.Model.extend({ setRequest: function( request ){ this.request = new app.Models.Front.Request( request ); + this.request.save(); }, setAccounts: function( accounts ){ @@ -217,6 +218,9 @@ app.Models.Front.Request = Backbone.Model.extend({ account_fname: '', account_lname: '', }, + + url: ajaxUrl+'&glm_action=regFront&collection=request', + }); // js/collections/accounts.js diff --git a/js/models/front/cart.js b/js/models/front/cart.js index 6fb50a4..3e0deb4 100644 --- a/js/models/front/cart.js +++ b/js/models/front/cart.js @@ -10,6 +10,7 @@ app.Models.Front.Cart = Backbone.Model.extend({ setRequest: function( request ){ this.request = new app.Models.Front.Request( request ); + this.request.save(); }, setAccounts: function( accounts ){ diff --git a/js/models/front/request.js b/js/models/front/request.js index 39e1e29..cf94aef 100644 --- a/js/models/front/request.js +++ b/js/models/front/request.js @@ -5,4 +5,7 @@ app.Models.Front.Request = Backbone.Model.extend({ account_fname: '', account_lname: '', }, + + url: ajaxUrl+'&glm_action=regFront&collection=request', + }); diff --git a/models/admin/ajax/regFront.php b/models/admin/ajax/regFront.php index 515c31e..87fe752 100644 --- a/models/admin/ajax/regFront.php +++ b/models/admin/ajax/regFront.php @@ -2,7 +2,7 @@ /** * Gaslight Media Members Database - * Registration add-on front AJAX processor + * Registration add-on front AJAX processor * * PHP version 5.5 * @@ -14,7 +14,7 @@ */ /** - * This class processes AJAX requests from front-end Backbone.js registrations interface + * This class processes AJAX requests from front-end Backbone.js registrations interface */ class GlmMembersAdmin_ajax_regFront { @@ -73,39 +73,39 @@ class GlmMembersAdmin_ajax_regFront // Get Backbone collection we're talking with $collection = filter_var( $_REQUEST['collection'], FILTER_SANITIZE_STRING ); - + // If not a valid collection, die quietly - if (!in_array($collection, array('regClasses', 'regRates'))) { + if (!in_array($collection, array('regClasses', 'request'))) { 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($modelData); - - + + } } diff --git a/models/admin/ajax/regFront/request.php b/models/admin/ajax/regFront/request.php new file mode 100644 index 0000000..85c2998 --- /dev/null +++ b/models/admin/ajax/regFront/request.php @@ -0,0 +1,114 @@ + + * @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_request 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)); + + // Perform specified action + switch ($modelData['option']) { + + case 'add': + break; + + case 'get': + break; + + case 'update': + break; + + case 'delete': + break; + + default: + die(); // should never get here + break; + + } + + wp_die(); + + + + } + + +} -- 2.17.1