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