Source: mvc/controllers/helper.js

  1. define(
  2. //this comment is needed by jsdoc2 [copy of comment for: function Helper(...]
  3. /**
  4. * 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>
  5. *
  6. * @param {Controller} ctrl Controller instance / object
  7. * @param {String} name Name of the Helper
  8. * @param {Function} instanceConstr the constructor for creating a new helper instance
  9. *
  10. * @name Helper
  11. * @class
  12. */
  13. function(
  14. ){
  15. //the next comment enables JSDoc2 to map all functions etc. to the correct class description
  16. /** @scope Helper.prototype */
  17. //set to @ignore in order to avoid doc-duplication in jsdoc3
  18. /**
  19. * 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>
  20. *
  21. * @constructs Helper
  22. * @param {Controller} ctrl Controller instance / object
  23. * @param {String} name Name of the Helper
  24. * @param {Function} instanceConstr the constructor for creating a new helper instance
  25. *
  26. * @ignore
  27. */
  28. function Helper(ctrl, name, instanceConstr){
  29. /**
  30. * The name of the helper.
  31. *
  32. * @type String
  33. * @public
  34. */
  35. this.name=name;
  36. /**
  37. * The controller to which this helper belongs.
  38. *
  39. * @type Controller
  40. * @public
  41. */
  42. this.controller = ctrl;
  43. /**
  44. * The definition of the helper object, i.e. its implementation,
  45. * containing all properties and functions of the controller.<br>
  46. *
  47. * A method of the helper can be called via:
  48. * <pre>
  49. * this.impl.method(parameter);
  50. * </pre>
  51. *
  52. * @type Object
  53. * @public
  54. */
  55. this.impl = new instanceConstr(this);
  56. /**
  57. * @deprecated use {@link #impl} instead
  58. * @protected
  59. */
  60. this.script = this.impl;
  61. }
  62. /**
  63. * This function performs an action of a helper.<br>
  64. *
  65. * @function
  66. * @param {String} actionName Name of the method to be executed
  67. * @param {Object} data Data to pass to the method of the helper as argument
  68. * @returns {Object} The return value of the executed method
  69. * @public
  70. */
  71. Helper.prototype.perform = function(actionName, data){
  72. // if(logger.isv()) logger.v("should perform '" + actionName + "' of '" + this.name + "'" + ((typeof data !== 'undefined' && data !== null)? " with data: "+JSON.stringify(data): ""));//debug
  73. if(arguments.length > 2){
  74. return this.impl[actionName](this.controller, data, arguments[2]);
  75. }
  76. else {
  77. return this.impl[actionName](this.controller, data);
  78. }
  79. };
  80. return Helper;
  81. });//END: define(...