Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
13 rsolanki 1
<%
2
'=============================================================
3
'//
4
'//						Popup Menu Control
5
'//
6
'// version: 		0.4
7
'//	last modified: 	09-May-2004 03:03 by Sasha Vukovic
8
'=============================================================
9
%>
10
<%
11
Class PopupMenuControl
12
 
13
	Private mArrPopupMenuDef()
14
	Private mobjNameDefMap			' Item can be accesed by name. Must be unique within one page
15
	Private mobjIdDefMap			' Item can be accesed by id. Must be unique within one page. If NULL, ubound is assigned to it
16
	Private mobjSeparator			' Has a name of item after separator is applied
17
 
18
	Private mPreCodeTemplate
19
	Private mPostCodeTemplate
20
	Private mMenuItemTemplate
21
	Private mSeparatorTemplate
22
 
23
	Private mNumOfItemProperties
24
	Private mLastItemPropertyInx
25
 
26
 
27
	Private mbHideAll
28
	Private mbDisableAll
29
 
30
 
31
	Private InxItemTableName
32
	Private InxdbAccessManagerObjID
33
	Private InxdbName
34
	Private InxTxt
35
	Private InxImg
36
	Private InxImgOff
37
	Private InxLink
38
	Private InxEventHandler
39
	Private InxHint
40
	Private InxActive
41
	Private InxVisible
42
 
43
 
44
 
45
	Public Property Let AllVisible ( cVal )
46
		If cVal = enumDB_YES Then
47
			mbHideAll = FALSE
48
		Else
49
			mbHideAll = TRUE
50
		End If
51
 
52
	End Property
53
 
54
	Public Property Let AllActive ( cVal )
55
		If cVal = enumDB_YES Then
56
			mbDisableAll = FALSE
57
		Else
58
			mbDisableAll = TRUE
59
		End If
60
 
61
	End Property
62
 
63
 
64
	'-----------------------------------------------------------------------------------------------------------------
65
	Public Sub PopupMenuStyle( sTemplateDoc, sStyleId ) 
66
		Dim mobjTemplateManager
67
 
68
		Set mobjTemplateManager = New TemplateManager
69
		mobjTemplateManager.TemplateDoc = sTemplateDoc
70
 
71
		' Set Templates
72
		mPreCodeTemplate	= mobjTemplateManager.getElementValue ( sStyleId &"/PreMenuCode" )
73
		mMenuItemTemplate	= mobjTemplateManager.getElementValue ( sStyleId &"/MenuItem" )
74
		mSeparatorTemplate	= mobjTemplateManager.getElementValue ( sStyleId &"/Separator" )
75
		mPostCodeTemplate	= mobjTemplateManager.getElementValue ( sStyleId &"/PostMenuCode" )
76
 
77
		Set mobjTemplateManager = Nothing
78
	End Sub
79
	'-----------------------------------------------------------------------------------------------------------------
80
	Private Sub SetItemPropertyByIndex ( nInx, nProperty, Value )
81
		If nInx = ""  OR  nProperty = ""  OR  Value = "" Then Err.Raise 8, "Method SetItemPropertyByIndex", "Empty parameters found. nInx="& nInx &", nProperty="& nProperty &", Value="& Value 
82
 
83
		mArrPopupMenuDef ( nProperty, nInx ) = Value
84
 
85
		'Response.write "mArrPopupMenuDef ( "& nProperty &", "& nInx &" ) = "& Value &"<br>"
86
	End Sub
87
	'-----------------------------------------------------------------------------------------------------------------
88
	Private Function LastItemInx ()
89
		 LastItemInx = UBound ( mArrPopupMenuDef, 2 )
90
	End Function
91
	'-----------------------------------------------------------------------------------------------------------------
92
	Public Sub LoadRows ( aRows )
93
		' Pass the full array row matching the columns of mArrPopupMenuDef()
94
		Dim nProperty, newArrayDim, numOfRows, rowNum
95
 
96
		numOfRows = UBound( aRows, 2 )
