Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
64 jtweddle 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
 
46
	Public Property Let AllVisible ( cVal )
47
		If cVal = enumDB_YES Then
48
			mbHideAll = FALSE
49
		Else
50
			mbHideAll = TRUE
51
		End If
52
 
53
	End Property
54
 
55
	Public Property Let AllActive ( cVal )
56
		If cVal = enumDB_YES Then
57
			mbDisableAll = FALSE
58
		Else
59
			mbDisableAll = TRUE
60
		End If
61
 
62
	End Property
63
 
64
 
65
	'-----------------------------------------------------------------------------------------------------------------
66
	Public Sub PopupMenuStyle( sTemplateDoc, sStyleId ) 
67
		Dim mobjTemplateManager
68
 
69
		Set mobjTemplateManager = New TemplateManager
70
		mobjTemplateManager.TemplateDoc = sTemplateDoc
71
 
72
		' Set Templates
73
		mPreCodeTemplate	= mobjTemplateManager.getElementValue ( sStyleId &"/PreMenuCode" )
74
		mMenuItemTemplate	= mobjTemplateManager.getElementValue ( sStyleId &"/MenuItem" )
75
		mSeparatorTemplate	= mobjTemplateManager.getElementValue ( sStyleId &"/Separator" )
76
		mPostCodeTemplate	= mobjTemplateManager.getElementValue ( sStyleId &"/PostMenuCode" )
77
 
78
		Set mobjTemplateManager = Nothing
79
	End Sub
80
	'-----------------------------------------------------------------------------------------------------------------
81
	Private Sub SetItemPropertyByIndex ( nInx, nProperty, Value )
82
		If nInx = ""  OR  nProperty = ""  OR  Value = "" Then Err.Raise 8, "Method SetItemPropertyByIndex", "Empty parameters found. nInx="& nInx &", nProperty="& nProperty &", Value="& Value 
83
 
84
		mArrPopupMenuDef ( nProperty, nInx ) = Value
85
 
86
		'Response.write "mArrPopupMenuDef ( "& nProperty &", "& nInx &" ) = "& Value &"<br>"
87
	End Sub
88
	'-----------------------------------------------------------------------------------------------------------------
89
	Private Function LastItemInx ()
90
		 LastItemInx = UBound ( mArrPopupMenuDef, 2 )
91
	End Function
92
	'-----------------------------------------------------------------------------------------------------------------
93
	Public Sub LoadRows ( aRows )
94
		' Pass the full array row matching the columns of mArrPopupMenuDef()
95
		Dim nProperty, newArrayDim, numOfRows, rowNum
96
 
97
		numOfRows = UBound( aRows, 2 )
98
 
99
 
100
		For rowNum = 0 To numOfRows
101
			' Increase array by 1
102
			newArrayDim = LastItemInx() + 1
103
			ReDim Preserve mArrPopupMenuDef( mNumOfItemProperties, newArrayDim )
104
 
105
			mobjNameDefMap.Add ( Cstr( aRows ( InxdbName, rowNum ) ) ), CStr( newArrayDim )
106
 
107
			For nProperty = 0 To mLastItemPropertyInx
108
				If (nProperty = InxLink) OR (nProperty = InxEventHandler) Then
109
					' Link And EventHandlers need to be evaluated
110
					mArrPopupMenuDef ( nProperty, newArrayDim ) = Eval ( aRows ( nProperty, rowNum ) )
111
				Else
112
					mArrPopupMenuDef ( nProperty, newArrayDim ) = aRows ( nProperty, rowNum )
113
				End If
114
			Next
115
		Next
116
 
117
	End Sub
118
	'-----------------------------------------------------------------------------------------------------------------
119
	Public Sub AddMenuItem ( sItemName, nItemID )
120
		Dim newArrayDim
121
 
122
		If InStr( sItemName, " " ) > 0 Then	Err.Raise 8, "Method AddMenuItem", "Item Name '"& sItemName &"' cannot have spaces."
