liquid_feedback_frontend
view app/main/initiative/_show.lua @ 647:27226084fcab
Fixed wrong links in area list
| author | bsw | 
|---|---|
| date | Mon Jun 25 20:14:26 2012 +0200 (2012-06-25) | 
| parents | 285d1ca156ba | 
| children | 
 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   if initiative.issue.ranks_available and initiative.admitted then
   131     local class = initiative.winner and "admitted_info" or "not_admitted_info"
   132     ui.container{
   133       attr = { class = class },
   134       content = function()
   135         local max_value = initiative.issue.voter_count
   136         slot.put(" ")
   137         local positive_votes = initiative.positive_votes
   138         local negative_votes = initiative.negative_votes
   139         local sum_votes = initiative.positive_votes + initiative.negative_votes
   140         local function perc(votes, sum)
   141           if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
   142           return ""
   143         end
   144         slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
   145         slot.put(" · ")
   146         slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
   147         slot.put(" · ")
   148         slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
   149         slot.put(" · ")
   150         slot.put("<b>")
   151         if initiative.winner then
   152           slot.put(_"Approved")
   153         elseif initiative.rank then
   154           slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
   155         else
   156           slot.put(_"Not approved")
   157         end
   158         slot.put("</b>")
   159       end
   160     }
   161   end
   163   if initiative.admitted == false then
   164     local policy = initiative.issue.policy
   165     ui.container{
   166       attr = { class = "not_admitted_info" },
   167       content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
   168     }
   169   end
   171   if initiative.revoked then
   172     ui.container{
   173       attr = { class = "revoked_info" },
   174       content = function()
   175         slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
   176         local suggested_initiative = initiative.suggested_initiative
   177         if suggested_initiative then
   178           slot.put("<br /><br />")
   179           slot.put(_("The initiators suggest to support the following initiative:"))
   180           slot.put(" ")
   181           ui.link{
   182             content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
   183             module = "initiative",
   184             view = "show",
   185             id = suggested_initiative.id
   186           }
   187         end
   188       end
   189     }
   190   end
   192 end }
   194 util.help("initiative.show")
   197 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
   198   ui.container{
   199     attr = { class = "initiator_invite_info" },
   200     content = function()
   201       slot.put(_"You are invited to become initiator of this initiative.")
   202       slot.put(" ")
   203       ui.link{
   204         image  = { static = "icons/16/tick.png" },
   205         text   = _"Accept invitation",
   206         module = "initiative",
   207         action = "accept_invitation",
   208         id     = initiative.id,
   209         routing = {
   210           default = {
   211             mode = "redirect",
   212             module = request.get_module(),
   213             view = request.get_view(),
   214             id = param.get_id_cgi(),
   215             params = param.get_all_cgi()
   216           }
   217         }
   218       }
   219       slot.put(" ")
   220       ui.link{
   221         image  = { static = "icons/16/cross.png" },
   222         text   = _"Refuse invitation",
   223         module = "initiative",
   224         action = "reject_initiator_invitation",
   225         params = {
   226           initiative_id = initiative.id,
   227           member_id = app.session.member.id
   228         },
   229         routing = {
   230           default = {
   231             mode = "redirect",
   232             module = request.get_module(),
   233             view = request.get_view(),
   234             id = param.get_id_cgi(),
   235             params = param.get_all_cgi()
   236           }
   237         }
   238       }
   239     end
   240   }
   241   slot.put("<br />")
   242 end
   245 local supporter
   247 if app.session.member_id then
   248   supporter = app.session.member:get_reference_selector("supporters")
   249     :add_where{ "initiative_id = ?", initiative.id }
   250     :optional_object_mode()
   251     :exec()
   252 end
   254 if supporter and not initiative.issue.closed then
   255   local old_draft_id = supporter.draft_id
   256   local new_draft_id = initiative.current_draft.id
   257   if old_draft_id ~= new_draft_id then
   258     ui.container{
   259       attr = { class = "draft_updated_info" },
   260       content = function()
   261         slot.put(_"The draft of this initiative has been updated!")
   262         slot.put(" ")
   263         ui.link{
   264           content = _"Show diff",
   265           module = "draft",
   266           view = "diff",
   267           params = {
   268             old_draft_id = old_draft_id,
   269             new_draft_id = new_draft_id
   270           }
   271         }
   272         if not initiative.revoked then
   273           slot.put(" ")
   274           ui.link{
   275             text   = _"Refresh support to current draft",
   276             module = "initiative",
   277             action = "add_support",
   278             id     = initiative.id,
   279             routing = {
   280               default = {
   281                 mode = "redirect",
   282                 module = "initiative",
   283                 view = "show",
   284                 id = initiative.id
   285               }
   286             }
   287           }
   288         end
   289       end
   290     }
   291   end
   292 end
   294 execute.view{
   295   module = "initiative",
   296   view = "show_tab",
   297   params = {
   298     initiative = initiative,
   299     initiator = initiator
   300   }
   301 }
   303 if initiative.issue.snapshot then
   304   slot.put("<br />")
   305   ui.field.timestamp{ label = _"Last snapshot:", value = initiative.issue.snapshot }
   306 end
