liquid_feedback_frontend
view app/main/initiative/show.lua @ 1496:ed3c40911ae1
Completed image attachments feature
author | bsw |
---|---|
date | Tue Feb 11 15:24:36 2020 +0100 (2020-02-11) |
parents | 17e7082c377a |
children | 056bccb61eee |
line source
1 local initiative = Initiative:by_id ( param.get_id() )
2 local member = app.session.member
4 if not initiative then
5 execute.view { module = "index", view = "404" }
6 request.set_status("404 Not Found")
7 return
8 end
10 app.current_initiative = initiative
12 local issue_info
14 if member then
15 initiative:load_everything_for_member_id(member.id)
16 initiative.issue:load_everything_for_member_id(member.id)
17 issue_info = initiative.issue.member_info
18 end
20 local direct_supporter
22 if app.session.member_id then
23 direct_supporter = initiative.issue.member_info.own_participation and initiative.member_info.supported
24 end
26 slot.put_into("header", initiative.display_name)
28 execute.view{ module = "issue", view = "_head", params = { issue = initiative.issue, link_issue = true } }
30 ui.grid{ content = function()
32 ui.cell_main{ content = function()
33 ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
34 execute.view{
35 module = "initiative", view = "_head", params = {
36 initiative = initiative
37 }
38 }
40 if direct_supporter and not initiative.issue.closed then
41 local supporter = app.session.member:get_reference_selector("supporters")
42 :add_where{ "initiative_id = ?", initiative.id }
43 :optional_object_mode()
44 :exec()
46 if supporter then
48 local old_draft_id = supporter.draft_id
49 local new_draft_id = initiative.current_draft.id
51 if old_draft_id ~= new_draft_id then
52 ui.container {
53 attr = { class = "mdl-card__content mdl-card--no-bottom-pad mdl-card--notice" },
54 content = _"The draft of this initiative has been updated!"
55 }
56 ui.container {
57 attr = { class = "mdl-card__actions mdl-card--action-border mdl-card--notice" },
58 content = function ()
59 if not initiative.revoked then
60 ui.link{
61 attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
62 text = _"refresh my support",
63 module = "initiative",
64 action = "add_support",
65 id = initiative.id,
66 params = { draft_id = initiative.current_draft.id },
67 routing = {
68 default = {
69 mode = "redirect",
70 module = "initiative",
71 view = "show",
72 id = initiative.id
73 }
74 }
75 }
76 slot.put(" ")
77 ui.link{
78 attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
79 content = _"show differences",
80 module = "draft",
81 view = "diff",
82 params = {
83 old_draft_id = old_draft_id,
84 new_draft_id = new_draft_id
85 }
86 }
87 slot.put(" ")
88 end
89 ui.link{
90 attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
91 text = _"remove my support",
92 module = "initiative",
93 action = "remove_support",
94 id = initiative.id,
95 routing = {
96 default = {
97 mode = "redirect",
98 module = "initiative",
99 view = "show",
100 id = initiative.id
101 }
102 }
103 }
105 end
106 }
107 end
108 end
109 end
111 if config.render_external_reference and config.render_external_reference.initiative then
112 config.render_external_reference.initiative(initiative, function (callback)
113 ui.sectionRow(callback)
114 end)
115 end
116 local draft_content = initiative.current_draft.content
117 if config.initiative_abstract then
118 local abstract = string.match(draft_content, "(.+)<!%--END_OF_ABSTRACT%-->")
119 if abstract then
120 draft_content = string.match(draft_content, "<!%--END_OF_ABSTRACT%-->(.*)")
121 end
122 end
123 ui.container {
124 attr = { class = "draft mdl-card__content mdl-card--border" },
125 content = function ()
126 if initiative.current_draft.formatting_engine == "html" or not initiative.current_draft.formatting_engine then
127 if config.draft_filter then
128 slot.put(config.draft_filter(draft_content))
129 else
130 slot.put(draft_content)
131 end
132 else
133 slot.put ( initiative.current_draft:get_content ( "html" ) )
134 end
135 end
136 }
138 if config.attachments then
140 local files = File:new_selector()
141 :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
142 :add_where{ "draft_attachment.draft_id = ?", initiative.current_draft.id }
143 :reset_fields()
144 :add_field("file.id")
145 :add_field("draft_attachment.title")
146 :add_field("draft_attachment.description")
147 :add_order_by("draft_attachment.id")
148 :exec()
150 if #files > 0 then
151 ui.container {
152 attr = { class = "mdl-card__content mdl-card--border" },
153 content = function()
154 for i, file in ipairs(files) do
155 ui.link{ module = "file", view = "show.jpg", id = file.id, content = function()
156 ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
157 end }
158 ui.container{ content = function()
159 ui.tag{ tag = "strong", content = file.title or "" }
160 end }
161 ui.container{ content = file.description or "" }
162 slot.put("<br /><br />")
163 end
164 end
165 }
166 end
167 end
169 local drafts_count = initiative:get_reference_selector("drafts"):count()
171 if not config.voting_only then
172 ui.container {
173 attr = { class = "mdl-card__actions" },
174 content = function()
175 ui.link{
176 attr = { class = "mdl-button mdl-js-button" },
177 module = "initiative", view = "history", id = initiative.id,
178 content = _("draft history (#{count})", { count = drafts_count })
179 }
180 end
181 }
182 end
184 end }
186 execute.view{ module = "initiative", view = "_suggestions", params = { initiative = initiative } }
188 end }
190 ui.cell_sidebar{ content = function()
191 if config.logo then
192 config.logo()
193 end
194 execute.view {
195 module = "issue", view = "_sidebar",
196 params = {
197 issue = initiative.issue,
198 initiative = initiative,
199 member = app.session.member
200 }
201 }
203 execute.view {
204 module = "issue", view = "_sidebar_whatcanido",
205 params = {
206 issue = initiative.issue,
207 initiative = initiative,
208 member = app.session.member
209 }
210 }
212 execute.view {
213 module = "issue", view = "_sidebar_members", params = {
214 issue = initiative.issue, initiative = initiative
215 }
216 }
218 end }
220 end }