OW2 Consortium telosys

Rev

Rev 13 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13 Rev 20
1
//------------------------------------------------------------------------------
1
//------------------------------------------------------------------------------
2
// TelosysEnv_class.js : Telosys environment object
2
// TelosysEnv_class.js : Telosys environment object
3
// Telosys framework
3
// Telosys framework
4
// Author  : Laurent Guérin 
4
// Author  : Laurent Guérin 
5
//------------------------------------------------------------------------------
5
//------------------------------------------------------------------------------
6
/**
6
/**
7
 * This object stores the absolute URLs to access the server side with AJAX calls.
7
 * This object stores the absolute URLs to access the server side with AJAX calls.
8
 * It provides different kind of objects ( Screen, Service, Actions, ... )
8
 * It provides different kind of objects ( Screen, Service, Actions, ... )
9
 *
9
 *
10
 * @param String : Application root URL ( required )
10
 * @param String : Application root URL ( required )
11
 * @param String : Screen Map URL ( required )
11
 * @param String : Screen Map URL ( required )
12
 * @param String : Screen Context AJAX calls URL ( required )
12
 * @param String : Screen Context AJAX calls URL ( required )
13
 * @param String : Current Screen Name 
13
 * @param String : Current Screen Name 
14
 * @param int    : Current Screen ID
14
 * @param int    : Current Screen ID
15
 *
15
 *
16
 */
16
 */
17
//------------------------------------------------------------------------------
17
//------------------------------------------------------------------------------
18
 
18
 
