liquid_feedback_frontend

changeset 575:5650f8163a29

Fixed errors from delegation dialog
author bsw
date Wed Jun 20 00:22:53 2012 +0200 (2012-06-20)
parents e7baf2713987
children bf744a72c406
files app/main/delegation/_action/update.lua app/main/delegation/show.lua
line diff
     1.1 --- a/app/main/delegation/_action/update.lua	Tue Jun 19 23:42:13 2012 +0200
     1.2 +++ b/app/main/delegation/_action/update.lua	Wed Jun 20 00:22:53 2012 +0200
     1.3 @@ -8,6 +8,8 @@
     1.4  
     1.5  local issue_id = param.get("issue_id", atom.integer)
     1.6  
     1.7 +local initiative_id = param.get("initiative_id", atom.integer)
     1.8 +
     1.9  if issue_id then 
    1.10    area_id = nil
    1.11  end
    1.12 @@ -16,7 +18,7 @@
    1.13  
    1.14  if preview == "1" then
    1.15    request.redirect{ module = "delegation", view = "show", params = {
    1.16 -    unit_id = unit_id, area_id = area_id, issue_id = issue_id, preview_trustee_id = trustee_id
    1.17 +    unit_id = unit_id, area_id = area_id, issue_id = issue_id, initiative_id = initiative_id, preview_trustee_id = trustee_id
    1.18    } }
    1.19    return
    1.20  end
     2.1 --- a/app/main/delegation/show.lua	Tue Jun 19 23:42:13 2012 +0200
     2.2 +++ b/app/main/delegation/show.lua	Wed Jun 20 00:22:53 2012 +0200
     2.3 @@ -38,7 +38,62 @@
     2.4    util.help("delegation.new.issue")
     2.5  end
     2.6  
     2.7 -local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
     2.8 +
     2.9 +local delegation
    2.10 +local unit_id
    2.11 +local area_id
    2.12 +local issue_id
    2.13 +local initiative_id
    2.14 +local initiative
    2.15 +
    2.16 +local scope = "unit"
    2.17 +
    2.18 +unit_id = param.get("unit_id", atom.integer)
    2.19 +
    2.20 +local inline = param.get("inline", atom.boolean)
    2.21 +
    2.22 +if param.get("initiative_id", atom.integer) then
    2.23 +  initiative_id = param.get("initiative_id", atom.integer)
    2.24 +  initiative = Initiative:by_id(initiative_id)
    2.25 +  issue_id = initiative.issue_id
    2.26 +  scope = "issue"
    2.27 +end
    2.28 +
    2.29 +if param.get("issue_id", atom.integer) then
    2.30 +  issue_id = param.get("issue_id", atom.integer)
    2.31 +  scope = "issue"
    2.32 +end
    2.33 +
    2.34 +if param.get("area_id", atom.integer) then
    2.35 +  area_id = param.get("area_id", atom.integer)
    2.36 +  scope = "area"
    2.37 +end
    2.38 +
    2.39 +
    2.40 +
    2.41 +local delegation
    2.42 +local issue
    2.43 +
    2.44 +if issue_id then
    2.45 +  issue = Issue:by_id(issue_id)
    2.46 +  delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
    2.47 +  if not delegation then
    2.48 +    delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
    2.49 +  end
    2.50 +  if not delegation then
    2.51 +    delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
    2.52 +  end
    2.53 +elseif area_id then
    2.54 +  delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
    2.55 +  if not delegation then
    2.56 +    local area = Area:by_id(area_id)
    2.57 +    delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
    2.58 +  end
    2.59 +end
    2.60 +
    2.61 +if not delegation then
    2.62 +  delegation = Delegation:by_pk(app.session.member.id, unit_id)
    2.63 +end
    2.64  
    2.65  local contact_members = Member:build_selector{
    2.66    is_contact_of_member_id = app.session.member_id,
    2.67 @@ -93,13 +148,14 @@
    2.68      unit_id = unit and unit.id or nil,
    2.69      area_id = area and area.id or nil,
    2.70      issue_id = issue and issue.id or nil,
    2.71 +    initiative_id = initiative_id
    2.72    },
    2.73    routing = {
    2.74      default = {
    2.75        mode = "redirect",
    2.76        module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
    2.77        view = "show",
    2.78 -      id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id
    2.79 +      id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
    2.80      }
    2.81    },
    2.82    content = function()
    2.83 @@ -182,15 +238,25 @@
    2.84        end
    2.85      end
    2.86      -- add saved members
    2.87 -    records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
    2.88 -    for i, record in ipairs(contact_members) do
    2.89 -      records[#records+1] = record
    2.90 +    if #contact_members > 0 then
    2.91 +      records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
    2.92 +      for i, record in ipairs(contact_members) do
    2.93 +        records[#records+1] = record
    2.94 +      end
    2.95      end
    2.96  
    2.97      disabled_records = {}
    2.98      disabled_records["_"] = true
    2.99      disabled_records[app.session.member_id] = true
   2.100  
   2.101 +    local value = current_trustee_id
   2.102 +    if preview_trustee_id then
   2.103 +      value = preview_trustee_id
   2.104 +    end
   2.105 +    if preview_trustee_id == nil and delegation and not delegation.trustee_id then
   2.106 +      value = 0
   2.107 +    end
   2.108 +    
   2.109      ui.field.select{
   2.110        attr = { onchange = "updateDelegationInfo();" },
   2.111        label = _"Trustee",
   2.112 @@ -199,7 +265,7 @@
   2.113        foreign_id = "id",
   2.114        foreign_name = "name",
   2.115        disabled_records = disabled_records,
   2.116 -      value = preview_trustee_id or current_trustee_id
   2.117 +      value = value
   2.118      }
   2.119  
   2.120      ui.field.hidden{ name = "preview" }
   2.121 @@ -210,134 +276,72 @@
   2.122  }
   2.123  
   2.124  
   2.125 -
   2.126  -- ------------------------
   2.127  
   2.128  
   2.129 -
   2.130 -
   2.131 -local delegation
   2.132 -local unit_id
   2.133 -local area_id
   2.134 -local issue_id
   2.135 -local initiative_id
   2.136 -
   2.137 -local scope = "unit"
   2.138 -
   2.139 -unit_id = param.get("unit_id", atom.integer)
   2.140 +local delegation_chain = Member:new_selector()
   2.141 +  :add_field("delegation_chain.*")
   2.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")
   2.143 +  :add_order_by("index")
   2.144 +  :exec()
   2.145  
   2.146 -local inline = param.get("inline", atom.boolean)
   2.147 -
   2.148 -if param.get("initiative_id", atom.integer) then
   2.149 -  initiative_id = param.get("initiative_id", atom.integer)
   2.150 -  issue_id = Initiative:by_id(initiative_id).issue_id
   2.151 -  scope = "issue"
   2.152 -end
   2.153 -
   2.154 -if param.get("issue_id", atom.integer) then
   2.155 -  issue_id = param.get("issue_id", atom.integer)
   2.156 -  scope = "issue"
   2.157 +for i, record in ipairs(delegation_chain) do
   2.158 +  local style
   2.159 +  local overridden = (not issue or issue.state ~= 'voting') and record.overridden
   2.160 +  if record.scope_in then
   2.161 +    if not overridden then
   2.162 +      ui.image{
   2.163 +        attr = { class = "delegation_arrow" },
   2.164 +        static = "delegation_arrow_24_vertical.png"
   2.165 +      }
   2.166 +    else
   2.167 +      ui.image{
   2.168 +        attr = { class = "delegation_arrow delegation_arrow_overridden" },
   2.169 +        static = "delegation_arrow_24_vertical.png"
   2.170 +      }
   2.171 +    end
   2.172 +    ui.tag{
   2.173 +      attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   2.174 +      content = function()
   2.175 +        if record.scope_in == "unit" then
   2.176 +          slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   2.177 +        elseif record.scope_in == "area" then
   2.178 +          slot.put(_"Area delegation")
   2.179 +        elseif record.scope_in == "issue" then
   2.180 +          slot.put(_"Issue delegation")
   2.181 +        end
   2.182 +      end
   2.183 +    }
   2.184 +  end
   2.185 +  ui.container{
   2.186 +    attr = { class = overridden and "delegation_overridden" or "" },
   2.187 +    content = function()
   2.188 +      execute.view{
   2.189 +        module = "member",
   2.190 +        view = "_show_thumb",
   2.191 +        params = { member = record }
   2.192 +      }
   2.193 +    end
   2.194 +  }
   2.195 +  if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
   2.196 +    ui.container{
   2.197 +      attr = { class = "delegation_participation" },
   2.198 +      content = function()
   2.199 +        slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   2.200 +      end
   2.201 +    }
   2.202 +  end
   2.203 +  slot.put("<br style='clear: left'/>")
   2.204  end
   2.205  
   2.206 -if param.get("area_id", atom.integer) then
   2.207 -  area_id = param.get("area_id", atom.integer)
   2.208 -  scope = "area"
   2.209 -end
   2.210 -
   2.211 -
   2.212 -
   2.213 -local delegation
   2.214 -local issue
   2.215 -
   2.216 -if issue_id then
   2.217 -  issue = Issue:by_id(issue_id)
   2.218 -  delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
   2.219 -  if not delegation then
   2.220 -    delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
   2.221 -  end
   2.222 -  if not delegation then
   2.223 -    delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
   2.224 -  end
   2.225 -elseif area_id then
   2.226 -  delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
   2.227 -  if not delegation then
   2.228 -    local area = Area:by_id(area_id)
   2.229 -    delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
   2.230 +if preview_trustee_id == 0 or not preview_trustee_id ==null and delegation and not delegation.trustee_id then
   2.231 +  ui.image{
   2.232 +    static = "icons/16/table_go_crossed.png"
   2.233 +  }
   2.234 +  if delegation.issue_id then
   2.235 +    slot.put(_"Delegation turned off for issue")
   2.236 +  elseif delegation.area_id then
   2.237 +    slot.put(_"Delegation turned off for area")
   2.238    end
   2.239  end
   2.240  
   2.241 -if not delegation then
   2.242 -  delegation = Delegation:by_pk(app.session.member.id, unit_id)
   2.243 -end
   2.244 -
   2.245 -local slot_name = "actions"
   2.246 -
   2.247 -if inline then
   2.248 -  slot_name = "default"
   2.249 -end
   2.250 -
   2.251 -  if delegation and not delegation.trustee_id then
   2.252 -    ui.image{
   2.253 -      static = "icons/16/table_go_crossed.png"
   2.254 -    }
   2.255 -    if delegation.issue_id then
   2.256 -      slot.put(_"Delegation turned off for issue")
   2.257 -    elseif delegation.area_id then
   2.258 -      slot.put(_"Delegation turned off for area")
   2.259 -    end
   2.260 -  end
   2.261 -
   2.262 -  local delegation_chain = Member:new_selector()
   2.263 -    :add_field("delegation_chain.*")
   2.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")
   2.265 -    :add_order_by("index")
   2.266 -    :exec()
   2.267 -
   2.268 -  for i, record in ipairs(delegation_chain) do
   2.269 -    local style
   2.270 -    local overridden = (not issue or issue.state ~= 'voting') and record.overridden
   2.271 -    if record.scope_in then
   2.272 -      if not overridden then
   2.273 -        ui.image{
   2.274 -          attr = { class = "delegation_arrow" },
   2.275 -          static = "delegation_arrow_24_vertical.png"
   2.276 -        }
   2.277 -      else
   2.278 -        ui.image{
   2.279 -          attr = { class = "delegation_arrow delegation_arrow_overridden" },
   2.280 -          static = "delegation_arrow_24_vertical.png"
   2.281 -        }
   2.282 -      end
   2.283 -      ui.tag{
   2.284 -        attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   2.285 -        content = function()
   2.286 -          if record.scope_in == "unit" then
   2.287 -            slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   2.288 -          elseif record.scope_in == "area" then
   2.289 -            slot.put(_"Area delegation")
   2.290 -          elseif record.scope_in == "issue" then
   2.291 -            slot.put(_"Issue delegation")
   2.292 -          end
   2.293 -        end
   2.294 -      }
   2.295 -    end
   2.296 -    ui.container{
   2.297 -      attr = { class = overridden and "delegation_overridden" or "" },
   2.298 -      content = function()
   2.299 -        execute.view{
   2.300 -          module = "member",
   2.301 -          view = "_show_thumb",
   2.302 -          params = { member = record }
   2.303 -        }
   2.304 -      end
   2.305 -    }
   2.306 -    if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
   2.307 -      ui.container{
   2.308 -        attr = { class = "delegation_participation" },
   2.309 -        content = function()
   2.310 -          slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   2.311 -        end
   2.312 -      }
   2.313 -    end
   2.314 -    slot.put("<br style='clear: left'/>")
   2.315 -  end

Impressum / About Us