liquid_feedback_frontend
view app/main/initiative/_action/create.lua @ 159:5d797c6706d5
implement quorum display
show the initiative quorum as a small 1px line in bargraph
allow to update your support on the diff page
better linked title in diff page
show absolute quorum numbers in detail pages of issue and initiative
show the initiative quorum as a small 1px line in bargraph
allow to update your support on the diff page
better linked title in diff page
show absolute quorum numbers in detail pages of issue and initiative
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sat Oct 09 03:42:48 2010 +0200 (2010-10-09) |
parents | 6a12fb7e4963 |
children | 7ea52c710503 b77e6a17ca77 |
line source
1 local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
2 if tmp then
3 if tmp.initiatives_left and tmp.initiatives_left < 1 then
4 slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
5 return false
6 end
7 if tmp.text_entries_left and tmp.text_entries_left < 1 then
8 slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
9 return false
10 end
11 end
13 local issue
14 local area
16 local issue_id = param.get("issue_id", atom.integer)
17 if issue_id then
18 issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
19 if issue.closed then
20 slot.put_into("error", _"This issue is already closed.")
21 return false
22 elseif issue.fully_frozen then
23 slot.put_into("error", _"Voting for this issue has already begun.")
24 return false
25 end
26 area = issue.area
27 else
28 local area_id = param.get("area_id", atom.integer)
29 area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
30 if not area.active then
31 slot.put_into("error", "Invalid area.")
32 return false
33 end
34 end
36 local name = param.get("name")
38 local name = util.trim(name)
40 if #name < 3 then
41 slot.put_into("error", _"This name is really too short!")
42 return false
43 end
45 local formatting_engine = param.get("formatting_engine")
47 local formatting_engine_valid = false
48 for fe, dummy in pairs(config.formatting_engine_executeables) do
49 if formatting_engine == fe then
50 formatting_engine_valid = true
51 end
52 end
53 if not formatting_engine_valid then
54 error("invalid formatting engine!")
55 end
57 if param.get("preview") then
58 return
59 end
62 local initiative = Initiative:new()
64 if not issue then
65 local policy_id = param.get("policy_id", atom.integer)
66 if policy_id == -1 then
67 slot.put_into("error", _"Please choose a policy")
68 return false
69 end
70 local policy = Policy:by_id(policy_id)
71 if not policy.active then
72 slot.put_into("error", "Invalid policy.")
73 return false
74 end
75 if not area:get_reference_selector("allowed_policies")
76 :add_where{ "policy.id = ?", policy_id }
77 :optional_object_mode()
78 :exec()
79 then
80 error("policy not allowed")
81 end
82 issue = Issue:new()
83 issue.area_id = area.id
84 issue.policy_id = policy_id
85 issue:save()
86 end
88 initiative.issue_id = issue.id
89 initiative.name = name
90 param.update(initiative, "discussion_url")
91 initiative:save()
93 local draft = Draft:new()
94 draft.initiative_id = initiative.id
95 draft.formatting_engine = formatting_engine
96 draft.content = param.get("draft")
97 draft.author_id = app.session.member.id
98 draft:save()
100 local initiator = Initiator:new()
101 initiator.initiative_id = initiative.id
102 initiator.member_id = app.session.member.id
103 initiator.accepted = true
104 initiator:save()
106 local supporter = Supporter:new()
107 supporter.initiative_id = initiative.id
108 supporter.member_id = app.session.member.id
109 supporter.draft_id = draft.id
110 supporter:save()
112 slot.put_into("notice", _"Initiative successfully created")
114 request.redirect{
115 module = "initiative",
116 view = "show",
117 id = initiative.id
118 }