|
@@ -59,10 +59,7 @@ function modpol.interactions.dashboard(user)
|
|
|
"dropdown[2,2.5;5,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
|
|
"label[0.5,4;All users:]",
|
|
|
"dropdown[2,3.5;5,0.8;all_users;"..formspec_list(all_users)..";;]",
|
|
|
- "button[0.5,7;1,0.8;test_poll;Test poll]",
|
|
|
- "button[2,7;1,0.8;add_org;Add org]",
|
|
|
- "button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
|
|
- "button[5.5,7;1.5,0.8;reset_orgs;Reset orgs]",
|
|
|
+ "button[0.5,7;1.5,0.8;reset_orgs;Reset orgs]",
|
|
|
"button_exit[8.5,7;1,0.8;close;Close]",
|
|
|
}
|
|
|
local formspec_string = table.concat(formspec, "")
|
|
@@ -75,22 +72,6 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
local pname = player:get_player_name()
|
|
|
if nil then
|
|
|
-- buttons first
|
|
|
- elseif fields.test_poll then
|
|
|
- -- FOR TESTING PURPOSES ONLY
|
|
|
- modpol.interactions.text_query(
|
|
|
- pname,"Poll question:",
|
|
|
- function(input)
|
|
|
- modpol.interactions.binary_poll_user(
|
|
|
- pname, input,
|
|
|
- function(vote)
|
|
|
- modpol.interactions.message(
|
|
|
- pname, pname .. " voted " .. vote)
|
|
|
- end)
|
|
|
- end)
|
|
|
- elseif fields.add_org then
|
|
|
- modpol.interactions.add_org(pname, 1)
|
|
|
- elseif fields.remove_org then
|
|
|
- modpol.interactions.remove_org(pname)
|
|
|
elseif fields.reset_orgs then
|
|
|
modpol.orgs.reset()
|
|
|
modpol.instance:add_member(pname)
|
|
@@ -144,18 +125,20 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|
|
-- prepare modules menu
|
|
|
local modules = {"View..."}
|
|
|
if org.modules then
|
|
|
- for k,v in ipairs(org.modules) do
|
|
|
- table.insert(modules, org.modules[k].slug)
|
|
|
+ for k,v in pairs(org.modules) do
|
|
|
+ table.insert(modules, v.slug)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
-- prepare actions menu
|
|
|
local actions = {"View..."}
|
|
|
+ local num_actions = 0
|
|
|
if org.pending[user] then
|
|
|
for k,v in pairs(org.pending[user]) do
|
|
|
local action_string = "[" .. k .. "] " ..
|
|
|
- org.processes[k].name
|
|
|
+ org.processes[k].name
|
|
|
table.insert(actions, action_string)
|
|
|
+ num_actions = num_actions + 1
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -177,7 +160,7 @@ function modpol.interactions.org_dashboard(user, org_name)
|
|
|
"dropdown[2,2.5;5,0.8;children;"..formspec_list(children)..";;]",
|
|
|
"label[0.5,4;Modules:]",
|
|
|
"dropdown[2,3.5;5,0.8;modules;"..formspec_list(modules)..";;]",
|
|
|
- "label[0.5,5;Actions:]",
|
|
|
+ "label[0.5,5;Actions ("..num_actions.."):]",
|
|
|
"dropdown[2,4.5;5,0.8;actions;"..formspec_list(actions)..";;]",
|
|
|
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
|
|
"button[2,7;1,0.8;add_child;Add child]",
|
|
@@ -195,12 +178,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
local org = modpol.orgs.get_org(_contexts[pname].current_org)
|
|
|
if nil then
|
|
|
elseif fields.join then
|
|
|
- local new_request = {
|
|
|
- user = pname,
|
|
|
- type = "add_member",
|
|
|
- params = {pname}
|
|
|
- }
|
|
|
- org:make_request(new_request)
|
|
|
+ org:add_member(pname)
|
|
|
modpol.interactions.org_dashboard(pname,org.name)
|
|
|
elseif fields.leave then
|
|
|
org:remove_member(pname)
|
|
@@ -217,24 +195,19 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
elseif fields.add_child then
|
|
|
modpol.interactions.text_query(
|
|
|
pname, "Child org name:",
|
|
|
- function(input)
|
|
|
- local new_request = {
|
|
|
- user = pname,
|
|
|
- type = "add_org",
|
|
|
- params = {input}
|
|
|
- }
|
|
|
- org:make_request(new_request)
|
|
|
- modpol.interactions.message(pname,"requested")
|
|
|
- modpol.interactions.org_dashboard(
|
|
|
- pname,org.name)
|
|
|
+ function(input)
|
|
|
+ org:add_org(input,pname)
|
|
|
+ modpol.interactions.message_org(
|
|
|
+ pname,
|
|
|
+ org.id,
|
|
|
+ "Child org created: " .. input)
|
|
|
end)
|
|
|
elseif fields.remove_org then
|
|
|
- local new_request = {
|
|
|
- user = pname,
|
|
|
- type = "delete",
|
|
|
- params = {}
|
|
|
- }
|
|
|
- org:make_request(new_request)
|
|
|
+ modpol.interactions.message_org(
|
|
|
+ pname,
|
|
|
+ org.id,
|
|
|
+ "Removing org: " .. org.name)
|
|
|
+ org:delete()
|
|
|
modpol.interactions.org_dashboard(pname,org.name)
|
|
|
elseif fields.back then
|
|
|
modpol.interactions.dashboard(pname)
|
|
@@ -244,8 +217,9 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
elseif fields.modules
|
|
|
and fields.modules ~= "View..." then
|
|
|
local module = fields.modules
|
|
|
- org:call_module(module, user)
|
|
|
-
|
|
|
+ org:call_module(module, pname)
|
|
|
+ modpol.interactions.org_dashboard(pname,org.name)
|
|
|
+
|
|
|
-- Receiving actions
|
|
|
elseif fields.actions
|
|
|
and fields.actions ~= "View..." then
|
|
@@ -253,7 +227,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
fields.actions,"%[(%d)%]")
|
|
|
local process = org.processes[tonumber(action)]
|
|
|
if process then
|
|
|
- org:interact(process, user)
|
|
|
+ org:interact(process.id, pname)
|
|
|
end
|
|
|
|
|
|
-- Children
|
|
@@ -282,8 +256,8 @@ end
|
|
|
-- ===========================
|
|
|
|
|
|
-- Function: modpol.interactions.message
|
|
|
--- input: message (string)
|
|
|
--- output
|
|
|
+-- input: user (string), message (string)
|
|
|
+-- output: displays message to specified user
|
|
|
function modpol.interactions.message(user, message)
|
|
|
minetest.chat_send_player(user, message)
|
|
|
end
|
|
@@ -291,7 +265,6 @@ end
|
|
|
-- Function: modpol.interactions.text_query
|
|
|
-- Overrides function at modpol/interactions.lua
|
|
|
-- input: user (string), query (string), func (function)
|
|
|
--- func input: user input (string)
|
|
|
-- output: Applies "func" to user input
|
|
|
function modpol.interactions.text_query(user, query, func)
|
|
|
-- set up formspec
|
|
@@ -303,7 +276,7 @@ function modpol.interactions.text_query(user, query, func)
|
|
|
"button[0.5,2.5;1,0.8;yes;OK]",
|
|
|
}
|
|
|
local formspec_string = table.concat(formspec, "")
|
|
|
- -- present to players
|
|
|
+ -- present to player
|
|
|
minetest.show_formspec(user, "modpol:text_query", formspec_string)
|
|
|
-- put func in _contexts
|
|
|
if _contexts[user] == nil then _contexts[user] = {} end
|
|
@@ -367,10 +340,6 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
end
|
|
|
end)
|
|
|
|
|
|
-
|
|
|
--- SECONDARY INTERACTIONS
|
|
|
--- ======================
|
|
|
-
|
|
|
-- Function: modpol.binary_poll_user(user, question, function)
|
|
|
-- Overrides function at modpol/interactions.lua
|
|
|
-- Params: user (string), question (string), func (function)
|
|
@@ -384,8 +353,8 @@ function modpol.interactions.binary_poll_user(user, question, func)
|
|
|
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
|
|
|
"button[1,1.5;1,0.8;yes;Yes]",
|
|
|
"button[2,1.5;1,0.8;no;No]",
|
|
|
- --TKTK can we enable text wrapping?
|
|
|
- --TKTK we could use scroll boxes to contain the text
|
|
|
+ --TODO can we enable text wrapping?
|
|
|
+ --TODO we could use scroll boxes to contain the text
|
|
|
}
|
|
|
local formspec_string = table.concat(formspec, "")
|
|
|
if _contexts[user] == nil then _contexts[user] = {} end
|
|
@@ -409,71 +378,3 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|
|
minetest.close_formspec(pname, formname)
|
|
|
end
|
|
|
end)
|
|
|
-
|
|
|
--- COMPLEX INTERACTIONS
|
|
|
--- ====================
|
|
|
-
|
|
|
--- Function: modpol.interactions.message_org
|
|
|
--- input: initiator (string), org_id (number), message (string)
|
|
|
--- output: broadcasts message to all org members
|
|
|
-function modpol.interactions.message_org(initiator, org_id, message)
|
|
|
- local org = modpol.orgs.get_org(org_id)
|
|
|
- local users = org:list_members()
|
|
|
- for k,v in ipairs(users) do
|
|
|
- modpol.interactions.message(v, message)
|
|
|
- end
|
|
|
-end
|
|
|
-
|
|
|
-
|
|
|
--- Function: modpol.interactions.binary_poll_org
|
|
|
--- input: initator (user string), org_id (number)
|
|
|
--- output: gets question from initiator, asks all org members, broadcasts answers
|
|
|
--- TODO for testing. This should be implemented as a request.
|
|
|
-function modpol.interactions.binary_poll_org(initiator, org_id, func)
|
|
|
- local org = modpol.orgs.get_org(org_id)
|
|
|
- local users = org:list_members()
|
|
|
- modpol.interactions.text_query(
|
|
|
- initiator, "Yes/no poll question:",
|
|
|
- function(input)
|
|
|
- for k,v in ipairs(users) do
|
|
|
- modpol.interactions.binary_poll_user(v, input, func)
|
|
|
- end
|
|
|
- end)
|
|
|
-end
|
|
|
-
|
|
|
--- Function: modpol.interactions.add_org
|
|
|
--- input: initator (user string), base_org_id (ID)
|
|
|
--- output: interaction begins
|
|
|
--- GODMODE
|
|
|
-function modpol.interactions.add_org(user, base_org_id)
|
|
|
- modpol.interactions.text_query(
|
|
|
- user,"Org name:",
|
|
|
- function(input)
|
|
|
- local base_org = modpol.orgs.get_org(1)
|
|
|
- local result = base_org:add_org(input, user)
|
|
|
- local message = input .. " created"
|
|
|
- modpol.interactions.message(user, message)
|
|
|
- modpol.interactions.dashboard(user)
|
|
|
- end)
|
|
|
-end
|
|
|
-
|
|
|
--- Function: modpol.interactions.remove_org
|
|
|
--- input: initator (user string)
|
|
|
--- output: interaction begins
|
|
|
--- GODMODE
|
|
|
-function modpol.interactions.remove_org(user)
|
|
|
- -- start formspec
|
|
|
- local orgs_list = modpol.orgs.list_all()
|
|
|
- local label = "Choose an org to remove:"
|
|
|
- modpol.interactions.dropdown_query(
|
|
|
- user, label, orgs_list,
|
|
|
- function(input)
|
|
|
- if input then
|
|
|
- local target_org = modpol.orgs.get_org(input)
|
|
|
- local result = target_org:delete()
|
|
|
- local message = input .. " deleted"
|
|
|
- modpol.interactions.message(user, message)
|
|
|
- end
|
|
|
- modpol.interactions.dashboard(user)
|
|
|
- end)
|
|
|
-end
|