add_child_org.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 = nil
  11. }
  12. add_child_org.config = {
  13. }
  14. --- Initiate consent for new child org
  15. -- @function add_child_org:initiate(result)
  16. -- @param result Callback if this module is embedded in other modules
  17. function add_child_org:initiate(result)
  18. modpol.interactions.text_query(
  19. self.initiator,"Child org name: ",
  20. function(input)
  21. if input == "" then
  22. modpol.interactions.message(
  23. self.initiator,
  24. "No name entered for child org")
  25. modpol.interactions.org_dashboard(
  26. self.initiator, self.org.name)
  27. self.org:delete_process(self.id)
  28. return
  29. elseif modpol.orgs.get_org(input) then
  30. modpol.interactions.message(
  31. self.initiator,
  32. "Org name already in use")
  33. modpol.interactions.org_dashboard(
  34. self.initiator, self.org.name)
  35. self.org:delete_process(self.id)
  36. if result then result() end
  37. return
  38. end
  39. self.data.child_name = input
  40. modpol.interactions.message(
  41. self.initiator,
  42. "Proposed child org: " .. input)
  43. -- create the org
  44. self:create_child_org()
  45. modpol.interactions.org_dashboard(
  46. self.initiator, self.org.name)
  47. end
  48. )
  49. end
  50. --- Create a new child orgg
  51. -- @function add_child_org:create_child_org
  52. function add_child_org:create_child_org()
  53. self.org:add_org(self.data.child_name, self.initiator)
  54. modpol.interactions.message_org(
  55. self.initiator,
  56. self.org.name,
  57. "Created child org "
  58. ..self.data.child_name)
  59. if self.data.result then self.data.result() end
  60. self.org:delete_process(self.id)
  61. end
  62. modpol.modules.add_child_org = add_child_org