97
 
98
 
99
		For rowNum = 0 To numOfRows
100
			' Increase array by 1
101
			newArrayDim = LastItemInx() + 1
102
			ReDim Preserve mArrPopupMenuDef( mNumOfItemProperties, newArrayDim )
103
 
104
			mobjNameDefMap.Add ( Cstr( aRows ( InxdbName, rowNum ) ) ), CStr( newArrayDim )
105
 
106
			For nProperty = 0 To mLastItemPropertyInx
107
				If (nProperty = InxLink) OR (nProperty = InxEventHandler) Then
108
					' Link And EventHandlers need to be evaluated
109
					mArrPopupMenuDef ( nProperty, newArrayDim ) = Eval ( aRows ( nProperty, rowNum ) )
110
				Else
111
					mArrPopupMenuDef ( nProperty, newArrayDim ) = aRows ( nProperty, rowNum )
112
				End If
113
			Next
114
		Next
115
 
116
	End Sub
117
	'-----------------------------------------------------------------------------------------------------------------
118
	Public Sub AddMenuItem ( sItemName, nItemID )
119
		Dim newArrayDim
120
 
121
		If InStr( sItemName, " " ) > 0 Then	Err.Raise 8, "Method AddMenuItem", "Item Name '"& sItemName &"' cannot have spaces."
122
 
123
 
124
 
125
		If NOT mobjNameDefMap.Exists (CStr( sItemName )) Then
126
 
127
			newArrayDim = LastItemInx() + 1
128
 
129
			ReDim Preserve mArrPopupMenuDef( mNumOfItemProperties, newArrayDim )
130
 
131
			' Store name
132
			Call SetItemPropertyByIndex ( newArrayDim, InxdbName, sItemName )
133
 
134
			mobjNameDefMap.Add ( Cstr( sItemName ) ), CStr( newArrayDim )
135
 
136
			If Not IsNull(nItemID) Then
137
				' If ID is supplied, map it to array index
138
				mobjIdDefMap.Add Cstr( nItemID ), CStr( newArrayDim )
139
 
140
				' Store ID
141
				Call SetItemPropertyByIndex ( newArrayDim, InxdbAccessManagerObjID, nItemID )
142
 
143
			Else
144
				' else use array index as ID
145
				mobjIdDefMap.Add Cstr( newArrayDim ), CStr( newArrayDim )
146
 
147
				' Store array index as ID
148
				Call SetItemPropertyByIndex ( newArrayDim, InxdbAccessManagerObjID, newArrayDim )
149
 
150
			End If
151
 
152
			' Set Defaults
153
			'Call SetItemDefaults ( sItemName )
154
		Else
155
			'TODO
156
 
157
		End If
158
 
159
	End Sub
160
	'-----------------------------------------------------------------------------------------------------------------
161
	Private Sub RenderItem ( itemIndex, bIsActiveByAccessControl )
162
		Dim sMenuItem
163
		sMenuItem  	 = mMenuItemTemplate								' Get menu item template
164
 
165
		' --- Menu Item ---
166
		' Check Active state
167
		If bIsActiveByAccessControl AND mArrPopupMenuDef( InxActive, itemIndex ) <> enumDB_NO Then			' Check if menu item is Active
168
 
169
			sMenuItem = Replace ( sMenuItem, "%TEXT%", "<a href='"& ( mArrPopupMenuDef( InxLink, itemIndex ) ) &"' "&_
170
													   " "& ( mArrPopupMenuDef( InxEventHandler, itemIndex ) ) &" class='menu_link' title='"& mArrPopupMenuDef( InxHint, itemIndex ) &"'>"& mArrPopupMenuDef( InxTxt, itemIndex ) &"</a>" )
171
 
172
			If NOT IsNull(mArrPopupMenuDef( InxImg, itemIndex )) AND (mArrPopupMenuDef( InxImg, itemIndex ) <> "") Then 
