webmcp
view framework/env/ui_deprecated/link.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
author | jbe/bsw |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
parents | 9fdfb27f8e67 |
children |
line source
1 function ui_deprecated.link(args)
2 if args.action then
3 local params = {}
4 if args.params then
5 for key, value in pairs(args.params) do
6 params[key] = value
7 end
8 end
9 ui_deprecated._prepare_redirect_params(params, args.redirect_to)
11 local attr_action = args.url or encode.url{
12 module = args.module or request.get_module(),
13 action = args.action,
14 id = args.id,
15 params = params
16 }
17 local attr_class = table.concat({ 'ui_link', args.class }, ' ')
18 local attr_target = args.target or ''
19 local redirect_to = args.redirect_to
20 local unique_id = "unique_" .. multirand.string(32, "abcdefghijklmnopqrstuvwxyz0123456789")
21 slot.put(
22 '<form',
23 ' id="', unique_id , '"',
24 ' action="', attr_action, '"',
25 ' class="', attr_class, '"',
26 ' target="', attr_target, '"',
27 ' method="post"',
28 '>\n',
29 '<input type="submit" value="', args.label or '', '" />',
30 '</form>',
31 '<script>document.getElementById(\'', unique_id, '\').style.display=\'none\';document.write(\'<a href="#" class="', attr_class , '" onclick="document.getElementById(\\\'', unique_id, '\\\').submit();">'
32 )
33 if args.icon then
34 ui_deprecated.image{ image = 'ui/icon/' .. args.icon }
35 end
36 if args.image then
37 ui_deprecated.image{ image = args.image }
38 end
39 if args.label then
40 slot.put(args.label)
41 end
42 slot.put("</a>');</script>")
43 else
44 local attr_class = table.concat({ 'ui_link', args.class }, ' ')
45 slot.put(
46 '<a href="',
47 args.url or encode.url{
48 module = args.module or request.get_module(),
49 view = args.view,
50 id = args.id,
51 params = args.params,
52 },
53 '" ',
54 ui_deprecated._stringify_table({ class = attr_class }),
55 ui_deprecated._stringify_table( args.html_options or {} ),
56 '>'
57 )
58 if args.icon then
59 ui_deprecated.image{ image = 'ui/icon/' .. args.icon }
60 end
61 if args.image then
62 ui_deprecated.image{ image = args.image }
63 end
64 if args.label then
65 slot.put(args.label)
66 end
67 slot.put('</a>')
68 end
69 end