<% '============================================================= '// '// Action Button Control '// '// version: 1.2 '// last modified: 11-Aug-2004 14:08 by Sasha Vukovic '============================================================= %> <% '--------------- Global Constants ---------------- Const enumABTNCTRL_ON_READONLY_HIDE = 1 Const enumABTNCTRL_ON_READONLY_DISABLE = 2 '------------------------------------------------- Class ActionButtonControl Private mArrAbtnDef() Private mobjNameDefMap ' Item can be accesed by name. Must be unique within one page Private mobjIdDefMap ' Item can be accesed by id. Must be unique within one page. If NULL, ubound is assigned to it Private mobjSeparator ' Has a name of item after separator is applied Private mnButtonSpacer Private mnButtonTextSpace Private mNumOfProperties Private mLastPropertyInx Private mbDisableAll Private mbIsReadonly Private mReadonlyActionBehaviour Private InxID Private InxName Private InxTxt Private InxLink Private InxEventHandler Private InxImg Private InxImgOff Private InxHint Private InxVisible Private InxActive Private InxIsReadonlyAction Public Property Let AllActive ( cActive ) If cActive = enumDB_NO Then mbDisableAll = TRUE Else mbDisableAll = FALSE End If End Property Public Property Let ButtonSpacer ( nWidth ) mnButtonSpacer = nWidth End Property Public Property Let ButtonTextSpacer ( nWidth ) mnButtonTextSpace = nWidth End Property Public Property Let IsReadonlyAction ( IsReadonly ) If IsReadonly = enumDB_YES Then mbIsReadonly = TRUE ElseIf IsReadonly = enumDB_NO Then mbIsReadonly = FALSE Else mbIsReadonly = IsReadonly End If End Property Public Property Let ReadonlyActionBehaviour ( nEnum ) mReadonlyActionBehaviour = nEnum End Property '----------------------------------------------------------------------------------------------------------------- Private Sub SetItemPropertyByIndex ( nInx, nProperty, Value ) If nInx = "" OR nProperty = "" OR Value = "" Then Err.Raise 8, "Method SetItemPropertyByIndex", "Empty parameters found. nInx="& nInx &", nProperty="& nProperty &", Value="& Value mArrAbtnDef ( nProperty, nInx ) = Value 'Response.write "mArrAbtnDef ( "& nProperty &", "& nInx &" ) = "& Value &"
" End Sub '----------------------------------------------------------------------------------------------------------------- Private Function LastItemInx () LastItemInx = UBound ( mArrAbtnDef, 2 ) End Function '----------------------------------------------------------------------------------------------------------------- Public Sub AddActionButton ( sItemName, nItemID ) Dim newArrayDim If InStr( sItemName, " " ) > 0 Then Err.Raise 8, "Method AddActionButton", "Item Name '"& sItemName &"' cannot have spaces." If NOT mobjNameDefMap.Exists (CStr( sItemName )) Then newArrayDim = LastItemInx() + 1 ReDim Preserve mArrAbtnDef( mNumOfProperties, newArrayDim ) ' Store name Call SetItemPropertyByIndex ( newArrayDim, InxName, sItemName ) mobjNameDefMap.Add Cstr( sItemName ), CStr( newArrayDim ) If Not IsNull(nItemID) Then ' Store ID Call SetItemPropertyByIndex ( newArrayDim, InxdbID, nItemID ) mobjIdDefMap.Add Cstr( nItemID ), CStr( newArrayDim ) End If ' Set Defaults Call SetItemDefaults ( sItemName ) Else Err.Raise 8, "Method AddActionButton", "Item Name '"& sItemName &"' has been already defined." End If End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub Render ( aAbtnList ) Dim itemInx, itemName, nLastItemInx, btnImage, ButtonStr, ButtonStrDisabled Response.write "" For Each itemName in aAbtnList itemInx = mobjNameDefMap.Item (Cstr(itemName)) 'If itemInx = "" Then Err.Raise 8, "Method Render", "Definition for item name '"& itemName &"' not found." '-- Define Image btnImage = "" If (mArrAbtnDef( InxImg, itemInx ) <> "") Then btnImage = "" End If '-- Define Button ButtonStr = _ "" '-- Define Disabled Button ButtonStrDisabled = _ "" If mArrAbtnDef( InxVisible, itemInx ) = enumDB_YES Then ' --- Display if Visible --- If ( mbDisableAll OR ( mArrAbtnDef( InxActive, itemInx ) = enumDB_NO ) ) AND ( itemInx <> "" ) Then ' --- Display DISABLED Button Item --- Response.write ButtonStrDisabled If mnButtonSpacer > 0 Then Response.write "" End If Else ' --- Display Action Button Item --- If ( NOT mbIsReadonly ) OR _ ( mbIsReadonly AND mArrAbtnDef( InxIsReadonlyAction, itemInx ) = enumDB_YES ) Then If InStr( itemName, "width=" ) > 0 Then Response.write "" ElseIf InStr( itemName, "height=" ) > 0 Then Response.write "" Else '/* It is a button, i.e. Display Button */ Response.write ButtonStr If mnButtonSpacer > 0 Then Response.write "" End If End If ElseIf ( mbIsReadonly AND mArrAbtnDef( InxIsReadonlyAction, itemInx ) = enumDB_NO ) Then If mReadonlyActionBehaviour = enumABTNCTRL_ON_READONLY_DISABLE Then Response.write ButtonStrDisabled End If End If End If End If ' --- Separators added manually using method AddSeparator or AddSeparatorAfter --- If mobjSeparator.Exists ( Cstr(mArrAbtnDef( InxName, itemInx )) ) Then Response.write "" End If Next Response.write "
"&_ ""&_ btnImage & mArrAbtnDef( InxTxt, itemInx ) &""&_ ""&_ ""&_ ""&_ "
" End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub LoadActionButtons ( aAbtnList, ByRef objOraDatabase ) Dim rsQry, query query = _ " SELECT "&_ " abd.abtn_id,"&_ " abd.abtn_name,"&_ " abd.text,"&_ " abd.action_link,"&_ " abd.event_handler,"&_ " abd.img_enabled,"&_ " abd.img_disabled,"&_ " abd.hint,"&_ " abd.visible,"&_ " abd.active,"&_ " abd.is_readonly_action "&_ " FROM DEF_ACTION_BUTTONS abd WHERE abd.abtn_name IN ('"& Join ( aAbtnList, "','") &"')" Set rsQry = OraDatabase.DbCreateDynaset( query , ORADYN_DEFAULT ) If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then Call LoadButtons ( rsQry.GetRows() ) End If rsQry.Close Set rsQry = Nothing End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub LoadButtons ( aRows ) Dim nProperty, newArrayDim, LastRow, rowNum LastRow = UBound( aRows, 2 ) For rowNum = 0 To LastRow ' Increase array by 1 newArrayDim = LastRowInx() + 1 ReDim Preserve mArrAbtnDef( mNumOfProperties, newArrayDim ) mobjNameDefMap.Item ( Cstr( aRows ( InxName, rowNum ) ) ) = newArrayDim For nProperty = 0 To mLastPropertyInx mArrAbtnDef ( nProperty, newArrayDim ) = aRows ( nProperty, rowNum ) Next Next End Sub '----------------------------------------------------------------------------------------------------------------- Private Function LastRowInx () LastRowInx = UBound ( mArrAbtnDef, 2 ) End Function '----------------------------------------------------------------------------------------------------------------- Public Sub AddSeparatorAfter ( sItemName, sSeparatorWidth ) If InStr( sItemName, " " ) > 0 Then Err.Raise 8, "Method AddSeparatorAfter", "Item Name '"& sItemName &"' cannot have spaces." mobjSeparator.Add (Cstr(sItemName)), CStr(sSeparatorWidth) End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub AddSeparator ( sSeparatorWidth ) mobjSeparator.Add ( Cstr(mArrAbtnDef(InxName, LastItemInx())) ), CStr(sSeparatorWidth) End Sub '----------------------------------------------------------------------------------------------------------------- Private Sub SetItemDefaults ( sItemName ) ' Additional default setup Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, enumDB_YES ) ' Default Active = enumDB_YES End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub Text ( sItemName, Value ) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxTxt, Value ) End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub ItemID ( sItemName, Value ) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxID, Value ) End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub Image ( sItemName, Value ) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImg, Value ) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImgOff, Value ) ' Default image disable to be the same as image End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub ImageOff ( sItemName, Value ) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxImgOff, Value ) End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub Link ( sItemName, Value ) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxLink, Value ) End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub EventHandler ( sItemName, Value ) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxEventHandler, Value ) End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub Hint ( sItemName, Value ) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxHint, Value ) End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub Visible ( sItemName, Value ) 'Response.write sItemName &"here"& mobjNameDefMap.Item (Cstr(sItemName)) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxVisible, Value ) End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub Active ( sItemName, Value ) 'Response.write sItemName &"here"& mobjNameDefMap.Item (Cstr(sItemName)) Call SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, Value ) End Sub '----------------------------------------------------------------------------------------------------------------- Private Sub Class_Initialize() '// Perform action on creation of object. e.g. Set myObj = New ThisClassName Set mobjNameDefMap = CreateObject("Scripting.Dictionary") Set mobjIdDefMap = CreateObject("Scripting.Dictionary") Set mobjSeparator = CreateObject("Scripting.Dictionary") 'mbIsReadonly = FALSE ' Tell control that it should use only readonly action buttons (i.e. actions which will not alter database ) mReadonlyActionBehaviour = enumABTNCTRL_ON_READONLY_HIDE ' Tell control what to do by default if mbIsReadonly = TRUE mnButtonSpacer = 0 mnButtonTextSpace = 4 mNumOfProperties = 11 ' Number of properties in array which define one menu item. mLastPropertyInx = mNumOfProperties - 1 mbDisableAll = FALSE ReDim mArrAbtnDef ( mNumOfProperties, -1 ) InxID = 0 InxName = 1 InxTxt = 2 InxLink = 3 InxEventHandler = 4 InxImg = 5 InxImgOff = 6 InxHint = 7 InxVisible = 8 InxActive = 9 InxIsReadonlyAction = 10 End Sub '----------------------------------------------------------------------------------------------------------------- Private Sub Class_Terminate() '// Perform action on object disposal. e.g. Set myObj = Nothing Set mobjNameDefMap = Nothing Set mobjIdDefMap = Nothing Set mobjSeparator = Nothing End Sub '----------------------------------------------------------------------------------------------------------------- End Class %>