#wip: Fixing ECMA UI.

This commit is contained in:
KyMAN 2026-07-14 07:28:07 +02:00
parent d4f7dd60c9
commit ebe451c88a
9 changed files with 99 additions and 17 deletions

View File

@ -39,6 +39,13 @@ export const AnP = (function(){
* @return {boolean} * @return {boolean}
*/ */
/**
* @callback execute_action_callback
* @param {?(Object.<string, any|null>|Array.<any|null>)} [data = null]
* @param {!number} [code = 200]
* @returns {any|null|void}
*/
/** /**
* @constructs AnP * @constructs AnP
* @param {?(Object.<string, any|null>|Array<any|null>)} [inputs = null] * @param {?(Object.<string, any|null>|Array<any|null>)} [inputs = null]
@ -204,6 +211,21 @@ export const AnP = (function(){
*/ */
this.exception = (exception, message, inputs = null, i = 0) => {}; this.exception = (exception, message, inputs = null, i = 0) => {};
/**
* @param {!(string|[string, string]|execute_action_callback)} action
* @param {?(Object.<string, any|null>|Array.<any|null>)} [data = null]
* @param {!number} [code = 200]
* @returns {any|null|void}
* @access public
*/
this.execute = (action, data = null, code = 200) => {
if(Check.is_string(action) || Check.is_array(action))
return self.controllers.execute(action, data, code);
if(Check.is_function(action))
return action(data, code);
return null;
};
constructor(); constructor();
}; };

View File

@ -66,7 +66,17 @@ export const FormsComponent = (function(){
...(view ? {data_view : view} : {}), ...(view ? {data_view : view} : {}),
method : Common.get_value("method", inputs, "post"), method : Common.get_value("method", inputs, "post"),
action : Common.get_value("action", inputs, "#"), action : Common.get_value("action", inputs, "#"),
...(submit ? {on_submit : submit} : {}) on_submit : (item, event) => {
event.preventDefault();
anp.execute(submit, {
item : item,
event : event
});
return false;
}
}, [ }, [
Fieldset({class : "form"}, [ Fieldset({class : "form"}, [
anp.components.i18n(name, "legend"), anp.components.i18n(name, "legend"),
@ -92,7 +102,7 @@ export const FormsComponent = (function(){
for : id, for : id,
data_i18n : name, data_i18n : name,
data_i18n_without : true, data_i18n_without : true,
title : anp.components.i18n(name, "label") title : anp.i18n.get(name, "label")
}, [ }, [
anp.components.i18n(name), anp.components.i18n(name),
anp.components.i18n(name + "_description"), anp.components.i18n(name + "_description"),
@ -104,10 +114,13 @@ export const FormsComponent = (function(){
]); ]);
})), })),
UL({class : "global-errors"}), UL({class : "global-errors"}),
Div({class : "buttons"}, Common.get_value(["actions", "buttons"], inputs, []).concat( Div({class : "buttons"}, Common.get_value(["actions", "buttons"], inputs, []).concat([
[anp.components.button(Common.get_value("submit_reset", inputs, "clean"), "reset")], anp.components.button(Common.get_value("submit_cancel", inputs, "cancel"), (item, event) => {
submit ? [anp.components.button(Common.get_value("submit_name", inputs, "submit"), "submit")] : [] anp.routes.back();
)) }),
anp.components.button(Common.get_value("submit_reset", inputs, "clean"), "reset"),
submit ? anp.components.button(Common.get_value("submit_name", inputs, "submit"), "submit") : null
]))
]) ])
]); ]);
}; };

View File

@ -32,11 +32,17 @@ export const SessionsController = (function(){
*/ */
const constructor = () => {}; const constructor = () => {};
this.login = () => {}; this.login = () => {
console.log("PASA login");
};
this.logout = () => {}; this.logout = () => {
console.log("PASA logout");
};
this.register = () => {}; this.register = () => {
console.log("PASA register");
};
constructor(); constructor();
}; };

View File

@ -154,11 +154,20 @@ export const ControllersManager = (function(){
* @param {!string} action * @param {!string} action
* @param {?any} [data = null] * @param {?any} [data = null]
* @param {!number} [code = 200] * @param {!number} [code = 200]
* @return {void} * @return {any|null|void}
* @access public * @access public
*/ */
this.execute = (controller, action, data = null, code = 200) => { this.execute = (action, data = null, code = 200) => {
controllers[controller] && controllers[controller][action] && controllers[controller][action](data, code);
/** @type {[string|null, string|null]} */
const [controller, method] = (
Check.is_string(action) ? action.split("@") :
Check.is_array(action) && action.length == 2 ? action :
[null, null]);
if(controller && method && controllers[controller] && controllers[controller][method])
return controllers[controller][method](data, code);
return null;
}; };
constructor(); constructor();

View File

@ -42,13 +42,19 @@ export const RoutesManager = (function(){
/** @type {RoutesManager} */ /** @type {RoutesManager} */
const self = this, const self = this,
/** @type {Array.<RouteModel>} */ /** @type {Array.<RouteModel>} */
routes = []; routes = [],
/** @type {Array.<string>} */
history = [],
/** @type {Array.<string>} */
history_post = [];
/** @type {boolean} */ /** @type {boolean} */
let started = false, let started = false,
/** @type {string} */ /** @type {string|null} */
last_url = "", last_url = null,
/** @type {number|null} */ /** @type {number|null} */
thread = null; thread = null,
/** @type {boolean} */
backed = false;
/** /**
* @returns {void} * @returns {void}
@ -73,8 +79,17 @@ export const RoutesManager = (function(){
const current_url = window.location.hash.substring(1); const current_url = window.location.hash.substring(1);
if(last_url != current_url){ if(last_url != current_url){
last_url = current_url; last_url = current_url;
if(backed){
history_post.splice(0, 0);
backed = false;
}else
history.push(current_url);
self.refresh(); self.refresh();
}; };
}; };
@ -241,6 +256,7 @@ export const RoutesManager = (function(){
*/ */
this.go = path => { this.go = path => {
/** @type {HTMLMainElement|null} */
const main = anp.item_self.querySelector("main"); const main = anp.item_self.querySelector("main");
if(!main) if(!main)
@ -262,6 +278,17 @@ export const RoutesManager = (function(){
}; };
/**
* @returns {void}
* @access public
*/
this.back = () => {
console.log("PASA");
backed = true;
history_post.push(history.pop());
window.location.href = "#" + history[history.length - 1];
};
constructor(); constructor();
}; };

View File

@ -33,6 +33,7 @@
"anpbot" : "AnPBot", "anpbot" : "AnPBot",
"clean" : "Limpiar", "clean" : "Limpiar",
"submit" : "Enviar", "submit" : "Enviar",
"cancel" : "Cancelar",
"AnP_Sessions_start" : null, "AnP_Sessions_start" : null,
"login" : "Acceder", "login" : "Acceder",

View File

@ -1237,6 +1237,9 @@
height: 1em; height: 1em;
margin-right: 0.3em; margin-right: 0.3em;
} }
.anp .form-component {
padding: 1em;
}
.anp .form-component fieldset { .anp .form-component fieldset {
margin: 0em; margin: 0em;
padding: 0em; padding: 0em;

File diff suppressed because one or more lines are too long

View File

@ -301,6 +301,7 @@
} }
.form-component{ .form-component{
padding : 1em;
fieldset{ fieldset{
margin : 0em; margin : 0em;
padding : 0em; padding : 0em;