Updating the custom field management tab to be under the member management.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 17 Oct 2017 16:05:18 +0000 (12:05 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 17 Oct 2017 16:05:18 +0000 (12:05 -0400)
Adding new filters for:
active, edit, form, capture, and data.

models/admin/management/fields.php
setup/adminHooks.php
setup/adminTabs.php
setup/validActions.php
views/admin/management/fields.html

index 9d943cd..2ce537a 100644 (file)
@@ -117,15 +117,14 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
      */
     public function modelAction($actionData = false)
     {
-
         $option                = false;
         $settings_updated      = false;
         $settings_update_error = false;
         $custom_fields         = false;
         $haveCustomFields      = false;
 
-        if (isset($_REQUEST['option'])) {
-            $option = $_REQUEST['option'];
+        if (isset($_REQUEST['option2'])) {
+            $option = $_REQUEST['option2'];
         }
 
         // Check if a field ID is supplied
@@ -187,7 +186,7 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
 
         // Compile template data
         $template_data = array(
-            'option'              => $option,
+            'option2'              => $option,
             'settingsUpdated'     => $settings_updated,
             'settingsUpdateError' => $settings_update_error,
             'custom_fields'       => $custom_fields,
index c020b98..1b83e06 100644 (file)
  *
  *  Also note that parameters will be in the context of the main admin controller constructor.
   */
+/**
+ * Filter will return true if the plugin is active.
+ */
+add_filter( 'glm-members-customfields-active', function( $active ){
+    return true;
+}, 10, 1 );
+/**
+ * Filter returns html from the management -> fields model.
+ */
+add_filter( 'glm-members-customfields-edit', function( $content, $uid ){
+    unset( $_REQUEST['glm_action'] );
+    $content = $this->controller( 'management', 'fields', array( 'uid' => $uid ), true );
+    return $content;
+}, 10, 3 );
+/**
+ * Filter returns the html for the form segment
+ */
+add_filter( 'glm-members-customfields-form', function( $content, $uid, $id ){
+    unset( $_REQUEST['glm_action'] );
+    $content = $this->controller( 'memberinfo', 'fields', array( 'uid' => $uid, 'memberId' => $id ), true );
+    return $content;
+}, 10, 3 );
+/**
+ * Filter Captured Data Success Status
+ *
+ * Returns Stored Data
+ */
+add_filter( 'glm-members-customfields-capture', function( $content, $uid, $id ){
+
+}, 10, 3 );
+/**
+ * Filter to Return Stored Data
+ */
+add_filter( 'glm-members-customfields-data', function( $content, $uid, $id ){
+
+}, 10, 3 );
 add_filter( 'glm-member-db-member-info-custom-nav', function( $content ){
     $out = '<a id="glm-member-info-custom-fields" data-show-table="glm-table-custom-fields" class="glm-member-info-tab nav-tab">Custom Fields</a>';
     return $out;
index 1a1447e..d77793a 100644 (file)
  */
 // If user can manage all members
 if (current_user_can('glm_members_members')) {
-    add_filter('glm-member-db-add-tab-for-management',
-        function($addOnTabs) {
-            $newTabs = array(
-                array(
-                    'text' => 'Custom Fields',
-                    'menu' => 'fields',
-                    'action' => 'fields',
-                    'option' => 'list'
-                ),
-
-            );
-            $addOnTabs = array_merge($addOnTabs, $newTabs);
-            return $addOnTabs;
-        }
-    );
+    // add_filter('glm-member-db-add-tab-for-management',
+    //     function($addOnTabs) {
+    //         $newTabs = array(
+    //             array(
+    //                 'text' => 'Custom Fields',
+    //                 'menu' => 'fields',
+    //                 'action' => 'fields',
+    //                 'option' => 'list'
+    //             ),
+    //
+    //         );
+    //         $addOnTabs = array_merge($addOnTabs, $newTabs);
+    //         return $addOnTabs;
+    //     }
+    // );
 }
 if (current_user_can('glm_members_management')) {
     add_filter('glm-member-db-add-tab-for-import',
index 086f431..3c2be84 100644 (file)
@@ -65,6 +65,9 @@ $glmMembersFieldsAddOnValidActions = array(
         'ajax' => array(
           'filterSearch' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
         ),
+        'fields' => array(
+            'fields' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
+        ),
         'management' => array(
             'fields' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
         ),
index 831bc91..a386da1 100644 (file)
-{include file='admin/management/header.html'}
+<!-- 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">
+        <input type="hidden" name="option" value="customfields">
+        <input type="hidden" name="option2" value="addNew">
 
-    <h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
-        <a id="glm-settings" data-show-table="glm-table-settings" class="glm-settings-tab nav-tab{if $option=='settings'} nav-tab-active{/if}">Custom Fields</a>
-    </h2>
-
-    <!-- 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="fields">
-            <input type="hidden" name="option" value="addNew">
-
-            <table class="glm-admin-table">
-                <tr>
-                    <th class="glm-required">Field Name:</th>
-                    <td>
-                        <input type="text" name="field_name" class="glm-form-text-input">
-                    </td>
-                </tr>
-                <tr>
-                    <th class="glm-required">Field Type:</th>
-                    <td>
-                        <select name="field_type">
-                            {foreach $field_types as $val => $label}
-                                <option value="{$val}">{$label}</option>
-                            {/foreach}
-                        </select>
-                    </td>
-                </tr>
-                <tr>
-                    <th>Admin Searchable</th>
-                    <td>
-                        <input type="hidden" name="admin_search" value="0" />
-                        <input type="checkbox" name="admin_search" value="1" />
-                        (text or checkbox only)
-                    </td>
-                </tr>
-            </table>
-            <p><span class="glm-required">*</span> Required</p>
-            <a id="newFieldCancel" class="button button-primary glm-right">Cancel</a>
-            <input type="submit" value="Add new Custom Field" class="button button-primary">
-        </form>
-    </div>
+        <table class="glm-admin-table">
+            <tr>
+                <th class="glm-required">Field Name:</th>
+                <td>
+                    <input type="text" name="field_name" class="glm-form-text-input">
+                </td>
+            </tr>
+            <tr>
+                <th class="glm-required">Field Type:</th>
+                <td>
+                    <select name="field_type">
+                        {foreach $field_types as $val => $label}
+                        <option value="{$val}">{$label}</option>
+                        {/foreach}
+                    </select>
+                </td>
+            </tr>
+            <tr>
+                <th>Admin Searchable</th>
+                <td>
+                    <input type="hidden" name="admin_search" value="0" />
+                    <input type="checkbox" name="admin_search" value="1" />
+                    (text or checkbox only)
+                </td>
+            </tr>
+        </table>
+        <p><span class="glm-required">*</span> Required</p>
+        <a id="newFieldCancel" class="button button-primary glm-right">Cancel</a>
+        <input type="submit" value="Add new Custom Field" class="button button-primary">
+    </form>
+</div>
 
-    <!-- Delete Field Button and Dialog Box -->
-    <div id="deleteFieldDialog" class="glm-dialog-box" title="Delete Field">
-        <center>
-            <p>Are you sure you want to delete this field?</p>
-            <p><div id="deleteFieldConfirm" class="button button-primary">Yes, delete this field</div></p>
-            <p><div id="deleteFieldCancel" class="button button-primary">Cancel</div></p>
-        </center>
-    </div>
+<!-- Delete Field Button and Dialog Box -->
+<div id="deleteFieldDialog" class="glm-dialog-box" title="Delete Field">
+    <center>
+        <p>Are you sure you want to delete this field?</p>
+        <p><div id="deleteFieldConfirm" class="button button-primary">Yes, delete this field</div></p>
+        <p><div id="deleteFieldCancel" class="button button-primary">Cancel</div></p>
+    </center>
+</div>
 
-    <!-- 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="fields">
-            <input type="hidden" name="option" value="update">
-            <input id="editFieldID" type="hidden" name="id" value="">
-            <table class="glm-admin-table">
-                <tr>
-                    <th class="glm-required">Field Name:</th>
-                    <td>
-                        <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input">
-                    </td>
-                </tr>
-                <tr>
-                    <th class="glm-required">Field Type:</th>
-                    <td>
-                        <select id="editFieldType" name="field_type">
-                            {foreach $field_types as $val => $label}
-                                <option value="{$val}">{$label}</option>
-                            {/foreach}
-                        </select>
-                    </td>
-                </tr>
-                <tr>
-                    <th>Admin Searchable</th>
-                    <td>
-                        <input type="hidden" name="admin_search" value="0" />
-                        <input type="checkbox" id="editAdminSearch" name="admin_search" value="1" />
-                        (text or checkbox only)
-                    </td>
-                </tr>
-            </table>
-            <p><span class="glm-required">*</span> Required</p>
-            <a id="editFieldCancel" class="button button-primary glm-right">Cancel</a>
-            <input type="submit" value="Update this Field">
-        </form>
-    </div>
-    <table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option!='settings'} glm-hidden{/if}">
-        <tr>
-            <td colspan="2">
-                {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
-                {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
-                <h2>Custom Fields</h2>
-            </td>
-        </tr>
-    </table>
-    <table id="glm-table-settings" class="glm-admin-table glm-settings-table">
-        <thead>
+<!-- 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">
+        <input type="hidden" name="option" value="customfields">
+        <input type="hidden" name="option2" value="update">
+        <input id="editFieldID" type="hidden" name="id" value="">
+        <table class="glm-admin-table">
+            <tr>
+                <th class="glm-required">Field Name:</th>
+                <td>
+                    <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input">
+                </td>
+            </tr>
+            <tr>
+                <th class="glm-required">Field Type:</th>
+                <td>
+                    <select id="editFieldType" name="field_type">
+                        {foreach $field_types as $val => $label}
+                        <option value="{$val}">{$label}</option>
+                        {/foreach}
+                    </select>
+                </td>
+            </tr>
             <tr>
-                <th>ID</th>
-                <th>Field</th>
-                <th>Type</th>
-                <th>&nbsp;</th>
+                <th>Admin Searchable</th>
+                <td>
+                    <input type="hidden" name="admin_search" value="0" />
+                    <input type="checkbox" id="editAdminSearch" name="admin_search" value="1" />
+                    (text or checkbox only)
+                </td>
             </tr>
-        </thead>
-        <tbody>
-            {if $haveCustomFields}
-                {assign var="i" value="0"}
-                {foreach $custom_fields as $t}
-                    {if $i++ is odd by 1}
-                        <tr>
-                    {else}
-                        <tr class="alternate">
-                    {/if}
+        </table>
+        <p><span class="glm-required">*</span> Required</p>
+        <a id="editFieldCancel" class="button button-primary glm-right">Cancel</a>
+        <input type="submit" value="Update this Field">
+    </form>
+</div>
+<table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option2!='settings'} glm-hidden{/if}">
+    <tr>
+        <td colspan="2">
+            {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
+            {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
+            <h2>Custom Fields</h2>
+        </td>
+    </tr>
+</table>
+<table id="glm-table-settings" class="glm-admin-table glm-settings-table">
+    <thead>
+        <tr>
+            <th>ID</th>
+            <th>Field</th>
+            <th>Type</th>
+            <th>&nbsp;</th>
+        </tr>
+    </thead>
+    <tbody>
+        {if $haveCustomFields}
+        {assign var="i" value="0"}
+        {foreach $custom_fields as $t}
+        {if $i++ is odd by 1}
+        <tr>
+            {else}
+            <tr class="alternate">
+                {/if}
                 <td>{$t.id}</td>
                 <td>
                     <div>
                 </td>
             </tr>
             {/foreach}
-        {else}
+            {else}
             <tr class="alternate"><td colspan="2">(no custom fields listed)</td></tr>
-        {/if}
-        </tbody>
-    </table>
-    <!-- Tests -->
+            {/if}
+    </tbody>
+</table>
+<!-- Tests -->
 
 <script type="text/javascript">
 jQuery(document).ready(function($) {
@@ -207,7 +203,7 @@ jQuery(document).ready(function($) {
     });
     $('#deleteFieldConfirm').click( function() {
         $("#deleteFieldDialog").dialog("close");
-        window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=fields&option=delete&id=" + id;
+        window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=import&option=customfields&option2=delete&id=" + id;
     });
     $('#deleteFieldCancel').click( function() {
         $("#deleteFieldDialog").dialog("close");