Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 1
<%
2
'=============================================================
3
'//
4
'//						Action Button Control
5
'//
6
'// version: 		2.0
7
'//	last modified: 	27-Jun-2005 10:49 by Sasha Vukovic
8
'=============================================================
9
%>
10
<%
11
'--------------- Global Constants ----------------
12
Const enumABTNCTRL_ON_READONLY_HIDE = 1
13
Const enumABTNCTRL_ON_READONLY_DISABLE = 2
14
'-------------------------------------------------
15
 
16
Class ActionButtonControl
17
 
18
	Private mArrAbtnDef()
19
	Private mobjNameDefMap			' Item can be accesed by name. Must be unique within one page
20
	Private mobjIdDefMap			' Item can be accesed by id. Must be unique within one page. If NULL, ubound is assigned to it
21
	Private mobjSeparator			' Has a name of item after separator is applied
22
	Private mobjACActionsMap		' Map of buttons to actions from access control
23
 
24
	Private mnButtonSpacer
25
	Private mnImageHspace
26
 
27
	Private mNumOfProperties
28
	Private mLastPropertyInx
29
 
30
	Private mbDisableAll
31
 
32
	Private mbIsReadonly
33
	Private mReadonlyActionBehaviour
34
 
35
	Private InxID
36
	Private InxName
37
	Private InxTxt
38
	Private InxLink
39
	Private InxEventHandler
40
	Private InxImg
41
	Private InxImgOff
42
	Private InxHint
43
	Private InxVisible
44
	Private InxActive
45
	Private InxIsReadonlyAction
46
 
47
 
48
 
49
 
50
	Public Property Let AllActive ( cActive )
51
		If cActive = enumDB_NO Then
52
			mbDisableAll = TRUE
53
		Else
54
			mbDisableAll = FALSE
55
		End If
56
 
57
	End Property
58
 
59
	Public Property Let ButtonSpacer ( nWidth )
60
		mnButtonSpacer = nWidth
61
	End Property
62
 
63
	Public Property Let ImageHspace ( nWidth )
64
		mnImageHspace = nWidth
65
	End Property
66
 
67
	Public Property Let IsReadonlyAction ( IsReadonly )
68
		If IsReadonly = enumDB_YES Then
69
			mbIsReadonly = TRUE
70
 
71
		ElseIf IsReadonly = enumDB_NO Then
72
			mbIsReadonly = FALSE
73
		Else
74
			mbIsReadonly = IsReadonly
75
 
76
		End If
77
 
78
	End Property
79
 
80
	Public Property Let ReadonlyActionBehaviour ( nEnum )
81
		mReadonlyActionBehaviour = nEnum
82
	End Property
83
 
84
	'-----------------------------------------------------------------------------------------------------------------
85
	Public Sub SetRelationship ( sButtonName, sActionName )
86
		Call mobjACActionsMap.Add ( sButtonName, sActionName )
87
	End Sub
88
	'-----------------------------------------------------------------------------------------------------------------
89
	Private Sub SetItemPropertyByIndex ( nInx, nProperty, Value )
90
		If nInx = "" Then Exit Sub	' Exit sub if you don't find defined button
91
 
92
		If nProperty = ""  OR  Value = "" Then Err.Raise 8, "Method SetItemPropertyByIndex", "Empty parameters found. nInx="& nInx &", nProperty="& nProperty &", Value="& Value 
93
 
94
		mArrAbtnDef ( nProperty, nInx ) = Value
95
 
96
		'Response.write "mArrAbtnDef ( "& nProperty &", "& nInx &" ) = "& Value &"<br>"
97
	End Sub
98
	'-----------------------------------------------------------------------------------------------------------------
99
	Private Function LastItemInx ()
100
		 LastItemInx = UBound ( mArrAbtnDef, 2 )
101
	End Function
102
	'-----------------------------------------------------------------------------------------------------------------
103
	Public Sub AddActionButton ( sItemName, nItemID )
104
		Dim newArrayDim
105
 
106
		If InStr( sItemName, " " ) > 0 Then	Err.Raise 8, "Method AddActionButton", "Item Name '"& sItemName &"' cannot have spaces."
107
 
108
 
109
 
110
		If NOT mobjNameDefMap.Exists (CStr( sItemName )) Then
111
 
112
			newArrayDim = LastItemInx() + 1
113
 
114
			ReDim Preserve mArrAbtnDef( mNumOfProperties, newArrayDim )
115
 
116
			' Store name
117
			Call SetItemPropertyByIndex ( newArrayDim, InxName, sItemName )
118
			mobjNameDefMap.Add Cstr( sItemName ), CStr( newArrayDim )
119
 
120
			If Not IsNull(nItemID) Then
121
				' Store ID
122
				Call SetItemPropertyByIndex ( newArrayDim, InxdbID, nItemID )
