Updated database to add custom_field_options table for picklist fields.
Added button to form edit output for picklist fields to add options.
Created add option dialog box. - Not submitting yet.
custom_field_type['text'] = 'Single Line Text Field'
custom_field_type['textarea'] = 'Multi-Line Text Area'
custom_field_type['checkbox'] = 'Checkbox'
+; custom_field_type['picklist'] = 'Picklist of Options'
; custom_field_type['integer'] = 'Integer Number'
; custom_field_type['float'] = 'Floating Point number'
* version from this plugin.
*/
define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_VERSION', '1.0.0');
-define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_VERSION', '1.0.1');
+define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_VERSION', '1.0.2');
// This is the minimum version of the GLM Members DB plugin require for this plugin.
define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0');
+++ /dev/null
--- Gaslight Media Members Database - Fields Add-On
--- File Created: 2017-03-27
--- Database Version: 1.0.0
--- Database Creation Script
---
--- This file is called to create a new set of tables for this
--- add-on for the most recent database version for this add-on.
---
--- There should only be one such file in this directory
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
-
-
--- Field Setup Table
-CREATE TABLE {prefix}custom_fields (
- id INT NOT NULL AUTO_INCREMENT,
- fid TEXT NOT NULL DEFAULT '', -- Unique ID for this form (group of these fields)
- field_name TINYTEXT NOT NULL DEFAULT '', -- Field reference name
- field_prompt TINYTEXT NOT NULL DEFAULT '', -- Prompt to display on form to user
- field_type TINYTEXT NOT NULL DEFAULT '', -- Field Type
- field_order SMALLINT NOT NULL DEFAULT 0, -- Order for Field
- required BOOLEAN NOT NULL DEFAULT '0', -- If the field is required.
- PRIMARY KEY (id),
- INDEX (field_name(40))
-);
-
-----
-
--- Data Table
-CREATE TABLE {prefix}custom_field_data (
- id INT NOT NULL AUTO_INCREMENT,
- field_id INT NOT NULL DEFAULT 0, -- Pointer to ID of custom_fields table for this field
- record_id INT NOT NULL DEFAULT 0, -- id for this submission of this form
- text_data TEXT NOT NULL DEFAULT '', -- Data for a text field
- checkbox_data BOOLEAN NOT NULL DEFAULT false, -- Data for a boolean field
- integer_data INTEGER NOT NULL DEFAULT 0, -- Data for an integer field
- float_data FLOAT NOT NULL DEFAULT '0.00', -- Data for a float field
- PRIMARY KEY (id),
- INDEX (field_id),
- INDEX (record_id)
-);
--- /dev/null
+-- Gaslight Media Members Database - Custom Fields Add-On
+-- File Created: 2017-03-27
+-- Database Version: 1.0.2
+-- Database Creation Script
+--
+-- This file is called to create a new set of tables for this
+-- add-on for the most recent database version for this add-on.
+--
+-- There should only be one such file in this directory
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+
+-- Field Setup Table
+CREATE TABLE {prefix}custom_fields (
+ id INT NOT NULL AUTO_INCREMENT,
+ fid TEXT NOT NULL DEFAULT '', -- Unique ID for this form (group of these fields)
+ field_name TINYTEXT NOT NULL DEFAULT '', -- Field reference name
+ field_prompt TINYTEXT NOT NULL DEFAULT '', -- Prompt to display on form to user
+ field_type TINYTEXT NOT NULL DEFAULT '', -- Field Type
+ field_order SMALLINT NOT NULL DEFAULT 0, -- Order for Field
+ required BOOLEAN NOT NULL DEFAULT '0', -- If the field is required.
+ PRIMARY KEY (id),
+ INDEX (field_name(40))
+);
+
+----
+
+-- Data Table
+CREATE TABLE {prefix}custom_field_data (
+ id INT NOT NULL AUTO_INCREMENT,
+ field_id INT NOT NULL DEFAULT 0, -- Pointer to ID of field in custom_fields table
+ record_id INT NOT NULL DEFAULT 0, -- id for this submission of this form
+ text_data TEXT NOT NULL DEFAULT '', -- Data for a text field
+ checkbox_data BOOLEAN NOT NULL DEFAULT false, -- Data for a boolean field
+ integer_data INTEGER NOT NULL DEFAULT 0, -- Data for an integer field
+ float_data FLOAT NOT NULL DEFAULT '0.00', -- Data for a float field
+ PRIMARY KEY (id),
+ INDEX (field_id),
+ INDEX (record_id)
+);
+
+----
+
+-- Picklist Field Options
+CREATE TABLE {prefix}custom_field_options (
+ id INT NOT NULL AUTO_INCREMENT,
+ field_id INT NOT NULL DEFAULT 0, -- Pointer to ID of fields in custom_fields table
+ option_text TINYTEXT NOT NULL DEFAULT '', -- Option's Displayed text
+ option_value TINYTEXT NOT NULL DEFAULT '', -- Option's value
+ option_cost FLOAT NOT NULL DEFAULT '0.00', -- A cost added when this option is selected
+ option_default BOOLEAN NOT NULL DEFAULT false, -- Flag indicating that this option is the default
+ PRIMARY KEY (id),
+ INDEX (field_id)
+);
$glmMembersCustomFieldsDbVersions = array(
'1.0.0' => array('version' => '1.0.0', 'tables' => 2, 'date' => '12/01/2017'),
- '1.0.1' => array('version' => '1.0.1', 'tables' => 2, 'date' => '12/05/2017')
+ '1.0.1' => array('version' => '1.0.1', 'tables' => 2, 'date' => '12/05/2017'),
+ '1.0.2' => array('version' => '1.0.2', 'tables' => 3, 'date' => '12/15/2017')
);
--- Gaslight Media Members Database - Registratiuons Add-On
+-- Gaslight Media Members Database - Custom Fields Add-On
-- File Created: 08/30/16 09:47:15
--- Database Version: 0.0.7
+-- Database Version: 1.0.1
-- Database Update From Previous Version Script
--
-- To permit each query below to be executed separately,
--- /dev/null
+-- Gaslight Media Members Database - Custom Fields Add-On
+-- File Created: 08/30/16 09:47:15
+-- Database Version: 1.0.2
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+CREATE TABLE {prefix}custom_field_options (
+ id INT NOT NULL AUTO_INCREMENT,
+ field_id INT NOT NULL DEFAULT 0,
+ option_text TINYTEXT NOT NULL DEFAULT '',
+ option_value TINYTEXT NOT NULL DEFAULT '',
+ option_cost FLOAT NOT NULL DEFAULT '0.00',
+ option_default BOOLEAN NOT NULL DEFAULT false,
+ PRIMARY KEY (id),
+ INDEX (field_id)
+);
+
{* A single line for the custom fields edit table *}
<tr class="FieldRow_{$fieldData.id}">
- <td>{$fieldData.field_name}</td>
+ <td style="font-weight: bold; text-align: left;">{$fieldData.field_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>
-->
<div class="{$fieldData.fid}_DeleteFieldButton button button-secondary glm-button-small" data-fieldID="{$fieldData.id}">Delete</div>
+ {if $fieldData.field_type=='picklist'}
+ <div class="AddOptionButton button button-secondary glm-button-small" data-fieldId="{$fieldData.id}">Add Option</div>
+ {/if}
</td>
</tr>
- <tr class="FieldRow_{$fieldData.id}"><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">Prompt: {$fieldData.field_prompt}</td></tr>
\ No newline at end of file
<table class="glm-admin-table" style="width: 100%">
<tr>
<th class="glm-required">Field Name:</th>
- <td><input id="{$fid}_NewFieldName" type="text" name="field_name" class="glm-form-text-input-small"></td>
+ <td>
+ <input id="{$fid}_NewFieldName" type="text" name="field_name" class="glm-form-text-input-short"> (for reference - keep short)
+ </td>
</tr>
<tr>
<th class="glm-required" style="width: 20%; white-space: nowrap;">User Prompt:</th>
</td>
</tr>
<tr>
- <th style="width: 20%; white-space: nowrap;">Required?</th>
+ <th style="width: 20%; white-space: nowrap;">Required:</th>
<td><input id="{$fid}_NewFieldRequired" type="checkbox" name="required"></td>
</tr>
</table>
</center>
</div>
-{* Edit field dialog box *}
+{* Edit field dialog box -- NOT IMPLEMENTED YET *}
<div id="{$fid}_editFieldDialog" class="glm-dialog-box" title="Edit this Field">
<table class="glm-admin-table" style="width: 100%;">
<tr>
<th class="glm-required" style="width: 20%; white-space: nowrap;">Field Name:</th>
- <td><input id="{$fid}_editFieldName" type="text" name="field_name" class="glm-form-text-input"></td>
+ <td><input id="{$fid}_editFieldName" type="text" name="field_name" class="glm-form-text-input-short"></td>
</tr>
<tr>
<th class="glm-required" style="width: 20%; white-space: nowrap;">User Prompt:</th>
</td>
</tr>
<tr>
- <th>Required?</th>
+ <th>Required:</th>
<td><input type="checkbox" id="{$fid}_editRequired" name="required" value="1" /></td>
</tr>
</table>
<input type="submit" value="Update this Field">
</div>
+{* New Picklist Option form *}
+<div id="{$fid}_NewOptionDialog" class="glm-dialog-box" style="width: 100%" title="Add a New Option">
+ <table class="glm-admin-table" style="width: 100%">
+ <tr>
+ <th class="glm-required" style="width: 20%; white-space: nowrap;">Option Name (for reference):</th>
+ <td><input id="{$fid}_NewOptionName" type="text" name="option_value" class="glm-form-text-input-short"></td>
+ </tr>
+ <tr>
+ <th class="glm-required">Displayed Text:</th>
+ <td><input id="{$fid}_NewOptionText" type="text" name="option_text" class="glm-form-text-input"></td>
+ </tr>
+ <tr>
+ <th style="width: 20%; white-space: nowrap;">Selected by Dedault</th>
+ <td><input id="{$fid}_NewOptionDefault]" type="checkbox" name="option_default"></td>
+ </tr>
+ <tr>
+ <th>Cost:</th>
+ <td>$<input id="{$fid}_NewOptionCost" type="text" name="option_cost" class="glm-form-text-input-veryshort"></td>
+ </tr>
+ </table>
+ <p><span class="glm-required">*</span> Required</p>
+ <div id="{$fid}_NewOptionCancel" class="button button-primary glm-right">Cancel</div>
+ <div id="{$fid}_NewOptionSubmit" class="button button-primary" data-fieldId="">Add new Picklist Option</div>
+ <div id="{$fid}_NewOptionDialogError" class="glm-error" style="display: none;"><p>Unable to create picklist option. Did you supply all required information?</p></div>
+</div>
+
{* Fields Table *}
<table class="" style="width: 100%; background-color: #fff; border: 1px solid black; l">
<tr style="background-color: #ddd;">
<!-- <div class="{$fid}_EditFieldButton button button-secondary glm-button-small" data-fieldId="{$t.id}" data-fieldName="{$t.field_name|escape:'html'}" data-fieldPrompt="{$t.field_prompt|escape:'html'}" data-fieldType="{$t.field_type.name|escape:'html'}" data-required="{$t.required.value}">Edit</div>
-->
<div class="{$fid}_DeleteFieldButton button button-secondary glm-button-small" data-fieldId="{$t.id}">Delete</div>
+ {if $t.field_type=='picklist'}
+ <div id="{$fid}-add-option-button" class="button button-secondary glm-button-small" data-fieldId="{$t.id}">Add Option</div>
+ {/if}
</td>
</tr>
- <tr class="FieldRow_{$t.id}"><td style="border-bottom: 1px solid black;" colspan="4" style="padding-left: 2rem;">Prompt: {$t.field_prompt}</td></tr>
+ <tr class="FieldRow_{$t.id}"><td style="border-bottom: 1px solid black;" colspan="4"">Prompt: {$t.field_prompt}</td></tr>
{/foreach}
{/if}
</tbody>
// Display form and reset all input
$('#{$fid}_newFieldButton').click( function() {
$("#{$fid}_NewFieldDialog").dialog("open");
- $('#{$fid}_NewFieldName').val(''),
- $('#{$fid}_NewFieldPrompt').val(''),
- $('#{$fid}_NewFieldType').prop('selectedIndex',0),
- $('#{$fid}_NewFieldRequired').removeAttr('checked')
+ $('#{$fid}_NewFieldName').val('');
+ $('#{$fid}_NewFieldPrompt').val('');
+ $('#{$fid}_NewFieldType').prop('selectedIndex',0);
+ $('#{$fid}_NewFieldRequired').removeAttr('checked');
});
// Submit form
$('#{$fid}_NewFieldSubmit').click( function() {
$("#{$fid}_DeleteFieldDialog").dialog("close");
});
+ /*
+ * New Picklist Option dialog box
+ */
+ // Setup
+ $("#{$fid}_NewOptionDialog").dialog({
+ autoOpen: false,
+ minWidth: 600,
+ dialogClass: "glm-dialog-no-close"
+ });
+ // Display form and reset all input
+ $('#{$fid}-add-option-button').click( function() {
+ var fieldId = $(this).attr('data-fieldId');
+alert(fieldId);
+ $("#{$fid}_NewOptionDialog").dialog("open");
+ $('#{$fid}_NewOptionName').val('');
+ $('#{$fid}_NewOptionText').val('');
+ $('#{$fid}_NewOptionDefault').removeAttr('checked');
+ $('#{$fid}_NewOptionCost').val('');
+
+ $('#{$fid}_NewOptionSubmit').data('data-fieldId', $(this).attr('data-fieldId'));
+ });
+ // Submit form
+ $('#{$fid}_NewOptionSubmit').click( function() {
+console.log($(this).attr('data-fieldId'));
+ // Collect the new field data
+ var formData = {
+ 'action': 'glm_members_admin_ajax',
+ 'glm_action': 'customFields',
+ 'option': 'addNewPicklistOption',
+ 'field_id': $(this).attr('data-fieldId'),
+ 'field_name': $('#{$fid}_NewFieldName').val(),
+ 'field_prompt': $('#{$fid}_NewFieldPrompt').val(),
+ 'field_type': $('#{$fid}_NewFieldType').val(),
+ 'required': $('#{$fid}_NewFieldRequired').is(':checked')
+ };
+alert(formData.field_id);
+return;
+ // Submit new field data - expect field new ID back
+ $.ajax({
+ type: 'POST',
+ url: '{$ajaxUrl}',
+ data: formData,
+ encode: true,
+ dataType: 'text'
+ })
+ .done( function(fieldHtml) {
+ if (fieldHtml == '') {
+ flashElement('{$fid}_NewFieldDialogError');
+ } else {
+
+ $('#{$fid}_FieldsListBody').append(fieldHtml);
+ $("#{$fid}_NewFieldDialog").dialog("close");
+
+ // Need to rebind edit field buttons
+ $('body').off('click', '.{$fid}_EditFieldButton', {$fid}_editFieldButton);
+ $('body').on('click', '.{$fid}_EditFieldButton', {$fid}_editFieldButton);
+
+ // Need to rebind delete field buttons
+ $('body').off('click', '.{$fid}_DeleteFieldButton', {$fid}_deleteFieldButton);
+ $('body').on('click', '.{$fid}_DeleteFieldButton', {$fid}_deleteFieldButton);
+ }
+ });
+
+ });
+ // Cancel
+ $('#{$fid}_NewOptionCancel').click( function() {
+ $("#{$fid}_NewOptionDialog").dialog("close");
+ });
+
+
// Flash an element for a short time
function flashElement(id) {