adding settings tab for asset types
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 6 Mar 2018 21:44:45 +0000 (16:44 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 6 Mar 2018 21:44:45 +0000 (16:44 -0500)
fixing data class field name bug and adding the setting tab in the admin, roughed in, for the
asset types, still need to style and structure the input fields in the pop up modal

classes/data/dataAssetTypes.php
models/admin/settings/assetTypes.php [new file with mode: 0644]
setup/adminTabs.php
setup/validActions.php
views/admin/settings/assetTypes.html [new file with mode: 0644]

index 1d253b3..54b6ce5 100644 (file)
@@ -133,7 +133,7 @@ class GlmDataAssetsAssetTypes extends GlmDataAbstract
 
             // Use Type
             'use_type' => array (
-                'field' => 'state',
+                'field' => 'use_type',
                 'type' => 'list',
                 'list' => $this->config['use_type'],
                 'force_list' => true,
diff --git a/models/admin/settings/assetTypes.php b/models/admin/settings/assetTypes.php
new file mode 100644 (file)
index 0000000..ab3f565
--- /dev/null
@@ -0,0 +1,146 @@
+
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Asset Types Settings
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Asset Types data abstract
+require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataAssetTypes.php';
+
+class GlmMembersAdmin_settings_assetTypes extends GlmDataAssetsAssetTypes
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Obit ID
+     *
+     * @var $assetTypetID
+     * @access public
+     */
+    public $obitID = false;
+
+    /**
+     * Constructor
+     *
+     * This contructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     * @wpdb object WordPress database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        /*
+         * Run constructor for the Asset Type data class
+         *
+         * Note, the third parameter is a flag that indicates to the Contacts
+         * data class that it should flag a group of fields as 'view_only'.
+         */
+        parent::__construct(false, false, true);
+
+    }
+
+    public function modelAction($actionData = false)
+    {
+
+        
+        // Check if an ID is supplied
+        $id = 0;
+        if ( isset( $_REQUEST['id'] ) ) {
+            $id = $_REQUEST['id'] - 0;
+        }
+        // If there's an action option
+        if ( isset( $_REQUEST['option'] ) ) {
+            switch( $_REQUEST['option'] ) {
+                
+                case 'addNew':
+                    $return = $this->insertEntry();
+//                    $id = $return['fieldData']['id'];
+                    echo '<pre>', print_r($return), '</pre>';
+                    break;
+
+                case 'update':
+                    if ( $id > 0 ) {
+                        $this->updateEntry( $id );
+                    }
+                    break;
+
+                case 'delete':
+                    if ( $id > 0 ) {
+                        $this->deleteEntry( $id, true );
+                    }
+                    break;
+
+                default:
+                    $option2 = false;
+                    break;
+
+            }
+        }
+
+        // Get number of obits
+
+        $assetTypes = $this->getList();
+
+        // Compile template data
+        $templateData = array(
+            'assetTypes'      => $assetTypes,
+        );
+             // Return status, any suggested view, and any data to controller
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => 'admin/settings/assetTypes.html',
+            'data'          => $templateData
+        );
+
+    }
+
+
+}
index 26be7b2..68ff62f 100644 (file)
  * );
  *
  */
+if (current_user_can('glm_members_members')) {
+    if (apply_filters('glm_members_permit_admin_members_assetTypes_tab', true)) {
+
+        add_filter('glm-member-db-add-tab-for-settings',
+            function($addOnTabs) {
+                $newTabs = array(
+                    array(
+                        'text'   => 'Asset Types',
+                        'menu'   => 'settings',
+                        'action' => 'assetTypes'
+                    ),
+                );
+                $addOnTabs = array_merge($addOnTabs, $newTabs);
+                return $addOnTabs;
+            }
+        );
+
+    }
+}
 
