webmcp

diff framework/env/ui/form.lua @ 56:36ebcae1cde3

File upload support in env/ui
author jbe
date Sun Dec 18 22:09:58 2011 +0100 (2011-12-18)
parents f3d3203cd2e4
children 6a830c1479b0
line diff
     1.1 --- a/framework/env/ui/form.lua	Sun Dec 18 21:14:43 2011 +0100
     1.2 +++ b/framework/env/ui/form.lua	Sun Dec 18 22:09:58 2011 +0100
     1.3 @@ -1,11 +1,12 @@
     1.4  --[[--
     1.5  ui.form{
     1.6 -  record    = record,     -- optional record to be used 
     1.7 -  read_only = read_only,  -- set to true, if form should be read-only (no submit button)
     1.8 -  external  = external,   -- external URL to be used as HTML form action
     1.9 -  module    = module,     -- module name to be used for HTML form action
    1.10 -  view      = view,       -- view name   to be used for HTML form action
    1.11 -  action    = action,     -- action name to be used for HTML form action
    1.12 +  record      = record,       -- optional record to be used 
    1.13 +  read_only   = read_only,    -- set to true, if form should be read-only (no submit button)
    1.14 +  file_upload = file_upload,  -- must be set to true, if form contains file upload element
    1.15 +  external    = external,     -- external URL to be used as HTML form action
    1.16 +  module      = module,       -- module name to be used for HTML form action
    1.17 +  view        = view,         -- view name   to be used for HTML form action
    1.18 +  action      = action,       -- action name to be used for HTML form action
    1.19    routing = {
    1.20      default = {           -- default routing for called action
    1.21        mode   = mode,      -- "forward" or "redirect"
    1.22 @@ -18,7 +19,7 @@
    1.23      error = { ... },      -- routing when "error" is returned by the called action
    1.24      ...   = { ... }       -- routing when "..."   is returned by the called action
    1.25    },
    1.26 -  partial   = {           -- parameters for partial loading, see below
    1.27 +  partial = {             -- parameters for partial loading, see below
    1.28      module = module,
    1.29      view   = view,
    1.30      id     = id,
    1.31 @@ -70,8 +71,9 @@
    1.32  function ui.form(args)
    1.33    local args = args or {}
    1.34    local slot_state = slot.get_state_table()
    1.35 -  local old_record   = slot_state.form_record
    1.36 -  local old_readonly = slot_state.form_readonly
    1.37 +  local old_record      = slot_state.form_record
    1.38 +  local old_readonly    = slot_state.form_readonly
    1.39 +  local old_file_upload = slot_state.form_file_upload
    1.40    slot_state.form_record = args.record
    1.41    if args.readonly then
    1.42      slot_state.form_readonly = true
    1.43 @@ -82,6 +84,13 @@
    1.44      prepare_routing_params(params, args.routing, args.module)
    1.45      params._webmcp_csrf_secret = request.get_csrf_secret()
    1.46      local attr = table.new(args.attr)
    1.47 +    if attr.enctype=="multipart/form-data" or slot_state.form_file_upload then
    1.48 +      slot_state.form_file_upload = true
    1.49 +      if attr.enctype == nil then
    1.50 +        attr.enctype = "multipart/form-data"
    1.51 +      end
    1.52 +    end
    1.53 +    end
    1.54      attr.action = encode.url{
    1.55        external  = args.external,
    1.56        module    = args.module or request.get_module(),
    1.57 @@ -149,6 +158,7 @@
    1.58      }
    1.59      slot_state.form_opened = false
    1.60    end
    1.61 -  slot_state.form_readonly = old_readonly
    1.62 -  slot_state.form_record   = old_record
    1.63 +  slot_state.form_file_upload = old_file_upload
    1.64 +  slot_state.form_readonly    = old_readonly
    1.65 +  slot_state.form_record      = old_record
    1.66  end

Impressum / About Us