liquid_feedback_frontend
view app/main/initiative/_action/add_support.lua @ 277:bde068b37608
Dropdown boxes except of delegation box removed, optical enhancements and repositioning of elements
author | bsw |
---|---|
date | Mon Feb 13 00:16:42 2012 +0100 (2012-02-13) |
parents | 6d30e49ad609 |
children | b77e6a17ca77 |
line source
1 local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
2 local auto_support = param.get("auto_support", atom.boolean)
4 -- TODO important m1 selectors returning result _SET_!
5 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
7 if issue.closed then
8 slot.put_into("error", _"This issue is already closed.")
9 return false
10 elseif issue.fully_frozen then
11 slot.put_into("error", _"Voting for this issue has already begun.")
12 return false
13 end
15 if initiative.revoked then
16 slot.put_into("error", _"This initiative is revoked")
17 return false
18 end
20 local member = app.session.member
22 local supporter = Supporter:by_pk(initiative.id, member.id)
24 local last_draft = Draft:new_selector()
25 :add_where{ "initiative_id = ?", initiative.id }
26 :add_order_by("id DESC")
27 :limit(1)
28 :single_object_mode()
29 :exec()
31 if not supporter then
32 supporter = Supporter:new()
33 supporter.member_id = member.id
34 supporter.initiative_id = initiative.id
35 supporter.draft_id = last_draft.id
36 if config.auto_support and auto_support ~= nil then
37 supporter.auto_support = auto_support
38 end
39 supporter:save()
40 -- slot.put_into("notice", _"Your support has been added to this initiative")
41 elseif supporter.draft_id ~= last_draft.id then
42 supporter.draft_id = last_draft.id
43 supporter:save()
44 -- slot.put_into("notice", _"Your support has been updated to the latest draft")
45 else
46 -- slot.put_into("notice", _"You are already supporting the latest draft")
47 end