liquid_feedback_frontend
view app/main/initiative/show.lua @ 3:768faea1096d
Version alpha4
Members interested in an issue or supporting an initiative have a weight information attached. Browsing the members causing that weight is possible.
Initiatives may provide a link to an external discussion platform
Direct link on every initiative page to create an alternative initiative
Bugfix: No error when clicking "neutral", when "neutral" is currently selected
Members interested in an issue or supporting an initiative have a weight information attached. Browsing the members causing that weight is possible.
Initiatives may provide a link to an external discussion platform
Direct link on every initiative page to create an alternative initiative
Bugfix: No error when clicking "neutral", when "neutral" is currently selected
| author | bsw | 
|---|---|
| date | Mon Nov 30 12:00:00 2009 +0100 (2009-11-30) | 
| parents | 5c601807d397 | 
| children | 80c215dbf076 | 
 line source
     1 local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
     3 --slot.put_into("html_head", '<link rel="alternate" type="application/rss+xml" title="RSS" href="../show/' .. tostring(initiative.id) .. '.rss" />')
     5 execute.view{
     6   module = "supporter",
     7   view = "_show_box",
     8   params = { initiative = initiative }
     9 }
    11 execute.view{
    12   module = "delegation",
    13   view = "_show_box",
    14   params = { issue_id = initiative.issue_id }
    15 }
    17 execute.view{
    18   module = "issue",
    19   view = "_show_box",
    20   params = { issue = initiative.issue }
    21 }
    23 slot.select("path", function()
    24   ui.link{
    25     content = _"Area '#{name}'":gsub("#{name}", initiative.issue.area.name),
    26     module = "area",
    27     view = "show",
    28     id = initiative.issue.area.id
    29   }
    30   ui.container{ content = "::" }
    31   ui.link{
    32     content = _"Issue ##{id}":gsub("#{id}", initiative.issue.id),
    33     module = "issue",
    34     view = "show",
    35     id = initiative.issue.id
    36   }
    37 end)
    39 slot.put_into("title", encode.html(_"Initiative: '#{name}'":gsub("#{name}", initiative.shortened_name) ))
    41 slot.select("actions", function()
    43   local initiator = Initiator:by_pk(initiative.id, app.session.member.id)
    45   if initiator then
    46     ui.link{
    47       content = function()
    48         ui.image{ static = "icons/16/script_add.png" }
    49         slot.put(_"Edit draft")
    50       end,
    51       module = "draft",
    52       view = "new",
    53       params = { initiative_id = initiative.id }
    54     }
    55   end
    57   if not initiative.issue.fully_frozen and not initiative.issue.closed then
    58     ui.link{
    59       attr = { class = "action" },
    60       content = function()
    61         ui.image{ static = "icons/16/script_add.png" }
    62         slot.put(_"Create alternative initiative" )
    63       end,
    64       module = "initiative",
    65       view = "new",
    66       params = { issue_id = initiative.issue.id }
    67     }
    68   end
    69 --  ui.twitter("http://example.com/i" .. tostring(initiative.id) .. " " .. initiative.name)
    71   if initiative.discussion_url and #initiative.discussion_url > 0 then
    72     ui.link{
    73       attr = { 
    74         target = _"blank",
    75         title = initiative.discussion_url
    76       },
    77       content = function()
    78         ui.image{ static = "icons/16/comments.png" }
    79         slot.put(_"External discussion")
    80       end,
    81       external = initiative.discussion_url
    82     }
    83   end
    84   if initiator then
    85     ui.link{
    86       content = _"(change)",
    87       module = "initiative",
    88       view = "edit",
    89       id = initiative.id
    90     }
    91   end
    92 end)
    95 ui.container{
    96   attr = {  id = "add_suggestion_form", class = "hidden_inline_form" },
    97   content = function()
    99     ui.link{
   100       content = _"Close",
   101       attr = {
   102         onclick = "document.getElementById('add_suggestion_form').style.display='none';return(false)",
   103         style = "float: right;"
   104       }
   105     }
   107     ui.field.text{ attr = { class = "head" }, value = _"Add new suggestion" }
   110     ui.form{
   111       module = "suggestion",
   112       action = "add",
   113       params = { initiative_id = initiative.id },
   114       routing = {
   115         default = {
   116           mode = "redirect",
   117           module = "initiative",
   118           view = "show",
   119           id = initiative.id,
   120           params = { tab = "suggestion" }
   121         }
   122       },
   123       attr = { class = "vertical" },
   124       content = function()
   125         ui.field.text{ label = _"Name",        name = "name" }
   126         ui.field.text{ label = _"Description", name = "description", multiline = true }
   127         ui.field.select{ 
   128           label = _"Degree", 
   129           name = "degree",
   130           foreign_records = { 
   131             { id =  1, name = _"should"},
   132             { id =  2, name = _"must"},
   133           },
   134           foreign_id = "id",
   135           foreign_name = "name"
   136         }
   137         ui.submit{ text = _"Commit suggestion" }
   138       end
   139     }
   140   end
   141 }
   143 local supporter = app.session.member:get_reference_selector("supporters")
   144   :add_where{ "initiative_id = ?", initiative.id }
   145   :optional_object_mode()
   146   :exec()
   148 if supporter then
   149   local old_draft_id = supporter.draft_id
   150   local new_draft_id = initiative.current_draft.id
   151   if old_draft_id ~= new_draft_id then
   152     ui.container{
   153       attr = { class = "draft_updated_info" },
   154       content = function()
   155         slot.put("The draft of this initiative has been updated!")
   156         slot.put(" ")
   157         ui.link{
   158           content = _"Show diff",
   159           module = "draft",
   160           view = "diff",
   161           params = {
   162             old_draft_id = old_draft_id,
   163             new_draft_id = new_draft_id
   164           }
   165         }
   166         slot.put(" ")
   167         ui.link{
   168           content = _"Refresh support to current draft",
   169           module = "initiative",
   170           action = "add_support",
   171           id = initiative.id,
   172           routing = {
   173             default = {
   174               mode = "redirect",
   175               module = "initiative",
   176               view = "show",
   177               id = initiative.id
   178             }
   179           }
   180         }
   181       end
   182     }
   183   end
   184 end
   186 ui.tabs{
   187   {
   188     name = "current_draft",
   189     label = _"Current draft",
   190     content = function()
   191       execute.view{ module = "draft", view = "_show", params = { draft = initiative.current_draft } }
   192     end
   193   },
   194   {
   195     name = "suggestion",
   196     label = _"Suggestions",
   197     content = function()
   198       execute.view{ module = "suggestion", view = "_list", params = { suggestions_selector = initiative:get_reference_selector("suggestions") } }
   199       slot.put("<br />")
   200       if not initiative.issue.frozen and not initiative.issue.closed then
   201         ui.link{
   202           content = function()
   203             ui.image{ static = "icons/16/comment_add.png" }
   204             slot.put(_"Add new suggestion")
   205           end,
   206           attr = { onclick = "document.getElementById('add_suggestion_form').style.display='block';return(false)" },
   207           static = "#"
   208         }
   209       end
   210     end
   211   },
   212   {
   213     name = "supporter",
   214     label = _"Supporter",
   215     content = function()
   216       execute.view{
   217         module = "member",
   218         view = "_list",
   219         params = {
   220           initiative = initiative,
   221           members_selector =  initiative:get_reference_selector("supporting_members_snapshot")
   222             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
   223             :join("direct_population_snapshot", nil, "direct_population_snapshot.event = issue.latest_snapshot_event AND direct_population_snapshot.issue_id = issue.id AND direct_population_snapshot.member_id = member.id")
   224             :add_field("direct_population_snapshot.weight")
   225             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   226         }
   227       }
   228     end
   229   },
   230   {
   231     name = "initiators",
   232     label = _"Initiators",
   233     content = function()
   234       execute.view{ module = "member", view = "_list", params = { members_selector = initiative:get_reference_selector("initiating_members") } }
   235     end
   236   },
   237   {
   238     name = "drafts",
   239     label = _"Old drafts",
   240     content = function()
   241       execute.view{ module = "draft", view = "_list", params = { drafts = initiative.drafts } }
   242     end
   243   },
   244   {
   245     name = "details",
   246     label = _"Details",
   247     content = function()
   248       ui.form{
   249         attr = { class = "vertical" },
   250         record = initiative,
   251         readonly = true,
   252         content = function()
   253           ui.field.text{ label = _"Issue policy", value = initiative.issue.policy.name }
   254           ui.field.text{
   255             label = _"Created at",
   256             value = tostring(initiative.created)
   257           }
   258           ui.field.text{
   259             label = _"Created at",
   260             value = format.timestamp(initiative.created)
   261           }
   262           ui.field.date{ label = _"Revoked at", name = "revoked" }
   263           ui.field.boolean{ label = _"Admitted", name = "admitted" }
   264         end
   265       }
   266     end
   267   },
   268 }
