sub-menu.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. function buildVariablesSubmenu() {
  2. subMenuOptionsTitleH3.innerText = `Variáveis`;
  3. let body = ``;
  4. body += `<hr />`;
  5. body += `<div class="row">`;
  6. body += ` <div class="col-md-12 text-center">`;
  7. body += ` <button type="button" class="btn btn-info" onclick="addVariable()">Adicionar</button>`;
  8. body += ` </div>`;
  9. body += `</div>`;
  10. body += `<hr />`;
  11. let allWorkspaceComponents = $(
  12. `input[type="hidden"][name="${WORKSPACE_COMPONENTS_NAME}"]`
  13. );
  14. // Place after manipulation
  15. body += `<div class="p-3 text-center">`;
  16. body += ` <h5>Disponíveis</h5>`;
  17. body += `</div>`;
  18. for (let i = 0; i < variables.length; i++) {
  19. body += `<div class="row p-3 text-center variable-available-sub-menu" id="subMenuOptionVariable${variables[i].id}">`;
  20. body += ` <div class="col-md-4">`;
  21. body += ` <h5>${variables[i].name}</h5>`;
  22. body += ` </div>`;
  23. body += ` <div class="col-md-8">`;
  24. body += ` <div class="col-md-8">`;
  25. body += ` <select class="form-control" id="placeVariableAfter${i}">`;
  26. body += ` <option value="" disabled>Adicionar após</option>`;
  27. for (let i = 0; i < allWorkspaceComponents.length; i++) {
  28. body += `<option value="${allWorkspaceComponents[i].attributes.universalworkspaceid.value}">${allWorkspaceComponents[i].value}</option>`;
  29. }
  30. body += ` </select>`;
  31. body += ` </div>`;
  32. body += ` </div>`;
  33. body += `</div>`;
  34. body += `<div class="row p-3">`;
  35. body += ` <div class="col-6 text-center">`;
  36. body += ` <button type="button" class="btn btn-info" onclick="positionVariableAfter(${i})">Posicionar</button>`;
  37. body += ` </div>`;
  38. body += ` <div class="col-6 text-center">`;
  39. body += ` <button type="button" class="btn btn-danger" onclick="deleteVariable(${i}, 'subMenuOptionVariable${variables[i].id}')">Excluir</button>`;
  40. body += ` </div>`;
  41. body += `</div>`;
  42. }
  43. body += `<hr />`;
  44. // Value attribution manipulation
  45. body += `<div class="p-3 text-center">`;
  46. body += ` <h5>Atribuir</h5>`;
  47. body += `</div>`;
  48. body += `<div>`;
  49. body += ` <div class="row p-3 variable-attribution-sub-menu">`;
  50. body += ` <div class="col-md-10" class="text-center">`;
  51. body += ` <select class="form-control" id="variableToBeAttributed">`;
  52. for (let i = 0; i < variables.length; i++) {
  53. body += ` <option value="${i}">${variables[i].name}</option>`;
  54. }
  55. body += ` </select>`;
  56. body += ` </div>`;
  57. body += ` <div class="col-md-2 align-content-center">`;
  58. body += ` <h5>=</h5>`;
  59. body += ` </div>`;
  60. body += ` </div>`;
  61. body += ` <div class="row p-4">`;
  62. body += ` <div class="col-md-12 text-center">`;
  63. body += ` <button type="button" class="btn btn-info" onclick="attributeVariable()">Posicionar</button>`;
  64. body += ` </div>`;
  65. body += ` </div>`;
  66. body += `</div>`;
  67. subMenuOptionsBody.innerHTML = body;
  68. subMenuOptions.style.display = 'inline';
  69. }
  70. function positionVariableAfter(variableIndex) {
  71. let placeAfter = $(`#placeVariableAfter${variableIndex} :selected`).val();
  72. if (placeAfter !== "") {
  73. addVariableToMain({
  74. id: universalId.next(),
  75. variable: variables[variableIndex],
  76. afterComponentWithId: placeAfter,
  77. });
  78. } else {
  79. addVariableToMain({
  80. id: universalId.next(),
  81. variable: variables[variableIndex],
  82. });
  83. }
  84. subMenuOptions.style.display = "none";
  85. }
  86. function attributeVariable() {
  87. let variableToBeAttributed = document.getElementById("variableToBeAttributed");
  88. attributeValueToMain({
  89. id: universalId.next(),
  90. variable: variables[variableToBeAttributed.value],
  91. });
  92. hideSubMenu();
  93. }