add_child_org.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.data.result = result
  46. self:call_module(
  47. self.config.approval_module,
  48. self.initiator,
  49. {
  50. prompt = "Create child org " ..
  51. self.data.child_name .. "?",
  52. votes_required = #self.org.members
  53. },
  54. function()
  55. self:create_child_org()
  56. end
  57. )
  58. modpol.interactions.org_dashboard(
  59. self.initiator, self.org.name)
  60. end
  61. )
  62. end
  63. --- Create a new child org
  64. -- @function add_child_org:create_child_org
  65. function add_child_org:create_child_org()
  66. self.org:add_org(self.data.child_name, self.initiator)
  67. modpol.interactions.message_org(
  68. self.initiator,
  69. self.org.name,
  70. "Created child org in " .. self.org.name .. ": "
  71. .. self.data.child_name)
  72. if self.data.result then self.data.result() end
  73. self.org:delete_process(self.id)
  74. end
  75. modpol.modules.add_child_org = add_child_org