OW2 Consortium telosys

Rev

Rev 20 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13 lguerin 1
//------------------------------------------------------------------------------
2
// Screen_class.js
3
// Telosys framework
4
// Author  : Laurent Guérin
5
//------------------------------------------------------------------------------
6
 
7
//------------------------------------------------------------------------------
8
// "Screen" Object
9
//------------------------------------------------------------------------------
10
function Screen(argScreenName, argAjaxUrl, argScreenId )
11
{
12
	//==============================================================================
13
	// STANDARD ATTRIBUTES & METHODS
14
	//==============================================================================
15
	var _bTrace = false ;
16
	//------------------------------------------------------------------------------
17
	function _trace ( sMsg )
18
	{
19
		if ( _bTrace ) alert ( "TRACE [Screen] :\n\n" + sMsg ) ;
20
	}
21
	//------------------------------------------------------------------------------
22
	function _error ( sMsg )
23
	{
24
		alert ( "ERROR [Screen] :\n\n" + sMsg ) ;
25
	}
26
 
27
	//------------------------------------------------------------------------------
28
	if ( argScreenName == null ) _error ( "constructor : 1st argument ( Screen Name ) is null " ) ;
29
	if ( argAjaxUrl  == null )   _error ( "constructor : 2nd argument ( Ajax URL ) is null " ) ;
30
	if ( argScreenId == null ) argScreenId = 0 ;
31
 
32
	//==============================================================================
33
	// PRIVATE ATTRIBUTES
34
	//==============================================================================
35
	//--- The name of the screen
36
	var _sScreenName       = argScreenName ;
37
 
38
	//--- The URL used to send the requests
39
	var _sUrlBase          = argAjaxUrl ;
40
 
41
	//--- The ScreenContext ID in the ScreenSession
42
	var _iScreenId         = argScreenId ;
43
 
44
	var _oInvalidField     = null ;
45
 
46
	//--- The ScreenFields Array ( Filled by "RegisterField()" )
47
	var _aScreenFields     = new Array() ;
48
 
49
	//--- The ScreenViews Array ( Filled by "RegisterView()" )
50
	var _aScreenViews      = new Array() ;
51
 
52
	//--- The list of all the elements referenced in the screen ( "elem1,elem2,elemN" )
53
	var _sElements         = null ;
54
 
55
	//--- The registered screen fields serialized in XML format
56
	var _sSerializedFields = "" ;
57
 
58
	//==============================================================================
59
	// PRIVATE METHODS
60
	//==============================================================================
61
 
62
	function _buildElementsList()
63
	{
64
		var map = new Map();
65
		for ( var i = 0 ; i < _aScreenFields.length ; i++ )
66
		{
67
			oScreenField = _aScreenFields[i] ;
68
			if ( oScreenField != null )
69
			{
70
				//--- If the field is mapped to a context element
71
				if ( oScreenField.sXmlTag != null )
72
				{
73
					//--- Store the element name as a map key
74
					map.put(oScreenField.sXmlTag, true);
75
				}
76
			}
77
		}
78
		_sElements = map.keysString();
79
	}
80
 
81
	//------------------------------------------------------------------------------
82
	// Serialize the given ScreenField object (in XML format)
83
	//------------------------------------------------------------------------------
84
	function _serializeScreenField ( oScreenField, oXmlTags )
85
	{
86
		var oField = oScreenField.oField ;
87
		if ( oField == null )
88
		{
89
			_error("_serializeField : ScreenField '" + oScreenField.sId + "' : oField attribute is null !" );
90
		}
91
		else
92
		{
93
			//--- If field marked as "DO NOT SEND TO SERVER" ( Receive only ) => no serialization
94
			if ( oField.bDoNotSend ) return ;
95
 
96
			var sFieldValue = null ;
97
			if ( oField.getValue )
98
			{
99
				sFieldValue = oField.getValue() ;
100
			}
101
			else
102
			{
103
				sFieldValue = oField.value ;
104
			}
105
			if ( oField.isLongText == true )
106
			{
107
				//--- Long Text field => add the value as a child tag ( not as an attribute )
108
				oXmlTags.addChildTag(oScreenField.sXmlTag, oScreenField.sXmlAttr, sFieldValue );
109
			}
110
			else
111
			{
112
				//--- Classical field => add the value as an attribute
113
				oXmlTags.addField(oScreenField.sXmlTag, oScreenField.sXmlAttr, sFieldValue );
114
			}
115
		}
116
	}
117
 
118
	//------------------------------------------------------------------------------
119
	// Serialize all the registered fields (in XML format)
120
	// or only the fields associated with the given element name (if arg set )
121
	//------------------------------------------------------------------------------
122
	function _serializeFields ( argElementName )
123
	{
124
		//_trace("_serializeFields()");
125
 
126
		var oXmlTags = new XmlTags();
127
		var oScreenField = null ;
128
		var oField = null ;
129
		var sFieldValue = null ;
130
 
131
		//--- For each field registered in this screen
132
		for ( var i = 0 ; i < _aScreenFields.length ; i++ )
133
		{
134
			oScreenField = _aScreenFields[i] ;
135
			if ( oScreenField == null )
136
			{
137
				_error("_serializeFields() : ScreenField ["+i+"] is null ! " );
138
			}
139
			else
140
			{
141
				//--- If the field is mapped to an XML attributue
142
				if (  oScreenField.sXmlTag != null && oScreenField.sXmlAttr != null )
143
				{
144
					if ( argElementName != null )
145
					{
146
						if ( argElementName == oScreenField.sXmlTag )
147
						{
148
							_serializeScreenField ( oScreenField, oXmlTags );
149
						}
150
					}
151
					else
152
					{
153
						_serializeScreenField ( oScreenField, oXmlTags );
154
					}
155
				}
156
			}
157
		}
158
		return oXmlTags.getXmlTags() ;
159
	}
160
	//------------------------------------------------------------------------------
161
	// Populate all the registered fields from the response object
162
	//------------------------------------------------------------------------------
163
	function _populateFields ( response )
164
	{
165
		//_trace("_populateFields(response) " );
166
		//--- If no data in the response => nothing to do
167
		if ( response.dataVoid() ) return ;
168
 
169
		var oScreenField = null ;
170
		var oField = null ;
171
		var sFieldValue = null ;
172
 
173
		//--- For each field registered in this screen
174
		for ( var i = 0 ; i < _aScreenFields.length ; i++ )
175
		{
176
			oScreenField = _aScreenFields[i] ;
177
			if ( oScreenField == null )
178
			{
179
				_error("_populateFields() : ScreenField ["+i+"] is null ! " );
180
			}
181
			else
182
			{
183
				//--- If the field is mapped to an XML attributue
184
				if (  oScreenField.sXmlTag != null && oScreenField.sXmlAttr != null )
185
				{
186
					oField = oScreenField.oField ;
187
					if ( oField != null )
188
					{
189
						//--- Search the field value in the response
190
						if ( oField.isLongText )
191
						{
192
							//--- Get the value from a CHILD TAG
193
							sFieldValue = response.getDataFieldValue ( oScreenField.sXmlTag, oScreenField.sXmlAttr, true ) ;
194
						}
195
						else
196
						{
197
							//--- Get the value from an ATTRIBUTE
198
							sFieldValue = response.getDataFieldValue ( oScreenField.sXmlTag, oScreenField.sXmlAttr, false ) ;
199
						}
200
						if ( sFieldValue != null )
201
						{
202
							if ( oField.setValue )
203
							{
204
								oField.setValue(sFieldValue) ;
205
							}
206
							else
207
							{
208
								oField.value = sFieldValue ;
209
							}
210
						}
211
						// else : the field is not in the response => no change on the screen
212
					}
213
					else
214
					{
215
						_error("_populateFields() : Field ["+i+"] is null ! " );
216
					}
217
				}
218
			}
219
		}
220
	}
221
	//------------------------------------------------------------------------------
222
	// Populate all the registered view from the response object
223
	//------------------------------------------------------------------------------
224
	function _populateViews ( response )
225
	{
226
		//_trace("_populateFields(response) " );
227
		if ( response.hasView() == false ) return ;
228
 
229
		var oScreenView = null ;
230
		var oContainer  = null ;
231
 
232
		//--- For each view registered in this screen
233
		for ( var i = 0 ; i < _aScreenViews.length ; i++ )
234
		{
235
			oScreenView = _aScreenViews[i] ;
236
			if ( oScreenView == null )
237
			{
238
				_error("_populateViews() : ScreenViews ["+i+"] is null ! " );
239
			}
240
			else
241
			{
242
				//--- If the field is mapped to a response view tag
243
				if (  oScreenView.getName() != null )
244
				{
245
					oContainer = oScreenView.getContainer();
246
					if ( oContainer == null )
247
					{
248
						_error("_populateViews() : Container ["+i+"] is null ! Container id = " + oScreenView.getContainerId() );
249
					}
250
					else
251
					{
252
						sViewContent = response.getViewContent ( oScreenView.getName() ) ;
253
						/*** v 1.1.0
254
						if ( sViewContent != null )
255
						{
256
							//--- Set the view in the container
257
							oScreenView.setContent(sViewContent);
258
							//oContainer.innerHTML = sViewContent  ;
259
							//--- If the container has a "onpopulate" event script => call it
260
							var sScript = oContainer.onpopulate ;
261
							if ( sScript != null )
262
							{
263
								eval ( sScript ) ;
264
							}
265
						}
266
						***/
267
						if ( sViewContent != null ) // v 1.1.0
268
						{
269
							fwkShowViewContent( oContainer, sViewContent ); // v 1.1.0
270
						}
24 lguerin 271
					    // else // v 1.1.0.a
272
					    // { // v 1.1.0.a
273
							//fwkShowViewContent(pContainer, ""); // v 1.1.0
274
							//fwkShowViewContent(oContainer, ""); // v 1.1.0.a
275
					    // } // v 1.1.0.a
13 lguerin 276
 
277
					}
278
				}
279
			}
280
		}
281
	}
282
 
283
	//==============================================================================
284
	// PUBLIC METHODS
285
	//==============================================================================
286
	this.setTrace = function ( p )
287
	{
288
		_bTrace = p ;
289
	}
290
	//------------------------------------------------------------------------------
291
	this.getScreenName = function()
292
	{
293
		return _sScreenName ;
294
	}
295
	//------------------------------------------------------------------------------
296
	this.getScreenId = function()
297
	{
298
		return _iScreenId ;
299
	}
300
	//------------------------------------------------------------------------------
301
	this.getRequestURL = function()
302
	{
303
		return _sUrlBase ;
304
	}
305
	//------------------------------------------------------------------------------
306
	this.getElementsString = function()
307
	{
308
		if ( _sElements == null )
309
		{
310
			//--- Build the elements list
311
			_buildElementsList();
312
		}
313
		return _sElements ;
314
	}
315
	//------------------------------------------------------------------------------
316
	this.getViews = function()
317
	{
318
		return _aScreenViews ;
319
	}
320
 
321
	//------------------------------------------------------------------------------
322
	this.ScreenToXml = function( argElementName )
323
	{
324
		//_trace ( "ScreenToXml()" );
325
		var sRet = null ;
326
    	if ( _aScreenFields.length > 0 )
327
    	{
328
    		sRet = _serializeFields( argElementName );
329
    	}
330
		return sRet ;
331
	}
332
 
333
	//------------------------------------------------------------------------------
334
	this.XmlToScreen = function(response)
335
	{
336
		//_trace ( "XmlToScreen()" );
337
		if ( response.dataNotFound() )
338
		{
339
			//_trace("Data not found.");
340
		}
341
		else
342
		{
343
			//--- Populate FIELDS and VIEWS
344
	    	if ( _aScreenFields.length > 0 )
345
	    	{
346
	    		_populateFields(response);
347
	    	}
348
	    	if ( _aScreenViews.length > 0 )
349
	    	{
350
	    		_populateViews(response);
351
	    	}
352
		}
353
	}
354
 
355
	//------------------------------------------------------------------------------
356
	this.RegisterView = function(sContainerId, sScreenZone, sXmlTag, sRenderer )
357
	{
358
		if ( sContainerId == null )
359
		{
360
			_error("RegisterView : no container id !");
361
			return null ;
362
		}
363
		var oContainer = null ;
364
		try {
365
			oContainer = document.getElementById(sContainerId);
366
			if ( oContainer )
367
			{
368
				var oScreenView = new ScreenView(sContainerId, oContainer, sScreenZone, sXmlTag, sRenderer);
369
	    		_aScreenViews.push( oScreenView );
370
			}
371
			else
372
			{
373
				_error("RegisterView : Container with id " + sContainerId + " not found ! " ) ;
374
			}
375
		} catch ( e ) {
376
			_error ( "Exception in RegisterView()! \n" + e.message ) ;
377
		}
378
    	return oContainer ;
379
	}
380
 
381
	//------------------------------------------------------------------------------
382
	this.RegisterField = function(sFieldId, sScreenZone, sXmlTag, sXmlAttr )
383
	{
384
		// _trace("RegisterField(" + sFieldId +"," + sScreenZone + "," + sXmlTag + "," + sXmlAttr + ")...");
385
		if ( sFieldId == null )
386
		{
387
			_error("RegisterField : no field id !");
388
			return null ;
389
		}
390
		var oField = null ;
391
		try {
392
			oField = document.getElementById(sFieldId);
393
			if ( oField )
394
			{
395
				var oScreenField = new ScreenField(sFieldId, oField, sScreenZone, sXmlTag, sXmlAttr);
396
	    		_aScreenFields.push( oScreenField );
397
	    		//--- Is there a picto for the field ?
398
				var oFieldPicto = document.getElementById(sFieldId+"_picto");
399
				if ( oFieldPicto )
400
				{
401
					oField.oPicto = oFieldPicto ;
402
					oField.setDisabled = fwkFieldSetDisabled ;
403
				}
404
			}
405
			else
406
			{
407
				_error("RegisterField : Object with id " + sFieldId + " not found ! " ) ;
408
			}
409
		} catch ( e ) {
410
			_error ( "Exception in RegisterField()! \n" + e.message ) ;
411
		}
412
    	return oField ;
413
	}
414
	//------------------------------------------------------------------------------
415
	this.RegisterFieldDate = function(sId, sScreenZone, sXmlTag, sXmlAttr, sFormat )
416
	{
417
		//_trace("RegisterFieldDate(" + sId +"," + sScreenZone + "," + sXmlTag + "," + sXmlAttr + ")...");
418
		try {
419
			var obj = this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
420
			if ( obj )
421
			{
422
				obj.getValue  = fwkFieldDateGetValue ;
423
				obj.setValue  = fwkFieldDateSetValue ;
424
				obj.format    = sFormat ;
425
				obj.dateValue = new SimpleDate(null, sFormat);
426
			}
427
		}
428
		catch (ex) {
429
			_error ( "Exception in RegisterFieldDate : \n" + ex.message ) ;
430
		}
431
	}
432
	//------------------------------------------------------------------------------
433
	this.RegisterHidden = function(sId, sScreenZone, sXmlTag, sXmlAttr )
434
	{
435
		this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
436
	}
437
	//------------------------------------------------------------------------------
438
	this.RegisterComboBox = function(sId, sScreenZone, sXmlTag, sXmlAttr )
439
	{
440
		this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
441
	}
442
	//------------------------------------------------------------------------------
443
	this.RegisterListBox = function(sId, sScreenZone, sXmlTag, sXmlAttr )
444
	{
445
		this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
446
	}
447
	//------------------------------------------------------------------------------
448
	this.RegisterCheckBox = function(sId, sScreenZone, sXmlTag, sXmlAttr, sValOn, sValOff )
449
	{
450
		//_trace("RegisterCheckBox(" + sId +"," + sScreenZone + "," + sXmlTag + "," + sXmlAttr + ")...");
451
		try {
452
			var obj = this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
453
			if ( obj )
454
			{
455
				obj.valueChecked   = sValOn ;
456
				obj.valueUnchecked = sValOff ;
457
				obj.getValue = fwkCheckboxGetValue ;
458
				obj.setValue = fwkCheckboxSetValue ;
459
			}
460
		}
461
		catch (ex) {
462
			_error ( "Exception in RegisterCheckBox : \n" + ex.message ) ;
463
		}
464
	}
465
	//------------------------------------------------------------------------------
466
	this.RegisterRadioGroup = function(sId, sScreenZone, sXmlTag, sXmlAttr, aRadioIds )
467
	{
468
		//_trace("RegisterRadioGroup(" + sId +"," + sScreenZone + "," + sXmlTag + "," + sXmlAttr + "," + aRadioIds + ")...");
469
		try {
470
			var obj = this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
471
			if ( obj )
472
			{
473
				//--- Build the "Radio" objects array
474
				var aRadios = new Array();
475
				var oRadio = null ;
476
				var iRadio = 0 ;
477
				for ( var i = 0 ; i < aRadioIds.length ; i++ )
478
				{
479
					oRadio = document.getElementById( aRadioIds[i] ) ;
480
					if ( oRadio != null )
481
					{
482
						aRadios[iRadio++] = oRadio ;
483
					}
484
					else
485
					{
486
						_error ( "RegisterRadioGroup() : Radio object not found !  id = " + aRadioIds[i] );
487
					}
488
				}
489
				obj.aRadios = aRadios ;
490
				//--- Set new methods
491
				obj.getValue = fwkRadioGroupGetValue ;
492
				obj.setValue = fwkRadioGroupSetValue ;
493
				obj.setDisabled = fwkRadioGroupSetDisabled ;
494
				obj.isRadioGroup = true ;
495
			}
496
		}
497
		catch (ex) {
498
			_error ( "Exception in RegisterRadioGroup : \n" + ex.message ) ;
499
		}
500
	}
501
	//------------------------------------------------------------------------------
502
	this.RegisterTextArea = function(sId, sScreenZone, sXmlTag, sXmlAttr )
503
	{
504
		try {
505
			var obj = this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
506
			if ( obj )
507
			{
508
				obj.isLongText = true ;
509
			}
510
		}
511
		catch (ex) {
512
			_error ( "Exception in RegisterTextArea : \n" + ex.message ) ;
513
		}
514
	}
515
	//------------------------------------------------------------------------------
516
	this.RegisterRichTextEditor = function(sId, sScreenZone, sXmlTag, sXmlAttr )
517
	{
518
		try {
519
			var obj = this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
520
			if ( obj )
521
			{
522
				obj.getValue  = fwkRTEGetValue ;
523
				obj.setValue  = fwkRTESetValue ;
524
				obj.isLongText = true ;
525
				obj.isRichTextEditor = true ;
526
			}
527
		}
528
		catch (ex) {
529
			_error ( "Exception in RegisterRichTextEditor : \n" + ex.message ) ;
530
		}
531
	}
532
	//------------------------------------------------------------------------------
533
	this.RegisterHtmlViewer = function(sId, sScreenZone, sXmlTag, sXmlAttr )
534
	{
535
		try {
536
			var obj = this.RegisterField (sId, sScreenZone, sXmlTag, sXmlAttr ) ;
537
			if ( obj )
538
			{
539
				//obj.getValue  = xxxx ; // unused
540
				obj.setValue  = fwkHtmlViewerSetValue ;
541
				obj.isLongText = true ;
542
				obj.bDoNotSend = true ;
543
				obj.isHtmlViewer = true ;
544
			}
545
		}
546
		catch (ex) {
547
			_error ( "Exception in RegisterHtmlViewer : \n" + ex.message ) ;
548
		}
549
	}
550
 
551
	//------------------------------------------------------------------------------
552
	// Clear a specific field passed by reference (object)
553
	//------------------------------------------------------------------------------
554
	this.clearField = function ( oField ) // RET : void
555
	{
556
		//_trace ( "Screen.clearField( nodeName=" + oField.nodeName + " id=" + oField.id + ")");
557
		var sType = oField.type ;
558
		if ( sType != null )
559
		{
560
			switch ( sType )
561
			{
562
				case "text" :
563
				case "file" :
564
				case "password" :
565
				case "textarea" :
566
					oField.value = "" ;
567
					/**
568
					// fwkResetFieldErrorStatus(oField); #TODO ????
569
					try {
570
						// Option par défaut (si elle existe)
571
						if ( oField.fwkDefaultValue != null ) // Par valeur
572
						{
573
							oField.value = oField.fwkDefaultValue ;
574
						}
575
	  				} catch ( ex ) {
576
						oField.value = "" ;
577
	  				}
578
	  				**/
579
					break ;
580
 
581
				case "select-one" :
582
				case "select-multiple" :
583
					oField.selectedIndex = -1 ; // Aucune ligne sélectionnée (OK / IE & Firefox)
584
					/**
585
					try {
586
						// Option par défaut (si elle existe)
587
						if ( oField.fwkDefaultValue != null )	   // Par valeur
588
						{
589
							oField.value = oField.fwkDefaultValue ;
590
						}
591
						else if ( oField.fwkDefaultIndex != null ) // Par index
592
						{
593
							oField.selectedIndex = oField.fwkDefaultIndex ;
594
						}
595
	  				} catch ( ex ) {
596
		  				oField.selectedIndex = -1 ;
597
	  				}
598
	  				**/
599
					break ;
600
 
601
				case "checkbox" :
602
				case "radio" :
603
					oField.checked = false ;
604
					break ;
605
			}
606
		}
607
		else // NO oField.type
608
		{
609
			if ( oField.isRichTextEditor == true ) // Rich Text Editor
610
			{
611
				//_trace ( "Screen.clearField( nodeName=" + oField.nodeName + " id=" + oField.id + ") : CLEAR RTE ");
612
				fwkRTEClearText(oField);
613
			}
614
			else if ( oField.isHtmlViewer == true ) // HtmlViewer ( DIV )
615
			{
616
				//_trace ( "Screen.clearField( nodeName=" + oField.nodeName + " id=" + oField.id + ") : CLEAR DIV");
617
				oField.innerHTML = "" ; // Clear the DIV content
618
			}
619
			else if ( oField.isRadioGroup == true ) // RadioGroup widget ( DIV )
620
			{
621
				var elements = oField.getElementsByTagName("input") ;
622
				if ( elements != null )
623
				{
624
					for ( var i=0 ; i < elements.length ; i++ )
625
					{
626
						//_trace ( "element["+i+"] : type = " + elements[i].type );
627
						if ( elements[i].type == "radio" )
628
						{
629
							elements[i].checked = false  ;
630
						}
631
					}
632
				}
633
			}
634
		}
635
	}
636
	//------------------------------------------------------------------------------
637
	// Enable / Disable a field
638
	//------------------------------------------------------------------------------
639
	this.setFieldDisabled = function ( oField, bFlag ) // RET : void
640
	{
641
		if ( oField.setDisabled )
642
		{
643
			//--- Specific disabled function for this field
644
			oField.setDisabled(bFlag) ;
645
		}
646
		else
647
		{
648
			oField.disabled = bFlag ;
649
			//fwkSetFieldButtonDisabled(sId, true);
650
		}
651
	}
652
	//------------------------------------------------------------------------------
653
 
654
	//------------------------------------------------------------------------------
655
	this.clearViews = function ( sZone ) // RET : void
656
	{
657
		var oScreenView = null ;
658
		for ( var i = 0 ; i < _aScreenViews.length ; i++ )
659
		{
660
			oScreenView = _aScreenViews[i] ;
661
			if ( oScreenView != null )
662
			{
663
				oScreenView.clear(sZone);
664
			}
665
			else
666
			{
667
				_error("clearViews() : View ["+i+"] is null ! " );
668
			}
669
		}
670
	}
671
	//------------------------------------------------------------------------------
672
	// Clear the entire screen or a specific zone
673
	// sZone arg can be null
674
	this.clear = function ( sZone ) // RET : void
675
	{
676
		//_trace("Clear() : sZone = " + sZone );
677
		var oScreenField = null ;
678
		var oField = null ;
679
 
680
		//--- For each field registered in this screen
681
		for ( var i = 0 ; i < _aScreenFields.length ; i++ )
682
		{
683
			oScreenField = _aScreenFields[i] ;
684
			if ( oScreenField == null )
685
			{
686
				_error("clear() : ScreenField ["+i+"] is null ! " );
687
			}
688
			else
689
			{
690
				oField = oScreenField.oField ;
691
				if ( oField == null )
692
				{
693
					_error("clear() : Field ["+i+"] is null ! " );
694
				}
695
				else
696
				{
697
					if ( sZone == null )
698
					{
699
						//_trace("Clear() : field " + i + " - field.type = " + oField.type );
700
						this.clearField(oField);
701
					}
702
					else
703
					{
704
						if ( oScreenField.sZone == sZone )
705
						{
706
							this.clearField(oField);
707
						}
708
					}
709
				}
710
			}
711
		}
712
		this.clearViews(sZone);
713
	}
714
	//------------------------------------------------------------------------------
715
	// Enable the entire screen or a specific zone
716
	// sZone arg can be null
717
	//------------------------------------------------------------------------------
718
	this.enable = function ( sZone ) // RET : void
719
	{
720
		this.setDisabled ( false, sZone ) // RET : void
721
	}
722
	this.disable = function ( sZone ) // RET : void
723
	{
724
		this.setDisabled ( true, sZone ) // RET : void
725
	}
726
	this.setDisabled = function ( bFlagDisabled, sZone ) // RET : void
727
	{
728
		var oScreenField = null ;
729
		var oField = null ;
730
 
731
		//--- For each field registered in this screen
732
		for ( var i = 0 ; i < _aScreenFields.length ; i++ )
733
		{
734
			oScreenField = _aScreenFields[i] ;
735
			if ( oScreenField == null )
736
			{
737
				_error("setDisabled() : ScreenField ["+i+"] is null ! " );
738
			}
739
			else
740
			{
741
				oField = oScreenField.oField ;
742
				if ( oField == null )
743
				{
744
					_error("setDisabled() : Field ["+i+"] is null ! " );
745
				}
746
				else
747
				{
748
					if ( sZone == null )
749
					{
750
						this.setFieldDisabled(oField, bFlagDisabled );
751
					}
752
					else
753
					{
754
						if ( oScreenField.sZone == sZone )
755
						{
756
							this.setFieldDisabled(oField, bFlagDisabled );
757
						}
758
					}
759
				}
760
			}
761
		}
762
	}
763
 
764
	//------------------------------------------------------------------------------
765
	// METHODE : Desc
766
	//------------------------------------------------------------------------------
767
	this.desc = function()
768
	{
769
		alert ( "SCREEN OBJECT : \n" +
770
				"\n . Screen-Name = " + _sScreenName +
771
				"\n . Context Id = " + _iScreenId +
772
				"\n . UrlBase = " + _sUrlBase +
773
				"\n . Elements : " + this.getElementsString() +
774
				"\n . " + _aScreenFields.length + " field(s) " +
775
				"" );
776
	}
777
 
778
	//------------------------------------------------------------------------------
779
	//------------------------------------------------------------------------------
780
	//------------------------------------------------------------------------------
781
/***
782
	this.OnLoad = function () // RET : void
783
	{
784
		this.New();
785
		this.printMessage();
786
	}
787
	//------------------------------------------------------------------------------
788
	this.Exit = function()
789
	{
790
		//--- On essaye de fermer l'écran
791
		try {
792
			this.close();
793
		}
794
		catch (e) {}
795
 
796
		//--- Si l'écran n'a pas été fermé on réinitialise l'écran
797
		this.New();
798
		this.printMessage();
799
	}
800
	//------------------------------------------------------------------------------
801
	this.close = function() // TODO ???
802
	{
803
		//--- Ecran popup
804
		if ( _iScreenId > 0 )
805
		{
806
			//--- On sort de l'écran
807
			window.close();
808
		}
809
		//--- Premier champ de l'écran
810
		else
811
		{
812
			try
813
			{
814
				//--- On ouvre la page d'accueil
815
				document.location.href = PageAccueil; // TODO ???
816
			} catch (e) {}
817
		}
818
	}
819
	//------------------------------------------------------------------------------
820
***/
821
	//==============================================================================
822
	//  GESTION DES CHAMPS ( KeyFields et DataFields ) : Disable / Clear / Check
823
	//==============================================================================
824
 
825
	//------------------------------------------------------------------------------
826
	// Check a specific field
827
	//------------------------------------------------------------------------------
828
	this.CheckField = function ( oField ) // RET : boolean : true = OK / false = NOK
829
	{
830
		//--- Champ NOT NULL -------------------------------------------------------
831
		if ( oField.getAttribute("fwkNotNull") )
832
		{
833
			// _trace ( "Check field ( id = " +oField.id+ " ) : attribute fwkNotNull found." ) ;
834
			switch ( oField.getAttribute("type") )
835
			{
836
				case "text" :       // Tag "input type=text "
837
				case "file" :
838
				case "password" :
839
				case "textarea" :   // Tag "textarea "
840
				case "select-one" : // Tag "select"
841
				// case "checkbox" :  // Not Null n'a pas de sens pour une "Check Box"
842
				// case "radio" :     // Not Null n'a pas de sens pour un  "Radio Button"
843
					if ( oField.value == null || oField.value == "" )
844
					{
845
						_oInvalidField = oField ;
846
						var memoColor = oField.style.backgroundColor ;
847
						oField.style.backgroundColor = 'orange' ;
848
						_error ( "The field "+oField.name+ " ( id = " +oField.id+ " ) is required " );
849
						oField.style.backgroundColor = memoColor ;
850
						return false ;
851
					}
852
					break ;
853
			}
854
		}
855
		//--- Champ dans l'état VALEUR INCORRECTE ----------------------------------
856
		if ( fwkIsFieldOnError(oField) || fwkIsFieldOnShallowCheckingError(oField) )
857
		{
858
			_oInvalidField = oField ;
859
			//_trace ( "There is an invalid field (at least) !" );
860
			return false ;
861
		}
862
		return true ;
863
	}
864
 
865
 
866
	//------------------------------------------------------------------------------
867
	// Fonction de vérification de l'ensemble des champs
868
	// ( La sortie du champ éventuellement en cours de saisie est forcée
869
	// au niveau de la gestion des touches de fonctions )
870
	//------------------------------------------------------------------------------
871
	this.CheckAllFields = function () // RET : boolean : true = OK / false = NOK
872
	{
873
		for ( var i = 0 ; i < _aScreenFields.length ; i++ )
874
		{
875
			if ( this.CheckField(_aScreenFields[i]) == false ) return false ;
876
		}
877
		//--- Here all the fields are OK
878
		_oInvalidField = null ;
879
		return true ;
880
	}
881
 
882
	//------------------------------------------------------------------------------
883
	function _getFieldParamValue ( oScreenField )
884
	{
885
		var oField = oScreenField.oField ;
886
		if ( oField == null )
887
		{
888
			_error("_setParamValue : ScreenField '" + oScreenField.sId + "' : oField attribute is null !" );
889
			return null ;
890
		}
891
		else
892
		{
893
			//--- If field marked as "DO NOT SEND TO SERVER" ( Receive only ) => do not use as parameter
894
			if ( oField.bDoNotSend ) return null ;
895
 
896
			//--- Long Text field : cannot be send as a parameter
897
			if ( oField.isLongText == true ) return null ;
898
 
899
			//--- Classical field => use the value as a parameter if not void
900
			var sFieldValue = null ;
901
			if ( oField.getValue )
902
			{
903
				sFieldValue = oField.getValue() ;
904
			}
905
			else
906
			{
907
				sFieldValue = oField.value ;
908
			}
909
			if ( sFieldValue == "" ) return null ;
910
			return sFieldValue ;
911
		}
912
	}
913
	//------------------------------------------------------------------------------
914
	this.setParametersFromFields = function ( argParamMap, argElementName ) // v 1.1.0
915
	{
916
		if ( argParamMap == null )
917
		{
918
			_error("setParametersFromFields : argParamMap is null");
919
			return ;
920
		}
921
		//--- For each field registered in this screen
922
		for ( var i = 0 ; i < _aScreenFields.length ; i++ )
923
		{
924
			oScreenField = _aScreenFields[i] ;
925
			if ( oScreenField != null )
926
			{
927
				//--- If the field is mapped to an XML attributue
928
				if (  oScreenField.sXmlTag != null && oScreenField.sXmlAttr != null )
929
				{
930
					if ( argElementName != null )
931
					{
932
						if ( argElementName == oScreenField.sXmlTag )
933
						{
934
							var sValue = _getFieldParamValue ( oScreenField );
935
							if ( sValue != null ) argParamMap.put(oScreenField.sXmlAttr, sValue) ;
936
						}
937
					}
938
					else
939
					{
940
						var sValue = _getFieldParamValue ( oScreenField );
941
						if ( sValue != null ) argParamMap.put(oScreenField.sXmlAttr, sValue) ;
942
					}
943
				}
944
			}
945
		}
946
	}
947
 
948
	//==============================================================================
949
	//  ACTIONS UTILISATEUR
950
	//==============================================================================
951
 
952
	//------------------------------------------------------------------------------
953
	// Triggers : A SURCHARGER SI NECESSAIRE
954
	//------------------------------------------------------------------------------
955
	this.beforeSelect = function () { return true ; }
956
	this.afterSelect  = function () { return ; }
957
	this.beforeUpdate = function () { return true ; }
958
	this.afterUpdate  = function () { return ; }
959
	this.beforeInsert = function () { return true ; }
960
	this.afterInsert  = function () { return ; }
961
	this.beforeDelete = function () { return true ; }
962
	this.afterDelete  = function () { return ; }
963
 
964
}