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