B4J Question [ABMaterial] [Fixed]ABMTable Click Event Not Captured

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

my abm ver is 4.3

1. My tbl1 in local(working with b4j together) is working(Can clicked). when i upload jar to my vps server, Its click event isn't working. Why ?? :(

2. My SideBarItem icon has same problem. It can show in local. when it in the vps,All SideBarItem's icon isn't showing. Why ?? :(

B4X:
Sub ConnectNavigationBar(page As ABMPage) 'ignore       
    ' Clear the dummies we created in BuildNavigationBar
    page.NavigationBar.Clear       
    '
    Dim loginuser As Map=LogIn(page)
    Dim bool As Boolean=jylab.IIF(loginuser.Get("account")<>"",True,False)
    ' add your navigationbar items           
    If bool Then
        page.NavigationBar.AddSideBarItem("Logoff", $"登出 [ ${loginuser.Get("account")} ]"$, "mdi-action-exit-to-app", "")
        page.NavigationBar.AddSideBarDivider
        page.NavigationBar.AddSideBarItem("Upload", "上 傳", "mdi-file-cloud-upload", "../upload/index.html")
        page.NavigationBar.AddSideBarItem("Edit", "編 輯", "mdi-editor-mode-edit", "../edit/index.html")
        page.NavigationBar.AddSideBarItem("View", "檢 視", "mdi-action-pageview", "../view/index.html")
        '
        page.NavigationBar.AddTopItemEx("User","","mdi-image-timer-auto",loginuser.Get("account"),"",ABM.COLOR_WHITE,ABM.INTENSITY_DARKEN1,ABM.ICONALIGN_CENTER)
    Else
        page.NavigationBar.AddSideBarItem("Register",  "新人註冊", "mdi-action-accessibility", "../register/index.html")
        page.NavigationBar.AddSideBarItem("Login",  "用戶登入", "mdi-action-exit-to-app", "")
        '
        page.NavigationBar.AddTopItemEx("User","","mdi-image-timer-auto","","",ABM.COLOR_GREY,ABM.INTENSITY_DARKEN2,ABM.ICONALIGN_CENTER)
    End If
    page.NavigationBar.AddSideBarDivider
    page.NavigationBar.AddSideBarItem("About", "關 於 ...", "mdi-action-perm-identity", $"../about/index.html"$)
    page.NavigationBar.Refresh ' IMPORTANT       
    'myMenu.Open
End Sub

B4X:
'Class module
Sub Class_Globals
    Private ws As WebSocket 'ignore
    ' will hold our page information
    Public page As ABMPage
    ' page theme
    Private theme As ABMTheme
    ' to access the constants
    Private ABM As ABMaterial 'ignore
    ' name of the page, must be the same as the class name (case sensitive!)
    Public Name As String = "view"  '<-------------------------------------------------------- IMPORTANT
    ' will hold the unique browsers window id
    Private ABMPageId As String = ""
    ' your own variables
    Private loginuser As Map
    Private pages As List
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    ' build the local structure IMPORTANT!
    BuildPage
End Sub

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    ws = WebSocket1
    ABMPageId = ABM.GetPageID(page, Name,ws)
   
    Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds)
    '----------------------START MODIFICATION 4.00-------------------------------
    If session.IsNew Then
        session.Invalidate
        ABMShared.NavigateToPage(ws, "", "./")
        Return
    End If
    '----------------------END MODIFICATION 4.00-------------------------------
    'If ABMShared.NeedsAuthorization Then
    loginuser = db.GetSessionAttribute(session) ' CreateMap("account":"","password":"","token":"","company":"","address":"")
    'If ABMShared.NeedsAuthorization Then
    If  db.GsaToken(loginuser) = "" Then
        ABMShared.NavigateToPage(ws, "", "../about")
        Return
    End If
    Log($"User. ${db.GsaToken(loginuser)}"$)
   
    ABM.UpdateFromCache(Me, ABMShared.CachedPages, ABMPageId, ws)
    If page.ComesFromPageCache Then
        ' when we have a page that is cached it doesn't matter if it comes or not from a new connection we serve the cached version.
        Log("Comes from cache")
        page.Refresh
        page.FinishedLoading
    Else
        If page.WebsocketReconnected Then
            Log("Websocket reconnected")
            ' when we have a client that doesn't have the page in cache and it's websocket reconnected and also it's session is new - basically when the client had internet problems and it's session (and also cache) expired before he reconnected so the user has content in the browser but we don't have any on the server. So we need to reload the page.
            ' when a client that doesn't have the page in cache and it's websocket reconnected but it's session is not new - when the client had internet problems and when he reconnected it's session was valid but he had no cache for this page we need to reload the page as the user browser has content, reconnected but we have no content in cache
            ABMShared.NavigateToPage (ws, ABMPageId, "./" & page.PageHTMLName)
        Else
            ' when the client did not reconnected it doesn't matter if the session was new or not because this is the websockets first connection so no dynamic content in the browser ... we are going to serve the dynamic content...
            Log("Websocket first connection")
            page.Prepare
            ConnectPage
        End If
    End If
    Log(ABMPageId)
