Incluida arquitectura 'Js_loader' con un ejemplo de uso

This commit is contained in:
imnavajas
2023-09-14 10:29:40 +02:00
parent 8754782dc9
commit 8a207b246b
8 changed files with 96 additions and 3 deletions

View File

@ -29,4 +29,4 @@ defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true);
| the system. This will control whether Kint is loaded, and a few other
| items. It can always be used within your own application too.
*/
defined('CI_DEBUG') || define('CI_DEBUG', false);
defined('CI_DEBUG') || define('CI_DEBUG', true);

View File

@ -0,0 +1,31 @@
<?php
namespace App\Controllers;
use App\Controllers\BaseController;
class Js_loader extends BaseController
{
function __construct()
{
}
function index()
{
echo "ok";
}
function comparador_js()
{
$this->response->setHeader('Content-Type', 'text/javascript');
return view('themes/backend/vuexy/form/presupuestos/cosidotapablanda/comparador.js');
}
}

View File

@ -172,6 +172,9 @@ class Cosidotapablanda extends \App\Controllers\GoBaseResourceController
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Presupuestos.moduleTitleCosidoTB') . ' ' . lang('Basic.global.addNewSuffix');
/* TEST JS LOADER */
$this->viewData['global_js_variables'] = array('jsVarTest' => "'Hola Jaime'");
return $this->displayForm(__METHOD__);
} // end function add()

View File

@ -0,0 +1,26 @@
<?php
namespace App\Controllers\Presupuestos;
use App\Controllers\BaseController;
class Js_loader extends BaseController
{
function __construct()
{
}
function comparador_js()
{
$data['test_var'] = 5;
$this->load->view('themes/backend/vuexy/form/presupuestos/cosidotapablanda/comparador.js', $data);
$this->output->set_content_type('text/javascript');
}
}

View File

@ -127,7 +127,7 @@ class LoginAuthFilter implements FilterInterface
*/
public function whiteListController(){
return [
'',
'Js_loader',
'BaseController',
'Home',
'Login',

View File

@ -0,0 +1,17 @@
$(function () {
console.log("Llamada desde JS Loader");
console.log("jsVarTest: " + jsVarTest);
});
function test(){
console.log("Test from function");
console.log("jsVarTest desde funcion: " + jsVarTest);
}

View File

@ -1,6 +1,7 @@
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
<?= $this->extend('themes/backend/vuexy/main/defaultlayout') ?>
<?= $this->section("content") ?>
<div class="row">
<div class="col-12">
@ -106,11 +107,16 @@
"<?=lang('Presupuestos.papelFormatoId') ?>*";
}
});
<?= $this->endSection() ?>
// Function from comparador.js
test();
<?= $this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
<script src="<?= site_url('themes/vuexy/vendor/libs/autosize/autosize.js') ?>"></script>
<script src="<?= site_url('js_loader/comparador_js') ?>"></script>
<?=$this->endSection() ?>

View File

@ -335,6 +335,16 @@ if (!empty($token) && $tfa == false) {
<!-- Page JS -->
<?= sweetAlert() ?>
<?php
if (isset($global_js_variables)) {
echo "<script>\n";
foreach ($global_js_variables as $name => $value):
echo "\t" . "var $name = $value;" . "\n";
endforeach;
echo "</script>\n";
}
?>
<script type="text/javascript">