liquid_feedback_frontend
view app/main/initiative/_show.lua @ 272:65a1f7a01e7b
More optical enhancements and repositioning of elements
| author | bsw | 
|---|---|
| date | Wed Feb 08 00:55:17 2012 +0100 (2012-02-08) | 
| parents | 1fdf1e607494 | 
| children | 7196685f9dd7 | 
 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")
     7 if not (initiator and initiator.accepted) then
     8   initiators_members_selector:add_where("initiator.accepted")
     9 end
    11 local initiators = initiators_members_selector:exec()
    13 slot.select("initiative_head", function()
    15   ui.container{
    16     attr = { class = "initiative_name" },
    17     content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
    18   }
    19   ui.tag{
    20     attr = { class = "initiator_names" },
    21     content = function()
    22       ui.tag{ content = _"by" }
    23       slot.put(" ")
    24       for i, initiator in ipairs(initiators) do
    25         if i == #initiators and i > 1 then
    26           slot.put(" ", _"and", " ")
    27         elseif i > 1 then
    28           slot.put(", ")
    29         end
    30         ui.link{
    31           text = initiator.name,
    32           module = "member", view = "show", id = initiator.id
    33         }
    34       end
    35     end
    36   }
    38   if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
    39     slot.put(" · ")
    40     ui.link{
    41       attr = { class = "action" },
    42       content = function()
    43         slot.put(_"Invite initiator")
    44       end,
    45       module = "initiative",
    46       view = "add_initiator",
    47       params = { initiative_id = initiative.id }
    48     }
    49     if #initiators > 1 then
    50       slot.put(" · ")
    51       ui.link{
    52         content = function()
    53           slot.put(_"Remove initiator")
    54         end,
    55         module = "initiative",
    56         view = "remove_initiator",
    57         params = { initiative_id = initiative.id }
    58       }
    59     end
    60   end
    61   if initiator and initiator.accepted == false then
    62       slot.put(" · ")
    63       ui.link{
    64         text   = _"Cancel refuse of invitation",
    65         module = "initiative",
    66         action = "remove_initiator",
    67         params = {
    68           initiative_id = initiative.id,
    69           member_id = app.session.member.id
    70         },
    71         routing = {
    72           ok = {
    73             mode = "redirect",
    74             module = "initiative",
    75             view = "show",
    76             id = initiative.id
    77           }
    78         }
    79       }
    80   end
    83 end )
    85 util.help("initiative.show")
    88 if initiative.issue.ranks_available and initiative.admitted then
    89   local class = initiative.rank == 1 and "admitted_info" or "not_admitted_info"
    90   ui.container{
    91     attr = { class = class },
    92     content = function()
    93       local max_value = initiative.issue.voter_count
    94       slot.put(" ")
    95       local positive_votes = initiative.positive_votes
    96       local negative_votes = initiative.negative_votes
    97       local sum_votes = initiative.positive_votes + initiative.negative_votes
    98       local function perc(votes, sum)
    99         if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
   100         return ""
   101       end
   102       slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
   103       slot.put(" · ")
   104       slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
   105       slot.put(" · ")
   106       slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
   107       slot.put(" · ")
   108       slot.put("<b>")
   109       if initiative.rank == 1 then
   110         slot.put(_"Approved")
   111       elseif initiative.rank then
   112         slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
   113       else
   114         slot.put(_"Not approved")
   115       end
   116       slot.put("</b>")
   117     end
   118   }
   119 end
   121 if initiative.admitted == false then
   122   local policy = initiative.issue.policy
   123   ui.container{
   124     attr = { class = "not_admitted_info" },
   125     content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
   126   }
   127 end
   129 local web20 = config.user_tab_mode == "accordeon"
   130   or config.user_tab_mode == "accordeon_first_expanded"
   131   or config.user_tab_mode == "accordeon_all_expanded"
   133 if not web20 and initiative.issue.state == "cancelled" then
   134   local policy = initiative.issue.policy
   135   ui.container{
   136     attr = { class = "not_admitted_info" },
   137     content = _("This issue has been cancelled. It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den) })
   138   }
   139 end
   141 if initiative.revoked then
   142   ui.container{
   143     attr = { class = "revoked_info" },
   144     content = function()
   145       slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
   146       local suggested_initiative = initiative.suggested_initiative
   147       if suggested_initiative then
   148         slot.put("<br /><br />")
   149         slot.put(_("The initiators suggest to support the following initiative:"))
   150         slot.put(" ")
   151         ui.link{
   152           content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
   153           module = "initiative",
   154           view = "show",
   155           id = suggested_initiative.id
   156         }
   157       end
   158     end
   159   }
   160 end
   162 if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
   163   ui.container{
   164     attr = { class = "initiator_invite_info" },
   165     content = function()
   166       slot.put(_"You are invited to become initiator of this initiative.")
   167       slot.put(" ")
   168       ui.link{
   169         image  = { static = "icons/16/tick.png" },
   170         text   = _"Accept invitation",
   171         module = "initiative",
   172         action = "accept_invitation",
   173         id     = initiative.id,
   174         routing = {
   175           default = {
   176             mode = "redirect",
   177             module = request.get_module(),
   178             view = request.get_view(),
   179             id = param.get_id_cgi(),
   180             params = param.get_all_cgi()
   181           }
   182         }
   183       }
   184       slot.put(" ")
   185       ui.link{
   186         image  = { static = "icons/16/cross.png" },
   187         text   = _"Refuse invitation",
   188         module = "initiative",
   189         action = "reject_initiator_invitation",
   190         params = {
   191           initiative_id = initiative.id,
   192           member_id = app.session.member.id
   193         },
   194         routing = {
   195           default = {
   196             mode = "redirect",
   197             module = request.get_module(),
   198             view = request.get_view(),
   199             id = param.get_id_cgi(),
   200             params = param.get_all_cgi()
   201           }
   202         }
   203       }
   204     end
   205   }
   206   slot.put("<br />")
   207 end
   210 local supporter
   212 if app.session.member_id then
   213   supporter = app.session.member:get_reference_selector("supporters")
   214     :add_where{ "initiative_id = ?", initiative.id }
   215     :optional_object_mode()
   216     :exec()
   217 end
   219 if supporter and not initiative.issue.closed then
   220   local old_draft_id = supporter.draft_id
   221   local new_draft_id = initiative.current_draft.id
   222   if old_draft_id ~= new_draft_id then
   223     ui.container{
   224       attr = { class = "draft_updated_info" },
   225       content = function()
   226         slot.put(_"The draft of this initiative has been updated!")
   227         slot.put(" ")
   228         ui.link{
   229           content = _"Show diff",
   230           module = "draft",
   231           view = "diff",
   232           params = {
   233             old_draft_id = old_draft_id,
   234             new_draft_id = new_draft_id
   235           }
   236         }
   237         if not initiative.revoked then
   238           slot.put(" ")
   239           ui.link{
   240             text   = _"Refresh support to current draft",
   241             module = "initiative",
   242             action = "add_support",
   243             id     = initiative.id,
   244             routing = {
   245               default = {
   246                 mode = "redirect",
   247                 module = "initiative",
   248                 view = "show",
   249                 id = initiative.id
   250               }
   251             }
   252           }
   253         end
   254       end
   255     }
   256   end
   257 end
   260 if app.session.member_id then
   261   ui.container{
   262     attr = {
   263       id = "initiative_" .. tostring(initiative.id) .. "_support"
   264     },
   265     content = function()
   266       execute.view{
   267         module = "initiative",
   268         view = "show_support",
   269         params = {
   270           initiative = initiative
   271         }
   272       }
   273     end
   274   }
   275 end
   277 if (initiative.discussion_url and #initiative.discussion_url > 0)
   278   or (initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked) then
   279   ui.container{
   280     attr = { class = "vertical" },
   281     content = function()
   282       ui.container{
   283         attr = { class = "ui_field_label" },
   284         content = _"Discussion with initiators"
   285       }
   286       ui.tag{
   287         tag = "span",
   288         content = function()
   289           if initiative.discussion_url:find("^https?://") then
   290             if initiative.discussion_url and #initiative.discussion_url > 0 then
   291               ui.link{
   292                 attr = {
   293                   class = "actions",
   294                   target = "_blank",
   295                   title = initiative.discussion_url
   296                 },
   297                 content = function()
   298                   slot.put(encode.html(initiative.discussion_url))
   299                 end,
   300                 external = initiative.discussion_url
   301               }
   302             end
   303           else
   304             slot.put(encode.html(initiative.discussion_url))
   305           end
   306           slot.put(" ")
   307           if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
   308             ui.link{
   309               attr   = { class = "actions" },
   310               text   = _"(change URL)",
   311               module = "initiative",
   312               view   = "edit",
   313               id     = initiative.id
   314             }
   315           end
   316         end
   317       }
   318     end
   319   }
   320 end
   324 execute.view{
   325   module = "initiative",
   326   view = "show_tab",
   327   params = {
   328     initiative = initiative,
   329     initiator = initiator
   330   }
   331 }
