liquid_feedback_frontend

changeset 126:36aedac3e4bf

Add default policy selector in area admin
author Daniel Poelzleithner <poelzi@poelzi.org>
date Mon Oct 04 15:52:22 2010 +0200 (2010-10-04)
parents eb6509288d67
children 4fb486bce608
files app/main/admin/_action/area_update.lua app/main/admin/area_show.lua model/allowed_policy.lua
line diff
     1.1 --- a/app/main/admin/_action/area_update.lua	Mon Oct 04 14:37:13 2010 +0200
     1.2 +++ b/app/main/admin/_action/area_update.lua	Mon Oct 04 15:52:22 2010 +0200
     1.3 @@ -24,4 +24,28 @@
     1.4    foreign_reference = "policy_id"
     1.5  }
     1.6  
     1.7 +-- we have to update the default flag because update_relationship can't handle it
     1.8 +old_default = AllowedPolicy:new_selector()
     1.9 +:add_where{ "allowed_policy.area_id = ? AND allowed_policy.default_policy = 't'", area.id }
    1.10 +:optional_object_mode()
    1.11 +:exec()
    1.12 +
    1.13 +if old_default then
    1.14 +  old_default.default_policy = false;
    1.15 +  old_default:save()
    1.16 +end
    1.17 +
    1.18 +default_policy_id = param.get("default_policy", atom.integer)
    1.19 +
    1.20 +if default_policy_id and default_policy_id ~= -1 then
    1.21 +  pol = AllowedPolicy:new_selector()
    1.22 +  :add_where{ "allowed_policy.area_id = ? AND allowed_policy.policy_id = ?", area.id, default_policy_id }
    1.23 +  :optional_object_mode()
    1.24 +  :exec()
    1.25 +  if pol then
    1.26 +    pol.default_policy = true;
    1.27 +    pol:save()
    1.28 +  end
    1.29 +end
    1.30 +
    1.31  slot.put_into("notice", _"Area successfully updated")
     2.1 --- a/app/main/admin/area_show.lua	Mon Oct 04 14:37:13 2010 +0200
     2.2 +++ b/app/main/admin/area_show.lua	Mon Oct 04 15:52:22 2010 +0200
     2.3 @@ -21,11 +21,28 @@
     2.4    },
     2.5    id = area and area.id or nil,
     2.6    content = function()
     2.7 +    policies = Policy:new_selector():add_where{ "active='t'"}:exec()
     2.8 +    local def_policy = {
     2.9 +      {
    2.10 +        id = "-1",
    2.11 +        name = _"No default"
    2.12 +      }
    2.13 +    }
    2.14 +    for i, record in ipairs(policies) do
    2.15 +      def_policy[#def_policy+1] = record
    2.16 +    end
    2.17 +
    2.18      ui.field.text{    label = _"Name",        name = "name" }
    2.19      ui.field.boolean{ label = _"Active?",     name = "active" }
    2.20      ui.field.text{    label = _"Description", name = "description", multiline = true }
    2.21 +    ui.field.select{   label = _"Default Policy",   name = "default_policy",
    2.22 +                 value=area.default_policy and area.default_policy.id or "-1",
    2.23 +                 foreign_records = def_policy,
    2.24 +                 foreign_id      = "id",
    2.25 +                 foreign_name    = "name"
    2.26 +    }
    2.27      ui.multiselect{   label = _"Policies",    name = "allowed_policies[]",
    2.28 -                      foreign_records = Policy:new_selector():add_where{ "active='t'"}:exec(),
    2.29 +                      foreign_records = policies,
    2.30                        foreign_id      = "id",
    2.31                        foreign_name    = "name",
    2.32                        connecting_records = area.allowed_policies,
     3.1 --- a/model/allowed_policy.lua	Mon Oct 04 14:37:13 2010 +0200
     3.2 +++ b/model/allowed_policy.lua	Mon Oct 04 15:52:22 2010 +0200
     3.3 @@ -1,2 +1,3 @@
     3.4  AllowedPolicy = mondelefant.new_class()
     3.5  AllowedPolicy.table = 'allowed_policy'
     3.6 +AllowedPolicy.primary_key = { "area_id", "policy_id" }

Impressum / About Us