Compile function NDW_FEATURE_FLAGS_EVENTS(CtrlEntId, Event, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10)
/***********************************************************************************************************************

    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from Infineon.

    Name        :   NDW_Feature_Flag_Events

    Description :   This function acts as a commuter module for all events related to this window.

    Notes       :   Commuter Modules are automatically called from the Promoted_Events function which is called by the
                    application-specific promoted event handler. This makes it possible to add QuickEvents that need to
                    execute Basic+ logic without having use the Form Designer to make the association, although this is
                    limited to the events which are currently promoted.

                    If the form needs to call the commuter module directly then the QuickEvent parameters should be
                    formatted like this:

                        '@SELF','@EVENT',['@PARAM1','@PARAMx']

    Parameters  :
        CtrlEntId   [in] -- The fully qualified name of the control calling the promoted event
        Event       [in] -- The event being executed. See the Notes section regarding "PRE" events
        Param1-15   [in] -- Additional event parameter holders
        EventFlow  [out] -- Set to 1 or 0 so the calling event knows whether or not to chain forward. See comments in
                            EVENT_SETUP insert

    History     :   (Date, Initials, Notes)
        03/07/2025    djs     Created initial commuter module.
                            

***********************************************************************************************************************/

#pragma precomp SRP_PreCompiler
#window NDW_FEATURE_FLAGS_EVENTS

$Insert EVENT_SETUP
$Insert LOGICAL
$Insert APP_INSERTS
$Insert REACTOR_LOG_EQUATES
$Insert POPUP_EQUATES

Equ NUM_COLS$                To 4
Equ COL.FEATURE_FLAG_ID$     To 1		
Equ COL.FEATURE_DESCRIPTION$ To 2
Equ COL.ENABLED$             To 3
Equ COL.BTN_VIEW_HISTORY$    To 4

Declare subroutine Post_Event, Database_Services, PlaceDialog, Development_Services, ErrMsg, Popup
Declare function   Datetime, SRP_String, Database_Services, Development_Services

// Update the arguments so that the OpenInsight OLE event will treate the ActiveX event as a native event handler.
If Event EQ 'OLE' then
    Transfer Event to OIEvent
    Transfer Param1 to Event
    Transfer Param2 to Param1
    Transfer Param3 to Param2
    Transfer Param4 to Param3
    Transfer Param5 to Param4
    Transfer Param6 to Param5
    Transfer Param7 to Param6
    Transfer Param8 to Param7
end

GoToEvent Event for CtrlEntId else
    // Event not implemented
end

Return EventFlow or 1

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Event Handlers
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Event WINDOW.CREATE(CreateParam)
    
    GoSub SetupOLEControls
    PlaceDialog(-2, -2)
    
end event


Event OLE_EDT_FEATURE_FLAGS.OnCheckChanged(Cell, OldCheckVal, NewCheckVal)
	
    Response  = Dialog_Box('NDW_ADD_COMMENT', @Window, True$)
    OkClicked = Response<1>
    Comment   = Response<2>
    Row        = Field(Cell, ';', 2)
    If OkClicked and Comment NE '' then
        // Record new enabled state and record the user, datetime, and comment
        FeatureRow = ''
        FeatureId  = Get_Property(CtrlEntId, 'OLE.CellText[':1:';':Row:']')
        Development_Services('ChangeFeatureState', FeatureId, NewCheckVal, @User4, Comment)
        If Error_Services('HasError') then
        	Error_Services('DisplayError')
        	Set_Property(CtrlEntID, "OLE.CellCheck[3; ":Row:"]", OldCheckVal)
        end
    end	else
    	Set_Property(CtrlEntID, "OLE.CellCheck[3; ":Row:"]", OldCheckVal)
    end
	
end event


Event OLE_EDT_FEATURE_FLAGS.OnButtonClick(Cell, Point, Button, Shift, Ctrl)
	
    // Record new enabled state and record the user, datetime, and comment
	FeatureRow = ''
	Row        = Field(Cell, ';', 2)
	FeatureId  = Get_Property(CtrlEntId, 'OLE.CellText[':1:';':Row:']')
	If RowExists('FEATURE_FLAGS', FeatureId) then
		
		FeatureRec               = Database_Services('ReadDataRow', 'FEATURE_FLAGS', FeatureId)
		If Error_Services('NoError') then 
			PopupRec            = ""
			PopupRec<PDISPLAY$> = FeatureId
			Popup(@Window, PopupRec, 'FEATURE_FLAGS_HISTORY')		
		end else
			Error_Services('DisplayError')
		end
	end	else
		ErrMsg('Feature record not found!')
	end
	
end event


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal GoSubs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SetupOLEControls:
	
    FeatureFlagArray = Development_Services('GetFeatureFlagArray')
    NumRows          = DCount(FeatureFlagArray, @FM)
    OLECtrl          = @Window:'.OLE_EDT_FEATURE_FLAGS'
    Set_Property(OLECtrl, 'OLE.Redraw', False$)
    Set_Property(OLECtrl, "OLE.Dimension", NUM_COLS$:@FM:NumRows)
    TitleList        = 'Feature ID':@VM:'Feature Description':@VM:'Feature Enabled':@VM:'Feature History'
    Set_Property(OLECtrl, 'OLE.TitleList', TitleList)
    DataColumn       = 200
    Set_Property(OLECtrl, "OLE.DataColumn[1]", DataColumn)
    DataColumn<4>    = True$ ; // Autosize Description column
    Set_Property(OLECtrl, "OLE.DataColumn[2]", DataColumn)
    DataColumn<1>    = 120
    DataColumn<4>    = False$
    Set_Property(OLECtrl, "OLE.DataColumn[3]", DataColumn)
    DataColumn<1>    = 100
    Set_Property(OLECtrl, "OLE.DataColumn[4]", DataColumn)
    Set_Property(OLECtrl, "OLE.CellProtection[1; All]", 'RO')
    Set_Property(OLECtrl, "OLE.CellProtection[2; All]", 'RO')
    Set_Property(OLECtrl, "OLE.HeaderColumn[1]", 40:@FM:False$)
    Set_Property(OLECtrl, "OLE.CellMultilined[All; All]", True$)
    Set_Property(OLECtrl, "OLE.AllowDeletions", False$)
	Set_Property(OLECtrl, "OLE.CellType[3; All]", "Check Box":@FM:False$:@FM:False$:@FM:False$)
	TypeArray        = "Push Button"
	Set_Property(OLECtrl, "OLE.CellType[4; All]", TypeArray)
	Set_Property(OLECtrl, "OLE.CellAlignment[3; All]", 'C':@FM:'C':@FM:'L')
	Set_Property(OLECtrl, "OLE.CellAlignment[4; All]", 'C':@FM:'C':@FM:'C')
	Set_Property(OLECtrl, "OLE.List", FeatureFlagArray)
	Set_Property(OLECtrl, "OLE.CellText[4; All]", 'View History')
	Set_Property(OLECtrl, 'OLE.Border', 'XP Flat')
    Set_Property(OLECtrl, 'OLE.Font', 'Segoe UI' : @SVM : '15')
	Set_Property(OLECtrl, 'OLE.Redraw', True$)
	Qualify          = ''
    Qualify<1>       = 1
    Qualify<4>       = 0
    Send_Message(OLECtrl, 'QUALIFY_EVENT', 'OLE.OnCheckChanged', Qualify)
    Send_Message(OLECtrl, 'QUALIFY_EVENT', 'OLE.OnButtonClick', Qualify)

return

