liquid_feedback_frontend

changeset 198:a9c6c11dd86c

Contact module refactored
author bsw
date Mon Nov 08 15:41:14 2010 +0100 (2010-11-08)
parents c0835d707465
children e60a26bf535b
files app/main/contact/_list.lua app/main/contact/list.lua model/contact.lua
line diff
     1.1 --- a/app/main/contact/_list.lua	Mon Nov 08 15:30:59 2010 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,99 +0,0 @@
     1.4 -
     1.5 -local contacts_selector = Contact:new_selector()
     1.6 -  :add_where{ "member_id = ?", app.session.member.id }
     1.7 -  :join("member", nil, "member.id = contact.other_member_id")
     1.8 -  :add_order_by("member.name")
     1.9 -
    1.10 -ui.paginate{
    1.11 -  selector = contacts_selector,
    1.12 -  content = function()
    1.13 -    local contacts = contacts_selector:exec()
    1.14 -    if #contacts == 0 then
    1.15 -      ui.field.text{ value = _"You didn't saved any member as contact yet." }
    1.16 -    else
    1.17 -      ui.list{
    1.18 -        records = contacts,
    1.19 -        columns = {
    1.20 -          {
    1.21 -            label = _"Name",
    1.22 -            content = function(record)
    1.23 -              ui.link{
    1.24 -                text = record.other_member.name,
    1.25 -                module = "member",
    1.26 -                view = "show",
    1.27 -                id = record.other_member_id
    1.28 -              }
    1.29 -            end
    1.30 -          },
    1.31 -          {
    1.32 -            label = _"Published",
    1.33 -            content = function(record)
    1.34 -              ui.field.boolean{ value = record.public }
    1.35 -            end
    1.36 -          },
    1.37 -          {
    1.38 -            content = function(record)
    1.39 -              if record.public then
    1.40 -                ui.link{
    1.41 -                  attr = { class = "action" },
    1.42 -                  text = _"Hide",
    1.43 -                  module = "contact",
    1.44 -                  action = "add_member",
    1.45 -                  id = record.other_member_id,
    1.46 -                  params = { public = false },
    1.47 -                  routing = {
    1.48 -                    default = {
    1.49 -                      mode = "redirect",
    1.50 -                      module = request.get_module(),
    1.51 -                      view = request.get_view(),
    1.52 -                      id = param.get_id_cgi(),
    1.53 -                      params = param.get_all_cgi()
    1.54 -                    }
    1.55 -                  }
    1.56 -                }
    1.57 -              else
    1.58 -                ui.link{
    1.59 -                  attr = { class = "action" },
    1.60 -                  text = _"Publish",
    1.61 -                  module = "contact",
    1.62 -                  action = "add_member",
    1.63 -                  id = record.other_member_id,
    1.64 -                  params = { public = true },
    1.65 -                  routing = {
    1.66 -                    default = {
    1.67 -                      mode = "redirect",
    1.68 -                      module = request.get_module(),
    1.69 -                      view = request.get_view(),
    1.70 -                      id = param.get_id_cgi(),
    1.71 -                      params = param.get_all_cgi()
    1.72 -                    }
    1.73 -                  }
    1.74 -                }
    1.75 -              end
    1.76 -            end
    1.77 -          },
    1.78 -          {
    1.79 -            content = function(record)
    1.80 -              ui.link{
    1.81 -                attr = { class = "action" },
    1.82 -                text = _"Remove",
    1.83 -                module = "contact",
    1.84 -                action = "remove_member",
    1.85 -                id = record.other_member_id,
    1.86 -                routing = {
    1.87 -                  default = {
    1.88 -                    mode = "redirect",
    1.89 -                    module = request.get_module(),
    1.90 -                    view = request.get_view(),
    1.91 -                    id = param.get_id_cgi(),
    1.92 -                    params = param.get_all_cgi()
    1.93 -                  }
    1.94 -                }
    1.95 -              }
    1.96 -            end
    1.97 -          },
    1.98 -        }
    1.99 -      }
   1.100 -    end
   1.101 -  end
   1.102 -}
     2.1 --- a/app/main/contact/list.lua	Mon Nov 08 15:30:59 2010 +0100
     2.2 +++ b/app/main/contact/list.lua	Mon Nov 08 15:41:14 2010 +0100
     2.3 @@ -1,9 +1,105 @@
     2.4 +local contacts_selector = Contact:build_selector{
     2.5 +  member_id = app.session.member_id,
     2.6 +  order = "name"
     2.7 +}
     2.8 +
     2.9 +
    2.10  slot.put_into("title", _"Contacts")
    2.11  
    2.12 +
    2.13  util.help("contact.list")
    2.14  
    2.15 -execute.view{
    2.16 -  module = "contact",
    2.17 -  view = "_list",
    2.18 -  params = { contacts_selector = app.session.member:get_reference_selector("contacts") }
    2.19 +
    2.20 +ui.paginate{
    2.21 +  selector = contacts_selector,
    2.22 +  content = function()
    2.23 +    local contacts = contacts_selector:exec()
    2.24 +    if #contacts == 0 then
    2.25 +      ui.field.text{ value = _"You didn't saved any member as contact yet." }
    2.26 +    else
    2.27 +      ui.list{
    2.28 +        records = contacts,
    2.29 +        columns = {
    2.30 +          {
    2.31 +            label = _"Name",
    2.32 +            content = function(record)
    2.33 +              ui.link{
    2.34 +                text = record.other_member.name,
    2.35 +                module = "member",
    2.36 +                view = "show",
    2.37 +                id = record.other_member_id
    2.38 +              }
    2.39 +            end
    2.40 +          },
    2.41 +          {
    2.42 +            label = _"Published",
    2.43 +            content = function(record)
    2.44 +              ui.field.boolean{ value = record.public }
    2.45 +            end
    2.46 +          },
    2.47 +          {
    2.48 +            content = function(record)
    2.49 +              if record.public then
    2.50 +                ui.link{
    2.51 +                  attr = { class = "action" },
    2.52 +                  text = _"Hide",
    2.53 +                  module = "contact",
    2.54 +                  action = "add_member",
    2.55 +                  id = record.other_member_id,
    2.56 +                  params = { public = false },
    2.57 +                  routing = {
    2.58 +                    default = {
    2.59 +                      mode = "redirect",
    2.60 +                      module = request.get_module(),
    2.61 +                      view = request.get_view(),
    2.62 +                      id = param.get_id_cgi(),
    2.63 +                      params = param.get_all_cgi()
    2.64 +                    }
    2.65 +                  }
    2.66 +                }
    2.67 +              else
    2.68 +                ui.link{
    2.69 +                  attr = { class = "action" },
    2.70 +                  text = _"Publish",
    2.71 +                  module = "contact",
    2.72 +                  action = "add_member",
    2.73 +                  id = record.other_member_id,
    2.74 +                  params = { public = true },
    2.75 +                  routing = {
    2.76 +                    default = {
    2.77 +                      mode = "redirect",
    2.78 +                      module = request.get_module(),
    2.79 +                      view = request.get_view(),
    2.80 +                      id = param.get_id_cgi(),
    2.81 +                      params = param.get_all_cgi()
    2.82 +                    }
    2.83 +                  }
    2.84 +                }
    2.85 +              end
    2.86 +            end
    2.87 +          },
    2.88 +          {
    2.89 +            content = function(record)
    2.90 +              ui.link{
    2.91 +                attr = { class = "action" },
    2.92 +                text = _"Remove",
    2.93 +                module = "contact",
    2.94 +                action = "remove_member",
    2.95 +                id = record.other_member_id,
    2.96 +                routing = {
    2.97 +                  default = {
    2.98 +                    mode = "redirect",
    2.99 +                    module = request.get_module(),
   2.100 +                    view = request.get_view(),
   2.101 +                    id = param.get_id_cgi(),
   2.102 +                    params = param.get_all_cgi()
   2.103 +                  }
   2.104 +                }
   2.105 +              }
   2.106 +            end
   2.107 +          },
   2.108 +        }
   2.109 +      }
   2.110 +    end
   2.111 +  end
   2.112  }
     3.1 --- a/model/contact.lua	Mon Nov 08 15:30:59 2010 +0100
     3.2 +++ b/model/contact.lua	Mon Nov 08 15:41:14 2010 +0100
     3.3 @@ -26,3 +26,18 @@
     3.4      :optional_object_mode()
     3.5      :exec()
     3.6  end
     3.7 +
     3.8 +function Contact:build_selector(args)
     3.9 +  local selector = Contact:new_selector()
    3.10 +  if args.member_id then
    3.11 +    selector:add_where{ "member_id = ?", args.member_id }
    3.12 +  end
    3.13 +  if order then
    3.14 +    if order == "name" then
    3.15 +      selector:add_order_by("name")
    3.16 +    else
    3.17 +      error("invalid order")
    3.18 +    end
    3.19 +  end
    3.20 +  return selector
    3.21 +end

Impressum / About Us