webmcp
annotate framework/env/ui/field/date.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 |
rev | line source |
---|---|
jbe/bsw@0 | 1 --[[-- |
jbe/bsw@0 | 2 ui.field.date{ |
jbe/bsw@0 | 3 ... -- generic ui.field.* arguments, as described for ui.autofield{...} |
jbe/bsw@0 | 4 } |
jbe/bsw@0 | 5 |
jbe/bsw@0 | 6 This function inserts a field for dates in the active slot. If the JavaScript library "gregor.js" has been loaded, a rich input field is used. For description of the generic field helper arguments, see help for ui.autofield{...}. |
jbe/bsw@0 | 7 |
jbe/bsw@0 | 8 --]]-- |
jbe/bsw@0 | 9 |
jbe/bsw@0 | 10 function ui.field.date(args) |
jbe/bsw@0 | 11 ui.form_element(args, {fetch_value = true}, function(args) |
jbe/bsw@0 | 12 local value_string = format.date(args.value, args.format_options) |
jbe/bsw@0 | 13 if args.readonly then |
jbe/bsw@0 | 14 ui.tag{ tag = args.tag, attr = args.attr, content = value_string } |
jbe/bsw@0 | 15 else |
jbe/bsw@0 | 16 local fallback_data = slot.use_temporary(function() |
jbe/bsw@0 | 17 local attr = table.new(args.attr) |
jbe/bsw@0 | 18 attr.type = "text" |
jbe/bsw@0 | 19 attr.name = args.html_name |
jbe/bsw@0 | 20 attr.value = value_string |
jbe/bsw@0 | 21 attr.class = attr.class or "ui_field_date" |
jbe/bsw@0 | 22 ui.tag{ tag = "input", attr = attr } |
jbe/bsw@0 | 23 ui.hidden_field{ |
jbe/bsw@0 | 24 name = args.html_name .. "__format", |
jbe/bsw@0 | 25 value = encode.format_info("date", args.format_options) |
jbe/bsw@0 | 26 } |
jbe/bsw@0 | 27 end) |
jbe/bsw@0 | 28 local user_field_id, hidden_field_id |
jbe/bsw@0 | 29 local helper_data = slot.use_temporary(function() |
jbe/bsw@0 | 30 local attr = table.new(args.attr) |
jbe/bsw@0 | 31 user_field_id = attr.id or ui.create_unique_id() |
jbe/bsw@0 | 32 hidden_field_id = ui.create_unique_id() |
jbe/bsw@0 | 33 attr.id = user_field_id |
jbe/bsw@0 | 34 attr.type = "text" |
jbe/bsw@0 | 35 attr.class = attr.class or "ui_field_date" |
jbe/bsw@0 | 36 ui.tag{ tag = "input", attr = attr } |
jbe/bsw@0 | 37 local attr = table.new(args.attr) |
jbe/bsw@0 | 38 attr.id = hidden_field_id |
jbe/bsw@0 | 39 attr.type = "hidden" |
jbe/bsw@0 | 40 attr.name = args.html_name |
jbe/bsw@0 | 41 attr.value = atom.dump(args.value) -- extra safety for JS failure |
jbe/bsw@0 | 42 ui.tag{ |
jbe/bsw@0 | 43 tag = "input", |
jbe/bsw@0 | 44 attr = { |
jbe/bsw@0 | 45 id = hidden_field_id, |
jbe/bsw@0 | 46 type = "hidden", |
jbe/bsw@0 | 47 name = args.html_name |
jbe/bsw@0 | 48 } |
jbe/bsw@0 | 49 } |
jbe/bsw@0 | 50 end) |
jbe/bsw@0 | 51 -- TODO: localization |
jbe/bsw@0 | 52 ui.script{ |
jbe/bsw@0 | 53 noscript = fallback_data, |
jbe/bsw@0 | 54 type = "text/javascript", |
jbe/bsw@0 | 55 content = function() |
jbe/bsw@0 | 56 slot.put( |
jbe/bsw@0 | 57 "if (gregor_addGui == null) document.write(", |
jbe/bsw@0 | 58 encode.json(fallback_data), |
jbe/bsw@0 | 59 "); else { document.write(", |
jbe/bsw@0 | 60 encode.json(helper_data), |
jbe/bsw@0 | 61 "); gregor_addGui({element_id: ", |
jbe/bsw@0 | 62 encode.json(user_field_id), |
jbe/bsw@0 | 63 ", month_names: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], weekday_names: ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'], week_numbers: 'left', format: 'DD.MM.YYYY', selected: " |
jbe/bsw@0 | 64 ) |
jbe/bsw@0 | 65 if (args.value) then |
jbe/bsw@0 | 66 slot.put( |
jbe/bsw@0 | 67 "{year: ", tostring(args.value.year), |
jbe/bsw@0 | 68 ", month: ", tostring(args.value.month), |
jbe/bsw@0 | 69 ", day: ", tostring(args.value.day), |
jbe/bsw@0 | 70 "}" |
jbe/bsw@0 | 71 ) |
jbe/bsw@0 | 72 else |
jbe/bsw@0 | 73 slot.put("null") |
jbe/bsw@0 | 74 end |
jbe/bsw@0 | 75 slot.put( |
jbe/bsw@0 | 76 ", select_callback: function(date) { document.getElementById(", |
jbe/bsw@0 | 77 encode.json(hidden_field_id), |
jbe/bsw@0 | 78 ").value = (date == null) ? '' : date.iso_string; } } ) }" |
jbe/bsw@0 | 79 ) |
jbe/bsw@0 | 80 end |
jbe/bsw@0 | 81 } |
jbe/bsw@0 | 82 end |
jbe/bsw@0 | 83 end) |
jbe/bsw@0 | 84 end |