liquid_feedback_frontend
view app/main/issue/_show.lua @ 1032:8acb8084a9fd
Code formatting
| author | bsw | 
|---|---|
| date | Mon Aug 12 21:49:00 2013 +0200 (2013-08-12) | 
| parents | 0008714fd208 | 
| children | 
 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 = format.interval_text(issue.closed_ago, { mode = "ago" }) }
    75       elseif issue.state_time_left then
    76         slot.put(" · ")
    77         if issue.state_time_left:sub(1,1) == "-" then
    78           if issue.state == "admission" 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 == "verification" 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 = format.interval_text(issue.state_time_left, { mode = "time_left" }) }
    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 voteable and not direct_voter then
   107     if not issue.member_info.non_voter then
   108       links[#links+1] ={
   109         content = _"Do not vote directly",
   110         module = "vote",
   111         action = "non_voter",
   112         params = { issue_id = issue.id },
   113         routing = {
   114           default = {
   115             mode = "redirect",
   116             module = request.get_module(),
   117             view = request.get_view(),
   118             id = param.get_id_cgi(),
   119             params = param.get_all_cgi()
   120           }
   121         }
   122       }
   123     else
   124       links[#links+1] = { attr = { class = "action" }, content = _"Do not vote directly" }
   125       links[#links+1] ={
   126         in_brackets = true,
   127         content = _"Cancel [nullify]",
   128         module = "vote",
   129         action = "non_voter",
   130         params = { issue_id = issue.id, delete = true },
   131         routing = {
   132           default = {
   133             mode = "redirect",
   134             module = request.get_module(),
   135             view = request.get_view(),
   136             id = param.get_id_cgi(),
   137             params = param.get_all_cgi()
   138           }
   139         }
   140       }
   141     end
   142   end
   144   if not for_member or for_member.id == app.session.member_id then
   146     if app.session.member_id then
   148       if issue.member_info.own_participation then
   149         if issue.closed then
   150           links[#links+1] = { content = _"You were interested" }
   151         else
   152           links[#links+1] = { content = _"You are interested" }
   153         end
   154       end
   156       if not issue.closed and not issue.fully_frozen then
   157         if issue.member_info.own_participation then
   158           links[#links+1] = {
   159             in_brackets = true,
   160             text    = _"Withdraw",
   161             module  = "interest",
   162             action  = "update",
   163             params  = { issue_id = issue.id, delete = true },
   164             routing = {
   165               default = {
   166                 mode = "redirect",
   167                 module = request.get_module(),
   168                 view = request.get_view(),
   169                 id = param.get_id_cgi(),
   170                 params = param.get_all_cgi()
   171               }
   172             }
   173           }
   174         elseif app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   175           links[#links+1] = {
   176             text    = _"Add my interest",
   177             module  = "interest",
   178             action  = "update",
   179             params  = { issue_id = issue.id },
   180             routing = {
   181               default = {
   182                 mode = "redirect",
   183                 module = request.get_module(),
   184                 view = request.get_view(),
   185                 id = param.get_id_cgi(),
   186                 params = param.get_all_cgi()
   187               }
   188             }
   189           }
   190         end
   191       end
   193       if not issue.closed and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   194         if issue.member_info.own_delegation_scope ~= "issue" then
   195           links[#links+1] = { text = _"Delegate issue", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   196         else
   197           links[#links+1] = { text = _"Change issue delegation", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   198         end
   199       end
   200     end
   202     if config.issue_discussion_url_func then
   203       local url = config.issue_discussion_url_func(issue)
   204       links[#links+1] = {
   205         attr = { target = "_blank" },
   206         external = url,
   207         content = _"Discussion on issue"
   208       }
   209     end
   211     if config.etherpad and app.session.member then
   212       links[#links+1] = {
   213         attr = { target = "_blank" },
   214         external = issue.etherpad_url,
   215         content = _"Issue pad"
   216       }
   217     end
   220     if app.session.member_id and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   221       if not issue.fully_frozen and not issue.closed then
   222       links[#links+1] = {
   223           attr   = { class = "action" },
   224           text   = _"Create alternative initiative",
   225           module = "initiative",
   226           view   = "new",
   227           params = { issue_id = issue.id }
   228         }
   229       end
   230     end
   232   end
   234   ui.container{ attr = { class = "content actions" }, content = function()
   235     for i, link in ipairs(links) do
   236       if link.in_brackets then
   237         slot.put(" (")
   238       elseif i > 1 then
   239         slot.put(" · ")
   240       end
   241       if link.module or link.external then
   242         ui.link(link)
   243       else
   244         ui.tag(link)
   245       end
   246       if link.in_brackets then
   247         slot.put(")")
   248       end
   249     end
   250   end }
   252   if not for_listing then
   253     if issue.state == "canceled_by_admin" then
   254       ui.container{
   255         attr = { class = "not_admitted_info" },
   256         content = function()
   257           ui.container{ content = _("This issue has been canceled by administrative intervention.") }
   258           slot.put("<br />")
   259           if issue.admin_notice then
   260             ui.container{ content = function() slot.put(encode.html_newlines(issue.admin_notice)) end }
   261           end
   262         end
   263       }
   264     elseif issue.admin_notice then
   265       ui.container{
   266         attr = { class = "not_admitted_info" },
   267         content = function() slot.put(encode.html_newlines(issue.admin_notice)) end
   268       }
   269     end
   271     if issue.state == "canceled_issue_not_accepted" then
   272       local policy = issue.policy
   273       ui.container{
   274         attr = { class = "not_admitted_info" },
   275         content = _("This issue has been canceled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
   276       }
   277     elseif
   278       issue.state:sub(1, #("canceled_")) == "canceled_" and 
   279       issue.state ~= "canceled_by_admin"
   280     then
   281       ui.container{
   282         attr = { class = "not_admitted_info" },
   283         content = _("This issue has been canceled.")
   284       }
   285     end
   286   end
   288   ui.container{ attr = { class = "initiative_list content" }, content = function()
   290     local initiatives_selector = issue:get_reference_selector("initiatives")
   291     local highlight_string = param.get("highlight_string")
   292     if highlight_string then
   293       initiatives_selector:add_field( {'"highlight"("initiative"."name", ?)', highlight_string }, "name_highlighted")
   294     end
   295     execute.view{
   296       module = "initiative",
   297       view = "_list",
   298       params = {
   299         issue = issue,
   300         initiatives_selector = initiatives_selector,
   301         highlight_initiative = for_initiative,
   302         highlight_string = highlight_string,
   303         no_sort = true,
   304         limit = (for_listing or for_initiative) and 5 or nil,
   305         for_member = for_member
   306       }
   307     }
   308   end }
   309 end }