End Sub

Private Sub WebSocket_Disconnected
    Log("Disconnected")
End Sub

Sub Page_ParseEvent(Params As Map)
    Dim eventName As String = Params.Get("eventname")
    Dim eventParams() As String = Regex.Split(",",Params.Get("eventparams"))
   
    If eventName = "beforeunload" Then
        Log("preparing for url refresh")
        ABM.RemoveMeFromCache(ABMShared.CachedPages, ABMPageId)
        Return
    End If
    Dim caller As Object = page.GetEventHandler(Me, eventName)
    If caller = Me Then
        If SubExists(Me, eventName) Then
            Params.Remove("eventname")
            Params.Remove("eventparams")
            ' BEGIN NEW DRAGDROP
            If eventName = "page_dropped" Then
                page.ProcessDroppedEvent(Params)
            End If
            ' END NEW DRAGDROP
            Select Case Params.Size
                Case 0
                    CallSub(Me, eventName)
                Case 1
                    CallSub2(Me, eventName, Params.Get(eventParams(0)))
                Case 2
                    If Params.get(eventParams(0)) = "abmistable" Then
                        Dim PassedTables As List = ABM.ProcessTablesFromTargetName(Params.get(eventParams(1)))
                        CallSub2(Me, eventName, PassedTables)
                    Else
                        CallSub3(Me, eventName, Params.Get(eventParams(0)), Params.Get(eventParams(1)))
                    End If
                Case Else
                    ' cannot be called directly, to many param
                    CallSub2(Me, eventName, Params)
            End Select
        End If
    Else
        CallSubDelayed2(caller, "ParseEvent", Params) 'ignore
    End If
End Sub

