Finishing up the amenity grouping in the admin.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Jun 2016 19:18:02 +0000 (15:18 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Jun 2016 19:18:02 +0000 (15:18 -0400)
Updating adding groups stays on the group tab now.
Updating groups in each amenity now working in amenity list.

models/admin/settings/amenities.php
views/admin/settings/amenities.html

index cc917dc..fd2532f 100644 (file)
@@ -105,6 +105,7 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities
         $haveGroups    = false;
         $amenities     = false;
         $error         = false;
+        $option2       = '';
         $newAmenity    = $this->newEntry();
 
         // Check if a category ID is supplied
@@ -119,15 +120,35 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities
         if ( isset( $_REQUEST['option'] ) ) {
             switch( $_REQUEST['option'] ) {
                 case 'addNew':
-                    $this->insertEntry();
+                    $return = $this->insertEntry();
+                    $id = $return['fieldData']['id'];
+                    if ( isset( $_REQUEST['grouped']['group'] ) ) {
+                        foreach ( $_REQUEST['grouped']['group'] as $group_id => $group_value ) {
+                            if ( $group_value == 1 ) {
+                                $this->wpdb->insert(
+                                    GLM_MEMBERS_PLUGIN_DB_PREFIX . 'grouped_amenities',
+                                    array(
+                                        'group_id'   => $group_id,
+                                        'amenity_id' => $id,
+                                        'searchable' => $_REQUEST['grouped']['searchable'][$group_id]
+                                    ),
+                                    array(
+                                        '%d',
+                                        '%d',
+                                        '%s'
+                                    )
+                                );
+                            }
+                        }
+                    }
                     break;
 
                 case 'update':
                     if ( $id > 0 ) {
                         $this->updateEntry( $id );
                     }
-                    echo '<pre>$id: ' . print_r($id, true) . '</pre>';
-                    echo '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
+                    //echo '<pre>$id: ' . print_r($id, true) . '</pre>';
+                    //echo '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
                     // Delete the current entries for the grouped amenities
                     $this->wpdb->delete(
                         GLM_MEMBERS_PLUGIN_DB_PREFIX . 'grouped_amenities',
@@ -176,12 +197,21 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities
                         $groupData->deleteEntry( $id );
                     } 
                     break;
+
+                default:
+                    $option2 = false;
+                    break;
+
             }
         }
 
+        if ( isset( $_REQUEST['option2'] ) ) {
+            $option2 = $_REQUEST['option2'];
+        }
+
         // Get a current list of amenities
         $amenities = $this->getList();
-        echo '<pre>$amenities: ' . print_r($amenities, true) . '</pre>';
+        //echo '<pre>$amenities: ' . print_r($amenities, true) . '</pre>';
 
         if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) {
             glmMembersAdmin::addNotice( $amenities, 'DataBlock', 'Amenities Data' );
@@ -236,6 +266,7 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities
             'haveGroups'    => $haveGroups,
             'amenities'     => $amenities,
             'groups'        => $groups,
+            'option2'       => $option2,
             'newAmenity'    => $newAmenity,
         );
 
index 008dc86..0ab54a1 100644 (file)
@@ -5,7 +5,7 @@
     <a id="glm-groups-list" data-show-table="glm-table-groups" class="glm-settings-tab nav-tab">Groups</a>
 </h2>
 
-<table id="glm-table-amenities" class="glm-admin-table glm-settings-table{if $option=''} glm-hidden{/if}">
+<table id="glm-table-amenities" class="glm-admin-table glm-settings-table{if $option2!=''} glm-hidden{/if}">
     <tr><td colspan="2">
         <!-- Add Amenities Button and Dialog Box -->
         <div id="newAmenityButton" class="button button-primary glm-right">Add an Amenity</div>
                     <tr>
                         <td colspan="2">
                             <table style="width: 100%;">
+                                <thead>
+                                    <tr>
+                                        <td>Groups</td>
+                                    </tr>
+                                </thead>
                                 {foreach $groups as $group}
                                     <tr>
                                         <td>
                                             <label>
                                                 <input type="hidden" name="grouped[group][{$group.id}]" value="0">
                                                 <input type="checkbox" name="grouped[group][{$group.id}]" value="1">
-                                            {$group.name}
+                                                {$group.name}
                                             </label>
                                         </td>
                                         <td>
                                             <label>
                                                 <input type="hidden" name="grouped[searchable][{$group.id}]" value="0">
                                                 <input type="checkbox" name="grouped[searchable][{$group.id}]" value="1">
-                                            Searchable
+                                                Searchable
                                             </label>
                                         </td>
                                     </tr>
                     <tr>
                         <td colspan="2">
                             <table style="width: 100%;">
+                                <thead>
+                                    <tr>
+                                        <td>Groups</td>
+                                    </tr>
+                                </thead>
                                 {foreach $groups as $group}
                                     <tr>
                                         <td>
                                             <label>
                                                 <input type="hidden" name="grouped[group][{$group.id}]" value="0">
