rev |
line source |
bsw/jbe@0
|
1 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
|
bsw/jbe@0
|
2
|
bsw/jbe@5
|
3 -- TODO important m1 selectors returning result _SET_!
|
bsw/jbe@5
|
4 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
|
bsw/jbe@5
|
5
|
bsw/jbe@5
|
6 if issue.closed then
|
bsw/jbe@5
|
7 slot.put_into("error", _"This issue is already closed.")
|
bsw/jbe@5
|
8 return false
|
bsw/jbe@5
|
9 elseif issue.half_frozen then
|
bsw/jbe@5
|
10 slot.put_into("error", _"This issue is already frozen.")
|
bsw/jbe@5
|
11 return false
|
bsw@964
|
12 elseif issue.phase_finished then
|
bsw@964
|
13 slot.put_into("error", _"Current phase is already closed.")
|
bsw@964
|
14 return false
|
bsw/jbe@5
|
15 end
|
bsw/jbe@5
|
16
|
bsw@10
|
17 local initiator = Initiator:by_pk(initiative.id, app.session.member.id)
|
bsw@10
|
18 if not initiator or not initiator.accepted then
|
bsw@10
|
19 error("access denied")
|
bsw@10
|
20 end
|
bsw@10
|
21
|
bsw@904
|
22 local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ? AND polling = ?", app.session.member.id, initiative.polling }, "opt_object")
|
bsw@904
|
23 if not tmp or tmp.text_entries_left < 1 then
|
bsw@904
|
24 slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
|
bsw@904
|
25 return false
|
bsw@904
|
26 end
|
bsw@904
|
27
|
bsw@10
|
28 local formatting_engine = param.get("formatting_engine")
|
bsw@81
|
29
|
bsw@10
|
30 local formatting_engine_valid = false
|
bsw@10
|
31 for fe, dummy in pairs(config.formatting_engine_executeables) do
|
bsw@10
|
32 if formatting_engine == fe then
|
bsw@10
|
33 formatting_engine_valid = true
|
bsw/jbe@4
|
34 end
|
bsw@10
|
35 end
|
bsw@10
|
36 if not formatting_engine_valid then
|
bsw@10
|
37 error("invalid formatting engine!")
|
bsw@10
|
38 end
|
bsw@81
|
39
|
bsw@95
|
40 if param.get("preview") then
|
bsw@95
|
41 return false
|
bsw@95
|
42 end
|
bsw@81
|
43
|
bsw@81
|
44 local draft = Draft:new()
|
bsw@81
|
45 draft.author_id = app.session.member.id
|
bsw@81
|
46 draft.initiative_id = initiative.id
|
bsw@10
|
47 draft.formatting_engine = formatting_engine
|
bsw@10
|
48 draft.content = param.get("content")
|
bsw@10
|
49 draft:save()
|
bsw/jbe@0
|
50
|
bsw@499
|
51 local supporter = Supporter:by_pk(initiative.id, app.session.member.id)
|
bsw@499
|
52
|
bsw@499
|
53 if supporter then
|
bsw@499
|
54 supporter.draft_id = draft.id
|
bsw@499
|
55 supporter:save()
|
bsw@499
|
56 end
|
bsw@499
|
57
|
bsw@81
|
58 draft:render_content()
|
bsw@81
|
59
|
bsw@10
|
60 slot.put_into("notice", _"New draft has been added to initiative")
|
bsw/jbe@0
|
61
|