main-variables.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const UNIVERSAL_WORKSPACE_ID = "universalworkspaceid";
  2. const WORKSPACE_COMPONENTS_NAME = "workspaceComponents";
  3. function addVariableToMain({
  4. id = null,
  5. variable = {name: "", type: "String", value: ""},
  6. afterComponentWithId = null,
  7. }) {
  8. let html = ``;
  9. if (afterComponentWithId === null) {
  10. html += `<div class="col-12">`;
  11. html += ` <div class="row">`;
  12. }
  13. html += ` <div class="col-2 p-2 m-2 variable-available-main" id="workspaceVariableDiv${id}">`;
  14. html += ` <input type="hidden" id="workspaceGlobalMenu${id}" name="${WORKSPACE_COMPONENTS_NAME}" value='${variable.name}' ${UNIVERSAL_WORKSPACE_ID}="${id}">`;
  15. html += ` <input type="hidden" id="variableId${id}" value='${variable.id}'>`;
  16. html += ` <input type="hidden" name="mainOperationsType" value='${mainCodeTypes.variable}'>`;
  17. html += ` <div class="row">`;
  18. html += ` <div class="col-9 pt-2 text-center" style="border-right: 1px solid #646464;">`;
  19. html += ` <h6>${variable.name}</h6>`;
  20. html += ` </div>`;
  21. html += ` <div class="col-3 text-center" style="border-left: 1px solid #646464;">`;
  22. html += ` <button type="button" class="btn btn-danger" onclick="deleteVariableFromMain(${id})">X</button>`;
  23. html += ` </div>`;
  24. html += ` </div>`;
  25. html += ` </div>`;
  26. if (afterComponentWithId === null) {
  27. html += ` </div>`;
  28. html += `</div>`;
  29. }
  30. if (afterComponentWithId == null) {
  31. $main.append(html);
  32. } else {
  33. $(html).insertAfter(`#workspaceVariableDiv${afterComponentWithId}`);
  34. }
  35. variable.usages.push(document.getElementById(`workspaceVariableDiv${id}`));
  36. }
  37. function attributeValueToMain({
  38. id = null,
  39. variable = {name: "", type: "String", value: ""},
  40. }) {
  41. let html = ``;
  42. html += `<div class="col-12">`;
  43. html += ` <div class="row">`;
  44. html += ` <div class="col-2 p-2 m-2 variable-attribution-main" id="workspaceVariableDiv${id}">`;
  45. html += ` <input type="hidden" id="workspaceGlobalMenu${id}" name="${WORKSPACE_COMPONENTS_NAME}" value='${variable.name} = ' ${UNIVERSAL_WORKSPACE_ID}="${id}">`;
  46. html += ` <input type="hidden" id="variableId${id}" value='${variable.id}'>`;
  47. html += ` <input type="hidden" name="mainOperationsType" value='${mainCodeTypes.attribution}'>`;
  48. html += ` <div class="row">`;
  49. html += ` <div class="col-9 pt-2 text-center" style="border-right: 1px solid #646464;">`;
  50. html += ` <h6>${variable.name} = </h6>`;
  51. html += ` </div>`;
  52. html += ` <div class="col-3 text-center" style="border-left: 1px solid #646464;">`;
  53. html += ` <button type="button" class="btn btn-danger" onclick="deleteVariableFromMain(${id})">X</button>`;
  54. html += ` </div>`;
  55. html += ` </div>`;
  56. html += ` </div>`;
  57. html += ` </div>`;
  58. html += `</div>`;
  59. $main.append(html);
  60. variable.attributions.push(document.getElementById(`workspaceVariableDiv${id}`));
  61. }
  62. function deleteVariableFromMain(id = null) {
  63. $(`#workspaceVariableDiv${id}`).remove();
  64. }