AJAX handler modified and initial loading of the first page handled
Signed-off-by: Piyush Vijay <piyushvijay.1997@gmail.com>
This commit is contained in:
parent
56ea9d27fc
commit
b712019735
229
js/messages.php
229
js/messages.php
@ -755,6 +755,26 @@ foreach ($js_messages as $name => $js_message) {
|
||||
Sanitize::printJsValue("PMA_messages['" . $name . "']", $js_message);
|
||||
}
|
||||
|
||||
/* for new js code */
|
||||
/* Calendar */
|
||||
echo "var globalVars = new Array();\n";
|
||||
echo "globalVars['themeCalendarImage'] = '" , $GLOBALS['pmaThemeImage']
|
||||
, 'b_calendar.png' , "';\n";
|
||||
|
||||
/* Image path */
|
||||
echo "globalVars['pmaThemeImage'] = '" , $GLOBALS['pmaThemeImage'] , "';\n";
|
||||
|
||||
echo "globalVars['mysql_doc_template'] = '" , PhpMyAdmin\Util::getMySQLDocuURL('%s')
|
||||
, "';\n";
|
||||
|
||||
//Max input vars allowed by PHP.
|
||||
$maxInputVars = ini_get('max_input_vars');
|
||||
echo "globalVars['maxInputVars'] = '"
|
||||
, (false === $maxInputVars || '' == $maxInputVars ? 'false' : (int)$maxInputVars)
|
||||
, ';' . "'\n";
|
||||
/* for new js code */
|
||||
|
||||
/* for old js code */
|
||||
/* Calendar */
|
||||
echo "var themeCalendarImage = '" , $GLOBALS['pmaThemeImage']
|
||||
, 'b_calendar.png' , "';\n";
|
||||
@ -770,7 +790,146 @@ $maxInputVars = ini_get('max_input_vars');
|
||||
echo 'var maxInputVars = '
|
||||
, (false === $maxInputVars || '' == $maxInputVars ? 'false' : (int)$maxInputVars)
|
||||
, ';' . "\n";
|
||||
/* for old js code */
|
||||
|
||||
/* for new js code */
|
||||
/* extending jquery-ui-timepicker-addon if ($.datepicker)
|
||||
$.extend($.datepicker._defaults, $.datepicker.regional['']); */
|
||||
|
||||
echo "var timePicker = new Array();\n";
|
||||
/* l10n: Display text for calendar close link */
|
||||
Sanitize::printJsValue("timePicker['closeText']", __('Done'));
|
||||
/* l10n: Display text for previous month link in calendar */
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['prevText']",
|
||||
_pgettext('Previous month', 'Prev')
|
||||
);
|
||||
/* l10n: Display text for next month link in calendar */
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['nextText']",
|
||||
_pgettext('Next month', 'Next')
|
||||
);
|
||||
/* l10n: Display text for current month link in calendar */
|
||||
Sanitize::printJsValue("timePicker['currentText']", __('Today'));
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['monthNames']",
|
||||
array(
|
||||
__('January'),
|
||||
__('February'),
|
||||
__('March'),
|
||||
__('April'),
|
||||
__('May'),
|
||||
__('June'),
|
||||
__('July'),
|
||||
__('August'),
|
||||
__('September'),
|
||||
__('October'),
|
||||
__('November'),
|
||||
__('December')
|
||||
)
|
||||
);
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['monthNamesShort']",
|
||||
array(
|
||||
/* l10n: Short month name */
|
||||
__('Jan'),
|
||||
/* l10n: Short month name */
|
||||
__('Feb'),
|
||||
/* l10n: Short month name */
|
||||
__('Mar'),
|
||||
/* l10n: Short month name */
|
||||
__('Apr'),
|
||||
/* l10n: Short month name */
|
||||
_pgettext('Short month name', 'May'),
|
||||
/* l10n: Short month name */
|
||||
__('Jun'),
|
||||
/* l10n: Short month name */
|
||||
__('Jul'),
|
||||
/* l10n: Short month name */
|
||||
__('Aug'),
|
||||
/* l10n: Short month name */
|
||||
__('Sep'),
|
||||
/* l10n: Short month name */
|
||||
__('Oct'),
|
||||
/* l10n: Short month name */
|
||||
__('Nov'),
|
||||
/* l10n: Short month name */
|
||||
__('Dec')
|
||||
)
|
||||
);
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['dayNames']",
|
||||
array(
|
||||
__('Sundayada'),
|
||||
__('Monday'),
|
||||
__('Tuesday'),
|
||||
__('Wednesday'),
|
||||
__('Thursday'),
|
||||
__('Friday'),
|
||||
__('Saturday')
|
||||
)
|
||||
);
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['dayNamesShort']",
|
||||
array(
|
||||
/* l10n: Short week day name */
|
||||
__('Sun'),
|
||||
/* l10n: Short week day name */
|
||||
__('Mon'),
|
||||
/* l10n: Short week day name */
|
||||
__('Tue'),
|
||||
/* l10n: Short week day name */
|
||||
__('Wed'),
|
||||
/* l10n: Short week day name */
|
||||
__('Thu'),
|
||||
/* l10n: Short week day name */
|
||||
__('Fri'),
|
||||
/* l10n: Short week day name */
|
||||
__('Sat')
|
||||
)
|
||||
);
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['dayNamesMin']",
|
||||
array(
|
||||
/* l10n: Minimal week day name */
|
||||
__('Su'),
|
||||
/* l10n: Minimal week day name */
|
||||
__('Mo'),
|
||||
/* l10n: Minimal week day name */
|
||||
__('Tu'),
|
||||
/* l10n: Minimal week day name */
|
||||
__('We'),
|
||||
/* l10n: Minimal week day name */
|
||||
__('Th'),
|
||||
/* l10n: Minimal week day name */
|
||||
__('Fr'),
|
||||
/* l10n: Minimal week day name */
|
||||
__('Sa')
|
||||
)
|
||||
);
|
||||
/* l10n: Column header for week of the year in calendar */
|
||||
Sanitize::printJsValue("timePicker['weekHeader']", __('Wk'));
|
||||
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['showMonthAfterYear']",
|
||||
/* l10n: Month-year order for calendar, use either "calendar-month-year"
|
||||
* or "calendar-year-month".
|
||||
*/
|
||||
(__('calendar-month-year') == 'calendar-year-month')
|
||||
);
|
||||
/* l10n: Year suffix for calendar, "none" is empty. */
|
||||
$year_suffix = _pgettext('Year suffix', 'none');
|
||||
Sanitize::printJsValue(
|
||||
"timePicker['yearSuffix']",
|
||||
($year_suffix == 'none' ? '' : $year_suffix)
|
||||
);
|
||||
Sanitize::printJsValue("timePicker['timeText']", __('Time'));
|
||||
Sanitize::printJsValue("timePicker['hourText']", __('Hour'));
|
||||
Sanitize::printJsValue("timePicker['minuteText']", __('Minute'));
|
||||
Sanitize::printJsValue("timePicker['secondText']", __('Second'));
|
||||
/* for new js code */
|
||||
|
||||
/* for old js code */
|
||||
echo "if ($.datepicker) {\n";
|
||||
/* l10n: Display text for calendar close link */
|
||||
Sanitize::printJsValue("$.datepicker.regional['']['closeText']", __('Done'));
|
||||
@ -908,11 +1067,80 @@ Sanitize::printJsValue("$.timepicker.regional['']['timeText']", __('Time'));
|
||||
Sanitize::printJsValue("$.timepicker.regional['']['hourText']", __('Hour'));
|
||||
Sanitize::printJsValue("$.timepicker.regional['']['minuteText']", __('Minute'));
|
||||
Sanitize::printJsValue("$.timepicker.regional['']['secondText']", __('Second'));
|
||||
/* for old js code */
|
||||
?>
|
||||
$.extend($.timepicker._defaults, $.timepicker.regional['']);
|
||||
} /* if ($.timepicker) */
|
||||
|
||||
<?php
|
||||
/* for new js code */
|
||||
/* Form validation */
|
||||
/* extending jquery form validation $.extend($.validator.messages, obj) */
|
||||
|
||||
/* Default validation functions */
|
||||
echo "var validationMessage = {\n";
|
||||
Sanitize::printJsValueForFormValidation('required', __('This field is required'));
|
||||
Sanitize::printJsValueForFormValidation('remote', __('Please fix this field'));
|
||||
Sanitize::printJsValueForFormValidation('email', __('Please enter a valid email address'));
|
||||
Sanitize::printJsValueForFormValidation('url', __('Please enter a valid URL'));
|
||||
Sanitize::printJsValueForFormValidation('date', __('Please enter a valid date'));
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'dateISO',
|
||||
__('Please enter a valid date ( ISO )')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation('number', __('Please enter a valid number'));
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'creditcard',
|
||||
__('Please enter a valid credit card number')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation('digits', __('Please enter only digits'));
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'equalTo',
|
||||
__('Please enter the same value again')
|
||||
);
|
||||
echo "\n};\n";
|
||||
echo "var validateFormat = {\n";
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'maxlength',
|
||||
__('Please enter no more than {0} characters')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'minlength',
|
||||
__('Please enter at least {0} characters')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'rangelength',
|
||||
__('Please enter a value between {0} and {1} characters long')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'range',
|
||||
__('Please enter a value between {0} and {1}')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'max',
|
||||
__('Please enter a value less than or equal to {0}')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'min',
|
||||
__('Please enter a value greater than or equal to {0}')
|
||||
);
|
||||
/* customed functions */
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'validationFunctionForDateTime',
|
||||
__('Please enter a valid date or time')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'validationFunctionForHex',
|
||||
__('Please enter a valid HEX input')
|
||||
);
|
||||
Sanitize::printJsValueForFormValidation(
|
||||
'validationFunctionForFuns',
|
||||
__('Error')
|
||||
);
|
||||
echo "\n};\n";
|
||||
/* for new js code */
|
||||
|
||||
/* for old js code */
|
||||
/* Form validation */
|
||||
|
||||
echo "function extendingValidatorMessages() {\n";
|
||||
@ -986,4 +1214,5 @@ Sanitize::printJsValueForFormValidation(
|
||||
);
|
||||
echo "\n});";
|
||||
echo "\n} /* if ($.validator) */";
|
||||
/* for old js code */
|
||||
?>
|
||||
|
||||
@ -363,6 +363,7 @@ export let AJAX = {
|
||||
* @return void
|
||||
*/
|
||||
responseHandler: function (data) {
|
||||
// console.log(data);
|
||||
if (typeof data === 'undefined' || data === null) {
|
||||
return;
|
||||
}
|
||||
@ -561,14 +562,33 @@ export let AJAX = {
|
||||
*
|
||||
* @return self For chaining
|
||||
*/
|
||||
add: function (file, fire) {
|
||||
add: function (file, fire, callback) {
|
||||
var self = this;
|
||||
this._scripts.push(file);
|
||||
if (fire) {
|
||||
// Record whether to fire any events for the file
|
||||
// This is necessary to correctly tear down the initial page
|
||||
this._scriptsToBeFired.push(file);
|
||||
}
|
||||
var fileImports = ['server_privileges', 'server_databases'];
|
||||
if ($.inArray(file, fileImports) !== -1) {
|
||||
console.log('import_check');
|
||||
import(`./${file}`)
|
||||
.then((module) => {
|
||||
for (var i in module) {
|
||||
if (i.indexOf('onload') !== -1) {
|
||||
AJAX.registerOnload(`${file}`, module[i]);
|
||||
} else if (i.indexOf('teardown') !== -1) {
|
||||
AJAX.registerTeardown(file, module[i]);
|
||||
}
|
||||
}
|
||||
AJAX.fireOnload(file);
|
||||
// AJAX.fireTeardown('server_databases_new.js');
|
||||
})
|
||||
.catch(e => console.log(e));
|
||||
}
|
||||
return this;
|
||||
|
||||
},
|
||||
/**
|
||||
* Download a list of js files in one request
|
||||
@ -604,7 +624,7 @@ export let AJAX = {
|
||||
var script = files[i].name;
|
||||
// Only for scripts that we don't already have
|
||||
if ($.inArray(script, self._scripts) === -1) {
|
||||
this.add(script);
|
||||
this.add(script, 0, callback);
|
||||
}
|
||||
self.done(script, callback);
|
||||
}
|
||||
|
||||
6
js/src/consts/files.js
Normal file
6
js/src/consts/files.js
Normal file
@ -0,0 +1,6 @@
|
||||
const files = {
|
||||
server_privileges: ['server_privileges'],
|
||||
server_databases: ['server_databases']
|
||||
};
|
||||
|
||||
export default files;
|
||||
@ -1,5 +1,18 @@
|
||||
import { AJAX } from './ajax';
|
||||
import './variables/import_variables';
|
||||
import { jQuery as $ } from './utils/extend_jquery';
|
||||
import files from './consts/files';
|
||||
|
||||
/**
|
||||
* This block of code is for importing javascript files needed
|
||||
* for the first time loading of the page.
|
||||
*/
|
||||
let firstPage = window.location.pathname.replace('/', '').replace('.php', '');
|
||||
if (typeof files[firstPage] !== 'undefined') {
|
||||
for (let i in files[firstPage]) {
|
||||
AJAX.scriptHandler.add(files[firstPage][i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Page load event handler
|
||||
@ -73,28 +86,27 @@ $(function () {
|
||||
$(document).on('click', 'a', AJAX.requestHandler);
|
||||
$(document).on('submit', 'form', AJAX.requestHandler);
|
||||
|
||||
import('./server_databases')
|
||||
.then((module) => {
|
||||
|
||||
console.log('adasdsadassadasdsasad');
|
||||
AJAX.registerOnload('server_databases_new.js', module.onload1);
|
||||
AJAX.registerTeardown('server_databases_new.js', module.teardown1);
|
||||
AJAX.fireOnload('server_databases_new.js');
|
||||
// AJAX.fireTeardown('server_databases_new.js');
|
||||
// import('./server_databases')
|
||||
// .then((module) => {
|
||||
// console.log('serverr_databases');
|
||||
// AJAX.registerOnload('server_databases_new.js', module.onload1);
|
||||
// AJAX.registerTeardown('server_databases_new.js', module.teardown1);
|
||||
// AJAX.fireOnload('server_databases_new.js');
|
||||
// // AJAX.fireTeardown('server_databases_new.js');
|
||||
|
||||
|
||||
})
|
||||
.catch(e => console.log(e));
|
||||
// })
|
||||
// .catch(e => console.log(e));
|
||||
|
||||
if( 1 === 1 ) {
|
||||
import('./server_privileges')
|
||||
.then((module) => {
|
||||
AJAX.registerOnload('server_privileges_new.js', module.onload1);
|
||||
AJAX.registerTeardown('server_privileges_new.js', module.teardown1);
|
||||
AJAX.fireOnload('server_privileges_new.js');
|
||||
// AJAX.fireTeardown('server_databases_new.js');
|
||||
})
|
||||
.catch(e => console.log(e));
|
||||
}
|
||||
// if( 1 === 1 ) {
|
||||
// import('./server_privileges')
|
||||
// .then((module) => {
|
||||
// AJAX.registerOnload('server_privileges_new.js', module.onload1);
|
||||
// AJAX.registerTeardown('server_privileges_new.js', module.teardown1);
|
||||
// AJAX.fireOnload('server_privileges_new.js');
|
||||
// // AJAX.fireTeardown('server_databases_new.js');
|
||||
// })
|
||||
// .catch(e => console.log(e));
|
||||
// }
|
||||
|
||||
// server_databases();
|
||||
|
||||
@ -84,7 +84,7 @@ class ServerDatabasesController extends Controller
|
||||
|
||||
$header = $this->response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('server_databases.js');
|
||||
$scripts->addFile('server_databases');
|
||||
|
||||
$this->_setSortDetails();
|
||||
$this->_dbstats = empty($_REQUEST['dbstats']) ? false : true;
|
||||
|
||||
@ -164,19 +164,18 @@ class Header
|
||||
private function _addDefaultScripts(): void
|
||||
{
|
||||
// Localised strings
|
||||
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.min.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery-migrate.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.min.js');/////////////////////
|
||||
$this->_scripts->addFile('vendor/jquery/jquery-migrate.js');/////////////////
|
||||
$this->_scripts->addFile('whitelist.php');
|
||||
$this->_scripts->addFile('vendor/sprintf.js');
|
||||
$this->_scripts->addFile('ajax.js');
|
||||
$this->_scripts->addFile('keyhandler.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery-ui.min.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery-ui.min.js');/////////////////
|
||||
$this->_scripts->addFile('vendor/js.cookie.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.mousewheel.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.event.drag-2.2.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.validate.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery-ui-timepicker-addon.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.mousewheel.js');/////////////
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.event.drag-2.2.js');/////////
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.validate.js');///////////////
|
||||
$this->_scripts->addFile('vendor/jquery/jquery-ui-timepicker-addon.js');////
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.ba-hashchange-1.3.js');
|
||||
$this->_scripts->addFile('vendor/jquery/jquery.debounce-1.0.5.js');
|
||||
$this->_scripts->addFile('menu_resizer.js');
|
||||
@ -185,6 +184,8 @@ class Header
|
||||
// the user preferences have not been merged at this point
|
||||
|
||||
$this->_scripts->addFile('messages.php', array('l' => $GLOBALS['lang']));
|
||||
$this->_scripts->addFile('common_params.php', array('l' => $GLOBALS['lang']));
|
||||
$this->_scripts->addFile('index_new.js');
|
||||
|
||||
// Cross-framing protection
|
||||
if ($GLOBALS['cfg']['AllowThirdPartyFraming'] === false) {
|
||||
|
||||
@ -37,6 +37,8 @@ class Scripts
|
||||
*/
|
||||
private $_code;
|
||||
|
||||
private $_fileName;
|
||||
|
||||
/**
|
||||
* Returns HTML code to include javascript file.
|
||||
*
|
||||
@ -65,7 +67,7 @@ class Scripts
|
||||
}
|
||||
$result .= '<script data-cfasync="false" type="text/javascript" src="' . $src . 'js/dist/'
|
||||
. $value['filename'] . '?' . Header::getVersionParameter() . '"></script>' . "\n";
|
||||
} else {
|
||||
} else if (strpos($value['filename'], ".js") !== false) {
|
||||
$result .= '<script data-cfasync="false" type="text/javascript" src="js/'
|
||||
. $value['filename'] . '?' . Header::getVersionParameter() . '"></script>' . "\n";
|
||||
}
|
||||
@ -137,6 +139,7 @@ class Scripts
|
||||
|| strpos($filename, 'messages.php') !== false
|
||||
|| strpos($filename, 'ajax.js') !== false
|
||||
|| strpos($filename, 'cross_framing_protection.js') !== false
|
||||
|| strpos($filename, 'index_new.js') !== false
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
@ -186,7 +189,6 @@ class Scripts
|
||||
public function getDisplay()
|
||||
{
|
||||
$retval = '';
|
||||
|
||||
if (count($this->_files) > 0) {
|
||||
$retval .= $this->_includeFiles(
|
||||
$this->_files
|
||||
|
||||
@ -35,8 +35,7 @@ $cfgRelation = $relation->getRelationsParam();
|
||||
$response = Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('server_privileges.js');
|
||||
$scripts->addFile('vendor/zxcvbn.js');
|
||||
$scripts->addFile('server_privileges');
|
||||
|
||||
$template = new Template();
|
||||
$serverPrivileges = new Privileges($template);
|
||||
|
||||
@ -25,9 +25,8 @@ require_once 'libraries/replication.inc.php';
|
||||
$response = Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('server_privileges.js');
|
||||
$scripts->addFile('server_privileges');
|
||||
$scripts->addFile('replication.js');
|
||||
$scripts->addFile('vendor/zxcvbn.js');
|
||||
|
||||
$template = new Template();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user