| 13 |
lguerin |
1 |
//------------------------------------------------------------------------------
|
|
|
2 |
// TelosysEnv_class.js : Telosys environment object
|
|
|
3 |
// Telosys framework
|
|
|
4 |
// Author : Laurent Guérin
|
|
|
5 |
//------------------------------------------------------------------------------
|
|
|
6 |
/**
|
|
|
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, ... )
|
|
|
9 |
*
|
|
|
10 |
* @param String : Application root URL ( required )
|
|
|
11 |
* @param String : Screen Map URL ( required )
|
|
|
12 |
* @param String : Screen Context AJAX calls URL ( required )
|
|
|
13 |
* @param String : Current Screen Name
|
|
|
14 |
* @param int : Current Screen ID
|
|
|
15 |
*
|
|
|
16 |
*/
|
|
|
17 |
//------------------------------------------------------------------------------
|
|
|
18 |
|
|
|
19 |
//------------------------------------------------------------------------------
|
|
|
20 |
// CLASS DEFINITION
|
|
|
21 |
//------------------------------------------------------------------------------
|
|
|
22 |
//function TelosysEnv( sRootUrl, sScreenMapUrl, sAjaxUrl, sScreenName, iScreenId )
|
|
|
23 |
function TelosysEnv()
|
|
|
24 |
{
|
|
|
25 |
//==============================================================================
|
|
|
26 |
// PRIVATE ATTRIBUTES
|
|
|
27 |
//==============================================================================
|
|
|
28 |
//--- URLs
|
|
|
29 |
var _sRootUrl = null ;
|
|
|
30 |
var _sScreenMapUrl = null ;
|
|
|
31 |
var _sAjaxUrl = null ;
|
|
|
32 |
|
|
|
33 |
//--- Current Screen Map
|
|
|
34 |
var _sScreenName = null ;
|
|
|
35 |
var _iScreenId = 0 ;
|
|
|
36 |
var _screen = null ;
|
|
|
37 |
var _actions = null ;
|
|
|
38 |
|
|
|
39 |
//--- Keyboard & browser
|
|
|
40 |
var _keyboard = Keyboard.getKeyboard();
|
|
|
41 |
var _browser = Browser.getBrowser() ;
|
|
|
42 |
|
|
|
43 |
//alert ( "in TelosysEnv : this = " + this + "\n constructor : \n" + this.constructor ) ;
|
|
|
44 |
|
|
|
45 |
//==============================================================================
|
|
|
46 |
// CONSTRUCTOR
|
|
|
47 |
//==============================================================================
|
|
|
48 |
_constructor.apply ( this, arguments ); //--- Call the constructor
|
|
|
49 |
function _constructor ( sRootUrl, sScreenMapUrl, sAjaxUrl, sScreenName, iScreenId )
|
|
|
50 |
{
|
|
|
51 |
if ( arguments.length != 3 && arguments.length != 5 )
|
|
|
52 |
{
|
|
|
53 |
alert("ERROR : TelosysEnv constructor : 3 or 5 arguments expected ! \n"
|
|
|
54 |
+ "( sRootUrl, sScreenMapUrl, sAjaxUrl [ , sScreenName, iScreenId ] ) ");
|
|
|
55 |
return null ;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
_sRootUrl = sRootUrl ;
|
|
|
59 |
_sScreenMapUrl = sScreenMapUrl ;
|
|
|
60 |
_sAjaxUrl = sAjaxUrl ;
|
|
|
61 |
|
|
|
62 |
if ( arguments.length == 5 )
|
|
|
63 |
{
|
|
|
64 |
//--- Initialize the current screen
|
|
|
65 |
_sScreenName = sScreenName ;
|
|
|
66 |
_iScreenId = iScreenId ;
|
|
|
67 |
_screen = _createScreen (_sScreenName, _iScreenId) ;
|
|
|
68 |
_actions = _createActions(_screen);
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
//==============================================================================
|
|
|
73 |
// PRIVATE METHODS
|
|
|
74 |
//==============================================================================
|
|
|
75 |
function _createScreen (sScreenName, sContextId)
|
|
|
76 |
{
|
|
|
77 |
if ( arguments.length < 2 )
|
|
|
78 |
{
|
|
|
79 |
alert("ERROR : TelosysEnv._createScreen() : 2 arguments expected !");
|
|
|
80 |
return null ;
|
|
|
81 |
}
|
|
|
82 |
//--- Create a new Screen and return it
|
|
|
83 |
return new Screen( sScreenName, _sAjaxUrl, sContextId ) ;
|
|
|
84 |
}
|
|
|
85 |
//------------------------------------------------------------------------------
|
|
|
86 |
function _createActions (oScreen)
|
|
|
87 |
{
|
|
|
88 |
if ( arguments.length < 1 )
|
|
|
89 |
{
|
|
|
90 |
alert("ERROR : TelosysEnv._createActions() : 1 argument expected !");
|
|
|
91 |
return null ;
|
|
|
92 |
}
|
|
|
93 |
return new ScreenActions( oScreen );
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
//==============================================================================
|
|
|
97 |
// PUBLIC / PRIVILEGED METHODS
|
|
|
98 |
//==============================================================================
|
|
|
99 |
//------------------------------------------------------------------------------
|
|
|
100 |
/**
|
|
|
101 |
* Return the absolute root URL of the WebApp
|
|
|
102 |
* @return String : the URL
|
|
|
103 |
*/
|
|
|
104 |
this.getRootUrl = function ()
|
|
|
105 |
{
|
|
|
106 |
return _sRootUrl ;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
//------------------------------------------------------------------------------
|
|
|
110 |
// Return the absolute URL for screenmap calls with optional parameters.
|
|
|
111 |
this.getScreenMapUrl = function (sName, sType, sContextId, sContextName, sAction, sParams)
|
|
|
112 |
{
|
|
|
113 |
if ( arguments.length == 0 ) {
|
|
|
114 |
return _sScreenMapUrl ;
|
|
|
115 |
}
|
|
|
116 |
/**
|
|
|
117 |
if ( arguments.length != 5 ) {
|
|
|
118 |
alert("ERROR : TelosysEnv.getScreenMapUrl() : 0 or 5 arguments expected !");
|
|
|
119 |
return null ;
|
|
|
120 |
}
|
|
|
121 |
*/
|
|
|
122 |
if ( sName == null ) {
|
|
|
123 |
alert("ERROR : TelosysEnv.getScreenMapUrl() : argument 'name' is null !");
|
|
|
124 |
return null ;
|
|
|
125 |
}
|
|
|
126 |
//--- Build the ScreenMap URL with parameters ...
|
|
|
127 |
var s = _sScreenMapUrl + "/" + sName ;
|
|
|
128 |
if ( sType != null ) {
|
|
|
129 |
s = s + "-" + sType ;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
if ( sContextId != null ) {
|
|
|
133 |
s = s + "/" + sContextId ;
|
|
|
134 |
}
|
|
|
135 |
if ( sContextName != null ) {
|
|
|
136 |
if ( sContextId != null ) {
|
|
|
137 |
s = s + "-" + sContextName;
|
|
|
138 |
}
|
|
|
139 |
else {
|
|
|
140 |
s = s + "/" + sContextName;
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
if ( sAction != null ) {
|
|
|
144 |
s = s + ":" + sAction ;
|
|
|
145 |
}
|
|
|
146 |
if ( sParams != null ) {
|
|
|
147 |
s = s + "?" + sParams ;
|
|
|
148 |
}
|
|
|
149 |
return s ;
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
//------------------------------------------------------------------------------
|
|
|
153 |
/**
|
|
|
154 |
* Return the absolute URL for Screen actions calls ( AJAX calls )
|
|
|
155 |
* @return String : the URL
|
|
|
156 |
*/
|
|
|
157 |
this.getAjaxUrl = function ()
|
|
|
158 |
{
|
|
|
159 |
return _sAjaxUrl ;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
//------------------------------------------------------------------------------
|
|
|
163 |
/**
|
|
|
164 |
* Returns the current 'Screen' instance
|
|
|
165 |
* Runtime error if no current screen
|
|
|
166 |
* @return Screen : the Screen instance ( or null after runtime error )
|
|
|
167 |
*/
|
|
|
168 |
this.getCurrentScreen = function ()
|
|
|
169 |
{
|
|
|
170 |
if ( _screen != null )
|
|
|
171 |
{
|
|
|
172 |
return _screen ;
|
|
|
173 |
}
|
|
|
174 |
else
|
|
|
175 |
{
|
|
|
176 |
alert("ERROR : TelosysEnv.getCurrentScreen() : No current screen !");
|
|
|
177 |
return null ;
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
//------------------------------------------------------------------------------
|
|
|
181 |
/**
|
|
|
182 |
* Returns the current 'Actions' instance
|
|
|
183 |
* Runtime error if not defined
|
|
|
184 |
* @return Actions : the Actions instance ( or null after runtime error )
|
|
|
185 |
*/
|
|
|
186 |
this.getCurrentActions = function ()
|
|
|
187 |
{
|
|
|
188 |
if ( _actions != null )
|
|
|
189 |
{
|
|
|
190 |
return _actions ;
|
|
|
191 |
}
|
|
|
192 |
else
|
|
|
193 |
{
|
|
|
194 |
alert("ERROR : TelosysEnv.getCurrentActions() : No current actions !");
|
|
|
195 |
return null ;
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
//------------------------------------------------------------------------------
|
|
|
199 |
/**
|
|
|
200 |
* Create and return a new 'Screen' object for the given name and id
|
|
|
201 |
* @param String : Screen name
|
|
|
202 |
* @param int : Screen context ID
|
|
|
203 |
* @return Screen : the Screen instance ( or null if error )
|
|
|
204 |
*/
|
|
|
205 |
this.getScreen = function (sScreenName, sContextId)
|
|
|
206 |
{
|
|
|
207 |
if ( arguments.length < 2 )
|
|
|
208 |
{
|
|
|
209 |
alert("ERROR : TelosysEnv.getScreen() : 2 arguments expected !");
|
|
|
210 |
return null ;
|
|
|
211 |
}
|
|
|
212 |
//--- Create a new Screen and return it
|
|
|
213 |
return new Screen( sScreenName, _sAjaxUrl, sContextId ) ;
|
|
|
214 |
}
|
|
|
215 |
//------------------------------------------------------------------------------
|
|
|
216 |
/**
|
|
|
217 |
* Create and return a new 'Service' object
|
|
|
218 |
* @param String : Service name
|
|
|
219 |
* @param Function : Callback function to call to process the service response
|
|
|
220 |
* @return Service : the Service instance ( or null if error )
|
|
|
221 |
*/
|
|
|
222 |
this.getService = function ( sServiceName, callbackFunction )
|
|
|
223 |
{
|
|
|
224 |
if ( arguments.length < 2 )
|
|
|
225 |
{
|
|
|
226 |
alert("ERROR : TelosysEnv.getService() : 2 arguments expected !");
|
|
|
227 |
return null ;
|
|
|
228 |
}
|
|
|
229 |
return new ScreenService( sServiceName, _sRootUrl, callbackFunction ) ;
|
|
|
230 |
}
|
|
|
231 |
//------------------------------------------------------------------------------
|
|
|
232 |
/**
|
|
|
233 |
* Create and return a new 'ScreenActions' object
|
|
|
234 |
* 2 signatures :
|
|
|
235 |
* . 1 : getActions( ScreenObject )
|
|
|
236 |
* . 2 : getActions( ScreenName, ScreenID )
|
|
|
237 |
* @param arg1 : Screen object or Screen Name
|
|
|
238 |
* @param arg2 : Screen Id ( with arg1 = Screen Name )
|
|
|
239 |
* @return ScreenActions : the ScreenActions instance ( or null if error )
|
|
|
240 |
*/
|
|
|
241 |
this.getActions = function ( arg1, arg2 )
|
|
|
242 |
{
|
|
|
243 |
if ( arguments.length == 2 )
|
|
|
244 |
{
|
|
|
245 |
if ( typeof arg1 == "string" && typeof arg2 == "string" )
|
|
|
246 |
{
|
|
|
247 |
return new ScreenActions( this.getScreen(arg1, arg2) );
|
|
|
248 |
}
|
|
|
249 |
else if ( typeof arg1 == "string" && typeof arg2 == "number" )
|
|
|
250 |
{
|
|
|
251 |
return new ScreenActions( this.getScreen(arg1, arg2) );
|
|
|
252 |
}
|
|
|
253 |
else
|
|
|
254 |
{
|
|
|
255 |
alert("ERROR : TelosysEnv.getActions() : invalid arguments type ! "
|
|
|
256 |
+ "\n . argument 1 : '" + ( typeof arg1 ) + "' ( string expected ) "
|
|
|
257 |
+ "\n . argument 2 : '" + ( typeof arg2 ) + "' ( string or number expected ) " );
|
|
|
258 |
return null ;
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
else if ( arguments.length == 1 )
|
|
|
262 |
{
|
|
|
263 |
if ( typeof arg1 == "object" )
|
|
|
264 |
{
|
|
|
265 |
return new ScreenActions( arg1 );
|
|
|
266 |
}
|
|
|
267 |
else
|
|
|
268 |
{
|
|
|
269 |
alert("ERROR : TelosysEnv.getActions() : the argument is not an object !");
|
|
|
270 |
return null ;
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
else
|
|
|
274 |
{
|
|
|
275 |
alert("ERROR : TelosysEnv.getActions() : " + arguments.length + " argument(s) ( 1 or 2 expected ) !");
|
|
|
276 |
return null ;
|
|
|
277 |
}
|
|
|
278 |
}
|
|
|
279 |
//------------------------------------------------------------------------------
|
|
|
280 |
this.getKeyboard = function ()
|
|
|
281 |
{
|
|
|
282 |
return _keyboard ;
|
|
|
283 |
}
|
|
|
284 |
//------------------------------------------------------------------------------
|
|
|
285 |
this.getBrowser = function ()
|
|
|
286 |
{
|
|
|
287 |
return _browser ;
|
|
|
288 |
}
|
|
|
289 |
//------------------------------------------------------------------------------
|
|
|
290 |
this.toString = function ()
|
|
|
291 |
{
|
|
|
292 |
return "Root URL='" + _sRootUrl
|
|
|
293 |
+ "' - ScreenMap URL='" + _sScreenMapUrl
|
|
|
294 |
+ "' - Ajax URL='" + _sAjaxUrl + "'" ;
|
|
|
295 |
}
|
|
|
296 |
//------------------------------------------------------------------------------
|
|
|
297 |
}
|
|
|
298 |
//------------------------------------------------------------------------------
|
|
|
299 |
// T H E E N D
|
|
|
300 |
//------------------------------------------------------------------------------
|