# HG changeset patch # User bsw # Date 1289227274 -3600 # Node ID a9c6c11dd86cbf2b3a290a71b69a5be803b5f2f1 # Parent c0835d7074650a4552a79580afb5744376ba65f7 Contact module refactored diff -r c0835d707465 -r a9c6c11dd86c app/main/contact/_list.lua --- a/app/main/contact/_list.lua Mon Nov 08 15:30:59 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ - -local contacts_selector = Contact:new_selector() - :add_where{ "member_id = ?", app.session.member.id } - :join("member", nil, "member.id = contact.other_member_id") - :add_order_by("member.name") - -ui.paginate{ - selector = contacts_selector, - content = function() - local contacts = contacts_selector:exec() - if #contacts == 0 then - ui.field.text{ value = _"You didn't saved any member as contact yet." } - else - ui.list{ - records = contacts, - columns = { - { - label = _"Name", - content = function(record) - ui.link{ - text = record.other_member.name, - module = "member", - view = "show", - id = record.other_member_id - } - end - }, - { - label = _"Published", - content = function(record) - ui.field.boolean{ value = record.public } - end - }, - { - content = function(record) - if record.public then - ui.link{ - attr = { class = "action" }, - text = _"Hide", - module = "contact", - action = "add_member", - id = record.other_member_id, - params = { public = false }, - 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 = "action" }, - text = _"Publish", - module = "contact", - action = "add_member", - id = record.other_member_id, - params = { public = true }, - routing = { - default = { - mode = "redirect", - module = request.get_module(), - view = request.get_view(), - id = param.get_id_cgi(), - params = param.get_all_cgi() - } - } - } - end - end - }, - { - content = function(record) - ui.link{ - attr = { class = "action" }, - text = _"Remove", - module = "contact", - action = "remove_member", - id = record.other_member_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 - end -} diff -r c0835d707465 -r a9c6c11dd86c app/main/contact/list.lua --- a/app/main/contact/list.lua Mon Nov 08 15:30:59 2010 +0100 +++ b/app/main/contact/list.lua Mon Nov 08 15:41:14 2010 +0100 @@ -1,9 +1,105 @@ +local contacts_selector = Contact:build_selector{ + member_id = app.session.member_id, + order = "name" +} + + slot.put_into("title", _"Contacts") + util.help("contact.list") -execute.view{ - module = "contact", - view = "_list", - params = { contacts_selector = app.session.member:get_reference_selector("contacts") } + +ui.paginate{ + selector = contacts_selector, + content = function() + local contacts = contacts_selector:exec() + if #contacts == 0 then + ui.field.text{ value = _"You didn't saved any member as contact yet." } + else + ui.list{ + records = contacts, + columns = { + { + label = _"Name", + content = function(record) + ui.link{ + text = record.other_member.name, + module = "member", + view = "show", + id = record.other_member_id + } + end + }, + { + label = _"Published", + content = function(record) + ui.field.boolean{ value = record.public } + end + }, + { + content = function(record) + if record.public then + ui.link{ + attr = { class = "action" }, + text = _"Hide", + module = "contact", + action = "add_member", + id = record.other_member_id, + params = { public = false }, + 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 = "action" }, + text = _"Publish", + module = "contact", + action = "add_member", + id = record.other_member_id, + params = { public = true }, + routing = { + default = { + mode = "redirect", + module = request.get_module(), + view = request.get_view(), + id = param.get_id_cgi(), + params = param.get_all_cgi() + } + } + } + end + end + }, + { + content = function(record) + ui.link{ + attr = { class = "action" }, + text = _"Remove", + module = "contact", + action = "remove_member", + id = record.other_member_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 + end } diff -r c0835d707465 -r a9c6c11dd86c model/contact.lua --- a/model/contact.lua Mon Nov 08 15:30:59 2010 +0100 +++ b/model/contact.lua Mon Nov 08 15:41:14 2010 +0100 @@ -26,3 +26,18 @@ :optional_object_mode() :exec() end + +function Contact:build_selector(args) + local selector = Contact:new_selector() + if args.member_id then + selector:add_where{ "member_id = ?", args.member_id } + end + if order then + if order == "name" then + selector:add_order_by("name") + else + error("invalid order") + end + end + return selector +end