1 /*
  2  * Naos Framework
  3  *
  4  * LICENSE
  5  * http://www.naos-framework.com/website.naos.framework/en/license
  6  *
  7  * Copyright (c) 2008 Jupiter GmbH
  8  */
  9  
 10 /**
 11  * This class enables you to register callback handler to deal with
 12  * certain events. Currently the following types are provided:<br/><br/>
 13  * 
 14  * <strong>Custom Operation Handler:</strong> Allows you to handle
 15  * calls from the PHP side of the Naos Framework.<br/><br/>
 16  * 
 17  * <strong>View Update Notifier:</strong> Whenever a view gets updated
 18  * these handlers will be calles afterwards.
 19  * 
 20  * <strong>Document OnLoad Notifier:</strong> These registered handlers
 21  * get called when the DOM tree of the HTML document is loaded fully
 22  * (notice: images and other media might still be in the process of
 23  * loading).
 24  *  
 25  * @namespace
 26  */
 27 NaosHandler =
 28 {
 29 	/**
 30 	 * Contains all registered Custom Operation Handler callback methods.
 31 	 * 
 32 	 * @type Array
 33 	 * @private
 34 	 */
 35 	_customOperationHandler: new Array(),
 36 	
 37 	/**
 38 	 * Triggers all registered Custom Operation Handler callback methods for
 39 	 * a module and type.
 40 	 * 
 41 	 * @param module Assigned module.
 42 	 * @param type Type of Custom Operation Handler, actually this is the identifier on module level.
 43 	 * @param data Data which is provided to the callback methods.
 44 	 */
 45 	customOperation: function(/**String*/ module, /**String*/ type, /**String|Object|Array*/ data)
 46 	{
 47 		for(var i=0; i<NaosHandler._customOperationHandler.length; ++i)
 48 		{
 49 			if(NaosHandler._customOperationHandler[i].module == module
 50 				&& NaosHandler._customOperationHandler[i].type == type)
 51 			{
 52 				NaosHandler._customOperationHandler[i].callback(data);
 53 			}
 54 		}
 55 	},
 56 	
 57 	/**
 58 	 * Registers a new Custom Operation Handler callback method for a module and type combination.
 59 	 * Use this function in your application to make use of this feature.
 60 	 * 
 61 	 * @param module Assigned module.
 62 	 * @param type Type of Custom Operation Handler, actually this is the identifier on module level.
 63 	 * @param callback Pointer to the callback method.
 64 	 */
 65 	registerCustomOperationHandler: function(/**String*/ module, /**String*/ type, /**function*/ callback)
 66 	{
 67 		NaosHandler._customOperationHandler.push(
 68 			{module: module, type: type, callback: callback});
 69 	},
 70 	
 71 	
 72 	/**
 73 	 * Contains all registered View Update Notifier callback methods.
 74 	 * 
 75 	 * @type Array
 76 	 * @private
 77 	 */
 78 	_viewUpdateNotifier: new Array(),
 79 	
 80 	/**
 81 	 * Triggers all registered View Update Notifier callback methods for a view.
 82 	 * 
 83 	 * @param view The view which gets updated.
 84 	 * @param output The new HTML output of the view.
 85 	 */
 86 	viewUpdateNotifier: function(/**String*/ view, /**String*/ output)
 87 	{
 88 		for(var i=0; i<NaosHandler._viewUpdateNotifier.length; ++i)
 89 		{
 90 			if(NaosHandler._viewUpdateNotifier[i].view == view)
 91 			{
 92 				NaosHandler._viewUpdateNotifier[i].callback(output);
 93 			}
 94 		}
 95 	},
 96 	
 97 	/**
 98 	 * Registers a new View Update Notifier callback method for a view.
 99 	 * Use this function in your application to make use of this feature.
100 	 * 
101 	 * @param view The view which gets updated.
102 	 * @param callback Pointer to the callback method.
103 	 */
104 	registerViewUpdateNotifier: function(/**String*/ view, /**String*/ callback)
105 	{
106 		NaosHandler._viewUpdateNotifier.push(
107 			{view: view, callback: callback});
108 	},
109 	
110 	
111 	/**
112 	 * Contains all registered Document OnLoad Notifier callback methods.
113 	 * 
114 	 * @type Array
115 	 * @private
116 	 */
117 	_documentOnLoadNotifier: new Array(),
118 	
119 	/**
120 	 * Triggers all registered Document OnLoad Notifier callback methods.
121 	 */
122 	documentOnLoadNotifier: function()
123 	{
124 		for(var i=0; i<NaosHandler._documentOnLoadNotifier.length; ++i)
125 		{
126 			NaosHandler._documentOnLoadNotifier[i].callback();
127 		}
128 	},
129 	
130 	/**
131 	 * Registers a new Document OnLoad Notifier callback method.
132 	 * Use this function in your application to make use of this feature.
133 	 * 
134 	 * @param callback Pointer to the callback method.
135 	 */
136 	registerDocumentOnLoadNotifier: function(/**function*/ callback)
137 	{
138 		NaosHandler._documentOnLoadNotifier.push(
139 			{callback: callback});
140 	}
141 	
142 }
143