liquid_feedback_frontend
view app/main/opinion/_action/update.lua @ 339:f8481330f4c2
Route user back to initiative after set/remove interest or delegation
| author | bsw | 
|---|---|
| date | Tue Feb 28 18:59:11 2012 +0100 (2012-02-28) | 
| parents | b77e6a17ca77 | 
| children | 1997cf1da04b | 
 line source
     1 local member_id = app.session.member.id
     3 local suggestion_id = param.get("suggestion_id", atom.integer)
     5 local opinion = Opinion:by_pk(member_id, suggestion_id)
     7 local suggestion = Suggestion:by_id(suggestion_id)
     9 if not suggestion then
    10   slot.put_into("error", _"This suggestion has been meanwhile deleted")
    11   return false
    12 end
    14 -- TODO important m1 selectors returning result _SET_!
    15 local issue = suggestion.initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
    17 if issue.closed then
    18   slot.put_into("error", _"This issue is already closed.")
    19   return false
    20 elseif issue.fully_frozen then 
    21   slot.put_into("error", _"Voting for this issue has already begun.")
    22   return false
    23 end
    25 if param.get("delete") then
    26   if opinion then
    27     opinion:destroy()
    28   end
    29   --slot.put_into("notice", _"Your rating has been deleted")
    30   return
    31 end
    33 local degree = param.get("degree", atom.number)
    34 local fulfilled = param.get("fulfilled", atom.boolean)
    36 if degree ~= 0 and not app.session.member:has_voting_right_for_unit_id(suggestion.initiative.issue.area.unit_id) then
    37   error("access denied")
    38 end
    40 if not opinion then
    41   opinion = Opinion:new()
    42   opinion.member_id     = member_id
    43   opinion.suggestion_id = suggestion_id
    44   opinion.fulfilled     = false
    45 end
    48 if degree ~= nil then
    49   opinion.degree = degree
    50 end
    52 if fulfilled ~= nil then
    53   opinion.fulfilled = fulfilled
    54 end
    56 opinion:save()
    58 --slot.put_into("notice", _"Your rating has been updated")
