bsw/jbe@0: local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec() poelzi@148: local auto_support = param.get("auto_support", atom.boolean) bsw/jbe@0: bsw@1045: local draft_id = param.get("draft_id", atom.integer) bsw@1045: bsw/jbe@5: -- TODO important m1 selectors returning result _SET_! bsw/jbe@5: local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec() bsw/jbe@5: bsw@281: if not app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then bsw@281: error("access denied") bsw@281: end bsw@281: 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@964: 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@964: elseif bsw@964: (issue.half_frozen and issue.phase_finished) or bsw@964: (not issue.accepted and issue.phase_finished) bsw@964: then bsw@964: slot.put_into("error", _"Current phase is already closed.") bsw@964: return false bsw/jbe@5: end bsw/jbe@5: bsw@10: if initiative.revoked then bsw@10: slot.put_into("error", _"This initiative is revoked") bsw@10: return false bsw@10: end bsw@10: 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@1045: bsw@1045: if draft_id and draft_id ~= last_draft.id then bsw@1045: slot.select("error", function() bsw@1045: ui.tag{ content = _"The initiative draft has been updated again in the meanwhile, support not updated!" } bsw@1045: end) bsw@1045: return false bsw@1045: end 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 poelzi@165: if config.auto_support and auto_support ~= nil then poelzi@165: supporter.auto_support = auto_support poelzi@165: end bsw/jbe@0: supporter:save() 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@1045: slot.put_into("notice", _"Your support has been updated to the latest draft") bsw/jbe@0: else bsw@1045: slot.put_into("notice", _"You are already supporting the latest draft") poelzi@148: end poelzi@148: