webmcp
annotate framework/env/ui_deprecated/list.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
author | jbe/bsw |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
parents | 9fdfb27f8e67 |
children |
rev | line source |
---|---|
jbe/bsw@0 | 1 -- |
jbe/bsw@0 | 2 -- Creates a list view of a collection |
jbe/bsw@0 | 3 -- |
jbe/bsw@0 | 4 -- Example: |
jbe/bsw@0 | 5 -- |
jbe/bsw@0 | 6 -- ui_deprecated.list({ |
jbe/bsw@0 | 7 -- label = 'Point table', |
jbe/bsw@0 | 8 -- collection = mycollection, |
jbe/bsw@0 | 9 -- type = 'table' -- 'table', 'ulli' |
jbe/bsw@0 | 10 -- cols = { |
jbe/bsw@0 | 11 -- { |
jbe/bsw@0 | 12 -- label = _'Id', |
jbe/bsw@0 | 13 -- field = 'id', |
jbe/bsw@0 | 14 -- width = 100, |
jbe/bsw@0 | 15 -- link = { module = 'mymodule', view = 'show' }, |
jbe/bsw@0 | 16 -- sort = true, |
jbe/bsw@0 | 17 -- }, |
jbe/bsw@0 | 18 -- { |
jbe/bsw@0 | 19 -- label = _'Name', |
jbe/bsw@0 | 20 -- field = 'name', |
jbe/bsw@0 | 21 -- width = 200, |
jbe/bsw@0 | 22 -- link = { module = 'mymodule', view = 'show' }, |
jbe/bsw@0 | 23 -- sort = true, |
jbe/bsw@0 | 24 -- }, |
jbe/bsw@0 | 25 -- { |
jbe/bsw@0 | 26 -- label = _'Points', |
jbe/bsw@0 | 27 -- func = function(record) |
jbe/bsw@0 | 28 -- return record.points_a + record.points_b + record.points_c |
jbe/bsw@0 | 29 -- end, |
jbe/bsw@0 | 30 -- width = 300 |
jbe/bsw@0 | 31 -- } |
jbe/bsw@0 | 32 -- } |
jbe/bsw@0 | 33 -- }) |
jbe/bsw@0 | 34 -- |
jbe/bsw@0 | 35 |
jbe/bsw@0 | 36 function ui_deprecated.list(args) |
jbe/bsw@0 | 37 local args = args |
jbe/bsw@0 | 38 args.type = args.type or 'table' |
jbe/bsw@0 | 39 if args.label then |
jbe/bsw@0 | 40 slot.put('<div class="ui_list_label">' .. encode.html(args.label) .. '</div>\n') |
jbe/bsw@0 | 41 end |
jbe/bsw@0 | 42 if not args or not args.collection or not args.cols then |
jbe/bsw@0 | 43 error('No args for ui_deprecated.list_end') |
jbe/bsw@0 | 44 end |
jbe/bsw@0 | 45 if args.type == 'table' then |
jbe/bsw@0 | 46 slot.put('<table class="ui_list">') |
jbe/bsw@0 | 47 slot.put('<tr class="ui_list_head">') |
jbe/bsw@0 | 48 elseif args.type == 'ulli' then |
jbe/bsw@0 | 49 slot.put('<ul class="ui_list">') |
jbe/bsw@0 | 50 slot.put('<li class="ui_list_head">') |
jbe/bsw@0 | 51 end |
jbe/bsw@0 | 52 if args.type == 'table' then |
jbe/bsw@0 | 53 elseif args.type == 'ulli' then |
jbe/bsw@0 | 54 end |
jbe/bsw@0 | 55 for j, col in ipairs(args.cols) do |
jbe/bsw@0 | 56 class_string = '' |
jbe/bsw@0 | 57 if col.align then |
jbe/bsw@0 | 58 class_string = ' class="' .. col.align .. '"' |
jbe/bsw@0 | 59 end |
jbe/bsw@0 | 60 if args.type == 'table' then |
jbe/bsw@0 | 61 slot.put('<th style="width: ' .. col.width .. ';"' .. class_string ..'>') |
jbe/bsw@0 | 62 slot.put(ui_deprecated.box({ name = 'ui_list_col_value', content = encode.html(col.label) }) ) |
jbe/bsw@0 | 63 slot.put('</th>') |
jbe/bsw@0 | 64 elseif args.type == 'ulli' then |
jbe/bsw@0 | 65 slot.put('<div style="width: ' .. col.width .. ';"' .. class_string ..'>') |
jbe/bsw@0 | 66 slot.put(ui_deprecated.box({ name = 'ui_list_col_value', content = encode.html(col.label) }) ) |
jbe/bsw@0 | 67 slot.put('</div>') |
jbe/bsw@0 | 68 end |
jbe/bsw@0 | 69 end |
jbe/bsw@0 | 70 if args.type == 'table' then |
jbe/bsw@0 | 71 slot.put('</tr>') |
jbe/bsw@0 | 72 elseif args.type == 'ulli' then |
jbe/bsw@0 | 73 slot.put('<br style="clear: left;" />') |
jbe/bsw@0 | 74 slot.put('</li>') |
jbe/bsw@0 | 75 end |
jbe/bsw@0 | 76 for i, obj in ipairs(args.collection) do |
jbe/bsw@0 | 77 if args.type == 'table' then |
jbe/bsw@0 | 78 slot.put('<tr>') |
jbe/bsw@0 | 79 elseif args.type == 'ulli' then |
jbe/bsw@0 | 80 slot.put('<li>') |
jbe/bsw@0 | 81 end |
jbe/bsw@0 | 82 for j, col in ipairs(args.cols) do |
jbe/bsw@0 | 83 class_string = '' |
jbe/bsw@0 | 84 if col.align then |
jbe/bsw@0 | 85 class_string = ' class="ui_list_col_align_' .. col.align .. '"' |
jbe/bsw@0 | 86 end |
jbe/bsw@0 | 87 if args.type == 'table' then |
jbe/bsw@0 | 88 slot.put('<td' .. class_string ..'>') |
jbe/bsw@0 | 89 elseif args.type == 'ulli' then |
jbe/bsw@0 | 90 slot.put('<div style="width: ' .. col.width .. ';"' .. class_string ..'>') |
jbe/bsw@0 | 91 end |
jbe/bsw@0 | 92 if col.link then |
jbe/bsw@0 | 93 local params = {} |
jbe/bsw@0 | 94 if col.link then |
jbe/bsw@0 | 95 params = col.link.params or {} |
jbe/bsw@0 | 96 end |
jbe/bsw@0 | 97 if col.link_values then |
jbe/bsw@0 | 98 for key, field in pairs(col.link_values) do |
jbe/bsw@0 | 99 params[key] = obj[field] |
jbe/bsw@0 | 100 end |
jbe/bsw@0 | 101 end |
jbe/bsw@0 | 102 local id |
jbe/bsw@0 | 103 if col.link_id_field then |
jbe/bsw@0 | 104 id = obj[col.link_id_field] |
jbe/bsw@0 | 105 end |
jbe/bsw@0 | 106 local value |
jbe/bsw@0 | 107 if col.value then |
jbe/bsw@0 | 108 value = col.value |
jbe/bsw@0 | 109 else |
jbe/bsw@0 | 110 value = obj[col.field] |
jbe/bsw@0 | 111 end |
jbe/bsw@0 | 112 ui_deprecated.link{ |
jbe/bsw@0 | 113 label = convert.to_human(value), |
jbe/bsw@0 | 114 module = col.link.module, |
jbe/bsw@0 | 115 view = col.link.view, |
jbe/bsw@0 | 116 id = id, |
jbe/bsw@0 | 117 params = params, |
jbe/bsw@0 | 118 } |
jbe/bsw@0 | 119 elseif col.link_func then |
jbe/bsw@0 | 120 local link = col.link_func(obj) |
jbe/bsw@0 | 121 if link then |
jbe/bsw@0 | 122 ui_deprecated.link(link) |
jbe/bsw@0 | 123 end |
jbe/bsw@0 | 124 else |
jbe/bsw@0 | 125 local text |
jbe/bsw@0 | 126 if col.func then |
jbe/bsw@0 | 127 text = col.func(obj) |
jbe/bsw@0 | 128 elseif col.value then |
jbe/bsw@0 | 129 text = convert.to_human(value) |
jbe/bsw@0 | 130 else |
jbe/bsw@0 | 131 text = convert.to_human(obj[col.field]) |
jbe/bsw@0 | 132 end |
jbe/bsw@0 | 133 ui_deprecated.box{ name = 'ui_list_col_value', content = text } |
jbe/bsw@0 | 134 end |
jbe/bsw@0 | 135 if args.type == 'table' then |
jbe/bsw@0 | 136 slot.put('</td>') |
jbe/bsw@0 | 137 elseif args.type == 'ulli' then |
jbe/bsw@0 | 138 slot.put('</div>') |
jbe/bsw@0 | 139 end |
jbe/bsw@0 | 140 end |
jbe/bsw@0 | 141 if args.type == 'table' then |
jbe/bsw@0 | 142 slot.put('</tr>') |
jbe/bsw@0 | 143 elseif args.type == 'ulli' then |
jbe/bsw@0 | 144 slot.put('<br style="clear: left;" />') |
jbe/bsw@0 | 145 slot.put('</li>') |
jbe/bsw@0 | 146 end |
jbe/bsw@0 | 147 end |
jbe/bsw@0 | 148 if args.type == 'table' then |
jbe/bsw@0 | 149 slot.put('</table>') |
jbe/bsw@0 | 150 elseif args.type == 'ulli' then |
jbe/bsw@0 | 151 slot.put('</ul><div style="clear: left"> </div>') |
jbe/bsw@0 | 152 end |
jbe/bsw@0 | 153 end |