liquid_feedback_frontend

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

Impressum / About Us