123
 
124
 
125
 
126
		If NOT mobjNameDefMap.Exists (CStr( sItemName )) Then
127
 
128
			newArrayDim = LastItemInx() + 1
129
 
130
			ReDim Preserve mArrPopupMenuDef( mNumOfItemProperties, newArrayDim )
131
 
132
			' Store name
133
			Call SetItemPropertyByIndex ( newArrayDim, InxdbName, sItemName )
134
 
135
			mobjNameDefMap.Add ( Cstr( sItemName ) ), CStr( newArrayDim )
136
 
137
			If Not IsNull(nItemID) Then
138
				' If ID is supplied, map it to array index
139
				mobjIdDefMap.Add Cstr( nItemID ), CStr( newArrayDim )
140
 
141
				' Store ID
142
				Call SetItemPropertyByIndex ( newArrayDim, InxdbAccessManagerObjID, nItemID )
143
 
144
			Else
145
				' else use array index as ID
146
				mobjIdDefMap.Add Cstr( newArrayDim ), CStr( newArrayDim )
147
 
148
				' Store array index as ID
149
				Call SetItemPropertyByIndex ( newArrayDim, InxdbAccessManagerObjID, newArrayDim )
150
 
151
			End If
152
 
153
			' Set Defaults
154
			'Call SetItemDefaults ( sItemName )
155
		Else
156
			'TODO
157
 
158
		End If
159
 
160
	End Sub
161
	'-----------------------------------------------------------------------------------------------------------------
162
	Private Sub RenderItem ( itemIndex, bIsActiveByAccessControl )
163
		Dim sMenuItem
164
		sMenuItem  	 = mMenuItemTemplate								' Get menu item template
165
 
166
		' --- Menu Item ---
167
		' Check Active state
168
		If bIsActiveByAccessControl AND mArrPopupMenuDef( InxActive, itemIndex ) <> enumDB_NO Then			' Check if menu item is Active
169
 
170
			sMenuItem = Replace ( sMenuItem, "%TEXT%", "<a href='"& ( mArrPopupMenuDef( InxLink, itemIndex ) ) &"' "&_
171
													   " "& ( mArrPopupMenuDef( InxEventHandler, itemIndex ) ) &" class='menu_link' title='"& mArrPopupMenuDef( InxHint, itemIndex ) &"'>"& mArrPopupMenuDef( InxTxt, itemIndex ) &"</a>" )
172
 
173
			If NOT IsNull(mArrPopupMenuDef( InxImg, itemIndex )) AND (mArrPopupMenuDef( InxImg, itemIndex ) <> "") Then 
174
				sMenuItem = Replace ( sMenuItem, "%IMAGE%", "<img src='"& mArrPopupMenuDef( InxImg, itemIndex ) &"'>" )
175
			Else
176
				' No image supplied
177
				sMenuItem = Replace ( sMenuItem, "%IMAGE%", "<img src='images/spacer.gif' height='19'>" )
178
			End If
179
 
180
 
181
		Else
182
 
183
 
184
			' Render DISABLE menu item
185
			sMenuItem = Replace ( sMenuItem, "%TEXT%", mArrPopupMenuDef( InxTxt, itemIndex ) )
186
 
187
			If NOT IsNull(mArrPopupMenuDef( InxImgOff, itemIndex )) AND (mArrPopupMenuDef( InxImgOff, itemIndex ) <> "") Then 
188
				sMenuItem = Replace ( sMenuItem, "%IMAGE%", "<img src='"& mArrPopupMenuDef( InxImgOff, itemIndex ) &"' title='"& mArrPopupMenuDef( InxHint, itemIndex ) &"'>" )
189
			Else
190
				' No image supplied
191
				sMenuItem = Replace ( sMenuItem, "%IMAGE%", Empty )
192
			End If
193
 
194
 
195
		End If
196
		Response.write sMenuItem		' Finally render Menu Item
197
 
198
	End Sub
199
	'-----------------------------------------------------------------------------------------------------------------
