B4J=true Group=Default Group ModulesStructureVersion=1 Type=Class Version=4.7 @EndOfDesignText@ '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 = "people" '<-------------------------------------------------------- IMPORTANT Private ABMPageId As String = "" ' your own variables Dim Origin As String = "http://localhost:51043" '<--- IMPORTANT for youtube videos. Set here your website address ' the download folder Public DownloadFolder As String = "/www/" & ABMShared.AppName & "/uploads/" Public DownloadMaxSize As String = 1000000*1024 Private myToastId As Int Private dbAction As Map Private ActiveID As Int Private IsNew As Boolean Private Filter As String Private LastSort As String Private FilterCount As String Private OldValue As String Public MaxRows As Int 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) Log("Connected") ws = WebSocket1 ABMPageId = ABM.GetPageID(page, Name,ws) Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds) If session.IsNew Then session.Invalidate ABMShared.NavigateToPage(ws, "", "./") Return End If If ABMShared.NeedsAuthorization Then If session.GetAttribute2("IsAuthorized", "") = "" Then ABMShared.NavigateToPage(ws, ABMPageId, "../") Return End If End If 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") 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") Try ws.Session.RemoveAttribute("abmcallback") ws.Session.RemoveAttribute("abmdownloadfolder") ws.Session.RemoveAttribute("abmmaxsize") Catch Log(LastException.Message) End Try 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) ' add additional themes specific for this page theme.Page.BackColor = ABM.COLOR_TRANSPARENT theme.Page.BackColorIntensity = ABM.INTENSITY_NORMAL theme.Page.ConnectedIndicatorColor = ABM.COLOR_GREEN theme.Page.ConnectedIndicatorColorIntensity = ABM.INTENSITY_NORMAL theme.Page.DisconnectedIndicatorColor = ABM.COLOR_RED theme.Page.DisconnectedIndicatorColorIntensity = ABM.INTENSITY_NORMAL theme.Page.PlaceHolderColor = ABM.COLOR_GREY theme.Page.PlaceHolderColorIntensity = ABM.INTENSITY_NORMAL theme.Page.searchmarkbackcolor = ABM.COLOR_YELLOW theme.Page.searchmarkbackcolorintensity = ABM.INTENSITY_NORMAL theme.Page.searchmarkforecolor = ABM.COLOR_BLACK theme.Page.searchmarkforecolorintensity = ABM.INTENSITY_NORMAL 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.ShowLoaderType=ABM.LOADER_TYPE_MANUAL page.PageHTMLName = "people.html" page.PageTitle = "Project.Show" page.PageDescription = "" page.PageKeywords = "" page.PageSiteMapPriority = "0.50" page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_MONTHLY 'page.UseFontAwesome = False page.DisableBackButton = False page.UseGoogleAnalytics(ABMShared.TrackingID, Null) ' IMPORTANT Change this to your own TrackingID !!!!!!! page.GoogleMapsAPIExtras = ABMShared.GoogleMapsAPIExtras page.IsFixedFooter = False page.DisablePageReloadOnSwipeDown = True page.ShowConnectedIndicator = True page.PageLanguage = "en" page.AlwaysShowVerticalScrollBar = False MashPlugIns.NeedsAnimation(page) ' adding a navigation bar Dim sbtopimg As ABMImage sbtopimg.Initialize(page, "sbtopimg", "../images/logo.png?" & DateTime.Now, 1) sbtopimg.IsCircular = False sbtopimg.SetFixedSize(236, 49) page.NavigationBar.Initialize(page, "navBar", ABM.SIDEBAR_MANUAL_ALWAYSHIDE, "People", True, True, 330, 48, sbtopimg, ABM.COLLAPSE_ACCORDION, "nb") page.NavigationBar.InitializeSearchButton(180, 240, 360, ABM.VISIBILITY_HIDE_ON_SMALL_ONLY) page.NavigationBar.ActiveSideReturnName = "people" page.NavigationBar.SideBarLogoHeight = 49 page.NavigationBar.TopBarDropDownConstrainWidth = True ' you must add at least ONE dummy item if you want to add items to the topbar in ConnectNaviagationBar page.NavigationBar.AddTopItem("DUMMY", "{NBSP}", "", "", False) ' you must add at least ONE dummy item if you want to add items to the sidebar ABMShared.AddSideBarItem(page,"DUMMY", "{NBSP}", "", "", "0", "0") page.ShowGridInfo = False ' create the page grid page.AddRows(1, False, "").AddCellsOSMP(1, 0, 0, 0, 12, 12, 12, 0, 0, 20, 20, "") page.AddRows(1, False, "").AddCellsOSMP(1, 0, 0, 0, 12, 12, 12, 0, 0, 20, 20, "") page.AddRows(3, False, "").AddCellsOSMP(1, 0, 0, 0, 12, 12, 12, 0, 0, 20, 20, "") page.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components ' add a error box template if the name is not entered page.AddModalSheetTemplate(ABMShared.BuildWrongInputModalSheet(page)) ' add a modal sheet template for a yes no msgbox page.AddModalSheetTemplate(ABMShared.BuildMsgBoxYesNo(page)) ' add a modal sheet template for a msgbox page.AddModalSheetTemplate(ABMShared.BuildMsgBox(page)) End Sub Private Sub msgenpeopleBuild() As ABMModalSheet Dim msgenpeople As ABMModalSheet Dim dSize As Int = ABM.MODALSHEET_SIZE_NORMAL If ABMShared.IsPhone(page) Then dSize = ABM.MODALSHEET_SIZE_FULL msgenpeople.Initialize(page, "msgenpeople", True, ABM.MODALSHEET_TYPE_NORMAL, "ms") msgenpeople.Size = dSize msgenpeople.IsDismissible = False msgenpeople.IsTextSelectable = True msgenpeople.Content.AddRows(1,True,"").AddCellsOSMPV(1, 0, 0, 0, 12, 12, 12, 0, 0, 0, 0, ABM.VISIBILITY_ALL, "") msgenpeople.Content.AddRows(1,True,"").AddCellsOSMPV(1, 0, 0, 0, 12, 6, 6, 0, 0, 10, 10, ABM.VISIBILITY_ALL, "").AddCellsOSMPV(1, 0, 0, 0, 12, 6, 6, 0, 0, 10, 10, ABM.VISIBILITY_ALL, "") msgenpeople.Content.AddRows(1,True,"").AddCellsOSMPV(1, 0, 0, 0, 12, 6, 6, 0, 0, 0, 0, ABM.VISIBILITY_ALL, "").AddCellsOSMPV(1, 0, 0, 0, 12, 6, 6, 0, 0, 0, 0, ABM.VISIBILITY_ALL, "") msgenpeople.Content.AddRows(1,True,"").AddCellsOSMPV(1, 0, 0, 0, 12, 6, 6, 0, 0, 0, 0, ABM.VISIBILITY_ALL, "").AddCellsOSMPV(1, 0, 0, 0, 12, 6, 6, 0, 0, 0, 0, ABM.VISIBILITY_ALL, "") msgenpeople.Content.AddRows(1,True,"").AddCellsOSMPV(1, 0, 0, 0, 12, 6, 6, 0, 0, 0, 0, ABM.VISIBILITY_ALL, "").AddCellsOSMPV(1, 0, 0, 0, 12, 6, 6, 0, 0, 0, 0, ABM.VISIBILITY_ALL, "") msgenpeople.Footer.AddRowsM(1, True, 0, 0, "").AddCellsOS(1, 0, 0, 0, 12, 12, 12, "") msgenpeople.Header.AddRowsM(1, True, 0, 0, "").AddCellsOS(1, 0, 0, 0, 12, 12, 12, "") msgenpeople.Header.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components msgenpeople.Content.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components msgenpeople.Footer.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components 'Add components to ModalSheet Dim lblgenpeople As ABMLabel lblgenpeople.Initialize(page, "lblgenpeople", $"{NBSP}Add / Edit Person"$, ABM.SIZE_H5, False, "whitefc") lblgenpeople.istextselectable = True lblgenpeople.supportemoji = False msgenpeople.Header.Cell(1,1).AddComponent(lblgenpeople) Dim imgprofileimg As ABMImage imgprofileimg.Initialize(page, "imgprofileimg", "../images/User_96px.png?"& DateTime.Now, 1) imgprofileimg.Tag = "imgprofileimg" imgprofileimg.IsResponsive = False imgprofileimg.IsCircular = True imgprofileimg.IsClickable = False imgprofileimg.IsMaterialBoxed = False imgprofileimg.SetFixedSize(100,100) msgenpeople.Content.Cell(2,1).AddComponent(imgprofileimg) Dim fileinpprofileupl As ABMFileInput fileinpprofileupl.Initialize(page,"fileinpprofileupl","","Browse",True,"","fb") fileinpprofileupl.accepts = "" msgenpeople.Content.Cell(2,2).AddComponent(fileinpprofileupl) Dim txtfullname As ABMInput txtfullname.Initialize(page, "txtfullname", ABM.INPUT_TEXT, "Full Name", False, "inp") txtfullname.Tag = "txtfullname" msgenpeople.Content.Cell(3,1).AddComponent(txtfullname) Dim cbocompanyid As ABMCombo cbocompanyid.Initialize(page, "cbocompanyid", "Company Name", 650, "cbo") cbocompanyid.Tag = "cbocompanyid" cbocompanyid.DataBelow = ABM.COMBO_DATA_BELOWINPUT cbocompanyid.IsValid = ABM.VALID_TRUE msgenpeople.Content.Cell(3,2).AddComponent(cbocompanyid) Dim txtemailaddress As ABMInput txtemailaddress.Initialize(page, "txtemailaddress", ABM.INPUT_EMAIL, "Email Address", False, "inp") txtemailaddress.Tag = "txtemailaddress" msgenpeople.Content.Cell(4,1).AddComponent(txtemailaddress) Dim txtmobilephone As ABMInput txtmobilephone.Initialize(page, "txtmobilephone", ABM.INPUT_TEL, "Mobile Phone #", False, "inp") txtmobilephone.Tag = "txtmobilephone" msgenpeople.Content.Cell(4,2).AddComponent(txtmobilephone) Dim txtjobtitle As ABMInput txtjobtitle.Initialize(page, "txtjobtitle", ABM.INPUT_TEXT, "Job Title", False, "inp") txtjobtitle.Tag = "txtjobtitle" msgenpeople.Content.Cell(5,1).AddComponent(txtjobtitle) Dim txtprojectrole As ABMInput txtprojectrole.Initialize(page, "txtprojectrole", ABM.INPUT_TEXT, "Project Role", False, "inp") txtprojectrole.Tag = "txtprojectrole" msgenpeople.Content.Cell(5,2).AddComponent(txtprojectrole) Dim btnApplygenpeople As ABMButton btnApplygenpeople.InitializeFlat(page, "btnApplygenpeople", "", "", "Save", "fb") btnApplygenpeople.Tag = "btnApplygenpeople" btnApplygenpeople.Size = ABM.BUTTONSIZE_NORMAL msgenpeople.Footer.Cell(1,1).AddComponent(btnApplygenpeople) Dim btnCancelgenpeople As ABMButton btnCancelgenpeople.InitializeFlat(page, "btnCancelgenpeople", "", "", "Cancel", "fb") btnCancelgenpeople.Tag = "btnCancelgenpeople" btnCancelgenpeople.Size = ABM.BUTTONSIZE_NORMAL msgenpeople.Footer.Cell(1,1).AddComponent(btnCancelgenpeople) Return msgenpeople End Sub Sub msgenpeopleClear() Dim msgenpeople As ABMModalSheet msgenpeople = page.ModalSheet("msgenpeople") RefreshOnLoad_cbocompanyid Dim imgprofileimg As ABMImage = msgenpeople.Content.Component("imgprofileimg") Dim fileinpprofileupl As ABMFileInput = msgenpeople.Content.Component("fileinpprofileupl") Dim txtfullname As ABMInput = msgenpeople.Content.Component("txtfullname") Dim cbocompanyid As ABMCombo = msgenpeople.Content.Component("cbocompanyid") Dim txtemailaddress As ABMInput = msgenpeople.Content.Component("txtemailaddress") Dim txtmobilephone As ABMInput = msgenpeople.Content.Component("txtmobilephone") Dim txtjobtitle As ABMInput = msgenpeople.Content.Component("txtjobtitle") Dim txtprojectrole As ABMInput = msgenpeople.Content.Component("txtprojectrole") imgprofileimg.Source = "../images/User_96px.png" & "?" & DateTime.Now imgprofileimg.Refresh fileinpprofileupl.Clear fileinpprofileupl.Refresh txtfullname.Text = "" txtfullname.Refresh cbocompanyid.SetActiveItemId("-1") cbocompanyid.Refresh txtemailaddress.Text = "" txtemailaddress.Refresh txtmobilephone.Text = "" txtmobilephone.Refresh txtjobtitle.Text = "" txtjobtitle.Refresh txtprojectrole.Text = "" txtprojectrole.Refresh End Sub Sub msgyes_Clicked(Target As String) Dim msg As ABMModalSheet = page.ModalSheet("confirm") Dim msgyes As ABMButton = msg.Footer.Component("msgyes") Dim strTag As String strTag = msgyes.Tag YesNoProcess(strTag) page.CloseModalSheet("confirm") End Sub Sub msgok_Clicked(Target As String) page.CloseModalSheet("msgbox") End Sub Sub msgno_Clicked(Target As String) page.CloseModalSheet("confirm") End Sub ' clicked on the navigation bar Sub Page_NavigationbarClicked(Action As String, Value As String) page.SaveNavigationBarPosition If Action = "LogOff" Then ABMShared.LogOff(page) Return End If Select Case Action.ToLowerCase Case "newrecord" ExecuteNewRecord Return Case "refresh" ExecuteRefresh Return Case "goback" ExecuteGoBack Return Case "logoff" ExecuteLogOff Return End Select ABMShared.NavigateToPage(ws, ABMPageId, Value) End Sub Sub Page_FileUploaded(FileName As String, success As Boolean) myToastId = myToastId + 1 If success Then page.ShowToast("toast" & myToastId, "toastgreen", "File " & FileName & " uploaded!", 3000, False) Else page.ShowToast("toast" & myToastId, "toastred", "File " & FileName & " not uploaded!", 3000, False) page.ws.Flush Return End If Dim actualFile As String = File.combine(File.DirApp, DownloadFolder & FileName) Dim msgenpeople As ABMModalSheet msgenpeople = page.ModalSheet("msgenpeople") Dim fileinpprofileupl As ABMFileInput = msgenpeople.Content.Component("fileinpprofileupl") fileinpprofileupl.Clear Dim imgprofileimg As ABMImage = msgenpeople.Content.Component("imgprofileimg") imgprofileimg.Source = "../uploads/" & FileName & "?" & DateTime.Now imgprofileimg.refresh page.ws.Flush ' IMPORTANT End Sub Sub Page_ToastDismissed(ToastId As String) End Sub Sub Page_ToastClicked(ToastId As String, Action As String) page.DismissToast(ToastId) End Sub Sub page_NavigationbarSearch(search As String) DoSearchgenpeople(search) End Sub Public Sub ConnectPage() 'connect navigation bar ConnectNavigationBar 'add components for the page Dim genpeople As ABMTable genpeople.Initialize(page, "genpeople", True, True, True, "tblTheme") genpeople.IsBordered = True genpeople.IsResponsive = True genpeople.IgnoreFormattingCodes = False genpeople.IsTextSelectable = True genpeople.SetHeaders(Array As String("Id", "{NBSP}", "Full Name", "Company Name", "Email Address", "Mobile Phone #", "Job Title", "Project Role", "Edit", "Delete")) genpeople.SetHeaderThemes(Array As String("bg", "bgc", "bg", "bg", "bg", "bg", "bg", "bg", "bgc", "bgc")) genpeople.SetHeaderHeights(Array As Int(0, 51, 0, 0, 0, 0, 0, 0, 48, 48)) genpeople.SetColumnVisible(Array As Boolean(False, True, True, True, True, True, True, True, True, True)) genpeople.SetColumnSortable(Array As Boolean(False, False, True, True, False, False, False, False, False, False)) genpeople.SetColumnDataFields(Array As String("id", "profileimg", "fullname", "companyid", "emailaddress", "mobilephone", "jobtitle", "projectrole", "", "")) genpeople.SetColumnWidths(Array As Int(0, 48, 0, 0, 0, 0, 0, 0, 100dip, 100dip)) page.Cell(5,1).AddComponent(genpeople) Dim genpeoplePager As ABMPagination genpeoplePager.Initialize(page, "genpeoplePager", 10, True, True, "pt") genpeoplePager.Tag = "genpeoplePager" page.Cell(4,1).AddComponent(genpeoplePager) Dim peopleNewRecord As ABMActionButton peopleNewRecord.Initialize(page, "peopleNewRecord", "mdi-content-add", "", "fb") peopleNewRecord.MainButton.Size = ABM.BUTTONSIZE_LARGE page.AddActionButton(peopleNewRecord) AdminAccess page.SetFontStack("arial,sans-serif") ' this page uses uploads, so needs some settings page.ws.session.SetAttribute("abmcallback", Me) page.ws.session.SetAttribute("abmdownloadfolder", DownloadFolder) page.ws.session.SetAttribute("abmmaxsize", DownloadMaxSize) page.InjectCss($"body { background-image: url("../images/cont_bg.png") !important; background-repeat: repeat !important; }"$) page.AddModalSheetTemplate(msgenpeopleBuild) Filter = "" LastSort = "ORDER BY fullname" Loadgenpeople(1) page.Refresh ' IMPORTANT ' NEW, because we use ShowLoaderType=ABM.LOADER_TYPE_MANUAL page.FinishedLoading 'IMPORTANT page.RestoreNavigationBarPosition End Sub Sub Page_SignedOffSocialNetwork(Network As String, Extra As String) page.ws.Session.SetAttribute("UserID", "") page.ws.Session.SetAttribute("UserEmail", "") page.ws.Session.SetAttribute("authType", "") page.ws.Session.SetAttribute("authName", "") page.ws.Session.SetAttribute("IsAuthorized", "") ABMShared.NavigateToPage(ws,ABMPageId, "../") End Sub Sub ExecuteNewRecord() 'Prepare page for new record If ABMShared.HasPermission("people","cancreate") = False Then Return ABMShared.SessionStorageSave(page, "action", "new") ABMShared.SessionStorageSave(page, "peopleid", "-1") msgenpeopleClear page.ShowModalSheet("msgenpeople") End Sub 'An ABMPagination event has been fired Sub genpeoplePager_PageChanged(OldPage As Int, NewPage As Int) Filter = "" LastSort = "ORDER BY fullname" Loadgenpeople(NewPage) End Sub 'An ABMFileInput file has changed Sub fileinpprofileupl_Changed(value As String) Dim msgenpeople As ABMModalSheet msgenpeople = page.ModalSheet("msgenpeople") Dim fileinpprofileupl As ABMFileInput = msgenpeople.Content.Component("fileinpprofileupl") fileinpprofileupl.UploadToServer 'Here the file is uploading End Sub 'There is an imageview to update. Sub ExecuteRefresh() ABMShared.NavigateToPage (ws, ABMPageId, "./" & page.PageHTMLName) End Sub Sub ExecuteGoBack() ABMShared.NavigateToPage(ws, ABMPageId, "../projects/projects.html") End Sub Sub ExecuteLogOff() ABMShared.NavigateToPage(ws, ABMPageId, "../frmLogin/frmLogin.html") End Sub 'An ABMActionButton has been clicked Sub peopleNewRecord_Clicked(Target As String, SubTarget As String) If SubTarget = "" Then Select Case Target.tolowercase Case "peoplenewrecord" 'Prepare page for new record If ABMShared.HasPermission("people","cancreate") = False Then Return ABMShared.SessionStorageSave(page, "action", "new") ABMShared.SessionStorageSave(page, "peopleid", "-1") End Select msgenpeopleClear page.ShowModalSheet("msgenpeople") Return End If End Sub 'An ABMButton has been clicked Sub btnApplygenpeople_Clicked(Target As String) msgenpeopleCreateUpdate page.CloseModalSheet("msgenpeople") End Sub 'An ABMButton has been clicked Sub btnCancelgenpeople_Clicked(Target As String) page.CloseModalSheet("msgenpeople") End Sub Private Sub Loadgenpeople(fromPage As Int) 'How many rows can we add to a single page MaxRows = 10 Dim NowWH As String = ABM.GetBrowserWidthHeight(page) If NowWH <> "" And NowWH <> ";" Then Dim split() As String = Regex.Split(";", NowWH) Dim NewH As Int = split(1) - 350 NewH = NewH / 50 NewH = NewH / 5 NewH = NewH * 5 If NewH >= 10 Then MaxRows = NewH End If End If 'Lets get the component from the page. Dim genpeople As ABMTable = page.Component("genpeople") 'Define list to store the results of the query Dim results As List Dim resCnt As Int Dim resTot As Int Dim resMap As Map Dim sqlQry As String 'Read arguments from LocalStorage (if any) 'Let's define the qry string sqlQry = "SELECT * FROM people " & Filter & " " & LastSort & " LIMIT " & ((fromPage - 1) * MaxRows) & ", " & MaxRows 'Get connection from current pool if MySQL/MSSQL Dim jSQL As SQL = ABMShared.SQLGet 'Get the number of records Dim SQL_str As String SQL_str = "Select Count(id) As IDS FROM people " & Filter Dim NumRecords As Int = ABMShared.SQLSelectSingleResult(jSQL, SQL_str, Null) 'Get the records as a list of maps from the db results = ABMShared.SQLExecuteMaps(jSQL, sqlQry, Null) 'Close the connection to the database ABMShared.SQLClose(jSQL) If results.Size = 0 And fromPage > 1 Then 'we are on a page without any lines fromPage = fromPage - 1 Loadgenpeople(fromPage) Return End If genpeople.Clear 'Loop throught each record read and process it resTot = results.size - 1 For resCnt = 0 To resTot 'Get the record map resMap = results.get(resCnt) 'Update each table row Dim rCellValues As List Dim rCellThemes As List rCellValues.Initialize rCellThemes.Initialize Dim primKey As String = resMap.get("id") Dim id As String = resMap.GetDefault("id", "") If id = "" Then rCellValues.Add("{NBSP}") Else rCellValues.Add(id) End If 'Add theme to the cell rCellThemes.Add("nocolor") Dim profileimg As String = resMap.GetDefault("profileimg", "") If profileimg = "" Then Dim imgprofileimg As ABMImage = ABMShared.ABMImageBuild(page,"imgprofileimg","../images/User_96px.png",1,False,False,"","",True,False,1,40,40) rCellValues.Add(imgprofileimg) Else Dim imgprofileimg As ABMImage = ABMShared.ABMImageBuild(page,"imgprofileimg",profileimg,1,False,False,"","",True,False,1,40,40) rCellValues.Add(imgprofileimg) End If 'Add theme to the cell rCellThemes.Add("nocolorc") Dim fullname As String = resMap.GetDefault("fullname", "") If fullname = "" Then rCellValues.Add("{NBSP}") Else rCellValues.Add(fullname) End If 'Add theme to the cell rCellThemes.Add("nocolor") Dim companyid As String = resMap.GetDefault("companyid", "") If companyid = "" Then rCellValues.Add("{NBSP}") Else Dim SQL_str As String SQL_str = "Select companyname As Outcome FROM companies Where id = ?" companyid = ABMShared.SQLSelectSingleResult(jSQL, SQL_str, Array As String(companyid)) If companyid = "-2" Then companyid = "{NBSP}" rCellValues.Add(companyid) End If 'Add theme to the cell rCellThemes.Add("nocolor") Dim emailaddress As String = resMap.GetDefault("emailaddress", "") If emailaddress = "" Then rCellValues.Add("{NBSP}") Else rCellValues.Add(emailaddress) End If 'Add theme to the cell rCellThemes.Add("nocolor") Dim mobilephone As String = resMap.GetDefault("mobilephone", "") If mobilephone = "" Then rCellValues.Add("{NBSP}") Else rCellValues.Add(mobilephone) End If 'Add theme to the cell rCellThemes.Add("nocolor") Dim jobtitle As String = resMap.GetDefault("jobtitle", "") If jobtitle = "" Then rCellValues.Add("{NBSP}") Else rCellValues.Add(jobtitle) End If 'Add theme to the cell rCellThemes.Add("nocolor") Dim projectrole As String = resMap.GetDefault("projectrole", "") If projectrole = "" Then rCellValues.Add("{NBSP}") Else rCellValues.Add(projectrole) End If 'Add theme to the cell rCellThemes.Add("nocolor") Dim btnEditgenpeople As ABMButton btnEditgenpeople.InitializeFloating(page, "btnEditgenpeople", "mdi-action-visibility", "fb") btnEditgenpeople.Size = ABM.BUTTONSIZE_NORMAL btnEditgenpeople.Enabled = ABMShared.HasPermission("people","canupdate") rCellValues.Add(btnEditgenpeople) rCellThemes.Add("openedit") Dim btnDeletegenpeople As ABMButton btnDeletegenpeople.InitializeFloating(page, "btnDeletegenpeople", "mdi-action-delete", "fb") btnDeletegenpeople.Size = ABM.BUTTONSIZE_NORMAL btnDeletegenpeople.Enabled = ABMShared.HasPermission("people","candelete") rCellValues.Add(btnDeletegenpeople) rCellThemes.Add("openedit") 'Add the row to the table genpeople.AddRow("id" & resCnt, rCellValues) genpeople.SetRowThemes(rCellThemes) Next genpeople.Refresh 'Update the paginating component Dim pager As ABMPagination = page.Component("genpeoplePager") If (NumRecords Mod MaxRows > 0) Or (NumRecords = 0) Then NumRecords = NumRecords/MaxRows + 1 Else NumRecords = NumRecords/MaxRows End If pager.SetTotalNumberOfPages(NumRecords) pager.SetActivePage(fromPage) pager.Refresh End Sub 'Code to handle the sorting of the table Sub genpeople_SortChanged(DataField As String, Order As String) Select Case DataField Case "fullname","companyid" LastSort = " ORDER BY " & DataField & " " & Order & ", id " Case Else LastSort = " ORDER BY fullname " End Select Dim pager As ABMPagination = page.Component("genpeoplePager") Loadgenpeople(pager.GetActivePage()) End Sub 'Code to handle the search on the data Sub DoSearchgenpeople(sSearch As String) Filter = sSearch If Filter <> "" Then Filter = " WHERE fullname LIKE '%" & Filter & "%' OR companyid LIKE '%" & Filter & "%' OR emailaddress LIKE '%" & Filter & "%' OR mobilephone LIKE '%" & Filter & "%' OR jobtitle LIKE '%" & Filter & "%' OR projectrole LIKE '%" & Filter & "%' " Else Filter = "" End If 'reload the table Loadgenpeople(1) End Sub 'Code to handle button clicks on table for edit/delete Sub genpeople_Clicked(PassedRowsAndColumns As List) 'Get the details of the cell being selected Dim tblCellInfo As ABMTableCell = PassedRowsAndColumns.Get(0) 'Get the table being processed. Dim genpeople As ABMTable = page.Component(tblCellInfo.TableName) 'Read the first column in the current row and assign value to ActiveID ActiveID = genpeople.GetString(tblCellInfo.Row, 0) Select Case tblCellInfo.Column Case 8 'Edit a record If ABMShared.HasPermission("people","canupdate") = False Then Return ABMShared.SessionStorageSave(page, "action", "edit") ABMShared.SessionStorageSave(page, "peopleid", ActiveID) msgenpeopleAddEditRecord Case 0 If ABMShared.HasPermission("people","cancreate") = False Then Return 'Clone a record ABMShared.SessionStorageSave(page, "action", "copy") ABMShared.SessionStorageSave(page, "peopleid", ActiveID) msgenpeopleCopyRecord Case 9 'Delete a record If ABMShared.HasPermission("people","candelete") = False Then Return ABMShared.ShowYesNo(page,"Are you sure that you want to delete this record? You will not be able to undo your action. Continue to delete", "Deletepeople", "CancelDeleteRecord") End Select End Sub Public Sub msgenpeopleCopyRecord() If ABMShared.HasPermission("people","cancreate") = False Then Return 'Show progress dialog... Filter = "" LastSort = "ORDER BY fullname" Dim peopleid As String 'Read the ID from localstorage... peopleid = ABMShared.SessionStorageRead(page, "peopleid") 'read the record from the database. Dim jSQL As SQL = ABMShared.SQLGet Dim m As Map m = ABMShared.SQLRecordRead(jSQL,"people", "id", peopleid) 'remove the primary key column m.Remove("id") 'save the record to the database and get new primary key value peopleid = ABMShared.SQLRecordInsert(jSQL, "people", m) ' the new key has been added 'Close the database connection... ABMShared.SQLClose(jSQL) 'Refresh the table Dim pager As ABMPagination = page.Component("genpeoplePager") Loadgenpeople(pager.GetActivePage()) If peopleid > 0 Then ABMShared.SessionStorageSave(page, "action", "edit") ABMShared.SessionStorageSave(page, "peopleid", peopleid) myToastId = myToastId + 1 page.ShowToast("toast" & myToastId, "toastgreen", "Record copied successfully.", 3000,False) ' open the record for editing msgenpeopleAddEditRecord Else myToastId = myToastId + 1 page.ShowToast("toast" & myToastId, "toastred", "Record could not be copied, please try again.", 3000,False) End If End Sub Public Sub msgenpeopleAddEditRecord() 'Show progress dialog... Filter = "" LastSort = "ORDER BY fullname" Dim strAction As String Dim peopleid As String OldValue = "" 'Read action from localstorage... strAction = ABMShared.SessionStorageRead(page, "action") 'Read the ID from localstorage... peopleid = ABMShared.SessionStorageRead(page, "peopleid") Select Case strAction Case "new" If ABMShared.HasPermission("people","cancreate") = False Then Return 'clear the contents of the modal sheet component msgenpeopleClear page.ShowModalSheet("msgenpeople") Case "edit" If ABMShared.HasPermission("people","canupdate") = False Then Return 'clear the controls of the page msgenpeopleClear 'read the record from the database. Dim jSQL As SQL = ABMShared.SQLGet Dim m As Map m = ABMShared.SQLRecordRead(jSQL,"people", "id", peopleid) 'Close the database connection... ABMShared.SQLClose(jSQL) If m.IsInitialized = True Then 'The record has been found, update the modal sheet controls... msgenpeopleSetContents(m) page.ShowModalSheet("msgenpeople") End If End Select End Sub Private Sub msgenpeopleCreateUpdate() Filter = "" LastSort = "ORDER BY fullname" 'define a map to hold the form contents Dim m As Map 'read the modal sheet contents to a map m = msgenpeopleGetContents 'validate the form contents where required If msgenpeopleValidate(m) = False Then Return End If 'the form contents are ok, continue with the save Dim strAction As String Dim peopleid As String 'determine the action we have been performing strAction = ABMShared.SessionStorageRead(page, "action") peopleid = ABMShared.SessionStorageRead(page, "peopleid") Select Case strAction Case "new" If ABMShared.HasPermission("people","cancreate") = False Then Return Dim fk As String = "" If fk <> "" Then fk = ABMShared.SessionStorageRead(page, fk.tolowercase) m.put("", fk) End If 'get the database connection Dim jSQL As SQL = ABMShared.SQLGet 'insert the record peopleid = ABMShared.SQLRecordInsert(jSQL, "people", m) If peopleid > 0 Then ABMShared.SessionStorageSave(page, "action", "edit") ABMShared.SessionStorageSave(page, "peopleid", peopleid) myToastId = myToastId + 1 page.ShowToast("toast" & myToastId, "toastgreen", "Record added successfully.", 3000,False) 'Refresh the table Dim pager As ABMPagination = page.Component("genpeoplePager") Loadgenpeople(pager.GetActivePage()) Else myToastId = myToastId + 1 page.ShowToast("toast" & myToastId, "toastred", "Record could not be added, please try again.", 3000,False) End If 'Close the connection to the database ABMShared.SQLClose(jSQL) Case "edit" If ABMShared.HasPermission("people","canupdate") = False Then Return Dim fk As String = "" If fk <> "" Then fk = ABMShared.SessionStorageRead(page, fk.tolowercase) m.put("", fk) End If 'get the database connection Dim jSQL As SQL = ABMShared.SQLGet If ABMShared.SQLRecordUpdate(jSQL,"people", m, "id", peopleid) = True Then myToastId = myToastId + 1 page.ShowToast("toast" & myToastId, "toastgreen", "Record updated successfully.", 3000,False) 'Refresh the table Dim pager As ABMPagination = page.Component("genpeoplePager") Loadgenpeople(pager.GetActivePage()) Else myToastId = myToastId + 1 page.ShowToast("toast" & myToastId, "toastred", "Record could not be updated, please try again.", 3000,False) End If 'Close the connection to the database ABMShared.SQLClose(jSQL) End Select End Sub 'Get the contents of the modal sheet input components and save to a map Sub msgenpeopleGetContents() As Map Dim pMap As Map pMap.Initialize Dim msgenpeople As ABMModalSheet msgenpeople = page.ModalSheet("msgenpeople") Dim imgprofileimg As ABMImage = msgenpeople.Content.Component("imgprofileimg") Dim fileinpprofileupl As ABMFileInput = msgenpeople.Content.Component("fileinpprofileupl") Dim txtfullname As ABMInput = msgenpeople.Content.Component("txtfullname") Dim cbocompanyid As ABMCombo = msgenpeople.Content.Component("cbocompanyid") Dim txtemailaddress As ABMInput = msgenpeople.Content.Component("txtemailaddress") Dim txtmobilephone As ABMInput = msgenpeople.Content.Component("txtmobilephone") Dim txtjobtitle As ABMInput = msgenpeople.Content.Component("txtjobtitle") Dim txtprojectrole As ABMInput = msgenpeople.Content.Component("txtprojectrole") pMap.put("profileimg", ABMShared.MvField(imgprofileimg.Source,1,"?")) pMap.put("profileupl", fileinpprofileupl.GetFileName) pMap.put("fullname", txtfullname.Text) pMap.put("companyid", cbocompanyid.GetActiveItemId) pMap.put("emailaddress", txtemailaddress.Text) pMap.put("mobilephone", txtmobilephone.Text) pMap.put("jobtitle", txtjobtitle.Text) pMap.put("projectrole", txtprojectrole.Text) Return pMap End Sub 'Get the contents of the modal sheet from GetContents and check validity Sub msgenpeopleValidate(gMap As Map) As Boolean Dim msgenpeople As ABMModalSheet msgenpeople = page.ModalSheet("msgenpeople") Dim stxtfullname As String stxtfullname = gMap.get("fullname") If stxtfullname = "null" Then stxtfullname = "" If stxtfullname.Length = 0 Then ABMShared.Warn(page,"Full Name cannot be blank. Please enter a value.") Dim txtfullname As ABMInput = msgenpeople.Content.Component("txtfullname") txtfullname.SetFocus Return False End If Dim scbocompanyid As String scbocompanyid = gMap.get("companyid") If scbocompanyid = "null" Then scbocompanyid = "" If scbocompanyid.Length = 0 Then ABMShared.Warn(page,"Company Name cannot be blank. Please select a value.") Dim cbocompanyid As ABMCombo = msgenpeople.Content.Component("cbocompanyid") cbocompanyid.SetFocus Return False End If Dim stxtemailaddress As String stxtemailaddress = gMap.get("emailaddress") If stxtemailaddress = "null" Then stxtemailaddress = "" If stxtemailaddress.Length = 0 Then ABMShared.Warn(page,"Email Address cannot be blank. Please enter a value.") Dim txtemailaddress As ABMInput = msgenpeople.Content.Component("txtemailaddress") txtemailaddress.SetFocus Return False End If Dim stxtjobtitle As String stxtjobtitle = gMap.get("jobtitle") If stxtjobtitle = "null" Then stxtjobtitle = "" If stxtjobtitle.Length = 0 Then ABMShared.Warn(page,"Job Title cannot be blank. Please enter a value.") Dim txtjobtitle As ABMInput = msgenpeople.Content.Component("txtjobtitle") txtjobtitle.SetFocus Return False End If Dim stxtprojectrole As String stxtprojectrole = gMap.get("projectrole") If stxtprojectrole = "null" Then stxtprojectrole = "" If stxtprojectrole.Length = 0 Then ABMShared.Warn(page,"Project Role cannot be blank. Please enter a value.") Dim txtprojectrole As ABMInput = msgenpeople.Content.Component("txtprojectrole") txtprojectrole.SetFocus Return False End If Return True End Sub 'Set the contents of the modal page input components from map Sub msgenpeopleSetContents(pMap As Map) Dim msgenpeople As ABMModalSheet msgenpeople = page.ModalSheet("msgenpeople") 'Get the page components to update Dim imgprofileimg As ABMImage = msgenpeople.Content.Component("imgprofileimg") Dim fileinpprofileupl As ABMFileInput = msgenpeople.Content.Component("fileinpprofileupl") Dim txtfullname As ABMInput = msgenpeople.Content.Component("txtfullname") Dim cbocompanyid As ABMCombo = msgenpeople.Content.Component("cbocompanyid") Dim txtemailaddress As ABMInput = msgenpeople.Content.Component("txtemailaddress") Dim txtmobilephone As ABMInput = msgenpeople.Content.Component("txtmobilephone") Dim txtjobtitle As ABMInput = msgenpeople.Content.Component("txtjobtitle") Dim txtprojectrole As ABMInput = msgenpeople.Content.Component("txtprojectrole") 'Update computations 'Assign content to component values Dim imgprofileimgContents As String If pMap.GetDefault("profileimg","") = "" Then Else imgprofileimgContents = pMap.get("profileimg") End If imgprofileimg.Source = imgprofileimgContents & "?" & DateTime.Now imgprofileimg.Refresh fileinpprofileupl.Clear fileinpprofileupl.Refresh Dim txtfullnameContents As String If pMap.GetDefault("fullname","") = "" Then txtfullname.Text = "" Else txtfullnameContents = pMap.get("fullname") End If txtfullname.Text = txtfullnameContents txtfullname.Refresh Dim cbocompanyidContents As String If pMap.GetDefault("companyid","") = "" Then cbocompanyid.SetActiveItemId("-1") Else cbocompanyidContents = pMap.get("companyid") cbocompanyid.SetActiveItemId(cbocompanyidContents) End If cbocompanyid.Refresh Dim txtemailaddressContents As String If pMap.GetDefault("emailaddress","") = "" Then txtemailaddress.Text = "" Else txtemailaddressContents = pMap.get("emailaddress") End If txtemailaddress.Text = txtemailaddressContents txtemailaddress.Refresh Dim txtmobilephoneContents As String If pMap.GetDefault("mobilephone","") = "" Then txtmobilephone.Text = "" Else txtmobilephoneContents = pMap.get("mobilephone") End If txtmobilephone.Text = txtmobilephoneContents txtmobilephone.Refresh Dim txtjobtitleContents As String If pMap.GetDefault("jobtitle","") = "" Then txtjobtitle.Text = "" Else txtjobtitleContents = pMap.get("jobtitle") End If txtjobtitle.Text = txtjobtitleContents txtjobtitle.Refresh Dim txtprojectroleContents As String If pMap.GetDefault("projectrole","") = "" Then txtprojectrole.Text = "" Else txtprojectroleContents = pMap.get("projectrole") End If txtprojectrole.Text = txtprojectroleContents txtprojectrole.Refresh End Sub 'Refresh the contents of the ABMCombo in runtime. Private Sub RefreshOnLoad_cbocompanyid() 'Get access to the component in the modal sheet. Dim msgenpeople As ABMModalSheet msgenpeople = page.ModalSheet("msgenpeople") Dim cbocompanyid As ABMCombo = msgenpeople.Content.Component("cbocompanyid") 'Clear the ABMCombo items cbocompanyid.Clear 'Define list details to load to the combo Dim results As List Dim resCnt As Int Dim resTot As Int Dim resMap As Map 'variable to hold the source field Dim id As String 'variable to hold the description field Dim companyname As String 'Add a spinner to the page 'Get connection from current pool if MySQL/MSSQL Dim jSQL As SQL = ABMShared.SQLGet 'Get the records as a list of maps from the db results = ABMShared.SQLExecuteMaps(jSQL,"select [id],[companyname] from companies order by companyname", Null) 'Close the connection to the database ABMShared.SQLClose(jSQL) 'Loop throught each record read and process it resTot = results.size - 1 For resCnt = 0 To resTot 'Get the record map resMap = results.get(resCnt) 'process the id field id = resMap.get("id") companyname = resMap.get("companyname") cbocompanyid.AddItem(id, companyname, ABMShared.ListItemTitle(page, id, companyname)) Next 'Refresh the ABMCombo contents cbocompanyid.Refresh End Sub Sub AdminAccess() 'Get the usertype Dim UserType As String = ws.Session.GetAttribute2("UserType", "0") End Sub Private Sub YesNoProcess(Tag As String) Select Case Tag Case "Deletepeople" Filter = "" LastSort = "" 'get the database connection Dim jSQL As SQL = ABMShared.SQLGet Dim bDeleted As Boolean = ABMShared.SQLRecordDelete(jSQL, "people", "id", ActiveID) ABMShared.SQLiteResetCounter(jSQL,"people","id") ABMShared.SQLClose(jSQL) If bDeleted = True Then myToastId = myToastId + 1 page.ShowToast("toast" & myToastId, "toastgreen", "Record deleted successfully.", 3000,False) 'Refresh the table Dim pager As ABMPagination = page.Component("genpeoplePager") Loadgenpeople(pager.GetActivePage()) Else myToastId = myToastId + 1 page.ShowToast("toast" & myToastId, "toastred", "Record could not be deleted, please try again.", 3000,False) End If End Select End Sub Sub ConnectNavigationBar() ' Clear the dummies we created in BuildNavigationBar page.NavigationBar.Clear 'connect the items in the navigation bar page.NavigationBar.AddTopItemEx("NewRecord", "", "mdi-content-add", "", True, ABM.COLOR_WHITE, ABM.INTENSITY_NORMAL, ABM.ICONALIGN_CENTER) page.NavigationBar.AddTopItemEx("Refresh", "", "mdi-notification-sync", "", True, ABM.COLOR_WHITE, ABM.INTENSITY_NORMAL, ABM.ICONALIGN_CENTER) page.NavigationBar.AddTopItem("GoBack", "", "mdi-image-navigate-before", "../projects/projects.html", False) page.NavigationBar.AddTopItemEx("LogOff", "", "fa fa-sign-out", "../frmLogin/frmLogin.html", True, ABM.COLOR_WHITE, ABM.INTENSITY_NORMAL, ABM.ICONALIGN_CENTER) 'refresh the navigation bar page.NavigationBar.Refresh ' IMPORTANT End Sub Sub Page_MsgboxResult(returnName As String, result As String) 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_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_CellClicked(Target As String, RowCell As String) 'Log(Target) End Sub Sub page_RowClicked(Target As String, Row As String) 'Log(Target) End Sub Sub Page_NativeResponse(jsonMessage 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