Writing Controller for Custom Logic

The controller is JavaScript code extending a framework class. A custom controller for a component can be added by following naming conventions (there are other ways to add a controller if the same code has to be reused in two components). In our example “tasks.htm”, “tasksC.js” would specify the controller code for “tasks.htm”. The suffix “C” indicates that it is a controller.

A controller receives all life cycle callbacks and events. A callback or event can be intercepted in the controller code for adding the application-specific logic. The following code shows an example controller.

/* globals InsureAdmin */

(function() {

  InsureAdmin.tasksC = Trillo.inherits(Shared.SharedC, function(viewSpec) {
    Shared.SharedC.call(this, viewSpec);
  });

  var tasksC = InsureAdmin.tasksC.prototype;
  var SharedC = Shared.SharedC.prototype;

  /* Intercepts click call on button, anchor or any element marked as an action */
  tasksC.handleAction = function(actionName, selectedObj, $e, targetController) {
    return SharedC.handleAction.call(this, actionName, selectedObj, $e, targetController);
  };

  /* Intercepts the call after a view is shown, it can be used to change UI state after all
     elements are rendered. For example, the state of button can be changed.
  */
  tasksC.postViewShown = function(view) {
    SharedC.postViewShown.call(this, view);
  };

})();