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