liquid_feedback_frontend

annotate app/main/initiative/new.lua @ 904:a176129ce282

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

Impressum / About Us