19
//------------------------------------------------------------------------------
19
//------------------------------------------------------------------------------
20
// CLASS DEFINITION
20
// CLASS DEFINITION
21
//------------------------------------------------------------------------------
21
//------------------------------------------------------------------------------
22
//function TelosysEnv( sRootUrl, sScreenMapUrl, sAjaxUrl, sScreenName, iScreenId )
22
//function TelosysEnv( sRootUrl, sScreenMapUrl, sAjaxUrl, sScreenName, iScreenId )
23
function TelosysEnv()
23
function TelosysEnv()
24
{
24
{
25
	//==============================================================================
25
	//==============================================================================
26
	// PRIVATE ATTRIBUTES
26
	// PRIVATE ATTRIBUTES
27
	//==============================================================================
27
	//==============================================================================
28
	//--- URLs 
28
	//--- URLs 
29
	var _sRootUrl      = null ;
29
	var _sRootUrl      = null ;
30
	var _sScreenMapUrl = null ;
30
	var _sScreenMapUrl = null ;
31
	var _sAjaxUrl      = null ;
31
	var _sAjaxUrl      = null ;
32

32

33
	//--- Current Screen Map   
33
	//--- Current Screen Map   
34
	var _sScreenName   = null ;
34
	var _sScreenName   = null ;
35
	var _iScreenId     = 0 ;
35
	var _iScreenId     = 0 ;
36
	var _screen        = null ;
36
	var _screen        = null ;
37
	var _actions       = null ;	
37
	var _actions       = null ;	
38
	
38
	
39
	//--- Keyboard & browser  
39
	//--- Keyboard & browser  
40
	var _keyboard      = Keyboard.getKeyboard(); 
40
	var _keyboard      = Keyboard.getKeyboard(); 
41
	var _browser       = Browser.getBrowser() ; 
41
	var _browser       = Browser.getBrowser() ; 
42
	
42
	
43
	//alert ( "in TelosysEnv : this = " + this + "\n constructor : \n" + this.constructor ) ;
43
	//alert ( "in TelosysEnv : this = " + this + "\n constructor : \n" + this.constructor ) ;
44
	
44
	
45
	//==============================================================================
45
	//==============================================================================
46
	// CONSTRUCTOR
46
	// CONSTRUCTOR
47
	//==============================================================================
47
	//==============================================================================
48
	_constructor.apply ( this, arguments );  //--- Call the constructor
48
	_constructor.apply ( this, arguments );  //--- Call the constructor
49
	function _constructor ( sRootUrl, sScreenMapUrl, sAjaxUrl, sScreenName, iScreenId ) 
49
	function _constructor ( sRootUrl, sScreenMapUrl, sAjaxUrl, sScreenName, iScreenId ) 
50
	{
50
	{
51
		if ( arguments.length != 3 && arguments.length != 5 )
51
		if ( arguments.length != 3 && arguments.length != 5 )
52
		{
52
		{
53
			alert("ERROR : TelosysEnv constructor : 3 or 5 arguments expected ! \n"
53
			alert("ERROR : TelosysEnv constructor : 3 or 5 arguments expected ! \n"
54
				+ "( sRootUrl, sScreenMapUrl, sAjaxUrl [ , sScreenName, iScreenId ] )  ");
54
				+ "( sRootUrl, sScreenMapUrl, sAjaxUrl [ , sScreenName, iScreenId ] )  ");
55
			return null ;
55
			return null ;
56
		}
56
		}
57
		
57
		
58
		_sRootUrl      = sRootUrl ;
58
		_sRootUrl      = sRootUrl ;
59
		_sScreenMapUrl = sScreenMapUrl ;
59
		_sScreenMapUrl = sScreenMapUrl ;
60
		_sAjaxUrl      = sAjaxUrl ;
60
		_sAjaxUrl      = sAjaxUrl ;
61
		
61
		
62
		if ( arguments.length == 5 )
62
		if ( arguments.length == 5 )
63
		{
63
		{
64
			//--- Initialize the current screen
64
			//--- Initialize the current screen
65
			_sScreenName = sScreenName ;
65
			_sScreenName = sScreenName ;
66
			_iScreenId   = iScreenId ;
66
			_iScreenId   = iScreenId ;
67
			_screen      = _createScreen (_sScreenName, _iScreenId) ;
67
			_screen      = _createScreen (_sScreenName, _iScreenId) ;
68
			_actions     = _createActions(_screen);
68
			_actions     = _createActions(_screen);
69
		}
69
		}
70
	}
70
	}
71
	
71
	
72
	//==============================================================================
72
	//==============================================================================
73
	// PRIVATE METHODS 
73
	// PRIVATE METHODS 
74
	//==============================================================================
74
	//==============================================================================
75
	function _createScreen (sScreenName, sContextId) 
75
	function _createScreen (sScreenName, sContextId) 
76
	{
76
	{
77
		if ( arguments.length < 2 )
77
		if ( arguments.length < 2 )
78
		{
78
		{
79
			alert("ERROR : TelosysEnv._createScreen() : 2 arguments expected !");
79
			alert("ERROR : TelosysEnv._createScreen() : 2 arguments expected !");
80
			return null ;
80
			return null ;
81
		}
81
		}
82
		//--- Create a new Screen and return it
82
		//--- Create a new Screen and return it
83
		return new Screen( sScreenName, _sAjaxUrl, sContextId ) ;
83
		return new Screen( sScreenName, _sAjaxUrl, sContextId ) ;
84
	}
84
	}
85
	//------------------------------------------------------------------------------
85
	//------------------------------------------------------------------------------
86
	function _createActions (oScreen) 
86
	function _createActions (oScreen) 
87
	{
87
	{
88
		if ( arguments.length < 1 )
88
		if ( arguments.length < 1 )
89
		{
89
		{
90
			alert("ERROR : TelosysEnv._createActions() : 1 argument expected !");
90
			alert("ERROR : TelosysEnv._createActions() : 1 argument expected !");
91
			return null ;
91
			return null ;
92
		}
92
		}
93
		return new ScreenActions( oScreen );
93
		return new ScreenActions( oScreen );
94
	}
94
	}
95
	
95
	
96
	//==============================================================================
96
	//==============================================================================
97
	// PUBLIC / PRIVILEGED  METHODS 
97
	// PUBLIC / PRIVILEGED  METHODS 
98
	//==============================================================================
98
	//==============================================================================
99
	//------------------------------------------------------------------------------
99
	//------------------------------------------------------------------------------
100
	/**
100
	/**
101
	 * Return the absolute root URL of the WebApp 
101
	 * Return the absolute root URL of the WebApp 
102
	 * @return String : the URL
102
	 * @return String : the URL
103
	 */
103
	 */
104
	this.getRootUrl = function () 
104
	this.getRootUrl = function () 
105
	{
105
	{
106
		return _sRootUrl ;
106
		return _sRootUrl ;
107
	}
107
	}
108

108

109
	//------------------------------------------------------------------------------
109
	//------------------------------------------------------------------------------
110
	// Return the absolute URL for screenmap calls with optional parameters.
110
	// Return the absolute URL for screenmap calls with optional parameters.
111
	this.getScreenMapUrl = function (sName, sType, sContextId, sContextName, sAction, sParams) 
111
	this.getScreenMapUrl = function (sName, sType, sContextId, sContextName, sAction, sParams) 
112
	{
112
	{
113
		if ( arguments.length == 0 ) {
113
		if ( arguments.length == 0 ) {
114
			return _sScreenMapUrl ;
114
			return _sScreenMapUrl ;
115
		}
115
		}
116
		/**
116
		/**
117
		if ( arguments.length != 5  ) {
117
		if ( arguments.length != 5  ) {
118
			alert("ERROR : TelosysEnv.getScreenMapUrl() : 0 or 5 arguments expected !");
118
			alert("ERROR : TelosysEnv.getScreenMapUrl() : 0 or 5 arguments expected !");
119
			return null ;
119
			return null ;
120
		}
120
		}
121
		*/
121
		*/
122
		if ( sName == null ) {
122
		if ( sName == null ) {
123
			alert("ERROR : TelosysEnv.getScreenMapUrl() : argument 'name' is null !");
123
			alert("ERROR : TelosysEnv.getScreenMapUrl() : argument 'name' is null !");
124
			return null ;
124
			return null ;
125
		}
125
		}
126
		//--- Build the ScreenMap URL with parameters ...
126
		//--- Build the ScreenMap URL with parameters ...
127
		var s = _sScreenMapUrl + "/" + sName ;
127
		var s = _sScreenMapUrl + "/" + sName ;
128
        if ( sType != null ) {
128
        if ( sType != null ) {
129
            s = s + "-" + sType ;
129
            s = s + "-" + sType ;
130
        }
130
        }
131
        
131
        
132
        if ( sContextId != null ) {
132
        if ( sContextId != null ) {
133
            s = s + "/" + sContextId ;
133
            s = s + "/" + sContextId ;
134
        }
134
        }
135
        if ( sContextName != null ) {
135
        if ( sContextName != null ) {
136
	        if ( sContextId != null  ) {
136
	        if ( sContextId != null  ) {
137
	        	s = s + "-" + sContextName;
137
	        	s = s + "-" + sContextName;
138
	        }
138
	        }
139
	        else {
139
	        else {
140
	        	s = s + "/" + sContextName;
140
	        	s = s + "/" + sContextName;
141
	        }
141
	        }
142
        }
142
        }
143
        if ( sAction != null ) {
143
        if ( sAction != null ) {
144
            s = s + ":" + sAction ;
144
            s = s + ":" + sAction ;
145
        }				
145
        }				
146
        if ( sParams != null ) {
146
        if ( sParams != null ) {
147
            s = s + "?" + sParams ;
147
            s = s + "?" + sParams ;
148
        }				
148
        }				
149
		return s ;
149
		return s ;
150
	}
150
	}
151

151

152
	//------------------------------------------------------------------------------
152
	//------------------------------------------------------------------------------
153
	/**
153
	/**
154
	 * Return the absolute URL for Screen actions calls ( AJAX calls )
154
	 * Return the absolute URL for Screen actions calls ( AJAX calls )
155
	 * @return String : the URL
155
	 * @return String : the URL
156
	 */
156
	 */
157
	this.getAjaxUrl = function () 
157
	this.getAjaxUrl = function () 
158
	{
158
	{
159
		return _sAjaxUrl ;
159
		return _sAjaxUrl ;
160
	}
160
	}
161

161

162
	//------------------------------------------------------------------------------
162
	//------------------------------------------------------------------------------
163
	/**
163
	/**
164
	 * Returns the current 'Screen' instance 
164
	 * Returns the current 'Screen' instance 
165
	 * Runtime error if no current screen
165
	 * Runtime error if no current screen
166
	 * @return Screen : the Screen instance ( or null after runtime error )
166
	 * @return Screen : the Screen instance ( or null after runtime error )
167
	 */
167
	 */
168
	this.getCurrentScreen = function () 
168
	this.getCurrentScreen = function () 
169
	{
169
	{
170
		if ( _screen != null )
170
		if ( _screen != null )
171
		{
171
		{
172
			return _screen ;
172
			return _screen ;
173
		}
173
		}
174
		else
174
		else
175
		{
175
		{
176
			alert("ERROR : TelosysEnv.getCurrentScreen() : No current screen !");
176
			alert("ERROR : TelosysEnv.getCurrentScreen() : No current screen !");
177
			return null ;
177
			return null ;
178
		}
178
		}
179
	}
179
	}
180
	//------------------------------------------------------------------------------
180
	//------------------------------------------------------------------------------
181
	/**
181
	/**
182
	 * Returns the current 'Actions' instance 
182
	 * Returns the current 'Actions' instance 
183
	 * Runtime error if not defined
183
	 * Runtime error if not defined
184
	 * @return Actions : the Actions instance ( or null after runtime error )
184
	 * @return Actions : the Actions instance ( or null after runtime error )
185
	 */
185
	 */
186
	this.getCurrentActions = function () 
186
	this.getCurrentActions = function () 
187
	{
187
	{
188
		if ( _actions != null )
188
		if ( _actions != null )
189
		{
189
		{
190
			return _actions ;
190
			return _actions ;
191
		}
191
		}
192
		else
192
		else
193
		{
193
		{
194
			alert("ERROR : TelosysEnv.getCurrentActions() : No current actions !");
194
			alert("ERROR : TelosysEnv.getCurrentActions() : No current actions !");
195
			return null ;
195
			return null ;
196
		}
196
		}
197
	}
197
	}
198
	//------------------------------------------------------------------------------
198
	//------------------------------------------------------------------------------
199
	/**
199
	/**
200
	 * Create and return a new 'Screen' object for the given name and id
200
	 * Create and return a new 'Screen' object for the given name and id
201
	 * @param  String : Screen name
201
	 * @param  String : Screen name
202
	 * @param  int    : Screen context ID
202
	 * @param  int    : Screen context ID
203
	 * @return Screen : the Screen instance ( or null if error )
203
	 * @return Screen : the Screen instance ( or null if error )
204
	 */
204
	 */
205
	this.getScreen = function (sScreenName, sContextId) 
205
	this.getScreen = function (sScreenName, sContextId) 
206
	{
206
	{
207
		if ( arguments.length < 2 )
207
		if ( arguments.length < 2 )
208
		{
208
		{
209
			alert("ERROR : TelosysEnv.getScreen() : 2 arguments expected !");
209
			alert("ERROR : TelosysEnv.getScreen() : 2 arguments expected !");
210
			return null ;
210
			return null ;
211
		}
211
		}
212
		//--- Create a new Screen and return it
212
		//--- Create a new Screen and return it
213
		return new Screen( sScreenName, _sAjaxUrl, sContextId ) ;
213
		return new Screen( sScreenName, _sAjaxUrl, sContextId ) ;
214
	}
214
	}
215
	//------------------------------------------------------------------------------
215
	//------------------------------------------------------------------------------
216
	/**
216
	/**
217
	 * Create and return a new 'Service' object
217
	 * Create and return a new 'Service' object
218
	 * @param  String   : Service name
218
	 * @param  String   : Service name
219
	 * @param  Function : Callback function to call to process the service response
219
	 * @param  Function : Callback function to call to process the service response
220
	 * @return Service  : the Service instance ( or null if error )
220
	 * @return Service  : the Service instance ( or null if error )
221
	 */
221
	 */
222
	this.getService = function ( sServiceName, callbackFunction ) 
222
	this.getService = function ( sServiceName, callbackFunction ) 
223
	{
223
	{
224
		if ( arguments.length < 2 )
224
		if ( arguments.length < 2 )
225
		{
225
		{
226
			alert("ERROR : TelosysEnv.getService() : 2 arguments expected !");
226
			alert("ERROR : TelosysEnv.getService() : 2 arguments expected !");
227
			return null ;
227
			return null ;
228
		}
228
		}
229
		return new ScreenService( sServiceName, _sRootUrl, callbackFunction ) ;
229
		return new ScreenService( sServiceName, _sRootUrl, callbackFunction ) ;
230
	}
230
	}
231
	//------------------------------------------------------------------------------
231
	//------------------------------------------------------------------------------
232
	/**
232
	/**
233
	 * Create and return a new 'ScreenActions' object
233
	 * Create and return a new 'ScreenActions' object
234
	 * 2 signatures :
234
	 * 2 signatures :
235
	 *  . 1 : getActions( ScreenObject )
235
	 *  . 1 : getActions( ScreenObject )
236
	 *  . 2 : getActions( ScreenName, ScreenID )
236
	 *  . 2 : getActions( ScreenName, ScreenID )
237
	 * @param  arg1 : Screen object or Screen Name 
237
	 * @param  arg1 : Screen object or Screen Name 
238
	 * @param  arg2 : Screen Id  ( with arg1 = Screen Name )
238
	 * @param  arg2 : Screen Id  ( with arg1 = Screen Name )
239
	 * @return ScreenActions : the ScreenActions instance ( or null if error )
239
	 * @return ScreenActions : the ScreenActions instance ( or null if error )
240
	 */
240
	 */
241
	this.getActions = function ( arg1, arg2 ) 
241
	this.getActions = function ( arg1, arg2 ) 
242
	{
242
	{
243
		if ( arguments.length == 2 )
243
		if ( arguments.length == 2 )
244
		{
244
		{
245
			if ( typeof arg1 == "string" && typeof arg2 == "string" )
245
			if ( typeof arg1 == "string" && typeof arg2 == "string" )
246
			{
246
			{
247
				return new ScreenActions( this.getScreen(arg1, arg2) );
247
				return new ScreenActions( this.getScreen(arg1, arg2) );
248
			}
248
			}
249
			else if ( typeof arg1 == "string" && typeof arg2 == "number" )
249
			else if ( typeof arg1 == "string" && typeof arg2 == "number" )
250
			{
250
			{
251
				return new ScreenActions( this.getScreen(arg1, arg2) );
251
				return new ScreenActions( this.getScreen(arg1, arg2) );
252
			}
252
			}
253
			else
253
			else
254
			{
254
			{
255
				alert("ERROR : TelosysEnv.getActions() : invalid arguments type ! "
255
				alert("ERROR : TelosysEnv.getActions() : invalid arguments type ! "
256
					+ "\n . argument 1 : '" + ( typeof arg1 ) + "' ( string expected ) " 
256
					+ "\n . argument 1 : '" + ( typeof arg1 ) + "' ( string expected ) " 
257
					+ "\n . argument 2 : '" + ( typeof arg2 ) + "' ( string or number expected ) " );
257
					+ "\n . argument 2 : '" + ( typeof arg2 ) + "' ( string or number expected ) " );
258
				return null ;
258
				return null ;
259
			}		
259
			}		
260
		}
260
		}
261
		else if ( arguments.length == 1 )
261
		else if ( arguments.length == 1 )
262
		{
262
		{
263
			if ( typeof arg1 == "object" )
263
			if ( typeof arg1 == "object" )
264
			{
264
			{
265
				return new ScreenActions( arg1 );
265
				return new ScreenActions( arg1 );
266
			}
266
			}
267
			else
267
			else
268
			{
268
			{
269
				alert("ERROR : TelosysEnv.getActions() : the argument is not an object !");
269
				alert("ERROR : TelosysEnv.getActions() : the argument is not an object !");
270
				return null ;
270
				return null ;
271
			}
271
			}
272
		}
272
		}
273
		else
273
		else
274
		{
274
		{
275
			alert("ERROR : TelosysEnv.getActions() : " + arguments.length + " argument(s) ( 1 or 2 expected ) !");
275
			alert("ERROR : TelosysEnv.getActions() : " + arguments.length + " argument(s) ( 1 or 2 expected ) !");
276
			return null ;
276
			return null ;
277
		}
277
		}
278
	}
278
	}
279
	//------------------------------------------------------------------------------
279
	//------------------------------------------------------------------------------
280
	this.getKeyboard = function () 
280
	this.getKeyboard = function () 
281
	{
281
	{
282
		return _keyboard ;
282
		return _keyboard ;
283
	}
283
	}
284
	//------------------------------------------------------------------------------
284
	//------------------------------------------------------------------------------
285
	this.getBrowser = function () 
285
	this.getBrowser = function () 
286
	{
286
	{
287
		return _browser ;
287
		return _browser ;
288
	}
288
	}
289
	//------------------------------------------------------------------------------
289
	//------------------------------------------------------------------------------
290
	this.toString = function () 
290
	this.toString = function () 
291
	{
291
	{
292
		return "Root URL='" + _sRootUrl 
292
		return "Root URL='" + _sRootUrl 
293
			 + "' - ScreenMap URL='" + _sScreenMapUrl 
293
			 + "' - ScreenMap URL='" + _sScreenMapUrl 
294
			 + "' - Ajax URL='" + _sAjaxUrl + "'" ;
294
			 + "' - Ajax URL='" + _sAjaxUrl + "'" ;
295
	}	
295
	}	
296
	//------------------------------------------------------------------------------	
296
	//------------------------------------------------------------------------------	
297
}
297
}
298
//------------------------------------------------------------------------------
298
//------------------------------------------------------------------------------
299
//                               T H E      E N D 
299
//                               T H E      E N D 
300
//------------------------------------------------------------------------------
300
//------------------------------------------------------------------------------
301
301
302

302

303
Generated by GNU enscript 1.6.4.
303
Generated by GNU enscript 1.6.4.
304

304

305

305