jbe/bsw@0: -- jbe/bsw@0: -- Creates a list view of a collection jbe/bsw@0: -- jbe/bsw@0: -- Example: jbe/bsw@0: -- jbe/bsw@0: -- ui_deprecated.list({ jbe/bsw@0: -- label = 'Point table', jbe/bsw@0: -- collection = mycollection, jbe/bsw@0: -- type = 'table' -- 'table', 'ulli' jbe/bsw@0: -- cols = { jbe/bsw@0: -- { jbe/bsw@0: -- label = _'Id', jbe/bsw@0: -- field = 'id', jbe/bsw@0: -- width = 100, jbe/bsw@0: -- link = { module = 'mymodule', view = 'show' }, jbe/bsw@0: -- sort = true, jbe/bsw@0: -- }, jbe/bsw@0: -- { jbe/bsw@0: -- label = _'Name', jbe/bsw@0: -- field = 'name', jbe/bsw@0: -- width = 200, jbe/bsw@0: -- link = { module = 'mymodule', view = 'show' }, jbe/bsw@0: -- sort = true, jbe/bsw@0: -- }, jbe/bsw@0: -- { jbe/bsw@0: -- label = _'Points', jbe/bsw@0: -- func = function(record) jbe/bsw@0: -- return record.points_a + record.points_b + record.points_c jbe/bsw@0: -- end, jbe/bsw@0: -- width = 300 jbe/bsw@0: -- } jbe/bsw@0: -- } jbe/bsw@0: -- }) jbe/bsw@0: -- jbe/bsw@0: jbe/bsw@0: function ui_deprecated.list(args) jbe/bsw@0: local args = args jbe/bsw@0: args.type = args.type or 'table' jbe/bsw@0: if args.label then jbe/bsw@0: slot.put('
') jbe/bsw@0: slot.put(ui_deprecated.box({ name = 'ui_list_col_value', content = encode.html(col.label) }) ) jbe/bsw@0: slot.put(' | ') jbe/bsw@0: elseif args.type == 'ulli' then jbe/bsw@0: slot.put('
---|
')
jbe/bsw@0: elseif args.type == 'ulli' then
jbe/bsw@0: slot.put(' ')
jbe/bsw@0: end
jbe/bsw@0: if col.link then
jbe/bsw@0: local params = {}
jbe/bsw@0: if col.link then
jbe/bsw@0: params = col.link.params or {}
jbe/bsw@0: end
jbe/bsw@0: if col.link_values then
jbe/bsw@0: for key, field in pairs(col.link_values) do
jbe/bsw@0: params[key] = obj[field]
jbe/bsw@0: end
jbe/bsw@0: end
jbe/bsw@0: local id
jbe/bsw@0: if col.link_id_field then
jbe/bsw@0: id = obj[col.link_id_field]
jbe/bsw@0: end
jbe/bsw@0: local value
jbe/bsw@0: if col.value then
jbe/bsw@0: value = col.value
jbe/bsw@0: else
jbe/bsw@0: value = obj[col.field]
jbe/bsw@0: end
jbe/bsw@0: ui_deprecated.link{
jbe/bsw@0: label = convert.to_human(value),
jbe/bsw@0: module = col.link.module,
jbe/bsw@0: view = col.link.view,
jbe/bsw@0: id = id,
jbe/bsw@0: params = params,
jbe/bsw@0: }
jbe/bsw@0: elseif col.link_func then
jbe/bsw@0: local link = col.link_func(obj)
jbe/bsw@0: if link then
jbe/bsw@0: ui_deprecated.link(link)
jbe/bsw@0: end
jbe/bsw@0: else
jbe/bsw@0: local text
jbe/bsw@0: if col.func then
jbe/bsw@0: text = col.func(obj)
jbe/bsw@0: elseif col.value then
jbe/bsw@0: text = convert.to_human(value)
jbe/bsw@0: else
jbe/bsw@0: text = convert.to_human(obj[col.field])
jbe/bsw@0: end
jbe/bsw@0: ui_deprecated.box{ name = 'ui_list_col_value', content = text }
jbe/bsw@0: end
jbe/bsw@0: if args.type == 'table' then
jbe/bsw@0: slot.put(' | ')
jbe/bsw@0: elseif args.type == 'ulli' then
jbe/bsw@0: slot.put('')
jbe/bsw@0: end
jbe/bsw@0: end
jbe/bsw@0: if args.type == 'table' then
jbe/bsw@0: slot.put('