Making custom field mgmt contacts-friendly
authorLaury GvR <laury@gaslightmedia.com>
Wed, 25 Oct 2017 16:50:27 +0000 (12:50 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Wed, 25 Oct 2017 16:50:27 +0000 (12:50 -0400)
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
models/admin/management/fields.php
setup/adminHooks.php
views/admin/management/fields.html

index 3115c1a..bae35c2 100644 (file)
@@ -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',
index ae387d6..e3ed2b7 100644 (file)
@@ -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 "<pre>" . print_r($custom_fields, true) . "</pre>";
+        $custom_fields = $this->getList( $where );
+        //  echo "<pre>REQUEST " . print_r($_REQUEST, true) . "</pre>";
+        //  echo "<pre>GET " . print_r($_GET, true) . "</pre>";
         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 "<pre>Template data:" . print_r($template_data, true) . "</pre>";
 
         // Return status, suggested view, and data to controller
         return array(
index f67d9f2..aa4131a 100644 (file)
@@ -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,
index 8df42e9..1f4086e 100644 (file)
@@ -1,8 +1,8 @@
 <!-- Add Custom Field Button and Dialog Box -->
 <div id="newFieldButton" class="button button-primary glm-right">Add a Custom Field</div>
 <div id="newFieldDialog" class="glm-dialog-box" title="Enter a New Custom Field">
-    <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
-        <input type="hidden" name="glm_action" value="import">
+    <form action="{$thisUrl}?page={$thisPage}&glm_action={$glm_action}&option=customfields" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="glm_action" value="{$glm_action}">
         <input type="hidden" name="option" value="customfields">
         <input type="hidden" name="option2" value="addNew">
 
@@ -57,8 +57,8 @@
 
 <!-- Edit Field Dialog Box -->
 <div id="editFieldDialog" class="glm-dialog-box" title="Edit this Field">
-    <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
-        <input type="hidden" name="glm_action" value="import">
+    <form action="{$thisUrl}?page={$thisPage}&glm_action={$glm_action}&option=customfields" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="glm_action" value="{$glm_action}">
         <input type="hidden" name="option" value="customfields">
         <input type="hidden" name="option2" value="update">
         <input id="editFieldID" type="hidden" name="id" value="">
                     (text or checkbox only)
                 </td>
             </tr>
-            <tr>
-                <th>Required?</th>
-                <td>
-                    <input type="hidden" name="required" value="0" />
-                    <input type="checkbox" id="editRequired" name="required" value="1" />
-                </td>
-            </tr>
+            <input type="hidden" name="uid" value="{$uid}">
         </table>
         <p><span class="glm-required">*</span> Required</p>
         <a id="editFieldCancel" class="button button-primary glm-right">Cancel</a>
                 <td>{$t.id}</td>
                 <td>
                     <div>
-                        <a class="editField" data-fieldID="{$t.id}" data-fieldType="{$t.field_type.name|escape:'html'}" data-adminSearch="{$t.admin_search.value}" data-required="{$t.required.value}">{$t.field_name}</a>
+                        <a class="editField" data-fieldID="{$t.id}" data-fieldType="{$t.field_type.name|escape:'html'}" data-adminSearch="{$t.admin_search.value}">{$t.field_name}</a>
                     </div>
                 </td>
                 <td id="editFieldType_{$t.id}">
@@ -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");