index.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. <!DOCTYPE html>
  2. <html lang="fr">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Simulation Machine à États - IFSM</title>
  7. <script src="ifsm/extlib/jquery-3.2.0.min.js"></script>
  8. <script src="ifsm/extlib/jquery.dotimeout.js"></script>
  9. <script src="ifsm/extlib/jquery.attrchange.js"></script>
  10. <script src="ifsm/iFSM.js"></script>
  11. <style>
  12. body {
  13. font-family: Arial, sans-serif;
  14. background: #f7f9fb;
  15. padding: 20px;
  16. margin: 0;
  17. }
  18. h1 {
  19. text-align: center;
  20. margin-bottom: 20px;
  21. }
  22. .machine {
  23. display: flex;
  24. flex-wrap: wrap;
  25. justify-content: center;
  26. gap: 20px;
  27. margin-bottom: 30px;
  28. }
  29. .etat {
  30. border: 2px solid #888;
  31. border-radius: 10px;
  32. padding: 15px 25px;
  33. background: white;
  34. min-width: 140px;
  35. text-align: center;
  36. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  37. transition: background 0.3s, transform 0.2s;
  38. }
  39. .etat.actif {
  40. background: #cde4ff;
  41. border-color: #007bff;
  42. transform: scale(1.05);
  43. }
  44. .liens {
  45. text-align: center;
  46. margin: 20px 0;
  47. }
  48. select {
  49. padding: 8px;
  50. border-radius: 5px;
  51. border: 1px solid #ccc;
  52. font-size: 14px;
  53. }
  54. .transition {
  55. text-align: center;
  56. font-style: italic;
  57. color: #555;
  58. margin-top: 10px;
  59. }
  60. hr {
  61. border: none;
  62. height: 1px;
  63. background: #ccc;
  64. margin: 30px 0;
  65. }
  66. .hidden {
  67. display: none;
  68. }
  69. </style>
  70. </head>
  71. <body>
  72. <h1>Machine à États - Simulation Interactive</h1>
  73. <div class="liens">
  74. <label for="eventSelect">Événement :</label>
  75. <select id="eventSelect">
  76. <option value="">-- Choisir un événement --</option>
  77. <option value="choixCategorie">choixCategorie</option>
  78. <option value="templateCategorie">templateCategorie</option>
  79. <option value="templateProduit">templateProduit</option>
  80. <option value="ajoutOk">ajoutOk</option>
  81. <option value="undisplayModele1">undisplayModele1</option>
  82. <option value="undisplayModele2">undisplayModele2</option>
  83. <option value="undisplayModele3">undisplayModele3</option>
  84. <option value="undisplayModele4">undisplayModele4</option>
  85. <option value="pack2">pack2</option>
  86. <option value="pack3">pack3</option>
  87. <option value="mes_gratuiteOk">mes_gratuiteOk</option>
  88. <option value="infosOk">infosOk</option>
  89. </select>
  90. </div>
  91. <!-- GLOBAL -->
  92. <div id="globalManager" class="machine">
  93. <div id="displayManager" class="etat">displayManager</div>
  94. <div id="votreDevis" class="etat">votreDevis</div>
  95. <div id="mes" class="etat">mes</div>
  96. <div id="nbButton" class="etat">nbButton</div>
  97. </div>
  98. <!-- MODELES -->
  99. <div id="modelesManager" class="machine">
  100. <div id="modele1" class="etat">modele1</div>
  101. <div id="modele2" class="etat">modele2</div>
  102. <div id="modele3" class="etat">modele3</div>
  103. <div id="modele4" class="etat">modele4</div>
  104. <div id="sortieModele" class="etat">sortieModele</div>
  105. </div>
  106. <!-- PACKS -->
  107. <div id="packManager" class="machine">
  108. <div id="packs" class="etat">packs</div>
  109. <div id="pack2Etat" class="etat">pack2</div>
  110. <div id="pack3Etat" class="etat">pack3</div>
  111. <div id="sortiePacks" class="etat">sortiePacks</div>
  112. </div>
  113. <!-- INFOS -->
  114. <div id="infosManager" class="machine">
  115. <div id="infos" class="etat">infos</div>
  116. <div id="questionnaire" class="etat">questionnaire</div>
  117. <div id="precisions" class="etat">precisions</div>
  118. <div id="infosSortie" class="etat">infosSortie</div>
  119. </div>
  120. <div id="transitionText" class="transition">
  121. Aucune transition effectuée.
  122. </div>
  123. <div id="displays" class="machine">
  124. <div id="display_modele1" class="etat hidden">modele1</div>
  125. <div id="display_modele2" class="etat hidden">modele2</div>
  126. <div id="display_modele3" class="etat hidden">modele3</div>
  127. <div id="display_modele4" class="etat hidden">modele4</div>
  128. <div id="display_pack2Etat" class="etat hidden">pack2</div>
  129. <div id="display_pack3" class="etat hidden">pack3</div>
  130. <div id="display_questionnaire" class="etat hidden">questionnaire</div>
  131. <div id="display_precisions" class="etat hidden">precisions</div>
  132. <div id="display_votreDevis" class="etat hidden">votreDevis</div>
  133. <div id="display_mes" class="etat hidden">mes</div>
  134. <div id="display_nbButton" class="etat hidden">nbButton</div>
  135. </div>
  136. <script>
  137. const modele1 = "#modele1";
  138. const modele2 = "#modele2";
  139. const modele3 = "#modele3";
  140. const modele4 = "#modele4";
  141. const globalManager = "#globalManager";
  142. const modelesManager = "#modelesManager";
  143. const packManager = "#packManager";
  144. const infosManager = "#infosManager";
  145. // === Helper Visuel ===
  146. /*function highlightState(fsm, machineId) {
  147. $(".etat").removeClass("actif");
  148. $("#" + fsm.currentState).addClass("actif");
  149. }*/
  150. // === MODELES MANAGER ===
  151. var modelesManagerDef = {
  152. modele1: {
  153. templateCategorie: {
  154. init_function: function () {
  155. this.trigger("display", "modele2");
  156. },
  157. pushpop_state: "PushState",
  158. next_state: "modele2",
  159. },
  160. templateProduit: {
  161. init_function: function () {
  162. this.trigger("modelesOk");
  163. },
  164. next_state: "sortieModele",
  165. pushpop_state: "PushState",
  166. },
  167. pack2: "templateProduit",
  168. pack3: "pack2",
  169. ajoutOk: {
  170. init_function: function () {
  171. $(globalManager).trigger("ajoutOkDisplayManager");
  172. this.trigger("undisplay", "modele1");
  173. },
  174. },
  175. },
  176. modele2: {
  177. templateCategorie: {
  178. init_function: function () {
  179. this.trigger("display", "modele3");
  180. },
  181. pushpop_state: "PushState",
  182. next_state: "modele3",
  183. },
  184. templateProduit: {
  185. init_function: function () {
  186. this.trigger("modelesOk");
  187. },
  188. next_state: "sortieModele",
  189. pushpop_state: "PushState",
  190. },
  191. pack2: "templateProduit",
  192. pack3: "pack2",
  193. undisplayModele1: {
  194. init_function: function () {
  195. this.trigger("undisplay", "modele2");
  196. },
  197. pushpop_state: "PopState",
  198. },
  199. ajoutOk: {
  200. init_function: function () {
  201. this.trigger("undisplay", "modele2");
  202. },
  203. propagate_event: "ajoutOk",
  204. pushpop_state: "PopState",
  205. },
  206. },
  207. modele3: {
  208. templateCategorie: {
  209. init_function: function () {
  210. this.trigger("display", "modele4");
  211. },
  212. next_state: "modele4",
  213. pushpop_state: "PushState",
  214. },
  215. templateProduit: {
  216. init_function: function () {
  217. this.trigger("modelesOk");
  218. },
  219. next_state: "sortieModele",
  220. pushpop_state: "PushState",
  221. },
  222. pack2: "templateProduit",
  223. pack3: "pack2",
  224. undisplayModele1: {
  225. init_function: function () {
  226. this.trigger("undisplay", "modele3");
  227. },
  228. propagate_event: "undisplayModele1",
  229. pushpop_state: "PopState",
  230. },
  231. undisplayModele2: {
  232. init_function: function () {
  233. this.trigger("undisplay", "modele3");
  234. },
  235. pushpop_state: "PopState",
  236. },
  237. ajoutOk: {
  238. init_function: function () {
  239. this.trigger("undisplay", "modele3");
  240. },
  241. propagate_event: "ajoutOk",
  242. pushpop_state: "PopState",
  243. },
  244. },
  245. modele4: {
  246. templateProduit: {
  247. init_function: function () {
  248. this.trigger("modelesOk");
  249. },
  250. next_state: "sortieModele",
  251. pushpop_state: "PushState",
  252. },
  253. pack2: "templateProduit",
  254. pack3: "pack2",
  255. undisplayModele1: {
  256. init_function: function () {
  257. this.trigger("undisplay", "modele4");
  258. },
  259. propagate_event: "undisplayModele1",
  260. pushpop_state: "PopState",
  261. },
  262. undisplayModele2: {
  263. init_function: function () {
  264. this.trigger("undisplay", "modele4");
  265. },
  266. propagate_event: "undisplayModele2",
  267. pushpop_state: "PopState",
  268. },
  269. undisplayModele3: {
  270. init_function: function () {
  271. this.trigger("undisplay", "modele4");
  272. },
  273. pushpop_state: "PopState",
  274. },
  275. ajoutOk: {
  276. init_function: function () {
  277. this.trigger("undisplay", "modele4");
  278. },
  279. propagate_event: "ajoutOk",
  280. pushpop_state: "PopState",
  281. },
  282. },
  283. sortieModele: {
  284. modelesOk: {
  285. init_function: function () {
  286. $(packManager).trigger("modelesOk");
  287. },
  288. },
  289. ajoutOk: {
  290. pushpop_state: "PopState",
  291. },
  292. undisplayModele1: "ajoutOk",
  293. undisplayModele2: "ajoutOk",
  294. undisplayModele3: "ajoutOk",
  295. undisplayModele4: "ajoutOk",
  296. },
  297. DefaultState: {
  298. start: { next_state: "modele1" },
  299. // enterState: {
  300. // init_function: function () {
  301. // highlightState(this, "modelesManager");
  302. // },
  303. // },
  304. enterState: {
  305. init_function: function () {
  306. $("#" + this.currentState).addClass("actif");
  307. },
  308. },
  309. exitState: {
  310. init_function: function () {
  311. $("#" + this.currentState).removeClass("actif");
  312. },
  313. },
  314. undisplay: {
  315. init_function: function (p, e, id) {
  316. $("#display_" + id).addClass("hidden");
  317. },
  318. },
  319. display: {
  320. init_function: function (p, e, id) {
  321. $("#display_" + id).removeClass("hidden");
  322. },
  323. },
  324. choixCategorie: { next_state: "modele1" },
  325. catchEvent: {
  326. init_function: function (p, e) {
  327. $("#transitionText").text(
  328. "modelesManager :" +
  329. this.currentState +
  330. " - événement non géré : " +
  331. e.type
  332. );
  333. },
  334. },
  335. },
  336. };
  337. $(modelesManager).iFSM(modelesManagerDef, {
  338. debug: true,
  339. LogLevel: 2,
  340. });
  341. // === PACK MANAGER ===
  342. var packManagerDef = {
  343. packs: {
  344. pack2: {
  345. init_function: function () {
  346. this.trigger("display", "pack2");
  347. },
  348. next_state: "pack2Etat",
  349. },
  350. pack3: {
  351. init_function: function () {
  352. this.trigger("display", "pack3");
  353. },
  354. next_state: "pack3Etat",
  355. },
  356. templateProduit: { next_state: "sortiePacks" },
  357. ajoutOk: {
  358. init_function: function () {
  359. $(modelesManager).trigger("ajoutOk");
  360. },
  361. },
  362. undisplayModele1: {
  363. init_function: function () {
  364. $(modelesManager).trigger("undisplayModele1");
  365. },
  366. },
  367. undisplayModele2: {
  368. init_function: function () {
  369. $(modelesManager).trigger("undisplayModele2");
  370. },
  371. },
  372. undisplayModele3: {
  373. init_function: function () {
  374. $(modelesManager).trigger("undisplayModele3");
  375. },
  376. },
  377. undisplayModele4: {
  378. init_function: function () {
  379. $(modelesManager).trigger("undisplayModele4");
  380. },
  381. },
  382. },
  383. pack2Etat: {
  384. ajoutOk: {
  385. pushpop_state: "PopState",
  386. init_function: function () {
  387. this.trigger("undisplay", "");
  388. },
  389. },
  390. templateProduit: {
  391. next_state: "sortiePacks",
  392. pushpop_state: "PushState",
  393. },
  394. },
  395. pack3Etat: {
  396. display: {
  397. init_function: function () {
  398. $("#" + this.currentState).addClass("actif");
  399. },
  400. },
  401. undisplay: {
  402. init_function: function () {
  403. $("#" + this.currentState).removeClass("actif");
  404. },
  405. },
  406. ajoutOk: {
  407. pushpop_state: "PopState",
  408. init_function: function () {
  409. $("#transitionText").text("packManager : ajoutOk → infosManager");
  410. $(infosManager).trigger("ajoutOk");
  411. },
  412. },
  413. templateProduit: {
  414. next_state: "sortiePacks",
  415. pushpop_state: "PushState",
  416. },
  417. },
  418. sortiePacks: {
  419. display: {
  420. init_function: function () {
  421. $("#" + this.currentState).addClass("actif");
  422. },
  423. },
  424. undisplay: {
  425. init_function: function () {
  426. $("#" + this.currentState).removeClass("actif");
  427. },
  428. },
  429. enterState: {
  430. // init_function: function () {
  431. // $(infosManager).trigger("mes_gratuiteOk");
  432. // $("#transitionText").text(
  433. // "packManager : arrivée sur sortiePacks → infosManager"
  434. // );
  435. // },
  436. },
  437. },
  438. DefaultState: {
  439. start: { next_state: "packs" },
  440. enterState: {
  441. init_function: function () {
  442. $("#" + this.currentState).addClass("actif");
  443. },
  444. },
  445. exitState: {
  446. init_function: function () {
  447. $("#" + this.currentState).removeClass("actif");
  448. },
  449. },
  450. undisplay: {
  451. init_function: function (p, e, id) {
  452. $("#display_" + id).addClass("hidden");
  453. },
  454. },
  455. display: {
  456. init_function: function (p, e, id) {
  457. $("#display_" + id).removeClass("hidden");
  458. },
  459. },
  460. catchEvent: {
  461. init_function: function (p, e) {
  462. $("#transitionText").text(
  463. "packManager : événement non géré " + e.type
  464. );
  465. },
  466. },
  467. },
  468. };
  469. $(packManager).iFSM(packManagerDef, { debug: true, LogLevel: 2 });
  470. // === INFOS MANAGER ===
  471. var infosManagerDef = {
  472. infos: {
  473. display: {
  474. init_function: function () {
  475. $("#" + this.currentState).addClass("actif");
  476. },
  477. },
  478. undisplay: {
  479. init_function: function () {
  480. $("#" + this.currentState).removeClass("actif");
  481. },
  482. },
  483. mes_gratuiteOk: { next_state: "questionnaire" },
  484. infosOk: { next_state: "infosSortie" },
  485. },
  486. questionnaire: {
  487. display: {
  488. init_function: function () {
  489. $("#" + this.currentState).addClass("actif");
  490. },
  491. },
  492. undisplay: {
  493. init_function: function () {
  494. $("#" + this.currentState).removeClass("actif");
  495. },
  496. },
  497. precisions: { next_state: "precisions" },
  498. infosOk: { next_state: "infosSortie" },
  499. },
  500. precisions: {
  501. display: {
  502. init_function: function () {
  503. $("#" + this.currentState).addClass("actif");
  504. },
  505. },
  506. undisplay: {
  507. init_function: function () {
  508. $("#" + this.currentState).removeClass("actif");
  509. },
  510. },
  511. infosOk: { next_state: "infosSortie" },
  512. },
  513. infosSortie: {
  514. display: {
  515. init_function: function () {
  516. $("#" + this.currentState).addClass("actif");
  517. },
  518. },
  519. undisplay: {
  520. init_function: function () {
  521. $("#" + this.currentState).removeClass("actif");
  522. },
  523. },
  524. },
  525. DefaultState: {
  526. start: { next_state: "infos" },
  527. enterState: {
  528. init_function: function () {
  529. $("#" + this.currentState).addClass("actif");
  530. },
  531. },
  532. exitState: {
  533. init_function: function () {
  534. $("#" + this.currentState).removeClass("actif");
  535. },
  536. },
  537. undisplay: {
  538. init_function: function (p, e, id) {
  539. $("#display_" + id).addClass("hidden");
  540. },
  541. },
  542. display: {
  543. init_function: function (p, e, id) {
  544. $("#display_" + id).removeClass("hidden");
  545. },
  546. },
  547. catchEvent: {
  548. init_function: function (p, e) {
  549. $("#transitionText").text(
  550. "infosManager : événement non géré " + e.type
  551. );
  552. },
  553. },
  554. },
  555. };
  556. $(infosManager).iFSM(infosManagerDef, { debug: true, LogLevel: 2 });
  557. // === GLOBAL MANAGER ===
  558. var globalManagerDef = {
  559. displayManager: {
  560. choixCategorie: {
  561. init_function: function () {
  562. $(modelesManager).trigger("display", "modele1");
  563. },
  564. },
  565. },
  566. votreDevis: {
  567. display: {
  568. init_function: function () {
  569. $("#" + this.currentState).addClass("actif");
  570. },
  571. },
  572. undisplay: {
  573. init_function: function () {
  574. $("#" + this.currentState).removeClass("actif");
  575. },
  576. },
  577. ajoutOk: {
  578. pushpop_state: "PopState",
  579. init_function: function () {
  580. $("#transitionText").text(
  581. "globalManager : ajoutOk → infosManager"
  582. );
  583. $(infosManager).trigger("ajoutOk");
  584. },
  585. },
  586. },
  587. mes: {
  588. display: {
  589. init_function: function () {
  590. $("#" + this.currentState).addClass("actif");
  591. },
  592. },
  593. undisplay: {
  594. init_function: function () {
  595. $("#" + this.currentState).removeClass("actif");
  596. },
  597. },
  598. },
  599. nbButton: {
  600. display: {
  601. init_function: function () {
  602. $("#" + this.currentState).addClass("actif");
  603. },
  604. },
  605. undisplay: {
  606. init_function: function () {
  607. $("#" + this.currentState).removeClass("actif");
  608. },
  609. },
  610. },
  611. options: {
  612. display: {
  613. init_function: function () {
  614. $("#" + this.currentState).addClass("actif");
  615. },
  616. },
  617. undisplay: {
  618. init_function: function () {
  619. $("#" + this.currentState).removeClass("actif");
  620. },
  621. },
  622. },
  623. DefaultState: {
  624. start: { next_state: "displayManager" },
  625. ajoutOkDisplayManager: { next_state: "displayManager" },
  626. enterState: {
  627. init_function: function () {
  628. $("#" + this.currentState).addClass("actif");
  629. },
  630. },
  631. exitState: {
  632. init_function: function () {
  633. $("#" + this.currentState).removeClass("actif");
  634. },
  635. },
  636. undisplay: {
  637. init_function: function (p, e, id) {
  638. $("#display_" + id).addClass("hidden");
  639. },
  640. },
  641. display: {
  642. init_function: function (p, e, id) {
  643. $("#display_" + id).removeClass("hidden");
  644. },
  645. },
  646. catchEvent: {
  647. init_function: function (p, e) {
  648. $("#transitionText").text(
  649. "globalManager : événement non géré " + e.type
  650. );
  651. },
  652. },
  653. },
  654. };
  655. $(globalManager).iFSM(globalManagerDef, { debug: true, LogLevel: 2 });
  656. // === TEST SELECT ===
  657. $("#eventSelect").on("change", function () {
  658. var ev = $(this).val();
  659. if (!ev) return;
  660. $("#transitionText").text("→ Événement déclenché : " + ev);
  661. // Propagation initiale (globalManager en premier)
  662. $(globalManager).trigger(ev);
  663. $(infosManager).trigger(ev);
  664. $(packManager).trigger(ev);
  665. $(modelesManager).trigger(ev);
  666. $(this).val("");
  667. });
  668. </script>
  669. </body>
  670. </html>