Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Implementação da função de edição de propriedades #3

Open
wants to merge 1 commit into
base: edit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 81 additions & 83 deletions public/scripts/events.js
Original file line number Diff line number Diff line change
@@ -1,108 +1,106 @@
const removeEventInSchema = function (eventName, eventIndex) {

schema.array.items.splice(eventIndex, 1);

schema.array.items.splice(eventIndex, 1);
};

btnAddEvent.onclick = function () {
let eventName = document.querySelector('#eventName').value;
let newEvent = new Option(eventName, eventName);

document.querySelector('#eventName').value = '';

if (eventName === '') {
alert('Please enter a valid Name');
return;
}

let eventObjt = {
"type": "object",
"properties": {
"event": {
"type": "string",
"enum": [eventName]
}
},
"required": ["event"]
}
schema.array.items.push(eventObjt);
eventList.add(newEvent);

updateSchemaExample(JSON.stringify(schema, undefined, 2));

}

eventList.addEventListener('change', () => {
btnRemoveEvent.hidden = false;
btnEditEvent.hidden = false;
btnAddProperty.hidden = false;

propertyName.disabled = false;
propertyType.disabled = false;
propertyRequired.disabled = false;
propertyValue.disabled = false;
let eventName = document.querySelector("#eventName").value;
let newEvent = new Option(eventName, eventName);

document.querySelector("#eventName").value = "";

if (eventName === "") {
alert("Please enter a valid Name");
return;
}

let eventObjt = {
type: "object",
properties: {
event: {
type: "string",
enum: [eventName],
},
},
required: ["event"],
};
schema.array.items.push(eventObjt);
eventList.add(newEvent);

updateSchemaExample(JSON.stringify(schema, undefined, 2));
};

eventList.addEventListener("change", () => {
btnRemoveEvent.hidden = false;
btnEditEvent.hidden = false;
btnAddProperty.hidden = false;

propertyName.disabled = false;
propertyType.disabled = false;
propertyRequired.disabled = false;
propertyValue.disabled = false;
});

btnRemoveEvent.onclick = function () {
removeEventInSchema(eventList.value, eventList.selectedIndex - 1);
eventList.remove(eventList.selectedIndex);

removeEventInSchema(eventList.value, eventList.selectedIndex - 1);
eventList.remove(eventList.selectedIndex);

if (eventList.length === 1) {
eventList[0].selected = true;
propertyType[0].selected = true;
propertyRequired[0].selected = true;
if (eventList.length === 1) {
eventList[0].selected = true;
propertyType[0].selected = true;
propertyRequired[0].selected = true;

btnRemoveEvent.hidden = true;
btnEditEvent.hidden = true;
btnAddProperty.hidden = true;
btnRemoveEvent.hidden = true;
btnEditEvent.hidden = true;
btnAddProperty.hidden = true;

propertyName.disabled = true;
propertyType.disabled = true;
propertyRequired.disabled = true;
propertyValue.disabled = true;
propertyName.disabled = true;
propertyType.disabled = true;
propertyRequired.disabled = true;
propertyValue.disabled = true;

propertyName.value = '';
propertyValue.value = '';
};
propertyName.value = "";
propertyValue.value = "";
}

updateSchemaExample(JSON.stringify(schema, undefined, 2));
}
updateSchemaExample(JSON.stringify(schema, undefined, 2));
};

//Funções do popup
const popup = document.querySelector('.popup-wrapper')
const close = document.querySelector('.popup-close')
const popup = document.querySelector(".popup-wrapper");
const close = document.querySelector(".popup-close");

btnEditEvent.onclick = function () {
popup.style.display = 'block'
}

close.onclick = function() {
popup.style.display = 'none'
}
popup.style.display = "block";
};

close.onclick = function () {
popup.style.display = "none";
};

//Funções de edit de evento
const addEdit = document.querySelector('#buttonAddEventPopup')
const cancelEdit = document.querySelector('#buttonCancelEventPopup')
const addEdit = document.querySelector("#buttonAddEventPopup");
const cancelEdit = document.querySelector("#buttonCancelEventPopup");

addEdit.onclick = function(){

let eventNameEdit = document.querySelector('#eventNamePopup').value;
let selectEvents = document.querySelectorAll('#eventSelected')[0]
addEdit.onclick = function () {
let eventNameEdit = document.querySelector("#eventNamePopup").value;
let selectEvents = document.querySelectorAll("#eventSelected")[0];

selectEvents.children[selectEvents.selectedIndex].value = eventNameEdit
selectEvents.children[selectEvents.selectedIndex].innerText = eventNameEdit
selectEvents.children[selectEvents.selectedIndex].value = eventNameEdit; //returns the value of events selection list
selectEvents.children[selectEvents.selectedIndex].innerText = eventNameEdit;

schema.array.items[selectEvents.selectedIndex-1].properties.event.enum = [eventNameEdit]
schema.array.items[selectEvents.selectedIndex - 1].properties.event.enum = [
eventNameEdit,
]; //returns the name to be changed

updateSchemaExample(JSON.stringify(schema, undefined, 2));
document.querySelector('#eventNamePopup').value = ""
popup.style.display = 'none'
}
updateSchemaExample(JSON.stringify(schema, undefined, 2));

//clear the fields and close the popup after edits
document.querySelector("#eventNamePopup").value = "";
popup.style.display = "none";
};

cancelEdit.onclick = function() {
document.querySelector('#eventNamePopup').value = ""
popup.style.display = 'none'
}
cancelEdit.onclick = function () {
//function to cancel editing
document.querySelector("#eventNamePopup").value = "";
popup.style.display = "none";
};
Loading