123
				mobjIdDefMap.Add Cstr( nItemID ), CStr( newArrayDim )
124
			End If
125
 
126
			' Set Defaults
127
			Call SetItemDefaults ( sItemName )
128
		Else
129
 
130
			Err.Raise 8, "Method AddActionButton", "Item Name '"& sItemName &"' has been already defined."
131
 
132
		End If
133
 
134
	End Sub
135
	'-----------------------------------------------------------------------------------------------------------------
136
	Public Sub Render ( aAbtnList, ByRef oAccessControl )
137
		Dim itemInx, itemName, nLastItemInx, btnImage, ButtonStr, ButtonStrDisabled, bIsVisibleAC, bIsActiveAC
138
		Response.write "<table cellpadding='0' cellspacing='0' width='1'><tr>"
139
 
140
		For Each itemName in aAbtnList
141
 
142
			itemInx = mobjNameDefMap.Item (Cstr(itemName))
143
 
144
 
145
			'-- Define Image
146
			btnImage = "<img src='images/spacer.gif' width='"& mnButtonSpacer &"' height='1' align='absmiddle' border='0'>"
147
			If (mArrAbtnDef( InxImg, itemInx ) <> "") Then
148
				btnImage = "<img src='"& mArrAbtnDef( InxImg, itemInx ) &"' hspace='"& mnImageHspace &"' border='0' align='absmiddle'>"
149
			End If
150
 
151
 
152
			'-- Define Button
153
			ButtonStr = _
154
				"<td nowrap>"&_
155
				"<a id='"& mArrAbtnDef( InxName, itemInx ) &"' "&_
156
				" name='"& mArrAbtnDef( InxName, itemInx ) &"' href='"& Eval( mArrAbtnDef( InxLink, itemInx ) ) &"' "&_
157
				" "& Eval( mArrAbtnDef( InxEventHandler, itemInx ) ) &" class='menu_link' title='"& mArrAbtnDef( InxHint, itemInx )  &"'>"&_
158
				btnImage & mArrAbtnDef( InxTxt, itemInx ) &"</a>"&_
159
				"</td>"
160
 
161
 
162
			'-- Define Disabled Button
163
			ButtonStrDisabled = _
164
				"<td nowrap>"&_
165
				"<img src='"& mArrAbtnDef( InxImgOff, itemInx ) &"' hspace='"& mnImageHspace &"' border='0' align='absmiddle'>"&_
166
				"<label class='menu_txt'>"& mArrAbtnDef( InxTxt, itemInx ) &"</label>"&_
167
				"</td>"
168
 
169
 
170
			'Response.write "HERE("&itemName & mArrAbtnDef( InxVisible, itemInx ) &")"
171
 
172
 
173
			'-- Get Access Control permissions --
174
			bIsVisibleAC = TRUE
175
			bIsActiveAC = TRUE
176
			If NOT IsNull( oAccessControl ) Then
177
				' Access control object is supplied
178
 
179
				If mobjACActionsMap.Exists ( itemName ) Then
180
					' Relationship supplied
181
					bIsVisibleAC = oAccessControl.IsVisible ( mobjACActionsMap.Item( itemName ) )
182
					bIsActiveAC = oAccessControl.IsActive ( mobjACActionsMap.Item( itemName ) )
183
					'Response.write itemName &":"& oAccessControl.IsVisible ( mobjACActionsMap.Item( itemName ) ) &"-"& oAccessControl.IsActive ( mobjACActionsMap.Item( itemName ) )
184
				End If
185
 
186
			End If
187
 
188
 
189
			If (  ( mArrAbtnDef( InxVisible, itemInx ) = enumDB_YES)   AND   bIsVisibleAC   ) _
190
			   OR  (InStr( itemName, "width=" ) > 0)  _
191
			   OR  (InStr( itemName, "height=" ) > 0) Then
192
 
193
				' --- Display if Visible ---
194
 
195
				'AND  (NOT bIsActiveAC)
196
				'( mbDisableAll OR (  mArrAbtnDef( InxActive, itemInx ) = enumDB_NO )     )   AND ( itemInx <> "" )
197
				'Response.write itemName &":"& mbDisableAll &"-"& Eval( mArrAbtnDef( InxActive, itemInx ) = enumDB_NO ) &"-"& Eval( NOT bIsActiveAC ) &"-"& itemInx &"<br>"
198
				If  ( itemInx <> "" ) AND _
199
					( mbDisableAll  OR _
200
						(  ( mArrAbtnDef( InxActive, itemInx ) = enumDB_NO )  OR  (NOT bIsActiveAC)  ) _
201
					) _
202
				Then
203
 
204
					' --- Display DISABLED Button Item ---
205
					Response.write ButtonStrDisabled
206
 
207
					If mnButtonSpacer > 0 Then
