| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774 |
- <!DOCTYPE html>
- <html lang="fr">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Simulation Machine à États - IFSM</title>
- <script src="ifsm/extlib/jquery-3.2.0.min.js"></script>
- <script src="ifsm/extlib/jquery.dotimeout.js"></script>
- <script src="ifsm/extlib/jquery.attrchange.js"></script>
- <script src="ifsm/iFSM.js"></script>
- <style>
- body {
- font-family: Arial, sans-serif;
- background: #f7f9fb;
- padding: 20px;
- margin: 0;
- }
- h1 {
- text-align: center;
- margin-bottom: 20px;
- }
- .machine {
- display: flex;
- flex-wrap: wrap;
- justify-content: center;
- gap: 20px;
- margin-bottom: 30px;
- }
- .etat {
- border: 2px solid #888;
- border-radius: 10px;
- padding: 15px 25px;
- background: white;
- min-width: 140px;
- text-align: center;
- box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
- transition: background 0.3s, transform 0.2s;
- }
- .etat.actif {
- background: #cde4ff;
- border-color: #007bff;
- transform: scale(1.05);
- }
- .liens {
- text-align: center;
- margin: 20px 0;
- }
- select {
- padding: 8px;
- border-radius: 5px;
- border: 1px solid #ccc;
- font-size: 14px;
- }
- .transition {
- text-align: center;
- font-style: italic;
- color: #555;
- margin-top: 10px;
- }
- hr {
- border: none;
- height: 1px;
- background: #ccc;
- margin: 30px 0;
- }
- .hidden {
- display: none;
- }
- </style>
- </head>
- <body>
- <h1>Machine à États - Simulation Interactive</h1>
- <div class="liens">
- <label for="eventSelect">Événement :</label>
- <select id="eventSelect">
- <option value="">-- Choisir un événement --</option>
- <option value="choixCategorie">choixCategorie</option>
- <option value="templateCategorie">templateCategorie</option>
- <option value="templateProduit">templateProduit</option>
- <option value="ajoutOk">ajoutOk</option>
- <option value="undisplayModele1">undisplayModele1</option>
- <option value="undisplayModele2">undisplayModele2</option>
- <option value="undisplayModele3">undisplayModele3</option>
- <option value="undisplayModele4">undisplayModele4</option>
- <option value="pack2">pack2</option>
- <option value="pack3">pack3</option>
- <option value="mes_gratuiteOk">mes_gratuiteOk</option>
- <option value="infosOk">infosOk</option>
- </select>
- </div>
- <!-- GLOBAL -->
- <div id="globalManager" class="machine">
- <div id="displayManager" class="etat">displayManager</div>
- <div id="votreDevis" class="etat">votreDevis</div>
- <div id="mes" class="etat">mes</div>
- <div id="nbButton" class="etat">nbButton</div>
- </div>
- <!-- MODELES -->
- <div id="modelesManager" class="machine">
- <div id="modele1" class="etat">modele1</div>
- <div id="modele2" class="etat">modele2</div>
- <div id="modele3" class="etat">modele3</div>
- <div id="modele4" class="etat">modele4</div>
- <div id="sortieModele" class="etat">sortieModele</div>
- </div>
- <!-- PACKS -->
- <div id="packManager" class="machine">
- <div id="packs" class="etat">packs</div>
- <div id="pack2Etat" class="etat">pack2</div>
- <div id="pack3Etat" class="etat">pack3</div>
- <div id="sortiePacks" class="etat">sortiePacks</div>
- </div>
- <!-- INFOS -->
- <div id="infosManager" class="machine">
- <div id="infos" class="etat">infos</div>
- <div id="questionnaire" class="etat">questionnaire</div>
- <div id="precisions" class="etat">precisions</div>
- <div id="infosSortie" class="etat">infosSortie</div>
- </div>
- <div id="transitionText" class="transition">
- Aucune transition effectuée.
- </div>
- <div id="displays" class="machine">
- <div id="display_modele1" class="etat hidden">modele1</div>
- <div id="display_modele2" class="etat hidden">modele2</div>
- <div id="display_modele3" class="etat hidden">modele3</div>
- <div id="display_modele4" class="etat hidden">modele4</div>
- <div id="display_pack2Etat" class="etat hidden">pack2</div>
- <div id="display_pack3" class="etat hidden">pack3</div>
- <div id="display_questionnaire" class="etat hidden">questionnaire</div>
- <div id="display_precisions" class="etat hidden">precisions</div>
- <div id="display_votreDevis" class="etat hidden">votreDevis</div>
- <div id="display_mes" class="etat hidden">mes</div>
- <div id="display_nbButton" class="etat hidden">nbButton</div>
- </div>
- <script>
- const modele1 = "#modele1";
- const modele2 = "#modele2";
- const modele3 = "#modele3";
- const modele4 = "#modele4";
- const globalManager = "#globalManager";
- const modelesManager = "#modelesManager";
- const packManager = "#packManager";
- const infosManager = "#infosManager";
- // === Helper Visuel ===
- /*function highlightState(fsm, machineId) {
- $(".etat").removeClass("actif");
- $("#" + fsm.currentState).addClass("actif");
- }*/
- // === MODELES MANAGER ===
- var modelesManagerDef = {
- modele1: {
- templateCategorie: {
- init_function: function () {
- this.trigger("display", "modele2");
- },
- pushpop_state: "PushState",
- next_state: "modele2",
- },
- templateProduit: {
- init_function: function () {
- this.trigger("modelesOk");
- },
- next_state: "sortieModele",
- pushpop_state: "PushState",
- },
- pack2: "templateProduit",
- pack3: "pack2",
- ajoutOk: {
- init_function: function () {
- $(globalManager).trigger("ajoutOkDisplayManager");
- this.trigger("undisplay", "modele1");
- },
- },
- },
- modele2: {
- templateCategorie: {
- init_function: function () {
- this.trigger("display", "modele3");
- },
- pushpop_state: "PushState",
- next_state: "modele3",
- },
- templateProduit: {
- init_function: function () {
- this.trigger("modelesOk");
- },
- next_state: "sortieModele",
- pushpop_state: "PushState",
- },
- pack2: "templateProduit",
- pack3: "pack2",
- undisplayModele1: {
- init_function: function () {
- this.trigger("undisplay", "modele2");
- },
- pushpop_state: "PopState",
- },
- ajoutOk: {
- init_function: function () {
- this.trigger("undisplay", "modele2");
- },
- propagate_event: "ajoutOk",
- pushpop_state: "PopState",
- },
- },
- modele3: {
- templateCategorie: {
- init_function: function () {
- this.trigger("display", "modele4");
- },
- next_state: "modele4",
- pushpop_state: "PushState",
- },
- templateProduit: {
- init_function: function () {
- this.trigger("modelesOk");
- },
- next_state: "sortieModele",
- pushpop_state: "PushState",
- },
- pack2: "templateProduit",
- pack3: "pack2",
- undisplayModele1: {
- init_function: function () {
- this.trigger("undisplay", "modele3");
- },
- propagate_event: "undisplayModele1",
- pushpop_state: "PopState",
- },
- undisplayModele2: {
- init_function: function () {
- this.trigger("undisplay", "modele3");
- },
- pushpop_state: "PopState",
- },
- ajoutOk: {
- init_function: function () {
- this.trigger("undisplay", "modele3");
- },
- propagate_event: "ajoutOk",
- pushpop_state: "PopState",
- },
- },
- modele4: {
- templateProduit: {
- init_function: function () {
- this.trigger("modelesOk");
- },
- next_state: "sortieModele",
- pushpop_state: "PushState",
- },
- pack2: "templateProduit",
- pack3: "pack2",
- undisplayModele1: {
- init_function: function () {
- this.trigger("undisplay", "modele4");
- },
- propagate_event: "undisplayModele1",
- pushpop_state: "PopState",
- },
- undisplayModele2: {
- init_function: function () {
- this.trigger("undisplay", "modele4");
- },
- propagate_event: "undisplayModele2",
- pushpop_state: "PopState",
- },
- undisplayModele3: {
- init_function: function () {
- this.trigger("undisplay", "modele4");
- },
- pushpop_state: "PopState",
- },
- ajoutOk: {
- init_function: function () {
- this.trigger("undisplay", "modele4");
- },
- propagate_event: "ajoutOk",
- pushpop_state: "PopState",
- },
- },
- sortieModele: {
- modelesOk: {
- init_function: function () {
- $(packManager).trigger("modelesOk");
- },
- },
- ajoutOk: {
- pushpop_state: "PopState",
- },
- undisplayModele1: "ajoutOk",
- undisplayModele2: "ajoutOk",
- undisplayModele3: "ajoutOk",
- undisplayModele4: "ajoutOk",
- },
- DefaultState: {
- start: { next_state: "modele1" },
- // enterState: {
- // init_function: function () {
- // highlightState(this, "modelesManager");
- // },
- // },
- enterState: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- exitState: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- undisplay: {
- init_function: function (p, e, id) {
- $("#display_" + id).addClass("hidden");
- },
- },
- display: {
- init_function: function (p, e, id) {
- $("#display_" + id).removeClass("hidden");
- },
- },
- choixCategorie: { next_state: "modele1" },
- catchEvent: {
- init_function: function (p, e) {
- $("#transitionText").text(
- "modelesManager :" +
- this.currentState +
- " - événement non géré : " +
- e.type
- );
- },
- },
- },
- };
- $(modelesManager).iFSM(modelesManagerDef, {
- debug: true,
- LogLevel: 2,
- });
- // === PACK MANAGER ===
- var packManagerDef = {
- packs: {
- pack2: {
- init_function: function () {
- this.trigger("display", "pack2");
- },
- next_state: "pack2Etat",
- },
- pack3: {
- init_function: function () {
- this.trigger("display", "pack3");
- },
- next_state: "pack3Etat",
- },
- templateProduit: { next_state: "sortiePacks" },
- ajoutOk: {
- init_function: function () {
- $(modelesManager).trigger("ajoutOk");
- },
- },
- undisplayModele1: {
- init_function: function () {
- $(modelesManager).trigger("undisplayModele1");
- },
- },
- undisplayModele2: {
- init_function: function () {
- $(modelesManager).trigger("undisplayModele2");
- },
- },
- undisplayModele3: {
- init_function: function () {
- $(modelesManager).trigger("undisplayModele3");
- },
- },
- undisplayModele4: {
- init_function: function () {
- $(modelesManager).trigger("undisplayModele4");
- },
- },
- },
- pack2Etat: {
- ajoutOk: {
- pushpop_state: "PopState",
- init_function: function () {
- this.trigger("undisplay", "");
- },
- },
- templateProduit: {
- next_state: "sortiePacks",
- pushpop_state: "PushState",
- },
- },
- pack3Etat: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- ajoutOk: {
- pushpop_state: "PopState",
- init_function: function () {
- $("#transitionText").text("packManager : ajoutOk → infosManager");
- $(infosManager).trigger("ajoutOk");
- },
- },
- templateProduit: {
- next_state: "sortiePacks",
- pushpop_state: "PushState",
- },
- },
- sortiePacks: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- enterState: {
- // init_function: function () {
- // $(infosManager).trigger("mes_gratuiteOk");
- // $("#transitionText").text(
- // "packManager : arrivée sur sortiePacks → infosManager"
- // );
- // },
- },
- },
- DefaultState: {
- start: { next_state: "packs" },
- enterState: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- exitState: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- undisplay: {
- init_function: function (p, e, id) {
- $("#display_" + id).addClass("hidden");
- },
- },
- display: {
- init_function: function (p, e, id) {
- $("#display_" + id).removeClass("hidden");
- },
- },
- catchEvent: {
- init_function: function (p, e) {
- $("#transitionText").text(
- "packManager : événement non géré " + e.type
- );
- },
- },
- },
- };
- $(packManager).iFSM(packManagerDef, { debug: true, LogLevel: 2 });
- // === INFOS MANAGER ===
- var infosManagerDef = {
- infos: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- mes_gratuiteOk: { next_state: "questionnaire" },
- infosOk: { next_state: "infosSortie" },
- },
- questionnaire: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- precisions: { next_state: "precisions" },
- infosOk: { next_state: "infosSortie" },
- },
- precisions: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- infosOk: { next_state: "infosSortie" },
- },
- infosSortie: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- },
- DefaultState: {
- start: { next_state: "infos" },
- enterState: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- exitState: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- undisplay: {
- init_function: function (p, e, id) {
- $("#display_" + id).addClass("hidden");
- },
- },
- display: {
- init_function: function (p, e, id) {
- $("#display_" + id).removeClass("hidden");
- },
- },
- catchEvent: {
- init_function: function (p, e) {
- $("#transitionText").text(
- "infosManager : événement non géré " + e.type
- );
- },
- },
- },
- };
- $(infosManager).iFSM(infosManagerDef, { debug: true, LogLevel: 2 });
- // === GLOBAL MANAGER ===
- var globalManagerDef = {
- displayManager: {
- choixCategorie: {
- init_function: function () {
- $(modelesManager).trigger("display", "modele1");
- },
- },
- },
- votreDevis: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- ajoutOk: {
- pushpop_state: "PopState",
- init_function: function () {
- $("#transitionText").text(
- "globalManager : ajoutOk → infosManager"
- );
- $(infosManager).trigger("ajoutOk");
- },
- },
- },
- mes: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- },
- nbButton: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- },
- options: {
- display: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- undisplay: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- },
- DefaultState: {
- start: { next_state: "displayManager" },
- ajoutOkDisplayManager: { next_state: "displayManager" },
- enterState: {
- init_function: function () {
- $("#" + this.currentState).addClass("actif");
- },
- },
- exitState: {
- init_function: function () {
- $("#" + this.currentState).removeClass("actif");
- },
- },
- undisplay: {
- init_function: function (p, e, id) {
- $("#display_" + id).addClass("hidden");
- },
- },
- display: {
- init_function: function (p, e, id) {
- $("#display_" + id).removeClass("hidden");
- },
- },
- catchEvent: {
- init_function: function (p, e) {
- $("#transitionText").text(
- "globalManager : événement non géré " + e.type
- );
- },
- },
- },
- };
- $(globalManager).iFSM(globalManagerDef, { debug: true, LogLevel: 2 });
- // === TEST SELECT ===
- $("#eventSelect").on("change", function () {
- var ev = $(this).val();
- if (!ev) return;
- $("#transitionText").text("→ Événement déclenché : " + ev);
- // Propagation initiale (globalManager en premier)
- $(globalManager).trigger(ev);
- $(infosManager).trigger(ev);
- $(packManager).trigger(ev);
- $(modelesManager).trigger(ev);
- $(this).val("");
- });
- </script>
- </body>
- </html>
|