From: Chuck Scott Date: Fri, 15 Dec 2017 20:14:56 +0000 (-0500) Subject: Started adding picklist type custom field. Currently commented out in plugin.ini... X-Git-Tag: v1.0.0^2~31 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=41cd70fa1844b0f259ac48349b4f82c8ccb6bb1d;p=WP-Plugins%2Fglm-member-db-customfields.git Started adding picklist type custom field. Currently commented out in plugin.ini file. 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. --- diff --git a/config/plugin.ini b/config/plugin.ini index faf7203..b4f66f4 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -12,5 +12,6 @@ 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' diff --git a/index.php b/index.php index 8b0d88e..ae3b290 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * 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'); diff --git a/setup/databaseScripts/create_database_V1.0.1.sql b/setup/databaseScripts/create_database_V1.0.1.sql deleted file mode 100644 index 765f2a0..0000000 --- a/setup/databaseScripts/create_database_V1.0.1.sql +++ /dev/null @@ -1,42 +0,0 @@ --- 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) -); diff --git a/setup/databaseScripts/create_database_V1.0.2.sql b/setup/databaseScripts/create_database_V1.0.2.sql new file mode 100644 index 0000000..c8c92c0 --- /dev/null +++ b/setup/databaseScripts/create_database_V1.0.2.sql @@ -0,0 +1,56 @@ +-- 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) +); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index aa2c14e..510cfbb 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -15,6 +15,7 @@ $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') ); diff --git a/setup/databaseScripts/update_database_V1.0.1.sql b/setup/databaseScripts/update_database_V1.0.1.sql index fecd86a..914a41b 100644 --- a/setup/databaseScripts/update_database_V1.0.1.sql +++ b/setup/databaseScripts/update_database_V1.0.1.sql @@ -1,6 +1,6 @@ --- 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, diff --git a/setup/databaseScripts/update_database_V1.0.2.sql b/setup/databaseScripts/update_database_V1.0.2.sql new file mode 100644 index 0000000..92af6f5 --- /dev/null +++ b/setup/databaseScripts/update_database_V1.0.2.sql @@ -0,0 +1,19 @@ +-- 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) +); + diff --git a/views/admin/ajax/newField.html b/views/admin/ajax/newField.html index 872931d..13dfedc 100644 --- a/views/admin/ajax/newField.html +++ b/views/admin/ajax/newField.html @@ -1,12 +1,15 @@ {* A single line for the custom fields edit table *} - {$fieldData.field_name} + {$fieldData.field_name} {$fieldData.field_type_descr} {$fieldData.required.name}
Delete
+ {if $fieldData.field_type=='picklist'} +
Add Option
+ {/if} - Prompt: {$fieldData.field_prompt} \ No newline at end of file + Prompt: {$fieldData.field_prompt} \ No newline at end of file diff --git a/views/admin/customFields/index.html b/views/admin/customFields/index.html index cf5d703..0589337 100644 --- a/views/admin/customFields/index.html +++ b/views/admin/customFields/index.html @@ -5,7 +5,9 @@ - + @@ -23,7 +25,7 @@ - +
Field Name: + (for reference - keep short) +
User Prompt:
Required?Required:
@@ -42,12 +44,12 @@ -{* Edit field dialog box *} +{* Edit field dialog box -- NOT IMPLEMENTED YET *}
- + @@ -65,7 +67,7 @@ - +
Field Name:
User Prompt:
Required?Required:
@@ -74,6 +76,32 @@
+{* New Picklist Option form *} +
+ + + + + + + + + + + + + + + + + +
Option Name (for reference):
Displayed Text:
Selected by Dedault
Cost:$
+

* Required

+
Cancel
+
Add new Picklist Option
+ +
+ {* Fields Table *} @@ -100,9 +128,12 @@
Delete
+ {if $t.field_type=='picklist'} +
Add Option
+ {/if} - + {/foreach} {/if} @@ -126,10 +157,10 @@ jQuery(document).ready(function($) { // 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() { @@ -261,6 +292,76 @@ jQuery(document).ready(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) {
Prompt: {$t.field_prompt}
Prompt: {$t.field_prompt}