public Sub BuildTheme()
    ' start with the base theme defined in ABMShared
    theme.Initialize("pagetheme")
    theme.AddABMTheme(ABMShared.MyTheme)
   
   
    theme.AddTableTheme("tbl1theme")
    theme.Table("tbl1theme").ZDepth = ABM.ZDEPTH_1
    theme.Table("tbl1theme").BackColor = ABM.COLOR_WHITE
   
    theme.Table("tbl1theme").AddCellTheme("headerfooter")
    theme.Table("tbl1theme").Cell("headerfooter").BackColor = "dragonflygreen"
    theme.Table("tbl1theme").Cell("headerfooter").ForeColor = ABM.COLOR_WHITE
   
    theme.Table("tbl1theme").AddCellTheme("headerfooterright")
    theme.Table("tbl1theme").Cell("headerfooterright").BackColor = "dragonflygreen"
    theme.Table("tbl1theme").Cell("headerfooterright").ForeColor = ABM.COLOR_WHITE
    theme.Table("tbl1theme").Cell("headerfooterright").Align = ABM.TABLECELL_HORIZONTALALIGN_RIGHT
   
    theme.Table("tbl1theme").AddCellTheme("headercenter1")
    theme.Table("tbl1theme").Cell("headercenter1").BackColor = "dragonflygreen"
    theme.Table("tbl1theme").Cell("headercenter1").ForeColor = ABM.COLOR_BLACK
    theme.Table("tbl1theme").Cell("headercenter1").Align = ABM.TABLECELL_HORIZONTALALIGN_CENTER
    theme.Table("tbl1theme").Cell("headercenter1").BorderColor=ABM.COLOR_GREY
    theme.Table("tbl1theme").Cell("headercenter1").FontSize=16
    theme.Table("tbl1theme").Cell("headercenter1").BorderWidth=1
   
    theme.Table("tbl1theme").AddCellTheme("headerleft1")
    theme.Table("tbl1theme").Cell("headerleft1").BackColor = "dragonflygreen"
    theme.Table("tbl1theme").Cell("headerleft1").ForeColor = ABM.COLOR_BLACK
    theme.Table("tbl1theme").Cell("headerleft1").Align = ABM.TABLECELL_HORIZONTALALIGN_CENTER
    theme.Table("tbl1theme").Cell("headerleft1").BorderColor=ABM.COLOR_GREY
    theme.Table("tbl1theme").Cell("headerleft1").BorderWidth=1
       
    theme.Table("tbl1theme").AddCellTheme("nc_left")
    theme.Table("tbl1theme").Cell("nc_left").BackColor = ABM.COLOR_WHITE
    theme.Table("tbl1theme").Cell("nc_left").ActiveBackColor = ABM.COLOR_BLUE
    theme.Table("tbl1theme").Cell("nc_left").ActiveBackColorIntensity = ABM.INTENSITY_LIGHTEN4
    theme.Table("tbl1theme").Cell("nc_left").BorderColor=ABM.COLOR_GREY
    theme.Table("tbl1theme").Cell("nc_left").BorderWidth=1
    theme.Table("tbl1theme").Cell("nc_left").FontSize = 14
   
    theme.Table("tbl1theme").AddCellTheme("nc_right")
    theme.Table("tbl1theme").Cell("nc_right").BackColor = ABM.COLOR_WHITE
    theme.Table("tbl1theme").Cell("nc_right").ActiveBackColor = ABM.COLOR_BLUE
    theme.Table("tbl1theme").Cell("nc_right").ActiveBackColorIntensity = ABM.INTENSITY_LIGHTEN4  
    theme.Table("tbl1theme").Cell("nc_right").BorderColor=ABM.COLOR_GREY
    theme.Table("tbl1theme").Cell("nc_right").Align = ABM.TABLECELL_HORIZONTALALIGN_RIGHT
    theme.Table("tbl1theme").Cell("nc_right").BorderWidth=1
    theme.Table("tbl1theme").Cell("nc_right").FontSize = 14
   
    theme.Table("tbl1theme").AddCellTheme("nc_center")
    theme.Table("tbl1theme").Cell("nc_center").BackColor = ABM.COLOR_WHITE
    theme.Table("tbl1theme").Cell("nc_center").Align = ABM.TABLECELL_HORIZONTALALIGN_CENTER
    theme.Table("tbl1theme").Cell("nc_center").ActiveBackColor = ABM.COLOR_BLUE
    theme.Table("tbl1theme").Cell("nc_center").ActiveBackColorIntensity = ABM.INTENSITY_LIGHTEN4
    theme.Table("tbl1theme").Cell("nc_center").BorderColor=ABM.COLOR_GREY
    theme.Table("tbl1theme").Cell("nc_center").BorderWidth=1
   
    theme.Table("tbl1theme").AddCellTheme("nc_center1")
    theme.Table("tbl1theme").Cell("nc_center1").BackColor = ABM.COLOR_WHITE
    theme.Table("tbl1theme").Cell("nc_center1").Align = ABM.TABLECELL_HORIZONTALALIGN_CENTER
    theme.Table("tbl1theme").Cell("nc_center1").ActiveBackColor = ABM.COLOR_WHITE
    theme.Table("tbl1theme").Cell("nc_center1").BorderColor=ABM.COLOR_GREY
    theme.Table("tbl1theme").Cell("nc_center1").BorderWidth=1
   
    theme.AddLabelTheme("LabelRight")
    theme.Label("LabelRight").Align = ABM.TEXTALIGN_RIGHT  
