liquid_feedback_frontend

view app/main/initiative/new.lua @ 901:f3d6d08b0125

Added support for creating free timed issues in poll mode
author bsw
date Tue Aug 21 01:16:03 2012 +0200 (2012-08-21)
parents ae9ab3edff89
children dd6c00eb215f
line source
1 local issue
2 local area
4 local issue_id = param.get("issue_id", atom.integer)
5 if issue_id then
6 issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
7 area = issue.area
9 else
10 local area_id = param.get("area_id", atom.integer)
11 area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
12 end
14 local policy_id = param.get("policy_id", atom.integer)
15 local policy
17 if policy_id then
18 policy = Policy:by_id(policy_id)
19 end
21 if issue_id then
22 ui.title(_"Add alternative initiative to issue")
23 else
24 ui.title(_"Create new issue")
25 end
27 if not issue_id and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
28 ui.actions(function()
29 for i, policy in ipairs(area.allowed_policies) do
30 if policy.polling then
31 ui.link{
32 text = policy.name,
33 module = "initiative", view = "new", params = {
34 area_id = area.id, policy_id = policy.id
35 }
36 }
37 end
38 end
39 end)
40 end
42 ui.form{
43 module = "initiative",
44 action = "create",
45 params = {
46 area_id = area.id,
47 issue_id = issue and issue.id or nil
48 },
49 attr = { class = "vertical" },
50 content = function()
51 ui.field.text{ label = _"Unit", value = area.unit.name }
52 ui.field.text{ label = _"Area", value = area.name }
53 slot.put("<br />")
54 if issue_id then
55 ui.field.text{ label = _"Issue", value = issue_id }
56 elseif policy_id then
57 ui.field.hidden{ name = "policy_id", value = policy.id }
58 ui.field.text{ label = _"Policy", value = policy.name }
59 if policy.free_timeable then
60 local available_timings
61 if config.free_timing and config.free_timing.available_func then
62 available_timings = config.free_timing.available_func(policy)
63 if available_timings == false then
64 error("error in free timing config")
65 end
66 end
67 if available_timings then
68 ui.field.select{
69 label = _"Free timing",
70 name = _"free_timing",
71 foreign_records = available_timings,
72 foreign_id = "id",
73 foreign_name = "name"
74 }
75 else
76 ui.field.text{ label = _"Free timing", name = "free_timing" }
77 end
78 end
79 else
80 tmp = { { id = -1, name = _"Please choose a policy" } }
81 for i, allowed_policy in ipairs(area.allowed_policies) do
82 if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then
83 tmp[#tmp+1] = allowed_policy
84 end
85 end
86 ui.field.select{
87 label = _"Policy",
88 name = "policy_id",
89 foreign_records = tmp,
90 foreign_id = "id",
91 foreign_name = "name",
92 value = param.get("policy_id", atom.integer) or area.default_policy and area.default_policy.id
93 }
94 ui.tag{
95 tag = "div",
96 content = function()
97 ui.tag{
98 tag = "label",
99 attr = { class = "ui_field_label" },
100 content = function() slot.put("&nbsp;") end,
101 }
102 ui.tag{
103 content = function()
104 ui.link{
105 text = _"Information about the available policies",
106 module = "policy",
107 view = "list"
108 }
109 slot.put(" ")
110 ui.link{
111 attr = { target = "_blank" },
112 text = _"(new window)",
113 module = "policy",
114 view = "list"
115 }
116 end
117 }
118 end
119 }
120 end
122 if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
123 ui.field.boolean{ name = "polling", label = _"Poll" }
124 end
126 if param.get("preview") then
127 ui.heading{ level = 1, content = encode.html(param.get("name")) }
128 local discussion_url = param.get("discussion_url")
129 ui.container{
130 attr = { class = "ui_field_label" },
131 content = _"Discussion with initiators"
132 }
133 ui.tag{
134 tag = "span",
135 content = function()
136 if discussion_url:find("^https?://") then
137 if discussion_url and #discussion_url > 0 then
138 ui.link{
139 attr = {
140 class = "actions",
141 target = "_blank",
142 title = discussion_url
143 },
144 content = discussion_url,
145 external = discussion_url
146 }
147 end
148 else
149 slot.put(encode.html(discussion_url))
150 end
151 end
152 }
153 ui.container{
154 attr = { class = "draft_content wiki" },
155 content = function()
156 slot.put(format.wiki_text(param.get("draft"), param.get("formatting_engine")))
157 end
158 }
159 slot.put("<br />")
160 ui.submit{ text = _"Save" }
161 slot.put("<br />")
162 slot.put("<br />")
163 end
164 slot.put("<br />")
166 ui.field.text{
167 label = _"Title of initiative",
168 name = "name",
169 value = param.get("name")
170 }
171 ui.field.text{
172 label = _"Discussion URL",
173 name = "discussion_url",
174 value = param.get("discussion_url")
175 }
176 ui.field.select{
177 label = _"Wiki engine",
178 name = "formatting_engine",
179 foreign_records = {
180 { id = "rocketwiki", name = "RocketWiki" },
181 { id = "compat", name = _"Traditional wiki syntax" }
182 },
183 attr = {id = "formatting_engine"},
184 foreign_id = "id",
185 foreign_name = "name",
186 value = param.get("formatting_engine")
187 }
188 ui.tag{
189 tag = "div",
190 content = function()
191 ui.tag{
192 tag = "label",
193 attr = { class = "ui_field_label" },
194 content = function() slot.put("&nbsp;") end,
195 }
196 ui.tag{
197 content = function()
198 ui.link{
199 text = _"Syntax help",
200 module = "help",
201 view = "show",
202 id = "wikisyntax",
203 attr = {onClick="this.href=this.href.replace(/wikisyntax[^.]*/g, 'wikisyntax_'+getElementById('formatting_engine').value)"}
204 }
205 slot.put(" ")
206 ui.link{
207 text = _"(new window)",
208 module = "help",
209 view = "show",
210 id = "wikisyntax",
211 attr = {target = "_blank", onClick="this.href=this.href.replace(/wikisyntax[^.]*/g, 'wikisyntax_'+getElementById('formatting_engine').value)"}
212 }
213 end
214 }
215 end
216 }
217 ui.field.text{
218 label = _"Draft",
219 name = "draft",
220 multiline = true,
221 attr = { style = "height: 50ex;" },
222 value = param.get("draft")
223 }
224 ui.submit{ name = "preview", text = _"Preview" }
225 ui.submit{ text = _"Save" }
226 end

Impressum / About Us