173
				sMenuItem = Replace ( sMenuItem, "%IMAGE%", "<img src='"& mArrPopupMenuDef( InxImg, itemIndex ) &"'>" )
174
			Else
175
				' No image supplied
176
				sMenuItem = Replace ( sMenuItem, "%IMAGE%", "<img src='images/spacer.gif' height='19'>" )
177
			End If
178
 
179
 
180
		Else
181
 
182
 
183
			' Render DISABLE menu item
184
			sMenuItem = Replace ( sMenuItem, "%TEXT%", mArrPopupMenuDef( InxTxt, itemIndex ) )
185
 
186
			If NOT IsNull(mArrPopupMenuDef( InxImgOff, itemIndex )) AND (mArrPopupMenuDef( InxImgOff, itemIndex ) <> "") Then 
187
				sMenuItem = Replace ( sMenuItem, "%IMAGE%", "<img src='"& mArrPopupMenuDef( InxImgOff, itemIndex ) &"' title='"& mArrPopupMenuDef( InxHint, itemIndex ) &"'>" )
188
			Else
189
				' No image supplied
190
				sMenuItem = Replace ( sMenuItem, "%IMAGE%", Empty )
191
			End If
192
 
193
 
194
		End If
195
		Response.write sMenuItem		' Finally render Menu Item
196
 
197
	End Sub
198
	'-----------------------------------------------------------------------------------------------------------------
199
	Public Sub RenderInOrder ( sDivName, aItemsList, oAccessControl, cObjectName )
200
		Dim itemInx, itemName, nLastItemInx, bIsVisible, bIsActive
201
 
202
		Response.write "<DIV id='"& sDivName &"' name='"& sDivName &"' style='display:none;'>"
203
		Response.write mPreCodeTemplate
204
 
205
		For Each itemName in aItemsList
206
			itemInx = mobjNameDefMap.Item (Cstr(itemName))
207
			'If itemInx = "" Then 	Err.Raise 8, "Method Render", "Definition for item name '"& itemName &"' not found."
208
 
209
			'===== Access Control =====
210
			If IsObject(oAccessControl) Then
211
				' Access Control takes priority
212
				bIsVisible = oAccessControl.IsDataVisible ( mArrPopupMenuDef( InxItemTableName, itemInx ), mArrPopupMenuDef( InxdbAccessManagerObjID, itemInx ), cObjectName )
213
				bIsActive = oAccessControl.IsDataActive ( mArrPopupMenuDef( InxItemTableName, itemInx ), mArrPopupMenuDef( InxdbAccessManagerObjID, itemInx ), cObjectName )
214
			Else
215
				' set Visible
216
				If mArrPopupMenuDef( InxVisible, itemInx ) = enumDB_YES Then
217
					bIsVisible = TRUE
218
				Else
219
					bIsVisible = FALSE
220
				End If
221
 
222
				' set Active
223
				If NOT mbDisableAll AND (mArrPopupMenuDef( InxActive, itemInx ) = enumDB_YES) Then
224
					bIsActive = TRUE
225
				Else
226
					bIsActive = FALSE
227
				End If
228
 
229
			End If
230
			'=========================
231
 
232
 
233
			If itemName = enumSEPARATOR_LABEL AND bIsVisible Then
234
				Response.write mSeparatorTemplate
235
			Else
236
 
237
				'TODO
238
				If bIsVisible Then
239
					Call RenderItem ( itemInx, bIsActive )
240
				End If
241
 
242
			End If
243
 
244
 
245
			' --- Separators added manually using  method AddSeparator or AddSeparatorAfter ---
246
			If mobjSeparator.Exists ( Cstr(mArrPopupMenuDef( InxdbName, itemInx )) ) AND bIsVisible Then
247
				Response.write mSeparatorTemplate
248
 
249
			End If
250
 
251
		Next
252
 
253
		Response.write mPostCodeTemplate
254
		Response.write "</DIV>"
255
	End Sub
256
	'-----------------------------------------------------------------------------------------------------------------
257
	Public Sub Render ( sDivName )
