var parentEvent = this.model.get( 'parent' );
// Try to save the registration class
- $newID = this.model.save({ option: 'add', parent: parentEvent.id, name: cName, descr: cDescr });
-
- if (!$newID){
- console.log('AJAX Save Error');
- } else {
- console.log('AJAX Save Successful');
- }
-
- this.model.set( 'id', $newID );
-
- this.$('.class-display-template').show();
- this.$('.class-edit-template').hide();
- this.$('.class-update').hide();
- this.$('.class-add').hide();
- this.$('.class-edit').show();
+ var newID = false;
+ myself = this;
+ this.model.save({
+ wait: true,
+ option: 'add',
+ parent: parentEvent.id,
+ name: cName,
+ descr: cDescr
+ }).success(function(data){
+ if (data > 0) {
+ console.log('AJAX Save Successful: ID = '+data);
+ myself.model.set({id: data});
+ myself.$('.class-display-template').show();
+ myself.$('.class-edit-template').hide();
+ myself.$('.class-update').hide();
+ myself.$('.class-add').hide();
+ myself.$('.class-edit').show();
+ myself.newClass = false;
+ } else {
+ alert('Unable to store 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);
// Add this new model to the collection.
var parentEvent = this.model.get( 'parent' ); // ????????
// parentEvent.classes.create( this.model );
glmSubmitRequired -= 1;
+
},
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.')
- }
+
+ // Remove class here
+ var x = this.model.get('id');
+ this.model.destroy({data: {
+ id: x,
+ option: 'delete'
+ }, processData: true});
+
this.remove();
- alert('Need to check that this is actually removing from database..');
},
cancel: function(){
console.log('editLevel called');
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
- this.$('.class-name').focus();
this.$('.class-update').show();
+ this.$('.class-edit').hide();
+ this.$('.class-name').focus();
glmSubmitRequired += 1;
},
}
this.$('.class-display-template').show();
this.$('.class-edit-template').hide();
+ this.$('.class-update').hide();
+ this.$('.class-edit').show();
glmSubmitRequired -= 1;
},
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
this.$('.class-update').hide();
+ this.$('.class-edit').show();
this.$('.class-add').show();
this.$('.class-name').focus();
this.newClass = true;
var parentEvent = this.model.get( 'parent' );
// Try to save the registration class
- $newID = this.model.save({ option: 'add', parent: parentEvent.id, name: cName, descr: cDescr });
-
- if (!$newID){
- console.log('AJAX Save Error');
- } else {
- console.log('AJAX Save Successful');
- }
-
- this.model.set( 'id', $newID );
-
- this.$('.class-display-template').show();
- this.$('.class-edit-template').hide();
- this.$('.class-update').hide();
- this.$('.class-add').hide();
- this.$('.class-edit').show();
+ var newID = false;
+ myself = this;
+ this.model.save({
+ wait: true,
+ option: 'add',
+ parent: parentEvent.id,
+ name: cName,
+ descr: cDescr
+ }).success(function(data){
+ if (data > 0) {
+ console.log('AJAX Save Successful: ID = '+data);
+ myself.model.set({id: data});
+ myself.$('.class-display-template').show();
+ myself.$('.class-edit-template').hide();
+ myself.$('.class-update').hide();
+ myself.$('.class-add').hide();
+ myself.$('.class-edit').show();
+ myself.newClass = false;
+ } else {
+ alert('Unable to store 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);
// Add this new model to the collection.
var parentEvent = this.model.get( 'parent' ); // ????????
// parentEvent.classes.create( this.model );
glmSubmitRequired -= 1;
+
},
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.')
- }
+
+ // Remove class here
+ var x = this.model.get('id');
+ this.model.destroy({data: {
+ id: x,
+ option: 'delete'
+ }, processData: true});
+
this.remove();
- alert('Need to check that this is actually removing from database..');
},
cancel: function(){
console.log('editLevel called');
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
- this.$('.class-name').focus();
this.$('.class-update').show();
+ this.$('.class-edit').hide();
+ this.$('.class-name').focus();
glmSubmitRequired += 1;
},
}
this.$('.class-display-template').show();
this.$('.class-edit-template').hide();
+ this.$('.class-update').hide();
+ this.$('.class-edit').show();
glmSubmitRequired -= 1;
},
this.$('.class-display-template').hide();
this.$('.class-edit-template').show();
this.$('.class-update').hide();
+ this.$('.class-edit').show();
this.$('.class-add').show();
this.$('.class-name').focus();
this.newClass = true;
*/
public function modelAction( $actionData = false )
{
-
+
// 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'))) {
- wp_die();
+ $this->failureResponse('Not a valid desitination (collection?).');
}
- // Try to decode the JSON
- $modelData = json_decode(stripslashes($_REQUEST['model']), true);
+ // Try to decode the JSON - if not provided, use REQUEST data instead
+ $modelData = array();
+ if (isset($_REQUEST['model'])) {
+ $modelData = json_decode(stripslashes($_REQUEST['model']), true);
+ } else {
+ $modelData = $_REQUEST;
+ }
// Build model and path and class names
$modelName = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH.'/models/admin/ajax/regAdmin/'.$collection.'.php';
// Instantiate the model and ask it to perform the work
$model = new $className($this->wpdb, $this->config);
-trigger_error(print_r($modelData,1));
-
$results = $model->modelAction($modelData);
}
+
+
}
public function modelAction($modelData)
{
+//trigger_error(print_r($modelData,1));
+
// Perform specified action
switch ($modelData['option']) {
// If there's a new classID, declare success
$classID = $this->wpdb->insert_id;
if ($classID) {
- return $classID;
+ echo json_encode($classID);
+ wp_die();
+ } else {
+ echo json_encode(false);
+ wp_die();
}
}
break;
case 'delete':
+
+ $classID = ($modelData['id'] - 0);
+ if ($classID > 0) {
+ $this->wpdb->delete( $this->table, array( 'id' => $classID ), array( '%d' ) );
+ }
+
+ return;
+
break;
default:
<table id="glm-table-calendar" class="glm-admin-table glm-event-table">
<tr>
<td>
- <div id="eventCalendar">(calendar loads here)</div>
+ <div id="eventCalendar" style="width: 50%;"></div>
</td>
</tr>
</table>