defer.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. --- Defer
  2. -- @module defer
  3. local defer = {
  4. name = "Defer ",
  5. slug = "defer",
  6. desc = "Defers a decision to another org",
  7. hide = true;
  8. }
  9. defer.data = {
  10. }
  11. --- Config for module
  12. -- @field defer_org Name or ID of target org
  13. -- @field approval_module module to use in target org
  14. -- @field prompt String passed on to approval_module
  15. defer.config = {
  16. approval_module = "consent",
  17. defer_org = "Root",
  18. prompt = ""
  19. }
  20. --- Initiate function
  21. -- @param result Callback if this module is embedded in other modules
  22. -- @function defer:initiate
  23. function defer:initiate(result)
  24. local defer_org = modpol.orgs.get_org(self.config.defer_org)
  25. if not defer_org then
  26. modpol.interactions.message(
  27. self.initiator, "Target org not found, aborting")
  28. self.org:delete_process(self.id)
  29. else
  30. defer_org:call_module(
  31. self.config.approval_module,
  32. self.initiator,
  33. {
  34. prompt = self.config.prompt
  35. },
  36. function()
  37. if result then result() end
  38. end)
  39. end
  40. modpol.interactions.org_dashboard(
  41. self.initiator, self.org.id)
  42. self.org:delete_process(self.id)
  43. end
  44. --- (Required) Add to module table
  45. modpol.modules.defer = defer