// Classes Collection
app.Collections.Admin.RegClasses = Backbone.Collection.extend({
model: app.Models.Admin.RegClass,
- url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses',
- add:
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses'
});
// js/collections/regRates.js
add: function(){
console.log('add called');
+
+ var cName = this.$('.class-name').val().trim();
+ var cDescr = this.$('.class-descr').val().trim();
+
+ if (cName == '') {
+ alert('The Level Name is Required!');
+ return;
+ }
+
this.$('.class-display-template').show();
this.$('.class-edit-template').hide();
this.$('.class-update').hide();
this.$('.class-add').hide();
- 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 })) {
+ // Get parent for id to send to backend for new class
+ var parentEvent = this.model.get( 'parent' );
+
+ if (!this.model.save({ option: 'add', parent: parentEvent.id, 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 );
+
+ glmSubmitRequired -= 1;
},
deleteLevel: 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 })) {
+ if (!this.model.save({ option: 'update', name: cName, descr: cDescr })) {
console.log('AJAX Save Error');
} else {
console.log('AJAX Save Successful');
// Classes Collection
app.Collections.Admin.RegClasses = Backbone.Collection.extend({
model: app.Models.Admin.RegClass,
- url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses',
- add:
+ url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses'
});
add: function(){
console.log('add called');
+
+ var cName = this.$('.class-name').val().trim();
+ var cDescr = this.$('.class-descr').val().trim();
+
+ if (cName == '') {
+ alert('The Level Name is Required!');
+ return;
+ }
+
this.$('.class-display-template').show();
this.$('.class-edit-template').hide();
this.$('.class-update').hide();
this.$('.class-add').hide();
- 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 })) {
+ // Get parent for id to send to backend for new class
+ var parentEvent = this.model.get( 'parent' );
+
+ if (!this.model.save({ option: 'add', parent: parentEvent.id, 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 );
+
+ glmSubmitRequired -= 1;
},
deleteLevel: 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 })) {
+ if (!this.model.save({ option: 'update', name: cName, descr: cDescr })) {
console.log('AJAX Save Error');
} else {
console.log('AJAX Save Successful');
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);
// Instantiate the model and ask it to perform the work
$model = new $className($this->wpdb, $this->config);
- $results = $model->modelAction($method, $modelData);
+ $results = $model->modelAction($modelData);
}
}
- public function modelAction($method, $modelData)
+ public function modelAction($modelData)
{
-//trigger_error(print_r($modelData,1)."Method = $method");
+trigger_error(print_r($modelData,1));
// Perform specified action
- switch ($method) {
+ switch ($modelData['option']) {
- // Create
- case 'POST':
+ case 'add':
break;
- // Read
- case 'GET':
+ case 'get':
break;
- // Update
- case 'PUT':
+ case 'update':
// If we have a numeric class (level) ID
$classID = ($modelData['id'] - 0);
break;
- // Patch
- case 'PATCH':
- break;
-
- // Delete
- case 'DELETE':
+ case 'delete':
break;
default:
// 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);
// Instantiate the model and ask it to perform the work
$model = new $className($this->wpdb, $this->config);
- $results = $model->modelAction($method, $modelData);
+ $results = $model->modelAction($modelData);
}
}
- public function modelAction($method, $modelData)
+ public function modelAction($modelData)
{
-//trigger_error(print_r($modelData,1)."Method = $method");
+trigger_error(print_r($modelData,1));
// Perform specified action
- switch ($method) {
+ switch ($modelData['option']) {
- // Create
- case 'POST':
+ case 'add':
break;
- // Read
- case 'GET':
+ case 'get':
break;
- // Update
- case 'PUT':
-
- break;
-
- // Patch
- case 'PATCH':
+ case 'update':
break;
- // Delete
- case 'DELETE':
+ case 'delete':
break;
default: