Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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