liquid_feedback_frontend
changeset 450:955bd41e1559
Added support for ignoring initiatives
author | bsw |
---|---|
date | Sun Mar 11 17:09:23 2012 +0100 (2012-03-11) |
parents | 8593115a687a |
children | 6a082a234e21 |
files | app/main/initiative/_action/update_ignore.lua app/main/supporter/_show_box.lua model/ignored_initiative.lua |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/initiative/_action/update_ignore.lua Sun Mar 11 17:09:23 2012 +0100 1.3 @@ -0,0 +1,20 @@ 1.4 +local member = app.session.member 1.5 +local initiative = Initiative:by_id(param.get_id()) 1.6 + 1.7 +local ignore_initiative = IgnoredInitiative:by_pk(member.id, initiative.id) 1.8 + 1.9 +if param.get("delete", atom.boolean) then 1.10 + if ignore_initiative then 1.11 + ignore_initiative:destroy() 1.12 + end 1.13 + return 1.14 +end 1.15 + 1.16 +if not ignore_initiative then 1.17 + ignore_initiative = IgnoredInitiative:new() 1.18 + ignore_initiative.member_id = member.id 1.19 + ignore_initiative.initiative_id = initiative.id 1.20 + ignore_initiative:save() 1.21 +end 1.22 + 1.23 +
2.1 --- a/app/main/supporter/_show_box.lua Sun Mar 11 13:35:04 2012 +0100 2.2 +++ b/app/main/supporter/_show_box.lua Sun Mar 11 17:09:23 2012 +0100 2.3 @@ -129,6 +129,49 @@ 2.4 id = initiative.id 2.5 } 2.6 end 2.7 + 2.8 + local ignored_initiative = IgnoredInitiative:by_pk(app.session.member.id, initiative.id) 2.9 + if ignored_initiative then 2.10 + ui.container{ 2.11 + attr = { class = "interest" }, 2.12 + content = _"You have ignored this initiative" 2.13 + } 2.14 + ui.link{ 2.15 + text = _"Stop ignoring initiative", 2.16 + module = "initiative", 2.17 + action = "update_ignore", 2.18 + id = initiative.id, 2.19 + params = { delete = true }, 2.20 + routing = { 2.21 + default = { 2.22 + mode = "redirect", 2.23 + module = request.get_module(), 2.24 + view = request.get_view(), 2.25 + id = param.get_id_cgi(), 2.26 + params = param.get_all_cgi() 2.27 + } 2.28 + } 2.29 + } 2.30 + else 2.31 + ui.link{ 2.32 + attr = { class = "interest" }, 2.33 + text = _"Ignore initiative", 2.34 + module = "initiative", 2.35 + action = "update_ignore", 2.36 + id = initiative.id, 2.37 + routing = { 2.38 + default = { 2.39 + mode = "redirect", 2.40 + module = request.get_module(), 2.41 + view = request.get_view(), 2.42 + id = param.get_id_cgi(), 2.43 + params = param.get_all_cgi() 2.44 + } 2.45 + } 2.46 + } 2.47 + end 2.48 + 2.49 + 2.50 end 2.51 } 2.52
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/model/ignored_initiative.lua Sun Mar 11 17:09:23 2012 +0100 3.3 @@ -0,0 +1,29 @@ 3.4 +IgnoredInitiative = mondelefant.new_class() 3.5 +IgnoredInitiative.table = 'ignored_initiative' 3.6 +IgnoredInitiative.primary_key = { "member_id", "initiative_id" } 3.7 + 3.8 +IgnoredInitiative:add_reference{ 3.9 + mode = 'm1', 3.10 + to = "Member", 3.11 + this_key = 'member_id', 3.12 + that_key = 'id', 3.13 + ref = 'member', 3.14 +} 3.15 + 3.16 +IgnoredInitiative:add_reference{ 3.17 + mode = 'm1', 3.18 + to = "Inititive", 3.19 + this_key = 'initiative_id', 3.20 + that_key = 'id', 3.21 + ref = 'initiative', 3.22 +} 3.23 + 3.24 + 3.25 +function IgnoredInitiative:by_pk(member_id, initiative_id) 3.26 + return self:new_selector() 3.27 + :add_where{ "member_id = ?", member_id } 3.28 + :add_where{ "initiative_id = ?", initiative_id } 3.29 + :optional_object_mode() 3.30 + :exec() 3.31 +end 3.32 +