liquid_feedback_frontend

view app/main/initiative/new.lua @ 578:54dc90658990

Fix "forgotten" policy id while using preview for new issue
author bsw
date Wed Jun 20 08:07:39 2012 +0200 (2012-06-20)
parents 418b590fa9ed
children ae9ab3edff89
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 if issue_id then
15 ui.title(_"Add alternative initiative to issue")
16 else
17 ui.title(_"Create new issue")
18 end
20 ui.form{
21 module = "initiative",
22 action = "create",
23 params = {
24 area_id = area.id,
25 issue_id = issue and issue.id or nil
26 },
27 attr = { class = "vertical" },
28 content = function()
29 ui.field.text{ label = _"Unit", value = area.unit.name }
30 ui.field.text{ label = _"Area", value = area.name }
31 slot.put("<br />")
32 if issue_id then
33 ui.field.text{ label = _"Issue", value = issue_id }
34 else
35 tmp = { { id = -1, name = _"Please choose a policy" } }
36 for i, allowed_policy in ipairs(area.allowed_policies) do
37 tmp[#tmp+1] = allowed_policy
38 end
39 ui.field.select{
40 label = _"Policy",
41 name = "policy_id",
42 foreign_records = tmp,
43 foreign_id = "id",
44 foreign_name = "name",
45 value = param.get("policy_id", atom.integer) or area.default_policy and area.default_policy.id
46 }
47 ui.tag{
48 tag = "div",
49 content = function()
50 ui.tag{
51 tag = "label",
52 attr = { class = "ui_field_label" },
53 content = function() slot.put("&nbsp;") end,
54 }
55 ui.tag{
56 content = function()
57 ui.link{
58 text = _"Information about the available policies",
59 module = "policy",
60 view = "list"
61 }
62 slot.put(" ")
63 ui.link{
64 attr = { target = "_blank" },
65 text = _"(new window)",
66 module = "policy",
67 view = "list"
68 }
69 end
70 }
71 end
72 }
73 end
75 if param.get("preview") then
76 ui.heading{ level = 1, content = encode.html(param.get("name")) }
77 local discussion_url = param.get("discussion_url")
78 ui.container{
79 attr = { class = "ui_field_label" },
80 content = _"Discussion with initiators"
81 }
82 ui.tag{
83 tag = "span",
84 content = function()
85 if discussion_url:find("^https?://") then
86 if discussion_url and #discussion_url > 0 then
87 ui.link{
88 attr = {
89 class = "actions",
90 target = "_blank",
91 title = discussion_url
92 },
93 content = discussion_url,
94 external = discussion_url
95 }
96 end
97 else
98 slot.put(encode.html(discussion_url))
99 end
100 end
101 }
102 ui.container{
103 attr = { class = "draft_content wiki" },
104 content = function()
105 slot.put(format.wiki_text(param.get("draft"), param.get("formatting_engine")))
106 end
107 }
108 slot.put("<br />")
109 ui.submit{ text = _"Save" }
110 slot.put("<br />")
111 slot.put("<br />")
112 end
113 slot.put("<br />")
115 ui.field.text{
116 label = _"Title of initiative",
117 name = "name",
118 value = param.get("name")
119 }
120 ui.field.text{
121 label = _"Discussion URL",
122 name = "discussion_url",
123 value = param.get("discussion_url")
124 }
125 ui.field.select{
126 label = _"Wiki engine",
127 name = "formatting_engine",
128 foreign_records = {
129 { id = "rocketwiki", name = "RocketWiki" },
130 { id = "compat", name = _"Traditional wiki syntax" }
131 },
132 attr = {id = "formatting_engine"},
133 foreign_id = "id",
134 foreign_name = "name",
135 value = param.get("formatting_engine")
136 }
137 ui.tag{
138 tag = "div",
139 content = function()
140 ui.tag{
141 tag = "label",
142 attr = { class = "ui_field_label" },
143 content = function() slot.put("&nbsp;") end,
144 }
145 ui.tag{
146 content = function()
147 ui.link{
148 text = _"Syntax help",
149 module = "help",
150 view = "show",
151 id = "wikisyntax",
152 attr = {onClick="this.href=this.href.replace(/wikisyntax[^.]*/g, 'wikisyntax_'+getElementById('formatting_engine').value)"}
153 }
154 slot.put(" ")
155 ui.link{
156 text = _"(new window)",
157 module = "help",
158 view = "show",
159 id = "wikisyntax",
160 attr = {target = "_blank", onClick="this.href=this.href.replace(/wikisyntax[^.]*/g, 'wikisyntax_'+getElementById('formatting_engine').value)"}
161 }
162 end
163 }
164 end
165 }
166 ui.field.text{
167 label = _"Draft",
168 name = "draft",
169 multiline = true,
170 attr = { style = "height: 50ex;" },
171 value = param.get("draft")
172 }
173 ui.submit{ name = "preview", text = _"Preview" }
174 ui.submit{ text = _"Save" }
175 end

Impressum / About Us