liquid_feedback_frontend

diff app/main/delegation/show.lua @ 529:5ca9de94cb13

Delegation preview when setting delegation, optical enhancements, typos fixed
author bsw
date Sun May 20 19:43:01 2012 +0200 (2012-05-20)
parents 63d6549cc00b
children c1dc3b14a4f3
line diff
     1.1 --- a/app/main/delegation/show.lua	Fri May 18 21:03:10 2012 +0200
     1.2 +++ b/app/main/delegation/show.lua	Sun May 20 19:43:01 2012 +0200
     1.3 @@ -1,14 +1,22 @@
     1.4  local voting_right_unit_id
     1.5 +local current_trustee_id
     1.6 +local current_trustee_name
     1.7  
     1.8  local unit = Unit:by_id(param.get("unit_id", atom.integer))
     1.9  if unit then
    1.10 +  unit:load_delegation_info_once_for_member_id(app.session.member_id)
    1.11    voting_right_unit_id = unit.id
    1.12 +  if unit.delegation_info.own_delegation_scope == 'unit' then
    1.13 +    current_trustee_id = unit.delegation_info.first_trustee_id
    1.14 +    current_trustee_name = unit.delegation_info.first_trustee_name
    1.15 +  end
    1.16    slot.put_into("title", encode.html(config.single_unit_id and _"Set global delegation" or _"Set unit delegation"))
    1.17    util.help("delegation.new.unit")
    1.18  end
    1.19  
    1.20  local area = Area:by_id(param.get("area_id", atom.integer))
    1.21  if area then
    1.22 +  area:load_delegation_info_once_for_member_id(app.session.member_id)
    1.23    voting_right_unit_id = area.unit_id
    1.24    slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name)))
    1.25    util.help("delegation.new.area")
    1.26 @@ -16,6 +24,7 @@
    1.27  
    1.28  local issue = Issue:by_id(param.get("issue_id", atom.integer))
    1.29  if issue then
    1.30 +  issue:load_delegation_info_once_for_member_id(app.session.member_id)
    1.31    voting_right_unit_id = issue.area.unit_id
    1.32    slot.put_into("title", encode.html(_"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name)))
    1.33    util.help("delegation.new.issue")
    1.34 @@ -23,6 +32,17 @@
    1.35  
    1.36  local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
    1.37  
    1.38 +local contact_members = Member:build_selector{
    1.39 +  is_contact_of_member_id = app.session.member_id,
    1.40 +  voting_right_for_unit_id = voting_right_unit_id,
    1.41 +  active = true,
    1.42 +  order = "name"
    1.43 +}:exec()
    1.44 +
    1.45 +local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
    1.46 +
    1.47 +ui.script{ static = "js/update_delegation_info.js" }
    1.48 +
    1.49  slot.select("actions", function()
    1.50    if issue then
    1.51      ui.link{
    1.52 @@ -57,14 +77,8 @@
    1.53  end)
    1.54  
    1.55  
    1.56 -local contact_members = Member:build_selector{
    1.57 -  is_contact_of_member_id = app.session.member_id,
    1.58 -  voting_right_for_unit_id = voting_right_unit_id,
    1.59 -  order = "name"
    1.60 -}:exec()
    1.61 -
    1.62  ui.form{
    1.63 -  attr = { class = "vertical" },
    1.64 +  attr = { class = "vertical", id = "delegationForm" },
    1.65    module = "delegation",
    1.66    action = "update",
    1.67    params = {
    1.68 @@ -148,6 +162,11 @@
    1.69  
    1.70      end
    1.71      -- add saved members
    1.72 +    if current_trustee_id then
    1.73 +      records[#records+1] = {id="_", name= "--- " .. _"Current trustee" .. " ---"}
    1.74 +      records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
    1.75 +    end
    1.76 +    -- add saved members
    1.77      records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
    1.78      for i, record in ipairs(contact_members) do
    1.79        records[#records+1] = record
    1.80 @@ -165,15 +184,20 @@
    1.81      disabled_records[app.session.member_id] = true
    1.82  
    1.83      ui.field.select{
    1.84 +      attr = { onchange = "updateDelegationInfo();" },
    1.85        label = _"Trustee",
    1.86        name = "trustee_id",
    1.87        foreign_records = records,
    1.88        foreign_id = "id",
    1.89        foreign_name = "name",
    1.90 -      disabled_records = disabled_records
    1.91 +      disabled_records = disabled_records,
    1.92 +      value = preview_trustee_id or current_trustee_id
    1.93      }
    1.94  
    1.95 +    ui.field.hidden{ name = "preview" }
    1.96 +    
    1.97      ui.submit{ text = _"Save" }
    1.98 +    
    1.99    end
   1.100  }
   1.101  
   1.102 @@ -244,9 +268,7 @@
   1.103    slot_name = "default"
   1.104  end
   1.105  
   1.106 -if delegation then
   1.107 -
   1.108 -  if not delegation.trustee_id then
   1.109 +  if delegation and not delegation.trustee_id then
   1.110      ui.image{
   1.111        static = "icons/16/table_go_crossed.png"
   1.112      }
   1.113 @@ -259,7 +281,7 @@
   1.114  
   1.115    local delegation_chain = Member:new_selector()
   1.116      :add_field("delegation_chain.*")
   1.117 -    :join("delegation_chain(" .. tostring(app.session.member.id) .. ", " .. tostring(unit_id or "NULL") .. ", " .. tostring(area_id or "NULL") .. ", " .. tostring(issue_id or "NULL") .. ")", "delegation_chain", "member.id = delegation_chain.member_id")
   1.118 +    :join({ "delegation_chain(?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, preview_trustee_id }, "delegation_chain", "member.id = delegation_chain.member_id")
   1.119      :add_order_by("index")
   1.120      :exec()
   1.121  
   1.122 @@ -311,4 +333,3 @@
   1.123      end
   1.124      slot.put("<br style='clear: left'/>")
   1.125    end
   1.126 -end
   1.127 \ No newline at end of file

Impressum / About Us