summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxzilla2006-08-18 21:02:41 +0000
committerxzilla2006-08-18 21:02:41 +0000
commit10ff95e31a3889daf6665ecbb3edea38a934f2a1 (patch)
tree828e7f34284aada1526a6072437e4035e0c76400
parentf58a041d7617937ae1b89547c3a753f5735168e5 (diff)
Add automagic enable/disable of length attribute based on selected type in table creation / alter screens.
Patch from John Jawed for Google SoC, with some cleanup and modifications from me.
-rwxr-xr-xclasses/database/Postgres.php5
-rw-r--r--tables.js18
-rw-r--r--tables.php28
-rw-r--r--tblproperties.php42
4 files changed, 74 insertions, 19 deletions
diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php
index 5599f706..c3fbc415 100755
--- a/classes/database/Postgres.php
+++ b/classes/database/Postgres.php
@@ -4,7 +4,7 @@
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.289 2006/08/13 15:31:13 xzilla Exp $
+ * $Id: Postgres.php,v 1.290 2006/08/18 21:02:41 xzilla Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -150,6 +150,9 @@ class Postgres extends ADODB_base {
// Help sub pages
var $help_page;
+
+ // Predefined size types
+ var $predefined_size_types = array('abstime','aclitem','bigserial','boolean','bytea','cid','cidr','circle','date','float4','float8','gtsvector','inet','int2','int4','int8','macaddr','money','oid','path','polygon','refcursor','regclass','regoper','regoperator','regproc','regprocedure','regtype','reltime','serial','smgr','text','tid','tinterval','tsquery','tsvector','varbit','void','xid');
/**
* Constructor
diff --git a/tables.js b/tables.js
new file mode 100644
index 00000000..a805a8b4
--- /dev/null
+++ b/tables.js
@@ -0,0 +1,18 @@
+var predefined_lengths = null;
+var sizesLength = false;
+
+function checkLengths(sValue,idx) {
+ if(predefined_lengths) {
+ if(sizesLength==false) {
+ sizesLength = predefined_lengths.length;
+ }
+ for(var i=0;i<sizesLength;i++) {
+ if(sValue.toString().toUpperCase()==predefined_lengths[i].toString().toUpperCase()) {
+ document.getElementById("lengths"+idx).value='';
+ document.getElementById("lengths"+idx).disabled='on';
+ return;
+ }
+ }
+ document.getElementById("lengths"+idx).disabled='';
+ }
+}
diff --git a/tables.php b/tables.php
index 866609a2..198880fb 100644
--- a/tables.php
+++ b/tables.php
@@ -3,7 +3,7 @@
/**
* List tables in a database
*
- * $Id: tables.php,v 1.81 2006/08/04 20:42:24 xzilla Exp $
+ * $Id: tables.php,v 1.82 2006/08/18 21:02:41 xzilla Exp $
*/
// Include application functions
@@ -98,11 +98,13 @@
}
$types = $data->getTypes(true, false, true);
-
+ $types_for_js = array();
+
$misc->printTrail('schema');
$misc->printTitle($lang['strcreatetable'], 'pg.table.create');
$misc->printMsg($msg);
+ echo "<script src=\"tables.js\" type=\"text/javascript\"></script>";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
// Output table header
@@ -121,9 +123,10 @@
echo "\t<tr>\n\t\t<td>", $i + 1, ".&nbsp;</td>\n";
echo "\t\t<td><input name=\"field[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_REQUEST['field'][$i]), "\" /></td>\n";
- echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\">\n";
+ echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\" id=\"types{$i}\" onchange=\"checkLengths(this.options[this.selectedIndex].value,{$i});\">\n";
// Output any "magic" types
foreach ($data->extraTypes as $v) {
+ $types_for_js[strtolower($v)] = 1;
echo "\t\t\t\t<option value=\"", htmlspecialchars($v), "\"",
(isset($_REQUEST['type'][$i]) && $v == $_REQUEST['type'][$i]) ? ' selected="selected"' : '', ">",
$misc->printVal($v), "</option>\n";
@@ -131,12 +134,21 @@
$types->moveFirst();
while (!$types->EOF) {
$typname = $types->f['typname'];
+ $types_for_js[$typname] = 1;
echo "\t\t\t\t<option value=\"", htmlspecialchars($typname), "\"",
(isset($_REQUEST['type'][$i]) && $typname == $_REQUEST['type'][$i]) ? ' selected="selected"' : '', ">",
$misc->printVal($typname), "</option>\n";
$types->moveNext();
}
- echo "\t\t\t</select>\n\t\t</td>\n";
+ echo "\t\t\t</select>\n\t\t\n";
+ if($i==0) { // only define js types array once
+ $predefined_size_types = array_intersect($data->predefined_size_types,array_keys($types_for_js));
+ $escaped_predef_types = array(); // the JS escaped array elements
+ foreach($predefined_size_types as $value) {
+ $escaped_predef_types[] = "'{$value}'";
+ }
+ echo "<script type=\"text/javascript\">predefined_lengths = new Array(". implode(",",$escaped_predef_types) .");</script>\n\t</td>";
+ }
// Output array type selector
echo "\t\t<td>\n\t\t\t<select name=\"array[{$i}]\">\n";
@@ -144,7 +156,7 @@
echo "\t\t\t\t<option value=\"[]\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
echo "\t\t\t</select>\n\t\t</td>\n";
- echo "\t\t<td><input name=\"length[{$i}]\" size=\"10\" value=\"",
+ echo "\t\t<td><input name=\"length[{$i}]\" id=\"lengths{$i}\" size=\"10\" value=\"",
htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>\n";
echo "\t\t<td><input type=\"checkbox\" name=\"notnull[{$i}]\"", (isset($_REQUEST['notnull'][$i])) ? ' checked="checked"' : '', " /></td>\n";
echo "\t\t<td align=\"center\"><input type=\"checkbox\" name=\"uniquekey[{$i}]\""
@@ -155,7 +167,9 @@
echo "\t\t<td><input name=\"default[{$i}]\" size=\"20\" value=\"",
htmlspecialchars($_REQUEST['default'][$i]), "\" /></td>\n";
echo "\t\t<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"",
- htmlspecialchars($_REQUEST['colcomment'][$i]), "\" /></td>\n\t</tr>\n";
+ htmlspecialchars($_REQUEST['colcomment'][$i]), "\" />
+ <script type=\"text/javascript\">checkLengths(document.getElementById('types{$i}').value,{$i});</script>
+ </td>\n\t</tr>\n";
}
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n";
@@ -445,7 +459,7 @@
}
echo "</p>\n";
echo "</form>\n";
- echo "<script>rEB(document.getElementById('no_ac').checked);</script>";
+ echo "<script type=\"text/javascript\">rEB(document.getElementById('no_ac').checked);</script>";
}
else {
if (!isset($_POST['values'])) $_POST['values'] = array();
diff --git a/tblproperties.php b/tblproperties.php
index b7e053f3..685f87cd 100644
--- a/tblproperties.php
+++ b/tblproperties.php
@@ -3,7 +3,7 @@
/**
* List tables in a database
*
- * $Id: tblproperties.php,v 1.71 2006/08/03 19:03:32 xzilla Exp $
+ * $Id: tblproperties.php,v 1.72 2006/08/18 21:02:41 xzilla Exp $
*/
// Include application functions
@@ -241,11 +241,12 @@
// Fetch all available types
$types = $data->getTypes(true, false, true);
+ $types_for_js = array();
$misc->printTrail('table');
$misc->printTitle($lang['straddcolumn'], 'pg.column.add');
$misc->printMsg($msg);
-
+ echo "<script src=\"tables.js\" type=\"text/javascript\"></script>";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
// Output table header
@@ -257,10 +258,11 @@
echo "<tr><td><input name=\"field\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['field']), "\" /></td>";
- echo "<td><select name=\"type\">\n";
+ echo "<td><select name=\"type\" id=\"type\" onchange=\"checkLengths(document.getElementById('type').value,'');\">\n";
// Output any "magic" types. This came in with the alter column type so we'll check that
if ($data->hasAlterColumnType()) {
foreach ($data->extraTypes as $v) {
+ $types_for_js[strtolower($v)] = 1;
echo "<option value=\"", htmlspecialchars($v), "\"",
($v == $_POST['type']) ? ' selected="selected"' : '', ">",
$misc->printVal($v), "</option>\n";
@@ -268,6 +270,7 @@
}
while (!$types->EOF) {
$typname = $types->f['typname'];
+ $types_for_js[$typname] = 1;
echo "<option value=\"", htmlspecialchars($typname), "\"", ($typname == $_POST['type']) ? ' selected="selected"' : '', ">",
$misc->printVal($typname), "</option>\n";
$types->moveNext();
@@ -278,9 +281,15 @@
echo "<td><select name=\"array\">\n";
echo "<option value=\"\"", ($_POST['array'] == '') ? ' selected="selected"' : '', "></option>\n";
echo "<option value=\"[]\"", ($_POST['array'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
- echo "</select></td>\n";
+ echo "</select>";
+ $predefined_size_types = array_intersect($data->predefined_size_types,array_keys($types_for_js));
+ $escaped_predef_types = array(); // the JS escaped array elements
+ foreach($predefined_size_types as $value) {
+ $escaped_predef_types[] = "'{$value}'";
+ }
+ echo "\t</td>\n";
- echo "<td><input name=\"length\" size=\"8\" value=\"",
+ echo "<td><input name=\"length\" id=\"lengths\" size=\"8\" value=\"",
htmlspecialchars($_POST['length']), "\" /></td>";
// Support for adding column with not null and default
if ($data->hasAlterColumnType()) {
@@ -302,7 +311,7 @@
echo "<p><input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
-
+ echo "<script type=\"text/javascript\">predefined_lengths = new Array(". implode(",",$escaped_predef_types) .");checkLengths(document.getElementById('type').value,'');</script>\n";
break;
case 2:
global $data, $lang;
@@ -348,11 +357,12 @@
$misc->printTrail('column');
$misc->printTitle($lang['straltercolumn'], 'pg.column.alter');
$misc->printMsg($msg);
+ echo "<script src=\"tables.js\" type=\"text/javascript\"></script>";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
// Output table header
- echo "<table>\n<tr>";
+ echo "<table>\n";
echo "<tr><th class=\"data required\">{$lang['strname']}</th>";
if ($data->hasAlterColumnType()) {
echo "<th class=\"data required\" colspan=\"2\">{$lang['strtype']}</th>";
@@ -401,16 +411,19 @@
if ($data->hasAlterColumnType()) {
// Fetch all available types
$types = $data->getTypes(true, false, true);
+ $types_for_js = array();
- echo "<td><select name=\"type\">\n";
+ echo "<td><select name=\"type\" id=\"type\" onchange=\"checkLengths(document.getElementById('type').value,'');\">\n";
// Output any "magic" types. This came in with Alter Column Type so we don't need to check that
foreach ($data->extraTypes as $v) {
+ $types_for_js[strtolower($v)] = 1;
echo "<option value=\"", htmlspecialchars($v), "\"",
($v == $_REQUEST['type']) ? ' selected="selected"' : '', ">",
$misc->printVal($v), "</option>\n";
}
while (!$types->EOF) {
$typname = $types->f['typname'];
+ $types_for_js[$typname] = 1;
echo "<option value=\"", htmlspecialchars($typname), "\"", ($typname == $_REQUEST['type']) ? ' selected="selected"' : '', ">",
$misc->printVal($typname), "</option>\n";
$types->moveNext();
@@ -421,9 +434,15 @@
echo "<td><select name=\"array\">\n";
echo "<option value=\"\"", ($_REQUEST['array'] == '') ? ' selected="selected"' : '', "></option>\n";
echo "<option value=\"[]\"", ($_REQUEST['array'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
- echo "</select></td>\n";
-
- echo "<td><input name=\"length\" size=\"8\" value=\"",
+ echo "</select>";
+ $predefined_size_types = array_intersect($data->predefined_size_types,array_keys($types_for_js));
+ $escaped_predef_types = array(); // the JS escaped array elements
+ foreach($predefined_size_types as $value) {
+ $escaped_predef_types[] = "'{$value}'";
+ }
+ echo "\t</td>\n";
+
+ echo "<td><input name=\"length\" id=\"lengths\" size=\"8\" value=\"",
htmlspecialchars($_REQUEST['length']), "\" /></td>";
} else {
// Otherwise draw the read-only type name
@@ -454,6 +473,7 @@
echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
+ echo "<script type=\"text/javascript\">predefined_lengths = new Array(". implode(",",$escaped_predef_types) .");checkLengths(document.getElementById('type').value,'');</script>\n";
break;
case 2: