Permalink
Browse files

Used AJAX for updating field information(type,collation,operators,fie…

…ld values) in zoom-search input form
  • Loading branch information...
1 parent f8daedc commit 9be5d8e02ae431be040e655da0eb39b134cd107d @ammaryasir ammaryasir committed with nijel Feb 20, 2012
Showing with 146 additions and 94 deletions.
  1. +70 −4 js/tbl_zoom_plot.js
  2. +76 −90 tbl_zoom_select.php
View
@@ -187,19 +187,85 @@ $(document).ready(function() {
** Input form submit on field change
**/
$('#tableid_0').change(function() {
- $('#zoom_search_form').submit();
+ //AJAX request for field type, collation, operators, and value field
+ $.post('tbl_zoom_select.php',{
+ 'ajax_request' : true,
+ 'change_tbl_info' : true,
+ 'db' : window.parent.db,
+ 'table' : window.parent.table,
+ 'field' : $('#tableid_0').val(),
+ 'it' : 0,
+ 'token' : window.parent.token,
+ },function(data) {
+ $('#tabId tr:eq(1) td:eq(0)').html(data.field_type);
+ $('#tabId tr:eq(1) td:eq(1)').html(data.field_collation);
+ $('#tabId tr:eq(1) td:eq(2)').html(data.field_operators);
+ $('#tabId tr:eq(1) td:eq(3)').html(data.field_value);
+ xLabel = $('#tableid_0').val();
+ $('#types_0').val(data.field_type);
+ $('#collations_0').val(data.field_collations);
+ });
});
$('#tableid_1').change(function() {
- $('#zoom_search_form').submit();
+ //AJAX request for field type, collation, operators, and value field
+ $.post('tbl_zoom_select.php',{
+ 'ajax_request' : true,
+ 'change_tbl_info' : true,
+ 'db' : window.parent.db,
+ 'table' : window.parent.table,
+ 'field' : $('#tableid_1').val(),
+ 'it' : 1,
+ 'token' : window.parent.token,
+ },function(data) {
+ $('#tabId tr:eq(3) td:eq(0)').html(data.field_type);
+ $('#tabId tr:eq(3) td:eq(1)').html(data.field_collation);
+ $('#tabId tr:eq(3) td:eq(2)').html(data.field_operators);
+ $('#tabId tr:eq(3) td:eq(3)').html(data.field_value);
+ yLabel = $('#tableid_1').val();
+ $('#types_1').val(data.field_type);
+ $('#collations_1').val(data.field_collations);
+ });
});
$('#tableid_2').change(function() {
- $('#zoom_search_form').submit();
+ //AJAX request for field type, collation, operators, and value field
+ $.post('tbl_zoom_select.php',{
+ 'ajax_request' : true,
+ 'change_tbl_info' : true,
+ 'db' : window.parent.db,
+ 'table' : window.parent.table,
+ 'field' : $('#tableid_2').val(),
+ 'it' : 2,
+ 'token' : window.parent.token,
+ },function(data) {
+ $('#tabId tr:eq(6) td:eq(0)').html(data.field_type);
+ $('#tabId tr:eq(6) td:eq(1)').html(data.field_collation);
+ $('#tabId tr:eq(6) td:eq(2)').html(data.field_operators);
+ $('#tabId tr:eq(6) td:eq(3)').html(data.field_value);
+ $('#types_2').val(data.field_type);
+ $('#collations_2').val(data.field_collations);
+ });
});
$('#tableid_3').change(function() {
- $('#zoom_search_form').submit();
+ //AJAX request for field type, collation, operators, and value field
+ $.post('tbl_zoom_select.php',{
+ 'ajax_request' : true,
+ 'change_tbl_info' : true,
+ 'db' : window.parent.db,
+ 'table' : window.parent.table,
+ 'field' : $('#tableid_3').val(),
+ 'it' : 3,
+ 'token' : window.parent.token,
+ },function(data) {
+ $('#tabId tr:eq(8) td:eq(0)').html(data.field_type);
+ $('#tabId tr:eq(8) td:eq(1)').html(data.field_collation);
+ $('#tabId tr:eq(8) td:eq(2)').html(data.field_operators);
+ $('#tabId tr:eq(8) td:eq(3)').html(data.field_value);
+ $('#types_3').val(data.field_type);
+ $('#collations_3').val(data.field_collations);
+ });
});
/**
View
@@ -55,6 +55,75 @@
PMA_ajaxResponse(null, true, $extra_data);
}
+/**
+ * Handle AJAX request for changing field information(value,collation,operators,field values)
+ * in input form
+ * @var post_params Object containing parameters for the POST request
+ */
+
+if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
+ $extra_data = array();
+ $field = $_REQUEST['field'];
+ if($field == 'pma_null') {
+ $extra_data['field_type'] = '';
+ $extra_data['field_collation'] = '';
+ $extra_data['field_operators'] = '';
+ PMA_ajaxResponse(NULL, true, $extra_data);
+ }
+
+
+ // Gets the list and number of fields
+ list($fields_list, $fields_type, $fields_collation, $fields_null) = PMA_tbl_getFields($_REQUEST['db'],$_REQUEST['table']);
+
+ $foreigners = PMA_getForeigners($db, $table);
+ $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
+ $key = array_search($field,$fields_list);
+ $extra_data['field_type'] = $fields_type[$key];
+ $extra_data['field_collation'] = $fields_collation[$key];
+
+ // HTML for operators
+ $html = '<select name="zoomFunc[]">';
+ if (strncasecmp($fields_type[$key], 'enum', 4) == 0) {
+ foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
+ $html .= "\n" . ' '
+ . '<option value="' . htmlspecialchars($fc) . '">'
+ . htmlspecialchars($fc) . '</option>';
+ }
+ } elseif (preg_match('@char|blob|text|set@i', $fields_type[$key])) {
+ foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
+ $html .= "\n" . ' '
+ . '<option value="' . htmlspecialchars($fc) . '">'
+ . htmlspecialchars($fc) . '</option>';
+ }
+ } else {
+ foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
+ $html .= "\n" . ' '
+ . '<option value="' . htmlspecialchars($fc) . '">'
+ . htmlspecialchars($fc) . '</option>';
+ }
+ } // end if... else...
+
+ if ($fields_null[$key]) {
+ foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
+ $html .= "\n" . ' '
+ . '<option value="' . htmlspecialchars($fc) . '">'
+ . htmlspecialchars($fc) . '</option>';
+ }
+ }
+ $html .= '</select>';
+ $extra_data['field_operators'] = $html;
+
+ // retrieve keys into foreign fields, if any
+ // check also foreigners even if relwork is FALSE (to get
+ // foreign keys from innodb)
+ $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
+
+ // HTML for field values
+ $html = PMA_getForeignFields_Values($foreigners, $foreignData, $field, array($_REQUEST['it'] => $fields_type[$key]), $_REQUEST['it'] ,$_REQUEST['db'], $_REQUEST['table'], $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], '');
+ $extra_data['field_value'] = $html;
+ PMA_ajaxResponse(NULL, true, $extra_data);
+}
+
$titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
/**
* Not selection yet required -> displays the selection form
@@ -133,7 +202,7 @@
<fieldset id="inputSection">
<legend><?php echo __('Do a "query by example" (wildcard: "%") for two different columns') ?></legend>
-<table class="data">
+<table class="data" id="tabId">
<?php echo PMA_tbl_setTableHeader();?>
<tbody>
<?php
@@ -162,98 +231,15 @@
}
} ?>
</select></th>
- <td><?php if (isset($tbl_fields_type[$i])) echo $tbl_fields_type[$i]; ?></td>
- <td><?php if (isset($tbl_fields_collation[$i])) echo $tbl_fields_collation[$i]; ?></td>
- <td>
- <?php
- if (isset($inputs) && $inputs[$i] != 'pma_null') { ?>
- <select name="zoomFunc[]">
- <?php
- if (strncasecmp($tbl_fields_type[$i], 'enum', 4) == 0) {
- foreach ($GLOBALS['cfg']['EnumOperators'] as $fc) {
- if (isset($zoomFunc[$i]) && $zoomFunc[$i] == htmlspecialchars($fc)) {
- echo "\n" . ' '
- . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
- . htmlspecialchars($fc) . '</option>';
- } else {
- echo "\n" . ' '
- . '<option value="' . htmlspecialchars($fc) . '">'
- . htmlspecialchars($fc) . '</option>';
- }
- }
- } elseif (preg_match('@char|blob|text|set@i', $tbl_fields_type[$i])) {
- foreach ($GLOBALS['cfg']['TextOperators'] as $fc) {
- if (isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc) {
- echo "\n" . ' '
- . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
- . htmlspecialchars($fc) . '</option>';
- } else {
- echo "\n" . ' '
- . '<option value="' . htmlspecialchars($fc) . '">'
- . htmlspecialchars($fc) . '</option>';
- }
- }
- } else {
- foreach ($GLOBALS['cfg']['NumOperators'] as $fc) {
- if (isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc) {
- echo "\n" . ' '
- . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
- . htmlspecialchars($fc) . '</option>';
- } else {
- echo "\n" . ' '
- . '<option value="' . htmlspecialchars($fc) . '">'
- . htmlspecialchars($fc) . '</option>';
- }
- }
- } // end if... else...
-
- if ($tbl_fields_null[$i]) {
- foreach ($GLOBALS['cfg']['NullOperators'] as $fc) {
- if (isset($zoomFunc[$i]) && $zoomFunc[$i] == $fc) {
- echo "\n" . ' '
- . '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
- . htmlspecialchars($fc) . '</option>';
- } else {
- echo "\n" . ' '
- . '<option value="' . htmlspecialchars($fc) . '">'
- . htmlspecialchars($fc) . '</option>';
- }
- }
- }
- ?>
- </select>
- </td>
- <td>
- <?php
- $field = $inputs[$i];
-
- $foreignData = PMA_getForeignData($foreigners, $field, false, '', '');
- if (isset($fields)) {
- echo PMA_getForeignFields_Values(
- $foreigners, $foreignData, $field, $tbl_fields_type, $i, $db,
- $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], $fields
- );
- } else {
- echo PMA_getForeignFields_Values(
- $foreigners, $foreignData, $field, $tbl_fields_type, $i, $db,
- $table, $titles, $GLOBALS['cfg']['ForeignKeyMaxLimit'], ''
- );
- }
- } else { ?>
-
- </td><td></td>
-
- <?php
- } ?>
-
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
</tr>
<tr><td>
- <input type="hidden" name="types[<?php echo $i; ?>]" id="types_<?php echo $i; ?>"
- value="<?php if(isset($tbl_fields_type[$i]))echo $tbl_fields_type[$i]; ?>" />
- <input type="hidden" name="collations[<?php echo $i; ?>]"
- value="<?php if(isset($tbl_fields_collation[$i]))echo $tbl_fields_collation[$i]; ?>" />
+ <input type="hidden" name="types[<?php echo $i; ?>]" id="types_<?php echo $i; ?>" />
+ <input type="hidden" name="collations[<?php echo $i;?>]" id="collations_<?php echo $i; ?>" />
</td></tr>
-
<?php
}//end for
?>

0 comments on commit 9be5d8e

Please sign in to comment.