From 48db6aad86fd5079d08b6e5b1077b5cbfddc894f Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 21 Sep 2017 13:26:53 -0400 Subject: [PATCH] Added menu, model, and view for reports. Nothing in there yet. Have admin reg events levels and rates displaying, adding, editing, saving, and storing Still some glitches in that page. --- js/adminRegApp.js | 41 +++++-- js/collections/admin/regRates.js | 3 +- js/models/admin/regClass.js | 6 +- js/models/admin/regEvent.js | 2 +- js/views/admin/regClass.js | 15 ++- js/views/admin/regEvent.js | 6 +- js/views/admin/regRate.js | 8 +- models/admin/registrations/accounts.php | 2 +- models/admin/registrations/events.php | 1 + models/admin/registrations/reports.php | 106 ++++++++++++++++++ models/admin/registrations/requests.php | 2 +- setup/adminMenus.php | 8 ++ setup/validActions.php | 3 +- .../admin/registrations/eventEditLevels.html | 9 +- .../admin/registrations/eventsDashboard.html | 2 +- views/admin/registrations/reports.html | 7 ++ 16 files changed, 188 insertions(+), 33 deletions(-) create mode 100644 models/admin/registrations/reports.php create mode 100644 views/admin/registrations/reports.html diff --git a/js/adminRegApp.js b/js/adminRegApp.js index 546b8eb..bad5d8d 100644 --- a/js/adminRegApp.js +++ b/js/adminRegApp.js @@ -15,7 +15,11 @@ app.Models.Admin.RegClass = Backbone.Model.extend({ this.rates = new app.Collections.Admin.RegRates; }, - url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses' + url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses', + + setRates: function(regRates){ + this.rates.set(regRates); + } }); @@ -42,7 +46,7 @@ app.Models.Admin.RegEvent = Backbone.Model.extend({ }, setClasses: function( regClasses ){ - this.classes.reset( regClasses ); + this.classes.set( regClasses ); } }); @@ -87,8 +91,8 @@ app.Collections.Admin.RegClasses = Backbone.Collection.extend({ app.Collections.Admin.RegRates = Backbone.Collection.extend({ model: app.Models.Admin.RegRate, url: ajaxUrl+'&glm_action=regAdmin&collection=regRates' -}); - +}); + // js/views/app.js Backbone.emulateJSON = true; Backbone.emulateHTTP = true; @@ -124,6 +128,9 @@ app.Views.Admin.RegClass = Backbone.View.extend({ initialize: function(){ this.listenTo( this.model, 'change', this.render ); + + // Use the reg rates sent as an attribute to the class to create the rates models + this.model.setRates(this.model.attributes.reg_rate); return this; }, @@ -190,7 +197,11 @@ app.Views.Admin.RegClass = Backbone.View.extend({ delete: function(){ console.log('deleteLevel called'); - + + if (!confirm('Are you sure you want to delete this? ( *** need to check for rates *** )')) { + return false; + } + // Remove class here var x = this.model.get('id'); this.model.destroy({data: { @@ -259,6 +270,12 @@ app.Views.Admin.RegClass = Backbone.View.extend({ render: function(addFlag){ this.$el.html( this.template( this.model.toJSON() ) ); + var rateView = this.model.rates.map(function(item){ + return (new app.Views.Admin.RegRate({ model: item })).render().el; + }); + var rateContainer = this.$('.class-rate-container'); + rateContainer.append(rateView); + // If addFlag set then we know the call to this is to add a class and not to initialize existing classes if (addFlag == true) { console.log('New level created'); @@ -297,9 +314,9 @@ app.Views.Admin.RegEvent = Backbone.View.extend({ events: { 'click #class-add': 'addLevel', - }, + }, - addLevel: function(){ + addLevel: function(){ console.log( 'addLevel Called' ); @@ -313,7 +330,7 @@ app.Views.Admin.RegEvent = Backbone.View.extend({ }); this.$el.append(view.render(true).el); }, - + render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); var view = regEvent.classes.map(function(item){ @@ -389,10 +406,9 @@ app.Views.Admin.RegRate = Backbone.View.extend({ alert('There was a problem communicating with the AJAX server.'); }); + glmSubmitRequired -= 1; console.log('New ID = '+newID); - glmSubmitRequired -= 1; - }, delete: function() { @@ -419,14 +435,14 @@ app.Views.Admin.RegRate = Backbone.View.extend({ update: function() { console.log('update called'); var cName = this.$('.rate-name').val().trim(); - if (!this.model.save({ option: 'update', name: cName, descr: cDescr })) { + if (!this.model.save({ option: 'update', name: cName})) { console.log('Rate Save Error'); } else { console.log('Rate Save Successful'); } this.$('.rate-display-template').show(); this.$('.rate-edit-template').hide(); - glmSubmitRequired -= 1; + glmSubmitRequired -= 1; }, @@ -434,6 +450,7 @@ app.Views.Admin.RegRate = Backbone.View.extend({ 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) { + // Setup to edit this for the first time console.log('New rate created'); this.$('.rate-display-template').hide(); this.$('.rate-edit-template').show(); diff --git a/js/collections/admin/regRates.js b/js/collections/admin/regRates.js index ff3ac3e..dfdbc75 100644 --- a/js/collections/admin/regRates.js +++ b/js/collections/admin/regRates.js @@ -4,4 +4,5 @@ app.Collections.Admin.RegRates = Backbone.Collection.extend({ model: app.Models.Admin.RegRate, url: ajaxUrl+'&glm_action=regAdmin&collection=regRates' -}); +}); + \ No newline at end of file diff --git a/js/models/admin/regClass.js b/js/models/admin/regClass.js index de805f9..6102da8 100644 --- a/js/models/admin/regClass.js +++ b/js/models/admin/regClass.js @@ -15,6 +15,10 @@ app.Models.Admin.RegClass = Backbone.Model.extend({ this.rates = new app.Collections.Admin.RegRates; }, - url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses' + url: ajaxUrl+'&glm_action=regAdmin&collection=regClasses', + + setRates: function(regRates){ + this.rates.set(regRates); + } }); diff --git a/js/models/admin/regEvent.js b/js/models/admin/regEvent.js index ae923d6..0d9ebff 100644 --- a/js/models/admin/regEvent.js +++ b/js/models/admin/regEvent.js @@ -21,7 +21,7 @@ app.Models.Admin.RegEvent = Backbone.Model.extend({ }, setClasses: function( regClasses ){ - this.classes.reset( regClasses ); + this.classes.set( regClasses ); } }); diff --git a/js/views/admin/regClass.js b/js/views/admin/regClass.js index 8feeab4..99c6ced 100644 --- a/js/views/admin/regClass.js +++ b/js/views/admin/regClass.js @@ -9,6 +9,9 @@ app.Views.Admin.RegClass = Backbone.View.extend({ initialize: function(){ this.listenTo( this.model, 'change', this.render ); + + // Use the reg rates sent as an attribute to the class to create the rates models + this.model.setRates(this.model.attributes.reg_rate); return this; }, @@ -75,7 +78,11 @@ app.Views.Admin.RegClass = Backbone.View.extend({ delete: function(){ console.log('deleteLevel called'); - + + if (!confirm('Are you sure you want to delete this? ( *** need to check for rates *** )')) { + return false; + } + // Remove class here var x = this.model.get('id'); this.model.destroy({data: { @@ -144,6 +151,12 @@ app.Views.Admin.RegClass = Backbone.View.extend({ render: function(addFlag){ this.$el.html( this.template( this.model.toJSON() ) ); + var rateView = this.model.rates.map(function(item){ + return (new app.Views.Admin.RegRate({ model: item })).render().el; + }); + var rateContainer = this.$('.class-rate-container'); + rateContainer.append(rateView); + // If addFlag set then we know the call to this is to add a class and not to initialize existing classes if (addFlag == true) { console.log('New level created'); diff --git a/js/views/admin/regEvent.js b/js/views/admin/regEvent.js index 0c24fd4..c6d4e0a 100644 --- a/js/views/admin/regEvent.js +++ b/js/views/admin/regEvent.js @@ -19,9 +19,9 @@ app.Views.Admin.RegEvent = Backbone.View.extend({ events: { 'click #class-add': 'addLevel', - }, + }, - addLevel: function(){ + addLevel: function(){ console.log( 'addLevel Called' ); @@ -35,7 +35,7 @@ app.Views.Admin.RegEvent = Backbone.View.extend({ }); this.$el.append(view.render(true).el); }, - + render: function(){ this.$el.html( this.template( this.model.toJSON() ) ); var view = regEvent.classes.map(function(item){ diff --git a/js/views/admin/regRate.js b/js/views/admin/regRate.js index c2635ec..b4b3d14 100644 --- a/js/views/admin/regRate.js +++ b/js/views/admin/regRate.js @@ -62,10 +62,9 @@ app.Views.Admin.RegRate = Backbone.View.extend({ alert('There was a problem communicating with the AJAX server.'); }); + glmSubmitRequired -= 1; console.log('New ID = '+newID); - glmSubmitRequired -= 1; - }, delete: function() { @@ -92,14 +91,14 @@ app.Views.Admin.RegRate = Backbone.View.extend({ update: function() { console.log('update called'); var cName = this.$('.rate-name').val().trim(); - if (!this.model.save({ option: 'update', name: cName, descr: cDescr })) { + if (!this.model.save({ option: 'update', name: cName})) { console.log('Rate Save Error'); } else { console.log('Rate Save Successful'); } this.$('.rate-display-template').show(); this.$('.rate-edit-template').hide(); - glmSubmitRequired -= 1; + glmSubmitRequired -= 1; }, @@ -107,6 +106,7 @@ app.Views.Admin.RegRate = Backbone.View.extend({ 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) { + // Setup to edit this for the first time console.log('New rate created'); this.$('.rate-display-template').hide(); this.$('.rate-edit-template').show(); diff --git a/models/admin/registrations/accounts.php b/models/admin/registrations/accounts.php index d7f4cc0..a479392 100644 --- a/models/admin/registrations/accounts.php +++ b/models/admin/registrations/accounts.php @@ -193,7 +193,7 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount // Load registration request and registration registrant data classes require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequest.php'; - $RegRequest = new GlmDataRegistrationsRequest($this->wpdb, $this->config); + $RegRequest = new GlmDataRegistrationsRegRequest($this->wpdb, $this->config); require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestRegistrant.php'; $RegRequestRegistrant = new GlmDataRegistrationsRequestRegistrant($this->wpdb, $this->config); diff --git a/models/admin/registrations/events.php b/models/admin/registrations/events.php index 9f5b22f..54ccd0f 100644 --- a/models/admin/registrations/events.php +++ b/models/admin/registrations/events.php @@ -177,6 +177,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent // Separate Event, Classes, and Times and send those as separate JSONs $regClassesJSON = json_encode($regEvent['reg_class']); $regTimesJSON = json_encode($regEvent['reg_time']); +// echo "
".print_r($regEvent['reg_class'],1)."
"; // Get rid of class and time arrays so we just have the event data unset($regEvent['reg_class']); diff --git a/models/admin/registrations/reports.php b/models/admin/registrations/reports.php new file mode 100644 index 0000000..b912ae9 --- /dev/null +++ b/models/admin/registrations/reports.php @@ -0,0 +1,106 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +class GlmMembersAdmin_registrations_reports +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Registrations Event ID + * + * @var $eventID + * @access public + */ + public $accountID = false; + + /** + * 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($actionData = false) + { + $view = 'reports'; + $reason = array(); + + // Compile template data + $templateData = array( + 'reason' => $reason + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'admin/registrations/' . $view . '.html', + 'data' => $templateData + ); + + } + + +} diff --git a/models/admin/registrations/requests.php b/models/admin/registrations/requests.php index 9b510a1..3eb7b1c 100644 --- a/models/admin/registrations/requests.php +++ b/models/admin/registrations/requests.php @@ -16,7 +16,7 @@ // Load Registration Requests data abstract require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequest.php'; -class GlmMembersAdmin_registrations_requests extends GlmDataRegistrationsRequest +class GlmMembersAdmin_registrations_requests extends GlmDataRegistrationsRegRequest { /** diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 94955d1..f79fc0b 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -83,3 +83,11 @@ add_submenu_page( 'glm-members-admin-menu-registrations-accounts', function() {$this->controller('registrations', 'accounts');} ); +add_submenu_page( + 'glm-members-admin-menu-members', + 'Registration Reports', + '    Reports', + 'glm_members_members', + 'glm-members-admin-menu-registrations-reports', + function() {$this->controller('registrations', 'reports');} + ); diff --git a/setup/validActions.php b/setup/validActions.php index 86d40d9..37e248e 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -68,7 +68,8 @@ $glmMembersRegistrationsAddOnValidActions = array( 'index' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, 'events' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, 'requests' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, - 'accounts' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG + 'accounts' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, + 'reports' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG ), 'management' => array( 'registrations' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG, diff --git a/views/admin/registrations/eventEditLevels.html b/views/admin/registrations/eventEditLevels.html index ef54305..05cbd52 100644 --- a/views/admin/registrations/eventEditLevels.html +++ b/views/admin/registrations/eventEditLevels.html @@ -40,8 +40,8 @@

<%= name %>

@@ -54,8 +54,6 @@
Level Name: @@ -74,7 +72,7 @@ Edit Delete Rate
-
+

<%= name %>

@@ -84,7 +82,6 @@
Rate Name: diff --git a/views/admin/registrations/eventsDashboard.html b/views/admin/registrations/eventsDashboard.html index 9156b7f..654b62f 100644 --- a/views/admin/registrations/eventsDashboard.html +++ b/views/admin/registrations/eventsDashboard.html @@ -46,7 +46,7 @@ {if $haveRegEvents} {assign var="i" value="0"} - {foreach $regEvents as $r}z + {foreach $regEvents as $r} {if $i++ is odd by 1} {else} diff --git a/views/admin/registrations/reports.html b/views/admin/registrations/reports.html new file mode 100644 index 0000000..2ac61d1 --- /dev/null +++ b/views/admin/registrations/reports.html @@ -0,0 +1,7 @@ + +

Reports

+ +

Move along now, nothing to see here.

+ +{include file='admin/footer.html'} + -- 2.17.1