258
		Dim item, nLastItemInx, sMenuItem
259
		' --- Check if GLOBAL Visible
260
		If NOT mbHideAll Then
261
 
262
			Response.write "<DIV id='"& sDivName &"' name='"& sDivName &"' style='display:none;'>"
263
			Response.write mPreCodeTemplate
264
 
265
			nLastItemInx = LastItemInx()
266
 
267
 
268
			For item = 0 To nLastItemInx
269
 
270
				' --- Check if GLOBAL Active
271
				'If mArrPopupMenuDef( InxdbName, item ) Then
272
					Call RenderItem ( item, TRUE )	' TODO
273
 
274
					' --- Separator ---
275
					If mobjSeparator.Exists ( Cstr(mArrPopupMenuDef( InxdbName, item )) ) Then
276
						Response.write mSeparatorTemplate
277
					End If
278
				'End If
279
 
280
 
281
			Next
282
 
283
			Response.write mPostCodeTemplate
284
			Response.write "</DIV>"
285
 
286
		End If
287
	End Sub
288
	'-----------------------------------------------------------------------------------------------------------------
289
	Public Sub AddSeparatorAfter ( sItemName )
290
		If InStr( sItemName, " " ) > 0 Then	Err.Raise 8, "Method AddSeparatorAfter", "Item Name '"& sItemName &"' cannot have spaces."
291
		mobjSeparator.Add (Cstr(sItemName)), ""
292
	End Sub
293
	'-----------------------------------------------------------------------------------------------------------------
294
	Public Sub AddSeparator ()
295
		mobjSeparator.Add ( Cstr(mArrPopupMenuDef(InxdbName, LastItemInx())) ), ""
296
	End Sub
297
	'-----------------------------------------------------------------------------------------------------------------
298
	'Private Sub SetItemDefaults ( sItemName )
299
	'	' Additional default setup
300
	'	'Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, enumDB_YES )		' Default Active = enumDB_YES
301
	'	'Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxVisible, enumDB_YES )		' Default Active = enumDB_YES
302
	'End Sub
303
	'-----------------------------------------------------------------------------------------------------------------
304
	Public Sub Text ( sItemName, Value )
305
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxTxt, Value )
306
	End Sub
307
	'-----------------------------------------------------------------------------------------------------------------
308
	Public Sub Image ( sItemName, Value )
309
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImg, Value )
310
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImgOff, Value )			' Default image disable to be the same as image
311
	End Sub
312
	'-----------------------------------------------------------------------------------------------------------------
313
	Public Sub ImageOff ( sItemName, Value )
314
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImgOff, Value )
315
	End Sub
316
	'-----------------------------------------------------------------------------------------------------------------
317
	Public Sub Link ( sItemName, Value )
318
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxLink, Value )
319
	End Sub
320
	'-----------------------------------------------------------------------------------------------------------------
321
	Public Sub EventHandler ( sItemName, Value )
322
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxEventHandler, Value )
323
	End Sub
324
	'-----------------------------------------------------------------------------------------------------------------
325
	Public Sub Hint ( sItemName, Value )
326
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxHint, Value )
327
	End Sub
328
	'-----------------------------------------------------------------------------------------------------------------
329
	Public Sub Active ( sItemName, Value )
330
		' Y = enabled, N = disabled
331
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, Value )
332
	End Sub
333
	'-----------------------------------------------------------------------------------------------------------------
334
	Public Sub Visible ( sItemName, Value )
335
		' Y = show, N = hide
336
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxVisible, Value )
337
	End Sub
338
	'-----------------------------------------------------------------------------------------------------------------
5836 dpurdie 339
    ' Load one row of data
340
    '   Is a bit round about as this replaces code that was read from the database
341
    Private Sub LoadRow(aData)
342
        Dim newArrayDim, nProperty
343
 
344
		' Increase array by 1
345
		newArrayDim = LastItemInx() + 1
346
		ReDim Preserve mArrPopupMenuDef( mNumOfItemProperties, newArrayDim )
