Move owned mailing lists in separated tab, prepare formspecs for public lists
This commit is contained in:
parent
f5198b9187
commit
e6be2f44bb
5
init.lua
5
init.lua
@ -18,7 +18,8 @@ mail = {
|
||||
drafts = {},
|
||||
trash = {},
|
||||
contacts = {},
|
||||
maillists = {},
|
||||
mailliststab = {},
|
||||
owned_maillists = {},
|
||||
to = {},
|
||||
cc = {},
|
||||
bcc = {},
|
||||
@ -67,6 +68,8 @@ dofile(MP .. "/ui/contacts.lua")
|
||||
dofile(MP .. "/ui/edit_contact.lua")
|
||||
dofile(MP .. "/ui/select_contact.lua")
|
||||
dofile(MP .. "/ui/maillists.lua")
|
||||
dofile(MP .. "/ui/owned_maillists.lua")
|
||||
dofile(MP .. "/ui/public_maillists.lua")
|
||||
dofile(MP .. "/ui/edit_maillists.lua")
|
||||
dofile(MP .. "/ui/compose.lua")
|
||||
dofile(MP .. "/ui/options.lua")
|
||||
|
@ -327,7 +327,7 @@ end
|
||||
-- returns the maillists of a player
|
||||
function mail.get_maillists(playername)
|
||||
local entry = mail.get_storage_entry(playername)
|
||||
return entry.lists
|
||||
return entry.lists or {}
|
||||
end
|
||||
|
||||
-- returns the maillists of a player
|
||||
@ -340,6 +340,10 @@ function mail.get_maillist_by_name(playername, listname)
|
||||
end
|
||||
end
|
||||
|
||||
function mail.get_public_maillists()
|
||||
return {} -- before implementing the scan
|
||||
end
|
||||
|
||||
-- updates or creates a maillist
|
||||
function mail.update_maillist(playername, list, old_list_name)
|
||||
local entry = mail.get_storage_entry(playername)
|
||||
|
@ -3,12 +3,20 @@ local S = minetest.get_translator("mail")
|
||||
|
||||
local FORMNAME = "mail:editmaillist"
|
||||
|
||||
function mail.show_edit_maillist(playername, maillist_name, desc, players, illegal_name_hint)
|
||||
function mail.show_edit_maillist(playername, maillist_name, desc, players, is_public, illegal_name_hint)
|
||||
local maillist = mail.get_maillist_by_name(playername, maillist_name) or {}
|
||||
local public_list = 1
|
||||
if not is_public and not maillist.is_public then
|
||||
public_list = 2
|
||||
end
|
||||
|
||||
local formspec = [[
|
||||
size[6,7]
|
||||
button[4,6.25;2,0.5;back;]] .. S("Back") .. [[]
|
||||
field[0.25,0.5;4,1;name;]] .. S("Maillist name") .. [[:;%s]
|
||||
textarea[0.25,1.6;4,2;desc;]] .. S("Desc") .. [[:;%s]
|
||||
dropdown[4,1.62;2,0.5;public_list;]] ..
|
||||
S("Public") .. "," .. S("Private") .. [[;]] .. public_list .. [[;true]
|
||||
textarea[0.25,3.6;4,4.25;players;]] .. S("Players") .. [[:;%s]
|
||||
button[4,0.10;2,1;save;]] .. S("Save") .. [[]
|
||||
]]
|
||||
@ -40,16 +48,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local maillists = mail.get_maillists(name)
|
||||
|
||||
if fields.save then
|
||||
local old_maillist = maillists[mail.selected_idxs.maillists[name]] or {name = ""}
|
||||
if mail.selected_idxs.maillists[name] then
|
||||
local old_maillist = maillists[mail.selected_idxs.owned_maillists[name]] or {name = ""}
|
||||
local is_public = fields.public_list == "1"
|
||||
if mail.selected_idxs.owned_maillists[name] then
|
||||
if old_maillist.name ~= fields.name or fields.name == "" then
|
||||
-- name changed!
|
||||
if #fields.name == 0 then
|
||||
mail.show_edit_maillist(name, old_maillist.name, fields.desc, fields.players, "empty")
|
||||
mail.show_edit_maillist(name, old_maillist.name, fields.desc, fields.players, is_public, "empty")
|
||||
return true
|
||||
|
||||
elseif mail.get_maillist_by_name(name, fields.name) then
|
||||
mail.show_edit_maillist(name, old_maillist.name, fields.desc, fields.players, "collision")
|
||||
mail.show_edit_maillist(name, old_maillist.name, fields.desc, fields.players, is_public, "collision")
|
||||
return true
|
||||
|
||||
else
|
||||
@ -57,15 +66,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
owner = name,
|
||||
name = fields.name,
|
||||
desc = fields.desc,
|
||||
is_public = is_public,
|
||||
players = mail.parse_player_list(fields.players)
|
||||
}, old_maillist.name)
|
||||
maillists[mail.selected_idxs.maillists[name]] = nil
|
||||
maillists[mail.selected_idxs.owned_maillists[name]] = nil
|
||||
end
|
||||
else
|
||||
mail.update_maillist(name, {
|
||||
owner = name,
|
||||
name = fields.name,
|
||||
desc = fields.desc,
|
||||
is_public = is_public,
|
||||
players = mail.parse_player_list(fields.players)
|
||||
}, old_maillist.name)
|
||||
end
|
||||
@ -74,6 +85,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
owner = name,
|
||||
name = fields.name,
|
||||
desc = fields.desc,
|
||||
is_public = is_public,
|
||||
players = mail.parse_player_list(fields.players)
|
||||
}, old_maillist.name)
|
||||
end
|
||||
|
122
ui/maillists.lua
122
ui/maillists.lua
@ -1,113 +1,13 @@
|
||||
-- translation
|
||||
local S = minetest.get_translator("mail")
|
||||
-- helper function for tabbed mailing lists
|
||||
|
||||
local FORMNAME = "mail:maillists"
|
||||
|
||||
local maillists_formspec = "size[8,9;]" .. mail.theme .. [[
|
||||
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") .. [[]
|
||||
tablecolumns[color;text;text]
|
||||
table[0,0;5.75,9;maillists;#999,]] .. S("Name") .. "," .. S("Note")
|
||||
|
||||
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
|
||||
formspec[#formspec + 1] = S("(No description)")
|
||||
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
|
||||
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No maillist") .. "]"
|
||||
end
|
||||
minetest.show_formspec(name, FORMNAME, table.concat(formspec, ""))
|
||||
function mail.show_maillists(playername)
|
||||
local index = mail.selected_idxs.mailliststab[playername] or 1
|
||||
if not mail.selected_idxs.mailliststab[playername] then
|
||||
mail.selected_idxs.mailliststab[playername] = 1
|
||||
end
|
||||
if index == 1 then
|
||||
mail.show_owned_maillists(playername)
|
||||
elseif index == 2 then
|
||||
mail.show_public_maillists(playername)
|
||||
end
|
||||
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
|
||||
mail.delete_maillist(name, maillists[mail.selected_idxs.maillists[name]].name)
|
||||
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
|
||||
end)
|
||||
|
123
ui/owned_maillists.lua
Normal file
123
ui/owned_maillists.lua
Normal file
@ -0,0 +1,123 @@
|
||||
-- translation
|
||||
local S = minetest.get_translator("mail")
|
||||
|
||||
local FORMNAME = "mail:maillists"
|
||||
|
||||
local owned_maillists_formspec = "size[8,9;]" .. mail.theme .. [[
|
||||
tabheader[0.3,1;mailliststab;]] .. S("Owned lists") .. "," .. S("Public lists") .. [[;1;false;false]
|
||||
|
||||
button[6,0.80;2,0.5;new;]] .. S("New") .. [[]
|
||||
button[6,1.55;2,0.5;edit;]] .. S("Edit") .. [[]
|
||||
button[6,2.30;2,0.5;delete;]] .. S("Delete") .. [[]
|
||||
button[6,8.4;2,0.5;back;]] .. S("Back") .. [[]
|
||||
tablecolumns[color;text;text]
|
||||
table[0,0.7;5.75,8.3;maillists;#999,]] .. S("Name") .. "," .. S("Desc")
|
||||
|
||||
function mail.show_owned_maillists(name)
|
||||
local formspec = { owned_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
|
||||
formspec[#formspec + 1] = S("(No description)")
|
||||
end
|
||||
end
|
||||
if mail.selected_idxs.owned_maillists[name] then
|
||||
formspec[#formspec + 1] = ";"
|
||||
formspec[#formspec + 1] = mail.selected_idxs.owned_maillists[name]
|
||||
end
|
||||
formspec[#formspec + 1] = "]"
|
||||
else
|
||||
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No maillist") .. "]"
|
||||
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.owned_maillists[name] = evt.row - 1
|
||||
if evt.type == "DCL" and maillists[mail.selected_idxs.owned_maillists[name]] then
|
||||
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.owned_maillists[name]].name)
|
||||
local players_string = mail.concat_player_list(maillist.players)
|
||||
mail.show_edit_maillist(
|
||||
name,
|
||||
maillists[mail.selected_idxs.owned_maillists[name]].name,
|
||||
maillists[mail.selected_idxs.owned_maillists[name]].desc,
|
||||
players_string
|
||||
)
|
||||
end
|
||||
|
||||
elseif fields.new then
|
||||
mail.selected_idxs.owned_maillists[name] = "#NEW#"
|
||||
mail.show_edit_maillist(name, "", "", "Player1, Player2, Player3")
|
||||
|
||||
elseif fields.edit and maillists[mail.selected_idxs.owned_maillists[name]] then
|
||||
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.owned_maillists[name]].name)
|
||||
local players_string = mail.concat_player_list(maillist.players)
|
||||
mail.show_edit_maillist(
|
||||
name,
|
||||
maillists[mail.selected_idxs.owned_maillists[name]].name,
|
||||
maillists[mail.selected_idxs.owned_maillists[name]].desc,
|
||||
players_string
|
||||
)
|
||||
|
||||
elseif fields.delete then
|
||||
if maillists[mail.selected_idxs.owned_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.owned_maillists[name] = k
|
||||
break
|
||||
elseif k == mail.selected_idxs.owned_maillists[name] then
|
||||
mail.delete_maillist(name, maillists[mail.selected_idxs.owned_maillists[name]].name)
|
||||
mail.selected_idxs.owned_maillists[name] = nil
|
||||
found = true
|
||||
else
|
||||
last = k
|
||||
end
|
||||
end
|
||||
if found and not mail.selected_idxs.owned_maillists[name] then
|
||||
-- was the last in the list, so take the previous (new last)
|
||||
mail.selected_idxs.owned_maillists[name] = last
|
||||
end
|
||||
end
|
||||
|
||||
mail.show_maillists(name)
|
||||
|
||||
elseif fields.mailliststab == "1" then
|
||||
mail.selected_idxs.mailliststab[name] = 1
|
||||
mail.show_owned_maillists(name)
|
||||
|
||||
elseif fields.mailliststab == "2" then
|
||||
mail.selected_idxs.mailliststab[name] = 2
|
||||
mail.show_public_maillists(name)
|
||||
|
||||
elseif fields.back then
|
||||
mail.show_mail_menu(name)
|
||||
end
|
||||
|
||||
return true
|
||||
end)
|
123
ui/public_maillists.lua
Normal file
123
ui/public_maillists.lua
Normal file
@ -0,0 +1,123 @@
|
||||
-- translation
|
||||
local S = minetest.get_translator("mail")
|
||||
|
||||
local FORMNAME = "mail:maillists"
|
||||
|
||||
local public_maillists_formspec = "size[8,9;]" .. mail.theme .. [[
|
||||
tabheader[0.3,1;mailliststab;]] .. S("Owned lists") .. "," .. S("Public lists") .. [[;2;false;false]
|
||||
|
||||
button[6,0.80;2,0.5;new;]] .. S("New") .. [[]
|
||||
button[6,1.55;2,0.5;edit;]] .. S("Edit") .. [[]
|
||||
button[6,2.30;2,0.5;delete;]] .. S("Delete") .. [[]
|
||||
button[6,8.4;2,0.5;back;]] .. S("Back") .. [[]
|
||||
tablecolumns[color;text;text;text;text]
|
||||
table[0,0.7;5.75,8.3;maillists;#999,]] .. S("Name") .. "," .. S("Owned") .. "," .. S("Desc") .. ","
|
||||
|
||||
function mail.show_public_maillists(name)
|
||||
local formspec = { public_maillists_formspec }
|
||||
local maillists = mail.get_public_maillists()
|
||||
|
||||
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
|
||||
formspec[#formspec + 1] = S("(No description)")
|
||||
end
|
||||
end
|
||||
if mail.selected_idxs.owned_maillists[name] then
|
||||
formspec[#formspec + 1] = ";"
|
||||
formspec[#formspec + 1] = mail.selected_idxs.owned_maillists[name]
|
||||
end
|
||||
formspec[#formspec + 1] = "]"
|
||||
else
|
||||
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No maillist") .. "]"
|
||||
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.owned_maillists[name] = evt.row - 1
|
||||
if evt.type == "DCL" and maillists[mail.selected_idxs.owned_maillists[name]] then
|
||||
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.owned_maillists[name]].name)
|
||||
local players_string = mail.concat_player_list(maillist.players)
|
||||
mail.show_edit_maillist(
|
||||
name,
|
||||
maillists[mail.selected_idxs.owned_maillists[name]].name,
|
||||
maillists[mail.selected_idxs.owned_maillists[name]].desc,
|
||||
players_string
|
||||
)
|
||||
end
|
||||
|
||||
elseif fields.new then
|
||||
mail.selected_idxs.owned_maillists[name] = "#NEW#"
|
||||
mail.show_edit_maillist(name, "", "", "Player1, Player2, Player3")
|
||||
|
||||
elseif fields.edit and maillists[mail.selected_idxs.owned_maillists[name]] then
|
||||
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.owned_maillists[name]].name)
|
||||
local players_string = mail.concat_player_list(maillist.players)
|
||||
mail.show_edit_maillist(
|
||||
name,
|
||||
maillists[mail.selected_idxs.owned_maillists[name]].name,
|
||||
maillists[mail.selected_idxs.owned_maillists[name]].desc,
|
||||
players_string
|
||||
)
|
||||
|
||||
elseif fields.delete then
|
||||
if maillists[mail.selected_idxs.owned_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.owned_maillists[name] = k
|
||||
break
|
||||
elseif k == mail.selected_idxs.owned_maillists[name] then
|
||||
mail.delete_maillist(name, maillists[mail.selected_idxs.owned_maillists[name]].name)
|
||||
mail.selected_idxs.owned_maillists[name] = nil
|
||||
found = true
|
||||
else
|
||||
last = k
|
||||
end
|
||||
end
|
||||
if found and not mail.selected_idxs.owned_maillists[name] then
|
||||
-- was the last in the list, so take the previous (new last)
|
||||
mail.selected_idxs.owned_maillists[name] = last
|
||||
end
|
||||
end
|
||||
|
||||
mail.show_maillists(name)
|
||||
|
||||
elseif fields.mailliststab == "1" then
|
||||
mail.selected_idxs.mailliststab[name] = 1
|
||||
mail.show_owned_maillists(name)
|
||||
|
||||
elseif fields.mailliststab == "2" then
|
||||
mail.selected_idxs.mailliststab[name] = 2
|
||||
mail.show_public_maillists(name)
|
||||
|
||||
elseif fields.back then
|
||||
mail.show_mail_menu(name)
|
||||
end
|
||||
|
||||
return true
|
||||
end)
|
Loading…
x
Reference in New Issue
Block a user