bsw/jbe@0: local member_id = app.session.member.id bsw/jbe@0: bsw/jbe@0: local suggestion_id = param.get("suggestion_id", atom.integer) bsw/jbe@0: bsw/jbe@0: local opinion = Opinion:by_pk(member_id, suggestion_id) bsw/jbe@0: bsw/jbe@6: local suggestion = Suggestion:by_id(suggestion_id) bsw/jbe@6: bsw/jbe@6: if not suggestion then bsw/jbe@6: slot.put_into("error", _"This suggestion has been meanwhile deleted") bsw/jbe@6: return false bsw/jbe@6: end bsw/jbe@6: bsw/jbe@5: -- TODO important m1 selectors returning result _SET_! bsw/jbe@6: local issue = suggestion.initiative:get_reference_selector("issue"):for_share():single_object_mode():exec() bsw/jbe@5: bsw/jbe@5: if issue.closed then bsw/jbe@5: slot.put_into("error", _"This issue is already closed.") bsw/jbe@5: return false bsw/jbe@5: elseif issue.fully_frozen then bsw/jbe@5: slot.put_into("error", _"Voting for this issue has already begun.") bsw/jbe@5: return false bsw/jbe@5: end bsw/jbe@5: bsw/jbe@5: bsw/jbe@5: bsw@3: if param.get("delete") then bsw@3: if opinion then bsw@3: opinion:destroy() bsw@3: end bsw@95: slot.put_into("notice", _"Your rating has been deleted") bsw/jbe@0: return bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: if not opinion then bsw/jbe@0: opinion = Opinion:new() bsw/jbe@0: opinion.member_id = member_id bsw/jbe@0: opinion.suggestion_id = suggestion_id bsw/jbe@0: opinion.fulfilled = false bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: local degree = param.get("degree", atom.number) bsw/jbe@0: local fulfilled = param.get("fulfilled", atom.boolean) bsw/jbe@0: bsw/jbe@0: if degree ~= nil then bsw/jbe@0: opinion.degree = degree bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: if fulfilled ~= nil then bsw/jbe@0: opinion.fulfilled = fulfilled bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: opinion:save() bsw/jbe@0: bsw@95: slot.put_into("notice", _"Your rating has been updated")