webmcp
view 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 source
     1 --[[--
     2 ui._partial_load_js{
     3 }
     5 TODO: documentation
     7 NOTE: may return nil
     9 --]]--
    11 function ui._partial_load_js(args, mode)
    12   local args = args or {}
    13   local module
    14   local view
    15   local id
    16   local params = {}
    17   local target
    18   if args.view and args.target then
    19     module = args.module
    20     view   = args.view
    21     id     = args.id
    22     target = args.target
    23   elseif not args.view and not args.target then
    24     if not ui._partial_state then
    25       return nil
    26     end
    27     module = ui._partial_state.module
    28     view   = ui._partial_state.view
    29     id     = ui._partial_state.id
    30     target = ui._partial_state.target
    31   else
    32     error("Unexpected arguments passed to ui._partial_load_js{...}")
    33   end
    35   if ui._partial_state then
    36     if ui._partial_state.params then
    37       for key, value in pairs(ui._partial_state.params) do
    38         params[key] = value
    39       end
    40     end
    41     for param_name, dummy in pairs(ui._partial_state.param_name_hash) do
    42       params[param_name] = cgi.params[param_name]
    43     end
    44   end
    45   if args.params then
    46     for key, value in pairs(args.params) do
    47       params[key] = value
    48     end
    49   end
    50   local encoded_url = encode.json(
    51     encode.url{
    52       module = module,
    53       view   = view,
    54       id     = id,
    55       params = params
    56     }
    57   )
    59   if mode == "form_normal" then
    60     -- NOTE: action in "action_mode" refers to WebMCP actions, while action
    61     -- in "this.action" refers to the action attribute of HTML forms
    62     slot.put('this.action = ', encoded_url, '; ')
    63   end
    65   return slot.use_temporary(function()
    66     slot.put(
    67       'partialMultiLoad({',
    68         -- mapping:
    69         '"trace": "trace", "system_error": "system_error", ',
    70         encode.json(target), ': "default" }, ',
    71         -- tempLoadingContents:
    72         '{}, ',
    73         -- failureContents:
    74         '"error", ',
    75         -- url:
    76         (mode == "form_normal" or mode == "form_action") and (
    77           'this'
    78         ) or (
    79           encoded_url
    80         ), ', ',
    81         -- urlParams:
    82         '"_webmcp_json_slots[]=default&_webmcp_json_slots[]=trace&_webmcp_json_slots[]=system_error", ',
    83         -- postParams:
    84         '{}, ',
    85         -- successHandler:
    86         'function() {}, ',
    87         -- failureHandler:
    88         'function() {} ',
    89       '); ',
    90       'return false;'
    91     )
    92   end)
    93 end
