liquid_feedback_frontend
view app/main/issue/_show.lua @ 886:2e9d39b53b64
Added support for setting/removing of beeing a non voter
| author | bsw | 
|---|---|
| date | Mon Aug 20 02:39:13 2012 +0200 (2012-08-20) | 
| parents | 1e4c6baf2d87 | 
| children | 06e72cc93c64 | 
 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 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         content = _"Cancel do not vote",
   127         module = "vote",
   128         action = "non_voter",
   129         params = { issue_id = issue.id, delete = true },
   130         routing = {
   131           default = {
   132             mode = "redirect",
   133             module = request.get_module(),
   134             view = request.get_view(),
   135             id = param.get_id_cgi(),
   136             params = param.get_all_cgi()
   137           }
   138         }
   139       }
   140     end
   141   end
   143   if not for_member or for_member.id == app.session.member_id then
   145     if app.session.member_id then
   147       if issue.member_info.own_participation then
   148         if issue.closed then
   149           links[#links+1] = { content = _"You were interested" }
   150         else
   151           links[#links+1] = { content = _"You are interested" }
   152         end
   153       end
   155       if not issue.closed and not issue.fully_frozen then
   156         if issue.member_info.own_participation then
   157           links[#links+1] = {
   158             in_brackets = true,
   159             text    = _"Withdraw",
   160             module  = "interest",
   161             action  = "update",
   162             params  = { issue_id = issue.id, delete = true },
   163             routing = {
   164               default = {
   165                 mode = "redirect",
   166                 module = request.get_module(),
   167                 view = request.get_view(),
   168                 id = param.get_id_cgi(),
   169                 params = param.get_all_cgi()
   170               }
   171             }
   172           }
   173         elseif app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   174           links[#links+1] = {
   175             text    = _"Add my interest",
   176             module  = "interest",
   177             action  = "update",
   178             params  = { issue_id = issue.id },
   179             routing = {
   180               default = {
   181                 mode = "redirect",
   182                 module = request.get_module(),
   183                 view = request.get_view(),
   184                 id = param.get_id_cgi(),
   185                 params = param.get_all_cgi()
   186               }
   187             }
   188           }
   189         end
   190       end
   192       if not issue.closed and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   193         if issue.member_info.own_delegation_scope ~= "issue" then
   194           links[#links+1] = { text = _"Delegate issue", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   195         else
   196           links[#links+1] = { text = _"Change issue delegation", module = "delegation", view = "show", params = { issue_id = issue.id, initiative_id = for_initiative_id } }
   197         end
   198       end
   199     end
   201     if config.issue_discussion_url_func then
   202       local url = config.issue_discussion_url_func(issue)
   203       links[#links+1] = {
   204         attr = { target = "_blank" },
   205         external = url,
   206         content = _"Discussion on issue"
   207       }
   208     end
   210     if config.etherpad and app.session.member then
   211       links[#links+1] = {
   212         attr = { target = "_blank" },
   213         external = issue.etherpad_url,
   214         content = _"Issue pad"
   215       }
   216     end
   219     if app.session.member_id and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
   220       if not issue.fully_frozen and not issue.closed then
   221       links[#links+1] = {
   222           attr   = { class = "action" },
   223           text   = _"Create alternative initiative",
   224           module = "initiative",
   225           view   = "new",
   226           params = { issue_id = issue.id }
   227         }
   228       end
   229     end
   231   end
   233   ui.container{ attr = { class = "content actions" }, content = function()
   234     for i, link in ipairs(links) do
   235       if link.in_brackets then
   236         slot.put(" (")
   237       elseif i > 1 then
   238         slot.put(" · ")
   239       end
   240       if link.module or link.external then
   241         ui.link(link)
   242       else
   243         ui.tag(link)
   244       end
   245       if link.in_brackets then
   246         slot.put(")")
   247       end
   248     end
   249   end }
   251   if not for_listing then
   252     if issue.state == "cancelled" then
   253       local policy = issue.policy
   254       ui.container{
   255         attr = { class = "not_admitted_info" },
   256         content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
   257       }
   258     end
   259   end
   261   ui.container{ attr = { class = "initiative_list content" }, content = function()
   263     local initiatives_selector = issue:get_reference_selector("initiatives")
   264     local highlight_string = param.get("highlight_string")
   265     if highlight_string then
   266       initiatives_selector:add_field( {'"highlight"("initiative"."name", ?)', highlight_string }, "name_highlighted")
   267     end
   268     execute.view{
   269       module = "initiative",
   270       view = "_list",
   271       params = {
   272         issue = issue,
   273         initiatives_selector = initiatives_selector,
   274         highlight_initiative = for_initiative,
   275         highlight_string = highlight_string,
   276         no_sort = true,
   277         limit = (for_listing or for_initiative) and 5 or nil,
   278         for_member = for_member
   279       }
   280     }
   281   end }
   282 end }
