Source: mvc/controllers/helper.js

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