Additional documentation and minor problem fixes.
authorChuck Scott <cscott@gaslightmedia.com>
Wed, 13 Dec 2017 13:54:21 +0000 (08:54 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Wed, 13 Dec 2017 13:54:21 +0000 (08:54 -0500)
classes/data/dataCustomFields.php
config/plugin.ini
models/admin/ajax/customFields.php
models/admin/customFields/index.php
setup/commonHooks.php
views/admin/ajax/newField.html
views/admin/customFields/index.html

index af8c507..f106a69 100644 (file)
@@ -149,8 +149,7 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
             // Field Type
             'field_type' => array(
                 'field'    => 'field_type',
-                'type'     => 'list',
-                'list'     => $this->config['custom_field_types'],
+                'type'     => 'text',
                 'required' => true,
                 'use'      => 'a'
             ),
@@ -190,6 +189,10 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract
      */
     public function entryPostProcessing($r, $a)
     {
+
+        // Get field type description from ini file.
+        $r['field_type_descr'] = $this->config['custom_field_type'][$r['field_type']];
+
         return $r;
     }
 
index 77b9ef0..faf7203 100644 (file)
@@ -4,3 +4,13 @@
 ;
 ; Place any static configuration parameters here.
 ;
+
+
+;
+; Custom Field Types
+;
+custom_field_type['text']           = 'Single Line Text Field'
+custom_field_type['textarea']       = 'Multi-Line Text Area'
+custom_field_type['checkbox']       = 'Checkbox'
+; custom_field_type['integer']        = 'Integer Number'
+; custom_field_type['float']          = 'Floating Point number'
index e5279b0..3ed14b3 100644 (file)
@@ -102,6 +102,11 @@ class GlmMembersAdmin_ajax_customFields extends GlmDataFieldsCustomFields
                 if (!is_array($customField) || !$customField['status']) {
                     echo "0";
                 } else {
+
+                    // Add description for the selected field type
+                    $customField['fieldData']['field_type_descr'] = $this->config['custom_field_type'][$customField['fieldData']['field_type']];
+
+                    // Produce HTML for the new field
                     $viewFile = 'admin/ajax/newField.html';
                     $newFieldHtml = $this->generateHTML($customField, $viewFile);
                     echo $newFieldHtml;
index 926abbd..3985ba0 100644 (file)
@@ -181,10 +181,15 @@ class GlmMembersAdmin_customFields_index extends GlmDataFieldsCustomFields
 
         }
 
-        $where .= " AND fid = '$fid' ";
+        // Build custom field types array for building picklist
+        $fieldTypes = array();
+        foreach ($this->config['custom_field_type'] as $typeKey=>$typeVal) {
+            $fieldTypes[$typeKey] = array('type_name' => $typeKey, 'prompt' => $typeVal);
+        }
 
         // Get list of Custom Fields
-        $custom_fields = $this->getList( $where );
+        $where .= " AND fid = '$fid' ";
+        $custom_fields = $this->getList( $where, false, true);
 
         if ( isset($custom_fields) && $custom_fields && count( $custom_fields ) > 0 ) {
             $haveCustomFields = true;
@@ -196,7 +201,7 @@ class GlmMembersAdmin_customFields_index extends GlmDataFieldsCustomFields
             'settingsUpdated'     => $settings_updated,
             'settingsUpdateError' => $settings_update_error,
             'custom_fields'       => $custom_fields,
-            'field_types'         => $this->config['custom_field_types'],
+            'fieldTypes'          => $fieldTypes,
             'haveCustomFields'    => $haveCustomFields,
             'fid'                 => $fid,
             'glm_action'          => $glm_action
index 518c422..72ce77a 100644 (file)
@@ -65,12 +65,13 @@ add_filter( 'glm-members-customfields-have-fields', function( $haveFields, $fid)
 /**
  * Return HTML for a custom fields form segment
  *
- * @param $content string Any supplied content. Form will be appended to this
- * @param $fid string Unique ID of form
- * @param $recordId integer Optional ID for instance of this form (generally the ID of the associated record)
- *                  If this is 0 then it's assumed this is a new form with no existing data.
- * @param $submitId string Optional ID of the submit button for the form this will be part of.
- * @param $formData array Optional array of data used to populate form (Not sure we're going to keep this)
+ * @param $content      string  Any supplied content. Form will be appended to this
+ * @param $fid          string  Unique ID of form
+ * @param $recordId     integer Optional ID for instance of this form (generally the ID of the associated record)
+ *                                  If this is 0 then it's assumed this is a new form with no existing data.
+ * @param $parentFormId string  Optional ID of the submit button for the form that will have these custom fields added.
+ *                                  This is used to block submit (if possible) for that form while there's still required custom fields.
+ * @param $formData     array   Optional array of data used to populate form (Not sure we're going to keep this)
  *
  * returns an array with status and HTML for editing the form.
  */
index 39429fd..872931d 100644 (file)
@@ -1,7 +1,7 @@
 {* A single line for the custom fields edit table *}
-        <tr id="FieldRow_{$fieldData.id}">
+        <tr class="FieldRow_{$fieldData.id}">
             <td>{$fieldData.field_name}</td>
-            <td id="editFieldType_{$fieldData.id}">{$fieldData.field_type.name}</td>
+            <td id="editFieldType_{$fieldData.id}">{$fieldData.field_type_descr}</td>
             <td>{$fieldData.required.name}</td>
             <td>
 <!--                 <div class="glmCustomFieldsEditFieldButton  button button-secondary glm-button-small" data-fieldID="{$fieldData.id}" data-fieldName="{$fieldData.field_name|escape:'html'}" data-fieldPrompt="{$fieldData.field_prompt|escape:'html'}" data-fieldType="{$fieldData.field_type.name|escape:'html'}" data-adminSearch="{$fieldData.admin_search.value}" data-required="{$fieldData.required.value}">Edit</div>
@@ -9,4 +9,4 @@
                 <div class="{$fieldData.fid}_DeleteFieldButton button button-secondary glm-button-small" data-fieldID="{$fieldData.id}">Delete</div>
             </td>
         </tr>
-        <tr><td colspan="4" style="padding-left: 2rem;">Prompt: {$fieldData.field_prompt}</td></tr>
\ No newline at end of file
+        <tr class="FieldRow_{$fieldData.id}"><td colspan="4" style="padding-left: 2rem;">Prompt: {$fieldData.field_prompt}</td></tr>
\ No newline at end of file
index 46192d6..79f2118 100644 (file)
             <td>
                 <select id="{$fid}_NewFieldType" name="field_type">
                     <option value=""></option>
-                    <option value="text">Single Line Text Field</option>
-                    <option value="textarea">Multi-line Text Area</option>
-                    <option value="checkbox">Checkbox</option>
-<!-- 
-                    <option value="integer">Integer Field</option>
-                    <option value="float">Floating Point Number Field</option>
- -->                    
+  {foreach $fieldTypes as $type}
+                    <option value="{$type.type_name}">{$type.prompt}</option>
+  {/foreach}
                 </select>
             </td>
         </tr>
@@ -95,7 +91,7 @@
         <tr class="FieldRow_{$t.id}">
             <th style="font-weight: bold;">{$t.field_name}</th>
             <td id="editFieldType_{$t.id}">
-                {$t.field_type.name}
+                {$t.field_type_descr}
             </td>
             <td>
                 {$t.required.name}