Correzioni JS per utilizzo nuovi controller

This commit is contained in:
Dasc3er 2021-02-22 16:17:05 +01:00 committed by Thomas Zilio
parent dfab8ff1f3
commit 2430ddd0b6
7 changed files with 60 additions and 95 deletions

View File

@ -371,12 +371,9 @@ function getCookie(cname) {
*/
function renderMessages() {
$.ajax({
url: globals.rootdir + '/ajax.php',
type: 'get',
url: globals.urls.messages,
type: 'GET',
dataType: 'JSON',
data: {
op: 'flash',
},
success: function (messages) {
let info = messages.info ? messages.info : [];
info.forEach(function (element) {

View File

@ -21,14 +21,10 @@
*/
function startHooks() {
$.ajax({
url: globals.rootdir + "/ajax.php",
type: "get",
data: {
op: "hooks",
},
success: function (data) {
hooks = JSON.parse(data);
url: globals.urls.hooks.list,
type: 'GET',
dataType: 'JSON',
success: function (hooks) {
$("#hooks-header").text(globals.translations.hooksExecuting);
$("#hooks-number").text(hooks.length);
@ -54,18 +50,15 @@ function startHooks() {
* Richiama l'hook per l'esecuzione.
*
* @param hook
* @param init
*/
function startHook(hook, init) {
$.ajax({
url: globals.rootdir + "/ajax.php",
type: "get",
data: {
op: "hook-lock",
id: hook.id,
},
success: function (data) {
var token = JSON.parse(data);
url: globals.urls.hooks.lock
.replace('|id|', hook.id),
type: 'GET',
dataType: 'JSON',
success: function (token) {
if (init) {
hookCount("#hooks-counter");
@ -75,7 +68,7 @@ function startHook(hook, init) {
if (token) {
executeHook(hook, token);
} else {
var timeout = 10;
let timeout = 10;
setTimeout(function () {
startHook(hook);
@ -93,18 +86,15 @@ function startHook(hook, init) {
*/
function executeHook(hook, token) {
$.ajax({
url: globals.rootdir + "/ajax.php",
type: "get",
data: {
op: "hook-execute",
id: hook.id,
token: token,
},
success: function (data) {
var result = JSON.parse(data);
url: globals.urls.hooks.execute
.replace('|id|', hook.id)
.replace('|token|', token),
type: 'GET',
dataType: 'JSON',
success: function (result) {
updateHook(hook);
var timeout;
let timeout;
if (result.execute) {
startHook(hook);
} else {
@ -122,23 +112,19 @@ function executeHook(hook, token) {
* Aggiorna le informazioni dell'hook.
*
* @param hook
* @param init
*/
function updateHook(hook) {
$.ajax({
url: globals.rootdir + "/ajax.php",
type: "get",
data: {
op: "hook-response",
id: hook.id,
},
success: function (data) {
var result = JSON.parse(data);
url: globals.urls.hooks.response
.replace('|id|', hook.id),
type: 'GET',
dataType: 'JSON',
success: function (result) {
renderHook(hook, result);
// Rimozione eventuale della rotella di caricamento
var counter = $("#hooks-counter").text();
var number = $("#hooks > li").length;
let counter = $("#hooks-counter").text();
let number = $("#hooks > li").length;
if (number == 0) {
$("#hooks-notified").html('<i class="fa fa-check" aria-hidden="true"></i>');
@ -153,7 +139,7 @@ function updateHook(hook) {
if (counter == $("#hooks-number").text()) {
$("#hooks-loading").hide();
var hookMessage;
let hookMessage;
if (number > 1) {
hookMessage = globals.translations.hookMultiple.replace('_NUM_', number);
} else if (number == 1) {
@ -174,8 +160,8 @@ function updateHook(hook) {
function hookCount(id, value) {
value = value ? value : 1;
var element = $(id);
var number = parseInt(element.text());
let element = $(id);
let number = parseInt(element.text());
number = isNaN(number) ? 0 : number;
number += value;
@ -187,16 +173,16 @@ function hookCount(id, value) {
/**
* Genera l'HTML per la visualizzazione degli hook.
*
* @param element_id
* @param hook
* @param result
*/
function renderHook(hook, result) {
if (result.length == 0) return;
var element_id = "hook-" + hook.id;
let element_id = "hook-" + hook.id;
// Inizializzazione
var element = $("#" + element_id);
let element = $("#" + element_id);
if (element.length == 0) {
$("#hooks").append('<li class="hook-element" id="' + element_id + '"></li>');
@ -211,12 +197,12 @@ function renderHook(hook, result) {
}
// Contenuto
var content = '<a href="' + (result.link ? result.link : "#") + '"><i class="' + result.icon + '"></i><span class="small"> ' + result.message + '</span>';
let content = '<a href="' + (result.link ? result.link : "#") + '"><i class="' + result.icon + '"></i><span class="small"> ' + result.message + '</span>';
if (result.progress) {
var current = result.progress.current;
var total = result.progress.total;
var percentage = current / total * 100;
let current = result.progress.current;
let total = result.progress.total;
let percentage = current / total * 100;
percentage = isNaN(percentage) ? 100 : percentage;
percentage = Math.round(percentage * 100) / 100;

View File

@ -22,7 +22,7 @@ include_once __DIR__.'/core.php';
if (!empty($id_record) && !empty($id_module)) {
redirect_legacy(base_url().'/editor.php?id_module='.$id_module.'&id_record='.$id_record);
} elseif (empty($id_module)) {
redirect_legacy(base_url().'/index.php');
redirect_legacy(base_url().'/');
}
include_once AppLegacy::filepath('include|custom|', 'top.php');

View File

@ -44,16 +44,6 @@ ini_set('session.use_only_cookies', '1');
session_set_cookie_params(0, base_url(), null, isHTTPS(true));
session_start();*/
// Lettura della configurazione
$config = AppLegacy::getConfig();
// Redirect al percorso HTTPS se impostato nella configurazione
if (!empty($config['redirectHTTPS']) && !isHTTPS(true)) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
throw new \App\Exceptions\LegacyExitException();
}
/* GESTIONE DEGLI ERRORI */
// Logger per la segnalazione degli errori
$logger = new Monolog\Logger('Logs');
@ -137,12 +127,6 @@ $handler->registerFatalHandler(Monolog\Logger::ERROR);
$dbo = $database = database();
/* INTERNAZIONALIZZAZIONE */
// Istanziamento del gestore delle traduzioni del progetto
$lang = !empty($config['lang']) ? $config['lang'] : (isset($_GET['lang']) ? $_GET['lang'] : null);
$formatter = !empty($config['formatter']) ? $config['formatter'] : [];
//$translator->addLocalePath(base_dir().'/locale');
//$translator->addLocalePath(base_dir().'/modules/*/locale');
//$translator->setLocale($lang, $formatter);
// Individuazione di versione e revisione del progetto
$version = Update::getVersion();
@ -161,7 +145,7 @@ if (!$continue && getURLPath() != slashes(base_url().'/index.php') && !Permissio
auth()->logout();
}
redirect_legacy(base_url().'/index.php');
redirect_legacy(base_url().'/');
throw new \App\Exceptions\LegacyExitException();
}
@ -171,26 +155,6 @@ if (!$api_request) {
// Impostazioni di Content-Type e Charset Header
header('Content-Type: text/html; charset=UTF-8');
// Controllo CSRF
if (empty($config['disableCSRF'])) {
//csrfProtector::init();
}
// Aggiunta del wrapper personalizzato per la generazione degli input
if (!empty($config['HTMLWrapper'])) {
HTMLBuilder\HTMLBuilder::setWrapper($config['HTMLWrapper']);
}
// Aggiunta dei gestori personalizzati per la generazione degli input
foreach ((array) $config['HTMLHandlers'] as $key => $value) {
HTMLBuilder\HTMLBuilder::setHandler($key, $value);
}
// Aggiunta dei gestori per componenti personalizzate
foreach ((array) $config['HTMLManagers'] as $key => $value) {
HTMLBuilder\HTMLBuilder::setManager($key, $value);
}
// Registrazione globale del template per gli input HTML
ob_start();
@ -200,7 +164,7 @@ if (!$api_request) {
session(['errors' => isset($_SESSION['errors']) ? array_unique($_SESSION['errors']) : []]);
// Impostazione del tema grafico di default
$theme = !empty($config['theme']) ? $config['theme'] : 'default';
$theme = 'default';
if ($continue) {
// Periodo di visualizzazione dei record

View File

@ -27,7 +27,7 @@ $read_only = $structure->permission == 'r';
if (empty($id_record) && !empty($id_module) && empty($id_plugin)) {
redirect_legacy(base_url().'/controller.php?id_module='.$id_module);
} elseif (empty($id_record) && empty($id_module) && empty($id_plugin)) {
redirect_legacy(base_url().'/index.php');
redirect_legacy(base_url().'/');
}
include_once AppLegacy::filepath('include|custom|', 'top.php');

View File

@ -178,7 +178,9 @@ if (auth()->check()) {
},
},
};
globals = {
content_was_modified: false,
rootdir: "'.base_url().'",
js: "'.$paths['js'].'",
css: "'.$paths['css'].'",
@ -235,12 +237,28 @@ if (auth()->check()) {
dataload_page_buffer: '.setting('Lunghezza in pagine del buffer Datatables').',
tempo_attesa_ricerche: '.setting('Tempo di attesa ricerche in secondi').',
restrict_summables_to_selected: '.setting('Totali delle tabelle ristretti alla selezione').',
urls: {
select: "'.route('ajax-select').'",
dataload: "'.route('ajax-dataload', ['module_id' => '|module_id|']).'",
dataload_plugin: "'.route('ajax-dataload', ['module_id' => '|module_id|', 'reference_id' => '|reference_id|']).'",
ajax_set: "'.route('ajax-session').'",
ajax_array_set: "'.route('ajax-session-array').'",
messages: "'.route('messages').'",
hooks: {
list: "'.route('hooks').'",
lock: "'.route('hook-lock', ['hook_id' => '|id|']).'",
execute: "'.route('hook-execute', ['hook_id' => '|id|', 'token' => '|token|']).'",
response: "'.route('hook-response', ['hook_id' => '|id|']).'",
}
}
};
</script>';
} else {
echo '
<script>
globals = {
content_was_modified: false,
rootdir: "'.base_url().'",
search: {},

View File

@ -86,7 +86,7 @@ class Permissions
if (!self::getSkip()) {
if (!auth()->check() && getURLPath() == slashes(base_url().'/index.php')) {
redirect_legacy(base_url().'/index.php');
redirect_legacy(base_url().'/');
$result = false;
throw new \App\Exceptions\LegacyExitException();
} else {