2023-03-31 18:47:36 +03:00
|
|
|
-- translation
|
|
|
|
local S = minetest.get_translator("mail")
|
|
|
|
|
2023-03-29 18:25:01 +03:00
|
|
|
local FORMNAME = "mail:maillists"
|
|
|
|
|
|
|
|
local maillists_formspec = "size[8,9;]" .. mail.theme .. [[
|
2023-03-29 20:23:16 +03:00
|
|
|
button[6,0.10;2,0.5;new;]] .. S("New") .. [[]
|
|
|
|
button[6,0.85;2,0.5;edit;]] .. S("Edit") .. [[]
|
|
|
|
button[6,1.60;2,0.5;delete;]] .. S("Delete") .. [[]
|
|
|
|
button[6,8.25;2,0.5;back;]] .. S("Back") .. [[]
|
2023-03-29 18:25:01 +03:00
|
|
|
tablecolumns[color;text;text]
|
2023-03-29 20:23:16 +03:00
|
|
|
table[0,0;5.75,9;maillists;#999,]] .. S("Name") .. "," .. S("Note")
|
2023-03-29 18:25:01 +03:00
|
|
|
|
|
|
|
function mail.show_maillists(name)
|
|
|
|
local formspec = { maillists_formspec }
|
|
|
|
local maillists = mail.get_maillists(name)
|
|
|
|
|
|
|
|
if maillists[1] then
|
|
|
|
for _, maillist in ipairs(maillists) do
|
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
formspec[#formspec + 1] = "@" .. minetest.formspec_escape(maillist.name)
|
|
|
|
formspec[#formspec + 1] = ","
|
|
|
|
if maillist.desc ~= "" then
|
|
|
|
if string.len(maillist.desc) > 30 then
|
|
|
|
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(maillist.desc, 1, 27))
|
|
|
|
formspec[#formspec + 1] = "..."
|
|
|
|
else
|
|
|
|
formspec[#formspec + 1] = minetest.formspec_escape(maillist.desc)
|
|
|
|
end
|
|
|
|
else
|
2023-03-29 20:23:16 +03:00
|
|
|
formspec[#formspec + 1] = S("(No description)")
|
2023-03-29 18:25:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if mail.selected_idxs.maillists[name] then
|
|
|
|
formspec[#formspec + 1] = ";"
|
|
|
|
formspec[#formspec + 1] = mail.selected_idxs.maillists[name]
|
|
|
|
end
|
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
else
|
2023-03-29 20:23:16 +03:00
|
|
|
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No maillist") .. "]"
|
2023-03-29 18:25:01 +03:00
|
|
|
end
|
|
|
|
minetest.show_formspec(name, FORMNAME, table.concat(formspec, ""))
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
if formname ~= FORMNAME then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local maillists = mail.get_maillists(name)
|
|
|
|
|
|
|
|
if fields.maillists then
|
|
|
|
local evt = minetest.explode_table_event(fields.maillists)
|
|
|
|
mail.selected_idxs.maillists[name] = evt.row - 1
|
|
|
|
if evt.type == "DCL" and maillists[mail.selected_idxs.maillists[name]] then
|
|
|
|
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.maillists[name]].name)
|
|
|
|
local players_string = mail.concat_player_list(maillist.players)
|
|
|
|
mail.show_edit_maillist(
|
|
|
|
name,
|
|
|
|
maillists[mail.selected_idxs.maillists[name]].name,
|
|
|
|
maillists[mail.selected_idxs.maillists[name]].desc,
|
|
|
|
players_string
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif fields.new then
|
|
|
|
mail.selected_idxs.maillists[name] = "#NEW#"
|
|
|
|
mail.show_edit_maillist(name, "", "", "Player1, Player2, Player3")
|
|
|
|
|
|
|
|
elseif fields.edit and maillists[mail.selected_idxs.maillists[name]] then
|
|
|
|
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.maillists[name]].name)
|
|
|
|
local players_string = mail.concat_player_list(maillist.players)
|
|
|
|
mail.show_edit_maillist(
|
|
|
|
name,
|
|
|
|
maillists[mail.selected_idxs.maillists[name]].name,
|
|
|
|
maillists[mail.selected_idxs.maillists[name]].desc,
|
|
|
|
players_string
|
|
|
|
)
|
|
|
|
|
|
|
|
elseif fields.delete then
|
|
|
|
if maillists[mail.selected_idxs.maillists[name]] then
|
|
|
|
-- delete the maillist and set the selected to the next in the list,
|
|
|
|
-- except if it was the last. Then determine the new last
|
|
|
|
local found = false
|
|
|
|
local last = nil
|
|
|
|
for k in mail.pairsByKeys(maillists) do
|
|
|
|
if found then
|
|
|
|
mail.selected_idxs.maillists[name] = k
|
|
|
|
break
|
|
|
|
elseif k == mail.selected_idxs.maillists[name] then
|
2023-04-02 11:37:58 +03:00
|
|
|
mail.delete_maillist(name, maillists[mail.selected_idxs.maillists[name]].name)
|
2023-03-29 18:25:01 +03:00
|
|
|
mail.selected_idxs.maillists[name] = nil
|
|
|
|
found = true
|
|
|
|
else
|
|
|
|
last = k
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if found and not mail.selected_idxs.maillists[name] then
|
|
|
|
-- was the last in the list, so take the previous (new last)
|
|
|
|
mail.selected_idxs.maillists[name] = last
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mail.show_maillists(name)
|
|
|
|
|
|
|
|
elseif fields.back then
|
|
|
|
mail.show_mail_menu(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
2023-03-29 20:23:16 +03:00
|
|
|
end)
|