Good morning, I have REST enabled Coldfusion functions that have been tested in Postman and are working correctly, inserting data from a new event into my database. I have implemented REST functions to set the events and calendars as follows:
class MyBackend extends scheduler.services.Backend {
events(params) {
return webix
.ajax("https://MyAPICalendarEventsRestPath")
.then(res => res.json());
}
calendars() {
return webix
.ajax("https://MyAPICalendarsRestPath")
.then(res => res.json());
}
}
When it comes to a Post or Put function, I have tried the below to no avail:
addEvent(obj) {
return webix
.ajax.post("https://MyAPIPostPath?start_date=obj.start_date&end_date=obj.end_date&text=obj.text&details=obj.details&color=obj.color&calendar=obj.calendar")
.then(res => res.json());
//return webix.promise.resolve(obj);
}
Any hint or assistance in using the Put and Post functions would be greatly appreciated.
Thanks,
-Daniel
Hello @DanTheProgrammer,
In your case, it looks like a simple syntax error. Please note that any of the webix.ajax interface methods should be called as follows:
webix.ajax().post(url); // instead of webix.ajax.post()
webix.ajax().put(url);
// and so on
Provided that your server returns the expected response back to the client, the widget should work as expected.
See Ajax Operations - AJAX usage: POST requests, JSON sending, incoming data parsing, etc. Webix Docs for more information on the webix.ajax interface.
Thank you Dzmitry, I was able to get this implemented by using the webix.ajax().post(url) method in the addEvent(obj) function:
addEvent(obj) {
webix.ajax().post("#MyAPIRESTPostURL#", { start_date: obj.start_date, end_date: obj.end_date, text: obj.text, details: obj.details, color: obj.color, calendar: obj.calendar, user_id: '<cfoutput>#SESSION.auth.usr_id#</cfoutput>' });
return webix.promise.resolve(obj);
}
Thanks,
-Daniel
Moving on to capturing calendars added, I’m having issues with getting the name of the calendar added to my database using another post REST API path. Placing a Javascript alert on the addCalendar(obj) code, it appears the function is called when clicking the ‘Add Calendar’ button before any information is filled out for a new calendar. Any hints on what other methods to use to capture new calendars added once their information is complete? See below the code I have:
addCalendar(obj) {
alert('New Calendar Text: ' + obj.text + ', Color: ' + obj.color);
webix.ajax().post("#MyRESTAPIPostURL#", { text: obj.text, color: obj.color, user_id: '<cfoutput>#SESSION.auth.usr_id#</cfoutput>' });
return webix.promise.resolve(obj);
}
I’m thinking that I need to use another method of sending new calendar data when it is complete.
-Daniel
I was able to place a temporary fix, once a new calendar is added, I reload the page. Then the user must open the new calendar, name it, and choose a color for it:
addCalendar(obj) {
webix.ajax().post("#MyAPIPostCalendarRESTpath#", { text: obj.text, color: obj.color, user_id: '<cfoutput>#SESSION.auth.usr_id#</cfoutput>', value: obj.value, });
location.reload();
return webix.promise.resolve(obj);
}