add_child_org.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --- Adds a child org
  2. -- @module add_child_org
  3. local add_child_org = {
  4. name = "Add child org",
  5. slug = "add_child_org",
  6. desc = "Create a child org in the current one"
  7. }
  8. add_child_org.data = {
  9. child_name = "",
  10. result = false
  11. }
  12. add_child_org.config = {
  13. approval_module = false
  14. }
  15. --- Initiate consent for new child org
  16. -- @function add_child_org:initiate(result)
  17. -- @param result Callback if this module is embedded in other modules
  18. function add_child_org:initiate(result)
  19. modpol.interactions.text_query(
  20. self.initiator,"Child org name: ",
  21. function(input)
  22. if input == "" then
  23. modpol.interactions.message(
  24. self.initiator,
  25. "No name entered for child org")
  26. modpol.interactions.org_dashboard(
  27. self.initiator, self.org.name)
  28. self.org:delete_process(self.id)
  29. return
  30. elseif modpol.orgs.get_org(input) then
  31. modpol.interactions.message(
  32. self.initiator,
  33. "Org name already in use")
  34. modpol.interactions.org_dashboard(
  35. self.initiator, self.org.name)
  36. self.org:delete_process(self.id)
  37. if result then result() end
  38. return
  39. end
  40. self.data.child_name = input
  41. modpol.interactions.message(
  42. self.initiator,
  43. "Proposed child org: " .. input)
  44. -- initiate consent process
  45. self:call_module(
  46. self.config.approval_module,
  47. self.initiator,
  48. {
  49. prompt = "Create child org " ..
  50. self.data.child_name .. "?",
  51. votes_required = #self.org.members
  52. },
  53. function()
  54. self:create_child_org()
  55. end
  56. )
  57. modpol.interactions.org_dashboard(
  58. self.initiator, self.org.name)
  59. end
  60. )
  61. end
  62. --- Create a new child org
  63. -- @function add_child_org:create_child_org
  64. function add_child_org:create_child_org()
  65. self.org:add_org(self.data.child_name, self.initiator)
  66. modpol.interactions.message_org(
  67. self.initiator,
  68. self.org.name,
  69. "Created child org in " .. self.org.name .. ": "
  70. .. self.data.child_name)
  71. if self.data.result then self.data.result() end
  72. self.org:delete_process(self.id)
  73. end
  74. modpol.modules.add_child_org = add_child_org