208
						Response.write "<td><img src='images/spacer.gif' width='"& mnButtonSpacer &"' height='1' align='absmiddle'></td>"
209
					End If
210
 
211
 
212
				Else
213
 
214
					' --- Display Action Button Item ---
215
					If	( NOT mbIsReadonly )  OR _
216
					   	( mbIsReadonly  AND  mArrAbtnDef( InxIsReadonlyAction, itemInx ) = enumDB_YES ) Then
217
 
218
						If InStr( itemName, "width=" ) > 0 Then
219
 
220
							Response.write "<td><img src='images/spacer.gif' "& itemName &" height='1' align='absmiddle'></td>"
221
 
222
						ElseIf InStr( itemName, "height=" ) > 0 Then
223
							Response.write "<td><img src='images/bg_bage_2.gif' width='1' "& itemName &" align='absmiddle' hspace='4'></td>"
224
 
225
						Else
226
							'/* It is a button, i.e. Display Button */
227
 
228
							' Check if button is loaded from Database
229
							If itemInx = "" Then 	Err.Raise 8, "Method Render", "Definition for item name '"& itemName &"' not found."
230
 
231
							Response.write ButtonStr
232
 
233
							If mnButtonSpacer > 0 Then
234
								Response.write "<td><img src='images/spacer.gif' width='"& mnButtonSpacer &"' height='1' align='absmiddle'></td>"
235
							End If
236
 
237
						End If
238
 
239
 
240
					ElseIf ( mbIsReadonly  AND  mArrAbtnDef( InxIsReadonlyAction, itemInx ) = enumDB_NO ) Then
241
 
242
						If mReadonlyActionBehaviour = enumABTNCTRL_ON_READONLY_DISABLE Then
243
							Response.write ButtonStrDisabled
244
						End If
245
 
246
 
247
					End If
248
 
249
				End If
250
 
251
			End If
252
 
253
 
254
 
255
 
256
			' --- Separators added manually using  method AddSeparator or AddSeparatorAfter ---
257
			If mobjSeparator.Exists ( Cstr(mArrAbtnDef( InxName, itemInx )) ) Then
258
				Response.write "<td><img src='images/spacer.gif' width='"& mobjSeparator.Item ( Cstr(mArrAbtnDef( InxName, itemInx )) ) &"' height='1'></td>"
259
 
260
			End If
261
 
262
 
263
		Next
264
 
265
		Response.write "</tr></table>"
266
	End Sub
267
	'-----------------------------------------------------------------------------------------------------------------
268
	Public Sub LoadActionButtons ( aAbtnList, ByRef objOraDatabase )
269
		Dim rsQry, query
270
 
271
		query = _
272
		" SELECT "&_
273
		"        abd.abtn_id,"&_
274
		"        abd.abtn_name,"&_
275
		"        abd.text,"&_
276
		"        abd.action_link,"&_
277
		"        abd.event_handler,"&_
278
		"        abd.img_enabled,"&_
279
		"        abd.img_disabled,"&_
280
		"        abd.hint,"&_
281
		"        abd.visible,"&_
282
		"        abd.active,"&_
283
		"        abd.is_readonly_action "&_
284
		"   FROM DEF_ACTION_BUTTONS abd  WHERE abd.abtn_name IN ('"& Join ( aAbtnList, "','") &"')"
285
 
286
		Set rsQry = OraDatabase.DbCreateDynaset( query , ORADYN_DEFAULT )
287
 
288
		If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
289
			Call LoadButtons ( rsQry.GetRows() )
290
 
291
		End If
292
 
293
		rsQry.Close
294
		Set rsQry = Nothing
295
	End Sub
296
	'-----------------------------------------------------------------------------------------------------------------
297
	Public Sub LoadButtons ( aRows )
298
		Dim nProperty, newArrayDim, LastRow, rowNum
299
 
300
		LastRow = UBound( aRows, 2 )
301
 
302
		For rowNum = 0 To LastRow
303
			' Increase array by 1
304
			newArrayDim = LastRowInx() + 1
305
			ReDim Preserve mArrAbtnDef( mNumOfProperties, newArrayDim )
306
 
307
 
308
			mobjNameDefMap.Item ( Cstr( aRows ( InxName, rowNum ) ) ) = newArrayDim
309
 
310
			For nProperty = 0 To mLastPropertyInx
311
				mArrAbtnDef ( nProperty, newArrayDim ) = aRows ( nProperty, rowNum )
312
 
313
			Next
314
 
315
		Next
316
 
317
	End Sub
318
	'-----------------------------------------------------------------------------------------------------------------
319
	Private Function LastRowInx ()
320
		 LastRowInx = UBound ( mArrAbtnDef, 2 )
321
	End Function
322
	'-----------------------------------------------------------------------------------------------------------------
