Added ajax edit/update feature to calendar cells in registration event dashboard.
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 14 Nov 2017 22:02:34 +0000 (17:02 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 14 Nov 2017 22:02:34 +0000 (17:02 -0500)
models/admin/ajax/updateAvailability.php [new file with mode: 0644]
models/admin/registrations/events.php
setup/validActions.php
views/admin/registrations/eventDashboard.html

diff --git a/models/admin/ajax/updateAvailability.php b/models/admin/ajax/updateAvailability.php
new file mode 100644 (file)
index 0000000..e37d121
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Update availability in reg_time records
+ * Called from admin time update dialog box
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  summary.php,v 1.0 2017/11/10 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+ require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegTime.php';
+
+ class GlmMembersAdmin_ajax_updateAvailability extends GlmDataRegistrationsRegTime {
+    /**
+    * 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 modelAction($actionData = false)
+    {
+
+        $haveRequest = false;
+
+        // Get the max attendees value
+        if (!isset($_REQUEST['max'])) {
+            wp_die();
+        }
+        $max = ($_REQUEST['max'] - 0);
+        if ($max <= 0) {
+            wp_die();
+        }
+
+trigger_error("1111",E_USER_NOTICE);
+        // Get the reg_time entry id
+        if (!isset($_REQUEST['reg_time'])) {
+            wp_die();
+        }
+        $regTimeId = ($_REQUEST['reg_time'] - 0);
+        if ($regTimeId <= 0) {
+            wp_die();
+        }
+
+trigger_error("regTimeId = $regTimeId",E_USER_NOTICE);
+        // Try to get the reg_time entry
+        $regTime = $this->getEntry($regTimeId);
+        if (!$regTime) {
+            wp_die();
+        }
+
+trigger_error("3333",E_USER_NOTICE);
+        // re-calculate the total
+        $avail = $max - $regTime['attendee_count'] - $regTime['attendees_pending'];
+trigger_error("max = $max, avail = $avail", E_USER_NOTICE);
+        // Try to update the reg_time entry
+        $this->wpdb->update(
+            $this->table,
+            array(
+                'attendee_max'  => $max,
+                'attendees_available' => $avail
+            ),
+            array('id' => $regTimeId),
+            array(
+                '%d',
+                '%d'
+            ),
+            array( '%d' )
+        );
+
+
+    }
+ }
index ce7fd73..43cf857 100644 (file)
@@ -400,7 +400,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
             update_option('glmMembersDatabaseRegistrationsRegEventID', $regEventID);
         }
 
-        //echo "<pre>".print_r($regEvent,1)."</pre>";
+        // echo "<pre>".print_r($regEvent,1)."</pre>";
 
         // Compile template data
         $templateData = array(
index 8cb4ce9..d835104 100644 (file)
@@ -64,7 +64,8 @@ $glmMembersRegistrationsAddOnValidActions = array(
             'regAdmin'                  => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
             'regFront'                  => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
             'cartLinkWidget'            => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
-            'summaryContent'            => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG
+            'summaryContent'            => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+            'updateAvailability'        => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG
         ),
         'registrations' => array(
             'index'                     => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
index 0da391c..0818070 100644 (file)
         <h3>Did not find selected event.</h3>
   {/if}
 </div>
+<div id="availabilityEditDialog" class="glm-dialog-box" title="Availability Edit">
+    <table>
+        <tr><th id="availabilityTitle" colspan="2"></th></tr>
+        <tr><th style="text-align: left">Maximum Attendees:</th><td><input class="glm-form-text-input-veryshort availabilityInput" type="text" id="dialogMaxAtt" value=""></td></tr>
+        <tr><th style="text-align: left">Registered Attendees:</th><td id="dialogRegAtt"></td></tr>
+        <tr><th style="text-align: left">Pending in Carts:</th><td id="dialogPendAtt"></td></tr>
+        <tr><th style="text-align: left">Available for Registration:</th><td id="dialogAvailAtt"></td></tr>
+        <tr><td style="text-align: right">
+            <div id="availabilitySubmit" class="button-primary" data-timeid="">Upate</div>      
+        </td></tr>
+    </table>
+</div>
 
 </div>
     <script type="text/javascript">
         jQuery(document).ready(function($) {
 
+            // Summary Dialog Box
+            $("#availabilityEditDialog").dialog({
+                autoOpen: false,
+                width: 'auto',
+                resizable: true
+            });
+                
             var fullCalendarLoaded = false;
 
             // If this is a time specific event, then display the calendar
                 /*
                  * Initialize the Full Calendar
                  */
+                
                 function initFullCalendar(){
                     $('#eventCalendar').fullCalendar({
-                        {if $regEvent}
-                            events: [
-                                {$sep = ''}
-                               {foreach $regEvent.reg_time as $t}
-                                   {$sep}{
-                                      {if $t.attendee_max == 0}
-                                        title : 'unlimited',
-                                      {else}
-                                        title : '{$t.attendee_max}-{$t.attendee_count}-{$t.attendees_pending}-{$t.attendees_available}',
-                                      {/if}
-                                       start : '{$t.start_datetime.datetime}',
-                                       end   : '{$t.end_datetime.datetime}',
-                                       allday : {$t.all_day.value}
-                                   }
-                                   {$sep = ','}
-                               {/foreach}
-                            ],
-                            defaultDate : '{$regEventFirstTime.start_time.datetime}',
-                            timeFormat  : 'h:mma',
-                            fixedWeekCount : false,
-                            eventClick: function(calEvent, jsEvent, view) {
-                                $("#occurrences").dialog();
-                                $(this).css('border-color', 'red');
+        {if $regEvent}
+                        events: [
+                            {$sep = ''}
+               {foreach $regEvent.reg_time as $t}
+                            {$sep}{
+                              {if $t.attendee_max == 0}
+                                title : 'unlimited',
+                              {else}
+                                title : '{$t.attendee_max}-{$t.attendee_count}-{$t.attendees_pending}-{$t.attendees_available}',
+                              {/if}
+                                start : '{$t.start_datetime.datetime}',
+                                end   : '{$t.end_datetime.datetime}',
+                                allday : {$t.all_day.value},
+                                max:     {$t.attendee_max},
+                                count:  {$t.attendee_count},
+                                pending:    {$t.attendees_pending},
+                                available:  {$t.attendees_available},
+                                datetime: '{$t.start_datetime.datetime}',
+                                timeid:   {$t.id}
+                                
                             }
-                        {/if}
+                            {$sep = ','}
+            {/foreach}
+                        ],
+                        eventMouseover : function(event, jsEvent, view) {
+                            $('.fc-event').css( 'cursor', 'pointer' );
+                        },
+                        defaultDate : '{$regEventFirstTime.start_time.datetime}',
+                        timeFormat  : 'h:mma',
+                        fixedWeekCount : false,
+                        eventClick: function(calEvent, jsEvent, view) {
+                            $("#occurrences").dialog();
+                            $(this).css('border-color', 'red');
+
+                            $('#availabilityEditDialog').dialog('open');
+
+                            $('#availabilityTitle').html(calEvent.datetime);
+                            $('#dialogMaxAtt').val(calEvent.max);
+                            $('#dialogRegAtt').html(calEvent.count);
+                            $('#dialogPendAtt').html(calEvent.pending);
+                            $('#dialogAvailAtt').html(calEvent.available);
+                            $('#availabilitySubmit').attr('data-timeid', calEvent.timeid);
+                            // Re-calculate total available when entering
+
+                            $('#dialogMaxAtt').on('change', function() {
+                                var max = $('#dialogMaxAtt').val();
+                                max = max -0;
+                                var available = max - calEvent.count - calEvent.pending;
+                                if (available < 0) {
+                                    max = max - available;
+                                    $('#dialogMaxAtt').val(max);
+                                    available = 0;
+                                }
+                                calEvent.available = available;
+                                $('#dialogAvailAtt').html(available);
+                                $('#dialogMaxAtt').off('change');
+                            });
+                            
+                            $('#availabilitySubmit').on('click', function() {
+                                var max = $('#dialogMaxAtt').val();
+                                var timeid = $('#availabilitySubmit').attr('data-timeid');
+                                $.ajax({
+                                    url: "{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=updateAvailability&max=" + max + "&reg_time=" + timeid
+                                 });
+                                $('#availabilityEditDialog').dialog('close');           
+                                $('#availabilitySubmit').off('click');           
+                                
+                                calEvent.title = max + '-' + calEvent.count + '-' + calEvent.pending + '-' + calEvent.available;
+                                $('#eventCalendar').fullCalendar('updateEvent', calEvent);      
+                            });
+
+                                            
+                        }
+        {/if}
                     });
                 }
 
                        initFullCalendar();
 
             }
-
+                            
             // Flash certain elements for a short time after display
             $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);