liquid_feedback_frontend
view app/main/initiative/_show.lua @ 276:f460555c9896
Code cleanup
| author | bsw | 
|---|---|
| date | Sun Feb 12 20:03:26 2012 +0100 (2012-02-12) | 
| parents | aec9df5b4cd3 | 
| children | fecd4c13054a | 
 line source
     1 local initiative = param.get("initiative", "table")
     2 local initiator = param.get("initiator", "table")
     4 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
     5   :add_field("initiator.accepted", "accepted")
     7 if not (initiator and initiator.accepted) then
     8   initiators_members_selector:add_where("initiator.accepted")
     9 end
    11 local initiators = initiators_members_selector:exec()
    14 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
    15 slot.select("initiatives_list", function()
    16   execute.view{
    17     module = "initiative",
    18     view = "_list",
    19     params = {
    20       issue = initiative.issue,
    21       initiatives_selector = initiatives_selector,
    22       no_sort = true, highlight_initiative = initiative, limit = 3
    23     }
    24   }
    25 end)
    27 slot.select("initiative_head", function()
    29   ui.container{
    30     attr = { class = "initiative_name" },
    31     content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
    32   }
    33   if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
    34     ui.tag{
    35       attr = { class = "initiator_names" },
    36       content = function()
    37         ui.tag{ content = _"by" }
    38         slot.put(" ")
    39         for i, initiator in ipairs(initiators) do
    40           if i == #initiators and i > 1 then
    41             slot.put(" ", _"and", " ")
    42           elseif i > 1 then
    43             slot.put(", ")
    44           end
    45           ui.link{
    46             text = initiator.name,
    47             module = "member", view = "show", id = initiator.id
    48           }
    49         end
    50       end
    51     }
    52   end
    54   if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
    55     slot.put(" · ")
    56     ui.link{
    57       attr = { class = "action" },
    58       content = function()
    59         slot.put(_"Invite initiator")
    60       end,
    61       module = "initiative",
    62       view = "add_initiator",
    63       params = { initiative_id = initiative.id }
    64     }
    65     if #initiators > 1 then
    66       slot.put(" · ")
    67       ui.link{
    68         content = function()
    69           slot.put(_"Remove initiator")
    70         end,
    71         module = "initiative",
    72         view = "remove_initiator",
    73         params = { initiative_id = initiative.id }
    74       }
    75     end
    76   end
    77   if initiator and initiator.accepted == false then
    78       slot.put(" · ")
    79       ui.link{
    80         text   = _"Cancel refuse of invitation",
    81         module = "initiative",
    82         action = "remove_initiator",
    83         params = {
    84           initiative_id = initiative.id,
    85           member_id = app.session.member.id
    86         },
    87         routing = {
    88           ok = {
    89             mode = "redirect",
    90             module = "initiative",
    91             view = "show",
    92             id = initiative.id
    93           }
    94         }
    95       }
    96   end
    99 end )
   101 util.help("initiative.show")
   104 if initiative.issue.ranks_available and initiative.admitted then
   105   local class = initiative.rank == 1 and "admitted_info" or "not_admitted_info"
   106   ui.container{
   107     attr = { class = class },
   108     content = function()
   109       local max_value = initiative.issue.voter_count
   110       slot.put(" ")
   111       local positive_votes = initiative.positive_votes
   112       local negative_votes = initiative.negative_votes
   113       local sum_votes = initiative.positive_votes + initiative.negative_votes
   114       local function perc(votes, sum)
   115         if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
   116         return ""
   117       end
   118       slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
   119       slot.put(" · ")
   120       slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
   121       slot.put(" · ")
   122       slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
   123       slot.put(" · ")
   124       slot.put("<b>")
   125       if initiative.rank == 1 then
   126         slot.put(_"Approved")
   127       elseif initiative.rank then
   128         slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
   129       else
   130         slot.put(_"Not approved")
   131       end
   132       slot.put("</b>")
   133     end
   134   }
   135 end
   137 if initiative.admitted == false then
   138   local policy = initiative.issue.policy
   139   ui.container{
   140     attr = { class = "not_admitted_info" },
   141     content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
   142   }
   143 end
   145 local web20 = config.user_tab_mode == "accordeon"
   146   or config.user_tab_mode == "accordeon_first_expanded"
   147   or config.user_tab_mode == "accordeon_all_expanded"
   149 if not web20 and initiative.issue.state == "cancelled" then
   150   local policy = initiative.issue.policy
   151   ui.container{
   152     attr = { class = "not_admitted_info" },
   153     content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
   154   }
   155 end
   157 if initiative.revoked then
   158   ui.container{
   159     attr = { class = "revoked_info" },
   160     content = function()
   161       slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
   162       local suggested_initiative = initiative.suggested_initiative
   163       if suggested_initiative then
   164         slot.put("<br /><br />")
   165         slot.put(_("The initiators suggest to support the following initiative:"))
   166         slot.put(" ")
   167         ui.link{
   168           content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
   169           module = "initiative",
   170           view = "show",
   171           id = suggested_initiative.id
   172         }
   173       end
   174     end
   175   }
   176 end
   178 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
   179   ui.container{
   180     attr = { class = "initiator_invite_info" },
   181     content = function()
   182       slot.put(_"You are invited to become initiator of this initiative.")
   183       slot.put(" ")
   184       ui.link{
   185         image  = { static = "icons/16/tick.png" },
   186         text   = _"Accept invitation",
   187         module = "initiative",
   188         action = "accept_invitation",
   189         id     = initiative.id,
   190         routing = {
   191           default = {
   192             mode = "redirect",
   193             module = request.get_module(),
   194             view = request.get_view(),
   195             id = param.get_id_cgi(),
   196             params = param.get_all_cgi()
   197           }
   198         }
   199       }
   200       slot.put(" ")
   201       ui.link{
   202         image  = { static = "icons/16/cross.png" },
   203         text   = _"Refuse invitation",
   204         module = "initiative",
   205         action = "reject_initiator_invitation",
   206         params = {
   207           initiative_id = initiative.id,
   208           member_id = app.session.member.id
   209         },
   210         routing = {
   211           default = {
   212             mode = "redirect",
   213             module = request.get_module(),
   214             view = request.get_view(),
   215             id = param.get_id_cgi(),
   216             params = param.get_all_cgi()
   217           }
   218         }
   219       }
   220     end
   221   }
   222   slot.put("<br />")
   223 end
   226 local supporter
   228 if app.session.member_id then
   229   supporter = app.session.member:get_reference_selector("supporters")
   230     :add_where{ "initiative_id = ?", initiative.id }
   231     :optional_object_mode()
   232     :exec()
   233 end
   235 if supporter and not initiative.issue.closed then
   236   local old_draft_id = supporter.draft_id
   237   local new_draft_id = initiative.current_draft.id
   238   if old_draft_id ~= new_draft_id then
   239     ui.container{
   240       attr = { class = "draft_updated_info" },
   241       content = function()
   242         slot.put(_"The draft of this initiative has been updated!")
   243         slot.put(" ")
   244         ui.link{
   245           content = _"Show diff",
   246           module = "draft",
   247           view = "diff",
   248           params = {
   249             old_draft_id = old_draft_id,
   250             new_draft_id = new_draft_id
   251           }
   252         }
   253         if not initiative.revoked then
   254           slot.put(" ")
   255           ui.link{
   256             text   = _"Refresh support to current draft",
   257             module = "initiative",
   258             action = "add_support",
   259             id     = initiative.id,
   260             routing = {
   261               default = {
   262                 mode = "redirect",
   263                 module = "initiative",
   264                 view = "show",
   265                 id = initiative.id
   266               }
   267             }
   268           }
   269         end
   270       end
   271     }
   272   end
   273 end
   276 if app.session.member_id then
   277   ui.container{
   278     attr = {
   279       id = "initiative_" .. tostring(initiative.id) .. "_support"
   280     },
   281     content = function()
   282       execute.view{
   283         module = "initiative",
   284         view = "show_support",
   285         params = {
   286           initiative = initiative
   287         }
   288       }
   289     end
   290   }
   291 end
   294 execute.view{
   295   module = "initiative",
   296   view = "show_tab",
   297   params = {
   298     initiative = initiative,
   299     initiator = initiator
   300   }
   301 }