347
 
348
		mobjNameDefMap.Add ( Cstr( aData ( InxdbName ) ) ), CStr( newArrayDim )
349
 
350
        For nProperty = 0 To mLastItemPropertyInx
351
            If (nProperty = InxLink) OR (nProperty = InxEventHandler) Then
352
                ' Link And EventHandlers need to be evaluated
353
                mArrPopupMenuDef ( nProperty, newArrayDim ) = Eval ( aData ( nProperty ) )
354
            Else
355
                mArrPopupMenuDef ( nProperty, newArrayDim ) = aData ( nProperty )
356
            End If
357
        Next
358
    End Sub
359
 
360
	'-----------------------------------------------------------------------------------------------------------------
361
    '   Generate data - instead of reading it from a database
362
    '   Generate it one row (array) at a time
363
    '   Array contents need to match the Inx* indexes defined in this class
364
    Private Sub GenerateData()
365
 
366
        LoadRow Array( "DEF_MENU_ITEMS",_
367
                    "1",_
368
					"pmiNewBom",_
369
					"New...",_
370
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiNewBom"""" );ShowProgress();""",_
371
					null,_
372
					null,_
373
					null,_
374
					"Create New BOM...",_
375
					"Y",_
376
					"Y" )
377
 
378
        LoadRow Array( "DEF_MENU_ITEMS",_
379
                    "2",_
380
					"pmiBomProperties",_
381
					"BOM Properties",_
382
					"""#""",_
383
					null,_
384
					null,_
385
					null,_
386
					null,_
387
					"Y",_
388
					"Y" )
389
 
390
        LoadRow Array( "DEF_MENU_ITEMS",_
391
                    "3",_
392
					"pmiAcceptBom",_
393
					"Accept",_
394
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiAcceptBom"""" );ShowProgress();""",_
395
					null,_
396
					"icons/mi_accept.gif",_
397
					"icons/mi_accept.gif",_
398
					"Accept BOM",_
399
					"Y",_
400
					"Y" )
401
 
402
        LoadRow Array( "DEF_MENU_ITEMS",_
403
                    "4",_
404
					"pmiRejectBom",_
405
					"Reject",_
406
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiRejectBom"""" );ShowProgress();""",_
407
					null,_
408
					"icons/mi_reject.gif",_
409
					"icons/mi_reject.gif",_
410
					"Reject BOM",_
411
					"Y",_
412
					"Y" )
413
 
414
        LoadRow Array( "DEF_MENU_ITEMS",_
415
                    "5",_
416
					"pmiReleaseTo",_
417
					"Release To...",_
418
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiReleaseTo"""" );ShowProgress();""",_
419
					null,_
420
					"icons/mi_release_to.gif",_
421
					"icons/mi_release_to.gif",_
422
					null,_
423
					"Y",_
424
					"Y" )
425
 
426
        LoadRow Array( "DEF_MENU_ITEMS",_
427
                    "6",_
428
					"pmiDestroyBom",_
429
					"Destroy BOM",_
430
					"""javascript:go_submit( document.FormState""& StateId &"", """"btnDestroyBom"""" );ShowProgress();""",_
431
					"""onClick=""""return confirmAction('Destroy selected BOM?');""""""",_
432
					"icons/mi_destroy.gif",_
433
					"icons/mi_destroy.gif",_
434
					null,_
435
					"Y",_
436
					"Y" )
437
 
438
        LoadRow Array( "DEF_MENU_ITEMS",_
439
                    "7",_
440
					"pmiImportExportBom",_
441
					"Import and Export...",_
442
					"""#""",_
443
					null,_
444
					null,_
445
					null,_
446
					null,_
447
					"Y",_
448
					"Y" )
449
 
450
        LoadRow Array( "DEF_MENU_ITEMS",_
451
                    "8",_
452
					"pmiShowHideBom",_
453
					"Show and Hide...",_
454
					"""#""",_
455
					null,_
456
					null,_
457
					null,_
458
					null,_
459
					"Y",_
460
					"Y" )
