webmcp
diff 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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/ui/_partial_load_js.lua Fri Feb 12 18:40:22 2010 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +--[[-- 1.5 +ui._partial_load_js{ 1.6 +} 1.7 + 1.8 +TODO: documentation 1.9 + 1.10 +NOTE: may return nil 1.11 + 1.12 +--]]-- 1.13 + 1.14 +function ui._partial_load_js(args, mode) 1.15 + local args = args or {} 1.16 + local module 1.17 + local view 1.18 + local id 1.19 + local params = {} 1.20 + local target 1.21 + if args.view and args.target then 1.22 + module = args.module 1.23 + view = args.view 1.24 + id = args.id 1.25 + target = args.target 1.26 + elseif not args.view and not args.target then 1.27 + if not ui._partial_state then 1.28 + return nil 1.29 + end 1.30 + module = ui._partial_state.module 1.31 + view = ui._partial_state.view 1.32 + id = ui._partial_state.id 1.33 + target = ui._partial_state.target 1.34 + else 1.35 + error("Unexpected arguments passed to ui._partial_load_js{...}") 1.36 + end 1.37 + 1.38 + if ui._partial_state then 1.39 + if ui._partial_state.params then 1.40 + for key, value in pairs(ui._partial_state.params) do 1.41 + params[key] = value 1.42 + end 1.43 + end 1.44 + for param_name, dummy in pairs(ui._partial_state.param_name_hash) do 1.45 + params[param_name] = cgi.params[param_name] 1.46 + end 1.47 + end 1.48 + if args.params then 1.49 + for key, value in pairs(args.params) do 1.50 + params[key] = value 1.51 + end 1.52 + end 1.53 + local encoded_url = encode.json( 1.54 + encode.url{ 1.55 + module = module, 1.56 + view = view, 1.57 + id = id, 1.58 + params = params 1.59 + } 1.60 + ) 1.61 + 1.62 + if mode == "form_normal" then 1.63 + -- NOTE: action in "action_mode" refers to WebMCP actions, while action 1.64 + -- in "this.action" refers to the action attribute of HTML forms 1.65 + slot.put('this.action = ', encoded_url, '; ') 1.66 + end 1.67 + 1.68 + return slot.use_temporary(function() 1.69 + slot.put( 1.70 + 'partialMultiLoad({', 1.71 + -- mapping: 1.72 + '"trace": "trace", "system_error": "system_error", ', 1.73 + encode.json(target), ': "default" }, ', 1.74 + -- tempLoadingContents: 1.75 + '{}, ', 1.76 + -- failureContents: 1.77 + '"error", ', 1.78 + -- url: 1.79 + (mode == "form_normal" or mode == "form_action") and ( 1.80 + 'this' 1.81 + ) or ( 1.82 + encoded_url 1.83 + ), ', ', 1.84 + -- urlParams: 1.85 + '"_webmcp_json_slots[]=default&_webmcp_json_slots[]=trace&_webmcp_json_slots[]=system_error", ', 1.86 + -- postParams: 1.87 + '{}, ', 1.88 + -- successHandler: 1.89 + 'function() {}, ', 1.90 + -- failureHandler: 1.91 + 'function() {} ', 1.92 + '); ', 1.93 + 'return false;' 1.94 + ) 1.95 + end) 1.96 +end