Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ajaxified "Create View" functionality

  • Loading branch information...
commit 4c72c0e91f6a9cba02143008fe0a8715738c70c8 1 parent 49a7f12
@roccivic roccivic authored
View
1  ChangeLog
@@ -37,6 +37,7 @@ phpMyAdmin - ChangeLog
- Patch #3500882 Fixing checkbox behaviour while editing identical rows
+ rfe #3441722 [interface] Display description of datatypes
+ rfe #3517835 [structure] Move columns easily
++ Ajaxified "Create View" functionality
3.5.2.0 (not yet released)
- bug #3521416 [interface] JS error when editing index
View
62 js/functions.js
@@ -3720,6 +3720,68 @@ $(function () {
});
/**
+ * Ajaxification for the "Create View" action
+ */
+$(document).ready(function () {
+ $('span.create_view.ajax a').live('click', function (e) {
+ e.preventDefault();
+ var $msg = PMA_ajaxShowMessage();
+ var syntaxHighlighter = null;
+ $.get($(this).attr('href') + '&ajax_request=1', function (data) {
+ PMA_ajaxRemoveMessage($msg);
+ var buttonOptions = {};
+ buttonOptions[PMA_messages['strGo']] = function () {
+ if (typeof CodeMirror !== 'undefined') {
+ syntaxHighlighter.save();
+ }
+ $msg = PMA_ajaxShowMessage();
+ $.get('view_create.php', $('#createViewDialog').find('form').serialize(), function (data) {
+ PMA_ajaxRemoveMessage($msg);
+ if (data.success === true) {
+ $('#createViewDialog').dialog("close");
+ $('#result_query').html(data.message);
+ } else {
+ PMA_ajaxShowMessage(data.error, false);
+ }
+ });
+ };
+ buttonOptions[PMA_messages['strClose']] = function () {
+ $(this).dialog("close");
+ };
+ var $dialog = $('<div/>').attr('id', 'createViewDialog').append(data).dialog({
+ width: 500,
+ minWidth: 300,
+ maxWidth: 620,
+ modal: true,
+ buttons: buttonOptions,
+ title: $('legend', $(data)).html(),
+ close: function () {
+ $(this).remove();
+ }
+ });
+ $dialog.find('legend').remove();
+ // Attach syntax highlited editor
+ if (typeof CodeMirror !== 'undefined') {
+ var $elm = $dialog.find('textarea');
+ var opts = {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql"};
+ syntaxHighlighter = CodeMirror.fromTextArea($elm[0], opts);
+ }
+ $('input:visible[type=text]', $dialog).first().focus();
+ });
+ });
+ /**
+ * Attach Ajax event handlers for input fields in the editor
+ * and used to submit the Ajax request when the ENTER key is pressed.
+ */
+ $('#createViewDialog').find('input, select').live('keydown', function (e) {
+ if (e.which === 13) { // 13 is the ENTER key
+ e.preventDefault();
+ $(this).closest('.ui-dialog').find('.ui-button:first').click();
+ }
+ }); // end $.live()
+});
+
+/**
* Toggles row colors of a set of 'tr' elements starting from a given element
*
* @param $start Starting element
View
4 libraries/display_tbl.lib.php
@@ -2703,11 +2703,13 @@ function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql)
$header_shown = true;
}
if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) {
+ $ajax_class = $GLOBALS['cfg']['AjaxEnable'] ? ' ajax' : '';
+ echo "<span class='create_view$ajax_class'>";
echo PMA_linkOrButton(
'view_create.php' . $url_query,
PMA_getIcon('b_views.png', __('Create view'), true),
'', true, true, ''
- ) . "\n";
+ ) . "</span>\n";
}
if ($header_shown) {
echo '</fieldset><br />';
View
3  themes/original/css/theme_right.css.php
@@ -2099,7 +2099,8 @@
}
.rte_table td {
- vertical-align: middle;
+ vertical-align: middle;
+ padding: 0.2em;
}
.rte_table tr td:nth-child(1) {
View
1  themes/pmahomme/css/theme_right.css.php
@@ -2589,6 +2589,7 @@
.rte_table td {
vertical-align: middle;
+ padding: 0.2em;
}
.rte_table tr td:nth-child(1) {
View
50 view_create.php
@@ -63,11 +63,19 @@
}
if (PMA_DBI_try_query($sql_query)) {
- $message = PMA_Message::success();
- include './' . $cfg['DefaultTabDatabase'];
- exit();
+ if ($GLOBALS['is_ajax_request'] != true) {
+ $message = PMA_Message::success();
+ include './' . $cfg['DefaultTabDatabase'];
+ exit();
+ } else {
+ PMA_ajaxResponse(PMA_showMessage(PMA_Message::success(), $sql_query), 1);
+ }
} else {
- $message = PMA_Message::rawError(PMA_DBI_getError());
+ if ($GLOBALS['is_ajax_request'] != true) {
+ $message = PMA_Message::rawError(PMA_DBI_getError());
+ } else {
+ PMA_ajaxResponse(PMA_Message::error("<i>$sql_query</i><br /><br />" . PMA_DBI_getError()), 0);
+ }
}
}
@@ -90,8 +98,9 @@
* We use db links because a VIEW is not necessarily on a single table
*/
$num_tables = 0;
-require_once './libraries/db_links.inc.php';
-
+if ($GLOBALS['is_ajax_request'] != true) {
+ require_once './libraries/db_links.inc.php';
+}
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
@@ -104,9 +113,8 @@
<form method="post" action="view_create.php">
<?php echo PMA_generate_common_hidden_inputs($url_params); ?>
<fieldset>
- <legend>CREATE VIEW</legend>
-
- <table>
+ <legend><?php echo __('Create view') . PMA_showMySQLDocu('SQL-Syntax', 'CREATE_VIEW'); ?></legend>
+ <table class="rte_table">
<tr><td><label for="or_replace">OR REPLACE</label></td>
<td><input type="checkbox" name="view[or_replace]" id="or_replace"
<?php if ($view['or_replace']) { ?>
@@ -135,20 +143,21 @@
value="<?php echo htmlspecialchars($view['name']); ?>" />
</td>
</tr>
-
<tr><td><?php echo __('Column names'); ?></td>
<td><input type="text" maxlength="100" size="50" name="view[column_names]"
onfocus="this.select()"
value="<?php echo htmlspecialchars($view['column_names']); ?>" />
</td>
</tr>
-
<tr><td>AS</td>
<td>
<textarea name="view[as]" rows="<?php echo $cfg['TextareaRows']; ?>"
cols="<?php echo $cfg['TextareaCols']; ?>"
- dir="<?php echo $text_dir; ?>" onfocus="this.select();"
- ><?php echo htmlspecialchars($view['as']); ?></textarea>
+ dir="<?php echo $text_dir; ?>"<?php
+ if ($GLOBALS['cfg']['TextareaAutoSelect'] || true) {
+ echo ' onclick="selectContent(this, sql_box_locked, true)"';
+ }
+ ?>><?php echo htmlspecialchars($view['as']); ?></textarea>
</td>
</tr>
<tr><td>WITH</td>
@@ -161,17 +170,28 @@
}
echo ' id="view_with_' . str_replace(' ', '_', htmlspecialchars($option)) . '"';
echo ' value="' . htmlspecialchars($option) . '" />';
- echo '<label for="view_with_' . str_replace(' ', '_', htmlspecialchars($option)) . '">';
- echo htmlspecialchars($option) . '</label>&nbsp;';
+ echo '<label for="view_with_' . str_replace(' ', '_', htmlspecialchars($option)) . '">&nbsp;';
+ echo htmlspecialchars($option) . '</label><br />';
}
?>
</td>
</tr>
</table>
</fieldset>
+<?php
+ if ($GLOBALS['is_ajax_request'] != true) {
+?>
<fieldset class="tblFooters">
<input type="submit" name="createview" value="<?php echo __('Go'); ?>" />
</fieldset>
+<?php
+ } else {
+?>
+ <input type="hidden" name="createview" value="1" />
+ <input type="hidden" name="ajax_request" value="1" />
+<?php
+ }
+?>
</form>
</div>
<?php
Please sign in to comment.
Something went wrong with that request. Please try again.