# HG changeset patch # User bsw # Date 1331482163 -3600 # Node ID 955bd41e15590d46821b4e16d0b9e4893dff9f53 # Parent 8593115a687acd7195ca20f2a43ab1675b178b87 Added support for ignoring initiatives diff -r 8593115a687a -r 955bd41e1559 app/main/initiative/_action/update_ignore.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/main/initiative/_action/update_ignore.lua Sun Mar 11 17:09:23 2012 +0100 @@ -0,0 +1,20 @@ +local member = app.session.member +local initiative = Initiative:by_id(param.get_id()) + +local ignore_initiative = IgnoredInitiative:by_pk(member.id, initiative.id) + +if param.get("delete", atom.boolean) then + if ignore_initiative then + ignore_initiative:destroy() + end + return +end + +if not ignore_initiative then + ignore_initiative = IgnoredInitiative:new() + ignore_initiative.member_id = member.id + ignore_initiative.initiative_id = initiative.id + ignore_initiative:save() +end + + diff -r 8593115a687a -r 955bd41e1559 app/main/supporter/_show_box.lua --- a/app/main/supporter/_show_box.lua Sun Mar 11 13:35:04 2012 +0100 +++ b/app/main/supporter/_show_box.lua Sun Mar 11 17:09:23 2012 +0100 @@ -129,6 +129,49 @@ id = initiative.id } end + + local ignored_initiative = IgnoredInitiative:by_pk(app.session.member.id, initiative.id) + if ignored_initiative then + ui.container{ + attr = { class = "interest" }, + content = _"You have ignored this initiative" + } + ui.link{ + text = _"Stop ignoring initiative", + module = "initiative", + action = "update_ignore", + id = initiative.id, + params = { delete = true }, + routing = { + default = { + mode = "redirect", + module = request.get_module(), + view = request.get_view(), + id = param.get_id_cgi(), + params = param.get_all_cgi() + } + } + } + else + ui.link{ + attr = { class = "interest" }, + text = _"Ignore initiative", + module = "initiative", + action = "update_ignore", + id = initiative.id, + routing = { + default = { + mode = "redirect", + module = request.get_module(), + view = request.get_view(), + id = param.get_id_cgi(), + params = param.get_all_cgi() + } + } + } + end + + end } diff -r 8593115a687a -r 955bd41e1559 model/ignored_initiative.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/model/ignored_initiative.lua Sun Mar 11 17:09:23 2012 +0100 @@ -0,0 +1,29 @@ +IgnoredInitiative = mondelefant.new_class() +IgnoredInitiative.table = 'ignored_initiative' +IgnoredInitiative.primary_key = { "member_id", "initiative_id" } + +IgnoredInitiative:add_reference{ + mode = 'm1', + to = "Member", + this_key = 'member_id', + that_key = 'id', + ref = 'member', +} + +IgnoredInitiative:add_reference{ + mode = 'm1', + to = "Inititive", + this_key = 'initiative_id', + that_key = 'id', + ref = 'initiative', +} + + +function IgnoredInitiative:by_pk(member_id, initiative_id) + return self:new_selector() + :add_where{ "member_id = ?", member_id } + :add_where{ "initiative_id = ?", initiative_id } + :optional_object_mode() + :exec() +end +