optionsCTRL.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var tableOptions = [["Ajouter une nouvelle loi", false],["Améliorer une loi", false],["Supprimer une loi", false]];
  2. function chooseOption(id) {
  3. let listLaws = document.querySelector("#listLaws");
  4. listLaws.innerHTML = genListeTableLaws();
  5. switch (id) {
  6. case 0:
  7. listLaws.innerHTML = genListeAddLaws();
  8. break;
  9. case 1:
  10. listLaws.innerHTML = genListeUpgradeLaws();
  11. break;
  12. case 2:
  13. listLaws.innerHTML = genListeRemoveLaws();
  14. break;
  15. default:
  16. listLaws.innerHTML = genListeTableLaws();
  17. }
  18. enableOption(id);
  19. }
  20. function genListeOptions(newEventId) {
  21. console.log(newEventId);
  22. let element = document.querySelector("#options");
  23. let res = "";
  24. if (newEventId == -1) {
  25. for (var i = 0; i < tableOptions.length; i++) {
  26. res = res + genOption(i);
  27. }
  28. element.innerHTML = res;
  29. console.log(newEventId);
  30. }
  31. else {
  32. console.log("ca marche2");
  33. element.innerHTML = genAddEventLaw(newEventId, 0) + genAddEventLaw(newEventId, 1);
  34. }
  35. }
  36. function enableOption(id) {
  37. for (var i = 0; i < tableOptions.length; i++) {
  38. if (i == id) {
  39. tableOptions[i][1] = true;
  40. }
  41. else {
  42. tableOptions[i][1] = false;
  43. }
  44. }
  45. genListeOptions();
  46. }
  47. function resetOptions() {
  48. for (var i = 0; i < tableOptions.length; i++) {
  49. tableOptions[i][1] = false;
  50. }
  51. }
  52. function genOption(id, newEventId) {
  53. return "<p onClick=\"chooseOption(" + id + ")\">" + tableOptions[id][0] + "</p>";
  54. }