liquid_feedback_frontend
view app/main/initiative/show.lua @ 720:cdd0bcbbef8b
Improved paginators on initiative view, optical improvements
| author | bsw | 
|---|---|
| date | Wed Jun 27 19:28:39 2012 +0200 (2012-06-27) | 
| parents | cc64a4fc6ab6 | 
| children | 344e5fdce8c9 | 
 line source
     1 local initiative = Initiative:by_id(param.get_id())
     2 initiative:load_everything_for_member_id(app.session.member_id)
     4 local issue = initiative.issue
     6 if app.session.member_id then
     7   issue:load_everything_for_member_id(app.session.member_id)
     8 end
    10 app.html_title.title = initiative.name
    11 app.html_title.subtitle = _("Initiative ##{id}", { id = initiative.id })
    13 slot.select("head", function()
    14   execute.view{
    15     module = "issue", view = "_head",
    16     params = { issue = issue, initiative = initiative }
    17   }
    18 end)
    20 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
    21   :add_field("initiator.accepted", "accepted")
    22   :add_order_by("member.name")
    23 if initiator and initiator.accepted then
    24   initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
    25 else
    26   initiators_members_selector:add_where("initiator.accepted")
    27 end
    29 local initiators = initiators_members_selector:exec()
    32 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
    33 slot.select("head", function()
    34   execute.view{
    35     module = "issue",
    36     view = "_show",
    37     params = {
    38       issue = initiative.issue,
    39       initiative_limit = 3,
    40       for_initiative = initiative
    41     }
    42   }
    43 end)
    45 util.help("initiative.show")
    47 ui.container{ attr = { class = "initiative_head" }, content = function()
    49   ui.container{
    50     attr = { class = "title" },
    51     content = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name })
    52   }
    54   ui.container{ attr = { class = "content" }, content = function()
    55     if app.session.member_id or config.public_access == "pseudonym" or config.public_access == "full" then
    56       ui.tag{
    57         attr = { class = "initiator_names" },
    58         content = function()
    59           for i, initiator in ipairs(initiators) do
    60             slot.put(" ")
    61             if app.session.member_id or config.public_access == "full" then
    62               ui.link{
    63                 content = function ()
    64                   execute.view{
    65                     module = "member_image",
    66                     view = "_show",
    67                     params = {
    68                       member = initiator,
    69                       image_type = "avatar",
    70                       show_dummy = true,
    71                       class = "micro_avatar",
    72                       popup_text = text
    73                     }
    74                   }
    75                 end,
    76                 module = "member", view = "show", id = initiator.id
    77               }
    78               slot.put(" ")
    79             end
    80             ui.link{
    81               text = initiator.name,
    82               module = "member", view = "show", id = initiator.id
    83             }
    84             if not initiator.accepted then
    85               ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
    86             end
    87           end
    88         end
    89       }
    90     end
    92     if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
    93       slot.put(" · ")
    94       ui.link{
    95         attr = { class = "action" },
    96         content = function()
    97           slot.put(_"Invite initiator")
    98         end,
    99         module = "initiative",
   100         view = "add_initiator",
   101         params = { initiative_id = initiative.id }
   102       }
   103       if #initiators > 1 then
   104         slot.put(" · ")
   105         ui.link{
   106           content = function()
   107             slot.put(_"Remove initiator")
   108           end,
   109           module = "initiative",
   110           view = "remove_initiator",
   111           params = { initiative_id = initiative.id }
   112         }
   113       end
   114     end
   115     if initiator and initiator.accepted == false then
   116         slot.put(" · ")
   117         ui.link{
   118           text   = _"Cancel refuse of invitation",
   119           module = "initiative",
   120           action = "remove_initiator",
   121           params = {
   122             initiative_id = initiative.id,
   123             member_id = app.session.member.id
   124           },
   125           routing = {
   126             ok = {
   127               mode = "redirect",
   128               module = "initiative",
   129               view = "show",
   130               id = initiative.id
   131             }
   132           }
   133         }
   134     end
   135   end }
   136   ui.container{ attr = { class = "content" }, content = function()
   137     if app.session.member_id then
   138       execute.view{
   139         module = "supporter",
   140         view = "_show_box",
   141         params = {
   142           initiative = initiative
   143         }
   144       }
   145     end
   147   end }
   150   -- voting results
   151   if initiative.issue.ranks_available and initiative.admitted then
   152     local class = initiative.winner and "admitted_info" or "not_admitted_info"
   153     ui.container{
   154       attr = { class = class },
   155       content = function()
   156         local max_value = initiative.issue.voter_count
   157         slot.put(" ")
   158         local positive_votes = initiative.positive_votes
   159         local negative_votes = initiative.negative_votes
   160         local sum_votes = initiative.positive_votes + initiative.negative_votes
   161         local function perc(votes, sum)
   162           if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
   163           return ""
   164         end
   165         slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
   166         slot.put(" · ")
   167         slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
   168         slot.put(" · ")
   169         slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
   170         slot.put(" · ")
   171         slot.put("<b>")
   172         if initiative.winner then
   173           slot.put(_"Approved")
   174         elseif initiative.rank then
   175           slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
   176         else
   177           slot.put(_"Not approved")
   178         end
   179         slot.put("</b>")
   180       end
   181     }
   182   end
   184   ui.container{ attr = { class = "content" }, content = function()
   185     execute.view{
   186       module = "initiative",
   187       view = "_battles",
   188       params = { initiative = initiative }
   189     }
   190   end }
   192   -- initiative not admitted info
   193   if initiative.admitted == false then
   194     local policy = initiative.issue.policy
   195     ui.container{
   196       attr = { class = "not_admitted_info" },
   197       content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
   198     }
   199   end
   201   -- initiative revoked info
   202   if initiative.revoked then
   203     ui.container{
   204       attr = { class = "revoked_info" },
   205       content = function()
   206         slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
   207         local suggested_initiative = initiative.suggested_initiative
   208         if suggested_initiative then
   209           slot.put("<br /><br />")
   210           slot.put(_("The initiators suggest to support the following initiative:"))
   211           slot.put(" ")
   212           ui.link{
   213             content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
   214             module = "initiative",
   215             view = "show",
   216             id = suggested_initiative.id
   217           }
   218         end
   219       end
   220     }
   221   end
   224   -- invited as initiator
   225   if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
   226     ui.container{
   227       attr = { class = "initiator_invite_info" },
   228       content = function()
   229         slot.put(_"You are invited to become initiator of this initiative.")
   230         slot.put(" ")
   231         ui.link{
   232           image  = { static = "icons/16/tick.png" },
   233           text   = _"Accept invitation",
   234           module = "initiative",
   235           action = "accept_invitation",
   236           id     = initiative.id,
   237           routing = {
   238             default = {
   239               mode = "redirect",
   240               module = request.get_module(),
   241               view = request.get_view(),
   242               id = param.get_id_cgi(),
   243               params = param.get_all_cgi()
   244             }
   245           }
   246         }
   247         slot.put(" ")
   248         ui.link{
   249           image  = { static = "icons/16/cross.png" },
   250           text   = _"Refuse invitation",
   251           module = "initiative",
   252           action = "reject_initiator_invitation",
   253           params = {
   254             initiative_id = initiative.id,
   255             member_id = app.session.member.id
   256           },
   257           routing = {
   258             default = {
   259               mode = "redirect",
   260               module = request.get_module(),
   261               view = request.get_view(),
   262               id = param.get_id_cgi(),
   263               params = param.get_all_cgi()
   264             }
   265           }
   266         }
   267       end
   268     }
   269   end
   271   -- draft updated
   272   local supporter
   274   if app.session.member_id then
   275     supporter = app.session.member:get_reference_selector("supporters")
   276       :add_where{ "initiative_id = ?", initiative.id }
   277       :optional_object_mode()
   278       :exec()
   279   end
   281   if supporter and not initiative.issue.closed then
   282     local old_draft_id = supporter.draft_id
   283     local new_draft_id = initiative.current_draft.id
   284     if old_draft_id ~= new_draft_id then
   285       ui.container{
   286         attr = { class = "draft_updated_info" },
   287         content = function()
   288           slot.put(_"The draft of this initiative has been updated!")
   289           slot.put(" ")
   290           ui.link{
   291             content = _"Show diff",
   292             module = "draft",
   293             view = "diff",
   294             params = {
   295               old_draft_id = old_draft_id,
   296               new_draft_id = new_draft_id
   297             }
   298           }
   299           if not initiative.revoked then
   300             slot.put(" ")
   301             ui.link{
   302               text   = _"Refresh support to current draft",
   303               module = "initiative",
   304               action = "add_support",
   305               id     = initiative.id,
   306               routing = {
   307                 default = {
   308                   mode = "redirect",
   309                   module = "initiative",
   310                   view = "show",
   311                   id = initiative.id
   312                 }
   313               }
   314             }
   315           end
   316         end
   317       }
   318     end
   319   end
   322   execute.view{
   323     module = "draft",
   324     view = "_show",
   325     params = {
   326       draft = initiative.current_draft
   327     }
   328   }
   330 end }
   332 execute.view{
   333   module = "suggestion",
   334   view = "_list",
   335   params = {
   336     initiative = initiative,
   337     suggestions_selector = initiative:get_reference_selector("suggestions"),
   338     tab_id = param.get("tab_id")
   339   }
   340 }
   343 if config.public_access == "full" or app.session.member_id then
   344   if initiative.issue.ranks_available then
   345     local members_selector = initiative.issue:get_reference_selector("direct_voters")
   346           :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id })
   347           :add_field("direct_voter.weight as voter_weight")
   348           :add_field("coalesce(vote.grade, 0) as grade")
   349           :left_join("initiative", nil, "initiative.id = vote.initiative_id")
   350           :left_join("issue", nil, "issue.id = initiative.issue_id")
   352     ui.anchor{ name = "voter", attr = { class = "heading" }, content = _"Member voter" }
   354     execute.view{
   355       module = "member",
   356       view = "_list",
   357       params = {
   358         initiative = initiative,
   359         for_votes = true,
   360         members_selector = members_selector,
   361         paginator_name = "voter"
   362       }
   363     }
   364   end
   366   local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
   367             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
   368             :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
   369             :add_field("direct_interest_snapshot.weight")
   370             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   371             :add_where("direct_supporter_snapshot.satisfied")
   372             :add_field("direct_supporter_snapshot.informed", "is_informed")
   374   if members_selector:count() > 0 then
   375     if issue.fully_frozen then
   376       ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters (before begin of voting)" }
   377     else
   378       ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters" }
   379     end      
   381     execute.view{
   382       module = "member",
   383       view = "_list",
   384       params = {
   385         initiative = initiative,
   386         members_selector = members_selector,
   387         paginator_name = "supporters"
   388       }
   389   }
   390   else
   391     if issue.fully_frozen then
   392       ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters (before begin of voting)" }
   393     else
   394       ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters" }
   395     end
   396     slot.put("<br />")
   397   end
   399   local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
   400             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
   401             :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
   402             :add_field("direct_interest_snapshot.weight")
   403             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   404             :add_where("NOT direct_supporter_snapshot.satisfied")
   405             :add_field("direct_supporter_snapshot.informed", "is_informed")
   407   if members_selector:count() > 0 then
   408     if issue.fully_frozen then
   409       ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters (before begin of voting)" }
   410     else
   411       ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters" }
   412     end
   414     execute.view{
   415       module = "member",
   416       view = "_list",
   417       params = {
   418         initiative = initiative,
   419         members_selector = members_selector,
   420         paginator_name = "potential_supporters"
   421       }
   422     }
   423   else
   424     if issue.fully_frozen then
   425       ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters (before begin of voting)" }
   426     else
   427       ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters" }
   428     end
   429     slot.put("<br />")
   430   end
   432   ui.container{ attr = { class = "heading" }, content = _"Details" }
   433   execute.view {
   434     module = "initiative",
   435     view = "_details",
   436     params = {
   437       initiative = initiative,
   438       members_selector = members_selector
   439     }
   440   }
   442 end
