Type=Class Version=5.51 ModulesStructureVersion=1 B4J=true @EndOfDesignText@ Sub Class_Globals Dim ABMComp As ABMCustomComponent Dim ABM As ABMaterial Private HTML As String Private iID As String Private intPage As ABMPage Public Title As String Public IsFixed As Boolean Private sLogoImage As String Private sLogoTitle As String Private pgName As String Private ImageHeight As String = "48" Private ImageWidth As String = "48" Private bLogoRound As Boolean Private hasLogo As Boolean Public LogoPlacement As String '('left, right, center) Private DropDownItems As Map Private LogoIcon As String Private LogoIconPos As String Private fabContent As String Private searchBar As String Private BackColor As String Private LogoIconColor As String Private RightItems As List Private LeftItems As List End Sub 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize(InternalPage As ABMPage, ID As String, sTitle As String, sColor As String) ABMComp.Initialize("ABMComp", Me, InternalPage, ID) iID = ID 'get the page name pgName = InternalPage.Name intPage = InternalPage HTML = "" Title = sTitle RightItems.Initialize LeftItems.Initialize IsFixed = False bLogoRound = False hasLogo = False LogoPlacement = "center" DropDownItems.Initialize LogoIcon = "" fabContent = "" searchBar = "" BackColor = sColor LogoIconColor = "" End Sub 'add a search functionality Sub AddSearch Dim frm As HTMLElement frm.Initialize("","form") Dim div As HTMLElement div.Initialize("","div") div.AddClass("input-field") Dim inp As HTMLElement inp.Initialize(iID & "search","input") inp.AddAttribute("type","search") inp.IsRequired = True div.AddContent(inp.HTML) Dim lbl As HTMLElement lbl.Initialize("","label") lbl.AddClass("label-icon") lbl.AddAttribute("for", iID & "search") lbl.AddIcon("","mdi-search","") div.AddContent(lbl.HTML) div.AddIcon("","mdi-close","") frm.AddContent(div.HTML) searchBar = frm.html End Sub 'add a floating action button Sub AddFAB(iconName As String, iconColor As String, iconSize As String, bPulse As Boolean) Dim fabdiv As HTMLElement fabdiv.Initialize(iID & "fab","div") fabdiv.AddClass("nav-content") fabdiv.AddClass(BackColor) Dim a As HTMLElement a.Initialize(iID & "fab","a") a.AddClass("btn") a.AddClass("btn-floating") Select Case iconSize Case "small" a.AddClass("btn-small") Case "medium" a.AddClass("btn-medium") Case "large" a.AddClass("btn-large") End Select If bPulse = True Then a.AddClass("pulse") a.AddClass("halfway-fab waves-effect waves-light") a.AddClass(iconColor) 'add the icon to the anchor a.addicon(iID & "fabicon",iconName,"") 'add the anchor to the div fabdiv.AddContent(a.HTML) fabContent = fabdiv.html End Sub 'set the logo for the navbar Sub SetLogo(LogoImage As String, LogoTitle As String, LogoRound As Boolean, sHeight As String, sWidth As String) sLogoImage = LogoImage sLogoTitle = LogoTitle bLogoRound = LogoRound hasLogo = True End Sub 'set the logo icon Sub SetLogoIcon(iconName As String, iconPos As String, iconColor As String) LogoIcon = iconName LogoIconPos = iconPos LogoIconColor = iconColor End Sub 'add a divider Sub AddRightDivider Dim div As HTMLElement div.Initialize("","li") div.AddClass("divider") RightItems.Add(div.HTML) End Sub 'add a divider Sub AddLeftDivider Dim div As HTMLElement div.Initialize("","li") div.AddClass("divider") LeftItems.Add(div.HTML) End Sub 'add a divider to the dropdown Sub AddDropDownDivider(parentID As String) Dim div As HTMLElement div.Initialize("","li") div.AddClass("divider") parentID = parentID.ToLowerCase If DropDownItems.ContainsKey(parentID) Then Dim lstItems As List = DropDownItems.Get(parentID) lstItems.Add(div.html) DropDownItems.Put(parentID,lstItems) End If End Sub 'add a dropdown menu Sub AddDropDown(itemID As String, itemText As String, itemColor As String, itemPos As String, itemIcon As String) itemID = itemID.tolowercase 'define the item Dim li As HTMLElement li.Initialize(itemID, "li") 'If itemActive = True Then ' li.AddClass("active") 'End If 'add onclick method 'li.AddAttribute("onclick",$"navclick('${pgName.tolowercase}','${itemID}','${itemText}')"$) 'define the anchor Dim a As HTMLElement a.Initialize(iID & "anchor","a") a.AddAttribute("href", "#!") a.AddClass("dropdown-button") a.AddClass(itemColor & "-text") a.AddAttribute("data-activates", itemID & "items") a.AddContent(itemText) If itemIcon.Length = 0 Then a.AddIcon("","mdi-arrow_drop_down","right") Else a.AddIcon("",itemIcon,"right") End If 'add to the pill li.AddContent(a.HTML) If itemPos.tolowercase = "right" Then RightItems.Add(li.HTML) Else LeftItems.Add(li.HTML) End If 'initialize dropdown items Dim drpItems As List drpItems.Initialize DropDownItems.Put(itemID.tolowercase,drpItems) End Sub public Sub GetText(id As String) As String Try id = id.tolowercase Dim jqe As JQueryElement = intPage.ws.GetElementById(id) Return jqe.GetText.value Catch Return "" End Try End Sub public Sub SetText(id As String, value As String) Try id = id.tolowercase Dim jqe As JQueryElement = intPage.ws.GetElementById(id) jqe.SetText(value) Catch Return End Try End Sub 'does the item exist public Sub ItemExists(id As String) As Boolean Dim itemHTML As String = GetHTML(id) If itemHTML = "null" Then Return False Else Return True End If End Sub public Sub GetHTML(id As String) As String Try id = id.tolowercase Dim jqe As JQueryElement = intPage.ws.GetElementById(id) Return jqe.GetHtml.value Catch Return "" End Try End Sub public Sub SetHTML(id As String, value As String) Try id = id.tolowercase Dim jqe As JQueryElement = intPage.ws.GetElementById(id) jqe.SetHtml(value) Catch Return End Try End Sub public Sub GetClass(id As String) As String Try id = id.ToLowerCase Dim jqe As JQueryElement = intPage.ws.GetElementById(id) Return jqe.GetProp("class").Value Catch Return "" End Try End Sub public Sub SetClass(id As String, value As String) Try id = id.ToLowerCase Dim jqe As JQueryElement = intPage.ws.GetElementById(id) jqe.SetProp("class",value) Catch Return End Try End Sub 'set the badge for the item Public Sub SetBadge(itemID As String, sBadge As String, bIsNew As Boolean, sColor As String) itemID = itemID.tolowercase 'create the badge Dim span As HTMLElement span.Initialize(itemID & "badge","span") If bIsNew = True Then span.AddClass("new") End If span.AddClass("badge") If sColor <> "transparent" And sColor.Length > 0 Then span.AddClass(sColor) End If span.AddContent(sBadge) 'do we have an existing badge? Dim bExist As Boolean = ItemExists(itemID & "badge") Select Case bExist Case True 'the badge exist, overwrite it SetClass(itemID & "badge","") ABM.ReplaceMyInnerHTML(intPage, itemID & "badge", span.HTML) Case False 'badge does not exist, add it 'get the html part of the element Dim ehtml As String = GetHTML(itemID) 'locate the last Dim apos As Int = ehtml.LastIndexOf("") If apos > 0 Then Dim abefore As String = Left(ehtml,apos) Dim nHTML As String = abefore & span.HTML & "" SetHTML(itemID,nHTML) End If End Select End Sub Sub Left(Text As String, Length As Long)As String If Length>Text.Length Then Length=Text.Length Return Text.SubString2(0, Length) End Sub 'build an item Private Sub BuildItem(itemID As String, itemIcon As String, iconPos As String, itemText As String, itemNavigateTo As String, itemActive As Boolean, itemColor As String, textVisible As Boolean) As String itemID = itemID.tolowercase 'create the badge Dim span As HTMLElement span.Initialize(itemID & "badge","span") span.AddClass("badge") 'define the item Dim li As HTMLElement li.Initialize(itemID, "li") If itemActive = True Then li.AddClass("active") End If 'add onclick method 'li.AddAttribute("onclick",$"navclick('${pgName.tolowercase}','${itemID}','${itemText}')"$) 'define the anchor Dim a As HTMLElement a.Initialize(itemID & "anchor","a") If itemNavigateTo.Length = 0 Then itemNavigateTo = "#!" End If a.AddAttribute("href", itemNavigateTo) If itemColor <> "transparent" And BackColor <> itemColor Then a.AddClass(itemColor & "-text") End If If itemIcon.length > 0 Then a.AddIcon(itemID & "icon", itemIcon,iconPos) End If If textVisible = True Then a.AddContent(itemText) Else a.AddContent("") End If a.AddContent(span.HTML) 'add to the pill li.AddContent(a.HTML) Return li.html End Sub 'replace the navbar Sub ReplaceNavBar(navBarID As String) IsFixed = True navBarID = navBarID.tolowercase 'ABM.ReplaceMyHTML(intPage,navBarID,Render) ABM.ReplaceMyInnerHTML(intPage,navBarID,Render) ABM.ReplaceMyInnerHTML(intPage,"sidenavbutton","") End Sub Sub RemoveSideBar ABM.ReplaceMyHTML(intPage,"sidenavbutton","") End Sub private Sub BuildDropDownItems As String Dim sb As StringBuilder sb.Initialize For Each drpItem As String In DropDownItems.Keys Dim lstItems As List = DropDownItems.Get(drpItem) drpItem = drpItem.tolowercase 'define the ul master for this drplist Dim ul As HTMLElement ul.Initialize(drpItem & "items","ul") ul.AddClass("dropdown-content") For Each strItem As String In lstItems ul.AddContent(strItem) Next sb.Append(ul.HTML) Next Return sb.tostring End Sub 'add an item to the dropdown Sub AddDropDownItem(parentID As String, itemID As String, itemIcon As String, iconPos As String, itemText As String, itemNavigateTo As String, itemColor As String, hasDivider As Boolean) itemID = itemID.tolowercase Dim item As String = BuildItem(itemID,itemIcon,iconPos,itemText,itemNavigateTo, False, itemColor, True) 'get the list of existing items parentID = parentID.ToLowerCase If DropDownItems.ContainsKey(parentID) Then Dim lstItems As List = DropDownItems.Get(parentID) lstItems.Add(item) DropDownItems.Put(parentID,lstItems) End If If hasDivider = True Then AddDropDownDivider(parentID) End Sub 'add an item to the navbar Sub AddLeftItem(itemID As String, itemIcon As String, iconPos As String, itemText As String, itemNavigateTo As String, itemColor As String, textVisible As Boolean, hasDivider As Boolean) Dim item As String = BuildItem(itemID,itemIcon,iconPos,itemText,itemNavigateTo,False, itemColor, textVisible) LeftItems.Add(item) If hasDivider = True Then AddLeftDivider End If End Sub Sub AddRightItem(itemID As String, itemIcon As String, iconPos As String, itemText As String, itemNavigateTo As String, itemColor As String, textVisible As Boolean, hasDivider As Boolean) Dim item As String = BuildItem(itemID,itemIcon,iconPos,itemText,itemNavigateTo,False, itemColor, textVisible) RightItems.Add(item) If hasDivider = True Then AddRightDivider End If End Sub 'add an item to the navbar Sub AddButton(btnID As String, btnIcon As String, btnIconPos As String, btnText As String, btnNavigateTo As String, btnColor As String, btnPos As String, hasDivider As Boolean) btnID = btnID.tolowercase 'define the item Dim btnSize As String = "medium" Dim li As HTMLElement li.Initialize(btnID, "li") 'add onclick method 'li.AddAttribute("onclick",$"navclick('${pgName.tolowercase}','${itemID}','${itemText}')"$) 'define the anchor Dim a As HTMLElement a.Initialize(btnID & "anchor","a") a.AddClass("waves-effect") a.AddClass("waves-light") If btnColor <> "transparent" And BackColor <> btnColor Then a.AddClass(btnColor & "-text") End If Select Case btnSize Case "small" a.AddClass("btn-small") Case "medium" a.AddClass("btn-medium") Case "large" a.AddClass("btn-large") Case Else a.AddClass("btn") End Select If btnIcon.length > 0 Then a.AddIcon(btnID & "icon", btnIcon,btnIconPos) End If a.AddContent(btnText) 'add to the pill li.AddContent(a.HTML) If btnPos.ToLowerCase = "right" Then RightItems.Add(li.html) If hasDivider = True Then AddRightDivider End If Else LeftItems.Add(li.html) If hasDivider = True Then AddLeftDivider End If End If End Sub ' runs when an object is created for the first time. Expects a valid html string ' will get surrounded by a div automatically ' in the html file: Sub ABMComp_Build(internalID As String) As String iID = internalID Return $""$ End Sub ' Is useful to run some initalisation script. Sub ABMComp_FirstRun(InternalPage As ABMPage, internalID As String) intPage = InternalPage 'build the chart here and initialize it HTML = Build(internalID) ABM.ReplaceMyHTML(InternalPage,internalID,HTML) InternalPage.ws.Eval("$('.dropdown-button').dropdown();", Null) 'InternalPage.ws.Eval("$('.button-collapse').sideNav();", Null) End Sub ' runs when a refresh is called Sub ABMComp_Refresh(InternalPage As ABMPage, internalID As String) intPage = InternalPage ' use these methods to adjust the object ' ABM.HasClass ' ABM.AddClass ' ABM.RemoveClass ' ABM.AddHTML ' ABM.InsertHTMLAfter ' ABM.RemoveHTML ' ABM.GetProperty ' ABM.SetProperty ' ABM.RemoveProperty ' ABM.GetStyleProperty ' ABM.SetStyleProperty 'set chart properties HTML = Build(internalID) ABM.ReplaceMyHTML(InternalPage,internalID,HTML) ' do some script stuff like you do in RunJavaScript InternalPage.ws.Eval("$('.dropdown-button').dropdown();", Null) 'InternalPage.ws.Eval("$('.button-collapse').sideNav();", Null) End Sub ' do the stuff needed when the object is removed Sub ABMComp_CleanUp(InternalPage As ABMPage, internalID As String) End Sub Sub Render() As String Return Build(iID) End Sub private Sub Build(xid As String) As String 'define the buttons to add Dim ulL As HTMLElement ulL.Initialize(xid & "-mobile","ul") ulL.AddClass("left") 'ul.AddClass("hide-on-med-and-down") For Each strButton As String In LeftItems ulL.AddContent(strButton) Next Dim ulR As HTMLElement ulR.Initialize(xid & "-mobile","ul") ulR.AddClass("right") 'ul.AddClass("hide-on-med-and-down") For Each strButton As String In RightItems ulR.AddContent(strButton) Next 'define the logo and title Dim a As HTMLElement a.Initialize(xid & "logo","a") a.AddAttribute("href","#") a.AddClass("brand-logo") a.AddClass(LogoPlacement) If LogoIcon.Length > 0 Then a.AddIcon(iID & "logoicon", LogoIcon,LogoIconPos) End If a.AddContent(Title) 'define the wrapper Dim navwrapper As HTMLElement navwrapper.Initialize("","div") navwrapper.AddClass("nav-wrapper") navwrapper.AddClass(BackColor) 'add the logo navwrapper.AddContent(a.HTML) 'add the menu Dim m As HTMLElement m.Initialize("","a") m.AddAttribute("href","#") m.AddAttribute("data-activates","mobile-demo") m.AddClass("button-collapse") m.AddClass(BackColor) m.AddIcon("","mdi-menu","") navwrapper.AddContent(m.HTML) 'add the buttons navwrapper.AddContent(ulL.HTML) navwrapper.AddContent(ulR.HTML) 'add search bar navwrapper.AddContent(searchBar) 'add the sidebar Dim sbar As HTMLElement sbar.Initialize(iID & "sidebar","ul") sbar.addclass("side-nav") 'navwrapper.AddContent(sbar.HTML) 'define the navbar first item Dim nav As HTMLElement nav.Initialize(xid,"nav") nav.AddClass(BackColor) If fabContent.Length > 0 Then nav.AddClass("nav-extended") End If nav.AddContent(navwrapper.HTML) nav.AddContent(fabContent) Dim sout As String 'the navbar is fixed If IsFixed = True Then Dim navfixed As HTMLElement navfixed.Initialize("","div") navfixed.AddClass("navbar-fixed") navfixed.AddClass(BackColor) navfixed.AddContent(nav.HTML) sout = navfixed.html Else sout = nav.HTML End If 'define the dropdownitems Dim drpItems As String = BuildDropDownItems sout = drpItems & sout Return sout End Sub