Sub BuildModalSheet() As ABMModalSheet
Dim myModal As ABMModalSheet
myModal.Initialize(page, "myModal", False, ABM.MODALSHEET_TYPE_NORMAL, "mymodal")
myModal.Content.UseTheme("mymodal")
myModal.Footer.UseTheme("mymodal")
myModal.Size = ABM.MODALSHEET_SIZE_NORMAL
myModal.IsDismissible = False
FieldList.Initialize
FieldIndex = FieldIndex + 1
' create the grid for the content
myModal.Content.AddRows(1,True, "").AddCells12(5,"centre")
' ALAIN: Add one row with one cell. We will add all our Field containers in this cell
' this way, we do not have to add rows dynamically
myModal.Content.AddRows(1,True, "").AddCellsOSMPV(1,0,0,0,12,12,12,0,0,0,0,ABM.VISIBILITY_ALL, "centre")
myModal.Content.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
' add paragraph
myModal.Content.Cell(1,1).AddComponent(ABMShared.BuildParagraph(page,"par1","Enter Field Name and Field Type to Create Database Table"))
Dim googleInp As ABMInput
googleInp.Initialize(page, "tablename", ABM.INPUT_TEXT, "Enter Table Name", False, "input")
googleInp.AutoCompleteType = ABM.AUTOCOMPLETE_GOOGLE
myModal.Content.Cell(1,1).AddComponent(googleInp)
' ALAIN: we add our first field box. Note: we do not use AddArrayComponent here for the container
myModal.Content.Cell(2,1).AddComponent(BuildFieldBox)
' create the grid for the footer
' we add a row without the default 20px padding so we need to use AddRowsM(). If we do not use this method, a scrollbar will appear to the sheet.
myModal.Footer.AddRowsM(1,True,0,0, "").AddCellsOS(1,2,6,6,3,3,3,"modalsheet").AddCellsOS(1,4,0,0,3,3,3, "modalsheet")
myModal.Footer.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
' create the buttons for the footer
Dim msbtn1 As ABMButton
msbtn1.InitializeFlat(page, "msbtn1", "", "", "CREATE", "transparent")
myModal.Footer.Cell(1,1).AddComponent(msbtn1)
Dim msbtn2 As ABMButton
msbtn2.InitializeFlat(page, "msbtn2", "", "", "CANCEL", "transparent")
myModal.Footer.Cell(1,2).AddComponent(msbtn2)
Return myModal
End Sub
' ALAIN: Building a Field box container
Sub BuildFieldBox() As ABMContainer
Dim cont As ABMContainer
cont.Initialize(page, "cont" & FieldIndex, "")
cont.AddRows(1,False, "").AddCellsOSMPV(4,-1,0,0,4,3,3,0,0,0,0,ABM.VISIBILITY_ALL, "centre")
cont.BuildGrid
' create the input fields for the content
' ALAIN: For all the components in the Field box container, we add them using AddArrayCompoent.
' It is then easier to handle the events
Dim inp1 As ABMInput
inp1.Initialize(page, FieldIndex, ABM.INPUT_TEXT, "FieldName", False, "input") ' <------- Do NOT give it a name here, just an index
inp1.Tag = FieldIndex&",1"
inp1.PlaceHolderText = "FieldName"
cont.Cell(1,1).AddArrayComponent(inp1, "inp") ' <------ Here we give it a name
Dim fieldType As ABMCombo
fieldType.Initialize(page, FieldIndex, "FieldType", 350, "combo")
fieldType.Tag = FieldIndex&",2"
fieldType.AddItem("0", "TEXT",BuildSimpleItem("0", "", "TEXT"))
fieldType.AddItem("1", "INTEGER", BuildSimpleItem("1", "", "INTEGER"))
fieldType.AddItem("2", "BLOB", BuildSimpleItem("2", "", "BLOB"))
fieldType.AddItem("3", "REAL", BuildSimpleItem("3", "", "REAL"))
cont.Cell(1,2).AddArrayComponent(fieldType, "ftype")
Dim primarykey As ABMCheckbox
primarykey.Initialize(page, FieldIndex, "Make Primary Key", False, "")
primarykey.Tag = FieldIndex&",3"
cont.Cell(1,3).MarginTop = "30px"
cont.Cell(1,3).AddArrayComponent(primarykey, "chkbox")
Dim btnfieldadd As ABMButton
btnfieldadd.InitializeFloating(page, FieldIndex, "mdi-content-add", "right")
btnfieldadd.Size = ABM.BUTTONSIZE_NORMAL
btnfieldadd.Tag = "2,4"
cont.cell(1,4).UseTheme("right")
cont.Cell(1,4).AddArrayComponent(btnfieldadd, "btnfieldadd")
' ALAIN: if it is not the first one, add a Delete button
If FieldIndex > 1 Then
Dim btnfielddelete As ABMButton
btnfielddelete.InitializeFloating(page, FieldIndex, "mdi-action-delete", "right")
btnfielddelete.Size = ABM.BUTTONSIZE_NORMAL
btnfielddelete.Tag = FieldIndex&",4"
cont.Cell(1,4).UseTheme("right")
cont.Cell(1,4).AddArrayComponent(btnfielddelete, "btnfielddelete")
End If
' ALAIN: increment the FieldIndex
FieldIndex = FieldIndex + 1
Return cont
End Sub
' ALAIN:
Sub btnfieldadd_Clicked(Target As String)
' extract the index from the target (here target is e.g. cont1-btnfieldadd1 so we want to have 1)
Dim index As Int = Target.IndexOf("add")
index = Target.SubString(index + 3)
Log(index)
Dim myModal As ABMModalSheet = page.ModalSheet("myModal")
' remove buttons from the previous one
Dim contPrev As ABMContainer = myModal.Content.Component("cont" & index)
contPrev.Cell(1,4).RemoveAllComponents
contPrev.Cell(1,4).Refresh
' add a new Field Box
myModal.Content.Cell(2,1).AddComponent(BuildFieldBox)
myModal.Refresh
End Sub