let creatingVariable = false; /* * Workspace position modal attributes */ let $workspacePositionModal = $("#workspacePositionModal"); let $workspacePositionModalBody = $("#workspacePositionModalBody"); let $workspacePositionModalPositionsSelect = $("#workspacePositionModalPositionsSelect"); let workspaceToBeAddId = null; let workspaceToBeAddVariable = null; let workspaceToBeAddAfterComponent = null; function addVariable(variable = {name: "", type: dataTypes.String, value: ""}, id = null) { if (creatingVariable === false) { // Blocking future variable creation until finish the current creation creatingVariable = true; let html = ""; html += `
`; html += `
`; html += `
`; html += `

Adicionar variável

`; html += `
`; html += `
`; html += `
`; html += `
`; html += ` `; html += `
`; html += `
`; html += ` `; html += `
`; html += `
`; html += `
`; html += `
`; html += ` `; html += `
`; html += `
`; html += ` `; html += `
`; html += `
`; html += `
`; html += `
`; html += ` `; html += `
`; html += `
`; html += ` `; html += `
`; html += `
`; html += `
`; html += ` `; html += `
`; html += `
`; $workspace.append(html); } } function addVariableToCode({id = null}) { let code = ""; let variable = { name: $("#variableName").val(), type: $("#variableType").val(), value: $("#variableValue").val() }; code = mountCodeFromVariable(variable); // Sending code to screen addCodeToScreen({id: id, code: code, variable: variable}); // Removing div form for variable creation $("#variableCreationDiv").remove(); // Enabling future variable creation creatingVariable = false; } function cancelAddVariable(id = null) { // Removing div form for variable creation $("#variableCreationDiv").remove(); if (id != null) $(`#variableDiv${id}`).show(); // Enabling future variable creation creatingVariable = false; } function editVariable(id = null, variable = {name: "", type: dataTypes.String, value: ""}) { $(`#variableDiv${id}`).hide(); addVariable(variable, id); } function deleteVariable(id = null) { if (id != null) $(`#variableDiv${id}`).remove(); } function addCodeToScreen({ id = null, code = "Some code", variable = {name: "", type: "String", value: ""} }) { let html = ``; if (id != null) { $(`#mainCode${id}`).html(`${code}`); $(`#globalMenu${id}`).val(code); $(`#positionCode${id}`).html(``); $(`#editCode${id}`).html(``); $(`#variableDiv${id}`).show(); } else { html += `
`; html += ` `; html += `
`; html += `
`; html += `

Variável

`; html += `
`; html += `
`; html += `
`; html += `
${getCurrentMainLineNumber()}
`; html += `
${code}
`; html += `
`; html += `
`; html += ` `; html += `
`; html += `
`; $workspace.append(html); } // Increasing universal id universalId += 1; } function askWhereToPlaceTheVariable(id = null, variable = {name: "", type: "String", value: ""}) { if (buildAllWorkspaceComponentsSelect()) { $workspacePositionModal.modal('toggle'); $workspacePositionModalPositionsSelect.focus(); workspaceToBeAddId = id; workspaceToBeAddVariable = variable; } else { addVariableToMain({id: id, variable: variable}); } } function buildAllWorkspaceComponentsSelect() { let allWorkspaceComponents = $(`input[type="hidden"][name="${WORKSPACE_COMPONENTS_NAME}"]`); let selectOptions = []; if (allWorkspaceComponents.length > 0) { for (let i = 0; i < allWorkspaceComponents.length; i++) { console.log(allWorkspaceComponents[i].attributes); selectOptions.push(``); } $workspacePositionModalPositionsSelect.empty(); // remove old options selectOptions.forEach((object, index, array) => { $workspacePositionModalPositionsSelect.append($(object)); }) return true; } else { return false; } } $("#workspacePositionModalAddButton").click(() => { addVariableToMain({id: workspaceToBeAddId, variable: workspaceToBeAddVariable, afterComponentWithId: $workspacePositionModalPositionsSelect.val()}) // Reset variables for future use workspaceToBeAddId = null; workspaceToBeAddVariable = null; // Hide position modal $workspacePositionModal.modal('toggle'); });