200
	Public Sub RenderInOrder ( sDivName, aItemsList, oAccessControl, cObjectName )
201
		Dim itemInx, itemName, nLastItemInx, bIsVisible, bIsActive
202
 
203
		Response.write "<DIV id='"& sDivName &"' name='"& sDivName &"' style='display:none;'>"
204
		Response.write mPreCodeTemplate
205
 
206
		For Each itemName in aItemsList
207
			itemInx = mobjNameDefMap.Item (Cstr(itemName))
208
			'If itemInx = "" Then 	Err.Raise 8, "Method Render", "Definition for item name '"& itemName &"' not found."
209
 
210
			'===== Access Control =====
211
			If IsObject(oAccessControl) Then
212
				' Access Control takes priority
213
				bIsVisible = oAccessControl.IsDataVisible ( mArrPopupMenuDef( InxItemTableName, itemInx ), mArrPopupMenuDef( InxdbAccessManagerObjID, itemInx ), cObjectName )
214
				bIsActive = oAccessControl.IsDataActive ( mArrPopupMenuDef( InxItemTableName, itemInx ), mArrPopupMenuDef( InxdbAccessManagerObjID, itemInx ), cObjectName )
215
			Else
216
				' set Visible
217
				If mArrPopupMenuDef( InxVisible, itemInx ) = enumDB_YES Then
218
					bIsVisible = TRUE
219
				Else
220
					bIsVisible = FALSE
221
				End If
222
 
223
				' set Active
224
				If NOT mbDisableAll AND (mArrPopupMenuDef( InxActive, itemInx ) = enumDB_YES) Then
225
					bIsActive = TRUE
226
				Else
227
					bIsActive = FALSE
228
				End If
229
 
230
			End If
231
			'=========================
232
 
233
 
234
			If itemName = enumSEPARATOR_LABEL AND bIsVisible Then
235
				Response.write mSeparatorTemplate
236
			Else
237
 
238
				'TODO
239
				If bIsVisible Then
240
					Call RenderItem ( itemInx, bIsActive )
241
				End If
242
 
243
			End If
244
 
245
 
246
			' --- Separators added manually using  method AddSeparator or AddSeparatorAfter ---
247
			If mobjSeparator.Exists ( Cstr(mArrPopupMenuDef( InxdbName, itemInx )) ) AND bIsVisible Then
248
				Response.write mSeparatorTemplate
249
 
250
			End If
251
 
252
		Next
253
 
254
		Response.write mPostCodeTemplate
255
		Response.write "</DIV>"
256
	End Sub
257
	'-----------------------------------------------------------------------------------------------------------------
258
	Public Sub Render ( sDivName )
259
		Dim item, nLastItemInx, sMenuItem
260
		' --- Check if GLOBAL Visible
261
		If NOT mbHideAll Then
262
 
263
			Response.write "<DIV id='"& sDivName &"' name='"& sDivName &"' style='display:none;'>"
264
			Response.write mPreCodeTemplate
265
 
266
			nLastItemInx = LastItemInx()
267
 
268
 
269
			For item = 0 To nLastItemInx
270
 
271
				' --- Check if GLOBAL Active
272
				'If mArrPopupMenuDef( InxdbName, item ) Then
273
					Call RenderItem ( item, TRUE )	' TODO
274
 
275
					' --- Separator ---
276
					If mobjSeparator.Exists ( Cstr(mArrPopupMenuDef( InxdbName, item )) ) Then
277
						Response.write mSeparatorTemplate
278
					End If
279
				'End If
280
 
281
 
282
			Next
283
 
284
			Response.write mPostCodeTemplate
285
			Response.write "</DIV>"
286
 
287
		End If
288
	End Sub
289
	'-----------------------------------------------------------------------------------------------------------------
290
	Public Sub AddSeparatorAfter ( sItemName )
291
		If InStr( sItemName, " " ) > 0 Then	Err.Raise 8, "Method AddSeparatorAfter", "Item Name '"& sItemName &"' cannot have spaces."
