Share code for parsing data-post attribute

It can include leading question mark and we should deal with it in all
locations.

Fixes #13913

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2018-01-08 17:35:32 +01:00
parent d070e4a60f
commit 1fc566fd90
6 changed files with 24 additions and 14 deletions

View File

@ -283,15 +283,11 @@ var AJAX = {
var url = isLink ? href : $(this).attr('action');
var params = 'ajax_request=true&ajax_page_request=true';
var dataPost = AJAX.source.attr('data-post');
var dataPost = AJAX.source.getPostData();
if (! isLink) {
params += '&' + $(this).serialize();
} else if (dataPost) {
// Strip possible leading ?
if (dataPost.startsWith('?')) {
dataPost = dataPost.substr(1);
}
params += '&' + AJAX.source.attr('data-post');
params += '&' + dataPost;
isLink = false;
}
if (! (history && history.pushState)) {

View File

@ -298,7 +298,7 @@ AJAX.registerOnload('db_structure.js', function () {
$this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function (url) {
PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
var params = getJSConfirmCommonParam(this, $this_anchor.attr('data-post'));
var params = getJSConfirmCommonParam(this, $this_anchor.getPostData());
$.post(url, params, function (data) {
if (typeof data !== 'undefined' && data.success === true) {
@ -360,7 +360,7 @@ AJAX.registerOnload('db_structure.js', function () {
$this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function (url) {
var $msg = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
var params = getJSConfirmCommonParam(this, $this_anchor.attr('data-post'));
var params = getJSConfirmCommonParam(this, $this_anchor.getPostData());
$.post(url, params, function (data) {
if (typeof data !== 'undefined' && data.success === true) {

View File

@ -5086,3 +5086,16 @@ function configGet(key, cached=true)
});
return JSON.parse(localStorage.getItem(key));
}
/**
* Return POST data as stored by Util::linkOrButton
*/
jQuery.fn.getPostData = function() {
var dataPost = this.attr('data-post');
// Strip possible leading ?
if (dataPost.startsWith('?')) {
dataPost = dataPost.substr(1);
}
return dataPost;
};

View File

@ -401,7 +401,7 @@ RTE.COMMON = {
* the AJAX message shown to the user
*/
var $msg = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
var params = getJSConfirmCommonParam(this, $this.attr('data-post'));
var params = getJSConfirmCommonParam(this, $this.getPostData());
$.post(url, params, function (data) {
if (data.success === true) {
/**
@ -476,7 +476,7 @@ RTE.COMMON = {
* @var $curr_row Object containing reference to the current row
*/
var $curr_row = $anchor.parents('tr');
var params = getJSConfirmCommonParam(this, $anchor.attr('data-post'));
var params = getJSConfirmCommonParam(this, $anchor.getPostData());
$.post($anchor.attr('href'), params, function (data) {
returnCount++;
if (data.success === true) {

View File

@ -188,8 +188,9 @@ AJAX.registerOnload('sql.js', function () {
$link.PMA_confirm(question, $link.attr('href'), function (url) {
$msgbox = PMA_ajaxShowMessage();
var params = 'ajax_request=1&is_js_confirmed=1';
if ($link.attr('data-post')) {
params += '&' + $link.attr('data-post');
var postData = $link.getPostData();
if (postData) {
params += '&' + postData;
}
$.post(url, params, function (data) {
if (data.success) {

View File

@ -183,7 +183,7 @@ AJAX.registerOnload('tbl_structure.js', function () {
var $this_anchor = $(this);
$this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function (url) {
var $msg = PMA_ajaxShowMessage(PMA_messages.strDroppingColumn, false);
var params = getJSConfirmCommonParam(this, $this_anchor.attr('data-post'));
var params = getJSConfirmCommonParam(this, $this_anchor.getPostData());
params += '&ajax_page_request=1';
$.post(url, params, function (data) {
if (typeof data !== 'undefined' && data.success === true) {
@ -269,7 +269,7 @@ AJAX.registerOnload('tbl_structure.js', function () {
PMA_ajaxShowMessage();
AJAX.source = $this;
var params = getJSConfirmCommonParam(this, $this_anchor.attr('data-post'));
var params = getJSConfirmCommonParam(this, $this_anchor.getPostData());
params += '&ajax_page_request=1';
$.post(url, params, AJAX.responseHandler);
}); // end $.PMA_confirm()