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 namespace contains all necessary method for the communication
 12  * with the PHP service of the Naos Framework, as well as the necessary
 13  * hooks to integrate the AJAX operations transparently.
 14  *  
 15  * @namespace
 16  */
 17 Naos = {}
 18 
 19 /**
 20  * Updates the HTML content for a view. Takes the current configuration
 21  * into account. At the moment only the replace method 'inner' is supported.
 22  * 
 23  * @param view The view which gets to be updated
 24  * @param content The new HTML content
 25  */
 26 Naos.updateViewContent = function(/**String*/ view, /**String*/ content) {
 27 
 28 	// find element id
 29 	if(naosConfig.layout.view[view].match.substr(0, 3) != 'id:')
 30 	{
 31 		alert('Naos.updateView: matching with id supported only!');
 32 		return;
 33 	}
 34 	
 35 	var dom_id = naosConfig.layout.view[view].match.substr(3);
 36 	
 37 	// check for replacement mode
 38 	if(naosConfig.layout.view[view].replace != 'inner')
 39 	{
 40 		alert('Naos.updateView: replacement type "inner" supported only!');
 41 		return;
 42 	}
 43 	
 44 	document.getElementById(dom_id).innerHTML = content;
 45 }
 46 
 47 /**
 48  * Provides the AJAX hook for anchor tags. In general the method
 49  * {@link Naos.ajaxSwitchView} gets called.
 50  * 
 51  * @param view The view which we want to address.
 52  * @param node The datanode for the current request.
 53  * @param module The module for the current request.
 54  * @param controller The controller for the current request.
 55  * @param action The action for the current request.
 56  * @param parameter The parameter for the current request.
 57  * 
 58  * @type boolean
 59  */
 60 Naos.ajaxHookA = function (/**String*/ view, /**String*/ node, /**String*/ module, /**String*/ controller, /**String*/ action, /**Object*/ parameter)
 61 {
 62 	if(window.opera)
 63 		return true;
 64 
 65 	Naos.ajaxSwitchView(view, node, module, controller, action, parameter, []);
 66 	return false;
 67 }
 68 
 69 /**
 70  * Provides the same functionality as {@link Naos.ajaxHookA}, except that
 71  * the method takes a MenuItem configuration into account.
 72  * 
 73  * @type boolean
 74  */
 75 Naos.ajaxMenuitemHookA = function (/**Object*/ requests)
 76 {
 77 	if(window.opera)
 78 		return true;
 79 		
 80 	Naos.ajaxSwitchViews(requests, []);
 81 	return false;
 82 }
 83 
 84 /**
 85  * Provides the same functionality as {@link Naos.ajaxHookA}, except that
 86  * the hook is designed for form tags. Additionally the data of the form
 87  * object will be included into the request.
 88  * 
 89  * @param view The view which we want to address.
 90  * @param node The datanode for the current request.
 91  * @param module The module for the current request.
 92  * @param controller The controller for the current request.
 93  * @param action The action for the current request.
 94  * @param parameter The parameter for the current request.
 95  * @param domForm The form object which will be included in the request data.
 96  * 
 97  * @type boolean
 98  */
 99 Naos.ajaxHookForm = function (/**String*/ view, /**String*/ node, /**String*/ module, /**String*/ controller, /**String*/ action, /**Object*/ parameter, /**Form*/ domForm)
100 {
101 	if(window.opera)
102 		return true;
103 		
104 	Naos.ajaxSwitchView(view, node, module, controller, action, parameter, [domForm]);
105 	return false;
106 }
107 
108 /**
109  * Performs a request to the PHP service of the Naos Framework which
110  * requests to update a view. See {@link Naos.ajaxSwitchViews} for further
111  * information.
112  * 
113  * @param view The view which we want to address.
114  * @param node The datanode for the current request.
115  * @param module The module for the current request.
116  * @param controller The controller for the current request.
117  * @param action The action for the current request.
118  * @param parameter The parameter for the current request.
119  * @param domForms A list of form objects which will be included in the request data.
120  * 
121  */
122 Naos.ajaxSwitchView = function (/**String*/ view, /**String*/ node, /**String*/ module, /**String*/ controller, /**String*/ action, /**Object*/ parameter, /**Array*/ domForms)
123 {
124 	var requests = {};
125 	
126 	requests[view] = {};
127 	requests[view].node = node;
128 	requests[view].module = module;
129 	requests[view].controller = controller;
130 	requests[view].action = action;
131 	requests[view].parameter = parameter;
132 	
133 	Naos.ajaxSwitchViews(requests, domForms);
134 }
135 
136 /**
137  * Performs a request to the PHP service of the Naos Framework which
138  * requests to update a set of views.  In general it creates a new NaosAjax
139  * object and triggers the send method.
140  * 
141  * @see NaosAjax
142  * 
143  * @param requests See {@link NaosAjax} for further information.
144  * @param domForms A list of form objects which will be included in the request data.
145  * 
146  */
147 Naos.ajaxSwitchViews = function (/**Object*/ requests, /**Array*/ domForms)
148 {
149 	var na = new NaosAjax(requests, domForms, null);		
150 	na.send();
151 }
152 
153 
154 /**
155  * Performs a request to the PHP service of the Naos Framework which
156  * requests to update a view. The previous request data are taken into
157  * account, which results in a reload of the view.
158  * 
159  * @see Naos.ajaxSwitchView
160  * 
161  * @param view The view which should be reloaded.
162  */
163 Naos.ajaxReloadView = function (/**String*/ view)
164 {
165 	if(naosStatus.layout[view] != undefined)
166 	{
167 		Naos.ajaxSwitchView(view, naosStatus.layout[view].node, naosStatus.layout[view].module,
168 			naosStatus.layout[view].controller, naosStatus.layout[view].action,
169 			naosStatus.layout[view].parameter, []);
170 	}
171 }
172