Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds features discussed in #13023 #14436

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion js/ajax.js
Expand Up @@ -506,7 +506,13 @@ var AJAX = {
AJAX._callback = function () {};
});
} else {
PMA_ajaxShowMessage(data.error, false);
PMA_ajaxRemoveMessage(AJAX.$msgbox);
$('div.error, div.success, div#ajaxError').remove();
$ajaxError = $('<div/>');
$ajaxError.attr({ 'id': 'ajaxError' });
$('#page_content').append($ajaxError);
$ajaxError.html(data.error);
$('html, body').animate({ scrollTop: $(document).height() }, 200);
AJAX.active = false;
AJAX.xhr = null;
PMA_handleRedirectAndReload(data);
Expand Down
35 changes: 35 additions & 0 deletions js/functions.js
Expand Up @@ -2440,6 +2440,41 @@ $(function () {
$(this).parents('span.ajax_notification').tooltip('enable');
}
});

/**
* Copy text to clipboard
*
* @param text to copy to clipboard
*
* @returns bool true|false
*/
function copyToClipboard (text) {
var $temp = $('<input>');
$temp.css({ 'position': 'fixed', 'width': '2em', 'border': 0, 'top': 0, 'left': 0, 'padding': 0, 'background': 'transparent' });
$('body').append($temp);
$temp.val(text).select();
try {
var res = document.execCommand('copy');
$temp.remove();
return res;
} catch (e) {
$temp.remove();
return false;
}
}

$(document).on('click', 'a.copyQueryBtn', function (event) {
event.preventDefault();
var res = copyToClipboard($(this).attr('data-text'));
if (res) {
$(this).after('<span id=\'copyStatus\'> (Successfully copied!)</span>');
MauricioFauth marked this conversation as resolved.
Show resolved Hide resolved
} else {
$(this).after('<span id=\'copyStatus\'> (Coping Unsuccessful!)</span>');
MauricioFauth marked this conversation as resolved.
Show resolved Hide resolved
}
setTimeout(function () {
$('#copyStatus').remove();
}, 2000);
});
});

/**
Expand Down
1 change: 1 addition & 0 deletions js/sql.js
Expand Up @@ -654,6 +654,7 @@ AJAX.registerOnload('sql.js', function () {
$sqlqueryresultsouter
.show()
.html(data.error);
$('html, body').animate({ scrollTop: $(document).height() }, 200);
}
PMA_ajaxRemoveMessage($msgbox);
}); // end $.post()
Expand Down
16 changes: 15 additions & 1 deletion libraries/classes/Util.php
Expand Up @@ -295,6 +295,20 @@ public static function formatSql($sqlQuery, $truncate = false)
. '</pre></code>';
} // end of the "formatSql()" function

/**
* Displays a button to copy content to clipboard
*
* @param string $text Text to copy to clipboard
*
* @return string the html link
*
* @access public
*/
public static function showCopyToClipboard($text) {
$open_link = ' <a href="#" class="copyQueryBtn" data-text="' . $text . '">' . __('Copy') . '</a>';
return $open_link;
} // end of the 'showCopyToClipboard()' function

/**
* Displays a link to the documentation as an icon
*
Expand Down Expand Up @@ -565,7 +579,7 @@ public static function mysqlDie(
}

// Display the SQL query and link to MySQL documentation.
$error_msg .= '<p><strong>' . __('SQL query:') . '</strong>' . "\n";
$error_msg .= '<p><strong>' . __('SQL query:') . '</strong>' . self::showCopyToClipboard($sql_query) . "\n";
$formattedSqlToLower = mb_strtolower($formatted_sql);

// TODO: Show documentation for all statement types.
Expand Down