Private Sub ShowDialog2 (Action As String, Item As Map)
If Action = "Add" Then
PrefDialog2.Dialog.TitleBarColor = xui.Color_RGB(50, 205, 50)
Else
PrefDialog2.Dialog.TitleBarColor = xui.Color_RGB(65, 105, 225)
End If
PrefDialog2.Title = Action & " Product"
Dim sf As Object = PrefDialog2.ShowDialog(Item, "OK", "CANCEL")
Sleep(0)
PrefDialog2.CustomListView1.sv.Height = PrefDialog2.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
PrefDialog2.CustomListView1.GetPanel(0).GetView(0).Color = xui.Color_Transparent
PrefDialog2.CustomListView1.sv.ScrollViewInnerPanel.Color = xui.Color_Transparent
' Fix Linux UI
#if B4J
' Dim btnCancel As B4XView = PrefDialog2.Dialog.GetButton(xui.DialogResponse_Cancel)
' btnCancel.Width = btnCancel.Width + 20dip
' btnCancel.Left = btnCancel.Left - 20dip
' btnCancel.TextColor = xui.Color_Red
' Dim btnOk As B4XView = PrefDialog2.Dialog.GetButton(xui.DialogResponse_Positive)
' btnOk.Left = btnOk.Left - 20dip
#End If
Wait For (sf) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
If 0 = Item.Get("id") Then ' New row
CategoryId = GetCategoryId(Item.Get("Category"))
Dim ProductMap As Map = CreateMap("code": Item.Get("Product Code"), "name": Item.Get("Product Name"), "price": Item.Get("Product Price"))
Dim sd As Object = SendData("POST", $"category/${CategoryId}/product"$, ProductMap)
Wait For (sd) Complete (Data As Map)
If Data.Get("s") = "ok" Then
'Log(Data.Get("a")) ' 201 Created
Dim l As List = Data.Get("r")
Dim m As Map = l.Get(0)
xui.MsgboxAsync("New product created!", $"ID: ${m.Get("id")}"$)
Else
xui.MsgboxAsync(Data.Get("e"), "Error")
End If
Else
Dim NewCategoryId As Long = GetCategoryId(Item.Get("Category"))
Dim ProductMap As Map = CreateMap("cat_id": NewCategoryId, "code": Item.Get("Product Code"), "name": Item.Get("Product Name"), "price": Item.Get("Product Price"))
Dim sd As Object = SendData("PUT", $"category/${CategoryId}/product/${Item.Get("id")}"$, ProductMap)
Wait For (sd) Complete (Data As Map)
If Data.Get("s") = "ok" Then
xui.MsgboxAsync("Product updated!", "Edit")
CategoryId = NewCategoryId
Else
xui.MsgboxAsync(Data.Get("e"), "Error")
End If
End If
GetProducts
Else
Return
End If
End Sub