End Sub

public Sub BuildPage()
    ' initialize the theme
    BuildTheme
   
    ' initialize this page using our theme
    page.InitializeWithTheme(Name, "/ws/" & ABMShared.AppName & "/" & Name, False, ABMShared.SessionMaxInactiveIntervalSeconds, theme)
    page.ShowLoader=True
    page.PageHTMLName = "index.html"
    page.PageTitle = "Jin! Page"
    page.PageDescription = ""
    page.PageKeywords = ""
    page.PageSiteMapPriority = ""
    page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
    'page.SetBackgroundImage("../images/iotmodlink1.png")
       
    page.ShowConnectedIndicator = False
               
    ' adding a navigation bar
    ABMShared.BuildNavigationBar(page, "我的Page","../images/logo.png", "", "", "")
    ' create the page grid
    page.AddRowsM(1, True,32,0,"").AddCellsOS(1,2,2,2,8,8,8,"")
    page.BuildGrid 'IMPORTANT loaded the complete grid prior adding components
   
    ' Fixed Footer

    ' add a modal sheet template to enter contact information
    page.AddModalSheetTemplate(ABMShared.BuildMessageSheet(page))
    page.AddModalSheetTemplate(ABMShared.BuildLoginSheet(page))
End Sub

public Sub ConnectPage()
    '    connecting the navigation bar
    ABMShared.ConnectNavigationBar(page)    '
    ' create the input fields for the content
    page.Cell(1,1).AddComponent(BuildTable)
    ' refresh the page
    page.Refresh
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition
End Sub

Sub BuildTable As ABMTable
    Dim tbl1 As ABMTable
    tbl1.Initialize(page, "tbl1", False, False, True, "tbl1theme")
    tbl1.SetHeaders(Array As String("Page name", "View", "Liked", "Update","Edit","View"))
    tbl1.SetColumnWidths(Array As Int   (0,60,60,180, 60, 60))
    tbl1.SetHeaderThemes(Array As String("headercenter1", "headercenter1", "headercenter1","headercenter1","headercenter1","headercenter1"))
    tbl1.IsBordered=True
    tbl1.IsResponsive=True
    '
    pages = MySql.GetMyPages(db.GsaToken(loginuser))
    Dim id As Int=0
    For Each item As Map In pages
        Dim r As List
        Dim rct As List
        r.Initialize
        rct.Initialize
        ' script no      
        r.Add(buildTextCr($"page${id}"$,item.Get("page")))
        rct.Add("nc_left") ' nocoloredit
        ' device
        r.Add(buildTextR($"view${id}"$,item.Get("count")))
        rct.Add("nc_right")
        ' trigger
        r.Add(buildTextR($"like${id}"$,item.Get("liked")))
        rct.Add("nc_right")
        ' description
        r.Add(buildText($"date${id}"$,item.Get("updated")))
        rct.Add("nc_left")  
        ' edit
        r.Add(buildPNG($"edit${id}"$,"edit",24,24,True))
        rct.Add("nc_center1")
        ' delete
        r.Add(buildPNG($"view${id}"$,"view",24,24,True))
        rct.Add("nc_center1")
        '
        tbl1.AddRow($"row${id}"$, r)
        tbl1.SetRowThemes(rct) ' make sure you have as many items in rCellThemes as in r!
        id = id + 1
    Next
    Return tbl1
