# HG changeset patch # User bsw # Date 1345504563 -7200 # Node ID f3d6d08b01258f818bbbf80bd1a44ce7f37e379e # Parent 832c8d0f3c7ee871b877f60d439e4e03be56b0aa Added support for creating free timed issues in poll mode diff -r 832c8d0f3c7e -r f3d6d08b0125 app/main/admin/_action/policy_update.lua --- a/app/main/admin/_action/policy_update.lua Tue Aug 21 00:33:17 2012 +0200 +++ b/app/main/admin/_action/policy_update.lua Tue Aug 21 01:16:03 2012 +0200 @@ -12,5 +12,8 @@ ) if policy.admission_time == "" then policy.admission_time = nil end +if policy.discussion_time == "" then policy.discussion_time = nil end +if policy.verification_time == "" then policy.verification_time = nil end +if policy.voting_time == "" then policy.voting_time = nil end policy:save() diff -r 832c8d0f3c7e -r f3d6d08b0125 app/main/initiative/_action/create.lua --- a/app/main/initiative/_action/create.lua Tue Aug 21 00:33:17 2012 +0200 +++ b/app/main/initiative/_action/create.lua Tue Aug 21 01:16:03 2012 +0200 @@ -95,6 +95,36 @@ issue.accepted = 'now' issue.state = 'discussion' initiative.polling = true + + if policy.free_timeable then + local free_timing_string = util.trim(param.get("free_timing")) + local available_timings + if config.free_timing and config.free_timing.available_func then + available_timings = config.free_timing.available_func(policy) + if available_timings == false then + error("error in free timing config") + end + end + if available_timings then + local timing_available = false + for i, available_timing in ipairs(available_timings) do + if available_timing.id == free_timing_string then + timing_available = true + end + end + if not timing_available then + error('Invalid timing') + end + end + local timing = config.free_timing.calculate_func(policy, free_timing_string) + if not timing then + error("error in free timing config") + end + issue.discussion_time = timing.discussion + issue.verification_time = timing.verification + issue.voting_time = timing.voting + end + end issue:save() diff -r 832c8d0f3c7e -r f3d6d08b0125 app/main/initiative/new.lua --- a/app/main/initiative/new.lua Tue Aug 21 00:33:17 2012 +0200 +++ b/app/main/initiative/new.lua Tue Aug 21 01:16:03 2012 +0200 @@ -11,12 +11,34 @@ area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec() end +local policy_id = param.get("policy_id", atom.integer) +local policy + +if policy_id then + policy = Policy:by_id(policy_id) +end + if issue_id then ui.title(_"Add alternative initiative to issue") else ui.title(_"Create new issue") end +if not issue_id and app.session.member:has_polling_right_for_unit_id(area.unit_id) then + ui.actions(function() + for i, policy in ipairs(area.allowed_policies) do + if policy.polling then + ui.link{ + text = policy.name, + module = "initiative", view = "new", params = { + area_id = area.id, policy_id = policy.id + } + } + end + end + end) +end + ui.form{ module = "initiative", action = "create", @@ -31,6 +53,29 @@ slot.put("
") if issue_id then ui.field.text{ label = _"Issue", value = issue_id } + elseif policy_id then + ui.field.hidden{ name = "policy_id", value = policy.id } + ui.field.text{ label = _"Policy", value = policy.name } + if policy.free_timeable then + local available_timings + if config.free_timing and config.free_timing.available_func then + available_timings = config.free_timing.available_func(policy) + if available_timings == false then + error("error in free timing config") + end + end + if available_timings then + ui.field.select{ + label = _"Free timing", + name = _"free_timing", + foreign_records = available_timings, + foreign_id = "id", + foreign_name = "name" + } + else + ui.field.text{ label = _"Free timing", name = "free_timing" } + end + end else tmp = { { id = -1, name = _"Please choose a policy" } } for i, allowed_policy in ipairs(area.allowed_policies) do diff -r 832c8d0f3c7e -r f3d6d08b0125 model/policy.lua --- a/model/policy.lua Tue Aug 21 00:33:17 2012 +0200 +++ b/model/policy.lua Tue Aug 21 01:16:03 2012 +0200 @@ -18,3 +18,10 @@ selector:add_order_by("index") return selector end + +function Policy.object_get:free_timeable() + if self.discussion_time == nil and self.verification_time == nil and self.voting_time == nil then + return true + end + return false +end \ No newline at end of file