Refactor home.js file

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2022-02-06 08:13:05 -03:00
parent 11c9458e8a
commit 28892052df
2 changed files with 40 additions and 20 deletions

View File

@ -1,4 +1,6 @@
{
"esversion" : 6,
// Show more errors
"maxerr" : 1000,

View File

@ -4,7 +4,7 @@ const GitInfo = {
* @param {string} str
* @return {number | false}
*/
parseVersionString: function (str) {
parseVersionString: str => {
if (typeof(str) !== 'string') {
return false;
}
@ -37,7 +37,7 @@ const GitInfo = {
* Indicates current available version on main page.
* @param {object} data
*/
currentVersion: function (data) {
currentVersion: data => {
if (data && data.version && data.date) {
const current = GitInfo.parseVersionString($('span.version').text());
const latest = GitInfo.parseVersionString(data.version);
@ -96,7 +96,7 @@ const GitInfo = {
/**
* Loads Git revision data from ajax for index.php
*/
displayGitRevision: function () {
displayGitRevision: () => {
$('#is_git_revision').remove();
$('#li_pma_version_git').remove();
$.get(
@ -106,30 +106,22 @@ const GitInfo = {
'ajax_request': true,
'no_debug': true
},
function (data) {
data => {
if (typeof data !== 'undefined' && data.success === true) {
$(data.message).insertAfter('#li_pma_version');
}
}
);
}
};
AJAX.registerTeardown('home.js', function () {
$('#themesModal').off('show.bs.modal');
});
AJAX.registerOnload('home.js', function () {
$('#themesModal').on('show.bs.modal', function () {
$.get('index.php?route=/themes', function (data) {
$('#themesModal .modal-body').html(data.themes);
});
});
},
/**
* Load version information asynchronously.
*/
if ($('li.jsversioncheck').length > 0) {
loadVersion: () => {
if ($('li.jsversioncheck').length === 0) {
return;
}
$.ajax({
dataType: 'json',
url: 'index.php?route=/version-check',
@ -139,9 +131,35 @@ AJAX.registerOnload('home.js', function () {
},
success: GitInfo.currentVersion
});
}
},
showVersion: () => {
GitInfo.loadVersion();
if ($('#is_git_revision').length === 0) {
return;
}
if ($('#is_git_revision').length > 0) {
setTimeout(GitInfo.displayGitRevision, 10);
}
};
/**
* @implements EventListener
*/
const ThemesManager = {
handleEvent: () => {
$.get('index.php?route=/themes', data => {
$('#themesModal .modal-body').html(data.themes);
});
}
};
AJAX.registerTeardown('home.js', () => {
$('#themesModal').off('show.bs.modal');
});
AJAX.registerOnload('home.js', () => {
$('#themesModal').on('show.bs.modal', ThemesManager.handleEvent);
GitInfo.showVersion();
});