Dismissing task form for inexistent task

I made some progress with this. It is possible to dismiss a task, essentially using the same approach used by the dismissTask() function in cam-tasklist-task.js, only with window.location. You need to strip the task and detailsTab arguments from the URL hash. Something like:

$scope.dismissTask = function() {
	location.hash = $scope.stripParams({task: true, detailsTab: true});
};
$scope.stripParams = function (paramsToStrip) {
	var hash = location.hash;
	if (!hash) {
		return hash;
	}
	var hashParts = hash.split('?');
	var ret = hashParts[0] + '?';
	var hashQuery = hashParts[1];
	var params = hashQuery.split("&");
	for (var i = 0; i < params.length; i++) {
		var param = params[i].split("=");
		var key = param[0];
		if (!paramsToStrip[key]) {
			ret += params[i];
		}
	}
	return ret;
};

The dismissTask() function can be called when polling finds that the task does not exist anymore:

window.myApp = window.myApp || {};

// on form-loaded, clear possibly existing interval, then:
myApp.interval = window.setInterval(function () {
	$http.get(Uri.appUri('engine://engine/:engine/task/' + camForm.taskId))
		.error(function (data, status) {
			window.clearInterval(myApp.interval);
			myApp.interval = null;
			setTimeout(function(){
				$scope.dismissTask();
			});
		});
}, 1000);

One problem remains, however. The tasklist also should be updated when the task gets dismissed, otherwise users can click the inexistent task in the tasklist until the next update of the tasklist happens (a filter that updates itself regularly can mitigate this).
How can an embedded form update the tasklist? The cam-tasklist-task.js does that by invoking taskData.changed('taskList'). How can an embedded form do that?

1 Like