defaults: {
id: null,
reg_event: 0,
- reg_class: '',
+ reg_class: 0,
name: '',
start_days: 0,
end_days: 0,
},
events: {
- 'click .class-edit': 'editLevel',
+ 'click .class-edit': 'edit',
'click .class-update': 'update',
'click .class-add': 'add',
'click .class-cancel': 'cancel',
- 'click .class-delete-level': 'deleteLevel',
+ 'click .class-delete': 'delete',
'click .class-add-rate': 'addRate'
},
add: function(){
+
console.log('add called');
// Get data from form
return;
}
- // ???
this.model.set({ name: cName, descr: cDescr });
// Get parent for id to send to backend for new class
var parentEvent = this.model.get( 'parent' );
-
+
// Try to save the registration class
var newID = false;
myself = this;
this.model.save({
wait: true,
option: 'add',
- parent: parentEvent.id,
+ event: parentEvent.id,
name: cName,
descr: cDescr
}).success(function(data){
if (data > 0) {
- console.log('AJAX Save Successful: ID = '+data);
+ console.log('AJAX Class Save Successful: ID = '+data);
myself.model.set({id: data});
myself.$('.class-display-template').show();
myself.$('.class-edit-template').hide();
myself.$('.class-edit').show();
myself.newClass = false;
} else {
- alert('Unable to store data at this time.');
+ alert('Unable to store class ata at this time.');
}
- }).error(function(m,e){
+ }).error(function(m, e){
console.log(e);
alert('There was a problem communicating with the AJAX server.');
});
console.log('New ID = '+newID);
-
- // Add this new model to the collection.
- var parentEvent = this.model.get( 'parent' ); // ????????
-// parentEvent.classes.create( this.model );
glmSubmitRequired -= 1;
},
- deleteLevel: function(){
+ delete: function(){
console.log('deleteLevel called');
// Remove class here
this.remove();
},
- editLevel: function(){
- console.log('editLevel called');
+ edit: function(){
+ console.log('edit called');
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
this.$('.class-update').show();
var cName = this.$('.class-name').val().trim();
var cDescr = this.$('.class-descr').val().trim();
if (!this.model.save({ option: 'update', name: cName, descr: cDescr })) {
- console.log('AJAX Save Error');
+ console.log('Class Save Error');
} else {
- console.log('AJAX Save Successful');
+ console.log('Class Save Successful');
}
this.$('.class-display-template').show();
this.$('.class-edit-template').hide();
glmSubmitRequired -= 1;
},
+ addRate: function(){
+
+ console.log( 'addRate Called');
+
+ var reg_event = this.model.get('reg_event');
+ var reg_class = this.model.get('id');
+
+ var regRate = new app.Models.Admin.RegRate({
+ glmAction: 'regRate',
+ parent: this.model,
+ reg_event: reg_event,
+ reg_class: reg_class
+ });
+ var view = new app.Views.Admin.RegRate({
+ model: regRate,
+ });
+ this.$el.append(view.render(true).el);
+
+ // Place rates inside the class-rate-container of the parent class
+ var rateContainer = this.$('.class-rate-container');
+ rateContainer.append(view.render(true).el);
+
+
+ },
+
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
return this;
},
- addOne: function( item ){
- console.log('addOne called');
- if ( item.isValid() ) {
- var view = new app.Views.Admin.RegClasses({ model: item });
- this.$el.append( view.render().el );
- }
- },
-
- addAll: function(){
- console.log('addAll called');
- jQuery('.glm-reg-level').html('');
- },
-
- addRate: function(){
- console.log( 'addRate Called');
- var regRate = new app.Models.Admin.RegRate({ parent: this.model });
- //this.model.classes.add( regClass );
- var view = new app.Views.Admin.RegRate({ model: regRate });
- // Place rates inside the class-rate-container of the parent class
- var rateContainer = this.$('.class-rate-container');
- rateContainer.append(view.render(true).el);
- }
-
});
// js/views/adminRegEvent.js
},
addLevel: function(){
+
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({ glmAction: 'regClass', parent: this.model });
- //this.model.classes.add( regClass );
- var view = new app.Views.Admin.RegClass({ model: regClass });
+
+ var regClass = new app.Models.Admin.RegClass({
+ glmAction: 'regClass',
+ parent: this.model
+ });
+
+ var view = new app.Views.Admin.RegClass({
+ model: regClass
+ });
this.$el.append(view.render(true).el);
},
});
-// js/views/regClass.js
+// js/views/regRate.js
app.Views.Admin.RegRate = Backbone.View.extend({
tagName: 'div',
events: {
'click .rate-edit': 'edit',
'click .rate-update': 'update',
- 'click .rate-add': 'add',
+ 'click .rate-add': 'add',
'click .rate-cancel': 'cancel',
- 'click .rate-delete': 'deleteRate'
+ 'click .rate-delete': 'delete'
+ },
+
+
+ add: function(){
+
+ console.log('add called');
+
+ var cName = this.$('.rate-name').val().trim();
+
+ // Check for required data
+ if (cName == '') {
+ alert('The Level Name is Required!');
+ return;
+ }
+
+ this.model.set({ name: cName });
+
+ // Get parent for id to send to backend for new rate
+ var parentClass = this.model.get( 'parent' );
+
+ // Try to save the registration rate
+ var newID = false;
+ myself = this;
+ this.model.save({
+ wait: true,
+ option: 'add',
+ name: cName
+ }).success(function(data){
+ if (data > 0) {
+ console.log('AJAX Rate Save Successful: ID = '+data);
+ myself.model.set({id: data});
+ myself.$('.rate-display-template').show();
+ myself.$('.rate-edit-template').hide();
+ myself.$('.rate-update').hide();
+ myself.$('.rate-add').hide();
+ myself.newRate = false;
+ } else {
+ alert('Unable to store rate data at this time.');
+ }
+ }).error(function(m, e){
+ console.log(e);
+ alert('There was a problem communicating with the AJAX server.');
+ });
+
+ console.log('New ID = '+newID);
+
+ glmSubmitRequired -= 1;
+
},
+ delete: function() {
+ console.log('deleteRate called');
+
+ // Remove rate here
+ var x = this.model.get('id');
+ this.model.destroy({data: {
+ id: x,
+ option: 'delete'
+ }, processData: true});
+
+ this.remove();
+ },
+
edit: function() {
console.log('edit called');
this.$('.rate-display-template').hide();
this.$('.rate-edit-template').show();
this.$('.rate-name').focus();
-// glmSubmitRequired++;
+ glmSubmitRequired += 1;
},
update: function() {
console.log('update called');
var cName = this.$('.rate-name').val().trim();
-// this.model.save({ name: cName });
- this.$('.rate-display-template').show();
- this.$('.rate-edit-template').hide();
-// glmSubmitRequired--;
-
- },
-
- cancel: function() {
- console.log('cancel called');
- this.remove();
- },
-
- add: function(){
- console.log('add called');
+ if (!this.model.save({ option: 'update', name: cName, descr: cDescr })) {
+ console.log('Rate Save Error');
+ } else {
+ console.log('Rate Save Successful');
+ }
this.$('.rate-display-template').show();
this.$('.rate-edit-template').hide();
- this.$('.rate-update').hide();
- this.$('.rate-add').hide();
- var cName = this.$('.rate-name').val().trim();
- this.model.set({ name: cName });
- // Add this new model to the collection.
- var parentRate = this.model.get( 'parent' ); // ????????
-// parentRate.classes.create( this.model );
- },
+ glmSubmitRequired -= 1;
- deleteRate: function() {
- console.log('deleteRate called');
- if (this.newRate) {
-console.log('Removing a new rate. May have to avoid doing any ajax call if not updated yet.')
- }
- this.remove();
-console.log('Need to check that this is actually removing from database..');
},
render: function(addFlag){
this.$('.rate-add').show();
this.$('.rate-name').focus();
this.newRate = true;
-// glmSubmitRequired++;
+ glmSubmitRequired += 1;
}
return this;
}
-
+
});
defaults: {
id: null,
reg_event: 0,
- reg_class: '',
+ reg_class: 0,
name: '',
start_days: 0,
end_days: 0,
},
events: {
- 'click .class-edit': 'editLevel',
+ 'click .class-edit': 'edit',
'click .class-update': 'update',
'click .class-add': 'add',
'click .class-cancel': 'cancel',
- 'click .class-delete-level': 'deleteLevel',
+ 'click .class-delete': 'delete',
'click .class-add-rate': 'addRate'
},
add: function(){
+
console.log('add called');
// Get data from form
return;
}
- // ???
this.model.set({ name: cName, descr: cDescr });
// Get parent for id to send to backend for new class
var parentEvent = this.model.get( 'parent' );
-
+
// Try to save the registration class
var newID = false;
myself = this;
this.model.save({
wait: true,
option: 'add',
- parent: parentEvent.id,
+ event: parentEvent.id,
name: cName,
descr: cDescr
}).success(function(data){
if (data > 0) {
- console.log('AJAX Save Successful: ID = '+data);
+ console.log('AJAX Class Save Successful: ID = '+data);
myself.model.set({id: data});
myself.$('.class-display-template').show();
myself.$('.class-edit-template').hide();
myself.$('.class-edit').show();
myself.newClass = false;
} else {
- alert('Unable to store data at this time.');
+ alert('Unable to store class ata at this time.');
}
- }).error(function(m,e){
+ }).error(function(m, e){
console.log(e);
alert('There was a problem communicating with the AJAX server.');
});
console.log('New ID = '+newID);
-
- // Add this new model to the collection.
- var parentEvent = this.model.get( 'parent' ); // ????????
-// parentEvent.classes.create( this.model );
glmSubmitRequired -= 1;
},
- deleteLevel: function(){
+ delete: function(){
console.log('deleteLevel called');
// Remove class here
this.remove();
},
- editLevel: function(){
- console.log('editLevel called');
+ edit: function(){
+ console.log('edit called');
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
this.$('.class-update').show();
var cName = this.$('.class-name').val().trim();
var cDescr = this.$('.class-descr').val().trim();
if (!this.model.save({ option: 'update', name: cName, descr: cDescr })) {
- console.log('AJAX Save Error');
+ console.log('Class Save Error');
} else {
- console.log('AJAX Save Successful');
+ console.log('Class Save Successful');
}
this.$('.class-display-template').show();
this.$('.class-edit-template').hide();
glmSubmitRequired -= 1;
},
+ addRate: function(){
+
+ console.log( 'addRate Called');
+
+ var reg_event = this.model.get('reg_event');
+ var reg_class = this.model.get('id');
+
+ var regRate = new app.Models.Admin.RegRate({
+ glmAction: 'regRate',
+ parent: this.model,
+ reg_event: reg_event,
+ reg_class: reg_class
+ });
+ var view = new app.Views.Admin.RegRate({
+ model: regRate,
+ });
+ this.$el.append(view.render(true).el);
+
+ // Place rates inside the class-rate-container of the parent class
+ var rateContainer = this.$('.class-rate-container');
+ rateContainer.append(view.render(true).el);
+
+
+ },
+
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
return this;
},
- addOne: function( item ){
- console.log('addOne called');
- if ( item.isValid() ) {
- var view = new app.Views.Admin.RegClasses({ model: item });
- this.$el.append( view.render().el );
- }
- },
-
- addAll: function(){
- console.log('addAll called');
- jQuery('.glm-reg-level').html('');
- },
-
- addRate: function(){
- console.log( 'addRate Called');
- var regRate = new app.Models.Admin.RegRate({ parent: this.model });
- //this.model.classes.add( regClass );
- var view = new app.Views.Admin.RegRate({ model: regRate });
- // Place rates inside the class-rate-container of the parent class
- var rateContainer = this.$('.class-rate-container');
- rateContainer.append(view.render(true).el);
- }
-
});
},
addLevel: function(){
+
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({ glmAction: 'regClass', parent: this.model });
- //this.model.classes.add( regClass );
- var view = new app.Views.Admin.RegClass({ model: regClass });
+
+ var regClass = new app.Models.Admin.RegClass({
+ glmAction: 'regClass',
+ parent: this.model
+ });
+
+ var view = new app.Views.Admin.RegClass({
+ model: regClass
+ });
this.$el.append(view.render(true).el);
},
-// js/views/regClass.js
+// js/views/regRate.js
app.Views.Admin.RegRate = Backbone.View.extend({
tagName: 'div',
events: {
'click .rate-edit': 'edit',
'click .rate-update': 'update',
- 'click .rate-add': 'add',
+ 'click .rate-add': 'add',
'click .rate-cancel': 'cancel',
- 'click .rate-delete': 'deleteRate'
+ 'click .rate-delete': 'delete'
},
+
+ add: function(){
+
+ console.log('add called');
+
+ var cName = this.$('.rate-name').val().trim();
+
+ // Check for required data
+ if (cName == '') {
+ alert('The Level Name is Required!');
+ return;
+ }
+
+ this.model.set({ name: cName });
+
+ // Get parent for id to send to backend for new rate
+ var parentClass = this.model.get( 'parent' );
+
+ // Try to save the registration rate
+ var newID = false;
+ myself = this;
+ this.model.save({
+ wait: true,
+ option: 'add',
+ name: cName
+ }).success(function(data){
+ if (data > 0) {
+ console.log('AJAX Rate Save Successful: ID = '+data);
+ myself.model.set({id: data});
+ myself.$('.rate-display-template').show();
+ myself.$('.rate-edit-template').hide();
+ myself.$('.rate-update').hide();
+ myself.$('.rate-add').hide();
+ myself.newRate = false;
+ } else {
+ alert('Unable to store rate data at this time.');
+ }
+ }).error(function(m, e){
+ console.log(e);
+ alert('There was a problem communicating with the AJAX server.');
+ });
+
+ console.log('New ID = '+newID);
+
+ glmSubmitRequired -= 1;
+
+ },
+
+ delete: function() {
+ console.log('deleteRate called');
+
+ // Remove rate here
+ var x = this.model.get('id');
+ this.model.destroy({data: {
+ id: x,
+ option: 'delete'
+ }, processData: true});
+
+ this.remove();
+ },
+
edit: function() {
console.log('edit called');
this.$('.rate-display-template').hide();
this.$('.rate-edit-template').show();
this.$('.rate-name').focus();
-// glmSubmitRequired++;
+ glmSubmitRequired += 1;
},
update: function() {
console.log('update called');
var cName = this.$('.rate-name').val().trim();
-// this.model.save({ name: cName });
- this.$('.rate-display-template').show();
- this.$('.rate-edit-template').hide();
-// glmSubmitRequired--;
-
- },
-
- cancel: function() {
- console.log('cancel called');
- this.remove();
- },
-
- add: function(){
- console.log('add called');
+ if (!this.model.save({ option: 'update', name: cName, descr: cDescr })) {
+ console.log('Rate Save Error');
+ } else {
+ console.log('Rate Save Successful');
+ }
this.$('.rate-display-template').show();
this.$('.rate-edit-template').hide();
- this.$('.rate-update').hide();
- this.$('.rate-add').hide();
- var cName = this.$('.rate-name').val().trim();
- this.model.set({ name: cName });
- // Add this new model to the collection.
- var parentRate = this.model.get( 'parent' ); // ????????
-// parentRate.classes.create( this.model );
- },
+ glmSubmitRequired -= 1;
- deleteRate: function() {
- console.log('deleteRate called');
- if (this.newRate) {
-console.log('Removing a new rate. May have to avoid doing any ajax call if not updated yet.')
- }
- this.remove();
-console.log('Need to check that this is actually removing from database..');
},
render: function(addFlag){
this.$('.rate-add').show();
this.$('.rate-name').focus();
this.newRate = true;
-// glmSubmitRequired++;
+ glmSubmitRequired += 1;
}
return this;
}
-
+
});
*/
public function modelAction( $actionData = false )
{
-
+
// Get Backbone collection we're talking with
$collection = filter_var( $_REQUEST['collection'], FILTER_SANITIZE_STRING );
$res = $this->wpdb->insert(
$this->table,
array(
- 'reg_event' => $modelData['parent'],
+ 'reg_event' => $modelData['event'],
'name' => $modelData['name'],
'descr' => $modelData['descr']
),
echo json_encode($classID);
wp_die();
} else {
- echo json_encode(false);
+ echo json_encode(0);
wp_die();
}
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Registrations AJAX processing for Rates
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release regRates.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/dataRegRate.php';
+
+class GlmMembersAdmin_registrations_ajax_regRates extends GlmDataRegistrationsRegRate
+{
+
+ /**
+ * 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)
+ {
+
+ // Perform specified action
+ switch ($modelData['option']) {
+
+ case 'add':
+
+ // Make sure we got a parent ID with the data
+ if (isset($modelData['parent']) || (modelData['parent']-0) > 0) {
+
+ // Try to insert the rate (level) data
+ $res = $this->wpdb->insert(
+ $this->table,
+ array(
+ 'reg_event' => $modelData['reg_event'],
+ 'reg_class' => $modelData['reg_class'],
+ 'name' => $modelData['name']
+ ),
+ array(
+ '%d',
+ '%d',
+ '%s'
+ )
+ );
+
+ if ($res != 1) {
+ trigger_error('Registration Rate Insert failed');
+ return false;
+ }
+
+ // If there's a new rateID, declare success
+ $rateID = $this->wpdb->insert_id;
+ if ($rateID) {
+ echo json_encode($rateID);
+ wp_die();
+ } else {
+ echo json_encode(0);
+ wp_die();
+ }
+
+ }
+
+ break;
+
+ case 'get':
+ break;
+
+ case 'update':
+
+ // We must have a numeric class (level) ID
+ $rateID = ($modelData['id'] - 0);
+ if ($rateID > 0) {
+
+ // Try to update the class (level) data
+ $this->wpdb->update(
+ $this->table,
+ array(
+ 'name' => $modelData['name']
+ ),
+ array('id' => $rateID),
+ array(
+ '%s'
+ ),
+ array( '%d' )
+ );
+
+ }
+
+ break;
+
+ case 'delete':
+
+ $rateID = ($modelData['id'] - 0);
+ if ($rateID > 0) {
+ $this->wpdb->delete( $this->table, array( 'id' => $rateID ), array( '%d' ) );
+ }
+
+ return;
+
+ break;
+
+ default:
+ die(); // should never get here
+ break;
+
+ }
+
+ wp_die();
+
+
+
+ }
+
+
+}
----
--- A specific registrant for a selected registration rate
+-- A specific registrant for a selected registration rate - *** Need to remove the reg_request_registrant entry in this table ****
CREATE TABLE {prefix}reg_request_registrant (
id INT NOT NULL AUTO_INCREMENT,
- account INT NULL, -- Pointer to account for person submitting the registration
+ account INT NULL, -- Pointer to the account entry for the person being registered - False (0) if account no longer exists or registrant account not needed
reg_event INT NULL, -- Pointer to reg_event entry
event_name TINYTEXT NULL, -- Name of Event so it will always be in the cart data
reg_time INT NULL, -- Pointer reg_time entry
reg_request_event INT NULL, -- Pointer to reg_request_event table entry
reg_request_class INT NULL, -- Pointer to reg_request_class table entry
reg_request_rate INT NULL, -- Pointer to reg_request_rate table entry
- reg_request_registrant INT NULL, -- Pointer to account for registrant (person attending) - False (0) if account no longer exists or registrant account not needed
reg_request_hold BOOLEAN NULL, -- Registrant hold active - Registrant slots held certain time since last cart access - After this the slot needs to be updated if available
reg_request_hold_not_available BOOLEAN NULL, -- No registrant slot available for this registrant - Unable to get hold
fname TINYTEXT NULL, -- First name of registrant at the time of selection
<div class="glm-right">
<a class="class-edit button button-secondary glm-button-small">Edit</a>
<a class="class-add-rate button button-secondary glm-button-small">Add Reg Rate</a>
- <a class="class-delete-level button button-secondary glm-button-small">Delete Level</a>
+ <a class="class-delete button button-secondary glm-button-small">Delete Level</a>
</div>
<div class="glm-class-label">
<h3><%= name %></h3>
<div class="glm-right">
<a class="class-update button glm-button-small-highlighted">Update</a>
<a class="class-add button glm-button-small-highlighted" style="display: none;">Add</a>
- <a class="class-add-rate button button-secondary glm-button-small">Add Reg Rate</a>
- <a class="class-delete-level button button-secondary glm-button-small">Delete Level</a>
+ <a class="class-add-rate button button-secondary glm-button-small" style="display: none;">Add Reg Rate</a>
+ <a class="class-delete button button-secondary glm-button-small">Delete Level</a>
</div>
<div class="glm-class-label" style="padding-bottom: .3em;">
<b>Level Name:</b> <input class="class-name" type="text" name="class_name_<% if (id) { %><%- id %><% } else { %> new <% } %>" value="<% if (name) { %><%- name %><% } %>">