Added code for management of asset items. Not fully working yet.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 9 Mar 2018 19:58:16 +0000 (14:58 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 9 Mar 2018 19:58:16 +0000 (14:58 -0500)
00_DEVELOPMENT_TASK_LIST.txt
classes/assetsSupport.php [new file with mode: 0644]
classes/data/dataAssetItems.php
models/admin/ajax/assetManagement.php
models/admin/ajax/facilityManagement.php [new file with mode: 0644]
setup/databaseScripts/create_database_V0.0.1.sql
setup/validActions.php
views/admin/assets/assetForm.html [new file with mode: 0644]
views/admin/assets/facilityForm.html
views/admin/assets/facilityLine.html
views/admin/assets/index.html

index 3353063..90421f5 100644 (file)
@@ -1,7 +1,7 @@
 Asset Management Development Task List
 
 [X] Create Base Plugin
-[ ] Create Admin Menus
+[X] Create Admin Menus
     [X] Main: Asset Mgt
     [X] Create Database Tables
     [X] Create Data Classes for Tables
diff --git a/classes/assetsSupport.php b/classes/assetsSupport.php
new file mode 100644 (file)
index 0000000..2aa945a
--- /dev/null
@@ -0,0 +1,106 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Assets support class
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  assetsSupport.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+/*
+ * This class provides some standard methods used by this plugin
+ */
+class GlmAssetsSupport
+{
+
+    /**
+     * Merge template and data to produce HTML
+     *
+     * Checks the theme's view directories and the view directories for
+     * this plugin for a matching view file.
+     *
+     * Note that $view needs to have the proper view directory path
+     * includes. (i.e. "/views/front/registrations/summary.html")
+     *
+     * $view may also be a template as a string if $viewIsString is true.
+     *
+     * @param $data array Array of data to merge with the template
+     * @param $view string Name of view file (see above))
+     * @param $viewIsString boolean If true, $view is a string containing the view.
+     *
+     * @access public
+     * @return void
+     */
+    function generateHTML($data, $view, $viewIsString = false)
+    {
+
+        // Load Smarty Template support
+        $smarty = new smartyTemplateSupport();
+
+        // Add standard parameters
+        require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
+
+        // Add data from model to Smarty template
+        if (is_array($data) && count($data) > 0) {
+            foreach ($data as $k => $d) {
+                $smarty->templateAssign($k, $d);
+            }
+        }
+
+        // If is supplied as a string
+        if ($viewIsString) {
+
+            $out = $smarty->template->fetch('eval:'.$view);
+
+            // Otherwise $view is a file name
+        } else {
+
+            // Get the specified view file - check theme first
+            $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR."/views";
+            $viewPath2 = GLM_MEMBERS_ASSETS_PLUGIN_PATH . "/views";       // Save default
+
+            // If the view is not found in the theme, fall back to views in the plugin
+            if (!is_file($viewPath.'/'.$view)) {
+
+                // Next try the plugin/add-on
+                $viewPath = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . "/views";
+
+                if (!is_file($viewPath.'/'.$view)) {
+
+                    if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+                        trigger_error("Bad or missing view file when generating checkout HTML: $viewPath/$view", E_USER_NOTICE);
+                    }
+
+                }
+
+            }
+
+            // Update the Smarty view path
+            $smarty->template->setTemplateDir($viewPath);
+
+            // If the view path doesn't match the default, add the default (using theme view)
+            if ($viewPath2 != $viewPath) {
+                $smarty->template->addTemplateDir($viewPath2);
+            }
+
+            // Generate output from model data and view
+            $out = $smarty->template->fetch($view);
+
+        }
+
+        return $out;
+
+    }
+
+
+
+
+
+}
\ No newline at end of file
index d1c472b..affd018 100644 (file)
@@ -194,6 +194,14 @@ class GlmDataAssetsAssetItems extends GlmDataAbstract
                 'type' => 'money',
                 'use' => 'a'
             ),
