Fix a minor bug and optimize script reload

Signed-Off-By: Lakshay arora <arora.lakshya123@gmail.com>
This commit is contained in:
Lakshay arora 2018-05-23 19:02:31 +05:30
parent 5fd4a006ee
commit 53c85c7bd8
4 changed files with 19 additions and 83 deletions

View File

@ -359,85 +359,12 @@ var AJAX = {
if (typeof data === 'undefined' || data === null) {
return;
}
PMA_ajaxRemoveMessage(AJAX.$msgbox);
if (data._title) {
$('title').replaceWith(data._title);
}
if (data._menu) {
if (history && history.pushState) {
var state = {
url : data._selflink,
menu : data._menu
};
history.replaceState(state, null);
AJAX.handleMenu.replace(data._menu);
} else {
PMA_MicroHistory.menus.replace(data._menu);
PMA_MicroHistory.menus.add(data._menuHash, data._menu);
}
} else if (data._menuHash) {
if (! (history && history.pushState)) {
PMA_MicroHistory.menus.replace(PMA_MicroHistory.menus.get(data._menuHash));
}
}
if (data._disableNaviSettings) {
PMA_disableNaviSettings();
} else {
PMA_ensureNaviSettings(data._selflink);
}
// Remove all containers that may have
// been added outside of #page_content
$('body').children()
.not('#pma_navigation')
.not('#floating_menubar')
.not('#page_nav_icons')
.not('#page_content')
.not('#selflink')
.not('#pma_header')
.not('#pma_footer')
.not('#pma_demo')
.not('#pma_console_container')
.not('#prefs_autoload')
.not("#modalOverlay")
.remove();
PMA_commonParams.set("token", data.new_token);
AJAX.scriptHandler.load([]);
if (data._selflink) {
var source = data._selflink.split('?')[0];
// Check for faulty links
$selflink_replace = {
'import.php': 'tbl_sql.php',
'tbl_chart.php': 'sql.php',
'tbl_gis_visualization.php': 'sql.php'
};
if ($selflink_replace[source]) {
var replacement = $selflink_replace[source];
data._selflink = data._selflink.replace(source, replacement);
}
$('#selflink').find('> a').attr('href', data._selflink);
}
if (data._params) {
PMA_commonParams.setAll(data._params);
} else if(data.new_token){
PMA_commonParams.set("token", data.new_token);
}
if (data._scripts) {
AJAX.scriptHandler.load(data._scripts);
} else {
AJAX.scriptHandler.load([]);
}
if (data._selflink && data._scripts && data._menuHash && data._params) {
if (! (history && history.pushState)) {
PMA_MicroHistory.add(
data._selflink,
data._scripts,
data._menuHash,
data._params,
AJAX.source.attr('rel')
);
}
}
if (data._displayMessage) {
$('#page_content').prepend(data._displayMessage);
PMA_highlightSQL($('#page_content'));
@ -478,10 +405,6 @@ var AJAX = {
}
}
if (data._reloadNavigation) {
PMA_reloadNavigation();
}
PMA_ajaxShowMessage(msg, false);
// bind for php error reporting forms (popup)
$('#pma_ignore_errors_popup').on('click', function () {
@ -500,8 +423,10 @@ var AJAX = {
AJAX.xhr = null;
return;
}
// removet the login modal if the login is successful otherwise show error.
// remove the login modal if the login is successful otherwise show error.
if(typeof data.logged_in !== 'undefined' && data.logged_in == 1) {
AJAX.fireTeardown("functions.js");
AJAX.fireOnload("functions.js");
if($("#modalOverlay").length) {
$("#modalOverlay").remove();
}
@ -512,6 +437,8 @@ var AJAX = {
}
} else if(typeof data.logged_in !== 'undefined' && data.logged_in == 0) {
AJAX.fireTeardown("functions.js");
AJAX.fireOnload("functions.js");
$("#modalOverlay").replaceWith(data.error);
} else {
PMA_ajaxShowMessage(data.error, false);

View File

@ -987,6 +987,9 @@ AJAX.registerOnload('functions.js', function () {
$("#" + $(this).attr("aria-describedby")).dialog("close");
});
$("#input_username").focus();
} else {
PMA_commonParams.set("token", data.new_token);
$("input[name=token]").val(data.new_token);
}
_idleSecondsCounter = 0;
}
@ -4331,6 +4334,9 @@ function PMA_slidingMessage (msg, $obj) {
*/
AJAX.registerOnload('functions.js', function () {
var $elm = $('#sqlquery');
if ($elm.siblings().filter(".CodeMirror").length > 0) {
return;
}
if ($elm.length > 0) {
if (typeof CodeMirror !== 'undefined') {
codemirror_editor = PMA_getSQLEditor($elm);

View File

@ -38,6 +38,10 @@ $(document).ready(function () {
}
});
$(document).on('keydown', function (e) {
//disable the shortcuts when session has timed out.
if ($("#modalOverlay").length > 0) {
return;
}
if (e.ctrlKey && e.altKey && e.keyCode === keyC) {
PMA_console.toggle();
}

View File

@ -89,7 +89,6 @@ class AuthenticationCookie extends AuthenticationPlugin
// When sending login modal after session has expired, send the new token explicitly with the response to update the token in all the forms having a hidden token.
$session_expired = isset($_REQUEST['check_timeout']) || isset($_REQUEST['session_timedout']);
if (!$session_expired && $response->loginPage()) {
if (defined('TESTSUITE')) {
return true;
@ -130,7 +129,7 @@ class AuthenticationCookie extends AuthenticationPlugin
$autocomplete = ' autocomplete="off"';
}
// wrap the login form in a div which overlays the whole page.
// wrap the login form in a div which overlays the whole page.
if($session_expired) {
echo $this->template->render('login/header', ['theme' => $GLOBALS['PMA_Theme'], 'add_class' => ' modal_form', 'session_expired' => 1]);
} else {