End Sub

Sub buildPNG(id As String,source As String,width As Int,height As Int,IsClickable As Boolean) As ABMImage
    Dim img1 As ABMImage
    img1.Initialize(page,id,$"../images/${source}.png"$,1)
    img1.SetFixedSize(width,height)
    img1.IsClickable=IsClickable
    Return img1
End Sub

Sub buildText(id As String,text As String) As ABMLabel
    Dim lbl1 As ABMLabel
    lbl1.Initialize(page, id, text, ABM.SIZE_H6, False, "lbl_black")
    lbl1.Truncate=False
    lbl1.MarginTop = "2px"
    lbl1.MarginBottom = "2px"
    Return lbl1
End Sub
'
Sub buildTextR(id As String,text As String) As ABMLabel
    Dim lbl1 As ABMLabel
    lbl1.Initialize(page, id, text, ABM.SIZE_H6, False, "lbl_black")
    lbl1.UseTheme("LabelRight")
    lbl1.MarginTop = "2px"
    lbl1.MarginBottom = "2px"
    Return lbl1
End Sub
'
Sub buildTextCr(id As String,text As String) As ABMLabel
    Dim lbl1 As ABMLabel
    lbl1.Initialize(page, id, text,ABM.SIZE_H6, False, "lbl_black_center")
    lbl1.MarginTop = "2px"
    lbl1.MarginBottom = "2px"
    Return lbl1
End Sub
' color = #FF0000
Sub buildText1(id As String,text As String,color As String) As ABMLabel
    Dim lbl1 As ABMLabel
    lbl1.Initialize(page, id, $"{C:${color}}${text}{/C}"$, ABM.SIZE_H5, False, "lbl_black")
    Return lbl1
End Sub

Sub ErrorMsg(id As String,text As String)
    page.ShowToast(id,"redwhite",text,1500,False)
End Sub

Sub NotifyMsg(id As String,text As String)
    page.ShowToast(id,"blued3white",text,1500,False)
End Sub

Sub toMessage(msg As String)
    Dim lbl As ABMLabel = page.Footer.Component("footlbl3")
    lbl.Text=msg
    lbl.Refresh
End Sub

Sub page_MsgboxResult(returnName As String, result As String)
   
End Sub

Sub Page_Dropped(Params As Map)
    If Params.Get("before") = "" Then
        Log("'" & Params.Get("component") & "' moved from " & Params.Get("source") & " to " & Params.Get("target"))
    Else
        Log("'" & Params.Get("component") & "' moved from " & Params.Get("source") & " to " & Params.Get("target") & " before component " & Params.Get("before"))
    End If
End Sub
' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String)
    ' saving the navigation bar position
    page.SaveNavigationBarPosition
   
    If Action = "User" Then
       
    End If
   
    If Action = "Login" Then
        ABMShared.ShowLoginSheet(page)
        Return
    End If
   
    If Action = "Logoff" Then
        ABMShared.LogOff(page)
        Return
    End If

    ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub
'
Sub LoginOK_Clicked(Target As String)
    Dim mymodal As ABMModalSheet = page.ModalSheet("login")
    Dim inp1 As ABMInput = mymodal.Content.Component("inp1")
    Dim inp2 As ABMInput = mymodal.Content.Component("inp2")
    ' here check the login a page against your login database
    loginuser = MySql.UserLogin(inp1.Text,inp2.Text)
    If loginuser.GetDefault("token","")="" Then
        ABMShared.ShowMessage(page,"The login Or password are incorrect!")
        Return
    End If
    Log($"User login.${inp1.text},${inp2.text}=${loginuser.Get("token")}"$)
    ws.Session.SetAttribute("IsAuthorized",db.MapToString(loginuser))
    page.CloseModalSheet("login")
    ABMShared.ConnectNavigationBar(page)
    ' ABMShared.NavigateToPage(ws, "", "../AboutPage/")
