webmcp
annotate framework/env/ui_deprecated/link.lua @ 31:1cd9e69b85cb
add execute.load_chunk(args)
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Tue Oct 05 02:34:04 2010 +0200 (2010-10-05) |
parents | 9fdfb27f8e67 |
children |
rev | line source |
---|---|
jbe/bsw@0 | 1 function ui_deprecated.link(args) |
jbe/bsw@0 | 2 if args.action then |
jbe/bsw@0 | 3 local params = {} |
jbe/bsw@0 | 4 if args.params then |
jbe/bsw@0 | 5 for key, value in pairs(args.params) do |
jbe/bsw@0 | 6 params[key] = value |
jbe/bsw@0 | 7 end |
jbe/bsw@0 | 8 end |
jbe/bsw@0 | 9 ui_deprecated._prepare_redirect_params(params, args.redirect_to) |
jbe/bsw@0 | 10 |
jbe/bsw@0 | 11 local attr_action = args.url or encode.url{ |
jbe/bsw@0 | 12 module = args.module or request.get_module(), |
jbe/bsw@0 | 13 action = args.action, |
jbe/bsw@0 | 14 id = args.id, |
jbe/bsw@0 | 15 params = params |
jbe/bsw@0 | 16 } |
jbe/bsw@0 | 17 local attr_class = table.concat({ 'ui_link', args.class }, ' ') |
jbe/bsw@0 | 18 local attr_target = args.target or '' |
jbe/bsw@0 | 19 local redirect_to = args.redirect_to |
jbe/bsw@0 | 20 local unique_id = "unique_" .. multirand.string(32, "abcdefghijklmnopqrstuvwxyz0123456789") |
jbe/bsw@0 | 21 slot.put( |
jbe/bsw@0 | 22 '<form', |
jbe/bsw@0 | 23 ' id="', unique_id , '"', |
jbe/bsw@0 | 24 ' action="', attr_action, '"', |
jbe/bsw@0 | 25 ' class="', attr_class, '"', |
jbe/bsw@0 | 26 ' target="', attr_target, '"', |
jbe/bsw@0 | 27 ' method="post"', |
jbe/bsw@0 | 28 '>\n', |
jbe/bsw@0 | 29 '<input type="submit" value="', args.label or '', '" />', |
jbe/bsw@0 | 30 '</form>', |
jbe/bsw@0 | 31 '<script>document.getElementById(\'', unique_id, '\').style.display=\'none\';document.write(\'<a href="#" class="', attr_class , '" onclick="document.getElementById(\\\'', unique_id, '\\\').submit();">' |
jbe/bsw@0 | 32 ) |
jbe/bsw@0 | 33 if args.icon then |
jbe/bsw@0 | 34 ui_deprecated.image{ image = 'ui/icon/' .. args.icon } |
jbe/bsw@0 | 35 end |
jbe/bsw@0 | 36 if args.image then |
jbe/bsw@0 | 37 ui_deprecated.image{ image = args.image } |
jbe/bsw@0 | 38 end |
jbe/bsw@0 | 39 if args.label then |
jbe/bsw@0 | 40 slot.put(args.label) |
jbe/bsw@0 | 41 end |
jbe/bsw@0 | 42 slot.put("</a>');</script>") |
jbe/bsw@0 | 43 else |
jbe/bsw@0 | 44 local attr_class = table.concat({ 'ui_link', args.class }, ' ') |
jbe/bsw@0 | 45 slot.put( |
jbe/bsw@0 | 46 '<a href="', |
jbe/bsw@0 | 47 args.url or encode.url{ |
jbe/bsw@0 | 48 module = args.module or request.get_module(), |
jbe/bsw@0 | 49 view = args.view, |
jbe/bsw@0 | 50 id = args.id, |
jbe/bsw@0 | 51 params = args.params, |
jbe/bsw@0 | 52 }, |
jbe/bsw@0 | 53 '" ', |
jbe/bsw@0 | 54 ui_deprecated._stringify_table({ class = attr_class }), |
jbe/bsw@0 | 55 ui_deprecated._stringify_table( args.html_options or {} ), |
jbe/bsw@0 | 56 '>' |
jbe/bsw@0 | 57 ) |
jbe/bsw@0 | 58 if args.icon then |
jbe/bsw@0 | 59 ui_deprecated.image{ image = 'ui/icon/' .. args.icon } |
jbe/bsw@0 | 60 end |
jbe/bsw@0 | 61 if args.image then |
jbe/bsw@0 | 62 ui_deprecated.image{ image = args.image } |
jbe/bsw@0 | 63 end |
jbe/bsw@0 | 64 if args.label then |
jbe/bsw@0 | 65 slot.put(args.label) |
jbe/bsw@0 | 66 end |
jbe/bsw@0 | 67 slot.put('</a>') |
jbe/bsw@0 | 68 end |
jbe/bsw@0 | 69 end |