123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- --- remove_process
- -- @module remove_process
- local remove_process = {
- name = "Remove process",
- slug = "remove_process",
- desc = "User can remove own processes, consent required for those of others",
- hide = false;
- }
- --- (Required) Data for module
- -- Variables that module uses during the course of a process
- -- Can be blank
- remove_process.data = {
- }
- remove_process.config = {
- }
- --- (Required): initiate function
- -- @param result (optional) Callback if this module is embedded in other modules
- -- @function initiate
- function remove_process:initiate(result)
- -- prepare process options
- local available_processes = {}
- for k,process in pairs(self.org.processes) do
- if process ~= "deleted" then
- available_processes[process.id] = process
- end
- end
- local process_list = {}
- local process_count = 0
- for k,v in pairs(available_processes) do
- local mine = ""
- if v.initiator == self.initiator then mine = "*" end
- table.insert(process_list,"["..v.id.."] "..v.slug..mine)
- process_count = process_count + 1
- end
- -- abort if no processes to remove
- if process_count == 0 then
- modpol.interactions.message(
- self.initiator, "Org has no modules")
- modpol.interactions.org_dashboard(
- self.initiator, self.org.id)
- if result then result() end
- self.org:delete_process(self.id)
- return
- end
- table.sort(process_list)
- -- now ask which to remove
- modpol.interactions.dropdown_query(
- self.initiator, "Choose a process to remove (* marks yours, no consent required):",
- process_list,
- function(process_choice)
- -- confirm choice
- local process_id = tonumber(
- string.match(process_choice, "%d+"))
- local process_mine = string.match(process_choice,
- "%*")
- modpol.interactions.binary_poll_user(
- self.initiator,
- "Confirm: Remove process \""..
- process_choice .. "\"?",
- function(input)
- if input == "Yes" then
- if process_mine then
- self.org:delete_process_tree(process_id)
- modpol.interactions.message(
- self.initiator,
- "Removed process: "..process_choice)
- modpol.interactions.org_dashboard(
- self.initiator, self.org.id)
- if result then result() end
- self.org:delete_process(self.id)
- else
- self:call_module(
- "consent",
- self.initiator,
- {
- prompt = "Approve removal of process "..process_choice.."?",
- votes_required = #self.org.members
- },
- function(input)
- modpol.interactions.message_org(
- self.initiator,
- self.org.id,
- "Removing process: "..
- process_choice)
- self.org:delete_process_tree(process_id)
- modpol.interactions.org_dashboard(
- self.initiator, self.org.id)
- if result then result() end
- self.org:delete_process(self.id)
- end
- )
- end
- modpol.interactions.org_dashboard(
- self.initiator, self.org.id)
- else
- modpol.interactions.org_dashboard(
- self.initiator, self.org.id)
- if result then result() end
- self.org:delete_process(self.id)
- end
- end
- )
- end
- )
- end
- --- (Required) Add to module table
- modpol.modules.remove_process = remove_process
|