rename_org.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --- Rename org
  2. -- Calls a process on an org to rename it.
  3. -- @module rename_org
  4. local rename_org = {
  5. name = "Rename this org",
  6. slug = "rename_org",
  7. desc = "Renames an org."
  8. }
  9. rename_org.data = {
  10. result = nil,
  11. new_name = nil
  12. }
  13. rename_org.config = {
  14. approval_module = false
  15. }
  16. --- Renames the org after consent is reached
  17. -- @function rename_org:initiate
  18. -- @param result Callback if this module is embedded in other modules
  19. function rename_org:initiate(result)
  20. modpol.interactions.text_query(
  21. self.initiator,"New org name: ",
  22. function(input)
  23. if input == "" then
  24. modpol.interactions.message(
  25. self.initiator,
  26. "No name entered for child org")
  27. modpol.interactions.org_dashboard(
  28. self.initiator, self.org.name)
  29. self.org:delete_process(self.id)
  30. if result then result() end
  31. return
  32. elseif modpol.orgs.get_org(input) then
  33. modpol.interactions.message(
  34. self.initiator,
  35. "Org name already in use")
  36. modpol.interactions.org_dashboard(
  37. self.initiator, self.org.name)
  38. self.org:delete_process(self.id)
  39. if result then result() end
  40. return
  41. end
  42. self.data.new_name = input
  43. modpol.interactions.message(
  44. self.initiator,
  45. "Proposed to change name of org " ..
  46. self.org.name .. " to " .. input)
  47. -- initiate consent process
  48. self:call_module(
  49. self.config.approval_module,
  50. self.initiator,
  51. {
  52. prompt = "Change name of org " ..
  53. self.org.name .. " to " .. input .. "?"
  54. },
  55. function()
  56. self:complete()
  57. end
  58. )
  59. modpol.interactions.org_dashboard(
  60. self.initiator, self.org.name)
  61. end
  62. )
  63. end
  64. --- Changes the name of the org
  65. -- @funciton rename_org
  66. function rename_org:complete()
  67. modpol.interactions.message_org(
  68. self.initiator,
  69. self.org.name,
  70. "Changing name of org " .. self.org.name ..
  71. " to " .. self.data.new_name)
  72. self.org.name = self.data.new_name
  73. if self.data.result then self.data.result() end
  74. self.org:delete_process(self.id)
  75. end
  76. modpol.modules.rename_org = rename_org