292
		mobjSeparator.Add (Cstr(sItemName)), ""
293
	End Sub
294
	'-----------------------------------------------------------------------------------------------------------------
295
	Public Sub AddSeparator ()
296
		mobjSeparator.Add ( Cstr(mArrPopupMenuDef(InxdbName, LastItemInx())) ), ""
297
	End Sub
298
	'-----------------------------------------------------------------------------------------------------------------
299
	'Private Sub SetItemDefaults ( sItemName )
300
	'	' Additional default setup
301
	'	'Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, enumDB_YES )		' Default Active = enumDB_YES
302
	'	'Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxVisible, enumDB_YES )		' Default Active = enumDB_YES
303
	'End Sub
304
	'-----------------------------------------------------------------------------------------------------------------
305
	Public Sub Text ( sItemName, Value )
306
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxTxt, Value )
307
	End Sub
308
	'-----------------------------------------------------------------------------------------------------------------
309
	Public Sub Image ( sItemName, Value )
310
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImg, Value )
311
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImgOff, Value )			' Default image disable to be the same as image
312
	End Sub
313
	'-----------------------------------------------------------------------------------------------------------------
314
	Public Sub ImageOff ( sItemName, Value )
315
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImgOff, Value )
316
	End Sub
317
	'-----------------------------------------------------------------------------------------------------------------
318
	Public Sub Link ( sItemName, Value )
319
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxLink, Value )
320
	End Sub
321
	'-----------------------------------------------------------------------------------------------------------------
322
	Public Sub EventHandler ( sItemName, Value )
323
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxEventHandler, Value )
324
	End Sub
325
	'-----------------------------------------------------------------------------------------------------------------
326
	Public Sub Hint ( sItemName, Value )
327
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxHint, Value )
328
	End Sub
329
	'-----------------------------------------------------------------------------------------------------------------
330
	Public Sub Active ( sItemName, Value )
331
		' Y = enabled, N = disabled
332
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, Value )
333
	End Sub
334
	'-----------------------------------------------------------------------------------------------------------------
335
	Public Sub Visible ( sItemName, Value )
336
		' Y = show, N = hide
337
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxVisible, Value )
338
	End Sub
339
	'-----------------------------------------------------------------------------------------------------------------
340
	Private Sub Class_Initialize()
341
		'// Perform action on creation of object. e.g. Set myObj = New ThisClassName
342
		Set mobjNameDefMap = CreateObject("Scripting.Dictionary")
343
		Set mobjIdDefMap = CreateObject("Scripting.Dictionary")
344
		Set mobjSeparator = CreateObject("Scripting.Dictionary")
345
 
346
 
347
		mNumOfItemProperties = 11  	' Number of properties in array which define one menu item.
348
		mLastItemPropertyInx = mNumOfItemProperties - 1
349
 
350
		mbHideAll = FALSE
351
		mbDisableAll = FALSE
352
 
353
		ReDim mArrPopupMenuDef ( mNumOfItemProperties, -1 )
354
 
355
		InxItemTableName		= 0
356
		InxdbAccessManagerObjID	= 1
357
		InxdbName				= 2
358
		InxTxt					= 3
359
		InxLink					= 4
360
		InxEventHandler			= 5
361
		InxImg					= 6
362
		InxImgOff				= 7
363
		InxHint					= 8
364
		InxVisible				= 9
365
		InxActive				= 10
366
 
367
 
368
	End Sub
369
	'-----------------------------------------------------------------------------------------------------------------
370
	Private Sub Class_Terminate()
371
		'// Perform action on object disposal. e.g. Set myObj = Nothing
372
		Set mobjNameDefMap = Nothing
373
		Set mobjIdDefMap = Nothing
374
		Set mobjSeparator = Nothing
375
 
376
 
377
	End Sub
378
	'-----------------------------------------------------------------------------------------------------------------
379
End Class
380
%>