From b8022422f757ab0aad9bfab98b5356f25e6f98c2 Mon Sep 17 00:00:00 2001 From: lorilee Date: Tue, 20 Jul 2010 12:22:39 -0700 Subject: [PATCH] Updated enum/set editor (submit button has only one function, escapes special characters, has more instructions for formatting --- enum_editor.php | 39 ++++++++++++++------------- js/functions.js | 46 +++++++++++++++----------------- libraries/tbl_properties.inc.php | 7 ++--- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/enum_editor.php b/enum_editor.php index 4ab0d7f59..570d0499d 100644 --- a/enum_editor.php +++ b/enum_editor.php @@ -10,50 +10,51 @@ require_once './libraries/header_meta_style.inc.php';
-

Values for the column ""

-

Enter each value in a separate field.

+

+

'; - $stripped_values[] = $value; + echo sprintf('', htmlspecialchars($value)); + $stripped_values[] = htmlspecialchars($value); } } + + $total_fields = $field_counter; // If extra fields are added, display them - if($_GET['add_extra_fields']) { - $extra_fields = $_GET['extra_fields']; - $total_fields = $extra_fields + $field_counter; - for($i = ($field_counter+1); $i <= $total_fields; $i++) { + if(isset($_GET['extra_fields'])) { + $total_fields += $_GET['extra_fields']; + for($i = $field_counter+1; $i <= $total_fields; $i++) { echo ''; } - } else { - $total_fields = $field_counter; } + ?>

- Add more values + + + Restart insertion and add a new value +

- + - +

Output

Copy and paste the joined values into the "Length/Values" field

diff --git a/js/functions.js b/js/functions.js index cbfe0e38a..cd6af4138 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1786,9 +1786,11 @@ $(document).ready(function() { var values = $(this).parent().prev("input").attr("value").split(","); $.each(values, function(index, val) { if(jQuery.trim(val) != "") { + // escape the single quotes, except the mandatory ones enclosing the entire string + val = val.substr(1, val.length-2).replace(/'/g, "'"); + // escape the greater-than symbol + val = val.replace(/>/g, ">"); $("#enum_editor #values").append(""); - } else { - $("#enum_editor #values").append(""); } }); // So we know which column's data is being edited @@ -1806,30 +1808,26 @@ $(document).ready(function() { disable_popup(); }); - // When the submit button is clicked, put the data back into the original form if - // the "add x more values" checkbox is not checked. Otherwise, just insert x more - // textboxes - $("#enum_editor input[type='submit']").click(function() { - if($("input[type='checkbox'][name='add_extra_fields']").attr("checked")) { - for(i = 0; i < $("input[type='text'][name='extra_fields']").attr("value"); i++) { - $("#enum_editor #values").append(""); - } - // Uncheck it - $("input[type='checkbox'][name='add_extra_fields']").removeAttr("checked"); - } else { - var value_array = new Array(); - $.each($("#enum_editor #values input"), function(index, input_element) { - val = jQuery.trim(input_element.value); - if(val != "") { - value_array.push("'" + val + "'"); - } - }); - var values_id = $("#enum_editor input[type='hidden']").attr("value"); - $("input[id='" + values_id + "']").attr("value", value_array.join(",")); - disable_popup(); - } + // When "add a new value" is clicked, append an empty text field + $("a[class='add_value']").click(function() { + $("#enum_editor #values").append(""); }); + // When the submit button is clicked, put the data back into the original form + $("#enum_editor input[type='submit']").click(function() { + var value_array = new Array(); + $.each($("#enum_editor #values input"), function(index, input_element) { + val = jQuery.trim(input_element.value); + if(val != "") { + value_array.push("'" + val + "'"); + } + }); + // get the Length/Values text field where this value belongs + var values_id = $("#enum_editor input[type='hidden']").attr("value"); + $("input[id='" + values_id + "']").attr("value", value_array.join(",")); + disable_popup(); + }); + /** * Hides certain table structure actions, replacing them with the word "More". They are displayed * in a dropdown menu when the user hovers over the word "More." diff --git a/libraries/tbl_properties.inc.php b/libraries/tbl_properties.inc.php index e0a91546c..386324f5a 100644 --- a/libraries/tbl_properties.inc.php +++ b/libraries/tbl_properties.inc.php @@ -371,7 +371,7 @@ for ($i = 0; $i < $num_fields; $i++) { . ' class="textfield" />' . '

'; $content_cells[$i][$ci] .= __('ENUM or SET data too long?') - . ' ' + . ' ' . __('Get more editing space') . '

'; $ci++; @@ -797,9 +797,10 @@ if ($action == 'tbl_create.php') {
Close -

Enter each value in a separate field.

+

+

-

Add more values

+

+ Add a new value

Cancel