Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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