Created
September 30, 2021 17:58
-
-
Save moisescastillo/f69ccf7f326f5d914bfbc1679cf31bd3 to your computer and use it in GitHub Desktop.
To-Do App Appscript GS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// OnLoad GUI | |
window.addEventListener("load", initGui, true); | |
const tarea = document.getElementById('tarea'); | |
const btnRegistrar = document.getElementById('registrar'); | |
function initGui() { | |
getData(); | |
} | |
btnRegistrar.addEventListener('click', function(e) { | |
let txtTarea = tarea.value; | |
// Validaciones | |
if (txtTarea.trim().length == 0) { | |
tarea.focus(); | |
return false; | |
} | |
let data = { | |
tarea: txtTarea | |
} | |
// Save data | |
google.script.run.withSuccessHandler(guardaTarea).addData(data); | |
}); | |
function guardaTarea() { | |
tarea.value = ''; | |
tarea.focus(); | |
google.script.run.withSuccessHandler(getData).getAllData(); | |
} | |
function getData() { | |
google.script.run.withSuccessHandler(listado).getAllData(); | |
} | |
function listado(data) { | |
document.getElementById('listado').innerHTML = ''; | |
let section = document.querySelector("#listado"); | |
if (data.length > 0) { | |
// Existen actividades | |
data.reverse().forEach(item => { | |
let row = document.querySelector('#row'); | |
let texto = row.content.querySelectorAll('div.content > div.text > a'); | |
let control = row.content.querySelectorAll('div.content > div.control > a'); | |
// href text | |
texto[0].text = item[1]; | |
texto[0].setAttribute("data-id", item[0]); | |
if (parseInt(item[2]) == 1) { | |
texto[0].classList.add("check"); | |
} else { | |
texto[0].classList.remove("check"); | |
} | |
// href control | |
control[0].setAttribute("data-id", item[0]); | |
let clone = document.importNode(row.content, true); | |
section.appendChild(clone); | |
}); | |
// Texto | |
let linkTexto = document.getElementsByClassName("descripcion"); | |
Array.from(linkTexto).forEach(function(el) { | |
el.addEventListener("click", function() { | |
let idCliente = el.getAttribute("data-id"); | |
google.script.run.withSuccessHandler(getData).cambiarEstatus(idCliente); | |
}); | |
}); | |
// Borrar | |
let btnBorrar = document.getElementsByClassName("borrar"); | |
Array.from(btnBorrar).forEach(function(el) { | |
el.addEventListener("click", function() { | |
let idCliente = el.getAttribute("data-id"); | |
google.script.run.withSuccessHandler(getData).deleteRow(idCliente); | |
}); | |
}); | |
} else { | |
// No hay actividades | |
let alert = document.querySelector('#alert'); | |
let clone = document.importNode(alert.content, true); | |
section.appendChild(clone); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment