liquid_feedback_frontend

changeset 901:f3d6d08b0125

Added support for creating free timed issues in poll mode
author bsw
date Tue Aug 21 01:16:03 2012 +0200 (2012-08-21)
parents 832c8d0f3c7e
children eb16d41929bd
files app/main/admin/_action/policy_update.lua app/main/initiative/_action/create.lua app/main/initiative/new.lua model/policy.lua
line diff
     1.1 --- a/app/main/admin/_action/policy_update.lua	Tue Aug 21 00:33:17 2012 +0200
     1.2 +++ b/app/main/admin/_action/policy_update.lua	Tue Aug 21 01:16:03 2012 +0200
     1.3 @@ -12,5 +12,8 @@
     1.4  )
     1.5  
     1.6  if policy.admission_time == "" then policy.admission_time = nil end
     1.7 +if policy.discussion_time == "" then policy.discussion_time = nil end
     1.8 +if policy.verification_time == "" then policy.verification_time = nil end
     1.9 +if policy.voting_time == "" then policy.voting_time = nil end
    1.10  
    1.11  policy:save()
     2.1 --- a/app/main/initiative/_action/create.lua	Tue Aug 21 00:33:17 2012 +0200
     2.2 +++ b/app/main/initiative/_action/create.lua	Tue Aug 21 01:16:03 2012 +0200
     2.3 @@ -95,6 +95,36 @@
     2.4      issue.accepted = 'now'
     2.5      issue.state = 'discussion'
     2.6      initiative.polling = true
     2.7 +    
     2.8 +    if policy.free_timeable then
     2.9 +      local free_timing_string = util.trim(param.get("free_timing"))
    2.10 +      local available_timings
    2.11 +      if config.free_timing and config.free_timing.available_func then
    2.12 +        available_timings = config.free_timing.available_func(policy)
    2.13 +        if available_timings == false then
    2.14 +          error("error in free timing config")
    2.15 +        end
    2.16 +      end
    2.17 +      if available_timings then
    2.18 +        local timing_available = false
    2.19 +        for i, available_timing in ipairs(available_timings) do
    2.20 +          if available_timing.id == free_timing_string then
    2.21 +            timing_available = true
    2.22 +          end
    2.23 +        end
    2.24 +        if not timing_available then
    2.25 +          error('Invalid timing')
    2.26 +        end
    2.27 +      end
    2.28 +      local timing = config.free_timing.calculate_func(policy, free_timing_string)
    2.29 +      if not timing then
    2.30 +        error("error in free timing config")
    2.31 +      end
    2.32 +      issue.discussion_time = timing.discussion
    2.33 +      issue.verification_time = timing.verification
    2.34 +      issue.voting_time = timing.voting
    2.35 +    end
    2.36 +    
    2.37    end
    2.38    
    2.39    issue:save()
     3.1 --- a/app/main/initiative/new.lua	Tue Aug 21 00:33:17 2012 +0200
     3.2 +++ b/app/main/initiative/new.lua	Tue Aug 21 01:16:03 2012 +0200
     3.3 @@ -11,12 +11,34 @@
     3.4    area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
     3.5  end
     3.6  
     3.7 +local policy_id = param.get("policy_id", atom.integer)
     3.8 +local policy
     3.9 +
    3.10 +if policy_id then
    3.11 +  policy = Policy:by_id(policy_id)
    3.12 +end
    3.13 +
    3.14  if issue_id then
    3.15    ui.title(_"Add alternative initiative to issue")
    3.16  else
    3.17    ui.title(_"Create new issue")
    3.18  end
    3.19  
    3.20 +if not issue_id and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
    3.21 +  ui.actions(function()
    3.22 +    for i, policy in ipairs(area.allowed_policies) do
    3.23 +      if policy.polling  then
    3.24 +        ui.link{ 
    3.25 +          text = policy.name,
    3.26 +          module = "initiative", view = "new", params = {
    3.27 +            area_id = area.id, policy_id = policy.id        
    3.28 +          }
    3.29 +        }
    3.30 +      end
    3.31 +    end
    3.32 +  end)
    3.33 +end
    3.34 +
    3.35  ui.form{
    3.36    module = "initiative",
    3.37    action = "create",
    3.38 @@ -31,6 +53,29 @@
    3.39      slot.put("<br />")
    3.40      if issue_id then
    3.41        ui.field.text{ label = _"Issue",  value = issue_id }
    3.42 +    elseif policy_id then
    3.43 +      ui.field.hidden{ name = "policy_id", value = policy.id }
    3.44 +      ui.field.text{ label = _"Policy",  value = policy.name }
    3.45 +      if policy.free_timeable then
    3.46 +        local available_timings
    3.47 +        if config.free_timing and config.free_timing.available_func then
    3.48 +          available_timings = config.free_timing.available_func(policy)
    3.49 +          if available_timings == false then
    3.50 +            error("error in free timing config")
    3.51 +          end
    3.52 +        end
    3.53 +        if available_timings then
    3.54 +          ui.field.select{
    3.55 +            label = _"Free timing",
    3.56 +            name = _"free_timing",
    3.57 +            foreign_records = available_timings,
    3.58 +            foreign_id = "id",
    3.59 +            foreign_name = "name"
    3.60 +          }
    3.61 +        else
    3.62 +          ui.field.text{ label = _"Free timing", name = "free_timing" }
    3.63 +        end
    3.64 +      end
    3.65      else
    3.66        tmp = { { id = -1, name = _"Please choose a policy" } }
    3.67        for i, allowed_policy in ipairs(area.allowed_policies) do
     4.1 --- a/model/policy.lua	Tue Aug 21 00:33:17 2012 +0200
     4.2 +++ b/model/policy.lua	Tue Aug 21 01:16:03 2012 +0200
     4.3 @@ -18,3 +18,10 @@
     4.4    selector:add_order_by("index")
     4.5    return selector
     4.6  end
     4.7 +
     4.8 +function Policy.object_get:free_timeable()
     4.9 +  if self.discussion_time == nil and self.verification_time == nil and self.voting_time == nil then
    4.10 +    return true
    4.11 +  end
    4.12 +  return false
    4.13 +end
    4.14 \ No newline at end of file

Impressum / About Us