window.editPoets = {
poetsSvc: null,
init: function({ moduleId }) {
const sxc = $2sxc(moduleId);
poetsSvc = sxc.data('PoetsToEdit');
},
add: function() {
const newPoet = {
name: document.querySelector('#name').value,
birthdate: document.querySelector('#birthdate').value,
poems: document.querySelector('#poems').value
};
poetsSvc.create(newPoet).then(() => { alert('created poet, will reload'); location.reload(); });
},
delete: function(id) {
poetsSvc.delete(id).then(() => { alert('deleted poet, will reload'); location.reload(); });
},
updateCount: function(id) {
const updatedPoet = {
Poems: Math.floor(Math.random() * 100).toString()
};
poetsSvc.update(id, updatedPoet)
.then(res => {
document.querySelector(`[data-poet='${id}']`).innerText = res.Poems
});
}
}