Move common code into a function

This commit is contained in:
Marc Delisle
2011-04-24 08:56:54 -04:00
parent 24e05e1cb2
commit 8f16bfbc53
6 changed files with 23 additions and 37 deletions

View File

@@ -34,10 +34,7 @@ $(document).ready(function() {
var question = 'CREATE DATABASE ' + $('#new_db_name').val() + ' / DROP DATABASE ' + window.parent.db; var question = 'CREATE DATABASE ' + $('#new_db_name').val() + ' / DROP DATABASE ' + window.parent.db;
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { PMA_prepareForAjaxRequest($form);
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
/** /**
* @var button_options Object containing options for jQueryUI dialog buttons * @var button_options Object containing options for jQueryUI dialog buttons
*/ */
@@ -95,9 +92,7 @@ $(document).ready(function() {
var $form = $(this); var $form = $(this);
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { PMA_prepareForAjaxRequest($form);
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.get($form.attr('action'), $form.serialize(), function(data) { $.get($form.attr('action'), $form.serialize(), function(data) {
// use messages that stay on screen // use messages that stay on screen
@@ -135,9 +130,7 @@ $(document).ready(function() {
var $form = $(this); var $form = $(this);
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { PMA_prepareForAjaxRequest($form);
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
PMA_ajaxShowMessage(PMA_messages['strChangingCharset']); PMA_ajaxShowMessage(PMA_messages['strChangingCharset']);

View File

@@ -142,10 +142,7 @@ $(document).ready(function() {
// jQuery object to reuse // jQuery object to reuse
$form = $(this); $form = $(this);
// add this hidden field just once PMA_prepareForAjaxRequest($form);
if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(), function(response) { $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(), function(response) {
if (typeof response == 'string') { if (typeof response == 'string') {

View File

@@ -20,6 +20,18 @@ var only_once_elements = new Array();
*/ */
var ajax_message_init = false; var ajax_message_init = false;
/**
* Add a hidden field to the form to indicate that this will be an
* Ajax request (only if this hidden field does not exist)
*
* @param object the form
*/
function PMA_prepareForAjaxRequest($form) {
if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
}
/** /**
* Generate a new password and copy it to the password input areas * Generate a new password and copy it to the password input areas
* *
@@ -1403,9 +1415,7 @@ $(document).ready(function() {
button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();} button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();}
var $msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { PMA_prepareForAjaxRequest($form);
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.get($form.attr('action'), $form.serialize(), function(data) { $.get($form.attr('action'), $form.serialize(), function(data) {
//in the case of an error, show the error message returned. //in the case of an error, show the error message returned.
@@ -1467,9 +1477,7 @@ $(document).ready(function() {
// OK, form passed validation step // OK, form passed validation step
if ($form.hasClass('ajax')) { if ($form.hasClass('ajax')) {
PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { PMA_prepareForAjaxRequest($form);
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
//User wants to submit the form //User wants to submit the form
$.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) { $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
if(data.success == true) { if(data.success == true) {
@@ -1561,9 +1569,7 @@ $(document).ready(function() {
var $form = $("#create_table_form"); var $form = $("#create_table_form");
var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { PMA_prepareForAjaxRequest($form);
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
//User wants to add more fields to the table //User wants to add more fields to the table
$.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) { $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=" + $(this).val(), function(data) {
@@ -1670,10 +1676,7 @@ $(document).ready(function() {
$form = $(this); $form = $(this);
PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
PMA_prepareForAjaxRequest($form);
if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.post($form.attr('action'), $form.serialize(), function(data) { $.post($form.attr('action'), $form.serialize(), function(data) {
if(data.success == true) { if(data.success == true) {

View File

@@ -254,9 +254,7 @@ $(document).ready(function() {
$form = $(this); $form = $(this);
var $msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { PMA_prepareForAjaxRequest($form);
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.post($(this).attr('action'), $(this).serialize() , function(data) { $.post($(this).attr('action'), $(this).serialize() , function(data) {
if(data.success == true) { if(data.success == true) {

View File

@@ -283,9 +283,7 @@ $(document).ready(function() {
event.preventDefault(); event.preventDefault();
PMA_ajaxShowMessage(); PMA_ajaxShowMessage();
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { PMA_prepareForAjaxRequest($form);
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.post($form.attr('action'), $form.serialize(), function(data) { $.post($form.attr('action'), $form.serialize(), function(data) {
if (typeof data.success != 'undefined') { if (typeof data.success != 'undefined') {

View File

@@ -60,10 +60,7 @@ $(document).ready(function() {
$("#sqlqueryresults").empty(); $("#sqlqueryresults").empty();
var msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']); var msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']);
// add this hidden field just once PMA_prepareForAjaxRequest($search_form);
if (! $search_form.find('input:hidden').is('#ajax_request_hidden')) {
$search_form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
$.post($search_form.attr('action'), $search_form.serialize(), function(response) { $.post($search_form.attr('action'), $search_form.serialize(), function(response) {
if (typeof response == 'string') { if (typeof response == 'string') {