Get default_fk_check_value on demand rather than checking the value in every script

Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
This commit is contained in:
Madhura Jayaratne 2015-06-22 08:36:46 +05:30
parent b31b92032a
commit f889561c59
5 changed files with 49 additions and 22 deletions

View File

@ -245,7 +245,7 @@ AJAX.registerOnload('db_structure.js', function () {
*/
var question = PMA_messages.strTruncateTableStrongWarning + ' '
+ PMA_sprintf(PMA_messages.strDoYouReally, 'TRUNCATE ' + escapeHtml(curr_table_name))
+ getForeignKeyCheckbox();
+ getForeignKeyCheckboxLoader();
$this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function (url) {
@ -273,7 +273,7 @@ AJAX.registerOnload('db_structure.js', function () {
PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest + " : " + data.error, false);
}
}); // end $.get()
}); //end $.PMA_confirm()
}, loadForeignKeyCheckbox); //end $.PMA_confirm()
}); //end of Truncate Table Ajax action
/**
@ -308,7 +308,7 @@ AJAX.registerOnload('db_structure.js', function () {
question =
PMA_sprintf(PMA_messages.strDoYouReally, 'DROP VIEW ' + escapeHtml(curr_table_name));
}
question += getForeignKeyCheckbox();
question += getForeignKeyCheckboxLoader();
$this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function (url) {
@ -328,7 +328,7 @@ AJAX.registerOnload('db_structure.js', function () {
PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest + " : " + data.error, false);
}
}); // end $.get()
}); // end $.PMA_confirm()
}, loadForeignKeyCheckbox); // end $.PMA_confirm()
}); //end of Drop Table Ajax action
/**

View File

@ -1695,18 +1695,33 @@ function pdfPaperSize(format, axis)
*
* @return string
*/
function getForeignKeyCheckbox() {
default_fk_check_value = PMA_commonParams.get('default_fk_check_value');
var html = "";
html += "<div>";
html += "<input type=\"hidden\" name=\"fk_checks\" value=\"0\" />";
html += "<input type=\"checkbox\" name=\"fk_checks\""
+ " id=\"fk_checks\"" + (default_fk_check_value ? " checked=\"checked\"" : "") + " />";
html += "<label for=\"fk_checks\">" + PMA_messages.strForeignKeyCheck + "</label>";
html += "</div>";
function getForeignKeyCheckboxLoader() {
var html = '';
html += '<div>';
html += '<div class="load-default-fk-check-value">';
html += PMA_getImage('ajax_clock_small.gif');
html += '</div>';
html += '</div>';
return html;
}
function loadForeignKeyCheckbox() {
// Load default foreign key check value
var params = {
'ajax_request': true,
'token': PMA_commonParams.get('token'),
'server': PMA_commonParams.get('server'),
'get_default_fk_check_value': true
};
$.get('sql.php', params, function (data) {
var html = '<input type="hidden" name="fk_checks" value="0" />'
+ '<input type="checkbox" name="fk_checks" id="fk_checks"'
+ (data.default_fk_check_value ? ' checked="checked"' : '') + ' />'
+ '<label for="fk_checks">' + PMA_messages.strForeignKeyCheck + '</label>';
$('.load-default-fk-check-value').replaceWith(html);
});
}
function getJSConfirmCommonParam(elem) {
return {
'is_js_confirmed' : 1,
@ -1765,7 +1780,7 @@ AJAX.registerOnload('functions.js', function () {
var old_text = $inner_sql.html();
var new_content = "<textarea name=\"sql_query_edit\" id=\"sql_query_edit\">" + sql_query + "</textarea>\n";
new_content += getForeignKeyCheckbox();
new_content += getForeignKeyCheckboxLoader();
new_content += "<input type=\"submit\" id=\"sql_query_edit_save\" class=\"button btnSave\" value=\"" + PMA_messages.strGo + "\"/>\n";
new_content += "<input type=\"button\" id=\"sql_query_edit_discard\" class=\"button btnDiscard\" value=\"" + PMA_messages.strCancel + "\"/>\n";
var $editor_area = $('div#inline_editor');
@ -1774,6 +1789,7 @@ AJAX.registerOnload('functions.js', function () {
$editor_area.insertBefore($inner_sql);
}
$editor_area.html(new_content);
loadForeignKeyCheckbox();
$inner_sql.hide();
bindCodeMirrorToInlineEditor();
@ -2595,12 +2611,13 @@ function PMA_SQLPrettyPrint(string)
* return a jQuery object yet and hence cannot be chained
*
* @param string question
* @param string url URL to be passed to the callbackFn to make
* @param string url URL to be passed to the callbackFn to make
* an Ajax call to
* @param function callbackFn callback to execute after user clicks on OK
* @param function callbackFn callback to execute after user clicks on OK
* @param function openCallback optional callback to run when dialog is shown
*/
jQuery.fn.PMA_confirm = function (question, url, callbackFn) {
jQuery.fn.PMA_confirm = function (question, url, callbackFn, openCallback) {
var confirmState = PMA_commonParams.get('confirm');
if (! confirmState) {
// user does not want to confirm
@ -2644,6 +2661,7 @@ jQuery.fn.PMA_confirm = function (question, url, callbackFn) {
close: function () {
$(this).remove();
},
open: openCallback,
modal: true
});
};

View File

@ -203,7 +203,7 @@ AJAX.registerOnload('tbl_operations.js', function () {
question += PMA_sprintf(
PMA_messages.strDoYouReally,
'DROP TABLE ' + escapeHtml(PMA_commonParams.get('table'))
) + getForeignKeyCheckbox();
) + getForeignKeyCheckboxLoader();
$(this).PMA_confirm(question, $(this).attr('href'), function (url) {
@ -227,7 +227,7 @@ AJAX.registerOnload('tbl_operations.js', function () {
PMA_ajaxShowMessage(data.error, false);
}
}); // end $.get()
}); // end $.PMA_confirm()
}, loadForeignKeyCheckbox); // end $.PMA_confirm()
}); //end of Drop Table Ajax action
$(document).on('click', "#drop_view_anchor.ajax", function (event) {
@ -272,7 +272,7 @@ AJAX.registerOnload('tbl_operations.js', function () {
question += PMA_sprintf(
PMA_messages.strDoYouReally,
'TRUNCATE ' + escapeHtml(PMA_commonParams.get('table'))
) + getForeignKeyCheckbox();
) + getForeignKeyCheckboxLoader();
$(this).PMA_confirm(question, $(this).attr('href'), function (url) {
PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
@ -294,7 +294,7 @@ AJAX.registerOnload('tbl_operations.js', function () {
PMA_ajaxShowMessage(data.error, false);
}
}); // end $.get()
}); // end $.PMA_confirm()
}, loadForeignKeyCheckbox); // end $.PMA_confirm()
}); //end of Truncate Table Ajax action
}); //end $(document).ready for 'Table operations'

View File

@ -257,7 +257,6 @@ class PMA_Header
'confirm' => $GLOBALS['cfg']['Confirm'],
'LoginCookieValidity' => $GLOBALS['cfg']['LoginCookieValidity'],
'logged_in' => isset($GLOBALS['userlink']) ? true : false,
'default_fk_check_value' => PMA_Util::getDefaultFKCheckValue() ? 1 : 0
);
if (isset($GLOBALS['cfg']['Server'])
&& isset($GLOBALS['cfg']['Server']['auth_type'])

10
sql.php
View File

@ -109,6 +109,16 @@ if (isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) {
// script has exited at this point
}
if (isset($_REQUEST['get_default_fk_check_value'])
&& $_REQUEST['get_default_fk_check_value'] == true
) {
$response = PMA_Response::getInstance();
$response->addJSON(
'default_fk_check_value', PMA_Util::getDefaultFKCheckValue()
);
exit;
}
/**
* Check ajax request to set the column order and visibility
*/