End Sub
'
Sub LoginNO_Clicked(Target As String)
    page.CloseModalSheet("login")
    'ABMShared.NavigateToPage(ws, "", "./" & InitialPage)
End Sub
'
Sub Page_InputboxResult(returnName As String, result As String)
   
End Sub

Sub Page_DebugConsole(message As String)
    Log("---> " & message)
End Sub

Sub Page_FileUploaded(FileName As String, success As Boolean)
   
End Sub

Sub Page_ToastClicked(toastID As String, Action As String)
       
End Sub

Sub Page_ToastDismissed(ToastId As String)
   
End Sub

Sub Page_Authenticated(Params As Map)
   
End Sub

Sub Page_FirebaseAuthError(extra As String)
   
End Sub

Sub Page_FirebaseAuthStateChanged(IsLoggedIn As Boolean)
   
End Sub

Sub Page_FirebaseStorageError(jobID As String, extra As String)
   
End Sub

Sub Page_FirebaseStorageResult(jobID As String, extra As String)
   
End Sub

Sub Page_ModalSheetDismissed(ModalSheetName As String)
   
End Sub

Sub Page_NextContent(TriggerComponent As String)
   
End Sub

Sub Page_SignedOffSocialNetwork(Network As String, Extra As String)
   
End Sub

Sub page_CellClicked(Target As String, RowCell As String)
    #If DEBUG  
    Log("CellClick : " & Target & " , " & RowCell)
    #End If
End Sub

Sub page_RowClicked(Target As String, Row As String)
    #If DEBUG  
    Log("RowClick : " & Target & " , " & Row)
    #End If
End Sub

Sub PageDirectory(page1 As String) As String
    If pages.Size<1 Then
        Return ""
    End If
    Dim s1 As String
    For Each item As Map In pages
        s1=item.Getdefault("page","")
        If s1=page1 Then
            s1 = item.Getdefault("directory","")
            If s1<>"" Then
                Return s1
            End If
        End If
    Next
    Return ""
End Sub

Sub tbl1_Clicked(PassedRowsAndColumns As List)
    ' is the root table
    Dim tblCellInfo As ABMTableCell = PassedRowsAndColumns.Get(0)
    Dim tbl As ABMTable = page.Cell(1,1).Component(tblCellInfo.TableName)
    If tblCellInfo.Column<4 Then
        Return
    End If
    Dim lbl1 As ABMLabel = tbl.GetComponent(tblCellInfo.Row, $"page${tblCellInfo.Row}"$)
    #if DEBUG
    NotifyMsg("st449",$"page${tblCellInfo.Row}, ${lbl1.text}"$)
    Else
    Log($"page${tblCellInfo.Row}, ${lbl1.text}"$)
    #End If
    Dim s1 As String=PageDirectory(lbl1.Text)
    If s1="" Then
        ErrorMsg("st472",$"Page名.${lbl1.text}不存在 !!"$)
        Return
    End If
   
    If tblCellInfo.Column = 5 Then ' view
        Log($"window.open("/jinpage/pages/${s1}?${DateTime.Time(DateTime.Now)}","jinpg1");"$)
        ws.Eval($"window.open("/jinpage/pages/${s1}?${DateTime.Time(DateTime.Now)}","jinpg1");"$,Null)
       
    else if tblCellInfo.Column = 4 Then ' edit
        Log($"..\edit?page=${lbl1.text}&directory=${s1}"$)
        ABMShared.NavigateToPage(ws, "", $"..\edit?page=${lbl1.text}&directory=${s1}"$)
    End If  
   
End Sub

Sub Page_NativeResponse(jsonMessage As String)
   
End Sub

Sub Page_NavigationbarSearch(search As String)
   
End Sub
 
Last edited:

jinyistudio

Well-Known Member
Licensed User
Longtime User
I copy all files into vps again. It is OK. :p
 
Upvote 0
Top