optionsCTRL.js 1.4 KB

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