|
|
@@ -1,6 +1,12 @@
|
|
|
-$(document).ready(function() {
|
|
|
+// @require DOMParser - browser
|
|
|
+// @require jQuery, moment, p5UI__notifyAjaxCallback
|
|
|
+if ('undefined' === typeof BASE_URL) throw "Missing BASE_URL"
|
|
|
+if ('undefined' === typeof USER) throw "Missing USER"
|
|
|
+if ('undefined' === typeof CALENDAR_NODE_ID) throw "Missing CALENDAR_NODE_ID"
|
|
|
+
|
|
|
+jQuery(document).ready(function() {
|
|
|
var cached = {};
|
|
|
- $('#calendar').fullCalendar({
|
|
|
+ jQuery('#' + CALENDAR_NODE_ID).fullCalendar({
|
|
|
header: {
|
|
|
left: 'prev,next today',
|
|
|
center: 'title',
|
|
|
@@ -23,6 +29,39 @@ $(document).ready(function() {
|
|
|
],*/
|
|
|
});
|
|
|
|
|
|
+ function parseWfsFeatureMember(featureMember) { // HTMLCollection.children @returns event { id, start_work_hour, end_work_hour, date }
|
|
|
+ // gml:featureMember / p5_default_db:GRAFIK_PRACY / p5_default_db:ID
|
|
|
+ // gml:featureMember / p5_default_db:GRAFIK_PRACY / p5_default_db:START_WORK_HOUR
|
|
|
+ // gml:featureMember / p5_default_db:GRAFIK_PRACY / p5_default_db:END_WORK_HOUR
|
|
|
+ // gml:featureMember / p5_default_db:GRAFIK_PRACY / p5_default_db:DATE
|
|
|
+ if (!featureMember) return null
|
|
|
+ if (!featureMember.children.length) return null
|
|
|
+ var grafik = featureMember.children[0]
|
|
|
+ if (!grafik) return null
|
|
|
+ if (!grafik.children.length) return null
|
|
|
+ var calendarItem = {
|
|
|
+ id: null,
|
|
|
+ start_work_hour: null,
|
|
|
+ end_work_hour: null,
|
|
|
+ date: null,
|
|
|
+ }
|
|
|
+ var i = 0
|
|
|
+ for (i = 0; i < grafik.children.length; i++) {
|
|
|
+ var field = grafik.children[i]
|
|
|
+ switch (field.localName) {
|
|
|
+ case 'ID': calendarItem.id = field.textContent; break;
|
|
|
+ case 'START_WORK_HOUR': calendarItem.start_work_hour = field.textContent; break;
|
|
|
+ case 'END_WORK_HOUR': calendarItem.end_work_hour = field.textContent; break;
|
|
|
+ case 'DATE': calendarItem.date = field.textContent; break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!calendarItem.id) return null
|
|
|
+ if (!calendarItem.start_work_hour) return null
|
|
|
+ if (!calendarItem.end_work_hour) return null
|
|
|
+ if (!calendarItem.date) return null
|
|
|
+ return calendarItem
|
|
|
+ }
|
|
|
+
|
|
|
function getWorkingHours(date) {
|
|
|
if (cached[date] != true) {
|
|
|
cached[date] = true;
|
|
|
@@ -30,42 +69,29 @@ $(document).ready(function() {
|
|
|
//console.log(link);
|
|
|
if (DBG) console.log('DBG API fetch', link);
|
|
|
|
|
|
- $.get(link, function(data){
|
|
|
- if (DBG) console.log('DBG jQuery.fn.jquery', jQuery.fn.jquery);
|
|
|
- if (DBG) console.log('DBG fetched data', data);
|
|
|
- if (DBG) console.log('DBG $ data', $(data));
|
|
|
- if (DBG) console.log('DBG $ data.children()', $(data).children());
|
|
|
- if (DBG) console.log('DBG $ data.children().children()', $(data).children().children());
|
|
|
- // if (DBG) console.log('DBG featureMembers $ parsed', $($.parseXML(data)).find("gml:featureMember"));
|
|
|
- if (DBG) console.log('DBG featureMembers $', $(data).find("featureMember"));
|
|
|
- if (DBG) console.log('DBG featuremembers $', $(data).find("featuremember"));
|
|
|
- $.each($($(data).children()[0]).children(), function() {
|
|
|
- var item = { // BUG not working everywhere
|
|
|
- id: $(this).find("ID").text(),
|
|
|
- start_work_hour: $(this).find("START_WORK_HOUR").text(),
|
|
|
- end_work_hour: $(this).find("END_WORK_HOUR").text(),
|
|
|
- date: $(this).find("DATE").text(),
|
|
|
- };
|
|
|
- if (!$(this)[0]) {
|
|
|
- if (DBG) console.warn("Missing $(this)[0]", $(this));
|
|
|
- return false;
|
|
|
- }
|
|
|
- var fmNode = $(this)[0]
|
|
|
- var item = {
|
|
|
- id: fmNode.getElementsByTagName('ID'),
|
|
|
- start_work_hour: fmNode.getElementsByTagName("START_WORK_HOUR"),
|
|
|
- end_work_hour: fmNode.getElementsByTagName("END_WORK_HOUR"),
|
|
|
- date: fmNode.getElementsByTagName("DATE"),
|
|
|
- };
|
|
|
- if (item.id) item.id = $(item.id).text();
|
|
|
- if (item.start_work_hour) item.start_work_hour = $(item.start_work_hour).text();
|
|
|
- if (item.end_work_hour) item.end_work_hour = $(item.end_work_hour).text();
|
|
|
- if (item.date) item.date = $(item.date).text();
|
|
|
- if (DBG) console.log('DBG featureMember item', item);
|
|
|
- if (!item.id) {
|
|
|
- if (DBG) console.warn('Missing featureMember item', item);
|
|
|
- return false;
|
|
|
- }
|
|
|
+ window.fetch(link, {
|
|
|
+ method: 'GET',
|
|
|
+ credentials: 'same-origin',
|
|
|
+ }).then(function (response) {
|
|
|
+ return response.text()
|
|
|
+ }).then(function (txtResponse) {
|
|
|
+ // return jQuery.parseXML(txtResponse)
|
|
|
+ var xmlParser = new DOMParser();
|
|
|
+ return xmlParser.parseFromString(txtResponse, "text/xml");
|
|
|
+ }).then(function (xmlResponse) {
|
|
|
+ if (!xmlResponse.children.length) throw "Missing response xml root element"
|
|
|
+ return xmlResponse.children[0]
|
|
|
+ }).then(function (wfsFeatureCollection) {
|
|
|
+ if ('wfs:FeatureCollection' !== wfsFeatureCollection.tagName) throw "Missing wfs:FeatureCollection element"
|
|
|
+ var events = []
|
|
|
+ for (var i = 0; i < wfsFeatureCollection.children.length; i++) {
|
|
|
+ events.push(parseWfsFeatureMember(wfsFeatureCollection.children[i]))
|
|
|
+ }
|
|
|
+ return events.filter(function (item) { return !!item; })
|
|
|
+ }).then(function __eventsRender(events) {
|
|
|
+ if (DBG) console.table(events);
|
|
|
+ var calJqNode = jQuery('#' + CALENDAR_NODE_ID)
|
|
|
+ events.forEach(function(item) {
|
|
|
var source = {};
|
|
|
if (moment(item.start_work_hour, "HH:mm:ss").format("HH:mm") != "00:00") {
|
|
|
source["title"] = moment(item.start_work_hour, "HH:mm:ss").format("HH:mm")+" - "+moment(item.end_work_hour, "HH:mm:ss").format("HH:mm");
|
|
|
@@ -75,12 +101,13 @@ $(document).ready(function() {
|
|
|
source["className"] = 'empty';
|
|
|
}
|
|
|
source["start"] = item.date;
|
|
|
-
|
|
|
source["url"] = BASE_URL + 'index.php?_route=ViewTableAjax&namespace=default_db/GRAFIK_PRACY#EDIT/'+item.id;
|
|
|
-
|
|
|
- $('#calendar').fullCalendar('renderEvent', source, true);
|
|
|
- });
|
|
|
- });
|
|
|
+ calJqNode.fullCalendar('renderEvent', source, true);
|
|
|
+ })
|
|
|
+ }).catch(function (e) {
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'error', msg: e })
|
|
|
+ console.warn(e)
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|