323
	Public Sub AddSeparatorAfter ( sItemName, sSeparatorWidth )
324
		If InStr( sItemName, " " ) > 0 Then	Err.Raise 8, "Method AddSeparatorAfter", "Item Name '"& sItemName &"' cannot have spaces."
325
		mobjSeparator.Add (Cstr(sItemName)), CStr(sSeparatorWidth)
326
	End Sub
327
	'-----------------------------------------------------------------------------------------------------------------
328
	Public Sub AddSeparator ( sSeparatorWidth )
329
		mobjSeparator.Add ( Cstr(mArrAbtnDef(InxName, LastItemInx())) ), CStr(sSeparatorWidth)
330
	End Sub
331
	'-----------------------------------------------------------------------------------------------------------------
332
	Private Sub SetItemDefaults ( sItemName )
333
		' Additional default setup
334
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, enumDB_YES )			' Default Active = enumDB_YES
335
	End Sub
336
	'-----------------------------------------------------------------------------------------------------------------
337
	Public Sub Text ( sItemName, Value )
338
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxTxt, Value )
339
	End Sub
340
	'-----------------------------------------------------------------------------------------------------------------
341
	Public Sub ItemID ( sItemName, Value )
342
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxID, Value )
343
	End Sub
344
	'-----------------------------------------------------------------------------------------------------------------
345
	Public Sub Image ( sItemName, Value )
346
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImg, Value )
347
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImgOff, Value )			' Default image disable to be the same as image
348
	End Sub
349
	'-----------------------------------------------------------------------------------------------------------------
350
	Public Sub ImageOff ( sItemName, Value )
351
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImgOff, Value )
352
	End Sub
353
	'-----------------------------------------------------------------------------------------------------------------
354
	Public Sub Link ( sItemName, Value )
355
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxLink, Value )
356
	End Sub
357
	'-----------------------------------------------------------------------------------------------------------------
358
	Public Sub EventHandler ( sItemName, Value )
359
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxEventHandler, Value )
360
	End Sub
361
	'-----------------------------------------------------------------------------------------------------------------
362
	Public Sub Hint ( sItemName, Value )
363
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxHint, Value )
364
	End Sub
365
	'-----------------------------------------------------------------------------------------------------------------
366
	Public Sub Visible ( sItemName, Value )
367
		'Response.write sItemName &"here"& mobjNameDefMap.Item (Cstr(sItemName))
368
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxVisible, Value )
369
	End Sub
370
	'-----------------------------------------------------------------------------------------------------------------
371
	Public Sub Active ( sItemName, Value )
372
		'Response.write sItemName &"here"& mobjNameDefMap.Item (Cstr(sItemName))
373
		Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, Value )
374
	End Sub
375
	'-----------------------------------------------------------------------------------------------------------------
376
	Private Sub Class_Initialize()
377
		'// Perform action on creation of object. e.g. Set myObj = New ThisClassName
378
		Set mobjNameDefMap = CreateObject("Scripting.Dictionary")
379
		Set mobjIdDefMap = CreateObject("Scripting.Dictionary")
380
		Set mobjSeparator = CreateObject("Scripting.Dictionary")
381
		Set mobjACActionsMap = CreateObject("Scripting.Dictionary")
382
 
383
		'mbIsReadonly = FALSE	' Tell control that it should use only readonly action buttons (i.e. actions which will not alter database )
384
		mReadonlyActionBehaviour = enumABTNCTRL_ON_READONLY_HIDE		' Tell control what to do by default if mbIsReadonly = TRUE
385
 
386
		mnButtonSpacer = 0
387
		mnImageHspace = 4
388
 
389
		mNumOfProperties = 11  	' Number of properties in array which define one menu item.
390
		mLastPropertyInx = mNumOfProperties - 1
391
 
392
		mbDisableAll = FALSE
393
 
394
		ReDim mArrAbtnDef ( mNumOfProperties, -1 )
395
		InxID					= 0
396
		InxName					= 1
397
		InxTxt					= 2
398
		InxLink					= 3
399
		InxEventHandler			= 4
400
		InxImg					= 5
401
		InxImgOff				= 6
402
		InxHint					= 7
403
		InxVisible				= 8
404
		InxActive				= 9
405
		InxIsReadonlyAction		= 10
406
 
407
	End Sub
408
	'-----------------------------------------------------------------------------------------------------------------
409
	Private Sub Class_Terminate()
410
		'// Perform action on object disposal. e.g. Set myObj = Nothing
411
		Set mobjNameDefMap = Nothing
412
		Set mobjIdDefMap = Nothing
413
		Set mobjSeparator = Nothing
414
		Set mobjACActionsMap = Nothing
415
 
416
 
417
	End Sub
418
	'-----------------------------------------------------------------------------------------------------------------
419
End Class
420
%>