Last active
May 2, 2020 18:25
-
-
Save nescalante/9835058 to your computer and use it in GitHub Desktop.
Horas del SCP
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
var doc = window.frames[1] ? window.frames[1].frames[0].document : document, | |
user = doc.all.usuario_id.value, | |
array = doc.querySelectorAll(".linkmenu > div[width]"), | |
list = [], | |
url = "/SCP/cargaHoras/blanco.asp", | |
proyecto = getByName('cmb_proyectos'), | |
tarea = getByName('cmb_tareas'), | |
empresa = getByName('cmb_empresas'), | |
request = { | |
usuario: user, | |
proyecto: proyecto || '1-100686', | |
tarea: tarea || '3', | |
empresa: empresa || '1037', | |
horas: 8, | |
descrip: getByName('textfield') || 'Desarrollo', | |
accion: 'addtarea', | |
Ttarea: '3', | |
pIdCQ: 'SCP' | |
}; | |
for (var i in array) { | |
if (array[i].innerHTML == "") { | |
var day = array[i].id.substring(5); | |
if (!isDomingo(day) && !isFeriado(day) && isAvailable(day)) { | |
request.per = day.substring(0, 6) | |
list.push(day); | |
} | |
} | |
} | |
var confirmMessage = "carga de horas para los días: \n\n" + list.map(function (i) { return i.substring(6) + "/" + i.substring(4,6) }).join(", "); | |
if (!proyecto || !tarea || !empresa) { | |
confirmMessage += "\n\nalerta: no se llenaron los datos del proyecto en el formulario, se utilizarán los valores por defecto (CCR)." | |
} | |
if (list.length == 0) { | |
alert("no hay dias pendientes por cargar.") | |
} | |
else if (confirm(confirmMessage)) { | |
document.write("<p>cargando horas</p>"); | |
call(); | |
} | |
function getByName(name) { | |
var val = doc.getElementsByName(name)[0].value; | |
return val == "-1" || val == "" ? null : val; | |
} | |
function isDomingo(param) { | |
return doc.querySelectorAll(".linkDomingo #div" + param).length > 0; | |
} | |
function isFeriado(param) { | |
return doc.querySelectorAll("#td" + param + ".CajaN").length > 0; | |
} | |
function isAvailable(param) { | |
return doc.querySelectorAll("#div" + param).length > 0; | |
} | |
function call(index) { | |
document.write("."); | |
index = index || 0; | |
request.dia = list[index]; | |
var currentUrl = createUrl(request), | |
xhr = new XMLHttpRequest(); | |
xhr.open('GET', currentUrl, true); | |
xhr.onload = function(e){ | |
if (this.status === 200) { | |
if (list[index + 1]) { | |
call(index + 1); | |
} | |
else { | |
document.write("<p>recargando ...</p>"); | |
window.location.reload(); | |
} | |
} | |
}; | |
xhr.send(); | |
} | |
function createUrl(values) { | |
var result = url + "?", | |
isFirst = true; | |
for (var i in values) { | |
if (!isFirst) { | |
result = result + "&"; | |
} | |
result = result + i + "="+ values[i]; | |
isFirst = false; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment