Skip to content

Instantly share code, notes, and snippets.

@doivosevic
Created September 29, 2015 13:41
Show Gist options
  • Save doivosevic/8d2de0c20d726cdc0423 to your computer and use it in GitHub Desktop.
Save doivosevic/8d2de0c20d726cdc0423 to your computer and use it in GitHub Desktop.
function getProjectsTasksTicketsJobTypesLoccosEvents() {
console.log("getProjectsTasksTicketsJobTypesLoccosEvents");
var executionCounterGet = -1;
function nextGet() {
if (executionCounterGet >= executionOrderGet.length - 1) return;
executionCounterGet++;
executionOrderGet[executionCounterGet]();
return;
}
function getAllXfromCalendarApi() {
var itemName = itemNameList[executionCounterGet];
var path = 'http://localhost:48484/api/Calendar/get' + itemName;
$.get(path, function (data) {
if (itemName == 'events') eventsCallback(data);
else defaultCallback(data);
});
}
function defaultCallback(data) {
itemName = itemNameList[executionCounterGet];
window[itemName] = {};
data.forEach(function (item) { window[itemName][item.Id] = item; });
nextGet();
}
function eventsCallback(data) {
window.events = data;
// POPULATION OF THE CALENDAR WITH THE EVENTS FROM THE DATABASE
/// ADD ALL EVENT DATA WHICH IS REQUIRED FOR NORMAL CALENDAR FUNCTIONALITY
for (var i = 0; i < events.length; ++i) {
var startTime = moment(events[i].StartTime);
var endTime = moment(events[i].EndTime);
if (startTime.minute() != 0 && startTime.minute() != 15 && startTime.minute() != 30 && startTime.minute() != 45
|| endTime.minute() != 0 && endTime.minute() != 15 && endTime.minute() != 30 && endTime.minute() != 45
|| startTime.second() != 0 || endTime.second() != 0) {
console.log("Invalid event from service");
console.log(events[i]);
//deleteEventInDbWithoutPopup(events[i]);
continue;
}
events[i].title = "Event: " + events[i].IdEvent;
events[i].start = events[i].StartTime;
events[i].end = events[i].EndTime;
events[i].id = events[i].IdEvent;
}
next();
}
var itemNameList = ['projects', 'tasks', 'tickets', 'jobtypes', 'loccos', 'events'];
var executionOrderGet = [
getAllXfromCalendarApi,
getAllXfromCalendarApi,
getAllXfromCalendarApi,
getAllXfromCalendarApi,
getAllXfromCalendarApi,
getAllXfromCalendarApi,
next
];
nextGet();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment