main-operators.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. function placeOperationAt() {
  2. let firstVariable = document.getElementById('firstOperationSubMenuVariable');
  3. let operation = document.getElementById('operationTypeSubMenu');
  4. let secondVariable = document.getElementById('secondOperationSubMenuVariable');
  5. let id = universalId.next();
  6. let html = ``;
  7. let compiledView = `${variables[firstVariable.value].name} ${getOperationByValue(operation.value).operator} ${variables[secondVariable.value].name}`;
  8. html += `<div class="col-2 p-2 m-2 operation-main" id="workspaceVariableDiv${id}">`;
  9. html += ` <input type="hidden" id="workspaceGlobalMenu${id}" name="${WORKSPACE_COMPONENTS_NAME}" value='${compiledView}' ${UNIVERSAL_WORKSPACE_ID}="${id}">`;
  10. html += ` <input type="hidden" id="operationId${id}" value='${id}'>`;
  11. html += ` <input type="hidden" name="mainOperationsType" value='${mainCodeTypes.operation}'>`;
  12. html += ` <div class="row">`;
  13. html += ` <div class="col-9 pt-2 text-center" style="border-right: 1px solid #646464;">`;
  14. html += ` <h6>${compiledView}</h6>`;
  15. html += ` </div>`;
  16. html += ` <div class="col-3 text-center" style="border-left: 1px solid #646464;">`;
  17. html += ` <button type="button" class="btn btn-danger" onclick="deleteOperationFromMain(${id})">X</button>`;
  18. html += ` </div>`;
  19. html += ` </div>`;
  20. html += `</div>`;
  21. $(html).insertAfter(`#workspaceVariableDiv${document.getElementById('placeOperationAt').value}`);
  22. operations.push({
  23. id: id,
  24. firstVariable: variables[firstVariable.value],
  25. operation: getOperationByValue(operation.value),
  26. secondVariable: variables[secondVariable.value],
  27. usage: document.getElementById(`workspaceVariableDiv${id}`)
  28. });
  29. variables[firstVariable.value].usages.push(document.getElementById(`workspaceVariableDiv${id}`));
  30. variables[secondVariable.value].usages.push(document.getElementById(`workspaceVariableDiv${id}`));
  31. hideSubMenu();
  32. }
  33. function placeOperatorAt() {
  34. let operator = getOperationByValue(document.getElementById('operatorTypeSubMenu').value);
  35. let id = universalId.next();
  36. let html = ``;
  37. html += `<div class="col-2 p-2 m-2 operation-main" id="workspaceVariableDiv${id}">`;
  38. html += ` <input type="hidden" id="workspaceGlobalMenu${id}" name="${WORKSPACE_COMPONENTS_NAME}" value='${operator.operator}' ${UNIVERSAL_WORKSPACE_ID}="${id}">`;
  39. html += ` <input type="hidden" id="operatorValue${id}" value='${operator.value}'>`;
  40. html += ` <input type="hidden" name="mainOperationsType" value='${mainCodeTypes.operator}'>`;
  41. html += ` <div class="row">`;
  42. html += ` <div class="col-9 pt-2 text-center" style="border-right: 1px solid #646464;">`;
  43. html += ` <h6>${operator.operator}</h6>`;
  44. html += ` </div>`;
  45. html += ` <div class="col-3 text-center" style="border-left: 1px solid #646464;">`;
  46. html += ` <button type="button" class="btn btn-danger" onclick="deleteOperatorFromMain(${id})">X</button>`;
  47. html += ` </div>`;
  48. html += ` </div>`;
  49. html += `</div>`;
  50. $(html).insertAfter(`#workspaceVariableDiv${document.getElementById('placeOperatorAt').value}`);
  51. operatorsMain.push({
  52. id: id,
  53. operation: operator,
  54. usage: document.getElementById(`workspaceVariableDiv${id}`)
  55. });
  56. hideSubMenu();
  57. }
  58. function deleteOperationFromMain(id) {
  59. for (let i = 0; i < operations.length; i++) {
  60. if (operations[i].id === id) {
  61. operations[i].usage.remove();
  62. operations.splice(i, 1);
  63. }
  64. }
  65. }
  66. function deleteOperatorFromMain(id) {
  67. for (let i = 0; i < operatorsMain.length; i++) {
  68. if (operatorsMain[i].id === id) {
  69. operatorsMain[i].usage.remove();
  70. operatorsMain.splice(i, 1);
  71. }
  72. }
  73. }