App-Dochazka-WWW
view release on metacpan or search on metacpan
share/js/dochazka-www/caches.js view on Meta::CPAN
if (currentUser('flag1') === 1) {
// masquerade active; we are admin
rest["path"] = 'employee/eid/' + eid + '/full';
} else {
rest["path"] = 'employee/self/full';
}
sc = function (st) {
if (st.code === 'DISPATCH_EMPLOYEE_PROFILE_FULL') {
profileObj = $.extend(Object.create(appPrototypes.empProfile), st.payload);
setProfileCache(profileObj);
} else {
m = "Unexpected status code " + st.code;
console.log("CRITICAL ERROR: " + m);
coreLib.displayError(m);
}
populateContinue(populateArray);
};
fc = function (st) {
coreLib.displayError(st.payload.message);
populateContinue(populateArray);
};
ajax(rest, sc, fc);
},
populateLastExisting = function (populateArray) {
var cu = currentUser('obj'),
eid = cu.eid,
date, lia, tsr,
rest, sc, fc, populateContinue;
date = $("#iNdate").text();
console.log("Entering populateLastExisting() with date " + date);
populateContinue = populate.shift(populateArray);
tsr = fullDayTsrange(date);
rest = {
"method": "GET",
"path": "interval/eid/" + eid + "/" + tsr,
};
sc = function (st) {
if (st.code === "DISPATCH_RECORDS_FOUND") {
// payload is an array of interval objects
lia = [st.payload[st.payload.length - 1]];
appLib.displayIntervals(lia, $('#iNlastexistintvl'));
}
populateContinue(populateArray);
};
fc = function (st) {
if (st.code === "DISPATCH_NOTHING_IN_TSRANGE") {
// form field is pre-populated with "(none)"
coreLib.clearResult();
} else {
coreLib.displayError(st.payload.message);
}
populateContinue(populateArray);
};
ajax(rest, sc, fc);
},
populateLastPlusOffset = function (populateArray) {
var beginTime,
date = $('#iNdate').text(),
eolei,
endTime,
i,
lastExistIntvl = $('#iNlastexistintvl').text().trim().replace(/\s/g, ''),
offset = $('#iNoffset').text(),
schedAfter,
schedIntvls = $('#iNschedintvls').text().trim().replace(/\s/g, '').split(';'),
withinSchedIntvl,
rest, sc, fc, populateContinue;
console.log("Entering populateLastPlusOffset()");
console.log("Date", date);
console.log("Offset", offset);
if (schedIntvls.length === 1 && schedIntvls[0] === "(none)") {
schedIntvls = null;
}
console.log("Schedule intervals", schedIntvls);
if (lastExistIntvl === "(none)") {
lastExistIntvl = null;
}
console.log("Last existing interval", lastExistIntvl);
populateContinue = populate.shift(populateArray);
// no schedule intervals, no last existing interval
if (! schedIntvls && ! lastExistIntvl) {
[beginTime, endTime] = dt.canonicalizeTimeRangeOffset("00:00" + String(offset));
populateLastPlusOffsetFormFields(beginTime + '-' + endTime);
populateContinue(populateArray);
return null;
}
if (! schedIntvls && lastExistIntvl) {
[beginTime, endTime] = lastExistIntvl.split('-');
[beginTime, endTime] = dt.canonicalizeTimeRangeOffset(endTime + String(offset));
populateLastPlusOffsetFormFields(beginTime + '-' + endTime);
populateContinue(populateArray);
return null;
}
if (schedIntvls && ! lastExistIntvl) {
[beginTime, endTime] = schedIntvls[0].split('-');
[beginTime, endTime] = dt.canonicalizeTimeRangeOffset(beginTime + String(offset));
populateLastPlusOffsetFormFields(beginTime + '-' + endTime);
populateContinue(populateArray);
return null;
}
// Names/meanings of variables
//
// "eolei": end of last existing interval
[beginTime, endTime] = lastExistIntvl.split('-');
eolei = endTime;
console.log("eolei is " + eolei);
//
// "withinSchedIntvl": eolei falls within a schedule interval (boolean)
// Example: eolei is 8:00, schedIntvl is 8:00-12:00 -> true
// Example: eolei is 12:00, schedIntvl is 8:00-12:00 -> false
// Example: eolei is 11:55, schedIntvl is 8:00-12:00 -> true
// (Calculate withSchedIntvl by comparing eolei with each schedIntvl in turn.
// If computation is true for any of them, then the result is true)
for (i = 0; i < schedIntvls.length; i += 1) {
withinSchedIntvl = dt.isTimeWithinTimeRange(eolei, schedIntvls[i]);
if (withinSchedIntvl) {
[beginTime, endTime] = dt.canonicalizeTimeRangeOffset(eolei + String(offset));
populateLastPlusOffsetFormFields(beginTime + '-' + endTime);
populateContinue(populateArray);
return null;
}
}
console.log("eolei does not fall within any of the schedule intervals");
//
// "schedAfter": first schedule interval that lies fully after eolei
schedAfter = null;
for (i = 0; i < schedIntvls.length; i += 1) {
if (dt.isTimeRangeAfterTime(schedIntvls[i], eolei)) {
schedAfter = schedIntvls[i];
break;
}
}
// if schedAfter, add offset to beginning of schedAfter
// else, add offset to eolei
if (schedAfter) {
console.log("There is a schedule interval after eolei");
[beginTime, endTime] = schedAfter.split('-');
[beginTime, endTime] = dt.canonicalizeTimeRangeOffset(beginTime + String(offset));
} else {
console.log("There is no schedule interval after eolei");
[beginTime, endTime] = dt.canonicalizeTimeRangeOffset(eolei + String(offset));
}
populateLastPlusOffsetFormFields(beginTime + '-' + endTime);
populateContinue(populateArray);
},
populateLastPlusOffsetFormFields = function (buf) {
var formField = $('#iNlastplusoffset'),
formInput = $('input[id="iNtimerange"');
formField.html(String(buf));
formInput.val(String(buf));
},
populateNextScheduled = function (populateArray) {
var cu = currentUser('obj'),
schedIntvls = $('#iNschedintvls').text(),
m, sid, date, rest, sc, fc, populateContinue;
date = $("#iNdate").text();
console.log("Entering populateNextScheduled() with date " + date);
if (date === "(none)") {
date = null;
}
// Though #iNsid is hidden, the following will display its value
// console.log("SID", document.getElementById("iNsid").textContent);
populateContinue = populate.shift(populateArray);
sid = parseInt($("#iNsid").text(), 10);
if (coreLib.isInteger(sid) && sid > 0) {
console.log("Active schedule of EID " + cu.eid + " for " + date + " has SID " + sid);
} else {
m = "User " + cu.nick + " has no active schedule for " + date;
console.log(m);
coreLib.displayError(m);
populateContinue(populateArray);
return null;
}
// there is an active schedule: determine the schedule intervals
// while avoiding existing intervals
if (schedIntvls === "(none)") {
schedIntvls = null;
}
rest = {
"method": "POST",
"path": "interval/fillup",
"body": {
'clobber': '0',
'tsrange': fullDayTsrange(date),
'dry_run': '1',
'eid': String(cu.eid),
},
};
sc = function (st) {
if (st.code === "DISPATCH_SCHEDULED_INTERVALS_IDENTIFIED") {
appLib.displayIntervals([st.payload.success.intervals[0]], $('#iNnextscheduled'));
$('input[id="iNtimerange"]').val(
dt.tsrangeToTimeRange(st.payload.success.intervals[0].intvl)
);
} else {
if (date) {
m = "No unfulfilled scheduled intervals for " + date;
} else {
m = "No date given";
( run in 2.851 seconds using v1.01-cache-2.11-cpan-df04353d9ac )