+/*
+            // IMage
+            'image' => array (
+                'field' => 'image',
+                'type' => 'image',
+                'use' => 'a'
+            ),
+*/
 
             // Facility
             'facility' => array (
index 22acfa3..ec5253e 100644 (file)
@@ -2,7 +2,7 @@
 
 /**
  * Gaslight Media Members Database
- * Asset Management - Asset Admin
+ * Asset Management - Asset Admin - Asset Management
  *
  * PHP version 5.5
  *
  * @version  0.1
  */
 
+require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/assetsSupport.php';
+
 /*
  * This class performs the work of handling images passed to it via
  * an AJAX call that goes through the WorPress AJAX Handler.
  *
  */
-class GlmMembersAdmin_ajax_assetManagement
+class GlmMembersAdmin_ajax_assetManagement extends GlmAssetsSupport
 {
 
     /**
@@ -73,8 +75,8 @@ class GlmMembersAdmin_ajax_assetManagement
     public function modelAction ($actionData = false)
     {
 
-        require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataFacilities.php';
-        $Facilities = new GlmDataAssetsFacilities($this->wpdb, $this->config);
+        require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataAssetItems.php';
+        $Assets = new GlmDataAssetsAssetItems($this->wpdb, $this->config);
 
         if (!isset($_REQUEST) || !isset($_REQUEST['option'])) {
             die('No option specified.');
@@ -84,102 +86,96 @@ trigger_error("Option = ".$_REQUEST['option'],E_USER_NOTICE);
 
         switch($_REQUEST['option']) {
 
-            case 'newFacility':
+            case 'newAsset':
 
-                $facility = $Facilities->newEntry();
+                $asset = $Assets->newEntry();
 
-                $view = 'facilityForm';
+                $view = 'assetForm';
 
                 $templateData = array(
                     'status' => '0',
                     'use' => 'add',
-                    'facility' => $facility['fieldData']
+                    'asset' => $asset['fieldData']
                 );
 
                 break;
 
-            case 'addNewFacility':
+            case 'addNewAsset':
 
-                $facility = $Facilities->insertEntry();
+                $asset = $Assets->insertEntry();
 
-                // If facility was not added
-                if (!is_array($facility) || trim($facility['fieldData']['id']) == '') {
+                // If asset was not added
+                if (!is_array($asset) || trim($facility['asset']['id']) == '') {
 
-                    $view = 'facilityForm';
+                    $view = 'assetForm';
 
-                    // New facility was not added so we need to redisplay the form.
+                    // New asset was not added so we need to redisplay the form.
                     $templateData = array(
                         'status' => 1,
-                        'use' => 'add',
-                        'cities' => $cities,
-                        'states' => $this->config['states'],
-                        'countries' => $this->config['countries']
+                        'use' => 'add'
                     );
 
-                // Facility Added
+                // Asset Added
                 } else {
 
-                    $view = 'facilityLine';
+                    $view = 'assetLine';
 
                     $templateData = array(
                         'status' => '0',
-                        'facility' => $facility
+                        'asset' => $asset
                     );
 
                 }
 
                 break;
 
-            case 'editFacility':
+            case 'editAsset':
 
-                $facilityId = 0;
+                $assetId = 0;
                 if (isset($_REQUEST) && isset($_REQUEST['id']) ) {
-                    $facilityId = $_REQUEST['id'] + 0;
+                    $assetId = $_REQUEST['id'] + 0;
                 }
 
-                if ($facilityId > 0) {
-                    $facility = $Facilities->editEntry($facilityId);
-                    //echo " <pre>".print_r($facility,1)."</pre>";
-                    //die();
-                    $view = 'facilityForm';
+                if ($assetId > 0) {
+
+                    $asset = $Assets->editEntry($facilityId);
+
+                    $view = 'assetForm';
 
                     $templateData = array(
                         'status' => '0',
                         'use' => 'edit',
-                        'facility' => $facility['fieldData']
+                        'asset' => $asset['fieldData']
                     );
 
                 } else {
-                    die('1'.$this->config['terms']['assets_term_facility_cap'].' not found!');
+                    die('1'.$this->config['terms']['assets_term_asset_cap'].' not found!');
                 }
 
                 break;
 
-            case 'updateFacility':
+            case 'updateAsset':
 
                 $id = $_REQUEST['id'] - 0;
                 if ($id <= 0) {
-                    die('2'.$this->config['terms']['assets_term_facility_cap'].' ID not provided! Unable to edit.');
+                    die('2'.$this->config['terms']['assets_term_asset_cap'].' ID not provided! Unable to edit.');
                 }
 
-                $facility = $Facilities->updateEntry($id);
+                $asset = $Assets->updateEntry($id);
 
-                // If facility was not propertlyupdated
-                if (!is_array($facility) || trim($facility['fieldData']['id']) == '') {
+                // If asset was not propertlyupdated
+                if (!is_array($asset) || trim($asset['fieldData']['id']) == '') {
 
-                    $view = 'facilityForm';
+                    $view = 'assetForm';
 
-                    // New facility was not added so we need to redisplay the form.
+                    // New asset was not added so we need to redisplay the form.
                     $templateData = array(
                         'status' => 2,
-                        'use' => 'add',
-                        'cities' => $cities,
-                        'states' => $this->config['states'],
-                        'countries' => $this->config['countries']
+                        'use' => 'add'
                     );
 
                 } else {
-                    die('0'.$facility['fieldData']['name']);
+                    die('0'.$asset['fieldData']['name']);
                 }
 
                 break;
@@ -198,85 +194,4 @@ trigger_error("Option = ".$_REQUEST['option'],E_USER_NOTICE);
 
     }
 
-    /**
-     * Merge template and data to produce HTML
-     *
-     * Checks the theme's view directories and the view directories for
-     * this plugin for a matching view file.
-     *
-     * Note that $view needs to have the proper view directory path
-     * includes. (i.e. "/views/front/registrations/summary.html")
-     *
-     * $view may also be a template as a string if $viewIsString is true.
-     *
-     * @param $data array Array of data to merge with the template
-     * @param $view string Name of view file (see above))
-     * @param $viewIsString boolean If true, $view is a string containing the view.
-     *
-     * @access public
-     * @return void
-     */
-    function generateHTML($data, $view, $viewIsString = false)
-    {
-
-        // Load Smarty Template support
-        $smarty = new smartyTemplateSupport();
-
-        // Add standard parameters
-        require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php';
-
-        // Add data from model to Smarty template
-        if (is_array($data) && count($data) > 0) {
-            foreach ($data as $k => $d) {
-                $smarty->templateAssign($k, $d);
-            }
-        }
-
-        // If is supplied as a string
-        if ($viewIsString) {
-
-            $out = $smarty->template->fetch('eval:'.$view);
-
-            // Otherwise $view is a file name
-        } else {
-
-            // Get the specified view file - check theme first
-            $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR."/views";
-            $viewPath2 = GLM_MEMBERS_ASSETS_PLUGIN_PATH . "/views";       // Save default
-
-            // If the view is not found in the theme, fall back to views in the plugin
-            if (!is_file($viewPath.'/'.$view)) {
-
-                // Next try the plugin/add-on
-                $viewPath = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . "/views";
-
-                if (!is_file($viewPath.'/'.$view)) {
-
-                    if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
-                        trigger_error("Bad or missing view file when generating checkout HTML: $viewPath/$view", E_USER_NOTICE);
-                    }
-
-                }
-
-            }
-
-            // Update the Smarty view path
-            $smarty->template->setTemplateDir($viewPath);
-
-            // If the view path doesn't match the default, add the default (using theme view)
-            if ($viewPath2 != $viewPath) {
-                $smarty->template->addTemplateDir($viewPath2);
-            }
-
-            // Generate output from model data and view
-            $out = $smarty->template->fetch($view);
-
-        }
-
-        return $out;
-
-    }
-
-
-
 }
