Input update
Restructured inputs to match rest of bridge also removed qbobject from clothing
This commit is contained in:
1 parent
7610cadf04
commit
7ea4c9c38c
8 files changed
+372
-121
No files matched your search
@@ -1,6 +1,44 @@
|
||||
local resourceName = "qb-input"
|
||||
local configValue = BridgeClientConfig.InputSystem
|
||||
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
|
||||
function QBTypeToOxType(_type)
|
||||
if _type == "text" then
|
||||
return "input"
|
||||
elseif _type == "password" then
|
||||
return "input"
|
||||
elseif _type == "number" then
|
||||
return "number"
|
||||
elseif _type == "radio" then
|
||||
return "checkbox"
|
||||
elseif _type == "checkbox" then
|
||||
return "checkbox"
|
||||
elseif _type == "select" then
|
||||
return "select"
|
||||
end
|
||||
end
|
||||
|
||||
function QBToOxInput(data)
|
||||
local returnData = {}
|
||||
for i, v in pairs(data) do
|
||||
local input = {
|
||||
label = v.text,
|
||||
name = i,
|
||||
type = QBTypeToOxType(v.type),
|
||||
required = v.isRequired,
|
||||
default = v.placeholder,
|
||||
}
|
||||
if v.type == "select" then
|
||||
input.options = {}
|
||||
for i, v in pairs(v.options) do
|
||||
table.insert(input.options, {value = v.value, label = v.text})
|
||||
end
|
||||
elseif v.type == "checkbox" then
|
||||
for i, v in pairs(v.options) do
|
||||
table.insert(returnData, {value = v.value, label = v.text})
|
||||
end
|
||||
end
|
||||
table.insert(returnData, input)
|
||||
end
|
||||
return returnData
|
||||
end
|
||||
|
||||
|
||||
function OxTypeToQBType(_type)
|
||||
if _type == "input" then
|
||||
@@ -58,35 +96,4 @@ function OxToQBInput(data)
|
||||
table.insert(returnData, input)
|
||||
end
|
||||
return returnData
|
||||
end
|
||||
|
||||
function OpenInput(title, data, isQBFormat, submitText)
|
||||
local input = data.inputs
|
||||
if not isQBFormat then
|
||||
input = OxToQBInput(data)
|
||||
end
|
||||
local returnData = exports['qb-input']:ShowInput({
|
||||
header = title,
|
||||
submitText = submitText or "Submit",
|
||||
inputs = input
|
||||
})
|
||||
if not returnData then return end
|
||||
if returnData[1] then return returnData end
|
||||
--converting to standard format (ox)
|
||||
local convertedData = {}
|
||||
if isQBFormat then
|
||||
for i, v in pairs(input) do
|
||||
for k, j in pairs(returnData) do
|
||||
if k == v.text then
|
||||
convertedData[tonumber(i)] = j
|
||||
end
|
||||
end
|
||||
end
|
||||
return convertedData
|
||||
end
|
||||
|
||||
for i, v in pairs(returnData) do
|
||||
convertedData[tonumber(i)] = v
|
||||
end
|
||||
return convertedData
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
if GetResourceState('ox_lib') ~= 'started' and GetResourceState('qb-menu') ~= 'started' then return end
|
||||
-- {
|
||||
-- if GetResourceState('ox_lib') ~= 'started' and GetResourceState('qb-menu') ~= 'started' then return end
|
||||
-- -- {
|
||||
-- header = "Test",
|
||||
-- submitText = "Bill",
|
||||
-- inputs = {
|
||||
@@ -76,38 +76,38 @@ if GetResourceState('ox_lib') ~= 'started' and GetResourceState('qb-menu') ~= 's
|
||||
--QB types: text, password, number, radio, checkbox, select,
|
||||
--
|
||||
-- "input", "number", "checkbox", "select", "multi-select", "slider", "color", "date", "date-range", "time", "textarea",
|
||||
Input = {}
|
||||
-- Input = {}
|
||||
|
||||
-- qb to ox
|
||||
--Open menu
|
||||
-- -- qb to ox
|
||||
-- --Open menu
|
||||
|
||||
function Input.Open(title, data, isQBFormat, submitText)
|
||||
if isQBFormat then
|
||||
local inputs = data.inputs
|
||||
if BridgeClientConfig.InputSystem == "ox" then
|
||||
return lib.inputDialog(title, QBToOxInput(inputs))
|
||||
elseif BridgeClientConfig.InputSystem == "qb" then
|
||||
return exports['qb-input']:ShowInput({
|
||||
header = title,
|
||||
submitText = submitText or "Submit",
|
||||
inputs = inputs
|
||||
})
|
||||
end
|
||||
else
|
||||
if BridgeClientConfig.InputSystem == "ox" then
|
||||
return lib.inputDialog(title, data)
|
||||
elseif BridgeClientConfig.InputSystem == "qb" then
|
||||
return exports['qb-input']:ShowInput({
|
||||
header = title,
|
||||
submitText = submitText or "Submit",
|
||||
inputs = OxToQBInput(data)
|
||||
})
|
||||
end
|
||||
end
|
||||
return OpenInput(title, data, isQBFormat, submitText)
|
||||
end
|
||||
-- function Input.Open(title, data, isQBFormat, submitText)
|
||||
-- if isQBFormat then
|
||||
-- local inputs = data.inputs
|
||||
-- if BridgeClientConfig.InputSystem == "ox" then
|
||||
-- return lib.inputDialog(title, QBToOxInput(inputs))
|
||||
-- elseif BridgeClientConfig.InputSystem == "qb" then
|
||||
-- return exports['qb-input']:ShowInput({
|
||||
-- header = title,
|
||||
-- submitText = submitText or "Submit",
|
||||
-- inputs = inputs
|
||||
-- })
|
||||
-- end
|
||||
-- else
|
||||
-- if BridgeClientConfig.InputSystem == "ox" then
|
||||
-- return lib.inputDialog(title, data)
|
||||
-- elseif BridgeClientConfig.InputSystem == "qb" then
|
||||
-- return exports['qb-input']:ShowInput({
|
||||
-- header = title,
|
||||
-- submitText = submitText or "Submit",
|
||||
-- inputs = OxToQBInput(data)
|
||||
-- })
|
||||
-- end
|
||||
-- end
|
||||
-- return OpenInput(title, data, isQBFormat, submitText)
|
||||
-- end
|
||||
|
||||
return Input
|
||||
-- return Input
|
||||
|
||||
|
||||
--[[
|
||||
@@ -1,53 +0,0 @@
|
||||
local resourceName = "ox_lib"
|
||||
local configValue = BridgeClientConfig.InputSystem
|
||||
if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end
|
||||
|
||||
function QBTypeToOxType(_type)
|
||||
if _type == "text" then
|
||||
return "input"
|
||||
elseif _type == "password" then
|
||||
return "input"
|
||||
elseif _type == "number" then
|
||||
return "number"
|
||||
elseif _type == "radio" then
|
||||
return "checkbox"
|
||||
elseif _type == "checkbox" then
|
||||
return "checkbox"
|
||||
elseif _type == "select" then
|
||||
return "select"
|
||||
end
|
||||
end
|
||||
|
||||
function QBToOxInput(data)
|
||||
local returnData = {}
|
||||
for i, v in pairs(data) do
|
||||
local input = {
|
||||
label = v.text,
|
||||
name = i,
|
||||
type = QBTypeToOxType(v.type),
|
||||
required = v.isRequired,
|
||||
default = v.placeholder,
|
||||
}
|
||||
if v.type == "select" then
|
||||
input.options = {}
|
||||
for i, v in pairs(v.options) do
|
||||
table.insert(input.options, {value = v.value, label = v.text})
|
||||
end
|
||||
elseif v.type == "checkbox" then
|
||||
for i, v in pairs(v.options) do
|
||||
table.insert(returnData, {value = v.value, label = v.text})
|
||||
end
|
||||
end
|
||||
table.insert(returnData, input)
|
||||
end
|
||||
return returnData
|
||||
end
|
||||
|
||||
function OpenInput(title, data, isQBFormat, submitText)
|
||||
local inputs = data.inputs
|
||||
if isQBFormat then
|
||||
return lib.inputDialog(title, QBToOxInput(inputs))
|
||||
else
|
||||
return lib.inputDialog(title, data)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,47 @@
|
||||
local resourceName = "qb-input"
|
||||
local configValue = BridgeClientConfig.InputSystem
|
||||
if (configValue == "auto" and GetResourceState(resourceName) == "missing") or (configValue ~= "auto" and configValue ~= resourceName) then return end
|
||||
|
||||
Input = {}
|
||||
|
||||
|
||||
-- this probably needs improvement
|
||||
function Input.Open(title, data, isQBFormat, submitText)
|
||||
local input = data.inputs
|
||||
if not isQBFormat then
|
||||
input = OxToQBInput(data)
|
||||
end
|
||||
local returnData = exports['qb-input']:ShowInput({
|
||||
header = title,
|
||||
submitText = submitText or "Submit",
|
||||
inputs = input
|
||||
})
|
||||
if not returnData then return end
|
||||
print(json.encode(returnData))
|
||||
if returnData[1] then return returnData end
|
||||
--converting to standard format (ox)
|
||||
local convertedData = {}
|
||||
if isQBFormat then
|
||||
for i, v in pairs(input) do
|
||||
print("Converting input: " .. v.name)
|
||||
for k, j in pairs(returnData) do
|
||||
if k == v.name then
|
||||
convertedData[tonumber(i)] = j
|
||||
end
|
||||
end
|
||||
end
|
||||
return convertedData
|
||||
end
|
||||
|
||||
for i, v in pairs(returnData) do
|
||||
local index = i and tonumber(i)
|
||||
if not index then
|
||||
table.insert(convertedData, v)
|
||||
else
|
||||
convertedData[index] = v
|
||||
end
|
||||
end
|
||||
return convertedData
|
||||
end
|
||||
|
||||
return Input
|
||||
@@ -0,0 +1,16 @@
|
||||
local resourceName = "ox_lib"
|
||||
local configValue = BridgeClientConfig.InputSystem
|
||||
if (configValue == "auto" and GetResourceState(resourceName) == "missing") or (configValue ~= "auto" and configValue ~= resourceName) then return end
|
||||
|
||||
Input = {}
|
||||
function Input.Open(title, data, isQBFormat, submitText)
|
||||
local inputs = data.inputs
|
||||
if isQBFormat then
|
||||
return lib.inputDialog(title, QBToOxInput(inputs))
|
||||
else
|
||||
return lib.inputDialog(title, data)
|
||||
end
|
||||
end
|
||||
|
||||
return Input
|
||||
|
||||
Reference in new issue
Block a user