Browse files

rfe #3517835 [structure] Move columns easily

  • Loading branch information...
1 parent 2760d80 commit 37ac76c46124b6694a26949df9dd5df38c393f57 Jo Michael committed Apr 14, 2012
Showing with 244 additions and 16 deletions.
  1. +1 −0 ChangeLog
  2. +102 −16 js/tbl_structure.js
  3. +77 −0 tbl_alter.php
  4. +22 −0 tbl_structure.php
  5. +20 −0 themes/original/css/theme_right.css.php
  6. +22 −0 themes/pmahomme/css/theme_right.css.php
View
1 ChangeLog
@@ -27,6 +27,7 @@ phpMyAdmin - ChangeLog
- bug [export] Texy! Text: Columns containing Pipe Character don't export properly
+ [export] Show triggers in Open Document Text, Word and Texy! Text
- Patch #3415061 [auth] Login screen appears under the page
++ rfe #3517835 [structure] Move columns easily
3.5.1.0 (not yet released)
- bug #3510784 [edit] Limit clause ignored when sort order is remembered
View
118 js/tbl_structure.js
@@ -360,6 +360,83 @@ $(document).ready(function() {
});
/**
+ * Inline move columns
+ **/
+ $("#move_columns_anchor").live('click', function(e) {
+ e.preventDefault();
+
+ if ($(this).hasClass("move-active")) {
+ return;
+ }
+
+ /**
+ * @var button_options Object that stores the options passed to jQueryUI
+ * dialog
+ */
+ var button_options = {};
+
+ button_options[PMA_messages['strGo']] = function() {
+ event.preventDefault();
+ var $msgbox = PMA_ajaxShowMessage();
+ var $this = $(this);
+ var $form = $this.find("form");
+ var serialized = $form.serialize();
+
+ // check if any columns were moved at all
+ if (serialized == $form.data("serialized-unmoved")) {
+ PMA_ajaxRemoveMessage($msgbox);
+ $this.dialog('close');
+ return;
+ }
+
+ $.post($form.prop("action"), serialized + "&ajax_request=true", function (data) {
+ if (data.success != undefined && data.success == false) {
+ PMA_ajaxRemoveMessage($msgbox);
+ $this
+ .clone()
+ .html(data.error)
+ .dialog({
+ title: $(this).prop("title"),
+ height: 230,
+ width: 900,
+ modal: true,
+ buttons: button_options_error
+ }); // end dialog options
+ } else {
+ PMA_ajaxShowMessage(data.message);
+ reloadFieldForm();
+ $this.dialog('close');
+ }
+ });
+ };
+ button_options[PMA_messages['strCancel']] = function() {
+ $(this).dialog('close');
+ };
+
+ var button_options_error = {};
+ button_options_error[PMA_messages['strOK']] = function() {
+ $(this).dialog('close').remove();
+ };
+
+ $("#move_columns_dialog ul")
+ .sortable({
+ axis: 'y',
+ containment: $("#move_columns_dialog div")
+ })
+ .disableSelection();
+ var $form = $("#move_columns_dialog form");
+ $form.data("serialized-unmoved", $form.serialize());
+
+ $("#move_columns_dialog").dialog({
+ modal: true,
+ buttons: button_options,
+ beforeClose: function () {
+ $("#move_columns_anchor").removeClass("move-active");
+ }
+ });
+ });
+
+ /**
*Ajax event handler for Add column(s)
**/
$("#addColumns.ajax input[type=submit]").live('click', function(event){
@@ -389,7 +466,7 @@ $(document).ready(function() {
};
var $msgbox = PMA_ajaxShowMessage();
- $.get($form.attr('action') , $form.serialize()+"&ajax_request=true" , function(data) {
+ $.get($form.attr('action') , $form.serialize() + "&ajax_request=true" , function(data) {
//in the case of an error, show the error message returned.
if (data.success != undefined && data.success == false) {
$div
@@ -533,27 +610,14 @@ $(document).ready(function() {
$("<div id='sqlqueryresults'></div>").insertAfter("#floating_menubar");
$("#sqlqueryresults").html(data.sql_query);
$("#result_query .notice").remove();
- $("#result_query").prepend((data.message));
+ $("#result_query").prepend(data.message);
if ($("#change_column_dialog").length > 0) {
$("#change_column_dialog").dialog("close").remove();
} else if ($("#add_columns").length > 0) {
$("#add_columns").dialog("close").remove();
}
/*Reload the field form*/
- $.post($("#fieldsForm").attr('action'), $("#fieldsForm").serialize()+"&ajax_request=true", function(form_data) {
- $("#fieldsForm").remove();
- $("#addColumns").remove();
- var $temp_div = $("<div id='temp_div'><div>").append(form_data);
- if ($("#sqlqueryresults").length != 0) {
- $temp_div.find("#fieldsForm").insertAfter("#sqlqueryresults");
- } else {
- $temp_div.find("#fieldsForm").insertAfter(".error");
- }
- $temp_div.find("#addColumns").insertBefore("iframe.IE_hack");
- /*Call the function to display the more options in table*/
- $table_clone = false;
- moreOptsMenuResize();
- });
+ reloadFieldForm();
} else {
var $temp_div = $("<div id='temp_div'><div>").append(data);
var $error = $temp_div.find(".error code").addClass("error");
@@ -571,6 +635,28 @@ $(document).ready(function() {
}, 'top.frame_content'); //end $(document).ready for 'Change Table'
/**
+ * Reload fields table
+ */
+
+function reloadFieldForm() {
+ $.post($("#fieldsForm").attr('action'), $("#fieldsForm").serialize()+"&ajax_request=true", function(form_data) {
+ $("#fieldsForm").remove();
+ $("#addColumns").remove();
+ var $temp_div = $("<div id='temp_div'><div>").append(form_data);
+ if ($("#sqlqueryresults").length != 0) {
+ $temp_div.find("#fieldsForm").insertAfter("#sqlqueryresults");
+ } else {
+ $temp_div.find("#fieldsForm").insertAfter("#floating_menubar");
+ }
+ $temp_div.find("#addColumns").insertBefore("iframe.IE_hack");
+ $("#moveColumns").removeClass("move-active");
+ /*Call the function to display the more options in table*/
+ $table_clone = false;
+ moreOptsMenuResize();
+ });
+}
+
+/**
* Hides certain table structure actions, replacing them
* with the word "More". They are displayed in a dropdown
* menu when the user hovers over the word "More."
View
77 tbl_alter.php
@@ -36,6 +36,83 @@
*/
$err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
+/**
+ * Moving columns
+ */
+if (isset($_REQUEST['move_columns'])
+ && is_array($_REQUEST['move_columns'])
+ && $GLOBALS['is_ajax_request']) {
+ /*
+ * first, load the definitions for all columns
+ */
+ $result = PMA_DBI_try_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table));
+ // an error can happen, for example the table is crashed
+ $tmp_error = PMA_DBI_getError();
+ if ($tmp_error) {
+ PMA_ajaxResponse(PMA_Message::error($tmp_error), false);
+ }
+
+ if ($result != false && ($row = PMA_DBI_fetch_row($result))) {
+ $create_query = $row[1];
+ unset($row);
+
+ // Convert end of line chars to one that we want (note that MySQL doesn't return query it will accept in all cases)
+ if (strpos($create_query, "(\r\n ")) {
+ $create_query = str_replace("\r\n", "\n", $create_query);
+ } elseif (strpos($create_query, "(\r ")) {
+ $create_query = str_replace("\r", "\n", $create_query);
+ }
+ }
+ $create_query = explode("\n", $create_query);
+ $definitions = array();
+ $columns = array();
+ foreach($create_query as $row) {
+ $row = trim($row);
+ // trim any trailing commas
+ if (substr($row, -1) == ',') {
+ $row = substr($row, 0, -1);
+ }
+ // columns can be identified by the leading backtick
+ if (substr($row, 0, 1) == '`') {
+ $column = substr($row, 1, strpos($row, '`', 1) - 1);
+ $definitions[$column] = $row;
+ $columns[] = $column;
+ }
+ }
+ // move columns from first to last
+ for ($i = 0, $l = count($_REQUEST['move_columns']); $i < $l; $i++) {
+ $column = $_REQUEST['move_columns'][$i];
+ // is this column already correctly placed?
+ if ($columns[$i] == $column) {
+ continue;
+ }
+ // it is not, let's move it to index $i
+ $move_query = 'ALTER TABLE ' . PMA_backquote($table) . ' '
+ . 'CHANGE ' . PMA_backquote($column) . ' ' . $definitions[$column];
+ // to become first column?
+ if ($i == 0) {
+ $move_query .= ' FIRST';
+ }
+ else {
+ $move_query .= ' AFTER ' . PMA_backquote($columns[$i - 1]);
+ }
+ // move column here
+ $result = PMA_DBI_query($move_query);
+ $tmp_error = PMA_DBI_getError();
+ if ($tmp_error) {
+ PMA_ajaxResponse(PMA_Message::error($tmp_error), false);
+ }
+ // update current columns array, first delete old position
+ for($j = 0, $ll = count($columns); $j < $ll; $j++) {
+ if ($columns[$j] == $column) {
+ unset($columns[$j]);
+ }
+ }
+ // insert moved column
+ array_splice($columns, $i, 0, $column);
+ }
+ PMA_ajaxResponse(PMA_Message::success(__('The columns have been moved successfully.')), true);
+}
/**
* Modifications have been submitted -> updates the table
View
22 tbl_structure.php
@@ -577,6 +577,24 @@
</form>
<hr />
+<div id="move_columns_dialog" title="<?php echo __('Move columns'); ?>" style="display: none">
+ <p><?php echo __('Move the columns by dragging them up and down.'); ?></p>
+ <form action="tbl_alter.php">
+ <div>
+ <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
+ <ul>
+<?php
+foreach ($fields as $row) { ?>
+
+ <li class="placeholderDrag"><?php echo $field = htmlspecialchars($row['Field']); ?>
+ <input type="hidden" name="move_columns[]" value="<?php echo $field; ?>" /></li>
+<?php } ?>
+
+ </ul>
+ </div>
+ </form>
+</div>
+
<?php
/**
* Work on the table
@@ -630,6 +648,10 @@
}
?>
+ <a href="#" id="move_columns_anchor"><?php
+ echo PMA_getIcon('b_props.png', __('Move columns'), true);
+ ?></a>
+
<br />
<form method="post" action="tbl_addfield.php" id="addColumns" name="addColumns" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>
onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)">
View
20 themes/original/css/theme_right.css.php
@@ -1869,6 +1869,26 @@
overflow: hidden;
}
+#move_columns_dialog div {
+ padding: 1em;
+}
+#move_columns_dialog ul {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+#move_columns_dialog li {
+ background: <?php echo $GLOBALS['cfg']['ThBackground']; ?>;
+ border: 1px solid #aaa;
+ color: <?php echo $GLOBALS['cfg']['ThColor']; ?>;
+ font-weight: bold;
+ margin: .4em;
+ padding: .2em;
+ -webkit-border-radius: 2px;
+ -moz-border-radius: 2px;
+ border-radius: 2px;
+}
+
/* config forms */
.config-form ul.tabs {
margin: 1.1em 0.2em 0;
View
22 themes/pmahomme/css/theme_right.css.php
@@ -2336,6 +2336,28 @@
overflow: hidden;
}
+#move_columns_dialog div {
+ padding: 1em;
+}
+
+#move_columns_dialog ul {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+
+#move_columns_dialog li {
+ background: <?php echo $GLOBALS['cfg']['ThBackground']; ?>;
+ border: 1px solid #aaa;
+ color: <?php echo $GLOBALS['cfg']['ThColor']; ?>;
+ font-weight: bold;
+ margin: .4em;
+ padding: .2em;
+ -webkit-border-radius: 2px;
+ -moz-border-radius: 2px;
+ border-radius: 2px;
+}
+
/* config forms */
.config-form ul.tabs {
margin: 1.1em .2em 0;

0 comments on commit 37ac76c

Please sign in to comment.