Class Index | File Index

Classes


Namespace mmir.ControllerManager


Defined in: controllerManager.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
A class for managing the controllers of the application.
Field Summary
Field Attributes Field Name and Description
<private>  
Array of controller-instances
Method Summary
Method Attributes Method Name and Description
<private>  
_init(callback)
Initialize ControllerManager: Load all Controllers from /controller that are specified in /config/directories.json
<private>  
addGenPath(genDirPath, infoObj, fileNamePrefix)
HELPER FUNC: add file path for generated / compiled view-element if it exists.
<private>  
HELPER FUNC: convert first letter to upper case
 
getController(ctrlName)
This function gets the controller by name.
 
This function returns names of all loaded controllers.
<private>  
getControllerResources(controllerName, controllerPath)
This function gets the controller file names and builds a JSON object containing information about the location, file name etc.
 
Get instance of ControllerManager.
 
init(callback)
This function must be called before using the mmir.ControllerManager.
 
perform(ctrlName, actionName, data)
This function performs an action of a controller.
 
performHelper(ctrlName, actionName, data)
This function performs an action of a helper-class for a controller.
<private>  
removeFileExt(fileName)
HELPER FUNC: remove file extension from file-name
Namespace Detail
mmir.ControllerManager
A class for managing the controllers of the application.
It's purpose is to load the controllers and their views / partials and provide functions to find controllers or perform actions or helper-actions. This "class" is structured as a singleton - so that only one instance is in use.
Requires:
jQuery.Deferred
Field Detail
<private> {Dictionary} controllers
Array of controller-instances
Method Detail
<private> {Promise} _init(callback)
Initialize ControllerManager: Load all Controllers from /controller that are specified in /config/directories.json
Parameters:
{Function} callback Optional
OPTIONAL an optional callback that will be triggered after the controllers where loaded
Returns:
{Promise} a Deferred.promise that will get fulfilled when controllers are loaded

<private> {PlainObject} addGenPath(genDirPath, infoObj, fileNamePrefix)
HELPER FUNC: add file path for generated / compiled view-element if it exists.
Parameters:
{String} genDirPath
path the the directory, where the file for the generated view-element is potentially located (generated file may not exists)
{PlainObject} infoObj
the info-object for the view-element. MUST HAVE property name!
{String} fileNamePrefix Optional
OPTIONAL prefix for the file-name, e.g. in case of Partials, the file-name would be: fileNamePrefix + infoObj.name (+ file-extension)
Returns:
{PlainObject} the info-object: if a path for the generated file exists, a property genPath (String) with the path as value is added.

<private> firstToUpperCase(name)
HELPER FUNC: convert first letter to upper case
Parameters:
name

{Object} getController(ctrlName)
This function gets the controller by name.
Parameters:
{String} ctrlName
Name of the controller which should be returned
Returns:
{Object} controller if found, null else

{Array} getControllerNames()
This function returns names of all loaded controllers.
Returns:
{Array} Names of all loaded controllers

<private> {JSON} getControllerResources(controllerName, controllerPath)
This function gets the controller file names and builds a JSON object containing information about the location, file name etc. for the controller itself, its views, partials, layout, and helper.
//EXAMPLE for returned object:
{
  "fileName": "application",
  "name": "Application",
  "path": "controllers/application.js",
  "views": [
    {
      "name": "login",
      "path": "views/application/login.ehtml",
      "genPath": "gen/views/application/login.js"
    },
    {
      "name": "registration",
      "path": "views/application/registration.ehtml",
      "genPath": "gen/views/application/registration.js"
    },
    {
      "name": "welcome",
      "path": "views/application/welcome.ehtml",
      "genPath": "gen/views/application/welcome.js"
    }
  ],
  "partials": [
    {
      "name": "languageMenu",
      "path": "views/application/~languageMenu.ehtml",
      "genPath": "gen/views/application/~languageMenu.js"
    }
  ],
  "helper": {
    "fileName": "applicationHelper",
    "name": "ApplicationHelper",
    "path": "helpers/applicationHelper.js"
  },
  "layout": {
    "fileName": "application",
    "name": "application",
    "path": "views/layouts/application.ehtml",
    "genPath": "gen/views/layouts/application.js"
  }
}
//NOTE 1: genPath is an optional field, i.e. it will only be added
          if the corresponding file exists
//NOTE 2: layout may be NULL
Parameters:
{String} controllerName
the name of the Controller (must start with an upper case letter).
{String} controllerPath
the path (URL) where the file with the Controller's implementation is located (according to information in file /config/directories.json, i.e. mmir.CommonUtils#getDirectoryStructure)
Returns:
{JSON} JSON-Object containing information about the controller, its views, partials, and paths etc.
Requires:
mmir.CommonUtils
mmir.Constants

getInstance()
Get instance of ControllerManager.
Deprecated:
use directly: instead of mmir.ControllerManager.getInstance() use mmir.ControllerManager NOTE: The ControllerManager must be initialized, before it can be used! (see ControllerManager#init)

{Promise} init(callback)
This function must be called before using the mmir.ControllerManager. The Initialization process is asynchronous, because javascript-files must be loaded (the controllers). To ensure that the ControllerManager is initialized, a callback can be used, or the returned Promise (e.g. see documentation of jQuery.Deferred) for code, that relies on the presence of the loaded controllers.
Note: The callback function should be used for code, that requires the prior loading of the controllers.
The callback mechanism is necessary, because loading the controllers is asynchronous.

If provided, the callback function is invoked with 1 argument, the ControllerManager instance:
callbackFunction(controllerManagerInstance)
 //recommended style:
 require(['controllerManager', ...], function(controllerManager, ...) {
 	controllerManager.init().then(function(theInitializedControllerInstance){
 		...
 	});
 })
 
 //old style:
	function afterLoadingControllers(controllerManagerInstance){
		var appCtrl = controllerManagerInstance.getController('Application');
		//do something...
	} 
	mmir.ControllerManager.init(afterLoadingControllers);
Parameters:
{Function} callback Optional
OPTIONAL an optional callback that will be triggered after the controllers where loaded
Returns:
{Promise} a Deferred.promise that will get fulfilled when controllers are loaded

{Object} perform(ctrlName, actionName, data)
This function performs an action of a controller.
Parameters:
{String} ctrlName
Name of the controller to which the action belongs
{String} actionName
Name of the action that should be performed
{Object} data
optional data that can be submitted to the action
Returns:
{Object} the return object of the performed action

{Object} performHelper(ctrlName, actionName, data)
This function performs an action of a helper-class for a controller.
Parameters:
{String} ctrlName
Name of the controller to which the helper action belongs
{String} actionName
Name of the action that should be performed by the helper
{Object} data
optional data that can be submitted to the action
Returns:
{Object} the return object of the performed action

<private> removeFileExt(fileName)
HELPER FUNC: remove file extension from file-name
Parameters:
fileName

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Feb 26 2016 21:44:43 GMT+0100 (Mitteleuropäische Zeit)