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