461
 
462
        LoadRow Array( "DEF_MENU_ITEMS",_
463
                    "9",_
464
					"pmiLockBom",_
465
					"Protect...",_
466
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiLockBom"""" );ShowProgress();""",_
467
					"""onClick=""""return confirmAction('Protecting the BOM will prevent further changes?');""""""",_
468
					null,_
469
					null,_
470
					"Locking the BOM will prevent further changes",_
471
					"Y",_
472
					"Y" )
473
 
474
        LoadRow Array( "DEF_MENU_ITEMS",_
475
                    "10",_
476
					"pmiUnlockBom",_
477
					"Unprotect...",_
478
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiUnlockBom"""" );ShowProgress();""",_
479
					"""onClick=""""return confirmAction('Unprotecting the BOM will allow changes?');""""""",_
480
					null,_
481
					null,_
482
					null,_
483
					"Y",_
484
					"Y" )
485
 
486
        LoadRow Array( "DEF_MENU_ITEMS",_
487
                    "13",_
488
					"pmiVersionTree",_
489
					"Version Tree",_
490
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiVersionTree"""" );ShowProgress();""",_
491
					null,_
492
					null,_
493
					null,_
494
					null,_
495
					"Y",_
496
					"Y" )
497
 
498
        LoadRow Array( "DEF_MENU_ITEMS",_
499
                    "14",_
500
					"pmiToProduction",_
501
					"To Production Manager...",_
502
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiToProduction"""" );ShowProgress();""",_
503
					null,_
504
					null,_
505
					null,_
506
					null,_
507
					"Y",_
508
					"Y" )
509
 
510
        LoadRow Array( "DEF_MENU_ITEMS",_
511
                    "15",_
512
					"pmiUnDeployView",_
513
					"View",_
514
					"""javascript:go_submit( document.FormState""& StateId &"", """"pmiUnDeployView"""" );ShowProgress();""",_
515
					null,_
516
					"icons/btn_sync.gif",_
517
					"icons/btn_sync_off.gif",_
518
					null,_
519
					"Y",_
520
					"Y" )
521
 
522
    End Sub
523
	'-----------------------------------------------------------------------------------------------------------------
13 rsolanki 524
	Private Sub Class_Initialize()
525
		'// Perform action on creation of object. e.g. Set myObj = New ThisClassName
526
		Set mobjNameDefMap = CreateObject("Scripting.Dictionary")
527
		Set mobjIdDefMap = CreateObject("Scripting.Dictionary")
528
		Set mobjSeparator = CreateObject("Scripting.Dictionary")
529
 
530
 
531
		mNumOfItemProperties = 11  	' Number of properties in array which define one menu item.
532
		mLastItemPropertyInx = mNumOfItemProperties - 1
533
 
534
		mbHideAll = FALSE
535
		mbDisableAll = FALSE
536
 
537
		ReDim mArrPopupMenuDef ( mNumOfItemProperties, -1 )
538
 
539
		InxItemTableName		= 0
540
		InxdbAccessManagerObjID	= 1
541
		InxdbName				= 2
542
		InxTxt					= 3
543
		InxLink					= 4
544
		InxEventHandler			= 5
545
		InxImg					= 6
546
		InxImgOff				= 7
547
		InxHint					= 8
548
		InxVisible				= 9
549
		InxActive				= 10
550
 
5836 dpurdie 551
        Call GenerateData
552
 
13 rsolanki 553
	End Sub
554
	'-----------------------------------------------------------------------------------------------------------------
555
	Private Sub Class_Terminate()
556
		'// Perform action on object disposal. e.g. Set myObj = Nothing
557
		Set mobjNameDefMap = Nothing
558
		Set mobjIdDefMap = Nothing
559
		Set mobjSeparator = Nothing
560
 
561
 
562
	End Sub
563
	'-----------------------------------------------------------------------------------------------------------------
564
End Class
565
%>