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