Rev 64 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<%'============================================================='//'// Action Button Control'//'// version: 1.2'// last modified: 11-Aug-2004 14:08 by Sasha Vukovic'=============================================================%><%'--------------- Global Constants ----------------Const enumABTNCTRL_ON_READONLY_HIDE = 1Const enumABTNCTRL_ON_READONLY_DISABLE = 2'-------------------------------------------------Class ActionButtonControlPrivate mArrAbtnDef()Private mobjNameDefMap ' Item can be accesed by name. Must be unique within one pagePrivate mobjIdDefMap ' Item can be accesed by id. Must be unique within one page. If NULL, ubound is assigned to itPrivate mobjSeparator ' Has a name of item after separator is appliedPrivate mnButtonSpacerPrivate mnButtonTextSpacePrivate mNumOfPropertiesPrivate mLastPropertyInxPrivate mbDisableAllPrivate mbIsReadonlyPrivate mReadonlyActionBehaviourPrivate InxIDPrivate InxNamePrivate InxTxtPrivate InxLinkPrivate InxEventHandlerPrivate InxImgPrivate InxImgOffPrivate InxHintPrivate InxVisiblePrivate InxActivePrivate InxIsReadonlyActionPublic Property Let AllActive ( cActive )If cActive = enumDB_NO ThenmbDisableAll = TRUEElsembDisableAll = FALSEEnd IfEnd PropertyPublic Property Let ButtonSpacer ( nWidth )mnButtonSpacer = nWidthEnd PropertyPublic Property Let ButtonTextSpacer ( nWidth )mnButtonTextSpace = nWidthEnd PropertyPublic Property Let IsReadonlyAction ( IsReadonly )If IsReadonly = enumDB_YES ThenmbIsReadonly = TRUEElseIf IsReadonly = enumDB_NO ThenmbIsReadonly = FALSEElsembIsReadonly = IsReadonlyEnd IfEnd PropertyPublic Property Let ReadonlyActionBehaviour ( nEnum )mReadonlyActionBehaviour = nEnumEnd 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="& ValuemArrAbtnDef ( nProperty, nInx ) = Value'Response.write "mArrAbtnDef ( "& nProperty &", "& nInx &" ) = "& Value &"<br>"End Sub'-----------------------------------------------------------------------------------------------------------------Private Function LastItemInx ()LastItemInx = UBound ( mArrAbtnDef, 2 )End Function'-----------------------------------------------------------------------------------------------------------------Public Sub AddActionButton ( sItemName, nItemID )Dim newArrayDimIf InStr( sItemName, " " ) > 0 Then Err.Raise 8, "Method AddActionButton", "Item Name '"& sItemName &"' cannot have spaces."If NOT mobjNameDefMap.Exists (CStr( sItemName )) ThennewArrayDim = LastItemInx() + 1ReDim Preserve mArrAbtnDef( mNumOfProperties, newArrayDim )' Store nameCall SetItemPropertyByIndex ( newArrayDim, InxName, sItemName )mobjNameDefMap.Add Cstr( sItemName ), CStr( newArrayDim )If Not IsNull(nItemID) Then' Store IDCall SetItemPropertyByIndex ( newArrayDim, InxdbID, nItemID )mobjIdDefMap.Add Cstr( nItemID ), CStr( newArrayDim )End If' Set DefaultsCall SetItemDefaults ( sItemName )ElseErr.Raise 8, "Method AddActionButton", "Item Name '"& sItemName &"' has been already defined."End IfEnd Sub'-----------------------------------------------------------------------------------------------------------------Public Sub Render ( aAbtnList )Dim itemInx, itemName, nLastItemInx, btnImage, ButtonStr, ButtonStrDisabledResponse.write "<table cellpadding='0' cellspacing='0' width='1'><tr>"For Each itemName in aAbtnListitemInx = mobjNameDefMap.Item (Cstr(itemName))'If itemInx = "" Then Err.Raise 8, "Method Render", "Definition for item name '"& itemName &"' not found."'-- Define ImagebtnImage = "<img src='images/spacer.gif' width='"& mnButtonSpacer &"' height='1' align='absmiddle' border='0'>"If (mArrAbtnDef( InxImg, itemInx ) <> "") ThenbtnImage = "<img src='"& mArrAbtnDef( InxImg, itemInx ) &"' hspace='"& mnButtonTextSpace &"' border='0' align='absmiddle'>"End If'-- Define ButtonButtonStr = _"<td nowrap>"&_"<a id='"& mArrAbtnDef( InxName, itemInx ) &"' "&_" name='"& mArrAbtnDef( InxName, itemInx ) &"' href='"& Eval( mArrAbtnDef( InxLink, itemInx ) ) &"' "&_" "& Eval( mArrAbtnDef( InxEventHandler, itemInx ) ) &" class='menu_link' title='"& mArrAbtnDef( InxHint, itemInx ) &"'>"&_btnImage & mArrAbtnDef( InxTxt, itemInx ) &"</a>"&_"</td>"'-- Define Disabled ButtonButtonStrDisabled = _"<td nowrap>"&_"<img src='"& mArrAbtnDef( InxImgOff, itemInx ) &"' hspace='"& mnButtonTextSpace &"' border='0' align='absmiddle'>"&_"<label class='menu_txt'>"& mArrAbtnDef( InxTxt, itemInx ) &"</label>"&_"</td>"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 ButtonStrDisabledIf mnButtonSpacer > 0 ThenResponse.write "<td><img src='images/spacer.gif' width='"& mnButtonSpacer &"' height='1' align='absmiddle'></td>"End IfElse' --- Display Action Button Item ---If ( NOT mbIsReadonly ) OR _( mbIsReadonly AND mArrAbtnDef( InxIsReadonlyAction, itemInx ) = enumDB_YES ) ThenIf InStr( itemName, "width=" ) > 0 ThenResponse.write "<td><img src='images/spacer.gif' "& itemName &" height='1' align='absmiddle'></td>"ElseIf InStr( itemName, "height=" ) > 0 ThenResponse.write "<td><img src='images/bg_bage_2.gif' width='1' "& itemName &" align='absmiddle' hspace='4'></td>"Else'/* It is a button, i.e. Display Button */Response.write ButtonStrIf mnButtonSpacer > 0 ThenResponse.write "<td><img src='images/spacer.gif' width='"& mnButtonSpacer &"' height='1' align='absmiddle'></td>"End IfEnd IfElseIf ( mbIsReadonly AND mArrAbtnDef( InxIsReadonlyAction, itemInx ) = enumDB_NO ) ThenIf mReadonlyActionBehaviour = enumABTNCTRL_ON_READONLY_DISABLE ThenResponse.write ButtonStrDisabledEnd IfEnd IfEnd IfEnd If' --- Separators added manually using method AddSeparator or AddSeparatorAfter ---If mobjSeparator.Exists ( Cstr(mArrAbtnDef( InxName, itemInx )) ) ThenResponse.write "<td><img src='images/spacer.gif' width='"& mobjSeparator.Item ( Cstr(mArrAbtnDef( InxName, itemInx )) ) &"' height='1'></td>"End IfNextResponse.write "</tr></table>"End Sub'-----------------------------------------------------------------------------------------------------------------Public Sub LoadActionButtons ( aAbtnList, ByRef objOraDatabase )Dim rsQry, queryquery = _" 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)) ThenCall LoadButtons ( rsQry.GetRows() )End IfrsQry.CloseSet rsQry = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------Public Sub LoadButtons ( aRows )Dim nProperty, newArrayDim, LastRow, rowNumLastRow = UBound( aRows, 2 )For rowNum = 0 To LastRow' Increase array by 1newArrayDim = LastRowInx() + 1ReDim Preserve mArrAbtnDef( mNumOfProperties, newArrayDim )mobjNameDefMap.Item ( Cstr( aRows ( InxName, rowNum ) ) ) = newArrayDimFor nProperty = 0 To mLastPropertyInxmArrAbtnDef ( nProperty, newArrayDim ) = aRows ( nProperty, rowNum )NextNextEnd 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 setupCall SetItemPropertyByIndex ( mobjNameDefMap.Item (Cstr(sItemName)), InxActive, enumDB_YES ) ' Default Active = enumDB_YESEnd 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 imageEnd 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 ThisClassNameSet 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 = TRUEmnButtonSpacer = 0mnButtonTextSpace = 4mNumOfProperties = 11 ' Number of properties in array which define one menu item.mLastPropertyInx = mNumOfProperties - 1mbDisableAll = FALSEReDim mArrAbtnDef ( mNumOfProperties, -1 )InxID = 0InxName = 1InxTxt = 2InxLink = 3InxEventHandler = 4InxImg = 5InxImgOff = 6InxHint = 7InxVisible = 8InxActive = 9InxIsReadonlyAction = 10End Sub'-----------------------------------------------------------------------------------------------------------------Private Sub Class_Terminate()'// Perform action on object disposal. e.g. Set myObj = NothingSet mobjNameDefMap = NothingSet mobjIdDefMap = NothingSet mobjSeparator = NothingEnd Sub'-----------------------------------------------------------------------------------------------------------------End Class%>