webmcp

annotate framework/env/ui/link.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
author jbe
date Fri Feb 19 16:43:29 2010 +0100 (2010-02-19)
parents d76a8857ba62
children 2a3257f29c02
rev   line source
jbe/bsw@0 1 --[[--
jbe/bsw@0 2 ui.link{
jbe/bsw@0 3 external = external, -- external URL
jbe/bsw@0 4 static = static, -- URL relative to the static file directory
jbe/bsw@0 5 module = module, -- module name
jbe/bsw@0 6 view = view, -- view name
jbe/bsw@0 7 action = action, -- action name
jbe/bsw@0 8 id = id, -- optional id to be passed to the view or action to select a particular data record
jbe/bsw@0 9 params = params, -- optional parameters to be passed to the view or action
jbe/bsw@0 10 routing = routing, -- optional routing information for action links, as described for ui.form{...}
jbe/bsw@0 11 text = text, -- link text
jbe/bsw@11 12 content = content, -- link content (overrides link text, except for submit buttons for action calls without JavaScript)
jbe@12 13 partial = { -- parameters for partial loading, see below
jbe/bsw@11 14 module = module,
jbe/bsw@11 15 view = view,
jbe/bsw@11 16 id = id,
jbe@12 17 params = params,
jbe@12 18 target = target
jbe/bsw@11 19 }
jbe/bsw@0 20 }
jbe/bsw@0 21
jbe/bsw@0 22 This function inserts a link into the active slot. It may be either an internal application link ('module' given and 'view' or 'action' given), or a link to an external web page ('external' given), or a link to a file in the static file directory of the application ('static' given).
jbe/bsw@0 23
jbe@12 24 When passing a table as "partial" argument, AND if partial loading has been enabled by calling ui.enable_partial_loading(), then ui._partial_load_js is
jbe@12 25 used to create an onclick event (onsubmit event for action links). The
jbe@12 26 "partial" setting table is passed to ui._partial_load_js as first argument.
jbe@12 27 See ui._partial_load_js(...) for further documentation.
jbe@12 28
jbe/bsw@0 29 --]]--
jbe/bsw@0 30
jbe/bsw@0 31 function ui.link(args)
jbe/bsw@0 32 local args = args or {}
jbe/bsw@4 33 local content = args.content or args.text
jbe/bsw@0 34 assert(content, "ui.link{...} needs a text.")
jbe/bsw@0 35 local function wrapped_content()
jbe/bsw@11 36 if args.image then
jbe/bsw@11 37 ui.image(args.image)
jbe/bsw@11 38 end
jbe/bsw@0 39 if type(content) == "function" then
jbe/bsw@0 40 content()
jbe/bsw@0 41 else
jbe/bsw@0 42 slot.put(encode.html(content))
jbe/bsw@0 43 end
jbe/bsw@0 44 end
jbe/bsw@0 45 if args.action then
jbe/bsw@0 46 local form_attr = table.new(args.form_attr)
jbe/bsw@0 47 local form_id
jbe/bsw@0 48 if form_attr.id then
jbe/bsw@0 49 form_id = form_attr.id
jbe/bsw@0 50 else
jbe/bsw@0 51 form_id = ui.create_unique_id()
jbe/bsw@0 52 end
jbe/bsw@0 53 local quoted_form_id = encode.json(form_id)
jbe/bsw@0 54 form_attr.id = form_id
jbe/bsw@0 55 local a_attr = table.new(args.attr)
jbe/bsw@0 56 a_attr.href = "#"
jbe/bsw@0 57 a_attr.onclick =
jbe/bsw@0 58 "var f = document.getElementById(" .. quoted_form_id .. "); if (! f.onsubmit || f.onsubmit() != false) { f.submit() };"
jbe/bsw@0 59 ui.form{
jbe/bsw@0 60 external = args.external,
jbe/bsw@0 61 module = args.module or request.get_module(),
jbe/bsw@0 62 action = args.action,
jbe/bsw@0 63 id = args.id,
jbe/bsw@0 64 params = args.params,
jbe/bsw@0 65 routing = args.routing,
jbe/bsw@11 66 partial = args.partial,
jbe/bsw@0 67 attr = form_attr,
jbe/bsw@0 68 content = function()
jbe/bsw@0 69 ui.submit{ text = args.text, attr = args.submit_attr }
jbe/bsw@0 70 end
jbe/bsw@0 71 }
jbe/bsw@0 72 ui.script{
jbe/bsw@0 73 type = "text/javascript",
jbe/bsw@0 74 script = (
jbe/bsw@0 75 "document.getElementById(" ..
jbe/bsw@0 76 quoted_form_id ..
jbe/bsw@0 77 ").style.display = 'none'; document.write(" ..
jbe/bsw@0 78 encode.json(
jbe/bsw@0 79 slot.use_temporary(
jbe/bsw@0 80 function()
jbe/bsw@0 81 ui.tag{
jbe/bsw@0 82 tag = "a",
jbe/bsw@0 83 attr = a_attr,
jbe/bsw@0 84 content = wrapped_content
jbe/bsw@0 85 }
jbe/bsw@0 86 end
jbe/bsw@0 87 )
jbe/bsw@0 88 ) ..
jbe/bsw@0 89 ");"
jbe/bsw@0 90 )
jbe/bsw@0 91 }
jbe/bsw@0 92 else
jbe/bsw@0 93 -- TODO: support content function
jbe/bsw@0 94 local a_attr = table.new(args.attr)
jbe/bsw@0 95 a_attr.href = encode.url{
jbe/bsw@0 96 external = args.external,
jbe/bsw@0 97 static = args.static,
jbe/bsw@0 98 module = args.module or request.get_module(),
jbe/bsw@0 99 view = args.view,
jbe/bsw@0 100 id = args.id,
jbe/bsw@0 101 params = args.params,
jbe/bsw@0 102 }
jbe/bsw@11 103 if ui.is_partial_loading_enabled() and args.partial then
jbe/bsw@11 104 a_attr.onclick = ui._partial_load_js(args.partial)
jbe/bsw@11 105 end
jbe/bsw@0 106 return ui.tag{ tag = "a", attr = a_attr, content = wrapped_content }
jbe/bsw@0 107 end
jbe/bsw@0 108 end

Impressum / About Us