liquid_feedback_frontend
view app/main/initiative/_action/add_support.lua @ 466:e15e8b15ccf5
Show all issues as default in issue list
| author | bsw | 
|---|---|
| date | Tue Mar 13 20:21:48 2012 +0100 (2012-03-13) | 
| parents | b77e6a17ca77 | 
| children | 1997cf1da04b | 
 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 not app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
     8   error("access denied")
     9 end
    11 if issue.closed then
    12   slot.put_into("error", _"This issue is already closed.")
    13   return false
    14 elseif issue.fully_frozen then 
    15   slot.put_into("error", _"Voting for this issue has already begun.")
    16   return false
    17 end
    19 if initiative.revoked then
    20   slot.put_into("error", _"This initiative is revoked")
    21   return false
    22 end
    24 local member = app.session.member
    26 local supporter = Supporter:by_pk(initiative.id, member.id)
    28 local last_draft = Draft:new_selector()
    29   :add_where{ "initiative_id = ?", initiative.id }
    30   :add_order_by("id DESC")
    31   :limit(1)
    32   :single_object_mode()
    33   :exec()
    35 if not supporter then
    36   supporter = Supporter:new()
    37   supporter.member_id = member.id
    38   supporter.initiative_id = initiative.id
    39   supporter.draft_id = last_draft.id
    40   if config.auto_support and auto_support ~= nil then
    41     supporter.auto_support = auto_support
    42   end
    43   supporter:save()
    44 --  slot.put_into("notice", _"Your support has been added to this initiative")
    45 elseif supporter.draft_id ~= last_draft.id then
    46   supporter.draft_id = last_draft.id
    47   supporter:save()
    48 --  slot.put_into("notice", _"Your support has been updated to the latest draft")
    49 else
    50 --  slot.put_into("notice", _"You are already supporting the latest draft")
    51 end
