Kanban Item Status Change would be better if it supported promises

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.

Yep, we are aware that due to limitation of sync. event system, such kind of logic is hard to implement with Webix Widgets.

For now the best strategy is to

  • catch onBeforeStatusChange event
  • block it ( return false )
  • fire ajax call to check server side rules
  • if all fine, issue the API call to change the status of the card

Thanks for confirming that I am not missing something.
Implementing your strategy is not ideal, but I see how that will work just fine for our usecase.
I feel better about at least knowing that I’m not writing a bunch of code that has already been written.

Thanks Maksim