Source: tools/extensions/DialogManager4Compatibility.js

  1. define(['mmirf/util/extend','mmirf/controllerManager','mmirf/presentationManager'
  2. ],
  3. /**
  4. * Backwards compatibility for DialogManager (<= version 4.x):
  5. *
  6. * (re-)adds the following methods/functionality to the DialogManager instance:
  7. * * perform(ctrlName, actionName, data)
  8. * * performHelper(ctrlName, helperActionName, data)
  9. * * showDialog(ctrlName, dialogId, data)
  10. * * hideCurrentDialog()
  11. * * showWaitDialog(text, theme)
  12. * * hideWaitDialog()
  13. * * render(ctrlName, viewName, data)
  14. * * getOnPageRenderedHandler()
  15. * * setOnPageRenderedHandler(handlerFunction)
  16. *
  17. * * _setControllerManager(controllerManager)
  18. * * _setPresentationManager(presentationManager)
  19. *
  20. * @example
  21. * //extend DialogManager with helper/shortcut functions (e.g for <= v4.x backwards compatibility):
  22. * var dialogManager = require('mmirf/dialogManager');
  23. * //or: var dialogManager = mmir.dialog;
  24. * require('mmirf/dialogManager4Compatibility')(dialogManager);
  25. * dialogManager.render('Application', 'welcome').then(function(){ console.log('rendered welcome view') })
  26. *
  27. * @name mmir.compat.v4.DialogManager
  28. * @static
  29. * @class
  30. * @hideconstructor
  31. *
  32. * @requires mmir.ControllerManager
  33. * @requires mmir.PresentationManager
  34. *
  35. */
  36. function(extend, controllerManager, presentationManager
  37. ) {
  38. var _extend = function(dialogManager){
  39. //the next comment enables JSDoc2 to map all functions etc. to the correct class description
  40. /** @scope mmir.compat.v4.DialogManager.prototype */
  41. /**
  42. * @private
  43. * @type Function
  44. *
  45. * @see {@link mmir.compat.v4.DialogManager#getOnPageRenderedHandler}
  46. * @see {@link mmir.compat.v4.DialogManager#setOnPageRenderedHandler}
  47. *
  48. * @memberOf mmir.compat.v4.DialogManager.prototype
  49. */
  50. var onPageRenderedFunc;
  51. var ctrlManager = controllerManager;
  52. var presentManager = presentationManager;
  53. extend(dialogManager,
  54. /**
  55. * @memberOf mmir.compat.v4.DialogManager#
  56. */
  57. {
  58. /** @scope mmir.compat.v4.DialogManager.prototype */
  59. /**
  60. * This function performs an action of a controller by calling
  61. * the method {@link mmir.ControllerManager#perform} of the
  62. * {@link mmir.ControllerManager}
  63. *
  64. * @function
  65. * @param {String}
  66. * ctrlName Name of the controller to which the
  67. * action belongs
  68. * @param {String}
  69. * actionName Name of the action that should be
  70. * performed
  71. * @param {Object}
  72. * data optional data that can be submitted to the
  73. * action
  74. * @returns {Object} the return object of the performed action
  75. * @public
  76. * @memberOf mmir.compat.v4.DialogManager.prototype
  77. */
  78. perform: function(ctrlName, actionName, data) {
  79. // if(logger.isDebug()) logger.debug("going to perform ('" + ctrlName + "','" + actionName + "')");//debug
  80. return ctrlManager.perform(ctrlName, actionName, data);
  81. },
  82. /**
  83. * This function performs an action of a helper-class for a
  84. * controller by calling the method
  85. * {@link mmir.ControllerManager#performHelper} of the
  86. * {@link mmir.ControllerManager}
  87. *
  88. * @function
  89. * @param {String}
  90. * ctrlName Name of the controller to which the
  91. * helper action belongs
  92. * @param {String}
  93. * helper_method_name Name of the action that should
  94. * be performed by the helper
  95. * @param {Object}
  96. * data optional data that can be submitted to the
  97. * action
  98. * @returns {Object} the return object of the performed action
  99. * @public
  100. * @memberOf mmir.compat.v4.DialogManager.prototype
  101. */
  102. performHelper : function(ctrlName, helper_method_name, data) {
  103. if (arguments.length > 3) {
  104. return ctrlManager.performHelper(
  105. ctrlName, helper_method_name, data, arguments[3]
  106. );
  107. }
  108. else {
  109. return ctrlManager.performHelper(
  110. ctrlName, helper_method_name, data
  111. );
  112. }
  113. },
  114. /**
  115. * This function displays a dialog of a controller by calling
  116. * the method {@link mmir.PresentationManager#showDialog} of the
  117. * {@link mmir.PresentationManager}
  118. *
  119. * @function
  120. * @param {String}
  121. * ctrlName Name of the controller to which the
  122. * dialog belongs
  123. * @param {String}
  124. * dialogId Id of the dialog that should be displayed
  125. * @param {Object}
  126. * data Optional data that can be submitted to the
  127. * dialog
  128. * @public
  129. * @memberOf mmir.compat.v4.DialogManager.prototype
  130. */
  131. showDialog : function(ctrlName, dialogId, data) {
  132. presentManager.showDialog.apply(presentManager, arguments);
  133. },
  134. /**
  135. * This function closes a dialog of a controller by calling the
  136. * method {@link mmir.PresentationManager#hideCurrentDialog} of
  137. * the {@link mmir.PresentationManager}
  138. *
  139. * @function
  140. * @public
  141. * @memberOf mmir.compat.v4.DialogManager.prototype
  142. */
  143. hideCurrentDialog : function() {
  144. presentManager.hideCurrentDialog.apply(presentManager, arguments);
  145. },
  146. /**
  147. * Shows a "wait" dialog, indicating work-in-progress.
  148. *
  149. * This is a shortcut for calling
  150. * {@link mmir.PresentationManager#showWaitDialog}
  151. * (see documentation in <code>PresentationManager</code>
  152. * for parameters).
  153. *
  154. * @function
  155. *
  156. * @public
  157. *
  158. * @see mmir.PresentationManager#showWaitDialog
  159. * @see mmir.PresentationManager#hideWaitDialog
  160. *
  161. * @memberOf mmir.compat.v4.DialogManager.prototype
  162. */
  163. showWaitDialog : function(text, theme) {
  164. presentManager.showWaitDialog.apply(presentManager, arguments);
  165. },
  166. /**
  167. * Hides / closes the "wait" dialog.
  168. *
  169. *
  170. * This is a shortcut for calling
  171. * {@link mmir.PresentationManager#hideWaitDialog}
  172. * (see documentation in <code>PresentationManager</code>
  173. * for parameters).
  174. *
  175. * @function
  176. * @public
  177. *
  178. * @see mmir.PresentationManager#hideWaitDialog
  179. * @see mmir.PresentationManager#showWaitDialog
  180. *
  181. * @memberOf mmir.compat.v4.DialogManager.prototype
  182. */
  183. hideWaitDialog : function() {
  184. presentManager.hideWaitDialog.apply(presentManager, arguments);
  185. },
  186. /**
  187. * This function displays a view of a controller by calling the
  188. * method {@link mmir.PresentationManager#renderView} of the
  189. * {@link mmir.PresentationManager}.
  190. * <br>
  191. * And after rendering, the function set via #setOnPageRenderedHandler will
  192. * called in context of the controller instance with arguments:
  193. * <code>Controller.onPageRenderedFunc(ctrlName, viewName, data)</code>
  194. *
  195. *
  196. * @function
  197. * @param {String}
  198. * ctrlName Name of the controller to which the view
  199. * belongs
  200. * @param {String}
  201. * viewName Name of the view that should be rendered
  202. * @param {Object}
  203. * data Optional data that can be submitted to the
  204. * generation of the view
  205. * @returns {void|Promise}
  206. * if void/undefined is returned, the view is rendered synchronously, i.e.
  207. * the view is rendered, when this method returns.
  208. * If a Promise is returned, the view is rendered asynchronously
  209. * (rendering is finished, when the promise is resolved)
  210. *
  211. * @public
  212. * @memberOf mmir.compat.v4.DialogManager.prototype
  213. */
  214. render : function(ctrlName, viewName, data) {
  215. var defer = presentManager.render(ctrlName, viewName, data);
  216. if (typeof onPageRenderedFunc === 'function') {
  217. var ctrl = ctrlManager.get(ctrlName);
  218. if(defer){
  219. defer.then(function(){
  220. onPageRenderedFunc.call(ctrl, ctrlName, viewName, data);
  221. });
  222. } else {
  223. onPageRenderedFunc.call(ctrl, ctrlName, viewName, data);
  224. }
  225. }
  226. return defer;
  227. },
  228. /**
  229. * Get the current on-page-rendered hook function (if it was
  230. * set).
  231. *
  232. * @function
  233. * @param {Function}
  234. * the onPageRendered handler (NOTE: this may not be
  235. * set, i.e. <tt>undefined</tt>)
  236. *
  237. * @memberOf mmir.compat.v4.DialogManager.prototype
  238. */
  239. getOnPageRenderedHandler : function() {
  240. return onPageRenderedFunc;
  241. },
  242. /**
  243. * Set the on_page_loaded callback function.
  244. *
  245. * If <code>onPageRenderedHook</code> is a function object, it
  246. * will be executed after a view is rendered and after the
  247. * view's controller on_page_load function(s) has/have been
  248. * executed.
  249. *
  250. * <p>
  251. * This function will be executed after the view's
  252. * on_page_load()-function.<br>
  253. * The <code>onPageRenderedHook</code> function takes 3
  254. * arguments that refer to the parameters with which the
  255. * render-function was invoked: <br>
  256. * <code>{String} ctrlName </code> Name of the controller to
  257. * which the view belongs <br>
  258. * <code>{String} viewName</code> Name of the view that should
  259. * be rendered <br>
  260. * <code>{Object} [data]</code> <em>Optional</em> data that
  261. * can be submitted to the generation of the view
  262. *
  263. * @function
  264. * @param {Function}
  265. * onPageRenderedHook a callback function that will
  266. * be executed after a view was rendered i.e. after a
  267. * page was loaded.
  268. *
  269. * @memberOf mmir.compat.v4.DialogManager.prototype
  270. */
  271. setOnPageRenderedHandler : function(onPageRenderedHook) {
  272. onPageRenderedFunc = onPageRenderedHook;
  273. },
  274. /** @memberOf mmir.compat.v4.DialogManager.prototype */
  275. _setControllerManager: function(ctrlManager){
  276. ctrlManager = ctrlManager;
  277. },
  278. /** @memberOf mmir.compat.v4.DialogManager.prototype */
  279. _setPresentationManager: function(presentManager){
  280. presentManager = presentManager;
  281. }
  282. });//END: extend(dialogManager, {...
  283. return dialogManager;
  284. };
  285. return _extend;
  286. });//END: define(...