Last active
August 20, 2016 03:02
-
-
Save Telematica/5bc9f73781f33e6da6356f5a7c550c0f to your computer and use it in GitHub Desktop.
HITSS Host Hours AutoSubmission
This file contains hidden or 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
//;(function(window, $, datos) { | |
/** | |
* | |
* @ToDo Find calendar days | |
* | |
*/ | |
var activities =[ | |
{ 'Id_Actividad' : 380814, 'horas' : 2 }, //ANALISIS | |
{ 'Id_Actividad' : 380812, 'horas' : 6 } //DESARROLLO | |
] | |
,data = { | |
"Id_Proyecto": datos.Id_ProyectoDefault, //document.querySelector('[data-id_proyecto]').dataset.id_proyecto, | |
"Id_Recurso": document.getElementById('Id_Recurso').value, | |
"FechaDia": "2016-07-01", // "yyyy-mm-dd" : "2016-05-06" | |
"Comentario": "", //can be blank | |
"Actividades": [{ | |
"Id_CapturaActividad": "0", | |
"Id_Actividad": "380814", | |
"HorasCapturadas": "2", | |
"Comentario": "", | |
"HorasExtras": false, | |
"HorasNocturnas": false, | |
"Bloqueada": false | |
}], | |
"pantallaCaptura": true, | |
"Latitude": 0, | |
"Longitude": 0 | |
},days = getBusinessDayData(); //Request Payload | |
main(); | |
function main() { | |
Notification.requestPermission().then(function(result){ | |
if ('granted' === result) { | |
//new Notification('Starting Activity capture...'); | |
var dayData = days.next(); | |
data["FechaDia"] = dayData.value.day; | |
data["Actividades"][0]["Id_Actividad"] = dayData.value.activity['Id_Actividad']; | |
data["Actividades"][0]["HorasCapturadas"] = dayData.value.activity["horas"]; | |
serverRequest(); | |
} | |
}); | |
} | |
function* getBusinessDayData() { | |
var index = 0; | |
var count = -1; | |
var currentDate = getBusinessDays()[index++]; | |
while(index < getBusinessDays().length) { | |
if (1 === count) { | |
count = 0; | |
yield { day: (currentDate = getBusinessDays()[index++]), activity: activities[count] }; | |
} | |
++count; | |
yield { day: currentDate, activity: activities[count] }; | |
} | |
} | |
function getBusinessDays() { | |
var weeks = document.getElementById('calendario').querySelector('table.ui-datepicker-calendar').querySelector('tbody').querySelectorAll('tr') | |
,daysPerWeek | |
,day | |
,month | |
,year | |
,dayList = []; | |
for (var i = 0; i < weeks.length; ++i) { | |
daysPerWeek = weeks[i].querySelectorAll('a:not(.diaInhabil)'); | |
for (var j = 0; j < daysPerWeek.length; ++j) { | |
year = daysPerWeek[j].parentNode.dataset.year; | |
month = parseInt(daysPerWeek[j].parentNode.dataset.month, 10) + 1; // Months data from 0 to 11 | |
month = ((month).toString().length === 1 ? '0' + (month).toString() : (month).toString() ); | |
day = daysPerWeek[j].textContent.length === 1 ? '0'+daysPerWeek[j].textContent : daysPerWeek[j].textContent; | |
dayList.push(year+'-'+month+'-'+day); | |
} | |
} | |
return dayList; | |
} | |
function checkActivitiesByDay() { | |
var activityDays = document.querySelectorAll('[id*="diaActividadesAcordion_"]'); | |
if(activityDays.length === 0) { | |
} | |
} | |
function serverRequest() { | |
var ajaxRequest = new XMLHttpRequest(), | |
url = '/Horas/ActualizaActividades2'; //Request URL:http://host.globalhitss.com/Horas/ActualizaActividades2 | |
ajaxRequest.open('POST', url, true); | |
//Request Headers | |
ajaxRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | |
ajaxRequest.setRequestHeader('Accept', 'application/json, text/javascript, */*; q=0.01'); | |
ajaxRequest.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); | |
//AJAX Events | |
ajaxRequest.onload = function() { | |
if (ajaxRequest.readyState === 4) { | |
if (ajaxRequest.status === 200) { | |
var dayData = days.next(); | |
if (undefined === dayData.value) | |
{ | |
return new Notification('No more days to capture.'); | |
} | |
data["FechaDia"] = dayData.value.day; | |
data["Actividades"][0]["Id_Actividad"] = dayData.value.activity['Id_Actividad']; | |
data["Actividades"][0]["HorasCapturadas"] = dayData.value.activity["horas"]; | |
serverRequest(); | |
return new Notification('Setting Activity: ' + dayData.value.activity['Id_Actividad'] + ' from day ' + data["FechaDia"]); | |
console.log(ajaxRequest.responseText); | |
} else { | |
console.error(ajaxRequest.statusText); | |
return new Notification('Server responded the request, but an Error occurred! Check the logged data on console!'); | |
} | |
} | |
}; | |
ajaxRequest.onerror = function(e) { | |
console.error(ajaxRequest.statusText); | |
return new Notification('Error on Server! Check the logged data on console!'); | |
}; | |
//Perform and Return Request | |
return ajaxRequest.send(JSON.stringify(data)); | |
} | |
/** | |
* | |
* | |
*/ | |
function showNotification(message) { | |
var notification = new Notification(message); | |
} | |
/** | |
* | |
* @ToDo Play day action | |
* @deprecated | |
* | |
*/ | |
function planDay() { | |
var submitButton = $('#btnOk') | |
,comboActivities = $('#cmbActividades') | |
,comboHours = $('#HorasCapturadas') | |
,analysisActivityValue = 380814 | |
,analysisHrs = 2 | |
,developmentActivityValue = 380812 | |
,developmentHrs = 6; | |
/** | |
* Horas de análisis: 2hrs | |
*/ | |
comboActivities.val(analysisActivityValue); //(G) ANALISIS | |
comboHours.val(analysisHrs); | |
submitButton.trigger('click'); | |
/** | |
* Horas de desarrollo: 6hrs | |
*/ | |
comboActivities.val(developmentActivityValue); //(G) ANALISIS | |
comboHours.val(developmentHrs); | |
submitButton.trigger('click'); | |
} | |
//})(window, $); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment