webmcp
view framework/env/ui_deprecated/multiselect.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 | 
 line source
     1 function ui_deprecated.multiselect(args)
     2   local record = assert(slot.get_state_table(), "ui_deprecated.multiselect was not called within a form.").form_record
     3   local name = args.name
     4   local relationship = args.relationship
     6   local foreign_records = relationship.foreign_records
     8   local selector = relationship.connected_by_model:new_selector()
     9   selector:add_where{ relationship.connected_by_my_id .. ' = ?', record[relationship.my_id] }
    10   local connected_by_records = selector:exec()
    12   local connections = {}
    13   for i, connected_by_record in ipairs(connected_by_records) do
    14     connections[connected_by_record[relationship.connected_by_foreign_id]] = connected_by_record
    15   end
    17   local html = {}
    19   if args.type == "checkboxes" then
    20     for i, foreign_record in ipairs(foreign_records) do
    21       local selected = ''
    22       if connections[foreign_record[relationship.foreign_id]] then
    23         selected = ' checked="1"'
    24       end
    25       html[#html + 1] = '<input type="checkbox" name="' .. name .. '" value="' .. foreign_record[relationship.foreign_id] .. '"' .. selected .. '> ' .. convert.to_human(foreign_record[relationship.foreign_name], "string") .. '<br />\n'
    26     end
    28   else
    29     html[#html + 1] = '<select name="' .. name .. '" multiple="1">'
    30     for i, foreign_record in ipairs(foreign_records) do
    31       local selected = ''
    32       if connections[foreign_record[relationship.foreign_id]] then
    33         selected = ' selected="1"'
    34       end
    35       html[#html + 1] = '<option value="' .. foreign_record[relationship.foreign_id] .. '"' .. selected .. '>' .. convert.to_human(foreign_record[relationship.foreign_name], "string") .. '</option>\n'
    36     end
    37     html[#html + 1] = '</select>'
    39   end
    41   slot.put('<div class="ui_field ui_multiselect">\n')
    42   if args.label then
    43     slot.put('<div class="label">', encode.html(args.label), '</div>\n')
    44   end
    45   slot.put('<div class="value">',
    46         table.concat(html),
    47       '</div>\n',
    48     '</div>\n'
    49   )
    50 end
