webmcp
annotate framework/env/ui/_partial_load_js.lua @ 11:d76a8857ba62
Added ui.partial and other functions, which allow partial content replacement using XMLHttpRequests; Image support for ui.link
Also includes following changes:
- Fix for rocketcgi library to accept POST data content-types, which contain additional charset information.
- Support arrays passed as params to encode.url (only for keys ending with "[]")
- Version information changed to "1.0.7"
Documentation for added functions is not yet complete.
Also includes following changes:
- Fix for rocketcgi library to accept POST data content-types, which contain additional charset information.
- Support arrays passed as params to encode.url (only for keys ending with "[]")
- Version information changed to "1.0.7"
Documentation for added functions is not yet complete.
| author | jbe/bsw | 
|---|---|
| date | Fri Feb 12 18:40:22 2010 +0100 (2010-02-12) | 
| parents | |
| children | f3d3203cd2e4 | 
| rev | line source | 
|---|---|
| jbe/bsw@11 | 1 --[[-- | 
| jbe/bsw@11 | 2 ui._partial_load_js{ | 
| jbe/bsw@11 | 3 } | 
| jbe/bsw@11 | 4 | 
| jbe/bsw@11 | 5 TODO: documentation | 
| jbe/bsw@11 | 6 | 
| jbe/bsw@11 | 7 NOTE: may return nil | 
| jbe/bsw@11 | 8 | 
| jbe/bsw@11 | 9 --]]-- | 
| jbe/bsw@11 | 10 | 
| jbe/bsw@11 | 11 function ui._partial_load_js(args, mode) | 
| jbe/bsw@11 | 12 local args = args or {} | 
| jbe/bsw@11 | 13 local module | 
| jbe/bsw@11 | 14 local view | 
| jbe/bsw@11 | 15 local id | 
| jbe/bsw@11 | 16 local params = {} | 
| jbe/bsw@11 | 17 local target | 
| jbe/bsw@11 | 18 if args.view and args.target then | 
| jbe/bsw@11 | 19 module = args.module | 
| jbe/bsw@11 | 20 view = args.view | 
| jbe/bsw@11 | 21 id = args.id | 
| jbe/bsw@11 | 22 target = args.target | 
| jbe/bsw@11 | 23 elseif not args.view and not args.target then | 
| jbe/bsw@11 | 24 if not ui._partial_state then | 
| jbe/bsw@11 | 25 return nil | 
| jbe/bsw@11 | 26 end | 
| jbe/bsw@11 | 27 module = ui._partial_state.module | 
| jbe/bsw@11 | 28 view = ui._partial_state.view | 
| jbe/bsw@11 | 29 id = ui._partial_state.id | 
| jbe/bsw@11 | 30 target = ui._partial_state.target | 
| jbe/bsw@11 | 31 else | 
| jbe/bsw@11 | 32 error("Unexpected arguments passed to ui._partial_load_js{...}") | 
| jbe/bsw@11 | 33 end | 
| jbe/bsw@11 | 34 | 
| jbe/bsw@11 | 35 if ui._partial_state then | 
| jbe/bsw@11 | 36 if ui._partial_state.params then | 
| jbe/bsw@11 | 37 for key, value in pairs(ui._partial_state.params) do | 
| jbe/bsw@11 | 38 params[key] = value | 
| jbe/bsw@11 | 39 end | 
| jbe/bsw@11 | 40 end | 
| jbe/bsw@11 | 41 for param_name, dummy in pairs(ui._partial_state.param_name_hash) do | 
| jbe/bsw@11 | 42 params[param_name] = cgi.params[param_name] | 
| jbe/bsw@11 | 43 end | 
| jbe/bsw@11 | 44 end | 
| jbe/bsw@11 | 45 if args.params then | 
| jbe/bsw@11 | 46 for key, value in pairs(args.params) do | 
| jbe/bsw@11 | 47 params[key] = value | 
| jbe/bsw@11 | 48 end | 
| jbe/bsw@11 | 49 end | 
| jbe/bsw@11 | 50 local encoded_url = encode.json( | 
| jbe/bsw@11 | 51 encode.url{ | 
| jbe/bsw@11 | 52 module = module, | 
| jbe/bsw@11 | 53 view = view, | 
| jbe/bsw@11 | 54 id = id, | 
| jbe/bsw@11 | 55 params = params | 
| jbe/bsw@11 | 56 } | 
| jbe/bsw@11 | 57 ) | 
| jbe/bsw@11 | 58 | 
| jbe/bsw@11 | 59 if mode == "form_normal" then | 
| jbe/bsw@11 | 60 -- NOTE: action in "action_mode" refers to WebMCP actions, while action | 
| jbe/bsw@11 | 61 -- in "this.action" refers to the action attribute of HTML forms | 
| jbe/bsw@11 | 62 slot.put('this.action = ', encoded_url, '; ') | 
| jbe/bsw@11 | 63 end | 
| jbe/bsw@11 | 64 | 
| jbe/bsw@11 | 65 return slot.use_temporary(function() | 
| jbe/bsw@11 | 66 slot.put( | 
| jbe/bsw@11 | 67 'partialMultiLoad({', | 
| jbe/bsw@11 | 68 -- mapping: | 
| jbe/bsw@11 | 69 '"trace": "trace", "system_error": "system_error", ', | 
| jbe/bsw@11 | 70 encode.json(target), ': "default" }, ', | 
| jbe/bsw@11 | 71 -- tempLoadingContents: | 
| jbe/bsw@11 | 72 '{}, ', | 
| jbe/bsw@11 | 73 -- failureContents: | 
| jbe/bsw@11 | 74 '"error", ', | 
| jbe/bsw@11 | 75 -- url: | 
| jbe/bsw@11 | 76 (mode == "form_normal" or mode == "form_action") and ( | 
| jbe/bsw@11 | 77 'this' | 
| jbe/bsw@11 | 78 ) or ( | 
| jbe/bsw@11 | 79 encoded_url | 
| jbe/bsw@11 | 80 ), ', ', | 
| jbe/bsw@11 | 81 -- urlParams: | 
| jbe/bsw@11 | 82 '"_webmcp_json_slots[]=default&_webmcp_json_slots[]=trace&_webmcp_json_slots[]=system_error", ', | 
| jbe/bsw@11 | 83 -- postParams: | 
| jbe/bsw@11 | 84 '{}, ', | 
| jbe/bsw@11 | 85 -- successHandler: | 
| jbe/bsw@11 | 86 'function() {}, ', | 
| jbe/bsw@11 | 87 -- failureHandler: | 
| jbe/bsw@11 | 88 'function() {} ', | 
| jbe/bsw@11 | 89 '); ', | 
| jbe/bsw@11 | 90 'return false;' | 
| jbe/bsw@11 | 91 ) | 
| jbe/bsw@11 | 92 end) | 
| jbe/bsw@11 | 93 end |