-                                                <input type="checkbox" name="grouped[group][{$group.id}]" value="1">
-                                            {$group.name}
+                                                <input id="editAmenityGroup_{$group.id}" class="amenityGroup" type="checkbox" name="grouped[group][{$group.id}]" value="1">
+                                                {$group.name}
                                             </label>
                                         </td>
                                         <td>
                                             <label>
                                                 <input type="hidden" name="grouped[searchable][{$group.id}]" value="0">
-                                                <input type="checkbox" name="grouped[searchable][{$group.id}]" value="1">
-                                            Searchable
+                                                <input id="editAmenityGroupSearchable_{$group.id}" class="amenitySearch" type="checkbox" name="grouped[searchable][{$group.id}]" value="1">
+                                                Searchable
                                             </label>
                                         </td>
                                     </tr>
                     <th>Used With</th>
                     <th>Description</th>
                     <th>Short Description</th>
-                    <th>Uses Value</th>
                     <th>&nbsp;</th>
                 </tr>
             </thead>
                         <tr class="alternate">
                     {/if}
                             <td>
-                                <a class="editAmenity" data-amenityID="{$t.id}" data-refTypeID="{$t.ref_type.value}" data-amenityUsesValue="{$t.uses_value.value}">{$t.name}</a>
+                                <a class="editAmenity" data-amenityID="{$t.id}" data-refTypeID="{$t.ref_type.value}" data-amenityUsesValue="{$t.uses_value.value}" data-groupjson='{$t.groups_json}'>{$t.name}</a>
                             </td>
                             <td id="editAmenityRefType_{$t.id}">
                                 {$t.ref_type.name}
                             <td id="editAmenityShortDescr_{$t.id}">
                                 {$t.short_descr}
                             </td>
-                            <td id="editAmenityGroups_{$t.id}" data-groupjson='{$t.groups_json}'>
-                                {foreach $t.groups as $group}
-                                    
-                                {/foreach}
-                            </td>
                             <td>
                                 <div class="deleteAmenityButton button button-secondary glm-button-small glm-right" data-amenityID="{$t.id}">Delete</div>
                             </td>
             var amenityUsesValue = parseInt($(this).attr('data-amenityUsesValue'));
             var amenityDescr = $('#editAmenityDescr_' + amenityID).html();
             var amenityShortDescr = $('#editAmenityShortDescr_' + amenityID).html();
+            var amenityGroups = JSON.parse($(this).attr('data-groupjson'));
             $('#editAmenityID').val(amenityID);
             $('#editAmenityName').val(amenityName.trim());
             $('#editAmenityRef').val(amenityRefTypeID);
             $('#editAmenityUsesValue').prop('checked', amenityUsesValue);
             $('#editAmenityDescr').val(amenityDescr.trim());
             $('#editAmenityShortDescr').val(amenityShortDescr.trim());
+            $('.amenityGroup').each(function(){
+                $(this).prop('checked', false);
+            });
+            $('.amenitySearch').each(function(){
+                $(this).prop('checked', false);
+            });
+            for ( var group in amenityGroups ) {
+                console.log( amenityGroups[group] );
+                $('#editAmenityGroup_' + amenityGroups[group].group_id).prop('checked', true);
+                if ( amenityGroups[group].searchable == "1" ) {
+                    $('#editAmenityGroupSearchable_' + amenityGroups[group].group_id).prop('checked', true);
+                }
+            }
             $("#editAmenityDialog").dialog("open");
         });
         $('#editAmenityCancel').click( function() {
 
     });
 </script>
-<table id="glm-table-groups" class="glm-admin-table glm-settings-table{if $option!='groups'} glm-hidden{/if}">
+<table id="glm-table-groups" class="glm-admin-table glm-settings-table{if $option2!='group'} glm-hidden{/if}">
     <tr>
         <td colspan="2">
         <!-- Add Group Button and Dialog Box -->
             <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
                 <input type="hidden" name="glm_action" value="amenities">
                 <input type="hidden" name="option" value="addNewGroup">
+                <input type="hidden" name="option2" value="group">
 
                 <!-- This is only temporary until we reinstate the "Used With" selection below -->
                 <input type="hidden" name="ref_type" value="20">
             <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
                 <input type="hidden" name="glm_action" value="amenities">
                 <input type="hidden" name="option" value="updateGroup">
+                <input type="hidden" name="option2" value="group">
                 <input id="editGroupID" type="hidden" name="id" value="">
 
                 <!-- This is only temporary until we reinstate the "Used With" selection below -->
         });
         $('#deleteGroupConfirm').click( function() {
             $("#deleteGroupDialog").dialog("close");
-            window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=amenities&option=deleteGroup&id=" + id + "&option=groups";
+            window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=amenities&option=deleteGroup&id=" + id + "&option2=group";
         });
         $('#deleteGroupCancel').click( function() {
             $("#deleteGroupDialog").dialog("close");