1 /*
  2  * 	Copyright (C) 2012-2013 DFKI GmbH
  3  * 	Deutsches Forschungszentrum fuer Kuenstliche Intelligenz
  4  * 	German Research Center for Artificial Intelligence
  5  * 	http://www.dfki.de
  6  * 
  7  * 	Permission is hereby granted, free of charge, to any person obtaining a 
  8  * 	copy of this software and associated documentation files (the 
  9  * 	"Software"), to deal in the Software without restriction, including 
 10  * 	without limitation the rights to use, copy, modify, merge, publish, 
 11  * 	distribute, sublicense, and/or sell copies of the Software, and to 
 12  * 	permit persons to whom the Software is furnished to do so, subject to 
 13  * 	the following conditions:
 14  * 
 15  * 	The above copyright notice and this permission notice shall be included 
 16  * 	in all copies or substantial portions of the Software.
 17  * 
 18  * 	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
 19  * 	OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 20  * 	MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 21  * 	IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
 22  * 	CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 23  * 	TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 24  * 	SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25  */
 26 
 27 
 28 define(
 29 	//this comment is needed by jsdoc2 [copy of comment for: function Helper(...]
 30 	/**
 31 	 * The Helper Class is a kind of interface-class which gives access to the methods and data of a helper (which itself belongs to a controller)<br>
 32 	 * 
 33 	 * @param {Controller} ctrl Controller instance / object
 34 	 * @param {String} name Name of the Helper
 35 	 * 
 36 	 * @name Helper
 37 	 * @class
 38 	 */
 39 	function(
 40 ){
 41 	//the next comment enables JSDoc2 to map all functions etc. to the correct class description
 42 	/** @scope Helper.prototype */
 43 	
 44 	//set to @ignore in order to avoid doc-duplication in jsdoc3
 45 	/**
 46 	 * @ignore
 47 	 * 
 48 	 * The Helper Class is a kind of interface-class which gives access to the methods and data of a helper (which itself belongs to a controller)<br>
 49 	 * 
 50 	 * @constructs Helper
 51 	 * @param {Controller} ctrl Controller instance / object
 52 	 * @param {String} name Name of the Helper
 53 	 */
 54 	function Helper(ctrl, name){
 55 	    /**
 56 	     * The definition of the helper object, containing all properties and functions of the controller.<br>
 57 	     * A method of the controller can be called via:
 58 
 59 		this.script.methodController(parameter);
 60 
 61 	     * 
 62 	     * @type Object
 63 	     * @public
 64 	     */
 65 		// this can only be invoked, if a function with the name "name" exists
 66 		this.script = new window[name]();
 67 
 68 		/**
 69 	     * The name of the helper. 
 70 	     * 
 71 	     * @type String
 72 	     * @public
 73 	     */
 74 		this.name=name;
 75 
 76 		/**
 77 	     * The controller to which this helper belongs.
 78 	     * 
 79 	     * @type Controller
 80 	     * @public
 81 	     */
 82 		this.controller = ctrl;
 83 
 84 	}
 85 
 86 
 87 	/**
 88 	 * This function performs an action of a helper.<br>
 89 	 * 
 90 	 * @function
 91 	 * @param {String} actionName Name of the method to be executed
 92 	 * @param {Object} data Data to pass to the method of the helper as argument
 93 	 * @returns {Object} The return value of the executed method 
 94 	 * @public
 95 	 */
 96 	Helper.prototype.perform = function(actionName, data){
 97 		
 98 //		if(logger.isv()) logger.v("should perform '" + actionName + "' of '" + this.name + "'" + ((typeof data !== 'undefined' && data !== null)? " with data: "+JSON.stringify(data): ""));//debug
 99 		
100 		if(arguments.length > 2){
101 		    return this.script[actionName](this.controller, data, arguments[2]);
102 		}
103 		else {
104 		    return this.script[actionName](this.controller, data);
105 		}
106 	};
107 
108 
109 	return Helper;
110 	
111 });//END: define(...
112 
113