webmcp
annotate framework/env/ui_deprecated/form.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 |
| rev | line source |
|---|---|
| jbe/bsw@0 | 1 -- |
| jbe/bsw@0 | 2 -- Creates a formular |
| jbe/bsw@0 | 3 -- |
| jbe/bsw@0 | 4 -- record (record) Take field values from this object (optional) |
| jbe/bsw@0 | 5 -- class (string) Style class (optional) |
| jbe/bsw@0 | 6 -- method (string) Submit method ['post', 'get'] (optional) |
| jbe/bsw@0 | 7 -- module (string) The module to submit to |
| jbe/bsw@0 | 8 -- action (string) The action to submit to |
| jbe/bsw@0 | 9 -- params (table) The GET parameter to be send with |
| jbe/bsw@0 | 10 -- content (function) Function for the content of the form |
| jbe/bsw@0 | 11 -- |
| jbe/bsw@0 | 12 -- Example: |
| jbe/bsw@0 | 13 -- |
| jbe/bsw@0 | 14 -- ui_deprecated.form({ |
| jbe/bsw@0 | 15 -- object = client, |
| jbe/bsw@0 | 16 -- class = 'form_class', |
| jbe/bsw@0 | 17 -- method = 'post', |
| jbe/bsw@0 | 18 -- module = 'client', |
| jbe/bsw@0 | 19 -- action = 'update', |
| jbe/bsw@0 | 20 -- params = { |
| jbe/bsw@0 | 21 -- id = client.id |
| jbe/bsw@0 | 22 -- }, |
| jbe/bsw@0 | 23 -- redirect_to = { |
| jbe/bsw@0 | 24 -- ok = { |
| jbe/bsw@0 | 25 -- module = 'client', |
| jbe/bsw@0 | 26 -- view = 'list' |
| jbe/bsw@0 | 27 -- }, |
| jbe/bsw@0 | 28 -- error = { |
| jbe/bsw@0 | 29 -- module = 'client', |
| jbe/bsw@0 | 30 -- view = 'edit', |
| jbe/bsw@0 | 31 -- params = { |
| jbe/bsw@0 | 32 -- id = client.id |
| jbe/bsw@0 | 33 -- } |
| jbe/bsw@0 | 34 -- } |
| jbe/bsw@0 | 35 -- }, |
| jbe/bsw@0 | 36 -- }) |
| jbe/bsw@0 | 37 |
| jbe/bsw@0 | 38 function ui_deprecated.form(args) |
| jbe/bsw@0 | 39 local slot_state = slot.get_state_table() |
| jbe/bsw@0 | 40 if slot_state.form_opened then |
| jbe/bsw@0 | 41 error("Cannot open a form inside a form.") |
| jbe/bsw@0 | 42 end |
| jbe/bsw@0 | 43 slot_state.form_opened = true |
| jbe/bsw@0 | 44 local old_record = slot_state.form_record |
| jbe/bsw@0 | 45 slot_state.form_record = args.record or {} -- TODO: decide what really should happen when no record is specified |
| jbe/bsw@0 | 46 |
| jbe/bsw@0 | 47 local params = {} |
| jbe/bsw@0 | 48 if args.params then |
| jbe/bsw@0 | 49 for key, value in pairs(args.params) do |
| jbe/bsw@0 | 50 params[key] = value |
| jbe/bsw@0 | 51 end |
| jbe/bsw@0 | 52 end |
| jbe/bsw@0 | 53 ui_deprecated._prepare_redirect_params(params, args.redirect_to) |
| jbe/bsw@0 | 54 |
| jbe/bsw@0 | 55 local attr_action = args.url or encode.url{ |
| jbe/bsw@0 | 56 module = args.module, |
| jbe/bsw@0 | 57 view = args.view, |
| jbe/bsw@0 | 58 action = args.action, |
| jbe/bsw@0 | 59 id = args.id, |
| jbe/bsw@0 | 60 params = params |
| jbe/bsw@0 | 61 } |
| jbe/bsw@0 | 62 |
| jbe/bsw@0 | 63 local base = request.get_relative_baseurl() |
| jbe/bsw@0 | 64 local attr_class = table.concat({ 'ui_form', args.class }, ' ') |
| jbe/bsw@0 | 65 local attr_method = args.method or 'POST' -- TODO: uppercase/sanatize method |
| jbe/bsw@0 | 66 |
| jbe/bsw@0 | 67 slot.put( |
| jbe/bsw@0 | 68 '<form', |
| jbe/bsw@0 | 69 ' action="', attr_action, '"', |
| jbe/bsw@0 | 70 ' class="', attr_class, '"', |
| jbe/bsw@0 | 71 ' method="', attr_method, '"', |
| jbe/bsw@0 | 72 '>\n' |
| jbe/bsw@0 | 73 ) |
| jbe/bsw@0 | 74 |
| jbe/bsw@0 | 75 if type(args.content) == 'function' then |
| jbe/bsw@0 | 76 args.content() |
| jbe/bsw@0 | 77 else |
| jbe/bsw@0 | 78 error('No content function') |
| jbe/bsw@0 | 79 end |
| jbe/bsw@0 | 80 |
| jbe/bsw@0 | 81 slot.put('</form>') |
| jbe/bsw@0 | 82 slot_state.form_record = old_record |
| jbe/bsw@0 | 83 slot_state.form_opened = false |
| jbe/bsw@0 | 84 |
| jbe/bsw@0 | 85 end |