From a1093f43106ee1941c96b963b3004266a906abb6 Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Wed, 25 Oct 2017 12:50:27 -0400 Subject: [PATCH] Making custom field mgmt contacts-friendly No longer is the custom field plugin only accessible by the member db on management. Fields can also be deleted, added and edited which took some changes to option, option2, the form href, etc. --- models/admin/entity/fields.php | 4 ++-- models/admin/management/fields.php | 20 +++++++++++++++---- setup/adminHooks.php | 6 +++--- views/admin/management/fields.html | 31 ++++++++---------------------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/models/admin/entity/fields.php b/models/admin/entity/fields.php index 3115c1a..bae35c2 100644 --- a/models/admin/entity/fields.php +++ b/models/admin/entity/fields.php @@ -122,7 +122,7 @@ class GlmMembersAdmin_entity_fields extends GlmDataFieldsCustomFields $customFieldData = false; $where = 'true'; $uid = ''; - + if (isset($_REQUEST['option'])) { $option = $_REQUEST['option']; } @@ -157,7 +157,7 @@ class GlmMembersAdmin_entity_fields extends GlmDataFieldsCustomFields require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php'; $customFieldsData = customFieldsGetFieldData( $entityID ); - + // Compile template data $template_data = array( 'prefix' => 'glm_custom_field', diff --git a/models/admin/management/fields.php b/models/admin/management/fields.php index ae387d6..e3ed2b7 100644 --- a/models/admin/management/fields.php +++ b/models/admin/management/fields.php @@ -117,21 +117,28 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields */ public function modelAction($actionData = false) { + $glm_action = ''; $option = false; $settings_updated = false; $settings_update_error = false; $custom_fields = false; $haveCustomFields = false; + $where = ' TRUE '; if (isset($_REQUEST['option2'])) { $option = $_REQUEST['option2']; } + if (isset($_GET['glm_action'])) { + $glm_action = $_GET['glm_action']; + } + // Check if a field ID is supplied $id = 0; if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']-0; } + $uid = 0; if (isset($actionData['uid'])) { @@ -183,23 +190,28 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields } + $where .= " AND uid = '$uid' "; + // Get list of Custom Fields - $custom_fields = $this->getList(); - // echo "
" . print_r($custom_fields, true) . "
"; + $custom_fields = $this->getList( $where ); + // echo "
REQUEST " . print_r($_REQUEST, true) . "
"; + // echo "
GET " . print_r($_GET, true) . "
"; if ( isset($custom_fields) && $custom_fields && count( $custom_fields ) > 0 ) { $haveCustomFields = true; } // Compile template data $template_data = array( - 'option2' => $option, + 'option2' => $option, 'settingsUpdated' => $settings_updated, 'settingsUpdateError' => $settings_update_error, 'custom_fields' => $custom_fields, 'field_types' => $this->config['custom_field_types'], 'haveCustomFields' => $haveCustomFields, - 'uid' => $uid + 'uid' => $uid, + 'glm_action' => $glm_action ); + // echo "
Template data:" . print_r($template_data, true) . "
"; // Return status, suggested view, and data to controller return array( diff --git a/setup/adminHooks.php b/setup/adminHooks.php index f67d9f2..aa4131a 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -32,7 +32,7 @@ add_filter( 'glm-members-customfields-active', function( $active ){ return true; }, 10, 1 ); /** - * Filter returns html from the management -> fields model. + * Filter returns html from the management -> fields model. */ add_filter( 'glm-members-customfields-edit', function( $content, $uid ){ unset( $_REQUEST['glm_action'] ); @@ -157,11 +157,11 @@ add_filter('glm-member-db-admin-search-query', function() { } return $queryParts; }); -add_filter('glm-member-db-save-custom-fields', function( $entityID ) { +add_filter('glm-member-db-save-custom-fields', function( $entityID, $uid ) { require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php'; // this will save the member data //echo "uid = $uid"; - customFieldsSaveFields( $entityID ); + customFieldsSaveFields( $entityID, $uid ); return true; }, 10, diff --git a/views/admin/management/fields.html b/views/admin/management/fields.html index 8df42e9..1f4086e 100644 --- a/views/admin/management/fields.html +++ b/views/admin/management/fields.html @@ -1,8 +1,8 @@
Add a Custom Field
-
- + + @@ -57,8 +57,8 @@
- - + + @@ -87,13 +87,7 @@ (text or checkbox only) - - Required? - - - - - +

* Required

Cancel @@ -133,7 +127,7 @@ {$t.id}
- {$t.field_name} + {$t.field_name}
@@ -203,12 +197,10 @@ jQuery(document).ready(function($) { var fieldName = $(this).text(); var fieldType = $(this).attr('data-fieldType'); var adminSearch = $(this).attr('data-adminSearch'); - var required = $(this).attr('data-required'); - $('#editFieldID').val(fieldID); $('#editFieldName').val(fieldName.trim()); $('#editFieldType').val(fieldType); - + console.log(adminSearch); if (adminSearch === '1') { console.log('setting the checked to true'); $('#editAdminSearch').prop('checked', true); @@ -216,13 +208,6 @@ jQuery(document).ready(function($) { console.log('setting the checked to false'); $('#editAdminSearch').prop('checked', false); } - // check required fields - if (required === '1') { - $('#editRequired').prop('checked', true); - } else { - console.log('setting the checked to false'); - $('#editRequired').prop('checked', false); - } $("#editFieldDialog").dialog("open"); }); $('#editFieldCancel').click( function() { @@ -239,7 +224,7 @@ jQuery(document).ready(function($) { }); $('#deleteFieldConfirm').click( function() { $("#deleteFieldDialog").dialog("close"); - window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=import&option=customfields&option2=delete&id=" + id; + window.location.href = "{$thisUrl}?page={$thisPage}&glm_action={$glm_action}&option=customfields&option2=delete&id=" + id; }); $('#deleteFieldCancel').click( function() { $("#deleteFieldDialog").dialog("close"); -- 2.17.1