<%@ include file="/js/chemoAppointmentsLookup.js" %>

/*
 * This is a lookup table for user-defined JS functions.
 * I want to let the user choose to run a javascript function from a Form Editor 'Command' button,
 * but without introducing a security risk by letting them enter and call arbitrary code.
 * The idea is that we expose only a function code name rather than the name of the function itself.
 * When the button is clicked, we search the list of functions and call the relevant one, if found.
 * To extend this for future functionality, include the JS from this file and add an entry to the array 'functionsLibrary' below.
 * array of code name + corresponding name of function
 */
var functionsLibrary = [
			{name: "appointmentsLookup", theFunction: appointmentsLookup},
			{name: "anotherfunc", theFunction: dummyFunction}
		];


/*
 * Search through the user function library, look for the specified function code name, invoke the corresponding function.
 */
function invokeUserFunction (funcname)	{
	var f;
	var aFunction;
	console.log("user invoking function " + funcname);
	for (f = 0; f < functionsLibrary.length; f++)	{
		aFunction = functionsLibrary[f];
		if (aFunction.name == funcname)	{
			console.log("About to call function " + aFunction.name)
			aFunction.theFunction();
			console.log("After function " + aFunction.name)
			return;
		}
	}
	alert("Unknown function code '" + funcname +"'");
}

// just for debugging
function dummyFunction ()	{
	alert("this is a test function which does nothing significant");
}