diff --git a/models/admin/ajax/facilityManagement.php b/models/admin/ajax/facilityManagement.php
new file mode 100644 (file)
index 0000000..1952573
--- /dev/null
@@ -0,0 +1,203 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Asset Management - Asset Admin - Facility Management
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/assetsSupport.php';
+
+/*
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_facilityManagement extends GlmAssetsSupport
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This modelAction takes an AJAX image upload and stores the image in the
+     * media/images directory of the plugin.
+     *
+     * This model action does not return, it simply does it's work then calls die();
+     *
+     * Status characters returned
+     * 0 - Submission OK
+     * 1 - Faciltiy not found when trying to edit
+     * 2 - ID not provided for facility update on form submission
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataFacilities.php';
+        $Facilities = new GlmDataAssetsFacilities($this->wpdb, $this->config);
+
+        if (!isset($_REQUEST) || !isset($_REQUEST['option'])) {
+            die('No option specified.');
+        }
+
+trigger_error("Option = ".$_REQUEST['option'],E_USER_NOTICE);
+
+        switch($_REQUEST['option']) {
+
+            case 'newFacility':
+
+                $facility = $Facilities->newEntry();
+
+                $view = 'facilityForm';
+
+                $templateData = array(
+                    'status' => '0',
+                    'use' => 'add',
+                    'facility' => $facility['fieldData']
+                );
+
+                break;
+
+            case 'addNewFacility':
+
+                $facility = $Facilities->insertEntry();
+
+                // If facility was not added
+                if (!is_array($facility) || trim($facility['fieldData']['id']) == '') {
+
+                    $view = 'facilityForm';
+
+                    // New facility was not added so we need to redisplay the form.
+                    $templateData = array(
+                        'status' => 1,
+                        'use' => 'add',
+                        'cities' => $cities,
+                        'states' => $this->config['states'],
+                        'countries' => $this->config['countries']
+                    );
+
+                // Facility Added
+                } else {
+
+                    $view = 'facilityLine';
+
+                    $templateData = array(
+                        'status' => '0',
+                        'facility' => $facility
+                    );
+
+                }
+
+                break;
+
+            case 'editFacility':
+
+                $facilityId = 0;
+                if (isset($_REQUEST) && isset($_REQUEST['id']) ) {
+                    $facilityId = $_REQUEST['id'] + 0;
+                }
+
+                if ($facilityId > 0) {
+                    $facility = $Facilities->editEntry($facilityId);
+                    //echo " <pre>".print_r($facility,1)."</pre>";
+                    //die();
+                    $view = 'facilityForm';
+
+                    $templateData = array(
+                        'status' => '0',
+                        'use' => 'edit',
+                        'facility' => $facility['fieldData']
+                    );
+
+                } else {
+                    die('1'.$this->config['terms']['assets_term_facility_cap'].' not found!');
+                }
+
+                break;
+
+            case 'updateFacility':
+
+                $id = $_REQUEST['id'] - 0;
+                if ($id <= 0) {
+                    die('2'.$this->config['terms']['assets_term_facility_cap'].' ID not provided! Unable to edit.');
+                }
+
+                $facility = $Facilities->updateEntry($id);
+
+                // If facility was not propertlyupdated
+                if (!is_array($facility) || trim($facility['fieldData']['id']) == '') {
+
+                    $view = 'facilityForm';
+
+                    // New facility was not added so we need to redisplay the form.
+                    $templateData = array(
+                        'status' => 2,
+                        'use' => 'add',
+                        'cities' => $cities,
+                        'states' => $this->config['states'],
+                        'countries' => $this->config['countries']
+                    );
+
+                } else {
+                    die('0'.$facility['fieldData']['name']);
+                }
+
+                break;
+
+            default:
+                die('No valid option provided');
+                break;
+        }
+
+        $templateData['$glmPluginMediaUrl'] = GLM_MEMBERS_PLUGIN_MEDIA_URL;
+        $html = $this->generateHTML($templateData, 'admin/assets/'.$view.'.html');
+        die($html);
+
+
+        die('Nothing Here');
+
+    }
+
+}
index 7483a97..7e2259e 100644 (file)
@@ -164,6 +164,7 @@ CREATE TABLE {prefix}asset_item (
     lead_time INTEGER NULL,                                     -- Actual lead time required to request this item - Abstract "interval" type 
     reuse_time INTEGER NULL,                                    -- Actual time required to prepair this type for reuse for this item  - Abstract "interval" type 
     cost FLOAT NULL,                                            -- Default cost for use of this asset type
+  ++image TINYTEXT NULL,                                        -- Asset Image
     facility INTEGER NULL,                                      -- Pointer to facility
     -- Map location data has to go here
     PRIMARY KEY (id),
@@ -179,8 +180,8 @@ CREATE TABLE {prefix}asset_assignment (
     status TINYINT NULL,                                        -- Status of this assignment - Config list "assignment_status"
     name TINYTEXT NULL,                                         -- Name of this assignment (Event, requester, ...)
     account INTEGER NULL,                                       -- Pointer to account record
-    start_time DATETIME NULL,                                   -- Start time of assignment
-    end_time DATETIME NULL,                                     -- End time of assignment
+  --start_time DATETIME NULL,                                   -- Start time of assignment
+  --end_time DATETIME NULL,                                     -- End time of assignment
     PRIMARY KEY (id),
     INDEX (start_time),
     INDEX (end_time),
@@ -196,6 +197,8 @@ CREATE TABLE {prefix}asset_assigned (
     asset_item INTEGER NULL,                                    -- Pointer to asset_item
     asset_type INTEGER NULL,                                    -- Pointer to asset_type
     quant INTEGER NULL,                                         -- Quantity of asset_item assigned - Default to 1
+  ++start_time DATETIME NULL,                                   -- Start time of assignment
+  ++end_time DATETIME NULL,                                     -- End time of assignment
     hold_release_time DATETIME NULL,                            -- Time at which hold on this asset item is released (0 if assignment is complete) 
     PRIMARY KEY (id),
     INDEX (asset_assignment),
index f3f4656..03e02ad 100644 (file)
@@ -60,6 +60,7 @@
 $glmMembersAssetsAddOnValidActions = array(
     'adminActions' => array(
         'ajax' => array(
+            'facilityManagement' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG,
             'assetManagement' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG
         ),
         'assets' => array(
diff --git a/views/admin/assets/assetForm.html b/views/admin/assets/assetForm.html
new file mode 100644 (file)
index 0000000..6b9e171
--- /dev/null
@@ -0,0 +1,68 @@
+{$status} {* first character of this file is a status flag for the calling AJAX code. *}
+
+*** Still Building Form ***<br>
+
+    <style type='text/css'>
+        .assets-dialog-box {
+            display: grid;
+            grid-gap: 5px 5px;
+            grid-template-columns: 8rem auto;
+        }
+        .assets-facility-descr {
+            width: 30em !important;
+        }
+        .assets-asset-input-prompt {
+            padding: 5px 0 0 5px;
+        }       
+        .assetsAssetInputReqired {
+            color: red;
+        }
+    </style>
+
+
+    {* Asset Dialog Box *}
+        
+        <form id="assetForm" method="post" enctype="multipart/form-data">
+
+            <input type="hidden" name="glm_action" value="assetManagement">
+    {if $use == 'add'}
+            <input type="hidden" name="option" value="addNewAsset">
+    {/if}
+    {if $use == 'edit'}
+            <input type="hidden" name="option" value="updateAsset">    
+            <input type="hidden" name="id" value="{$asset.id}">    
+    {/if}
+            
+            <div class="assets-dialog-box">
+                
+                <div class="glm-required assets-asset-input-prompt">Name:</div>
+                <div><input type="text" name="name" class="glm-form-text-intput glm-form-text-input-medium" value="{$asset.name}" required><span id="assetsAssetInputMsg_name" class="assetsAssetInputReqired"></span></div>
+                
+                <div class="assets-asset-input-prompt">Description:</div>
+                <div><textarea name="descr" class="glm-form-textarea assets-asset-descr">{$asset.descr}</textarea></div>
+                
+                <div class="assets-asset-input-prompt">{$terms.assets_term_facility_cap} Image:</div>
+                <div>
+    {if $asset.image}                    
+                    <input type="checkbox" name="logo_delete"> Delete Image<br>
+                    <img src="{$glmPluginMediaUrl}/images/small/{$asset.image}"><br>
+                    <a href="{$glmPluginMediaUrl}/images/large/{$asset.image}" target="assetImage">{$asset.image}</a><br>
+    {/if}
+                    <b>New image:</b> <input id="assetImage" type="file" name="image_new">
+                </div>
+
+                <div>&nbsp;</div><div>&nbsp;</div>
+
+                <div><span class="glm-required">*</span> Required</div>
+                <div>
+                    <input class="button button-primary" type="submit" name="Click Here" 
+                        {if $use == 'add'} value="Add New {$terms.assets_term_asset_cap}" {/if}
+                        {if $use == 'edit'} value="Update {$terms.assets_term_asset_cap}" {/if}
+                    >
+                    <a id="assetsDialogCancel" class="button button-primary">Cancel</a>
+                </div>
+                
+                </div> {* assetsAssetDialog *}
+            
+        
+        </form>
index 526a088..2aebd0e 100644 (file)
@@ -4,7 +4,7 @@
         .assets-dialog-box {
             display: grid;
             grid-gap: 5px 5px;
-            grid-template-columns: 8rem auto;
+            grid-template-columns: 8em auto;
         }
         .assets-facility-descr {
             width: 30em !important;
         .assets-facility-input-prompt {
             padding: 5px 0 0 5px;
         }       
-        .assetsFacilityInputMsg {
+        .assetsFacilityInputReqired {
             color: red;
         }
     </style>
 
 
-    {* New Facility Dialog Box *}
+    {* Facility Dialog Box *}
         
         <form id="facilityForm" method="post" enctype="multipart/form-data">
 
@@ -34,7 +34,7 @@
             <div class="assets-dialog-box">
                 
                 <div class="glm-required assets-facility-input-prompt">Name:</div>
-                <div><input type="text" name="name" class="glm-form-text-intput glm-form-text-input-medium" value="{$facility.name}" required><span id="assetsFacilityInputMsg_name" class="assetsFacilityInputMsg"></span></div>
+                <div><input type="text" name="name" class="glm-form-text-intput glm-form-text-input-medium" value="{$facility.name}" required><span id="assetsFacilityInputMsg_name" class="assetsFaclityInputReqired"></span></div>
                 
                 <div class="assets-facility-input-prompt">Description:</div>
                 <div><textarea name="descr" class="glm-form-textarea assets-facility-descr">{$facility.descr}</textarea></div>
index b7dc767..4466d83 100644 (file)
@@ -1,7 +1,8 @@
 {$status} {* first character of this file is a status flag for the calling AJAX code. *}
 
 <div style="grid-column: 1 / span 7;" class="facility_{$facility.fieldData.id} facility-name" data-id="{$facility.fieldData.id}">{$facility.fieldData.name}</div>
-<div style="grid-column: 2 / span 6;" id="facilityEditLinks_{$facility.fieldData.id}" class="glm-hidden facility_{$facility.fieldData.id}">
+<div style="grid-column: 2 / span 6;" id="facilityEditLinks_{$facility.fieldData.id}" class="assetsEditLinks glm-hidden facility_{$facility.fieldData.id}">
     <a class="facility-edit button glm-button-small" data-id="{$facility.fieldData.id}">Edit</a>
     <a class="facility-delete button glm-button-small" data-id="{$facility.fieldData.id}">Delete</a>
+    <a class="asset-add button glm-button-small" data-id="{$facility.fieldData.id}">Add Asset</a>
 </div>
index e5da26a..54eab88 100644 (file)
@@ -9,20 +9,20 @@
         .assets-admin-content {
             display: grid;
             grid-gap: 0 0;
-            grid-template-columns: 1rem 1rem 1rem auto auto auto auto;
+            grid-template-columns: 1em 1em 1em auto auto auto auto;
         }
         .facility-name {
             font-weight: bold;
             margin-top: 10px;
-            font-size: 1rem;
+            font-size: 1.1em;
         }
-        .assets-colum-title {
+        .assets-column-title {
             font-weight: bold;
         }
         .assets-dialog-box {
             display: grid;
             grid-gap: 5px 5px;
-            grid-template-columns: 8rem auto;
+            grid-template-columns: 8em auto;
         }
         .assets-facility-descr {
             width: 30em !important;
         .assetsFacilityInputMsg {
             color: red;
         }
+        .assetsEditLinks {
+            margin-top: 10px;
+            margin-bottom: 10px;
+        }
     </style>
     
 
                 
                 {* First indent here *}
                 
-                <div style="grid-column: 2 / span 6;" id="facilityEditLinks_{$facility.id}" class="glm-hidden facility_{$facility.id}">
+                <div style="grid-column: 2 / span 6;" id="facilityEditLinks_{$facility.id}" class="assetsEditLinks glm-hidden facility_{$facility.id}">
                     <a class="facility-edit button glm-button-small" data-id="{$facility.id}">Edit</a>
                     <a class="facility-delete button glm-button-small" data-id="{$facility.id}">Delete</a>
+                    <a class="glm-assets-add-asset-button button glm-button-small" data-id="{$facility.id}">Add Asset</a>
                 </div>
                 
-                <div style="grid-column: 2 / span 3;" class="assets-colum-title facility_{$facility.id} glm-hidden">Asset Type</div>
-                <div class="assets-colum-title facility_{$facility.id} glm-hidden">Name</div>
-                <div class="assets-colum-title facility_{$facility.id} glm-hidden">Number</div>
-                <div class="assets-colum-title facility_{$facility.id} glm-hidden">Quantity</div>
+                <div style="grid-column: 2 / span 3;" class="assets-column-title facility_{$facility.id} glm-hidden">Asset Type</div>
+                <div class="assets-column-title facility_{$facility.id} glm-hidden">Name</div>
+                <div class="assets-column-title facility_{$facility.id} glm-hidden">Number</div>
+                <div class="assets-column-title facility_{$facility.id} glm-hidden">Quantity</div>
                 
                 <div style="grid-column: 2 / span 3;" class="facility_{$facility.id} glm-hidden">Room</div>
                 <div class="facility_{$facility.id} glm-hidden">Ballroom</div>
                 
                 <div style="grid-column: 3 / span 5;" class="facility_{$facility.id} glm-hidden"><a href="#edit">Edit</a> <a href="#edit">Delete</a></div>
         
-                <div style="grid-column: 3 / span 2;" class="assets-colum-title facility_{$facility.id} glm-hidden">Start</div>
-                <div class="assets-colum-title facility_{$facility.id} glm-hidden">End</div>
-                <div class="assets-colum-title facility_{$facility.id} glm-hidden">Account</div>
-                <div class="assets-colum-title facility_{$facility.id} glm-hidden">Quantity</div>
+                <div style="grid-column: 3 / span 2;" class="assets-column-title facility_{$facility.id} glm-hidden">Start</div>
+                <div class="assets-column-title facility_{$facility.id} glm-hidden">End</div>
+                <div class="assets-column-title facility_{$facility.id} glm-hidden">Account</div>
+                <div class="assets-column-title facility_{$facility.id} glm-hidden">Quantity</div>
     
                 {foreach $asset.assignments as $assignment}                        
 
 jQuery(document).ready(function($){
 
 
-    var facilityEditFlag = false;
+    var editFlag = false;
     var facilityHoverId = false;    
     var currentFormAction = false;
     
     // File Line Hover Action
     $('.facility-name').live( 'mouseenter', function() {     
-        if (facilityEditFlag) {
+        if (editFlag) {
             return;
         }
         if (facilityHoverId) {
@@ -159,16 +164,11 @@ jQuery(document).ready(function($){
 
     function clearFacilityExpand() {
         facilityLinksEditSelected();
-        facilityEditFlag = false;
+        editFlag = false;
         facilityHoverId = false;
     }
     
-    
-    
-    
-    
-    
-    // Facility dialog box
+    // Add / Edit dialog box
     $('#assetsDialog').dialog({
         autoOpen: false,
         width: 600,
@@ -184,15 +184,18 @@ jQuery(document).ready(function($){
     // Cancel facility dialog box
     $('#assetsDialogCancel').live('click', function() {
         $('#assetsDialog').dialog('close');
-        facilityEditFlag = false;
+        editFlag = false;
     });
     
-
+    /*
+     * Facility
+     */
+     
     // Add a facility
     $('#glm-assets-add-facility-button').live('click', function(event) {
-        facilityEditFlag = true;
+        editFlag = true;
         $.ajax({
-            url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=assetManagement&option=newFacility',
+            url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=facilityManagement&option=newFacility',
             type: $(this).attr("method"),
             dataType: 'html',
             processData: false,
@@ -214,9 +217,9 @@ jQuery(document).ready(function($){
     
     // Edit a facility
     $('.facility-edit').live('click', function(event) {
-        facilityEditFlag = true;
+        editFlag = true;
         $.ajax({
-            url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=assetManagement&option=editFacility&id=' + facilityHoverId,
+            url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=facilityManagement&option=editFacility&id=' + facilityHoverId,
             type: $(this).attr("method"),
             dataType: 'html',
             processData: false,
@@ -248,7 +251,7 @@ jQuery(document).ready(function($){
 
         event.preventDefault();        
         $.ajax({
-            url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=assetManagement&option=' + thisOption,
+            url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=facilityManagement&option=' + thisOption,
             type: $(this).attr("method"),
             dataType: 'html',
             data: new FormData(this),
@@ -262,7 +265,7 @@ jQuery(document).ready(function($){
                 // If all is good add this facility to the top of the list for now
                 if (status == 0) {
 
-                    facilityEditFlag = false;
+                    editFlag = false;
                     
                     if (currentFormAction == 'add') {
                         $('#assetsFacilitiesContainer').prepend(html);
@@ -285,6 +288,84 @@ jQuery(document).ready(function($){
         });        
     });
     
+    /*
+     * Asset
+     */
+     
+    // Add an Asset
+    $('.glm-assets-add-asset-button').live('click', function(event) {
+        editFlag = true;
+        var facilityId = $(this).attr('data-id');
+        $.ajax({
+            url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=assetManagement&option=newAsset&facility=',
+            type: $(this).attr("method"),
+            dataType: 'html',
+            processData: false,
+            contentType: false,
+            success: function (data, status)
+            {
+                currentFormAction = 'add';
+                var status = data.charAt(0);
+                $('#assetsDialog').html(data.substring(1));
+                $('#assetsDialog').dialog( "option", "title", "Add a new {$terms.assets_term_asset_cap}" );
+                $('#assetsDialog').dialog('open');
+            },
+            error: function (xhr, desc, err)
+            {
+                alert("Sorry, we were unable to talk to our systems at the moment. Please try again.");
+            }
+        });        
+    });
+
+
+    // Submit Asset Form
+    $('#assetForm').live('submit', function(event) {
+        
+        if (currentFormAction == 'add') {
+            var thisOption = 'addNewAsset';
+        }
+        if (currentFormAction == 'edit') {
+            var thisOption = 'updateAsset';
+        }
+
+        event.preventDefault();        
+        $.ajax({
+            url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=assetManagement&option=' + thisOption,
+            type: $(this).attr("method"),
+            dataType: 'html',
+            data: new FormData(this),
+            processData: false,
+            contentType: false,
+            success: function (data, status)
+            {
+                var status = data.charAt(0);
+                var html = data.substring(1);
+
+                // If all is good add this asset to the top of the list for now
+                if (status == 0) {
+
+                    editFlag = false;
+                    
+                    if (currentFormAction == 'add') {
+// Need to fix this                        $('#assetsAssetsContainer').prepend(html);
+                        $('#assetsDialog').dialog('close');
+                    }
+                    if (currentFormAction == 'edit') {
+                        $('#facility_' + facilityHoverId).html(html);
+// ***                        $('#facility_' + facilityHoverId).html(html);
+                        $('#assetsDialog').dialog('close');
+                    }    
+                }
+
+                // if status....
+                
+            },
+            error: function (xhr, desc, err)
+            {
+                alert("Sorry, we were unable to talk to our systems at the moment. Please try again.");
+            }
+        });        
+    });
     
     function flashNotice(notice) {
         notice.fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);