In the Kanban board’s “onBeforeStatusChange” event it would be really nice if that handler would support a return value of a Promise as well as the standard boolean.
The use case here is to validate if a user is allowed to move the item before it is actually moved. This needs to happen on the server side due to complex rules. This event is also nice because it cancels the status update with a pleasing UI experience.
Here is the sample code:
onBeforeStatusChange: function (id, status, list) {
return new Promise((resolve, reject) => {
webix.ajax.get(`/some_api/can_user_move_item?id=${id}&new_status=${status}`).then(r => {
let msg = r.json();
if (msg.success) {
resolve(true);
} else {
resolve(false);
}
}, err => { reject(err); });
});
},
In kanban.js this is handled with this line:
if (statusChange) {
if (!kanban.callEvent("onBeforeStatusChange", [sid, tobj.config.status, tobj])) return;
kanban.setListStatus(item, tobj);
If you add a Deferred object to that, then it should be able to handle both situations.
This would make this even a lot more powerful.
I would also suggest adding this kind of logic to some of the other events in other webix controls since many of these events would benefit from being able to handle async / promise returns.
Lastly, this isn’t just about making ajax calls either. If you wanted to have a “confirm” on that status move, then this would allow that also.