webmcp

diff framework/env/ui_deprecated/input.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/input.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +--
     1.5 +-- Creates an input field in a form
     1.6 +--
     1.7 +-- label      (string) The label of the input field
     1.8 +-- field      (string) The name of the record field
     1.9 +-- field_type (string) The type of the record field
    1.10 +--
    1.11 +-- Example:
    1.12 +--
    1.13 +--  ui_deprecated.input({
    1.14 +--    label = _'Comment',
    1.15 +--    field = 'comment', 
    1.16 +--    field_type = 'textarea'
    1.17 +--  })
    1.18 +--
    1.19 +local field_type_to_atom_class_map = {
    1.20 +  text       = atom.string,
    1.21 +  textarea   = atom.string,
    1.22 +  number     = atom.number,
    1.23 +  percentage = atom.number,
    1.24 +}
    1.25 +
    1.26 +function ui_deprecated.input(args)
    1.27 +  local record = assert(slot.get_state_table(), "ui_deprecated.input was not called within a form.").form_record
    1.28 +
    1.29 +  local field_type = args.field_type or "text"
    1.30 +
    1.31 +  local field_func = assert(ui_deprecated.input_field[field_type], "no field helper for given type '" .. field_type .. "'")
    1.32 +
    1.33 +  local html_name = args.name or args.field
    1.34 +  local field_html
    1.35 +
    1.36 +  if args.field then
    1.37 +    local param_type = field_type_to_atom_class_map[field_type] or error('Unkown field type')
    1.38 +    field_html = field_func{
    1.39 +      name  = html_name, 
    1.40 +      value = param.get(html_name, param_type) 
    1.41 +              or record[args.field],
    1.42 +      height = args.height,
    1.43 +    }
    1.44 +
    1.45 +  elseif args.value then
    1.46 +    field_html = field_func{
    1.47 +      name  = html_name, 
    1.48 +      value = args.value,
    1.49 +      height = args.height,
    1.50 +    }
    1.51 +  
    1.52 +  else
    1.53 +    field_html = field_func{
    1.54 +      name  = html_name, 
    1.55 +      value = '',
    1.56 +      height = args.height,
    1.57 +    }
    1.58 +    
    1.59 +  end
    1.60 +  
    1.61 +  slot.put('<div class="ui_field ui_input_', field_type, '">\n')
    1.62 +  if args.label then
    1.63 +    slot.put('<div class="label">', encode.html(args.label), '</div>\n')
    1.64 +  end
    1.65 +  slot.put('<div class="value">',
    1.66 +        field_html,
    1.67 +      '</div>\n',
    1.68 +    '</div>\n'
    1.69 +  )
    1.70 +end

Impressum / About Us