add_child_org.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --- @module add_child_org
  2. -- Adds a child org
  3. -- Depends on `consent`
  4. local add_child_org = {
  5. name = "Add child org",
  6. slug = "add_child_org",
  7. desc = "Create a child org within the current one with consent"
  8. }
  9. add_child_org.data = {
  10. child_name = ""
  11. }
  12. add_child_org.config = {
  13. }
  14. -- @function initiate
  15. function add_child_org:initiate(config, result)
  16. self.org:add_pending_action(
  17. self.id, self.initiator,
  18. "name_child_org")
  19. end
  20. function add_child_org:name_child_org()
  21. modpol.interactions.text_query(
  22. self.initiator,"Child org name: ",
  23. function(input)
  24. if input == "" then
  25. modpol.interactions.message(
  26. self.initiator,
  27. "No name entered for child org")
  28. self.org:wipe_pending_actions(self.id)
  29. return end
  30. self.data.child_name = input
  31. modpol.interactions.message(
  32. self.initiator,
  33. "Proposed child org: " .. input)
  34. self.org:wipe_pending_actions(self.id)
  35. self:propose_child_org()
  36. end
  37. )
  38. end
  39. function add_child_org:propose_child_org()
  40. self.org:call_module(
  41. "consent",
  42. self.initiator,
  43. {
  44. prompt = "Create child org " .. self.data.child_name .. "?",
  45. votes_required = #self.org.members
  46. },
  47. function()
  48. self.org:add_org(self.data.child_name, self.initiator)
  49. modpol.interactions.message_org(
  50. self.initiator,
  51. self.org.id,
  52. "Child org created: "..self.data.child_name)
  53. end
  54. )
  55. end
  56. --- (Required) Add to module table
  57. modpol.modules.add_child_org = add_child_org