liquid_feedback_frontend

diff app/main/delegation/show.lua @ 575:5650f8163a29

Fixed errors from delegation dialog
author bsw
date Wed Jun 20 00:22:53 2012 +0200 (2012-06-20)
parents e7baf2713987
children fd41ff8d9563
line diff
     1.1 --- a/app/main/delegation/show.lua	Tue Jun 19 23:42:13 2012 +0200
     1.2 +++ b/app/main/delegation/show.lua	Wed Jun 20 00:22:53 2012 +0200
     1.3 @@ -38,7 +38,62 @@
     1.4    util.help("delegation.new.issue")
     1.5  end
     1.6  
     1.7 -local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
     1.8 +
     1.9 +local delegation
    1.10 +local unit_id
    1.11 +local area_id
    1.12 +local issue_id
    1.13 +local initiative_id
    1.14 +local initiative
    1.15 +
    1.16 +local scope = "unit"
    1.17 +
    1.18 +unit_id = param.get("unit_id", atom.integer)
    1.19 +
    1.20 +local inline = param.get("inline", atom.boolean)
    1.21 +
    1.22 +if param.get("initiative_id", atom.integer) then
    1.23 +  initiative_id = param.get("initiative_id", atom.integer)
    1.24 +  initiative = Initiative:by_id(initiative_id)
    1.25 +  issue_id = initiative.issue_id
    1.26 +  scope = "issue"
    1.27 +end
    1.28 +
    1.29 +if param.get("issue_id", atom.integer) then
    1.30 +  issue_id = param.get("issue_id", atom.integer)
    1.31 +  scope = "issue"
    1.32 +end
    1.33 +
    1.34 +if param.get("area_id", atom.integer) then
    1.35 +  area_id = param.get("area_id", atom.integer)
    1.36 +  scope = "area"
    1.37 +end
    1.38 +
    1.39 +
    1.40 +
    1.41 +local delegation
    1.42 +local issue
    1.43 +
    1.44 +if issue_id then
    1.45 +  issue = Issue:by_id(issue_id)
    1.46 +  delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
    1.47 +  if not delegation then
    1.48 +    delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
    1.49 +  end
    1.50 +  if not delegation then
    1.51 +    delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
    1.52 +  end
    1.53 +elseif area_id then
    1.54 +  delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
    1.55 +  if not delegation then
    1.56 +    local area = Area:by_id(area_id)
    1.57 +    delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
    1.58 +  end
    1.59 +end
    1.60 +
    1.61 +if not delegation then
    1.62 +  delegation = Delegation:by_pk(app.session.member.id, unit_id)
    1.63 +end
    1.64  
    1.65  local contact_members = Member:build_selector{
    1.66    is_contact_of_member_id = app.session.member_id,
    1.67 @@ -93,13 +148,14 @@
    1.68      unit_id = unit and unit.id or nil,
    1.69      area_id = area and area.id or nil,
    1.70      issue_id = issue and issue.id or nil,
    1.71 +    initiative_id = initiative_id
    1.72    },
    1.73    routing = {
    1.74      default = {
    1.75        mode = "redirect",
    1.76        module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
    1.77        view = "show",
    1.78 -      id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id
    1.79 +      id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
    1.80      }
    1.81    },
    1.82    content = function()
    1.83 @@ -182,15 +238,25 @@
    1.84        end
    1.85      end
    1.86      -- add saved members
    1.87 -    records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
    1.88 -    for i, record in ipairs(contact_members) do
    1.89 -      records[#records+1] = record
    1.90 +    if #contact_members > 0 then
    1.91 +      records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
    1.92 +      for i, record in ipairs(contact_members) do
    1.93 +        records[#records+1] = record
    1.94 +      end
    1.95      end
    1.96  
    1.97      disabled_records = {}
    1.98      disabled_records["_"] = true
    1.99      disabled_records[app.session.member_id] = true
   1.100  
   1.101 +    local value = current_trustee_id
   1.102 +    if preview_trustee_id then
   1.103 +      value = preview_trustee_id
   1.104 +    end
   1.105 +    if preview_trustee_id == nil and delegation and not delegation.trustee_id then
   1.106 +      value = 0
   1.107 +    end
   1.108 +    
   1.109      ui.field.select{
   1.110        attr = { onchange = "updateDelegationInfo();" },
   1.111        label = _"Trustee",
   1.112 @@ -199,7 +265,7 @@
   1.113        foreign_id = "id",
   1.114        foreign_name = "name",
   1.115        disabled_records = disabled_records,
   1.116 -      value = preview_trustee_id or current_trustee_id
   1.117 +      value = value
   1.118      }
   1.119  
   1.120      ui.field.hidden{ name = "preview" }
   1.121 @@ -210,134 +276,72 @@
   1.122  }
   1.123  
   1.124  
   1.125 -
   1.126  -- ------------------------
   1.127  
   1.128  
   1.129 -
   1.130 -
   1.131 -local delegation
   1.132 -local unit_id
   1.133 -local area_id
   1.134 -local issue_id
   1.135 -local initiative_id
   1.136 -
   1.137 -local scope = "unit"
   1.138 -
   1.139 -unit_id = param.get("unit_id", atom.integer)
   1.140 +local delegation_chain = Member:new_selector()
   1.141 +  :add_field("delegation_chain.*")
   1.142 +  :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.143 +  :add_order_by("index")
   1.144 +  :exec()
   1.145  
   1.146 -local inline = param.get("inline", atom.boolean)
   1.147 -
   1.148 -if param.get("initiative_id", atom.integer) then
   1.149 -  initiative_id = param.get("initiative_id", atom.integer)
   1.150 -  issue_id = Initiative:by_id(initiative_id).issue_id
   1.151 -  scope = "issue"
   1.152 -end
   1.153 -
   1.154 -if param.get("issue_id", atom.integer) then
   1.155 -  issue_id = param.get("issue_id", atom.integer)
   1.156 -  scope = "issue"
   1.157 +for i, record in ipairs(delegation_chain) do
   1.158 +  local style
   1.159 +  local overridden = (not issue or issue.state ~= 'voting') and record.overridden
   1.160 +  if record.scope_in then
   1.161 +    if not overridden then
   1.162 +      ui.image{
   1.163 +        attr = { class = "delegation_arrow" },
   1.164 +        static = "delegation_arrow_24_vertical.png"
   1.165 +      }
   1.166 +    else
   1.167 +      ui.image{
   1.168 +        attr = { class = "delegation_arrow delegation_arrow_overridden" },
   1.169 +        static = "delegation_arrow_24_vertical.png"
   1.170 +      }
   1.171 +    end
   1.172 +    ui.tag{
   1.173 +      attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   1.174 +      content = function()
   1.175 +        if record.scope_in == "unit" then
   1.176 +          slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   1.177 +        elseif record.scope_in == "area" then
   1.178 +          slot.put(_"Area delegation")
   1.179 +        elseif record.scope_in == "issue" then
   1.180 +          slot.put(_"Issue delegation")
   1.181 +        end
   1.182 +      end
   1.183 +    }
   1.184 +  end
   1.185 +  ui.container{
   1.186 +    attr = { class = overridden and "delegation_overridden" or "" },
   1.187 +    content = function()
   1.188 +      execute.view{
   1.189 +        module = "member",
   1.190 +        view = "_show_thumb",
   1.191 +        params = { member = record }
   1.192 +      }
   1.193 +    end
   1.194 +  }
   1.195 +  if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
   1.196 +    ui.container{
   1.197 +      attr = { class = "delegation_participation" },
   1.198 +      content = function()
   1.199 +        slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   1.200 +      end
   1.201 +    }
   1.202 +  end
   1.203 +  slot.put("<br style='clear: left'/>")
   1.204  end
   1.205  
   1.206 -if param.get("area_id", atom.integer) then
   1.207 -  area_id = param.get("area_id", atom.integer)
   1.208 -  scope = "area"
   1.209 -end
   1.210 -
   1.211 -
   1.212 -
   1.213 -local delegation
   1.214 -local issue
   1.215 -
   1.216 -if issue_id then
   1.217 -  issue = Issue:by_id(issue_id)
   1.218 -  delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
   1.219 -  if not delegation then
   1.220 -    delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
   1.221 -  end
   1.222 -  if not delegation then
   1.223 -    delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
   1.224 -  end
   1.225 -elseif area_id then
   1.226 -  delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
   1.227 -  if not delegation then
   1.228 -    local area = Area:by_id(area_id)
   1.229 -    delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
   1.230 +if preview_trustee_id == 0 or not preview_trustee_id ==null and delegation and not delegation.trustee_id then
   1.231 +  ui.image{
   1.232 +    static = "icons/16/table_go_crossed.png"
   1.233 +  }
   1.234 +  if delegation.issue_id then
   1.235 +    slot.put(_"Delegation turned off for issue")
   1.236 +  elseif delegation.area_id then
   1.237 +    slot.put(_"Delegation turned off for area")
   1.238    end
   1.239  end
   1.240  
   1.241 -if not delegation then
   1.242 -  delegation = Delegation:by_pk(app.session.member.id, unit_id)
   1.243 -end
   1.244 -
   1.245 -local slot_name = "actions"
   1.246 -
   1.247 -if inline then
   1.248 -  slot_name = "default"
   1.249 -end
   1.250 -
   1.251 -  if delegation and not delegation.trustee_id then
   1.252 -    ui.image{
   1.253 -      static = "icons/16/table_go_crossed.png"
   1.254 -    }
   1.255 -    if delegation.issue_id then
   1.256 -      slot.put(_"Delegation turned off for issue")
   1.257 -    elseif delegation.area_id then
   1.258 -      slot.put(_"Delegation turned off for area")
   1.259 -    end
   1.260 -  end
   1.261 -
   1.262 -  local delegation_chain = Member:new_selector()
   1.263 -    :add_field("delegation_chain.*")
   1.264 -    :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.265 -    :add_order_by("index")
   1.266 -    :exec()
   1.267 -
   1.268 -  for i, record in ipairs(delegation_chain) do
   1.269 -    local style
   1.270 -    local overridden = (not issue or issue.state ~= 'voting') and record.overridden
   1.271 -    if record.scope_in then
   1.272 -      if not overridden then
   1.273 -        ui.image{
   1.274 -          attr = { class = "delegation_arrow" },
   1.275 -          static = "delegation_arrow_24_vertical.png"
   1.276 -        }
   1.277 -      else
   1.278 -        ui.image{
   1.279 -          attr = { class = "delegation_arrow delegation_arrow_overridden" },
   1.280 -          static = "delegation_arrow_24_vertical.png"
   1.281 -        }
   1.282 -      end
   1.283 -      ui.tag{
   1.284 -        attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   1.285 -        content = function()
   1.286 -          if record.scope_in == "unit" then
   1.287 -            slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   1.288 -          elseif record.scope_in == "area" then
   1.289 -            slot.put(_"Area delegation")
   1.290 -          elseif record.scope_in == "issue" then
   1.291 -            slot.put(_"Issue delegation")
   1.292 -          end
   1.293 -        end
   1.294 -      }
   1.295 -    end
   1.296 -    ui.container{
   1.297 -      attr = { class = overridden and "delegation_overridden" or "" },
   1.298 -      content = function()
   1.299 -        execute.view{
   1.300 -          module = "member",
   1.301 -          view = "_show_thumb",
   1.302 -          params = { member = record }
   1.303 -        }
   1.304 -      end
   1.305 -    }
   1.306 -    if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
   1.307 -      ui.container{
   1.308 -        attr = { class = "delegation_participation" },
   1.309 -        content = function()
   1.310 -          slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   1.311 -        end
   1.312 -      }
   1.313 -    end
   1.314 -    slot.put("<br style='clear: left'/>")
   1.315 -  end

Impressum / About Us