liquid_feedback_frontend

view app/main/initiative/_action/add_support.lua @ 165:6d30e49ad609

don't set null on auto_support field
author Daniel Poelzleithner <poelzi@poelzi.org>
date Sat Oct 09 21:11:59 2010 +0200 (2010-10-09)
parents 034f96181e59
children bde068b37608
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 if supporter.auto_active then
42 slot.put_into("notice", _"Auto support is now enabled")
43 end
44 elseif (auto_support ~= nil and supporter.auto_support ~= auto_support) and config.auto_support then
45 supporter.auto_support = auto_support
46 if auto_support then
47 slot.put_into("notice", _"Auto support is now enabled")
48 else
49 slot.put_into("notice", _"Auto support is now disabled")
50 end
51 supporter.draft_id = last_draft.id
52 supporter:save()
53 elseif supporter.draft_id ~= last_draft.id then
54 supporter.draft_id = last_draft.id
55 supporter:save()
56 slot.put_into("notice", _"Your support has been updated to the latest draft")
57 else
58 slot.put_into("notice", _"You are already supporting the latest draft")
59 end

Impressum / About Us