Improved js controls for null/not null fields and fixed js bugs with the MSIE autocomplete feature

This commit is contained in:
Loïc Chapeaux
2002-03-22 14:17:01 +00:00
parent 368d7bb618
commit 59a17524e8
3 changed files with 91 additions and 17 deletions

View File

@@ -135,6 +135,13 @@ var errorMsg2 = '<?php echo str_replace('\'', '\\\'', $strNotValidNumber); ?>'
</script> </script>
<script src="libraries/indexes.js" type="text/javascript" language="javascript"></script> <script src="libraries/indexes.js" type="text/javascript" language="javascript"></script>
<?php <?php
} else if (isset($js_to_run) && $js_to_run == 'tbl_change.js') {
echo "\n";
?>
//-->
</script>
<script src="libraries/tbl_change.js" type="text/javascript" language="javascript"></script>
<?php
} else { } else {
echo "\n"; echo "\n";
?> ?>

59
libraries/tbl_change.js Normal file
View File

@@ -0,0 +1,59 @@
/* $Id$ */
/**
* Modify from controls when the "NULL" checkbox is selected
*
* @param string the MySQL field type
* @param string the urlencoded field name
* @param string the md5 hashed field name
*
* @return boolean always true
*/
function nullify(theType, urlField, md5Field)
{
var rowForm = document.forms['insertForm'];
if (typeof(rowForm.elements['funcs[' + urlField + ']']) != 'undefined') {
rowForm.elements['funcs[' + urlField + ']'].selectedIndex = -1;
}
// "SET" field or "ENUM" field with more than 20 characters
if (theType == 1 || theType == 3) {
rowForm.elements['field_' + md5Field + '[]'].selectedIndex = -1;
}
// Other "ENUM" field
else if (theType == 2) {
var elts = rowForm.elements['field_' + md5Field + '[]'];
var elts_cnt = elts.length;
for (var i = 0; i < elts_cnt; i++ ) {
elts[i].checked = false;
} // end for
}
// Other field types
else /*if (theType == 4)*/ {
rowForm.elements['fields[' + urlField + ']'].value = '';
} // end if... else if... else
return true;
} // end of the 'nullify()' function
/**
* Unchecks the "NULL" control when a function has been selected or a value
* entered
*
* @param string the urlencoded field name
*
* @return boolean always true
*/
function unNullify(urlField)
{
var rowForm = document.forms['insertForm'];
if (typeof(rowForm.elements['fields_null[' + urlField + ']']) != 'undefined') {
rowForm.elements['fields_null[' + urlField + ']'].checked = false
} // end if
return true;
} // end of the 'unNullify()' function

View File

@@ -6,6 +6,7 @@
* Get the variables sent or posted to this script and displays the header * Get the variables sent or posted to this script and displays the header
*/ */
require('./libraries/grab_globals.lib.php3'); require('./libraries/grab_globals.lib.php3');
$js_to_run = 'tbl_change.js';
include('./header.inc.php3'); include('./header.inc.php3');
// Displays the query submitted and its result // Displays the query submitted and its result
if (!empty($message)) { if (!empty($message)) {
@@ -111,8 +112,12 @@ else
/** /**
* Displays the form * Displays the form
*/ */
// loic1: autocomplete feature of IE kills the "onchange" event handler and it
// Had to put the URI because when hosted on an https server, // must be replaced by the "onpropertychange" one in this case
$chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
? 'onpropertychange'
: 'onchange';
// Had to put the URI because when hosted on an https server,
// some browsers send wrongly this form to the http server. // some browsers send wrongly this form to the http server.
?> ?>
@@ -257,7 +262,7 @@ for ($i = 0; $i < $fields_cnt; $i++) {
} else { } else {
?> ?>
<td bgcolor="<?php echo $bgcolor; ?>"> <td bgcolor="<?php echo $bgcolor; ?>">
<select name="funcs[<?php echo urlencode($field); ?>]" tabindex="<?php echo ($i+2*$fields_cnt); ?>" > <select name="funcs[<?php echo urlencode($field); ?>]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i+2*$fields_cnt); ?>" >
<option></option> <option></option>
<?php <?php
echo "\n"; echo "\n";
@@ -265,9 +270,9 @@ for ($i = 0; $i < $fields_cnt; $i++) {
for ($j = 0; $j < count($cfgFunctions); $j++) { for ($j = 0; $j < count($cfgFunctions); $j++) {
// for default function = NOW() on first timestamp field // for default function = NOW() on first timestamp field
// -- swix/18jul01 // -- swix/18jul01
$selected = ($first_timestamp && $cfgFunctions[$j] == 'NOW') $selected = ($first_timestamp && $cfgFunctions[$j] == 'NOW')
? ' selected="selected"' ? ' selected="selected"'
: ''; : '';
echo ' '; echo ' ';
echo '<option' . $selected . '>' . $cfgFunctions[$j] . '</option>' . "\n"; echo '<option' . $selected . '>' . $cfgFunctions[$j] . '</option>' . "\n";
} // end for } // end for
@@ -286,20 +291,23 @@ for ($i = 0; $i < $fields_cnt; $i++) {
if ($row_table_def['Null'] == 'YES') { if ($row_table_def['Null'] == 'YES') {
echo ' <input type="checkbox" tabindex=' . ($i+3*$fields_cnt) . '"' echo ' <input type="checkbox" tabindex=' . ($i+3*$fields_cnt) . '"'
. ' name="fields_null[' . urlencode($field) . ']"'; . ' name="fields_null[' . urlencode($field) . ']"';
if ($data == 'NULL') { if ($data == 'NULL' && !$first_timestamp) {
echo ' checked="checked"'; echo ' checked="checked"';
} }
$onclick = ' onclick="if (this.checked) {nullify(';
if (strstr($row_table_def['True_Type'], 'enum')) { if (strstr($row_table_def['True_Type'], 'enum')) {
if (strlen($row_table_def['Type']) > 20) { if (strlen($row_table_def['Type']) > 20) {
echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\'].selectedIndex = -1}; return true" />' . "\n"; $onclick .= '1, ';
} else { } else {
echo ' onclick="if (this.checked) {var elts = document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\']; var elts_cnt = elts.length; for (var i = 0; i < elts_cnt; i++ ) {elts[i].checked = false}}; return true" />' . "\n"; $onclick .= '2, ';
} }
} else if (strstr($row_table_def['True_Type'], 'set')) { } else if (strstr($row_table_def['True_Type'], 'set')) {
echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'field_' . md5($field) . '[]\'].selectedIndex = -1}; return true" />' . "\n"; $onclick .= '3, ';
} else { } else {
echo ' onclick="if (this.checked) {document.forms[\'insertForm\'].elements[\'fields[' . urlencode($field) . ']\'].value = \'\'}; return true" />' . "\n"; $onclick .= '4, ';
} }
$onclick .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\'); this.checked = true}; return true" />' . "\n";
echo $onclick;
} else { } else {
echo ' &nbsp;' . "\n"; echo ' &nbsp;' . "\n";
} }
@@ -311,7 +319,7 @@ for ($i = 0; $i < $fields_cnt; $i++) {
?> ?>
<td bgcolor="<?php echo $bgcolor; ?>"> <td bgcolor="<?php echo $bgcolor; ?>">
<?php echo $backup_field . "\n"; ?> <?php echo $backup_field . "\n"; ?>
<textarea name="fields[<?php echo urlencode($field); ?>]" rows="<?php echo $cfgTextareaRows; ?>" cols="<?php echo $cfgTextareaCols; ?>" wrap="virtual" onchange="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}" tabindex="<?php echo $i; ?>"><?php echo $special_chars; ?></textarea> <textarea name="fields[<?php echo urlencode($field); ?>]" rows="<?php echo $cfgTextareaRows; ?>" cols="<?php echo $cfgTextareaCols; ?>" wrap="virtual" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo $i; ?>"><?php echo $special_chars; ?></textarea>
</td> </td>
<?php <?php
echo "\n"; echo "\n";
@@ -334,7 +342,7 @@ for ($i = 0; $i < $fields_cnt; $i++) {
if (strlen($row_table_def['Type']) > 20) { if (strlen($row_table_def['Type']) > 20) {
echo "\n"; echo "\n";
?> ?>
<select name="field_<?php echo md5($field); ?>[]" onchange="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}" tabindex="<?php echo $i+1; ?>"> <select name="field_<?php echo md5($field); ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo $i+1; ?>">
<option value=""></option> <option value=""></option>
<?php <?php
echo "\n"; echo "\n";
@@ -395,7 +403,7 @@ for ($i = 0; $i < $fields_cnt; $i++) {
<td bgcolor="<?php echo $bgcolor; ?>"> <td bgcolor="<?php echo $bgcolor; ?>">
<?php echo $backup_field . "\n"; ?> <?php echo $backup_field . "\n"; ?>
<input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="$set$" /> <input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="$set$" />
<select name="field_<?php echo md5($field); ?>[]" size="<?php echo $size; ?>" multiple="multiple" onchange="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}" tabindex="<?php echo $i+1; ?>" > <select name="field_<?php echo md5($field); ?>[]" size="<?php echo $size; ?>" multiple="multiple" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo $i+1; ?>" >
<?php <?php
echo "\n"; echo "\n";
$countset = count($set); $countset = count($set);
@@ -431,7 +439,7 @@ for ($i = 0; $i < $fields_cnt; $i++) {
?> ?>
<td bgcolor="<?php echo $bgcolor; ?>"> <td bgcolor="<?php echo $bgcolor; ?>">
<?php echo $backup_field . "\n"; ?> <?php echo $backup_field . "\n"; ?>
<textarea name="fields[<?php echo urlencode($field); ?>]" rows="<?php echo $cfgTextareaRows; ?>" cols="<?php echo $cfgTextareaCols; ?>" wrap="virtual" onchange="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}" tabindex="<?php echo $i+1; ?>" ><?php echo $special_chars; ?></textarea> <textarea name="fields[<?php echo urlencode($field); ?>]" rows="<?php echo $cfgTextareaRows; ?>" cols="<?php echo $cfgTextareaCols; ?>" wrap="virtual" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo $i+1; ?>" ><?php echo $special_chars; ?></textarea>
</td> </td>
<?php <?php
} else { } else {
@@ -445,7 +453,7 @@ for ($i = 0; $i < $fields_cnt; $i++) {
?> ?>
<td bgcolor="<?php echo $bgcolor; ?>"> <td bgcolor="<?php echo $bgcolor; ?>">
<?php echo $backup_field . "\n"; ?> <?php echo $backup_field . "\n"; ?>
<input type="text" name="fields[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" onchange="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}" tabindex="<?php echo $i+1; ?>" /> <input type="text" name="fields[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo $i+1; ?>" />
</td> </td>
<?php <?php
} // end if...elseif...else } // end if...elseif...else
@@ -461,7 +469,7 @@ for ($i = 0; $i < $fields_cnt; $i++) {
?> ?>
<td bgcolor="<?php echo $bgcolor; ?>"> <td bgcolor="<?php echo $bgcolor; ?>">
<?php echo $backup_field . "\n"; ?> <?php echo $backup_field . "\n"; ?>
<input type="text" name="fields[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" onchange="if (typeof(document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]']) != 'undefined') {document.forms['insertForm'].elements['fields_null[<?php echo urlencode($field); ?>]'].checked = false}" tabindex="<?php echo $i+1; ?>" /> <input type="text" name="fields[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo $i+1; ?>" />
</td> </td>
<?php <?php
} }