liquid_feedback_frontend
view app/main/issue/_show.lua @ 574:e7baf2713987
Make direct delegation to initiator work again
| author | bsw | 
|---|---|
| date | Tue Jun 19 23:42:13 2012 +0200 (2012-06-19) | 
| parents | b8e72db6dd0d | 
| children | 09a91ebcbb8c | 
 line source
     1 local issue = param.get("issue", "table")
     2 local initiative_limit = param.get("initiative_limit", atom.integer)
     3 local for_listing = param.get("for_listing", atom.boolean)
     4 local for_initiative = param.get("for_initiative", "table")
     5 local for_initiative_id = for_initiative and for_initiative.id or nil
     7 local direct_voter
     8 if app.session.member_id then
     9   direct_voter = issue.member_info.direct_voted
    10 end
    12 local voteable = app.session.member_id and issue.state == 'voting' and
    13        app.session.member:has_voting_right_for_unit_id(issue.area.unit_id)
    15 local vote_link_text = direct_voter and _"Change vote" or "Vote now"
    18 local class = "issue"
    19 if issue.is_interested then
    20   class = class .. " interested"
    21 elseif issue.is_interested_by_delegation_to_member_id then
    22   class = class .. " interested_by_delegation"
    23 end
    25 ui.container{ attr = { class = class }, content = function()
    27   execute.view{ module = "delegation", view = "_info", params = { issue = issue } }
    29   ui.container{ attr = { class = "title" }, content = function()
    31     ui.link{
    32       attr = { class = "issue_id" },
    33       text = _("#{policy_name} ##{issue_id}", {
    34         policy_name = issue.policy.name,
    35         issue_id = issue.id
    36       }),
    37       module = "issue",
    38       view = "show",
    39       id = issue.id
    40     }
    41   end }
    42   if for_listing then
    43     ui.container{ attr = { class = "content" }, content = function()
    44       ui.tag{ content = issue.area.unit.name }
    45       slot.put(" · ")
    46       ui.tag{ content = issue.area.name }
    47     end }
    48   end
    50   ui.tag{
    51     attr = { class = "content issue_policy_info" },
    52     tag = "div",
    53     content = function()
    55       ui.tag{ attr = { class = "event_name" }, content = issue.state_name }
    57       if issue.state_time_left then
    58         slot.put(" · ")
    59         if issue.state_time_left:sub(1,1) == "-" then
    60           if issue.state == "accepted" then
    61             ui.tag{ content = _("Discussion starts soon") }
    62           elseif issue.state == "discussion" then
    63             ui.tag{ content = _("Verification starts soon") }
    64           elseif issue.state == "frozen" then
    65             ui.tag{ content = _("Voting starts soon") }
    66           elseif issue.state == "voting" then
    67             ui.tag{ content = _("Counting starts soon") }
    68           end
    69         else
    70           ui.tag{ content = _("#{time_left} left", { time_left = issue.state_time_left:gsub("days", _"days"):gsub("day", _"day") }) }
    71         end
    72       end
    74     end
    75   }
    77   local links = {}
    79     if voteable then
    80       links[#links+1] ={
    81         content = vote_link_text,
    82         module = "vote",
    83         view = "list",
    84         params = { issue_id = issue.id }
    85       }
    86     end
    88     if app.session.member_id then
    90       if issue.member_info.own_participation then
    91         if issue.closed then
    92           links[#links+1] = { content = _"You were interested" }
    93         else
    94           links[#links+1] = { content = _"You are interested" }
    95         end
    96       end
    98       if not issue.closed and not issue.fully_frozen then
    99         if issue.member_info.own_participation then
   100           links[#links+1] = {
   101             in_brackets = true,
   102             text    = _"Withdraw",
   103             module  = "interest",
   104             action  = "update",
   105             params  = { issue_id = issue.id, delete = true },
   106             routing = {
   107               default = {
   108                 mode = "redirect",
   109                 module = request.get_module(),
   110                 view = request.get_view(),
   111                 id = param.get_id_cgi(),
   112                 params = param.get_all_cgi()
   113               }
   114             }
   115           }
   116         elseif app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   117           links[#links+1] = {
   118             text    = _"Add my interest",
   119             module  = "interest",
   120             action  = "update",
   121             params  = { issue_id = issue.id },
   122             routing = {
   123               default = {
   124                 mode = "redirect",
   125                 module = request.get_module(),
   126                 view = request.get_view(),
   127                 id = param.get_id_cgi(),
   128                 params = param.get_all_cgi()
   129               }
   130             }
   131           }
   132         end
   133       end
   134     end
   136     if not issue.closed and app.session.member_id and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   137       if issue.member_info.own_delegation_scope ~= "issue" then
   138         links[#links+1] = { text = _"Delegate issue", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   139       else
   140         links[#links+1] = { text = _"Change issue delegation", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   141       end
   142     end
   144     if config.issue_discussion_url_func then
   145       local url = config.issue_discussion_url_func(issue)
   146       links[#links+1] = {
   147         attr = { target = "_blank" },
   148         external = url,
   149         content = _"Discussion on issue"
   150       }
   151     end
   153     if config.etherpad and app.session.member then
   154       links[#links+1] = {
   155         attr = { target = "_blank" },
   156         external = issue.etherpad_url,
   157         content = _"Issue pad"
   158       }
   159     end
   162     if app.session.member_id and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   163       if not issue.fully_frozen and not issue.closed then
   164       links[#links+1] = {
   165           attr   = { class = "action" },
   166           text   = _"Create alternative initiative",
   167           module = "initiative",
   168           view   = "new",
   169           params = { issue_id = issue.id }
   170         }
   171       end
   172     end
   174   ui.container{ attr = { class = "content actions" }, content = function()
   175     for i, link in ipairs(links) do
   176       if link.in_brackets then
   177         slot.put(" (")
   178       elseif i > 1 then
   179         slot.put(" · ")
   180       end
   181       if link.module then
   182         ui.link(link)
   183       else
   184         ui.tag(link)
   185       end
   186       if link.in_brackets then
   187         slot.put(")")
   188       end
   189     end
   190   end }
   192   if not for_listing then
   194     if voteable then
   195       ui.container{
   196         attr = { class = "voting_active_info" },
   197         content = function()
   198           slot.put(_"Voting for this issue is currently running!")
   199           slot.put(" ")
   200           if app.session.member_id then
   201             ui.link{
   202               content = vote_link_text,
   203               module = "vote",
   204               view = "list",
   205               params = { issue_id = issue.id }
   206             }
   207           end
   208         end
   209       }
   210     end
   212     if issue.state == "cancelled" then
   213       local policy = issue.policy
   214       ui.container{
   215         attr = { class = "not_admitted_info" },
   216         content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
   217       }
   218     end
   220   end
   222   ui.container{ attr = { class = "initiative_list" }, content = function()
   224     local initiatives_selector = issue:get_reference_selector("initiatives")
   225     local highlight_string = param.get("highlight_string")
   226     if highlight_string then
   227       initiatives_selector:add_field( {'"highlight"("initiative"."name", ?)', highlight_string }, "name_highlighted")
   228     end
   229     execute.view{
   230       module = "initiative",
   231       view = "_list",
   232       params = {
   233         issue = issue,
   234         initiatives_selector = initiatives_selector,
   235         highlight_string = highlight_string,
   236         no_sort = true,
   237         limit = 5,
   238         for_member = for_member
   239       }
   240     }
   241   end }
   242 end }
