webmcp

diff framework/env/ui_deprecated/list.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/ui_deprecated/list.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,153 @@
     1.4 +--
     1.5 +-- Creates a list view of a collection
     1.6 +--
     1.7 +-- Example:
     1.8 +--
     1.9 +--   ui_deprecated.list({ 
    1.10 +--     label = 'Point table',
    1.11 +--     collection = mycollection,
    1.12 +--     type = 'table' -- 'table', 'ulli'
    1.13 +--     cols = {
    1.14 +--       { 
    1.15 +--         label = _'Id',
    1.16 +--         field = 'id',
    1.17 +--         width = 100,
    1.18 +--         link = { module = 'mymodule', view = 'show' },
    1.19 +--              sort = true,
    1.20 +--       },
    1.21 +--       {
    1.22 +--         label = _'Name',
    1.23 +--         field = 'name',
    1.24 +--         width = 200,
    1.25 +--         link = { module = 'mymodule', view = 'show' },
    1.26 +--              sort = true,
    1.27 +--       },
    1.28 +--      {
    1.29 +--        label = _'Points',
    1.30 +--        func = function(record)
    1.31 +--          return record.points_a + record.points_b + record.points_c
    1.32 +--        end,
    1.33 +--        width = 300
    1.34 +--      }
    1.35 +--     }
    1.36 +--   })
    1.37 +--
    1.38 +
    1.39 +function ui_deprecated.list(args)
    1.40 +  local args = args
    1.41 +  args.type = args.type or 'table'
    1.42 +  if args.label then
    1.43 +    slot.put('<div class="ui_list_label">' .. encode.html(args.label) .. '</div>\n')
    1.44 +  end
    1.45 +  if not args or not args.collection or not args.cols then
    1.46 +    error('No args for ui_deprecated.list_end')
    1.47 +  end
    1.48 +  if args.type == 'table' then
    1.49 +    slot.put('<table class="ui_list">')
    1.50 +    slot.put('<tr class="ui_list_head">')
    1.51 +  elseif args.type == 'ulli' then
    1.52 +    slot.put('<ul class="ui_list">')
    1.53 +    slot.put('<li class="ui_list_head">')
    1.54 +  end
    1.55 +  if args.type == 'table' then
    1.56 +  elseif args.type == 'ulli' then
    1.57 +  end
    1.58 +  for j, col in ipairs(args.cols) do
    1.59 +    class_string = ''
    1.60 +    if col.align then
    1.61 +      class_string = ' class="' .. col.align .. '"'
    1.62 +    end
    1.63 +    if args.type == 'table' then
    1.64 +      slot.put('<th style="width: ' .. col.width .. ';"' .. class_string ..'>')
    1.65 +      slot.put(ui_deprecated.box({ name = 'ui_list_col_value', content = encode.html(col.label) }) )
    1.66 +      slot.put('</th>')
    1.67 +    elseif args.type == 'ulli' then
    1.68 +      slot.put('<div style="width: ' .. col.width .. ';"' .. class_string ..'>')
    1.69 +      slot.put(ui_deprecated.box({ name = 'ui_list_col_value', content = encode.html(col.label) }) )
    1.70 +      slot.put('</div>')
    1.71 +    end
    1.72 +  end
    1.73 +  if args.type == 'table' then
    1.74 +    slot.put('</tr>')
    1.75 +  elseif args.type == 'ulli' then
    1.76 +    slot.put('<br style="clear: left;" />')
    1.77 +    slot.put('</li>')
    1.78 +  end
    1.79 +  for i, obj in ipairs(args.collection) do
    1.80 +    if args.type == 'table' then
    1.81 +      slot.put('<tr>')
    1.82 +    elseif args.type == 'ulli' then
    1.83 +      slot.put('<li>')
    1.84 +    end
    1.85 +    for j, col in ipairs(args.cols) do
    1.86 +      class_string = ''
    1.87 +      if col.align then
    1.88 +        class_string = ' class="ui_list_col_align_' .. col.align .. '"'
    1.89 +      end
    1.90 +      if args.type == 'table' then
    1.91 +        slot.put('<td' .. class_string ..'>')
    1.92 +      elseif args.type == 'ulli' then
    1.93 +        slot.put('<div style="width: ' .. col.width .. ';"' .. class_string ..'>')
    1.94 +      end
    1.95 +      if col.link then
    1.96 +        local params = {}
    1.97 +        if col.link then
    1.98 +          params = col.link.params or {}
    1.99 +        end
   1.100 +        if col.link_values then
   1.101 +          for key, field in pairs(col.link_values) do
   1.102 +            params[key] = obj[field]
   1.103 +          end
   1.104 +        end
   1.105 +        local id
   1.106 +        if col.link_id_field then
   1.107 +          id = obj[col.link_id_field]
   1.108 +        end
   1.109 +        local value
   1.110 +        if col.value then
   1.111 +          value = col.value
   1.112 +        else
   1.113 +          value = obj[col.field]
   1.114 +        end
   1.115 +        ui_deprecated.link{
   1.116 +          label  = convert.to_human(value),
   1.117 +          module = col.link.module,
   1.118 +          view   = col.link.view,
   1.119 +          id     = id,
   1.120 +          params = params,
   1.121 +        }
   1.122 +      elseif col.link_func then
   1.123 +        local link = col.link_func(obj)
   1.124 +        if link then
   1.125 +	      ui_deprecated.link(link)
   1.126 +	    end
   1.127 +      else
   1.128 +        local text
   1.129 +        if col.func then
   1.130 +          text = col.func(obj)
   1.131 +        elseif col.value then
   1.132 +          text = convert.to_human(value)
   1.133 +        else
   1.134 +          text = convert.to_human(obj[col.field])
   1.135 +        end
   1.136 +        ui_deprecated.box{ name = 'ui_list_col_value', content = text }
   1.137 +      end
   1.138 +      if args.type == 'table' then
   1.139 +        slot.put('</td>')
   1.140 +      elseif args.type == 'ulli' then
   1.141 +        slot.put('</div>')
   1.142 +      end
   1.143 +    end
   1.144 +    if args.type == 'table' then
   1.145 +      slot.put('</tr>')
   1.146 +    elseif args.type == 'ulli' then
   1.147 +      slot.put('<br style="clear: left;" />')
   1.148 +      slot.put('</li>')
   1.149 +    end
   1.150 +  end
   1.151 +  if args.type == 'table' then
   1.152 +    slot.put('</table>')
   1.153 +  elseif args.type == 'ulli' then
   1.154 +    slot.put('</ul><div style="clear: left">&nbsp;</div>')
   1.155 +  end
   1.156 +end
   1.157 \ No newline at end of file

Impressum / About Us