liquid_feedback_frontend

annotate app/main/initiative/_action/add_support.lua @ 258:878526479494

Removed old test scripts
author bsw
date Tue Feb 07 17:25:03 2012 +0100 (2012-02-07)
parents 6d30e49ad609
children bde068b37608
rev   line source
bsw/jbe@0 1 local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
poelzi@148 2 local auto_support = param.get("auto_support", atom.boolean)
bsw/jbe@0 3
bsw/jbe@5 4 -- TODO important m1 selectors returning result _SET_!
bsw/jbe@5 5 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
bsw/jbe@5 6
bsw/jbe@5 7 if issue.closed then
bsw/jbe@5 8 slot.put_into("error", _"This issue is already closed.")
bsw/jbe@5 9 return false
bsw/jbe@5 10 elseif issue.fully_frozen then
bsw/jbe@5 11 slot.put_into("error", _"Voting for this issue has already begun.")
bsw/jbe@5 12 return false
bsw/jbe@5 13 end
bsw/jbe@5 14
bsw@10 15 if initiative.revoked then
bsw@10 16 slot.put_into("error", _"This initiative is revoked")
bsw@10 17 return false
bsw@10 18 end
bsw@10 19
bsw/jbe@0 20 local member = app.session.member
bsw/jbe@0 21
bsw/jbe@0 22 local supporter = Supporter:by_pk(initiative.id, member.id)
bsw/jbe@0 23
bsw/jbe@0 24 local last_draft = Draft:new_selector()
bsw/jbe@0 25 :add_where{ "initiative_id = ?", initiative.id }
bsw/jbe@0 26 :add_order_by("id DESC")
bsw/jbe@0 27 :limit(1)
bsw/jbe@0 28 :single_object_mode()
bsw/jbe@0 29 :exec()
bsw/jbe@0 30
bsw/jbe@0 31 if not supporter then
bsw/jbe@0 32 supporter = Supporter:new()
bsw/jbe@0 33 supporter.member_id = member.id
bsw/jbe@0 34 supporter.initiative_id = initiative.id
bsw/jbe@0 35 supporter.draft_id = last_draft.id
poelzi@165 36 if config.auto_support and auto_support ~= nil then
poelzi@165 37 supporter.auto_support = auto_support
poelzi@165 38 end
bsw/jbe@0 39 supporter:save()
bsw/jbe@0 40 slot.put_into("notice", _"Your support has been added to this initiative")
poelzi@148 41 if supporter.auto_active then
poelzi@148 42 slot.put_into("notice", _"Auto support is now enabled")
poelzi@148 43 end
poelzi@148 44 elseif (auto_support ~= nil and supporter.auto_support ~= auto_support) and config.auto_support then
poelzi@148 45 supporter.auto_support = auto_support
poelzi@148 46 if auto_support then
poelzi@148 47 slot.put_into("notice", _"Auto support is now enabled")
poelzi@148 48 else
poelzi@148 49 slot.put_into("notice", _"Auto support is now disabled")
poelzi@148 50 end
poelzi@148 51 supporter.draft_id = last_draft.id
poelzi@148 52 supporter:save()
bsw/jbe@0 53 elseif supporter.draft_id ~= last_draft.id then
bsw/jbe@0 54 supporter.draft_id = last_draft.id
bsw/jbe@0 55 supporter:save()
bsw/jbe@0 56 slot.put_into("notice", _"Your support has been updated to the latest draft")
bsw/jbe@0 57 else
bsw/jbe@0 58 slot.put_into("notice", _"You are already supporting the latest draft")
poelzi@148 59 end
poelzi@148 60

Impressum / About Us