liquid_feedback_frontend

annotate app/main/opinion/_action/update.lua @ 1455:24dc7bd75d0a

New layout for admin member edit view
author bsw
date Thu Oct 18 17:23:45 2018 +0200 (2018-10-18)
parents 32cc544d5a5b
children 4188405c2425
rev   line source
bsw/jbe@0 1 local member_id = app.session.member.id
bsw/jbe@0 2
bsw/jbe@0 3 local suggestion_id = param.get("suggestion_id", atom.integer)
bsw/jbe@0 4
bsw/jbe@0 5 local opinion = Opinion:by_pk(member_id, suggestion_id)
bsw/jbe@0 6
bsw/jbe@6 7 local suggestion = Suggestion:by_id(suggestion_id)
bsw/jbe@6 8
bsw@1045 9 local degree = param.get("degree", atom.number)
bsw@1045 10 local fulfilled = param.get("fulfilled", atom.boolean)
bsw@1045 11
bsw@1045 12
bsw/jbe@6 13 if not suggestion then
bsw/jbe@6 14 slot.put_into("error", _"This suggestion has been meanwhile deleted")
bsw/jbe@6 15 return false
bsw/jbe@6 16 end
bsw/jbe@6 17
bsw/jbe@5 18 -- TODO important m1 selectors returning result _SET_!
bsw/jbe@6 19 local issue = suggestion.initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
bsw/jbe@5 20
bsw/jbe@5 21 if issue.closed then
bsw/jbe@5 22 slot.put_into("error", _"This issue is already closed.")
bsw/jbe@5 23 return false
bsw/jbe@5 24 elseif issue.fully_frozen then
bsw/jbe@5 25 slot.put_into("error", _"Voting for this issue has already begun.")
bsw/jbe@5 26 return false
bsw@964 27 elseif
bsw@964 28 (issue.half_frozen and issue.phase_finished) or
bsw@964 29 (not issue.accepted and issue.phase_finished)
bsw@964 30 then
bsw@964 31 slot.put_into("error", _"Current phase is already closed.")
bsw@964 32 return false
bsw/jbe@5 33 end
bsw/jbe@5 34
bsw@1045 35 if degree == 0 then
bsw@3 36 if opinion then
bsw@3 37 opinion:destroy()
bsw@3 38 end
bsw@280 39 --slot.put_into("notice", _"Your rating has been deleted")
bsw/jbe@0 40 return
bsw/jbe@0 41 end
bsw/jbe@0 42
bsw@281 43 if degree ~= 0 and not app.session.member:has_voting_right_for_unit_id(suggestion.initiative.issue.area.unit_id) then
bsw/jbe@1309 44 return execute.view { module = "index", view = "403" }
bsw@281 45 end
bsw@281 46
bsw/jbe@0 47 if not opinion then
bsw/jbe@0 48 opinion = Opinion:new()
bsw/jbe@0 49 opinion.member_id = member_id
bsw/jbe@0 50 opinion.suggestion_id = suggestion_id
bsw/jbe@0 51 opinion.fulfilled = false
bsw/jbe@0 52 end
bsw/jbe@0 53
bsw/jbe@0 54
bsw/jbe@0 55 if degree ~= nil then
bsw/jbe@0 56 opinion.degree = degree
bsw/jbe@0 57 end
bsw/jbe@0 58
bsw/jbe@0 59 if fulfilled ~= nil then
bsw/jbe@0 60 opinion.fulfilled = fulfilled
bsw/jbe@0 61 end
bsw/jbe@0 62
bsw/jbe@0 63 opinion:save()
bsw/jbe@0 64
bsw@280 65 --slot.put_into("notice", _"Your rating has been updated")

Impressum / About Us