liquid_feedback_frontend
view app/main/initiative/_show.lua @ 589:c5878a5d7dc7
Make unlock of members work in admin section
| author | bsw | 
|---|---|
| date | Thu Jun 21 17:15:37 2012 +0200 (2012-06-21) | 
| parents | e7baf2713987 | 
| children | 285d1ca156ba | 
 line source
     1 local initiative = param.get("initiative", "table")
     3 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
     4   :add_field("initiator.accepted", "accepted")
     5   :add_order_by("member.name")
     6 if initiator and initiator.accepted then
     7   initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
     8 else
     9   initiators_members_selector:add_where("initiator.accepted")
    10 end
    12 local initiators = initiators_members_selector:exec()
    15 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
    16 slot.select("head", function()
    17   execute.view{
    18     module = "issue",
    19     view = "_show",
    20     params = {
    21       issue = initiative.issue,
    22       initiative_limit = 3,
    23       for_initiative = initiative
    24     }
    25   }
    26 end)
    28 ui.container{ attr = { class = "initiative_head" }, content = function()
    30   ui.container{
    31     attr = { class = "title" },
    32     content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
    33   }
    35   ui.container{ attr = { class = "content" }, content = function()
    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 or config.public_access == "full" 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   end }
   117   ui.container{ attr = { class = "content" }, content = function()
   118     if app.session.member_id then
   119       execute.view{
   120         module = "supporter",
   121         view = "_show_box",
   122         params = {
   123           initiative = initiative
   124         }
   125       }
   126     end
   128   end }
   130 end }
   133 util.help("initiative.show")
   135 --slot.select("initiative_head", function()
   137   if initiative.issue.ranks_available and initiative.admitted then
   138     local class = initiative.winner and "admitted_info" or "not_admitted_info"
   139     ui.container{
   140       attr = { class = class },
   141       content = function()
   142         local max_value = initiative.issue.voter_count
   143         slot.put(" ")
   144         local positive_votes = initiative.positive_votes
   145         local negative_votes = initiative.negative_votes
   146         local sum_votes = initiative.positive_votes + initiative.negative_votes
   147         local function perc(votes, sum)
   148           if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
   149           return ""
   150         end
   151         slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
   152         slot.put(" · ")
   153         slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
   154         slot.put(" · ")
   155         slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
   156         slot.put(" · ")
   157         slot.put("<b>")
   158         if initiative.winner then
   159           slot.put(_"Approved")
   160         elseif initiative.rank then
   161           slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
   162         else
   163           slot.put(_"Not approved")
   164         end
   165         slot.put("</b>")
   166       end
   167     }
   168   end
   170   if initiative.admitted == false then
   171     local policy = initiative.issue.policy
   172     ui.container{
   173       attr = { class = "not_admitted_info" },
   174       content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
   175     }
   176   end
   178   if initiative.revoked then
   179     ui.container{
   180       attr = { class = "revoked_info" },
   181       content = function()
   182         slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
   183         local suggested_initiative = initiative.suggested_initiative
   184         if suggested_initiative then
   185           slot.put("<br /><br />")
   186           slot.put(_("The initiators suggest to support the following initiative:"))
   187           slot.put(" ")
   188           ui.link{
   189             content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
   190             module = "initiative",
   191             view = "show",
   192             id = suggested_initiative.id
   193           }
   194         end
   195       end
   196     }
   197   end
   199 --end)
   201 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
   202   ui.container{
   203     attr = { class = "initiator_invite_info" },
   204     content = function()
   205       slot.put(_"You are invited to become initiator of this initiative.")
   206       slot.put(" ")
   207       ui.link{
   208         image  = { static = "icons/16/tick.png" },
   209         text   = _"Accept invitation",
   210         module = "initiative",
   211         action = "accept_invitation",
   212         id     = initiative.id,
   213         routing = {
   214           default = {
   215             mode = "redirect",
   216             module = request.get_module(),
   217             view = request.get_view(),
   218             id = param.get_id_cgi(),
   219             params = param.get_all_cgi()
   220           }
   221         }
   222       }
   223       slot.put(" ")
   224       ui.link{
   225         image  = { static = "icons/16/cross.png" },
   226         text   = _"Refuse invitation",
   227         module = "initiative",
   228         action = "reject_initiator_invitation",
   229         params = {
   230           initiative_id = initiative.id,
   231           member_id = app.session.member.id
   232         },
   233         routing = {
   234           default = {
   235             mode = "redirect",
   236             module = request.get_module(),
   237             view = request.get_view(),
   238             id = param.get_id_cgi(),
   239             params = param.get_all_cgi()
   240           }
   241         }
   242       }
   243     end
   244   }
   245   slot.put("<br />")
   246 end
   249 local supporter
   251 if app.session.member_id then
   252   supporter = app.session.member:get_reference_selector("supporters")
   253     :add_where{ "initiative_id = ?", initiative.id }
   254     :optional_object_mode()
   255     :exec()
   256 end
   258 if supporter and not initiative.issue.closed then
   259   local old_draft_id = supporter.draft_id
   260   local new_draft_id = initiative.current_draft.id
   261   if old_draft_id ~= new_draft_id then
   262     ui.container{
   263       attr = { class = "draft_updated_info" },
   264       content = function()
   265         slot.put(_"The draft of this initiative has been updated!")
   266         slot.put(" ")
   267         ui.link{
   268           content = _"Show diff",
   269           module = "draft",
   270           view = "diff",
   271           params = {
   272             old_draft_id = old_draft_id,
   273             new_draft_id = new_draft_id
   274           }
   275         }
   276         if not initiative.revoked then
   277           slot.put(" ")
   278           ui.link{
   279             text   = _"Refresh support to current draft",
   280             module = "initiative",
   281             action = "add_support",
   282             id     = initiative.id,
   283             routing = {
   284               default = {
   285                 mode = "redirect",
   286                 module = "initiative",
   287                 view = "show",
   288                 id = initiative.id
   289               }
   290             }
   291           }
   292         end
   293       end
   294     }
   295   end
   296 end
   298 execute.view{
   299   module = "initiative",
   300   view = "show_tab",
   301   params = {
   302     initiative = initiative,
   303     initiator = initiator
   304   }
   305 }
   307 if initiative.issue.snapshot then
   308   slot.put("<br />")
   309   ui.field.timestamp{ label = _"Last snapshot:", value = initiative.issue.snapshot }
   310 end
