webmcp
diff framework/env/ui/_partial_load_js.lua @ 12:f3d3203cd2e4
Documentation for partial loading added
NOTE: Previous changeset d76a8857ba62 also modified behaviour of ui.script: Scripts containing "]]>" are now rejected to avoid ambiguities
NOTE: Previous changeset d76a8857ba62 also modified behaviour of ui.script: Scripts containing "]]>" are now rejected to avoid ambiguities
author | jbe |
---|---|
date | Fri Feb 19 16:43:29 2010 +0100 (2010-02-19) |
parents | d76a8857ba62 |
children |
line diff
1.1 --- a/framework/env/ui/_partial_load_js.lua Fri Feb 12 18:40:22 2010 +0100 1.2 +++ b/framework/env/ui/_partial_load_js.lua Fri Feb 19 16:43:29 2010 +0100 1.3 @@ -1,10 +1,53 @@ 1.4 --[[-- 1.5 -ui._partial_load_js{ 1.6 +ui._partial_load_js( 1.7 + { 1.8 + module = module, 1.9 + view = view, 1.10 + id = id, 1.11 + params = params, 1.12 + target = target 1.13 + }, 1.14 + mode = mode 1.15 } 1.16 1.17 -TODO: documentation 1.18 +This function is not supposed to be called directly, but only to be used by 1.19 +ui.link{...} and ui.form{...}. 1.20 + 1.21 +It returns a JavaScript which can be used for onclick or onsubmit 1.22 +attributes in HTML to cause a partial load of contents. Behaviour differs 1.23 +for the following cases: 1.24 +a) module, view and target (and optionally id) are given as parameters 1.25 +b) neither module, view, id, nor target are given as parameters 1.26 + 1.27 +In case of a) the function will create a JavaScript which requests the 1.28 +given view (optionally with the given id and params) as JSON data. 1.29 + 1.30 +In case of b) the function will create a JavaScript requesting the view 1.31 +specified by the next outer ui.partial{...} call as JSON data. Request 1.32 +parameters specified by previous calls of add_partial_param_names({...}) 1.33 +are copied from the GET/POST parameters of the current request, while they 1.34 +can be overwritten using the "params" argument to this function. 1.35 1.36 -NOTE: may return nil 1.37 +If there is no outer ui.partial{...} call in case b), then this function 1.38 +returns nil. 1.39 + 1.40 +The called URL contains "_webmcp_json_slots[]" as GET parameters to 1.41 +indicate that slot contents should be returned as a JSON object, instead of 1.42 +being inserted to a page layout. 1.43 + 1.44 +TODO: Currently the slots requested are "default", "trace" and 1.45 +"system_error". The target for the slot "default" is passed as argument to 1.46 +this function or to ui.partial{...}. The targets for the slots "trace" and 1.47 +"system_error" are "trace" and "system_error". This is hardcoded and should 1.48 +be possible to change in future. The JavaScript will fail, if there are no 1.49 +HTML elements with id's "trace" and "system_error". 1.50 + 1.51 +A mode can be passed as second parameter to this function. When this mode 1.52 +is "nil" or non existent, the function creates JavaScript code to be used 1.53 +as onclick event for normal (GET) links. When mode is set to "form_normal" 1.54 +or "form_action", the returned code can be used as onsubmit event of web 1.55 +forms. "form_normal" is used when the form calls a view, "form_action" is 1.56 +used when the form calls an action. 1.57 1.58 --]]-- 1.59 1.60 @@ -33,6 +76,7 @@ 1.61 end 1.62 1.63 if ui._partial_state then 1.64 + -- TODO: do this only if args.view and args.target are unset!? 1.65 if ui._partial_state.params then 1.66 for key, value in pairs(ui._partial_state.params) do 1.67 params[key] = value