diff --git a/css/style.css b/css/style.css index 163078a..c7936a0 100644 --- a/css/style.css +++ b/css/style.css @@ -104,10 +104,16 @@ footer { box-shadow: 3px 2px white; } +.pseudo { + color: white; +} + /* General */ .smooth { padding: 5px; - border-radius: 10px; + padding-left: 10px; + padding-right: 10px; + border-radius: 5px; } .in-big { diff --git a/html/template.html b/html/template.html index 62edad4..75a8d2f 100644 --- a/html/template.html +++ b/html/template.html @@ -3,6 +3,7 @@
${err}
- `); - }); -}); - -auth.relog(); - diff --git a/js/scripts/main.js b/js/scripts/main.js new file mode 100644 index 0000000..ff60d41 --- /dev/null +++ b/js/scripts/main.js @@ -0,0 +1,54 @@ +import { Modal } from "../skama_code/ui/modal.js"; +import { Auth } from "../skama_code/auth/auth.js"; + +let my_agent = null; + +function menu_mod() { + if(my_agent && my_agent.name) $(".pseudo").text(`Agent name : ${my_agent.name}`); +} + +export function init_login(temp_engine) { + let auth = new Auth(true); + let modal = new Modal("login-modal", temp_engine); + + temp_engine.render("templates/login.html"); + menu_mod(); + + temp_engine.add_event("#ok", "click", () => { + temp_engine.render("templates/home.html"); + menu_mod(); + }); + + temp_engine.add_event("#forget", "click", () => { + my_agent = null; + auth.unload_token(); + modal.close(); + temp_engine.render("templates/login.html"); + }); + + temp_engine.add_event("#val", "click", () => { + let token = $("#in-token").val(); + auth.login(token); + }); + + temp_engine.add_event("#cancel", "click", () => { + $("#in-token").val(""); + }); + + modal.add_class("ext-modal"); + modal.load("templates/login_modal.html"); + + auth.done((agent) => { + modal.show(); + my_agent = agent; + }).fail((errs) => { + $(".errors").html(""); + errs.forEach(err => { + $(".errors").append(` +${err}
+ `); + }); + }); + + auth.relog(); +} \ No newline at end of file diff --git a/js/skama_code/commun/initialzer.js b/js/skama_code/commun/initialzer.js deleted file mode 100644 index ba21d0d..0000000 --- a/js/skama_code/commun/initialzer.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; - -export class Initialzer { - constructor(UI) { - this.UI = UI; - } - - init_menu_link(tag, template) { - this.UI.add_event(tag, "click", () => { - this.UI.render(`templates/${template}`); - }) - } -} \ No newline at end of file diff --git a/js/skama_code/ui/modal.js b/js/skama_code/ui/modal.js index 5bb4811..98890a3 100644 --- a/js/skama_code/ui/modal.js +++ b/js/skama_code/ui/modal.js @@ -9,7 +9,7 @@ export class Modal { this.modal_class = ""; } - render(template) { + load(template) { this.template_engine.get_template((reponse) => { $(this.tag).prepend(`