bsw/jbe@0: local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec() bsw/jbe@0: bsw/jbe@0: local member = app.session.member bsw/jbe@0: bsw/jbe@0: local supporter = Supporter:by_pk(initiative.id, member.id) bsw/jbe@0: bsw/jbe@0: local last_draft = Draft:new_selector() bsw/jbe@0: :add_where{ "initiative_id = ?", initiative.id } bsw/jbe@0: :add_order_by("id DESC") bsw/jbe@0: :limit(1) bsw/jbe@0: :single_object_mode() bsw/jbe@0: :exec() bsw/jbe@0: bsw/jbe@0: if not supporter then bsw/jbe@0: supporter = Supporter:new() bsw/jbe@0: supporter.member_id = member.id bsw/jbe@0: supporter.initiative_id = initiative.id bsw/jbe@0: supporter.draft_id = last_draft.id bsw/jbe@0: supporter:save() bsw/jbe@0: slot.put_into("notice", _"Your support has been added to this initiative") bsw/jbe@0: elseif supporter.draft_id ~= last_draft.id then bsw/jbe@0: supporter.draft_id = last_draft.id bsw/jbe@0: supporter:save() bsw/jbe@0: slot.put_into("notice", _"Your support has been updated to the latest draft") bsw/jbe@0: else bsw/jbe@0: slot.put_into("notice", _"You are already supporting the latest draft") bsw/jbe@0: end