liquid_feedback_frontend
view app/main/initiative/_show.lua @ 971:a8c6e80cdf5d
Fixed showing of wrong issue cancelled information
| author | bsw | 
|---|---|
| date | Sat Mar 09 19:13:55 2013 +0100 (2013-03-09) | 
| parents | 319161d5a904 | 
| children | c7215c18168b | 
 line source
     1 local initiative = param.get("initiative", "table")
     3 local show_as_head = param.get("show_as_head", atom.boolean)
     5 initiative:load_everything_for_member_id(app.session.member_id)
     7 local issue = initiative.issue
     9 -- TODO performance
    10 local initiator
    11 if app.session.member_id then
    12   initiator = Initiator:by_pk(initiative.id, app.session.member.id)
    13 end
    15 if app.session.member_id then
    16   issue:load_everything_for_member_id(app.session.member_id)
    17 end
    19 app.html_title.title = initiative.name
    20 app.html_title.subtitle = _("Initiative ##{id}", { id = initiative.id })
    22 slot.select("head", function()
    23   execute.view{
    24     module = "issue", view = "_head",
    25     params = { issue = issue, initiative = initiative }
    26   }
    27 end)
    29 local initiators_members_selector = initiative:get_reference_selector("initiating_members")
    30   :add_field("initiator.accepted", "accepted")
    31   :add_order_by("member.name")
    32 if initiator and initiator.accepted then
    33   initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
    34 else
    35   initiators_members_selector:add_where("initiator.accepted")
    36 end
    38 local initiators = initiators_members_selector:exec()
    41 local initiatives_selector = initiative.issue:get_reference_selector("initiatives")
    42 slot.select("head", function()
    43   execute.view{
    44     module = "issue",
    45     view = "_show",
    46     params = {
    47       issue = initiative.issue,
    48       initiative_limit = 3,
    49       for_initiative = initiative
    50     }
    51   }
    52 end)
    54 util.help("initiative.show")
    56 local class = "initiative_head"
    58 if initiative.polling then
    59   class = class .. " polling"
    60 end
    62 ui.container{ attr = { class = class }, content = function()
    64   local text = _("Initiative i#{id}: #{name}", { id = initiative.id, name = initiative.name }) 
    65   if show_as_head then
    66     ui.link{
    67       attr = { class = "title" }, text = text,
    68       module = "initiative", view = "show", id = initiative.id
    69     }
    70   else
    71     ui.container{ attr = { class = "title" }, content = text }
    72   end
    73   if app.session:has_access("authors_pseudonymous") then
    74     ui.container{ attr = { class = "content" }, content = function()
    75       ui.tag{
    76         attr = { class = "initiator_names" },
    77         content = function()
    78           for i, initiator in ipairs(initiators) do
    79             slot.put(" ")
    80             if app.session:has_access("all_pseudonymous") then
    81               ui.link{
    82                 content = function ()
    83                   execute.view{
    84                     module = "member_image",
    85                     view = "_show",
    86                     params = {
    87                       member = initiator,
    88                       image_type = "avatar",
    89                       show_dummy = true,
    90                       class = "micro_avatar",
    91                       popup_text = text
    92                     }
    93                   }
    94                 end,
    95                 module = "member", view = "show", id = initiator.id
    96               }
    97               slot.put(" ")
    98             end
    99             ui.link{
   100               text = initiator.name,
   101               module = "member", view = "show", id = initiator.id
   102             }
   103             if not initiator.accepted then
   104               ui.tag{ attr = { title = _"Not accepted yet" }, content = "?" }
   105             end
   106           end
   107           if initiator and initiator.accepted and not initiative.issue.fully_frozen and not initiative.issue.closed and not initiative.revoked then
   108             slot.put(" · ")
   109             ui.link{
   110               attr = { class = "action" },
   111               content = function()
   112                 slot.put(_"Invite initiator")
   113               end,
   114               module = "initiative",
   115               view = "add_initiator",
   116               params = { initiative_id = initiative.id }
   117             }
   118             if #initiators > 1 then
   119               slot.put(" · ")
   120               ui.link{
   121                 content = function()
   122                   slot.put(_"Remove initiator")
   123                 end,
   124                 module = "initiative",
   125                 view = "remove_initiator",
   126                 params = { initiative_id = initiative.id }
   127               }
   128             end
   129           end
   130           if initiator and initiator.accepted == false then
   131               slot.put(" · ")
   132               ui.link{
   133                 text   = _"Cancel refuse of invitation",
   134                 module = "initiative",
   135                 action = "remove_initiator",
   136                 params = {
   137                   initiative_id = initiative.id,
   138                   member_id = app.session.member.id
   139                 },
   140                 routing = {
   141                   ok = {
   142                     mode = "redirect",
   143                     module = "initiative",
   144                     view = "show",
   145                     id = initiative.id
   146                   }
   147                 }
   148               }
   149           end
   150           if (initiative.discussion_url and #initiative.discussion_url > 0) then
   151             slot.put(" · ")
   152             if initiative.discussion_url:find("^https?://") then
   153               if initiative.discussion_url and #initiative.discussion_url > 0 then
   154                 ui.link{
   155                   attr = {
   156                     target = "_blank",
   157                     title = _"Discussion with initiators"
   158                   },
   159                   text = _"Discuss with initiators",
   160                   external = initiative.discussion_url
   161                 }
   162               end
   163             else
   164               slot.put(encode.html(initiative.discussion_url))
   165             end
   166           end
   167           if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
   168             slot.put(" · ")
   169             ui.link{
   170               text   = _"change discussion URL",
   171               module = "initiative",
   172               view   = "edit",
   173               id     = initiative.id
   174             }
   175             slot.put(" ")
   176           end
   177         end
   178       }
   179     end }
   180   end
   182   if app.session.member_id then
   183     ui.container{ attr = { class = "content" }, content = function()
   184       execute.view{
   185         module = "supporter",
   186         view = "_show_box",
   187         params = {
   188           initiative = initiative
   189         }
   190       }
   191     end }
   192   end
   195   -- voting results
   196   if initiative.issue.ranks_available and initiative.admitted then
   197     local class = initiative.winner and "admitted_info" or "not_admitted_info"
   198     ui.container{
   199       attr = { class = class },
   200       content = function()
   201         local max_value = initiative.issue.voter_count
   202         slot.put(" ")
   203         local positive_votes = initiative.positive_votes
   204         local negative_votes = initiative.negative_votes
   205         local sum_votes = initiative.positive_votes + initiative.negative_votes
   206         local function perc(votes, sum)
   207           if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end
   208           return ""
   209         end
   210         slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>")
   211         slot.put(" · ")
   212         slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes)  .. "</b>")
   213         slot.put(" · ")
   214         slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>")
   215         slot.put(" · ")
   216         slot.put("<b>")
   217         if initiative.winner then
   218           slot.put(_"Approved")
   219         elseif initiative.rank then
   220           slot.put(_("Not approved (rank #{rank})", { rank = initiative.rank }))
   221         else
   222           slot.put(_"Not approved")
   223         end
   224         slot.put("</b>")
   225       end
   226     }
   227   end
   229   ui.container{ attr = { class = "content" }, content = function()
   230     execute.view{
   231       module = "initiative",
   232       view = "_battles",
   233       params = { initiative = initiative }
   234     }
   235   end }
   237   -- initiative not admitted info
   238   if initiative.admitted == false then
   239     local policy = initiative.issue.policy
   240     ui.container{
   241       attr = { class = "not_admitted_info" },
   242       content = _("This initiative has not been admitted! It failed the quorum of #{quorum}.", { quorum = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den) })
   243     }
   244   end
   246   -- initiative revoked info
   247   if initiative.revoked then
   248     ui.container{
   249       attr = { class = "revoked_info" },
   250       content = function()
   251         slot.put(_("This initiative has been revoked at #{revoked}", { revoked = format.timestamp(initiative.revoked) }))
   252         local suggested_initiative = initiative.suggested_initiative
   253         if suggested_initiative then
   254           slot.put("<br /><br />")
   255           slot.put(_("The initiators suggest to support the following initiative:"))
   256           slot.put(" ")
   257           ui.link{
   258             content = _("Issue ##{id}", { id = suggested_initiative.issue.id } ) .. ": " .. encode.html(suggested_initiative.name),
   259             module = "initiative",
   260             view = "show",
   261             id = suggested_initiative.id
   262           }
   263         end
   264       end
   265     }
   266   end
   269   -- invited as initiator
   270   if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
   271     ui.container{
   272       attr = { class = "initiator_invite_info" },
   273       content = function()
   274         slot.put(_"You are invited to become initiator of this initiative.")
   275         slot.put(" ")
   276         ui.link{
   277           image  = { static = "icons/16/tick.png" },
   278           text   = _"Accept invitation",
   279           module = "initiative",
   280           action = "accept_invitation",
   281           id     = initiative.id,
   282           routing = {
   283             default = {
   284               mode = "redirect",
   285               module = request.get_module(),
   286               view = request.get_view(),
   287               id = param.get_id_cgi(),
   288               params = param.get_all_cgi()
   289             }
   290           }
   291         }
   292         slot.put(" ")
   293         ui.link{
   294           image  = { static = "icons/16/cross.png" },
   295           text   = _"Refuse invitation",
   296           module = "initiative",
   297           action = "reject_initiator_invitation",
   298           params = {
   299             initiative_id = initiative.id,
   300             member_id = app.session.member.id
   301           },
   302           routing = {
   303             default = {
   304               mode = "redirect",
   305               module = request.get_module(),
   306               view = request.get_view(),
   307               id = param.get_id_cgi(),
   308               params = param.get_all_cgi()
   309             }
   310           }
   311         }
   312       end
   313     }
   314   end
   316   -- draft updated
   317   local supporter
   319   if app.session.member_id then
   320     supporter = app.session.member:get_reference_selector("supporters")
   321       :add_where{ "initiative_id = ?", initiative.id }
   322       :optional_object_mode()
   323       :exec()
   324   end
   326   if supporter and not initiative.issue.closed then
   327     local old_draft_id = supporter.draft_id
   328     local new_draft_id = initiative.current_draft.id
   329     if old_draft_id ~= new_draft_id then
   330       ui.container{
   331         attr = { class = "draft_updated_info" },
   332         content = function()
   333           slot.put(_"The draft of this initiative has been updated!")
   334           slot.put(" ")
   335           ui.link{
   336             content = _"Show diff",
   337             module = "draft",
   338             view = "diff",
   339             params = {
   340               old_draft_id = old_draft_id,
   341               new_draft_id = new_draft_id
   342             }
   343           }
   344           if not initiative.revoked then
   345             slot.put(" ")
   346             ui.link{
   347               text   = _"Refresh support to current draft",
   348               module = "initiative",
   349               action = "add_support",
   350               id     = initiative.id,
   351               routing = {
   352                 default = {
   353                   mode = "redirect",
   354                   module = "initiative",
   355                   view = "show",
   356                   id = initiative.id
   357                 }
   358               }
   359             }
   360           end
   361         end
   362       }
   363     end
   364   end
   366   if not show_as_head then
   367     local drafts_count = initiative:get_reference_selector("drafts"):count()
   369     ui.container{ attr = { class = "content" }, content = function()
   371       if initiator and initiator.accepted and not initiative.issue.half_frozen and not initiative.issue.closed and not initiative.revoked then
   372         ui.link{
   373           content = function()
   374             slot.put(_"Edit draft")
   375           end,
   376           module = "draft",
   377           view = "new",
   378           params = { initiative_id = initiative.id }
   379         }
   380         slot.put(" · ")
   381         ui.link{
   382           content = function()
   383             slot.put(_"Revoke initiative")
   384           end,
   385           module = "initiative",
   386           view = "revoke",
   387           id = initiative.id
   388         }
   389         slot.put(" · ")
   390       end
   392       ui.tag{
   393         attr = { class = "draft_version" },
   394         content = _("Latest draft created at #{date} #{time}", {
   395           date = format.date(initiative.current_draft.created),
   396           time = format.time(initiative.current_draft.created)
   397         })
   398       }
   399       if drafts_count > 1 then
   400         slot.put(" · ")
   401         ui.link{
   402           module = "draft", view = "list", params = { initiative_id = initiative.id },
   403           text = _("List all revisions (#{count})", { count = drafts_count })
   404         }
   405       end
   406     end }
   408     execute.view{
   409       module = "draft",
   410       view = "_show",
   411       params = {
   412         draft = initiative.current_draft
   413       }
   414     }
   415   end
   416 end }
   418 if not show_as_head then
   419   execute.view{
   420     module = "suggestion",
   421     view = "_list",
   422     params = {
   423       initiative = initiative,
   424       suggestions_selector = initiative:get_reference_selector("suggestions"),
   425       tab_id = param.get("tab_id")
   426     }
   427   }
   430   if app.session:has_access("all_pseudonymous") then
   431     if initiative.issue.ranks_available then
   432       local members_selector = initiative.issue:get_reference_selector("direct_voters")
   433             :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id })
   434             :add_field("direct_voter.weight as voter_weight")
   435             :add_field("coalesce(vote.grade, 0) as grade")
   436             :add_field("direct_voter.comment as voter_comment")
   437             :left_join("initiative", nil, "initiative.id = vote.initiative_id")
   438             :left_join("issue", nil, "issue.id = initiative.issue_id")
   440       ui.anchor{ name = "voter", attr = { class = "heading" }, content = _"Voters" }
   442       execute.view{
   443         module = "member",
   444         view = "_list",
   445         params = {
   446           initiative = initiative,
   447           for_votes = true,
   448           members_selector = members_selector,
   449           paginator_name = "voter"
   450         }
   451       }
   452     end
   454     local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
   455               :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
   456               :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")
   457               :add_field("direct_interest_snapshot.weight")
   458               :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   459               :add_where("direct_supporter_snapshot.satisfied")
   460               :add_field("direct_supporter_snapshot.informed", "is_informed")
   462     if members_selector:count() > 0 then
   463       if issue.fully_frozen then
   464         ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters (before begin of voting)" }
   465       else
   466         ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"Supporters" }
   467       end      
   469       execute.view{
   470         module = "member",
   471         view = "_list",
   472         params = {
   473           initiative = initiative,
   474           members_selector = members_selector,
   475           paginator_name = "supporters"
   476         }
   477     }
   478     else
   479       if issue.fully_frozen then
   480         ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters (before begin of voting)" }
   481       else
   482         ui.anchor{ name = "supporters", attr = { class = "heading" }, content = _"No supporters" }
   483       end
   484       slot.put("<br />")
   485     end
   487     local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
   488               :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
   489               :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")
   490               :add_field("direct_interest_snapshot.weight")
   491               :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   492               :add_where("NOT direct_supporter_snapshot.satisfied")
   493               :add_field("direct_supporter_snapshot.informed", "is_informed")
   495     if members_selector:count() > 0 then
   496       if issue.fully_frozen then
   497         ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters (before begin of voting)" }
   498       else
   499         ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"Potential supporters" }
   500       end
   502       execute.view{
   503         module = "member",
   504         view = "_list",
   505         params = {
   506           initiative = initiative,
   507           members_selector = members_selector,
   508           paginator_name = "potential_supporters"
   509         }
   510       }
   511     else
   512       if issue.fully_frozen then
   513         ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters (before begin of voting)" }
   514       else
   515         ui.anchor{ name = "potential_supporters", attr = { class = "heading" }, content = _"No potential supporters" }
   516       end
   517       slot.put("<br />")
   518     end
   520     ui.container{ attr = { class = "heading" }, content = _"Details" }
   521     execute.view {
   522       module = "initiative",
   523       view = "_details",
   524       params = {
   525         initiative = initiative,
   526         members_selector = members_selector
   527       }
   528     }
   530   end
   531 end