index d473d8e..cecc3c9 100644 (file)
@@ -61,7 +61,10 @@ $glmMembersAssetsAddOnValidActions = array(
     'adminActions' => array(
         'assets' => array(
             'index' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG
-        )
+        ),
+        'settings' => array(
+            'assetTypes' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG,
+        ),
     ),
     'frontActions' => array(
     )
diff --git a/views/admin/settings/assetTypes.html b/views/admin/settings/assetTypes.html
new file mode 100644 (file)
index 0000000..6950061
--- /dev/null
@@ -0,0 +1,181 @@
+{include file='admin/management/header.html'}
+
+<h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+    <a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=assetTypes" class="glm-settings-tab nav-tab nav-tab-active">Asset Types</a>
+</h2>
+<table class="glm-admin-table glm-settings-table" style="width: 90%;">
+    <tr><td colspan="2">
+        <!-- Add Registration Payment Code Button and Dialog Box -->
+        <div id="newAssetTypeButton" class="button button-primary glm-right">Add Asset Type</div>
+        <div id="newAssetTypeDialog" class="glm-dialog-box" title="Ener a AssetType">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                <input type="hidden" name="glm_action" value="assetTypes">
+                <input type="hidden" name="option" value="addNew">
+
+                <!-- This is only temporary until we reinstate the "Used With" selection below -->
+                <table class="glm-admin-table">
+                    <tr>
+                        <th class="glm-required">Asset Type Name: </th>
+                        <td>
+                            <input id="edit-name" data-id="code" type="text" name="name" class="glm-form-text-input">
+                            <input id="edit-cost" data-id="code" type="text" name="cost" class="glm-form-text-input">
+                            <input id="edit-descr" data-id="code" type="text" name="descr" class="glm-form-text-input">
+                            <input id="edit-lead_time" data-id="code" type="text" name="lead_time" class="glm-form-text-input">
+                            <input id="edit-reuse_time" data-id="code" type="text" name="reuse_time" class="glm-form-text-input">
+                            <input id="edit-hold_time" data-id="code" type="text" name="hold_time" class="glm-form-text-input">
+                            <input id="edit-map_item_type" data-id="code" type="text" name="map_item_type" class="glm-form-text-input">
+                            <input id="edit-state" data-id="code" type="text" name="use_type" class="glm-form-text-input">
+                        </td>
+                    </tr>
+                </table>
+                <p><span class="glm-required">*</span> Required</p>
+                <a id="newAssetTypeCancel" class="button button-primary glm-right">Cancel</a>
+                <input type="submit" value="Add new AssetType" class="button button-primary">
+                
+            </form>
+        </div>
+
+        <!-- Delete AssetType Button -->
+        <div id="deleteAssetTypeDialog" class="glm-dialog-box" title="Delete AssetType">
+            <center>
+                <p>Are you sure you want to delete this Asset Type?</p>
+                <p><div id="deleteAssetTypeConfirm" class="button button-primary">Yes, delete this AssetType</div></p>
+                <p><div id="deleteAssetTypeCancel" class="button button-primary">Cancel</div></p>
+            </center>
+        </div>
+
+        <!-- Edit Registration Payment Code Dialog Box -->
+        <div id="editAssetTypeDialog" class="glm-dialog-box" title="Edit This Asset Type">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                <input type="hidden" name="glm_action" value="assetTypes">
+                <input type="hidden" name="option" value="update">
+                <input id="editAssetTypeID" type="hidden" name="id" value="">
+
+                <!-- This is only temporary until we reinstate the "Used With" selection below -->
+                <table class="glm-admin-table">
+                      <tr>
+                        <th class="glm-required">AssetType Name:</th>
+                        <td>
+                            <input id="edit-name" data-id="code" type="text" name="name" class="glm-form-text-input">
+                            <input id="edit-cost" data-id="code" type="text" name="cost" class="glm-form-text-input">
+                            <input id="edit-descr" data-id="code" type="text" name="descr" class="glm-form-text-input">
+                            <input id="edit-lead_time" data-id="code" type="text" name="lead_time" class="glm-form-text-input">
+                            <input id="edit-reuse_time" data-id="code" type="text" name="reuse_time" class="glm-form-text-input">
+                            <input id="edit-hold_time" data-id="code" type="text" name="hold_time" class="glm-form-text-input">
+                            <input id="edit-map_item_type" data-id="code" type="text" name="map_item_type" class="glm-form-text-input">
+                            <input id="edit-state" data-id="code" type="text" name="state" class="glm-form-text-input">
+                        </td>
+                    </tr>
+                    <tr>
+                </table>
+                <p><span class="glm-required">*</span> Required</p>
+                <a id="editAssetTypeCancel" class="button button-primary glm-right">Cancel</a>
+                <input type="submit" value="Update this AssetType">
+
+            </form>
+        </div>
+
+        <table class="wp-list-table wideFat fixed posts glm-admin-table" style="width: 90%;">
+            <thead>
+                <tr>
+                    <th> AssetType Name </th>
+                    <th>&nbsp;</th>
+                </tr>
+            </thead>
+            <tbody>
+               {$assetTypes|@print_r}
+            {if $assetTypes}
+            
+                {assign var="i" value="0"}
+                {foreach $assetTypes as $n}
+                    {if $i++ is odd by 1}
+                        <tr>
+                    {else}
+                        <tr class="alternate">
+                    {/if}
+                            <td>
+                                <div class="assettype-record" id="assettype_{$n.id}" data-assettypeID="{$n.id}" >{$n.name}</div>
+                                <div class="editAssetTypeButton editAssetType button button-secondary glm-button-small glm-right" data-assettypeID="{$n.id}">Edit</div> 
+                                <div class="deleteAssetTypeButton button button-secondary glm-button-small glm-right" data-assettypeID="{$n.id}">Delete</div>
+                            </td>
+                        </tr>
+                  
+                {/foreach}
+            {else}
+                <tr class="alternate"><td colspan="2">(no asset types listed)</td></tr>
+            {/if}
+            </tbody>
+        </table>
+    </tr>
+</table>
+
+<script type="text/javascript">
+    jQuery(document).ready(function($) {
+
+        $("#newAssetTypeDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+        $("#editAssetTypeDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+        $("#deleteAssetTypeDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+
+        $('#newAssetTypeButton').click( function() {
+            $("#newAssetTypeDialog").dialog("open");
+        });
+        $('.editAssetType').click( function() {
+            var assettypeID        = $(this).attr('data-assettypeID');
+
+            $('#editAssetTypeID').val(assettypeID);
+
+            $("#editAssetTypeDialog").dialog("open");
+        });
+        $('#editAssetTypeCancel').click( function() {
+            $("#editAssetTypeDialog").dialog("close");
+        });
+        $('#newAssetTypeCancel').click( function() {
+            $("#newAssetTypeDialog").dialog("close");
+        });
+
+        var id = false;
+        $('.deleteAssetTypeButton').click( function() {
+            id = $(this).attr('data-assettypeID');
+            $("#deleteAssetTypeDialog").dialog("open");
+        });
+        $('#deleteAssetTypeConfirm').click( function() {
+            $("#deleteAssetTypeDialog").dialog("close");
+            window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=assetTypes&option=delete&id=" + id;
+        });
+        $('#deleteAssetTypeCancel').click( function() {
+            $("#deleteAssetTypeDialog").dialog("close");
+        });
+
+        /*
+         * Edit area tabs
+         */
+        $('.glm-settings-tab').click( function() {
+
+            // Clear tabl highlights and hide all tables
+            $('.glm-settings-tab').removeClass('nav-tab-active');
+            $('.glm-settings-table').addClass('glm-hidden');
+
+            // Highlight selected tab
+            $(this).addClass('nav-tab-active');
+
+            // Show selected table
+            var table = $(this).attr('data-show-table');
+            $('#' + table).removeClass('glm-hidden');
+
+        });
+
+    });
+</script>
+