webmcp
annotate framework/env/ui/form_element.lua @ 1:985024b16520
Version 1.0.1
New feature: JSON requests
Changes in ui.paginate: Current page setting is directly fetched from CGI params, instead of view params
Changed behavior of load methods of atom library to accept nil as input
Bugfixes in mondelefant_atom_connector timestamp(tz) loaders
Added global constant _WEBMCP_VERSION containing a version string
New feature: JSON requests
Changes in ui.paginate: Current page setting is directly fetched from CGI params, instead of view params
Changed behavior of load methods of atom library to accept nil as input
Bugfixes in mondelefant_atom_connector timestamp(tz) loaders
Added global constant _WEBMCP_VERSION containing a version string
author | jbe |
---|---|
date | Tue Nov 17 12:00:00 2009 +0100 (2009-11-17) |
parents | 9fdfb27f8e67 |
children | 993fbee179ae |
rev | line source |
---|---|
jbe/bsw@0 | 1 --[[-- |
jbe/bsw@0 | 2 ui.form_element( |
jbe/bsw@0 | 3 args, -- external arguments |
jbe/bsw@0 | 4 { -- options for this function call |
jbe/bsw@0 | 5 fetch_value = fetch_value_flag, -- true causes automatic determination of args.value, if nil |
jbe/bsw@0 | 6 fetch_record = fetch_record_flag, -- true causes automatic determination of args.record, if nil |
jbe/bsw@0 | 7 disable_label_for_id = disable_label_for_id_flag, -- true suppresses automatic setting of args.attr.id for a HTML label_for reference |
jbe/bsw@0 | 8 }, |
jbe/bsw@0 | 9 function(args) |
jbe/bsw@0 | 10 ... -- program code |
jbe/bsw@0 | 11 end |
jbe/bsw@0 | 12 ) |
jbe/bsw@0 | 13 |
jbe/bsw@0 | 14 This function helps other form helpers by preprocessing arguments passed to the helper, e.g. fetching a value from a record stored in a state-table of the currently active slot. |
jbe/bsw@0 | 15 |
jbe/bsw@0 | 16 --]]-- |
jbe/bsw@0 | 17 |
jbe/bsw@0 | 18 -- TODO: better documentation |
jbe/bsw@0 | 19 |
jbe/bsw@0 | 20 function ui.form_element(args, extra_args, func) |
jbe/bsw@0 | 21 local args = table.new(args) |
jbe/bsw@0 | 22 if extra_args then |
jbe/bsw@0 | 23 for key, value in pairs(extra_args) do |
jbe/bsw@0 | 24 args[key] = value |
jbe/bsw@0 | 25 end |
jbe/bsw@0 | 26 end |
jbe/bsw@0 | 27 local slot_state = slot.get_state_table() |
jbe/bsw@0 | 28 args.html_name = args.html_name or args.name |
jbe/bsw@0 | 29 if args.fetch_value then |
jbe/bsw@0 | 30 if args.value == nil then |
jbe/bsw@0 | 31 if not args.record and slot_state then |
jbe/bsw@0 | 32 args.record = slot_state.form_record |
jbe/bsw@0 | 33 end |
jbe/bsw@0 | 34 if args.record then |
jbe/bsw@0 | 35 args.value = args.record[args.name] |
jbe/bsw@0 | 36 end |
jbe/bsw@0 | 37 else |
jbe/bsw@0 | 38 args.value = nihil.lower(args.value) |
jbe/bsw@0 | 39 end |
jbe/bsw@0 | 40 elseif args.fetch_record then |
jbe/bsw@0 | 41 if not args.record and slot_state then |
jbe/bsw@0 | 42 args.record = slot_state.form_record |
jbe/bsw@0 | 43 end |
jbe/bsw@0 | 44 end |
jbe/bsw@0 | 45 if |
jbe/bsw@0 | 46 args.html_name and |
jbe/bsw@0 | 47 not args.readonly and |
jbe/bsw@0 | 48 slot_state.form_readonly == false |
jbe/bsw@0 | 49 then |
jbe/bsw@0 | 50 args.readonly = false |
jbe/bsw@0 | 51 local prefix |
jbe/bsw@0 | 52 if args.html_name_prefix == nil then |
jbe/bsw@0 | 53 prefix = slot_state.html_name_prefix |
jbe/bsw@0 | 54 else |
jbe/bsw@0 | 55 prefix = args.html_name_prefix |
jbe/bsw@0 | 56 end |
jbe/bsw@0 | 57 if prefix then |
jbe/bsw@0 | 58 args.html_name = prefix .. args.html_name |
jbe/bsw@0 | 59 end |
jbe/bsw@0 | 60 else |
jbe/bsw@0 | 61 args.readonly = true |
jbe/bsw@0 | 62 end |
jbe/bsw@0 | 63 if args.label then |
jbe/bsw@0 | 64 if not args.disable_label_for_id then |
jbe/bsw@0 | 65 if not args.attr then |
jbe/bsw@0 | 66 args.attr = { id = ui.create_unique_id() } |
jbe/bsw@0 | 67 elseif not args.attr.id then |
jbe/bsw@0 | 68 args.attr.id = ui.create_unique_id() |
jbe/bsw@0 | 69 end |
jbe/bsw@0 | 70 end |
jbe/bsw@0 | 71 if not args.label_attr then |
jbe/bsw@0 | 72 args.label_attr = { class = "ui_field_label" } |
jbe/bsw@0 | 73 elseif not args.label_attr.class then |
jbe/bsw@0 | 74 args.label_attr.class = "ui_field_label" |
jbe/bsw@0 | 75 end |
jbe/bsw@0 | 76 end |
jbe/bsw@0 | 77 ui.container{ |
jbe/bsw@0 | 78 auto_args = args, |
jbe/bsw@0 | 79 content = function() return func(args) end |
jbe/bsw@0 | 80 } |
jbe/bsw@0 | 81 end |