Permalink
Browse files

Ajaxify Index edit in table structure

  • Loading branch information...
1 parent 2c57318 commit 0cb77d14bad36196664f953d62e247193e1eb30d @lgtkaushalya lgtkaushalya committed Jul 1, 2011
Showing with 132 additions and 7 deletions.
  1. +115 −0 js/tbl_structure.js
  2. +7 −3 libraries/Index.class.php
  3. +9 −3 tbl_indexes.php
  4. +1 −1 tbl_structure.php
View
@@ -250,4 +250,119 @@ $(document).ready(function() {
}) // end $.post()
}) // end insert table button "do_save_data"
+ /**
+ *Ajax event handler for index edit
+ **/
+ $("#table_index tbody tr td.edit_index.ajax").live('click', function(event){
+ event.preventDefault();
+ var url = $(this).find("a").attr("href");
+ if (url.substring(0, 16) == "tbl_indexes.php?") {
+ url = url.substring(16, url.length );
+ }
+ url = url + "&ajax_request=true";
+
+ var div = $('<div id="edit_index_dialog"></div>');
+
+ /**
+ * @var button_options Object that stores the options passed to jQueryUI
+ * dialog
+ */
+ var button_options = {};
+ // in the following function we need to use $(this)
+ button_options[PMA_messages['strCancel']] = function() {$(this).parent().dialog('close').remove();}
+
+ var button_options_error = {};
+ button_options_error[PMA_messages['strOK']] = function() {$(this).parent().dialog('close').remove();}
+ var $msgbox = PMA_ajaxShowMessage();
+
+ $.get( "tbl_indexes.php" , url , function(data) {
+ //in the case of an error, show the error message returned.
+ if (data.success != undefined && data.success == false) {
+ div
+ .append(data.error)
+ .dialog({
+ title: PMA_messages['strEdit'],
+ height: 230,
+ width: 900,
+ open: PMA_verifyTypeOfAllColumns,
+ buttons : button_options_error
+ })// end dialog options
+ } else {
+ div
+ .append(data)
+ .dialog({
+ title: PMA_messages['strEdit'],
+ height: 600,
+ width: 900,
+ open: PMA_verifyTypeOfAllColumns,
+ buttons : button_options
+ })
+ //Remove the top menu container from the dialog
+ .find("#topmenucontainer").hide()
+ ; // end dialog options
+ }
+ PMA_ajaxRemoveMessage($msgbox);
+ }) // end $.get()
+ });
+
+ /**
+ *Ajax action for submiting the index form
+ **/
+ $("#index_frm.ajax input[name=do_save_data]").live('click', function(event) {
+ event.preventDefault();
+ /**
+ * @var the_form object referring to the export form
+ */
+ var $form = $("#index_frm");
+
+ PMA_prepareForAjaxRequest($form);
+ //User wants to submit the form
+ $.post($form.attr('action'), $form.serialize()+"&do_save_data=Save", function(data) {
+ if ($("#sqlqueryresults").length != 0) {
+ $("#sqlqueryresults").remove();
+ }
+ if (data.success == true) {
+ PMA_ajaxShowMessage(data.message);
+ $("<div id='sqlqueryresults'></div>").insertAfter("#topmenucontainer");
+ $("#sqlqueryresults").html(data.sql_query);
+ $("#result_query .notice").remove();
+ $("#result_query").prepend((data.message));
+
+ /*Reload the field form*/
+ $("#table_index").remove();
+ var temp_div = $("<div id='temp_div'><div>").append(data.index_table);
+ $(temp_div).find("#table_index").insertAfter("#index_header");
+ if ($("#edit_index_dialog").length > 0) {
+ $("#edit_index_dialog").dialog("close").remove();
+ }
+
+ } else {
+ var temp_div = $("<div id='temp_div'><div>").append(data.error);
+ var error = $(temp_div).find(".error code").addClass("error");
+ PMA_ajaxShowMessage(error);
+ }
+
+ }) // end $.post()
+ }) // end insert table button "do_save_data"
+
+ /**
+ *Ajax action for submiting the index form for add more columns
+ **/
+ $("#index_frm.ajax input[name=add_fields]").live('click', function(event) {
+ event.preventDefault();
+ /**
+ * @var the_form object referring to the export form
+ */
+ var $form = $("#index_frm");
+
+ PMA_prepareForAjaxRequest($form);
+ //User wants to submit the form
+ $.post($form.attr('action'), $form.serialize()+"&add_fields=Go", function(data) {
+ $("#index_columns").remove();
+ var temp_div = $("<div id='temp_div'><div>").append(data);
+ $(temp_div).find("#index_columns").insertAfter("#index_frm fieldset .error");
+ }) // end $.post()
+ }) // end insert table button "Go"
+
+
}) // end $(document).ready()
@@ -432,10 +432,10 @@ static public function getView($table, $schema, $print_mode = false)
$r = '';
- $r .= '<h2>' . __('Indexes') . ': ';
+ $r .= '<h2 id="index_header">' . __('Indexes') . ': ';
$r .= PMA_showMySQLDocu('optimization', 'optimizing-database-structure');
$r .= '</h2>';
- $r .= '<table>';
+ $r .= '<table id="table_index">';
$r .= '<thead>';
$r .= '<tr>';
if (! $print_mode) {
@@ -463,7 +463,11 @@ static public function getView($table, $schema, $print_mode = false)
if (! $print_mode) {
$this_params = $GLOBALS['url_params'];
$this_params['index'] = $index->getName();
- $r .= '<td ' . $row_span . '>'
+ $r .= '<td class="edit_index ';
+ if ($GLOBALS['cfg']['AjaxEnable']) {
+ $r .= 'ajax" ';
+ }
+ $r .= '" ' . $row_span . '>'
. ' <a href="tbl_indexes.php' . PMA_generate_common_url($this_params)
. '">' . PMA_getIcon('b_edit.png', __('Edit')) . '</a>'
. '</td>' . "\n";
View
@@ -97,7 +97,13 @@
PMA_DBI_query($sql_query);
$message = PMA_Message::success(__('Table %1$s has been altered successfully'));
$message->addParam($table);
-
+
+ if( $GLOBALS['is_ajax_request'] == true) {
+ $extra_data['index_table'] = PMA_Index::getView($table, $db);
+ $extra_data['sql_query'] = PMA_showMessage(NULL, $sql_query);
+ PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
+ }
+
$active_page = 'tbl_structure.php';
require './tbl_structure.php';
exit;
@@ -133,7 +139,7 @@
// end preparing form values
?>
-<form action="./tbl_indexes.php" method="post" name="index_frm"
+<form action="./tbl_indexes.php" method="post" name="index_frm" id="index_frm" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>
onsubmit="if (typeof(this.elements['index'].disabled) != 'undefined') {
this.elements['index'].disabled = false}">
<?php
@@ -183,7 +189,7 @@
PMA_Message::error(__('("PRIMARY" <b>must</b> be the name of and <b>only of</b> a primary key!)'))->display();
?>
-<table>
+<table id="index_columns">
<thead>
<tr><th><?php echo __('Column'); ?></th>
<th><?php echo __('Size'); ?></th>
View
@@ -14,7 +14,7 @@
$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
$GLOBALS['js_include'][] = 'tbl_structure.js';
-
+$GLOBALS['js_include'][] = 'indexes.js';
/**
* handle multiple field commands if required
*

0 comments on commit 0cb77d1

Please sign in to comment.