liquid_feedback_frontend
view app/main/issue/_show.lua @ 864:2a5c79639aa4
merge
| author | bsw | 
|---|---|
| date | Fri Aug 17 19:55:57 2012 +0200 (2012-08-17) | 
| parents | 4ab1e6f5f039 | 
| children | ea3d3757ddc3 | 
 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_link_text = direct_voter and _"Change vote" or _"Vote now"
    19 local class = "issue"
    20 if issue.is_interested then
    21   class = class .. " interested"
    22 elseif issue.is_interested_by_delegation_to_member_id then
    23   class = class .. " interested_by_delegation"
    24 end
    26 ui.container{ attr = { class = class }, content = function()
    28   execute.view{ module = "delegation", view = "_info", params = { issue = issue, member = for_member } }
    30   if for_listing then
    31     ui.container{ attr = { class = "content" }, content = function()
    32       ui.link{
    33         module = "unit", view = "show", id = issue.area.unit_id,
    34         attr = { class = "unit_link" }, text = issue.area.unit.name
    35       }
    36       slot.put(" ")
    37       ui.link{
    38         module = "area", view = "show", id = issue.area_id,
    39         attr = { class = "area_link" }, text = issue.area.name
    40       }
    41     end }
    42   end
    44   ui.container{ attr = { class = "title" }, content = function()
    46     ui.link{
    47       attr = { class = "issue_id" },
    48       text = _("#{policy_name} ##{issue_id}", {
    49         policy_name = issue.policy.name,
    50         issue_id = issue.id
    51       }),
    52       module = "issue",
    53       view = "show",
    54       id = issue.id
    55     }
    56   end }
    58   ui.tag{
    59     attr = { class = "content issue_policy_info" },
    60     tag = "div",
    61     content = function()
    63       ui.tag{ attr = { class = "event_name" }, content = issue.state_name }
    65       if issue.closed then
    66         slot.put(" · ")
    67         ui.tag{ content = _("#{closed_ago} ago", { closed_ago = issue.closed_ago:gsub("%..*", ""):gsub("days", _"days"):gsub("day", _"day") }) }        
    68       elseif issue.state_time_left then
    69         slot.put(" · ")
    70         if issue.state_time_left:sub(1,1) == "-" then
    71           if issue.state == "accepted" then
    72             ui.tag{ content = _("Discussion starts soon") }
    73           elseif issue.state == "discussion" then
    74             ui.tag{ content = _("Verification starts soon") }
    75           elseif issue.state == "frozen" then
    76             ui.tag{ content = _("Voting starts soon") }
    77           elseif issue.state == "voting" then
    78             ui.tag{ content = _("Counting starts soon") }
    79           end
    80         else
    81           ui.tag{ content = _("#{time_left} left", { time_left = issue.state_time_left:gsub("%..*", ""):gsub("days", _"days"):gsub("day", _"day") }) }
    82         end
    83       end
    85     end
    86   }
    88   local links = {}
    90   if voteable then
    91     links[#links+1] ={
    92       content = vote_link_text,
    93       module = "vote",
    94       view = "list",
    95       params = { issue_id = issue.id }
    96     }
    97   end
    99   if not for_member or for_member.id == app.session.member_id then
   101     if app.session.member_id then
   103       if issue.member_info.own_participation then
   104         if issue.closed then
   105           links[#links+1] = { content = _"You were interested" }
   106         else
   107           links[#links+1] = { content = _"You are interested" }
   108         end
   109       end
   111       if not issue.closed and not issue.fully_frozen then
   112         if issue.member_info.own_participation then
   113           links[#links+1] = {
   114             in_brackets = true,
   115             text    = _"Withdraw",
   116             module  = "interest",
   117             action  = "update",
   118             params  = { issue_id = issue.id, delete = true },
   119             routing = {
   120               default = {
   121                 mode = "redirect",
   122                 module = request.get_module(),
   123                 view = request.get_view(),
   124                 id = param.get_id_cgi(),
   125                 params = param.get_all_cgi()
   126               }
   127             }
   128           }
   129         elseif app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   130           links[#links+1] = {
   131             text    = _"Add my interest",
   132             module  = "interest",
   133             action  = "update",
   134             params  = { issue_id = issue.id },
   135             routing = {
   136               default = {
   137                 mode = "redirect",
   138                 module = request.get_module(),
   139                 view = request.get_view(),
   140                 id = param.get_id_cgi(),
   141                 params = param.get_all_cgi()
   142               }
   143             }
   144           }
   145         end
   146       end
   148       if not issue.closed and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   149         if issue.member_info.own_delegation_scope ~= "issue" then
   150           links[#links+1] = { text = _"Delegate issue", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   151         else
   152           links[#links+1] = { text = _"Change issue delegation", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   153         end
   154       end
   155     end
   157     if config.issue_discussion_url_func then
   158       local url = config.issue_discussion_url_func(issue)
   159       links[#links+1] = {
   160         attr = { target = "_blank" },
   161         external = url,
   162         content = _"Discussion on issue"
   163       }
   164     end
   166     if config.etherpad and app.session.member then
   167       links[#links+1] = {
   168         attr = { target = "_blank" },
   169         external = issue.etherpad_url,
   170         content = _"Issue pad"
   171       }
   172     end
   175     if app.session.member_id and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   176       if not issue.fully_frozen and not issue.closed then
   177       links[#links+1] = {
   178           attr   = { class = "action" },
   179           text   = _"Create alternative initiative",
   180           module = "initiative",
   181           view   = "new",
   182           params = { issue_id = issue.id }
   183         }
   184       end
   185     end
   187   end
   189   ui.container{ attr = { class = "content actions" }, content = function()
   190     for i, link in ipairs(links) do
   191       if link.in_brackets then
   192         slot.put(" (")
   193       elseif i > 1 then
   194         slot.put(" · ")
   195       end
   196       if link.module or link.external then
   197         ui.link(link)
   198       else
   199         ui.tag(link)
   200       end
   201       if link.in_brackets then
   202         slot.put(")")
   203       end
   204     end
   205   end }
   207   if not for_listing then
   208     if issue.state == "cancelled" then
   209       local policy = issue.policy
   210       ui.container{
   211         attr = { class = "not_admitted_info" },
   212         content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
   213       }
   214     end
   215   end
   217   ui.container{ attr = { class = "initiative_list content" }, content = function()
   219     local initiatives_selector = issue:get_reference_selector("initiatives")
   220     local highlight_string = param.get("highlight_string")
   221     if highlight_string then
   222       initiatives_selector:add_field( {'"highlight"("initiative"."name", ?)', highlight_string }, "name_highlighted")
   223     end
   224     execute.view{
   225       module = "initiative",
   226       view = "_list",
   227       params = {
   228         issue = issue,
   229         initiatives_selector = initiatives_selector,
   230         highlight_initiative = for_initiative,
   231         highlight_string = highlight_string,
   232         no_sort = true,
   233         limit = (for_listing or for_initiative) and 5 or nil,
   234         for_member = for_member
   235       }
   236     }
   237   end }
   238 end }
