From 658e8760d0e1d166d1c30d34a48a2da56a61a1fc Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 14 Jun 2016 15:18:02 -0400 Subject: [PATCH] Finishing up the amenity grouping in the admin. Updating adding groups stays on the group tab now. Updating groups in each amenity now working in amenity list. --- models/admin/settings/amenities.php | 39 +++++++++++++++++++--- views/admin/settings/amenities.html | 52 ++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 20 deletions(-) diff --git a/models/admin/settings/amenities.php b/models/admin/settings/amenities.php index cc917dc7..fd2532f5 100644 --- a/models/admin/settings/amenities.php +++ b/models/admin/settings/amenities.php @@ -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 '
$id: ' . print_r($id, true) . '
'; - echo '
$_REQUEST: ' . print_r($_REQUEST, true) . '
'; + //echo '
$id: ' . print_r($id, true) . '
'; + //echo '
$_REQUEST: ' . print_r($_REQUEST, true) . '
'; // 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 '
$amenities: ' . print_r($amenities, true) . '
'; + //echo '
$amenities: ' . print_r($amenities, true) . '
'; 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, ); diff --git a/views/admin/settings/amenities.html b/views/admin/settings/amenities.html index 008dc86a..0ab54a1d 100644 --- a/views/admin/settings/amenities.html +++ b/views/admin/settings/amenities.html @@ -5,7 +5,7 @@ Groups - +
Add an Amenity
@@ -39,20 +39,25 @@
+ + + + + {foreach $groups as $group} @@ -109,20 +114,25 @@
Groups
+ + + + + {foreach $groups as $group} @@ -148,7 +158,6 @@ - @@ -162,7 +171,7 @@ {/if} - @@ -219,12 +223,26 @@ 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() { @@ -271,7 +289,7 @@ }); -
Groups
Used With Description Short DescriptionUses Value  
- {$t.name} + {$t.name} {$t.ref_type.name} @@ -173,11 +182,6 @@ {$t.short_descr} - {foreach $t.groups as $group} - - {/foreach} -
Delete
+
@@ -280,6 +298,7 @@
+ @@ -313,6 +332,7 @@ + @@ -409,7 +429,7 @@ }); $('#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"); -- 2.17.1