fix delete barcode functionality; fix styling of product menus

This commit is contained in:
Riley L. 2025-01-02 00:40:33 +01:00
parent 5be820b181
commit 0b975df3e4
3 changed files with 27 additions and 16 deletions

View file

@ -698,6 +698,26 @@ end
local function r_products_post()
local data = form_data()
if data.deletebarcode then
local barcode = data.barcode
-- remove barcode
local new_barcodes = io.open("barcodes.new", "w+")
if new_barcodes == nil then
return error_box("{+error.open_new_barcodes}")
end
for name, a_barcode in read_barcodes() do
if barcode ~= a_barcode then
new_barcodes:write(string.format("%s,%s\n", name, a_barcode))
end
end
new_barcodes:flush()
new_barcodes:close()
os.rename("barcodes.new", "barcodes")
return
end
local name = data.name
if name == nil or name:match("^[%w_-]*$") == nil then
return error_box("{+error.invalid_name}")
@ -710,7 +730,7 @@ local function r_products_post()
end
for price, user, a_name in read_products() do
if name ~= a_name then
new_products:write(string.format("%d,%s,%s\n", price, user, name))
new_products:write(string.format("%d,%s,%s\n", price, user, a_name))
end
end
new_products:flush()
@ -785,7 +805,7 @@ local function r_products()
currency = config.unit or "",
}))
for _, _, name in read_products() do
print(format([[<option name="{name}">{name}</option>]], {
print(format([[<option value="{name}">{name}</option>]], {
name = name,
}))
end
@ -804,7 +824,7 @@ local function r_products()
currency = config.unit or "",
}))
for _, _, name in read_products() do
print(format([[<option name="{name}">{!name}</option>]], {
print(format([[<option value="{name}">{!name}</option>]], {
name = name,
}))
end
@ -814,7 +834,7 @@ local function r_products()
<!-- remove barcode -->
<form action="/?products" method="POST" class="box backgroundbox">
<h3>{+products.form.removebarcode}</h3>
<input type="text" name="delete" value="1" hidden />
<input type="text" name="deletebarcode" value="1" hidden />
<label for="barcode">{+field.barcode}: </label>
<select type="text" name="barcode" id="barcode">
]], {
@ -823,7 +843,7 @@ local function r_products()
local barcodes = {}
for name, barcode in read_barcodes() do
print(format([[<option name="{barcode}">{!barcode} ({!name})</option>]], {
print(format([[<option value="{barcode}">{!barcode} ({!name})</option>]], {
name = name,
barcode = barcode,
}))
@ -835,13 +855,6 @@ local function r_products()
end
end
for a, b in pairs(barcodes) do
print("name: " .. a)
for _, c in pairs(b) do
print("\t"..c)
end
end
print(format([[</select>
<input type="submit" value="{+products.form.remove.submit}" class="amount-ntr button" />
</form>

View file

@ -67,6 +67,7 @@ error.invalid_user=Username invalid
error.open_log=Failed to open log file
error.invalid_barcode=Barcode invalid
error.open_new_products=Failed to open new products file
error.open_new_barcodes=Failed to open new barcodes file
error.invalid_price=Price invalid
error.invalid_name=Name invalid
error.open_products=Failed to open products file

View file

@ -31,10 +31,7 @@ body>* {
}
.container {
display: grid;
flex-direction: column;
justify-content: left;
grid-template-columns: auto auto;
display: ruby;
list-style-type: none;
}