liquid_feedback_frontend
view app/main/issue/_show.lua @ 884:a1c7858c15e9
Show voting ballot from access_level all_pseudonymous and up
| author | bsw | 
|---|---|
| date | Mon Aug 20 01:29:18 2012 +0200 (2012-08-20) | 
| parents | 1e4c6baf2d87 | 
| children | 2e9d39b53b64 | 
 line source
     1 local issue = param.get("issue", "table")
     2 local initiative_limit = param.get("initiative_limit", atom.integer)
     3 local for_member = param.get("for_member", "table")
     4 local for_listing = param.get("for_listing", atom.boolean)
     5 local for_initiative = param.get("for_initiative", "table")
     6 local for_initiative_id = for_initiative and for_initiative.id or nil
     8 local direct_voter
     9 if app.session.member_id then
    10   direct_voter = issue.member_info.direct_voted
    11 end
    13 local voteable = app.session.member_id and issue.state == 'voting' and
    14        app.session.member:has_voting_right_for_unit_id(issue.area.unit_id)
    16 local vote_comment_able = app.session.member_id and issue.closed and direct_voter
    18 local vote_link_text
    19 if voteable then 
    20   vote_link_text = direct_voter and _"Change vote" or _"Vote now"
    21 elseif vote_comment_able then
    22   vote_link_text = direct_voter and _"Update voting comment"
    23 end  
    26 local class = "issue"
    27 if issue.is_interested then
    28   class = class .. " interested"
    29 elseif issue.is_interested_by_delegation_to_member_id then
    30   class = class .. " interested_by_delegation"
    31 end
    33 ui.container{ attr = { class = class }, content = function()
    35   execute.view{ module = "delegation", view = "_info", params = { issue = issue, member = for_member } }
    37   if for_listing then
    38     ui.container{ attr = { class = "content" }, content = function()
    39       ui.link{
    40         module = "unit", view = "show", id = issue.area.unit_id,
    41         attr = { class = "unit_link" }, text = issue.area.unit.name
    42       }
    43       slot.put(" ")
    44       ui.link{
    45         module = "area", view = "show", id = issue.area_id,
    46         attr = { class = "area_link" }, text = issue.area.name
    47       }
    48     end }
    49   end
    51   ui.container{ attr = { class = "title" }, content = function()
    53     ui.link{
    54       attr = { class = "issue_id" },
    55       text = _("#{policy_name} ##{issue_id}", {
    56         policy_name = issue.policy.name,
    57         issue_id = issue.id
    58       }),
    59       module = "issue",
    60       view = "show",
    61       id = issue.id
    62     }
    63   end }
    65   ui.tag{
    66     attr = { class = "content issue_policy_info" },
    67     tag = "div",
    68     content = function()
    70       ui.tag{ attr = { class = "event_name" }, content = issue.state_name }
    72       if issue.closed then
    73         slot.put(" · ")
    74         ui.tag{ content = _("#{closed_ago} ago", { closed_ago = issue.closed_ago:gsub("%..*", ""):gsub("days", _"days"):gsub("day", _"day") }) }        
    75       elseif issue.state_time_left then
    76         slot.put(" · ")
    77         if issue.state_time_left:sub(1,1) == "-" then
    78           if issue.state == "accepted" then
    79             ui.tag{ content = _("Discussion starts soon") }
    80           elseif issue.state == "discussion" then
    81             ui.tag{ content = _("Verification starts soon") }
    82           elseif issue.state == "frozen" then
    83             ui.tag{ content = _("Voting starts soon") }
    84           elseif issue.state == "voting" then
    85             ui.tag{ content = _("Counting starts soon") }
    86           end
    87         else
    88           ui.tag{ content = _("#{time_left} left", { time_left = issue.state_time_left:gsub("%..*", ""):gsub("days", _"days"):gsub("day", _"day") }) }
    89         end
    90       end
    92     end
    93   }
    95   local links = {}
    97   if vote_link_text then
    98     links[#links+1] ={
    99       content = vote_link_text,
   100       module = "vote",
   101       view = "list",
   102       params = { issue_id = issue.id }
   103     }
   104   end
   106   if not for_member or for_member.id == app.session.member_id then
   108     if app.session.member_id then
   110       if issue.member_info.own_participation then
   111         if issue.closed then
   112           links[#links+1] = { content = _"You were interested" }
   113         else
   114           links[#links+1] = { content = _"You are interested" }
   115         end
   116       end
   118       if not issue.closed and not issue.fully_frozen then
   119         if issue.member_info.own_participation then
   120           links[#links+1] = {
   121             in_brackets = true,
   122             text    = _"Withdraw",
   123             module  = "interest",
   124             action  = "update",
   125             params  = { issue_id = issue.id, delete = true },
   126             routing = {
   127               default = {
   128                 mode = "redirect",
   129                 module = request.get_module(),
   130                 view = request.get_view(),
   131                 id = param.get_id_cgi(),
   132                 params = param.get_all_cgi()
   133               }
   134             }
   135           }
   136         elseif app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   137           links[#links+1] = {
   138             text    = _"Add my interest",
   139             module  = "interest",
   140             action  = "update",
   141             params  = { issue_id = issue.id },
   142             routing = {
   143               default = {
   144                 mode = "redirect",
   145                 module = request.get_module(),
   146                 view = request.get_view(),
   147                 id = param.get_id_cgi(),
   148                 params = param.get_all_cgi()
   149               }
   150             }
   151           }
   152         end
   153       end
   155       if not issue.closed and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   156         if issue.member_info.own_delegation_scope ~= "issue" then
   157           links[#links+1] = { text = _"Delegate issue", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   158         else
   159           links[#links+1] = { text = _"Change issue delegation", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   160         end
   161       end
   162     end
   164     if config.issue_discussion_url_func then
   165       local url = config.issue_discussion_url_func(issue)
   166       links[#links+1] = {
   167         attr = { target = "_blank" },
   168         external = url,
   169         content = _"Discussion on issue"
   170       }
   171     end
   173     if config.etherpad and app.session.member then
   174       links[#links+1] = {
   175         attr = { target = "_blank" },
   176         external = issue.etherpad_url,
   177         content = _"Issue pad"
   178       }
   179     end
   182     if app.session.member_id and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   183       if not issue.fully_frozen and not issue.closed then
   184       links[#links+1] = {
   185           attr   = { class = "action" },
   186           text   = _"Create alternative initiative",
   187           module = "initiative",
   188           view   = "new",
   189           params = { issue_id = issue.id }
   190         }
   191       end
   192     end
   194   end
   196   ui.container{ attr = { class = "content actions" }, content = function()
   197     for i, link in ipairs(links) do
   198       if link.in_brackets then
   199         slot.put(" (")
   200       elseif i > 1 then
   201         slot.put(" · ")
   202       end
   203       if link.module or link.external then
   204         ui.link(link)
   205       else
   206         ui.tag(link)
   207       end
   208       if link.in_brackets then
   209         slot.put(")")
   210       end
   211     end
   212   end }
   214   if not for_listing then
   215     if issue.state == "cancelled" then
   216       local policy = issue.policy
   217       ui.container{
   218         attr = { class = "not_admitted_info" },
   219         content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
   220       }
   221     end
   222   end
   224   ui.container{ attr = { class = "initiative_list content" }, content = function()
   226     local initiatives_selector = issue:get_reference_selector("initiatives")
   227     local highlight_string = param.get("highlight_string")
   228     if highlight_string then
   229       initiatives_selector:add_field( {'"highlight"("initiative"."name", ?)', highlight_string }, "name_highlighted")
   230     end
   231     execute.view{
   232       module = "initiative",
   233       view = "_list",
   234       params = {
   235         issue = issue,
   236         initiatives_selector = initiatives_selector,
   237         highlight_initiative = for_initiative,
   238         highlight_string = highlight_string,
   239         no_sort = true,
   240         limit = (for_listing or for_initiative) and 5 or nil,
   241         for_member = for_member
   242       }
   243     }
   244   end }
   245 end }
