Skip to content

Commit

Permalink
Ajaxification for "Bookamrk this SQL query" form
Browse files Browse the repository at this point in the history
  • Loading branch information
roccivic committed Oct 30, 2012
1 parent f8fdc40 commit 03c904b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
15 changes: 15 additions & 0 deletions js/sql.js
Expand Up @@ -60,6 +60,7 @@ function getFieldName($this_field)
* Unbind all event handlers before tearing down a page
*/
AJAX.registerTeardown('sql.js', function() {
$('#bookmarkQueryForm').die('submit');
$('input#bkm_label').unbind('keyup');
$("#sqlqueryresults").die('makegrid');
$("#togglequerybox").unbind('click');
Expand Down Expand Up @@ -88,12 +89,26 @@ AJAX.registerTeardown('sql.js', function() {
* <li>Sort the results table</li>
* <li>Change table according to display options</li>
* <li>Grid editing of data</li>
* <li>Saving a bookmark</li>
* </ul>
*
* @name document.ready
* @memberOf jQuery
*/
AJAX.registerOnload('sql.js', function() {
// Ajaxification for 'Bookmark this SQL query'
$('#bookmarkQueryForm').live('submit', function (e) {
e.preventDefault();
PMA_ajaxShowMessage();
$.post($(this).attr('action'), 'ajax_request=1&' + $(this).serialize(), function (data) {
if (data.success) {
PMA_ajaxShowMessage(data.message);
} else {
PMA_ajaxShowMessage(data.error, false);
}
});
});

/* Hides the bookmarkoptions checkboxes when the bookmark label is empty */
$('input#bkm_label').keyup(function() {
$('input#id_bkm_all_users, input#id_bkm_replace')
Expand Down
36 changes: 26 additions & 10 deletions sql.php
Expand Up @@ -367,14 +367,28 @@
* Bookmark add
*/
if (isset($store_bkm)) {
PMA_Bookmark_save(
$result = PMA_Bookmark_save(
$fields,
(isset($bkm_all_users) && $bkm_all_users == 'true' ? true : false)
);
// go back to sql.php to redisplay query; do not use &amp; in this case:
PMA_sendHeaderLocation(
$cfg['PmaAbsoluteUri'] . $goto . '&label=' . $fields['label']
);
)
$response = PMA_Response::getInstance();
if ($response->isAjax()) {
if ($result) {
$msg = PMA_message::success(__('Bookmark %s created'));
$msg->addParam($fields['label']);
$response->addJSON('message', $msg);
} else {
$msg = PMA_message::error(__('Bookmark not created'));
$response->isSuccess(false);
$response->addJSON('message', $msg);
}
exit;
} else {
// go back to sql.php to redisplay query; do not use &amp; in this case:
PMA_sendHeaderLocation(
$cfg['PmaAbsoluteUri'] . $goto . '&label=' . $fields['label']
);
}
} // end if

/**
Expand Down Expand Up @@ -1233,7 +1247,8 @@
. '&amp;id_bookmark=1';

echo '<form action="sql.php" method="post"'
. ' onsubmit="return emptyFormElements(this, \'fields[label]\');">';
. ' onsubmit="return emptyFormElements(this, \'fields[label]\');"';
. ' id="bookmarkQueryForm">';
echo PMA_generate_common_hidden_inputs();
echo '<input type="hidden" name="goto" value="' . $goto . '" />';
echo '<input type="hidden" name="fields[dbase]"'
Expand Down Expand Up @@ -1264,7 +1279,8 @@
echo '<div class="clearfloat"></div>';
echo '</fieldset>';
echo '<fieldset class="tblFooters">';
echo '<input type="submit" name="store_bkm"'
echo '<input type="hidden" name="store_bkm" value="1" />';
echo '<input type="submit"';
. ' value="' . __('Bookmark this SQL query') . '" />';
echo '</fieldset>';
echo '</form>';
Expand Down Expand Up @@ -1623,13 +1639,13 @@ function PMA_getColumnNameInColumnDropSql($sql)
}

/**
* Verify if the result set contains all the columne of at least one unique key
* Verify if the result set contains all the columne of at least one unique key
*
* @param string $db
* @param string $table
* @param string $fields_meta
*
* @return boolean whether the result set contains a unique key
* @return boolean whether the result set contains a unique key
*/
function PMA_resultSetContainsUniqueKey($db, $table, $fields_meta)
{
Expand Down

0 comments on commit 03c904b

Please sign in to comment.