Permalink
Browse files

Functionality for edit data points added (primitive)

  • Loading branch information...
1 parent ea171be commit 362a57f7e1663de26149f27abc4ef49144e8f744 @ammaryasir ammaryasir committed Jul 10, 2011
Showing with 65 additions and 36 deletions.
  1. +51 −33 js/tbl_zoom_plot.js
  2. +14 −3 tbl_zoom_select.php
View
84 js/tbl_zoom_plot.js
@@ -11,28 +11,35 @@
** Display Help/Info
**/
function displayHelp() {
- var msgbox = PMA_ajaxShowMessage(PMA_messages['strDisplayHelp'],10000);
- msgbox.click(function() {
- $(this).remove();
- });
+ var msgbox = PMA_ajaxShowMessage(PMA_messages['strDisplayHelp'],10000);
+ msgbox.click(function() {
+ $(this).remove();
+ });
}
/**
** Extend the array object for max function
** @param array
**/
Array.max = function (array) {
- return Math.max.apply( Math, array );
+ return Math.max.apply( Math, array );
}
/**
** Extend the array object for min function
** @param array
**/
Array.min = function (array) {
- return Math.min.apply( Math, array );
+ return Math.min.apply( Math, array );
}
+/**
+ ** Checks if a string contains only numeric value
+ ** @param n: String (to be checked)
+ **/
+function isNumeric(n) {
+ return !isNaN(parseFloat(n)) && isFinite(n);
+}
/**
** Scrolls the view to the display section
@@ -47,12 +54,12 @@ function scrollToChart() {
** @param modal: type of dialog
**/
function ShowDialog(modal) {
- $("#overlay").show();
- $("#dialog").fadeIn(300);
- $("#overlay").click(function (e)
- {
- HideDialog();
- });
+ $("#overlay").show();
+ $("#dialog").fadeIn(300);
+ $("#overlay").click(function (e)
+ {
+ HideDialog();
+ });
}
/**
@@ -64,7 +71,6 @@ function HideDialog() {
$("#dialog").fadeOut(300);
}
-
$(document).ready(function() {
/**
@@ -138,7 +144,8 @@ $(document).ready(function() {
var it = 4;
for (key in data[currentData]) {
- data[currentData][key] = $('#fieldID_' + it).val();
+ if (key != 'where_clause')
+ data[currentData][key] = $('#fieldID_' + it).val();
it++
}
//Update the chart seiries for replot
@@ -160,29 +167,40 @@ $(document).ready(function() {
currentChart = PMA_createChart(currentSettings);
currentChart.series[currentData].data[0].select();
- $form = $('#zoom_display_form');
- $str = $form.serialize();
- alert('Working on it');
- $.post($form.attr('action'), $str, function(response) {
- /*var sql_query = 'Update film_actor Set last_update = \'2011-01-01\' where actor_id = 1;';
- $.post('sql.php', {
- 'token' : window.parent.token,
- 'db' : window.parent.db,
- 'ajax_request' : true,
- 'sql_query' : sql_query,
- 'inline_edit' : false
+
+ //Generate SQL query for update
+ var sql_query = 'UPDATE `' + window.parent.table + '` SET ';
+ $.each(data[currentData],function(index, value) {
+ if(index != 'where_clause') {
+ sql_query += '`' + index + '`='
+ if(!isNumeric(value))
+ sql_query += '\'' + value.replace(/'/g, "''") + '\' ,'
+ else
+ sql_query += value.replace(/'/g, "''") + ' ,'
+
+ }
+ else {
+ sql_query = sql_query.substring(0, sql_query.length - 1);
+ sql_query += ' WHERE ' + PMA_urldecode(value);
+ }
+ });
+ //Post SQL query to sql.php
+ $.post('sql.php', {
+ 'token' : window.parent.token,
+ 'db' : window.parent.db,
+ 'ajax_request' : true,
+ 'sql_query' : sql_query,
+ 'inline_edit' : false
}, function(data) {
if(data.success == true) {
- $('#sqlqueryresults').html(data.sql_query);
- $("#sqlqueryresults").trigger('appendAnchor');
+ $('#sqlqueryresults').html(data.sql_query);
+ $("#sqlqueryresults").trigger('appendAnchor');
}
- else
- PMA_ajaxShowMessage(data.error);
- })*/
+ else
+ PMA_ajaxShowMessage(data.error);
+ })
- })//end $.post('sql.php')
- });//end $.post
-
+ })//end $.post('sql.php')
/*
* Generate plot using Highcharts
View
17 tbl_zoom_select.php
@@ -28,8 +28,8 @@
$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
$GLOBALS['js_include'][] = 'jquery/timepicker.js';
-$titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage);
+$titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage);
/**
* Not selection yet required -> displays the selection form
*/
@@ -69,6 +69,7 @@
$maxPlotlLimit = $GLOBALS['cfg']['maxRowPlotLimit'];
?>
+<div id="sqlqueryresults"></div>
<fieldset id="fieldset_subtab">
<?php
$url_params = array();
@@ -318,9 +319,19 @@
* Query execution part
*/
$result = PMA_DBI_query( $sql_query . ";" , null, PMA_DBI_QUERY_STORE);
+ $fields_meta = PMA_DBI_get_fields_meta($result);
while ($row = PMA_DBI_fetch_assoc($result)) {
+ //Need a row with indexes as 0,1,2 for the PMA_getUniqueCondition hence using a temporary array
+ $tmpRow = array();
+ foreach($row as $val)
+ $tmpRow[] = $val;
+ //Get unique conditon on each row (will be needed for row update)
+ $uniqueCondition = PMA_getUniqueCondition($result, $fields_cnt, $fields_meta, $tmpRow, true);
+ //Append it to row array as where_clause
+ $row['where_clause'] = $uniqueCondition[0];
$data[] = $row;
- }
+ }
+
?>
<?php
@@ -390,7 +401,7 @@
<?php
}
?>
-<div id="sqlqueryresults"></div>
+
<?php
require './libraries/footer.inc.php';
?>

0 comments on commit 362a57f

Please sign in to comment.