From c362fe1936904bcb0872d7b32fe6b0b4d4effef3 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 22 Dec 2017 14:40:21 -0500 Subject: [PATCH] Reworked custom fields editing output due to standards violations. Added Edit and other features. Now will not permit changing from or to picklist type when editing a field. --- models/admin/ajax/customFields.php | 31 +- models/admin/customFields/index.php | 4 +- views/admin/ajax/newField.html | 57 ++-- views/admin/ajax/newFieldOption.html | 5 +- views/admin/customFields/index.html | 462 ++++++++++++++------------- 5 files changed, 312 insertions(+), 247 deletions(-) diff --git a/models/admin/ajax/customFields.php b/models/admin/ajax/customFields.php index 9e7a50b..2049723 100644 --- a/models/admin/ajax/customFields.php +++ b/models/admin/ajax/customFields.php @@ -80,7 +80,7 @@ class GlmMembersAdmin_ajax_customFields extends GlmDataFieldsCustomFields trigger_error(print_r($_REQUEST,1),E_USER_NOTICE); switch($_REQUEST['option']) { - + case 'addNewField': $customField = $this->insertEntry(); @@ -91,6 +91,7 @@ class GlmMembersAdmin_ajax_customFields extends GlmDataFieldsCustomFields // Add description for the selected field type $customField['fieldData']['field_type_descr'] = $this->config['custom_field_type'][$customField['fieldData']['field_type']]; +trigger_error('**** 11111 *****'.print_r($res,1),E_USER_NOTICE); // Produce HTML for the new field $viewFile = 'admin/ajax/newField.html'; @@ -100,6 +101,30 @@ class GlmMembersAdmin_ajax_customFields extends GlmDataFieldsCustomFields break; + case 'updateField': + + $fieldId = ($_REQUEST['fieldId'] -0); + if ($fieldId > 0) { + $res = $this->updateEntry($fieldId); + + if ($res) { + +trigger_error('**** 22222 *****'.$_REQUEST['fieldId'].":".print_r($res,1),E_USER_NOTICE); + + $customField = $this->editEntry($fieldId); +trigger_error('**** 33333 *****'.$_REQUEST['fieldId']." - ".print_r($customField,1),E_USER_NOTICE); + + // Produce HTML for the new field + $viewFile = 'admin/ajax/newField.html'; + $newFieldHtml = $this->generateHTML($customField, $viewFile); + echo $newFieldHtml; + + } + + } + + break; + case 'deleteField': $fieldId = false; @@ -114,7 +139,7 @@ class GlmMembersAdmin_ajax_customFields extends GlmDataFieldsCustomFields // Delete this custom field $this->deleteEntry($fieldId, true); - + // Delete any field options $this->wpdb->query( $this->wpdb->prepare( @@ -125,7 +150,7 @@ class GlmMembersAdmin_ajax_customFields extends GlmDataFieldsCustomFields $fieldId ) ); - + echo true; break; diff --git a/models/admin/customFields/index.php b/models/admin/customFields/index.php index 34a569f..c0af6bb 100644 --- a/models/admin/customFields/index.php +++ b/models/admin/customFields/index.php @@ -194,8 +194,8 @@ class GlmMembersAdmin_customFields_index extends GlmDataFieldsCustomFields if ( isset($custom_fields) && $custom_fields && count( $custom_fields ) > 0 ) { $haveCustomFields = true; } - - + + // Compile template data $template_data = array( 'option2' => $option, diff --git a/views/admin/ajax/newField.html b/views/admin/ajax/newField.html index 0dace59..f7e12d3 100644 --- a/views/admin/ajax/newField.html +++ b/views/admin/ajax/newField.html @@ -1,25 +1,42 @@ {* A single line for the custom fields edit table *} + - {$fieldData.field_name} - {$fieldData.field_type_descr} - {$fieldData.required.name} - - -
Delete
- {if $fieldData.field_type=='picklist'} -
Add Option
- {/if} + {$fieldData.field_name} + {$fieldData.field_type_descr} + {$fieldData.priority_display.name} + {$fieldData.required.name} + +
Delete
+
Edit
- Prompt: {$fieldData.field_prompt} - {if $fieldData.field_type=='picklist'} - - Option Value - Option Text - Cost - Default -   + + Prompt: {$fieldData.field_prompt} + + {if $t.field_type=='picklist'} + + + + + + + + + + +
Option NameOption TextCostDefault +
Add Option
+
+ - {/if} -   \ No newline at end of file + {/if} +   + + diff --git a/views/admin/ajax/newFieldOption.html b/views/admin/ajax/newFieldOption.html index 371b9da..f1618da 100644 --- a/views/admin/ajax/newFieldOption.html +++ b/views/admin/ajax/newFieldOption.html @@ -1,12 +1,13 @@ {* A line describing the new picklist option. *} "> - {$fieldData.option_value} + {$fieldData.option_value} {$fieldData.option_text} ${$fieldData.option_cost} {$fieldData.option_default.name} - +
Delete
+
Edit
diff --git a/views/admin/customFields/index.html b/views/admin/customFields/index.html index cc1d6d4..6a4532f 100644 --- a/views/admin/customFields/index.html +++ b/views/admin/customFields/index.html @@ -1,23 +1,23 @@ -{* New field form *} -
+{* New/Edit field form *} +
- + - +
Field Name: - +
(for reference - keep short)
User Prompt:
Field Type: - {foreach $fieldTypes as $type} @@ -28,202 +28,204 @@
Important Field: - + Display when limited output is selected.
Required:

* Required

-
Cancel
-
Add new Custom Field
- +
Cancel
+
(name supplied by code below)
+
{* Delete field button confirmation dialog box *} -
+

Are you sure you want to delete this field?

-

Yes, delete this field

-

Cancel

+

Yes, delete this field

+

Cancel

-{* Edit field dialog box -- NOT IMPLEMENTED YET *} -
- - - - - - - - - - - - - - - - - - - - - -
Field Name:
User Prompt:
Field Type: - -
Priority:
Required:
-

* Required

- Cancel - -
- {* New Picklist Option form *} -
+
- + - + - +
Option Name: - +
(For reference - keep short)
Displayed Text:
Selected by Dedault
Cost:$$

* Required

-
Cancel
-
Add new Picklist Option
- +
Cancel
+
Add new Picklist Option
+
{* Fields Table *} - +
+ + - + {if $haveCustomFields} {foreach $custom_fields as $t} + - - - - + + + + - - {if $t.field_type=='picklist'} - - - - - - + + - {if $t.options} - {foreach $t.options as $option} - - - - - - + - {/foreach} - {/if} - {/if} - + {/if} + + {/foreach} {/if} -
Field Name TypePriority Required -
Add a Custom Field
+
Add a Custom Field
 
{$t.field_name} - {$t.field_type_descr} - - {$t.required.name} - - -
Delete
- {if $t.field_type=='picklist'} -
Add Option
- {/if} +
{$t.field_name}{$t.field_type_descr}{$t.priority_display.name}{$t.required.name} +
Delete
+
Edit
Prompt: {$t.field_prompt}
Option NameOption TextCostDefault 
Prompt: {$t.field_prompt}
{$option.option_value}{$option.option_text}{$option.option_cost}{$option.option_default.name} -
Delete
+ {if $t.field_type=='picklist'} +
+ + + + + + + + + {if $t.options} + {foreach $t.options as $option} + + + + + + + + {/foreach} + {/if} +
Option NameOption TextCostDefault +
Add Option
+
{$option.option_value}{$option.option_text}${$option.option_cost|number_format:2}{$option.option_default.name} +
Delete
+
Edit
+