webmcp

changeset 223:32ec28229bb5

Finished removing all references to cgi module (except demo-app); Removed partial loading mechanism
author jbe
date Fri Feb 27 21:49:00 2015 +0100 (2015-02-27)
parents 38e5399718ca
children 9fcdec58aa31
files framework/bin/webmcp_shell framework/env/auth/openid/initiate.lua framework/env/auth/openid/verify.lua framework/env/auth/openid/xrds_header.lua framework/env/encode/json.lua framework/env/execute/config.lua framework/env/param/get.lua framework/env/param/get_all_cgi.lua framework/env/param/get_id_cgi.lua framework/env/param/get_list.lua framework/env/request/__init.lua framework/env/request/get_json_request_slots.lua framework/env/request/get_status.lua framework/env/request/is_post.lua framework/env/request/process.lua framework/env/request/set_allowed_json_request_slots.lua framework/env/request/set_cookie.lua framework/env/request/set_csrf_secret.lua framework/env/trace/_render_sub_tree.lua framework/env/trace/exectime.lua framework/env/ui/__init.lua framework/env/ui/_partial_load_js.lua framework/env/ui/add_partial_param_names.lua framework/env/ui/enable_partial_loading.lua framework/env/ui/filters.lua framework/env/ui/form.lua framework/env/ui/is_partial_loading_enabled.lua framework/env/ui/link.lua framework/env/ui/paginate.lua framework/env/ui/partial.lua framework/js/partialload.js
line diff
     1.1 --- a/framework/bin/webmcp_shell	Fri Feb 27 17:18:08 2015 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,10 +0,0 @@
     1.4 -#!/bin/sh
     1.5 -export WEBMCP_APP_BASEPATH="`pwd`"
     1.6 -export WEBMCP_CONFIG_NAME="$1"
     1.7 -export WEBMCP_INTERACTIVE="yes"
     1.8 -if [ "$WEBMCP_CONFIG_NAME" = "" ]; then
     1.9 -  echo "Error: No config name given." > /dev/stderr
    1.10 -  exit 1
    1.11 -fi
    1.12 -cd "`dirname "$0"`/../cgi-bin"
    1.13 -exec lua -i webmcp.lua
     2.1 --- a/framework/env/auth/openid/initiate.lua	Fri Feb 27 17:18:08 2015 +0100
     2.2 +++ b/framework/env/auth/openid/initiate.lua	Fri Feb 27 21:49:00 2015 +0100
     2.3 @@ -30,8 +30,8 @@
     2.4      return nil, errmsg, errcode
     2.5    end
     2.6    -- TODO: Use request.redirect once it supports external URLs
     2.7 -  cgi.set_status("303 See Other")
     2.8 -  cgi.add_header(
     2.9 +  request.set_status("303 See Other")
    2.10 +  request.add_header(
    2.11      "Location: " ..
    2.12      encode.url{
    2.13        external = dd.op_endpoint,
    2.14 @@ -51,6 +51,7 @@
    2.15        }
    2.16      }
    2.17    )
    2.18 -  cgi.send_data()
    2.19 -  exit()
    2.20 +  error("Not implemented")  -- TODO
    2.21 +  --cgi.send_data()
    2.22 +  --exit()
    2.23  end
     3.1 --- a/framework/env/auth/openid/verify.lua	Fri Feb 27 17:18:08 2015 +0100
     3.2 +++ b/framework/env/auth/openid/verify.lua	Fri Feb 27 21:49:00 2015 +0100
     3.3 @@ -11,12 +11,12 @@
     3.4  
     3.5  function auth.openid.verify(args)
     3.6    local args = args or {}
     3.7 -  if cgi.params["openid.ns"] ~= "http://specs.openid.net/auth/2.0" then
     3.8 +  if request.get_param{name="openid.ns"} ~= "http://specs.openid.net/auth/2.0" then
     3.9      return nil, "No indirect OpenID 2.0 message received."
    3.10    end
    3.11 -  local mode = cgi.params["openid.mode"]
    3.12 +  local mode = request.get_param{name="openid.mode"}
    3.13    if mode == "id_res" then
    3.14 -    local return_to_url = cgi.params["openid.return_to"]
    3.15 +    local return_to_url = request.get_param{name="openid.return_to"}
    3.16      if not return_to_url then
    3.17        return nil, "No return_to URL received in answer."
    3.18      end
    3.19 @@ -28,7 +28,7 @@
    3.20        return nil, "return_to URL not matching."
    3.21      end
    3.22      local discovery_args = table.new(args)
    3.23 -    local claimed_identifier = cgi.params["openid.claimed_id"]
    3.24 +    local claimed_identifier = request.get_param{name="openid.claimed_id"}
    3.25      if not claimed_identifier then
    3.26        return nil, "No claimed identifier received."
    3.27      end
    3.28 @@ -53,7 +53,7 @@
    3.29      if dd.claimed_identifier ~= cropped_identifier then
    3.30        return nil, "Claimed identifier does not match."
    3.31      end
    3.32 -    local nonce = cgi.params["openid.response_nonce"]
    3.33 +    local nonce = request.get_param{name="openid.response_nonce"}
    3.34      if not nonce then
    3.35        return nil, "Did not receive a response nonce."
    3.36      end 
     4.1 --- a/framework/env/auth/openid/xrds_header.lua	Fri Feb 27 17:18:08 2015 +0100
     4.2 +++ b/framework/env/auth/openid/xrds_header.lua	Fri Feb 27 21:49:00 2015 +0100
     4.3 @@ -50,5 +50,5 @@
     4.4  
     4.5  --]]--
     4.6  function auth.openid.xrds_header(args)
     4.7 -  cgi.add_header("X-XRDS-Location: " .. encode.url(args))
     4.8 +  request.add_header("X-XRDS-Location: " .. encode.url(args))
     4.9  end
     5.1 --- a/framework/env/encode/json.lua	Fri Feb 27 17:18:08 2015 +0100
     5.2 +++ b/framework/env/encode/json.lua	Fri Feb 27 21:49:00 2015 +0100
     5.3 @@ -8,6 +8,8 @@
     5.4  
     5.5  TODO: can't distinguish unambiguously between empty object and empty list!
     5.6  
     5.7 +TODO: replace with JSON library
     5.8 +
     5.9  --]]--
    5.10  
    5.11  -- TODO: check if numeric representations are JSON compatible
     6.1 --- a/framework/env/execute/config.lua	Fri Feb 27 17:18:08 2015 +0100
     6.2 +++ b/framework/env/execute/config.lua	Fri Feb 27 21:49:00 2015 +0100
     6.3 @@ -4,7 +4,7 @@
     6.4  )
     6.5  
     6.6  Executes a configuration file of the application.
     6.7 -This function is only used by by the webmcp.lua file in the cgi-bin/ directory.
     6.8 +This function is only used by by the mcp.lua file in the bin/ directory.
     6.9  
    6.10  --]]--
    6.11  
     7.1 --- a/framework/env/param/get.lua	Fri Feb 27 17:18:08 2015 +0100
     7.2 +++ b/framework/env/param/get.lua	Fri Feb 27 21:49:00 2015 +0100
     7.3 @@ -18,8 +18,8 @@
     7.4      end
     7.5      return value
     7.6    else
     7.7 -    local str         = cgi.params[key]
     7.8 -    local format_info = cgi.params[key .. "__format"]
     7.9 +    local str         = request.get_param{ name = key }
    7.10 +    local format_info = request.get_param{ name = key .. "__format" }
    7.11      if not str then
    7.12        if not format_info then
    7.13          return nil
     8.1 --- a/framework/env/param/get_all_cgi.lua	Fri Feb 27 17:18:08 2015 +0100
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,13 +0,0 @@
     8.4 ---[[--
     8.5 -params =
     8.6 -param.get_all_cgi()
     8.7 -
     8.8 -Deprecated. Alias for request.get_param_strings().
     8.9 -
    8.10 ---]]--
    8.11 -
    8.12 --- TODO: Remove this function.
    8.13 -
    8.14 -function param.get_all_cgi()
    8.15 -  return request.get_param_strings()
    8.16 -end
     9.1 --- a/framework/env/param/get_id_cgi.lua	Fri Feb 27 17:18:08 2015 +0100
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,13 +0,0 @@
     9.4 ---[[--
     9.5 -value =             -- id as string (or other type after if params.exchange(...) has been used), or nil
     9.6 -param.get_id_cgi()
     9.7 -
     9.8 -Deprecated. Alias for request.get_id_string().
     9.9 -
    9.10 ---]]--
    9.11 -
    9.12 --- TODO: Remove this function.
    9.13 -
    9.14 -function param.get_id_cgi()
    9.15 -  return request.get_id_string()
    9.16 -end
    10.1 --- a/framework/env/param/get_list.lua	Fri Feb 27 17:18:08 2015 +0100
    10.2 +++ b/framework/env/param/get_list.lua	Fri Feb 27 21:49:00 2015 +0100
    10.3 @@ -23,9 +23,9 @@
    10.4      end
    10.5      return values
    10.6    else
    10.7 -    local format_info = cgi.params[key .. "__format"]
    10.8 +    local format_info = request.get_param{ name = key .. "__format" }
    10.9      local parser = param._get_parser(format_info, param_type)
   10.10 -    local raw_values = cgi.params[key .. "[]"]
   10.11 +    local raw_values = request.get_param{ name = key .. "[]", multiple = true }
   10.12      local values = {}
   10.13      if raw_values then
   10.14        for idx, value in ipairs(raw_values) do
    11.1 --- a/framework/env/request/__init.lua	Fri Feb 27 17:18:08 2015 +0100
    11.2 +++ b/framework/env/request/__init.lua	Fri Feb 27 21:49:00 2015 +0100
    11.3 @@ -11,7 +11,6 @@
    11.4  request._force_absolute_baseurl = false
    11.5  request._perm_params = {}
    11.6  request._csrf_secret = nil
    11.7 -request._json_requests_allowed = false
    11.8  
    11.9  request._params = {}
   11.10  
    12.1 --- a/framework/env/request/get_json_request_slots.lua	Fri Feb 27 17:18:08 2015 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,16 +0,0 @@
    12.4 ---[[--
    12.5 -slot_idents =                    -- list of names of slots to be returned as JSON data
    12.6 -request.get_json_request_slots()
    12.7 -
    12.8 -If the current request is no JSON request, this function returns nil, otherwise a list of names of all slots to be returned in JSON format. This function also throws an error, if JSON data was requested, but request.set_allowed_json_request_slots(...) has not been called.
    12.9 -
   12.10 ---]]--
   12.11 -
   12.12 -function request.get_json_request_slots(slot_idents)
   12.13 -  if not cgi then return end
   12.14 -  local slot_idents = cgi.params["_webmcp_json_slots[]"]
   12.15 -  if slot_idents and not request._json_requests_allowed then
   12.16 -    error("JSON requests have not been allowed using request.set_allowed_json_request_slots(...).")
   12.17 -  end
   12.18 -  return slot_idents
   12.19 -end
    13.1 --- a/framework/env/request/get_status.lua	Fri Feb 27 17:18:08 2015 +0100
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,11 +0,0 @@
    13.4 ---[[--
    13.5 -status_string =
    13.6 -request.get_status()
    13.7 -
    13.8 -Returns a HTTP status previously set with request.set_status(...).
    13.9 -
   13.10 ---]]--
   13.11 -
   13.12 -function request.get_status()
   13.13 -  return request._status
   13.14 -end
    14.1 --- a/framework/env/request/is_post.lua	Fri Feb 27 17:18:08 2015 +0100
    14.2 +++ b/framework/env/request/is_post.lua	Fri Feb 27 21:49:00 2015 +0100
    14.3 @@ -10,6 +10,6 @@
    14.4    if request._forward_processed then
    14.5      return false
    14.6    else
    14.7 -    return cgi.method == "POST"
    14.8 +    return request._http_request.method == "POST"
    14.9    end
   14.10  end
    15.1 --- a/framework/env/request/process.lua	Fri Feb 27 17:18:08 2015 +0100
    15.2 +++ b/framework/env/request/process.lua	Fri Feb 27 21:49:00 2015 +0100
    15.3 @@ -66,7 +66,7 @@
    15.4              assert(routing_view,   "Routing information has no view.")
    15.5              if routing_mode == "redirect" then
    15.6                local routing_params = {}
    15.7 -              for key, value in request.get_param_strings{method="POST", include_internal=true} do
    15.8 +              for key, value in request.get_param_strings{ method="POST", include_internal=true } do
    15.9                  local status, stripped_key = string.match(
   15.10                    key, "^_webmcp_routing%.([^%.]*)%.params%.(.*)$"
   15.11                  )
   15.12 @@ -140,8 +140,8 @@
   15.13  
   15.14    if not success then trace.error{} end
   15.15  
   15.16 -  -- laufzeitermittlung
   15.17 -  trace.exectime{ real = extos.monotonic_hires_time(), cpu = os.clock() }
   15.18 +  -- TODO: extend trace system to generally monitor execution time
   15.19 +  -- trace.exectime{ real = extos.monotonic_hires_time(), cpu = os.clock() }
   15.20  
   15.21    slot.select('trace', trace.render)  -- render trace information
   15.22  
   15.23 @@ -151,8 +151,8 @@
   15.24    if not success then
   15.25      local errobj     = error_info.errobj
   15.26      local stacktrace = error_info.stacktrace
   15.27 -    if not request.get_status() and not request.get_json_request_slots() then
   15.28 -      request.set_status("500 Internal Server Error")
   15.29 +    if not request._status then
   15.30 +      request._status = "500 Internal Server Error"
   15.31      end
   15.32      slot.set_layout('system_error')
   15.33      slot.select('system_error', function()
   15.34 @@ -180,11 +180,9 @@
   15.35      if slot_dump ~= "" then
   15.36        redirect_params.tempstore = tempstore.save(slot_dump)
   15.37      end
   15.38 -    local json_request_slots = request.get_json_request_slots()
   15.39 -    if json_request_slots then
   15.40 -      redirect_params["_webmcp_json_slots[]"] = json_request_slots  
   15.41 -    end
   15.42 -    cgi.redirect(
   15.43 +    request._http_request:send_status("303 See Other")
   15.44 +    request._http_request:send_header(
   15.45 +      "Location",
   15.46        encode.url{
   15.47          base   = request.get_absolute_baseurl(),
   15.48          module = redirect_data.module,
   15.49 @@ -194,28 +192,18 @@
   15.50          anchor = redirect_data.anchor
   15.51        }
   15.52      )
   15.53 -    cgi.send_data()
   15.54 +    request._http_request:finish()
   15.55    end
   15.56  
   15.57    if not success or not redirect_data then
   15.58  
   15.59 -    local http_status = request.get_status()
   15.60 -    if http_status then
   15.61 -      cgi.set_status(http_status)
   15.62 +    request._http_request:send_status(request._status or "200 OK")
   15.63 +    for i, header in ipairs(request._response_headers) do
   15.64 +      request._http_request:send_header(header[1], header[2])
   15.65      end
   15.66 -
   15.67 -    local json_request_slots = request.get_json_request_slots()
   15.68 -    if json_request_slots then
   15.69 -      cgi.set_content_type('application/json')
   15.70 -      local data = {}
   15.71 -      for idx, slot_ident in ipairs(json_request_slots) do
   15.72 -        data[slot_ident] = slot.get_content(slot_ident)
   15.73 -      end
   15.74 -      cgi.send_data(encode.json(data))
   15.75 -    else
   15.76 -      cgi.set_content_type(slot.get_content_type())
   15.77 -      cgi.send_data(slot.render_layout())
   15.78 -    end
   15.79 +    request._http_request:send_header("Content-Type", slot.get_content_type())
   15.80 +    request._http_request:send_data(slot.render_layout())
   15.81 +    request._http_request:finish()
   15.82    end
   15.83  
   15.84  end
    16.1 --- a/framework/env/request/set_allowed_json_request_slots.lua	Fri Feb 27 17:18:08 2015 +0100
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,25 +0,0 @@
    16.4 ---[[--
    16.5 -request.set_allowed_json_request_slots(
    16.6 -  slot_idents                            -- list of names of slots which can be requested in JSON format
    16.7 -)
    16.8 -
    16.9 -This function enables JSON requests. The given list of names of slots selects, which slots may be requestd in JSON format (without layout).
   16.10 -
   16.11 ---]]--
   16.12 -
   16.13 -function request.set_allowed_json_request_slots(slot_idents)
   16.14 -  if cgi then  -- do nothing, when being in interactive mode
   16.15 -    local hash = {}
   16.16 -    for idx, slot_ident in ipairs(slot_idents) do
   16.17 -      hash[slot_ident] = true
   16.18 -    end
   16.19 -    if cgi.params["_webmcp_json_slots[]"] then
   16.20 -      for idx, slot_ident in ipairs(cgi.params["_webmcp_json_slots[]"]) do
   16.21 -        if not hash[slot_ident] then
   16.22 -          error('Requesting slot "' .. slot_ident .. '" is forbidden.')
   16.23 -        end
   16.24 -      end
   16.25 -    end
   16.26 -    request._json_requests_allowed = true
   16.27 -  end
   16.28 -end
    17.1 --- a/framework/env/request/set_cookie.lua	Fri Feb 27 17:18:08 2015 +0100
    17.2 +++ b/framework/env/request/set_cookie.lua	Fri Feb 27 21:49:00 2015 +0100
    17.3 @@ -12,32 +12,45 @@
    17.4  --]]--
    17.5  
    17.6  function request.set_cookie(args)
    17.7 -  local path = args.path
    17.8 -  if not path then
    17.9 -    path = string.match(
   17.10 +  local args = table.new(args)
   17.11 +  if not args.path then
   17.12 +    args.path = string.match(
   17.13        request.get_absolute_baseurl(),
   17.14        "://[^/]*(.*)"
   17.15      )
   17.16 -    if path == nil or path == "" then
   17.17 +    if path == nil then
   17.18        path = "/"
   17.19      end
   17.20    end
   17.21 -  local secure = args.secure
   17.22 -  if secure == nil then
   17.23 +  if args.secure == nil then
   17.24      if string.find(
   17.25        string.lower(request.get_absolute_baseurl()),
   17.26        "^https://"
   17.27      ) then
   17.28 -      secure = true
   17.29 +      args.secure = true
   17.30      else
   17.31 -      secure = false
   17.32 +      args.secure = false
   17.33      end
   17.34    end
   17.35 -  cgi.set_cookie{
   17.36 -    name   = args.name,
   17.37 -    value  = args.value,
   17.38 -    domain = args.domain,
   17.39 -    path   = path,
   17.40 -    secure = secure
   17.41 -  }
   17.42 +  assert(string.find(args.name, "^[0-9A-Za-z%%._~-]+$"), "Illegal cookie name")
   17.43 +  assert(string.find(args.value, "^[0-9A-Za-z%%._~-]+$"), "Illegal cookie value")
   17.44 +  local parts = {args.name .. "=" .. args.value}
   17.45 +  if args.domain then
   17.46 +    assert(
   17.47 +      string.find(args.path, "^[0-9A-Za-z%%/._~-]+$"),
   17.48 +      "Illegal cookie domain"
   17.49 +    )
   17.50 +    parts[#parts+1] = "domain=" .. args.domain
   17.51 +  end
   17.52 +  if args.path then
   17.53 +    assert(
   17.54 +      string.find(args.path, "^[0-9A-Za-z%%/._~-]+$"),
   17.55 +      "Illegal cookie path"
   17.56 +    )
   17.57 +    parts[#parts+1] = "path=" .. args.path
   17.58 +  end
   17.59 +  if args.secure then
   17.60 +    parts[#parts+1] = "secure"
   17.61 +  end
   17.62 +  request.add_header("Set-Cookie", table.concat(parts, "; "))
   17.63  end
    18.1 --- a/framework/env/request/set_csrf_secret.lua	Fri Feb 27 17:18:08 2015 +0100
    18.2 +++ b/framework/env/request/set_csrf_secret.lua	Fri Feb 27 21:49:00 2015 +0100
    18.3 @@ -10,7 +10,7 @@
    18.4  function request.set_csrf_secret(secret)
    18.5    if
    18.6      request.get_action() and
    18.7 -    cgi.params._webmcp_csrf_secret ~= secret
    18.8 +    request._http_request.post_params["_webmcp_csrf_secret"] ~= secret
    18.9    then
   18.10      error("Cross-Site Request Forgery attempt detected");
   18.11    end
    19.1 --- a/framework/env/trace/_render_sub_tree.lua	Fri Feb 27 17:18:08 2015 +0100
    19.2 +++ b/framework/env/trace/_render_sub_tree.lua	Fri Feb 27 21:49:00 2015 +0100
    19.3 @@ -166,6 +166,7 @@
    19.4      open_head(node)
    19.5      slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
    19.6      close_with_children()
    19.7 +  --[[
    19.8    elseif node_type == "exectime" then
    19.9      open("exectime")
   19.10      open_head(node)
   19.11 @@ -177,6 +178,7 @@
   19.12        ' ms CPU)'
   19.13      )
   19.14      close_with_children()
   19.15 +  --]]
   19.16    elseif node_type == "sql" then
   19.17      open("sql")
   19.18      if node.error_position then
    20.1 --- a/framework/env/trace/exectime.lua	Fri Feb 27 17:18:08 2015 +0100
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,23 +0,0 @@
    20.4 ---[[--
    20.5 -trace.exectime{
    20.6 -  real = real,   -- physical time in seconds
    20.7 -  cpu  = cpu     -- CPU time in seconds
    20.8 -}
    20.9 -
   20.10 -This function is called automatically to log the execution time of the handling of a request.
   20.11 -
   20.12 ---]]--
   20.13 -
   20.14 -function trace.exectime(args)
   20.15 -  if not trace._disabled then
   20.16 -    local real = args.real
   20.17 -    local cpu  = args.cpu
   20.18 -    if type(real) ~= "number" then
   20.19 -      error("Called trace.exectime{...} without numeric 'real' argument.")
   20.20 -    end
   20.21 -    if type(cpu) ~= "number" then
   20.22 -      error("Called trace.exectime{...} without numeric 'cpu' argument.")
   20.23 -    end
   20.24 -    trace._new_entry{ type = "exectime", real = args.real, cpu = args.cpu }
   20.25 -  end
   20.26 -end
    21.1 --- a/framework/env/ui/__init.lua	Fri Feb 27 17:18:08 2015 +0100
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,2 +0,0 @@
    21.4 -ui._partial_loading_enabled = false
    21.5 -ui._partial_state = nil
    22.1 --- a/framework/env/ui/_partial_load_js.lua	Fri Feb 27 17:18:08 2015 +0100
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,137 +0,0 @@
    22.4 ---[[--
    22.5 -ui._partial_load_js(
    22.6 -  {
    22.7 -    module = module,
    22.8 -    view   = view,
    22.9 -    id     = id,
   22.10 -    params = params,
   22.11 -    target = target
   22.12 -  },
   22.13 -  mode = mode
   22.14 -}
   22.15 -
   22.16 -This function is not supposed to be called directly, but only to be used by
   22.17 -ui.link{...} and ui.form{...}.
   22.18 -
   22.19 -It returns a JavaScript which can be used for onclick or onsubmit
   22.20 -attributes in HTML to cause a partial load of contents. Behaviour differs
   22.21 -for the following cases:
   22.22 -a) module, view and target (and optionally id) are given as parameters
   22.23 -b) neither module, view, id, nor target are given as parameters
   22.24 -
   22.25 -In case of a) the function will create a JavaScript which requests the
   22.26 -given view (optionally with the given id and params) as JSON data.
   22.27 -
   22.28 -In case of b) the function will create a JavaScript requesting the view
   22.29 -specified by the next outer ui.partial{...} call as JSON data. Request
   22.30 -parameters specified by previous calls of add_partial_param_names({...})
   22.31 -are copied from the GET/POST parameters of the current request, while they
   22.32 -can be overwritten using the "params" argument to this function.
   22.33 -
   22.34 -If there is no outer ui.partial{...} call in case b), then this function
   22.35 -returns nil.
   22.36 -
   22.37 -The called URL contains "_webmcp_json_slots[]" as GET parameters to
   22.38 -indicate that slot contents should be returned as a JSON object, instead of
   22.39 -being inserted to a page layout.
   22.40 -
   22.41 -TODO: Currently the slots requested are "default", "trace" and
   22.42 -"system_error". The target for the slot "default" is passed as argument to
   22.43 -this function or to ui.partial{...}. The targets for the slots "trace" and
   22.44 -"system_error" are "trace" and "system_error". This is hardcoded and should
   22.45 -be possible to change in future. The JavaScript will fail, if there are no
   22.46 -HTML elements with id's "trace" and "system_error".
   22.47 -
   22.48 -A mode can be passed as second parameter to this function. When this mode
   22.49 -is "nil" or non existent, the function creates JavaScript code to be used
   22.50 -as onclick event for normal (GET) links. When mode is set to "form_normal"
   22.51 -or "form_action", the returned code can be used as onsubmit event of web
   22.52 -forms. "form_normal" is used when the form calls a view, "form_action" is
   22.53 -used when the form calls an action.
   22.54 -
   22.55 ---]]--
   22.56 -
   22.57 -function ui._partial_load_js(args, mode)
   22.58 -  local args = args or {}
   22.59 -  local module
   22.60 -  local view
   22.61 -  local id
   22.62 -  local params = {}
   22.63 -  local target
   22.64 -  if args.view and args.target then
   22.65 -    module = args.module
   22.66 -    view   = args.view
   22.67 -    id     = args.id
   22.68 -    target = args.target
   22.69 -  elseif not args.view and not args.target then
   22.70 -    if not ui._partial_state then
   22.71 -      return nil
   22.72 -    end
   22.73 -    module = ui._partial_state.module
   22.74 -    view   = ui._partial_state.view
   22.75 -    id     = ui._partial_state.id
   22.76 -    target = ui._partial_state.target
   22.77 -  else
   22.78 -    error("Unexpected arguments passed to ui._partial_load_js{...}")
   22.79 -  end
   22.80 -
   22.81 -  if ui._partial_state then
   22.82 -    -- TODO: do this only if args.view and args.target are unset!?
   22.83 -    if ui._partial_state.params then
   22.84 -      for key, value in pairs(ui._partial_state.params) do
   22.85 -        params[key] = value
   22.86 -      end
   22.87 -    end
   22.88 -    for param_name, dummy in pairs(ui._partial_state.param_name_hash) do
   22.89 -      params[param_name] = cgi.params[param_name]
   22.90 -    end
   22.91 -  end
   22.92 -  if args.params then
   22.93 -    for key, value in pairs(args.params) do
   22.94 -      params[key] = value
   22.95 -    end
   22.96 -  end
   22.97 -  local encoded_url = encode.json(
   22.98 -    encode.url{
   22.99 -      module = module,
  22.100 -      view   = view,
  22.101 -      id     = id,
  22.102 -      params = params
  22.103 -    }
  22.104 -  )
  22.105 -
  22.106 -  if mode == "form_normal" then
  22.107 -    -- NOTE: action in "action_mode" refers to WebMCP actions, while action
  22.108 -    -- in "this.action" refers to the action attribute of HTML forms
  22.109 -    slot.put('this.action = ', encoded_url, '; ')
  22.110 -  end
  22.111 -
  22.112 -  return slot.use_temporary(function()
  22.113 -    slot.put(
  22.114 -      'partialMultiLoad({',
  22.115 -        -- mapping:
  22.116 -        '"trace": "trace", "system_error": "system_error", ',
  22.117 -        encode.json(target), ': "default" }, ',
  22.118 -        -- tempLoadingContents:
  22.119 -        '{}, ',
  22.120 -        -- failureContents:
  22.121 -        '"error", ',
  22.122 -        -- url:
  22.123 -        (mode == "form_normal" or mode == "form_action") and (
  22.124 -          'this'
  22.125 -        ) or (
  22.126 -          encoded_url
  22.127 -        ), ', ',
  22.128 -        -- urlParams:
  22.129 -        '"_webmcp_json_slots[]=default&_webmcp_json_slots[]=trace&_webmcp_json_slots[]=system_error", ',
  22.130 -        -- postParams:
  22.131 -        '{}, ',
  22.132 -        -- successHandler:
  22.133 -        'function() {}, ',
  22.134 -        -- failureHandler:
  22.135 -        'function() {} ',
  22.136 -      '); ',
  22.137 -      'return false;'
  22.138 -    )
  22.139 -  end)
  22.140 -end
    23.1 --- a/framework/env/ui/add_partial_param_names.lua	Fri Feb 27 17:18:08 2015 +0100
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,18 +0,0 @@
    23.4 ---[[--
    23.5 -ui.add_partial_param_names(
    23.6 -  name_list
    23.7 -)
    23.8 -
    23.9 -This function adds names of GET/POST parameters to the list of parameters
   23.10 -which are to be copied when calling ui._partial_load_js{...} or
   23.11 -ui.link{..., partial = {...}} or ui.form{..., partial = {...}}.
   23.12 -
   23.13 ---]]--
   23.14 -
   23.15 -function ui.add_partial_param_names(name_list)
   23.16 -  if ui._partial_state then
   23.17 -    for idx, param_name in ipairs(name_list) do
   23.18 -      ui._partial_state.param_name_hash[param_name] = true
   23.19 -    end
   23.20 -  end
   23.21 -end
    24.1 --- a/framework/env/ui/enable_partial_loading.lua	Fri Feb 27 17:18:08 2015 +0100
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,19 +0,0 @@
    24.4 ---[[--
    24.5 -ui.enable_partial_loading()
    24.6 -
    24.7 -This function tells subsequent calls of ui.link{...} and ui.form{...} that
    24.8 -partial loading should be enabled when requested by passing "partial"
    24.9 -arguments to ui.link or ui.form.
   24.10 -
   24.11 -NOTE: To use partial loading, the slots being requested need to be
   24.12 -white-listed by calling request.set_allowed_json_request_slots({...})
   24.13 -in the application configuration file. TODO: By now, at least the slot
   24.14 -names "default", "trace" and "system_error" need to be white-listed, as
   24.15 -these slots are currently hardwired in ui._partial_load_js(...).
   24.16 -
   24.17 ---]]--
   24.18 -
   24.19 -function ui.enable_partial_loading()
   24.20 -  ui._partial_loading_enabled = true
   24.21 -  request.force_absolute_baseurl()
   24.22 -end
    25.1 --- a/framework/env/ui/filters.lua	Fri Feb 27 17:18:08 2015 +0100
    25.2 +++ b/framework/env/ui/filters.lua	Fri Feb 27 21:49:00 2015 +0100
    25.3 @@ -55,7 +55,7 @@
    25.4                local current_options = {}
    25.5                for idx, filter in ipairs(args) do
    25.6                  local filter_name = filter.name or "filter"
    25.7 -                local current_option = atom.string:load(cgi.params[filter_name])
    25.8 +                local current_option = atom.string:load(request.get_param{name=filter_name})
    25.9                  if not current_option then
   25.10                    current_option = param.get(filter_name)
   25.11                  end
   25.12 @@ -90,7 +90,7 @@
   25.13          content = function()
   25.14            for idx, filter in ipairs(args) do
   25.15              local filter_name = filter.name or "filter"
   25.16 -            local current_option = atom.string:load(cgi.params[filter_name])
   25.17 +            local current_option = atom.string:load(request.get_param{name=filter_name})
   25.18              if not current_option then
   25.19                current_option = param.get(filter_name)
   25.20              end
   25.21 @@ -116,12 +116,7 @@
   25.22                      view    = request.get_view(),
   25.23                      id      = id,
   25.24                      params  = params,
   25.25 -                    text    = option.label,
   25.26 -                    partial = {
   25.27 -                      params = {
   25.28 -                        [filter_name] = option.name
   25.29 -                      }
   25.30 -                    }
   25.31 +                    text    = option.label
   25.32                    }
   25.33                  end
   25.34                end
    26.1 --- a/framework/env/ui/form.lua	Fri Feb 27 17:18:08 2015 +0100
    26.2 +++ b/framework/env/ui/form.lua	Fri Feb 27 21:49:00 2015 +0100
    26.3 @@ -20,13 +20,6 @@
    26.4      error = { ... },      -- routing when "error" is returned by the called action
    26.5      ...   = { ... }       -- routing when "..."   is returned by the called action
    26.6    },
    26.7 -  partial = {             -- parameters for partial loading, see below
    26.8 -    module = module,
    26.9 -    view   = view,
   26.10 -    id     = id,
   26.11 -    params = params,
   26.12 -    target = target
   26.13 -  },
   26.14    content = function()
   26.15      ...                   -- code creating the contents of the form
   26.16    end
   26.17 @@ -34,10 +27,6 @@
   26.18  
   26.19  This functions creates a web form, which encloses the content created by the given 'content' function. When a 'record' is given, ui.field.* helper functions will be able to automatically determine field values by using the given record. If 'read_only' is set to true, then a call of ui.submit{...} will be ignored, and ui.field.* helper functions will behave differently.
   26.20  
   26.21 -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
   26.22 -used to create an onsubmit event. The "partial" setting table is passed to ui._partial_load_js as first argument. See ui._partial_load_js(...) for
   26.23 -further documentation.
   26.24 -
   26.25  --]]--
   26.26  
   26.27  local function prepare_routing_params(params, routing, default_module)
   26.28 @@ -99,45 +88,6 @@
   26.29        action    = args.action,
   26.30      }
   26.31      attr.method = args.method and string.upper(args.method) or "POST"
   26.32 -    if ui.is_partial_loading_enabled() and args.partial then
   26.33 -      attr.onsubmit = slot.use_temporary(function()
   26.34 -        local partial_mode = "form_normal"
   26.35 -        if args.action then
   26.36 -          partial_mode = "form_action"
   26.37 -          slot.put(
   26.38 -            'var element; ',
   26.39 -            'var formElements = []; ',
   26.40 -            'for (var i=0; i<this.elements.length; i++) { ',
   26.41 -              'formElements[formElements.length] = this.elements[i]; ',
   26.42 -            '} ',
   26.43 -            'for (i=0; i<formElements.length; i++) { ',
   26.44 -              'element = formElements[i]; ',
   26.45 -              'if (element.name.search(/^_webmcp_routing\\./) >= 0) { ',
   26.46 -                'element.parentNode.removeChild(element); ',
   26.47 -              '} ',
   26.48 -            '}'
   26.49 -          )
   26.50 -          local routing_params = {}
   26.51 -          prepare_routing_params(
   26.52 -            routing_params,
   26.53 -            args.partial.routing,
   26.54 -            args.partial.module
   26.55 -          )
   26.56 -          for key, value in pairs(routing_params) do
   26.57 -            slot.put(
   26.58 -              ' ',
   26.59 -              'element = document.createElement("input"); ',
   26.60 -              'element.setAttribute("type", "hidden"); ',
   26.61 -              'element.setAttribute("name", ', encode.json(key), '); ',
   26.62 -              'element.setAttribute("value", ', encode.json(value), '); ',
   26.63 -              'this.appendChild(element);'
   26.64 -            )
   26.65 -          end
   26.66 -          slot.put(' ')
   26.67 -        end
   26.68 -        slot.put(ui._partial_load_js(args.partial, partial_mode))
   26.69 -      end)
   26.70 -    end
   26.71      if slot_state.form_opened then
   26.72        error("Cannot open a non-readonly form inside a non-readonly form.")
   26.73      end
    27.1 --- a/framework/env/ui/is_partial_loading_enabled.lua	Fri Feb 27 17:18:08 2015 +0100
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,12 +0,0 @@
    27.4 ---[[--
    27.5 -result =
    27.6 -ui.is_partial_loading_enabled()
    27.7 -
    27.8 -This function returns true, if partial loading has been enabled by calling
    27.9 -ui.enable_partial_loading().
   27.10 -
   27.11 ---]]--
   27.12 -
   27.13 -function ui.is_partial_loading_enabled()
   27.14 -  return ui._partial_loading_enabled
   27.15 -end
    28.1 --- a/framework/env/ui/link.lua	Fri Feb 27 17:18:08 2015 +0100
    28.2 +++ b/framework/env/ui/link.lua	Fri Feb 27 21:49:00 2015 +0100
    28.3 @@ -13,23 +13,11 @@
    28.4    routing   = routing,    -- optional routing information for action links, as described for ui.form{...}
    28.5    anchor    = anchor,     -- for views: anchor in destination URL
    28.6    text      = text,       -- link text
    28.7 -  content   = content,    -- link content (overrides link text, except for submit buttons for action calls without JavaScript)
    28.8 -  partial   = {           -- parameters for partial loading, see below
    28.9 -    module = module,
   28.10 -    view   = view,
   28.11 -    id     = id,
   28.12 -    params = params,
   28.13 -    target = target
   28.14 -  }
   28.15 +  content   = content     -- link content (overrides link text, except for submit buttons for action calls without JavaScript)
   28.16  }
   28.17  
   28.18  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).
   28.19  
   28.20 -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
   28.21 -used to create an onclick event (onsubmit event for action links). The
   28.22 -"partial" setting table is passed to ui._partial_load_js as first argument.
   28.23 -See ui._partial_load_js(...) for further documentation.
   28.24 -
   28.25  --]]--
   28.26  
   28.27  function ui.link(args)
   28.28 @@ -67,7 +55,6 @@
   28.29        id       = args.id,
   28.30        params   = args.params,
   28.31        routing  = args.routing,
   28.32 -      partial  = args.partial,
   28.33        attr     = form_attr,
   28.34        content  = function()
   28.35          ui.submit{ text = args.text, attr = args.submit_attr }
   28.36 @@ -105,9 +92,6 @@
   28.37        params    = args.params,
   28.38        anchor    = args.anchor
   28.39      }
   28.40 -    if ui.is_partial_loading_enabled() and args.partial then
   28.41 -      a_attr.onclick = ui._partial_load_js(args.partial)
   28.42 -    end
   28.43      return ui.tag{ tag  = "a", attr = a_attr, content = wrapped_content }
   28.44    end
   28.45  end
    29.1 --- a/framework/env/ui/paginate.lua	Fri Feb 27 17:18:08 2015 +0100
    29.2 +++ b/framework/env/ui/paginate.lua	Fri Feb 27 21:49:00 2015 +0100
    29.3 @@ -11,7 +11,7 @@
    29.4    end
    29.5  }
    29.6  
    29.7 -This function preceeds and appends the output of the given 'content' function with page selection links. The passed selector will be modified to show only a limited amount ('per_page') of items. The currently displayed page will be determined directly by cgi.params, and not via the param.get(...) function, in order to pass page selections automatically to sub-views.
    29.8 +This function preceeds and appends the output of the given 'content' function with page selection links. The passed selector will be modified to show only a limited amount ('per_page') of items. The currently displayed page will be determined directly by request.get_param{...}, and not via the param.get(...) function, in order to pass page selections automatically to sub-views.
    29.9  
   29.10  --]]--
   29.11  
   29.12 @@ -29,7 +29,7 @@
   29.13    if count > 0 then
   29.14      page_count = math.floor((count - 1) / per_page) + 1
   29.15    end
   29.16 -  local current_page = atom.integer:load(cgi.params[name]) or 1
   29.17 +  local current_page = atom.integer:load(request.get_param{name=name}) or 1
   29.18    if current_page > page_count then
   29.19      current_page = page_count
   29.20    end
   29.21 @@ -48,14 +48,6 @@
   29.22          if current_page == page then
   29.23            attr.class = "active"
   29.24          end
   29.25 -        local partial
   29.26 -        if ui.is_partial_loading_enabled() then
   29.27 -          partial = {
   29.28 -            params = {
   29.29 -              [name] = tostring(page)
   29.30 -            }
   29.31 -          }
   29.32 -        end
   29.33          ui.link{
   29.34            attr   = attr,
   29.35            module = request.get_module(),
   29.36 @@ -63,8 +55,7 @@
   29.37            id     = id,
   29.38            params = params,
   29.39            anchor = args.anchor,
   29.40 -          text   = tostring(page),
   29.41 -          partial = partial
   29.42 +          text   = tostring(page)
   29.43          }
   29.44        end
   29.45      end
    30.1 --- a/framework/env/ui/partial.lua	Fri Feb 27 17:18:08 2015 +0100
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,32 +0,0 @@
    30.4 ---[[--
    30.5 -ui.partial{
    30.6 -  module  = module,     -- module to be used to reload inner contents
    30.7 -  view    = view,       -- view   to be used to reload inner contents
    30.8 -  id      = id,         -- id     to be used to reload inner contents
    30.9 -  params  = params,     -- params to be used to reload inner contents
   30.10 -  target  = target,     -- id of HTML element containing contents to be replaced
   30.11 -  content = function()
   30.12 -    ...
   30.13 -  end
   30.14 -}
   30.15 -
   30.16 -Calling this function declares that the inner contents can be requested
   30.17 -directly via the given module, view, id and params. The parameter "target"
   30.18 -specifies the id of the HTML element, which should be replaced when
   30.19 -reloading partially.
   30.20 -
   30.21 -The function has an effect on inner calls of ui.link{..., partial = {...}}
   30.22 -and ui.form{..., partial = {...}}.
   30.23 -
   30.24 ---]]--
   30.25 -
   30.26 -function ui.partial(args)
   30.27 -  local old_state = ui._partial_state
   30.28 -  ui._partial_state = table.new(args)
   30.29 -  ui._partial_state.param_name_hash = {}
   30.30 -  if args.param_names then
   30.31 -    ui.add_partial_param_names(args.param_names)
   30.32 -  end
   30.33 -  args.content()
   30.34 -  ui._partial_state = old_state
   30.35 -end
    31.1 --- a/framework/js/partialload.js	Fri Feb 27 17:18:08 2015 +0100
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,271 +0,0 @@
    31.4 -
    31.5 -partialload_queue = [];
    31.6 -partialload_queueRPos = 0;
    31.7 -partialload_queueWPos = 0;
    31.8 -
    31.9 -function partialload_getFormKeyValuePairs(form) {
   31.10 -  var result = {};
   31.11 -  for (var i=0; i<form.elements.length; i++) {
   31.12 -    var inputElement = form.elements[i];
   31.13 -    var key = inputElement.name;
   31.14 -    var value = inputElement.value;
   31.15 -    if (result[key] == null) result[key] = value;
   31.16 -    else if (typeof(result[key]) == "object") {
   31.17 -      result[key][result[key].length] = value;
   31.18 -    } else {
   31.19 -      result[key] = [result[key], value];
   31.20 -    }
   31.21 -  }
   31.22 -  return result;
   31.23 -}
   31.24 -
   31.25 -function partialload_encodeFormData(params) {
   31.26 -  var result = "";
   31.27 -  for (var key in params) {
   31.28 -    var value = params[key];
   31.29 -    if (value instanceof Array) {
   31.30 -      var i;
   31.31 -      for (i=0; i<value.length; i++) {
   31.32 -        if (result != "") result += "&";
   31.33 -        result += encodeURIComponent(key) + "=" + encodeURIComponent(value[i].toString());
   31.34 -      }
   31.35 -    } else {
   31.36 -      if (result != "") result += "&";
   31.37 -      result += encodeURIComponent(key) + "=" + encodeURIComponent(value.toString());
   31.38 -    }
   31.39 -  }
   31.40 -  return result;
   31.41 -}
   31.42 -
   31.43 -function partialload_addFormDataToUrl(url, params) {
   31.44 -  if (params != null && typeof(params) != "string") {
   31.45 -    params = partialload_encodeFormData(params);
   31.46 -  }
   31.47 -  if (params != null) {
   31.48 -    if (url.search(/\?/) >= 0) {
   31.49 -      if (url.search(/&$/) >= 0) {
   31.50 -        url = url + params;
   31.51 -      } else {
   31.52 -        url = url + "&" + params;
   31.53 -      }
   31.54 -    } else {
   31.55 -      url = url + "?" + params;
   31.56 -    }
   31.57 -  }
   31.58 -  return url;
   31.59 -}
   31.60 -
   31.61 -function partialload_mergeEncodedFormData(data1, data2) {
   31.62 -  if (data2 == null || data2 == "") return data1;
   31.63 -  if (data1 == null || data1 == "") return data2;
   31.64 -  return data1 + "&" + data2;
   31.65 -}
   31.66 -
   31.67 -function partialload_startNextRequest() {
   31.68 -  var entry = partialload_queue[partialload_queueRPos++];
   31.69 -  var req = new XMLHttpRequest();
   31.70 -  req.open(entry.method, entry.url, true);
   31.71 -  req.onreadystatechange = function() {
   31.72 -    if (req.readyState == 4) {
   31.73 -      if (req.status == 200) {
   31.74 -        if (entry.successHandler != null) entry.successHandler(req.responseText);
   31.75 -      } else {
   31.76 -        if (entry.failureHandler != null) entry.failureHandler();
   31.77 -      }
   31.78 -      if (partialload_queue[partialload_queueRPos]) {
   31.79 -        partialload_startNextRequest();
   31.80 -      } else {
   31.81 -        partialload_queue = [];
   31.82 -        partialload_queueRPos = 0;
   31.83 -        partialload_queueWPos = 0;
   31.84 -      }
   31.85 -    }
   31.86 -  }
   31.87 -  if (entry.data) {
   31.88 -    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   31.89 -  }
   31.90 -  req.send(entry.data);
   31.91 -}
   31.92 -
   31.93 -function queuedHttpRequest(
   31.94 -  url_or_form,
   31.95 -  urlParams,
   31.96 -  postParams,
   31.97 -  successHandler,
   31.98 -  failureHandler
   31.99 -) {
  31.100 -  var method;
  31.101 -  var data = null;
  31.102 -  if (typeof(postParams) == "string") {
  31.103 -    data = postParams;
  31.104 -  } else if (postParams != null) {
  31.105 -    data = partialload_encodeFormData(postParams);
  31.106 -  }
  31.107 -  var url;
  31.108 -  if (typeof(url_or_form) == "object") {
  31.109 -    // form element given
  31.110 -    var form = url_or_form;
  31.111 -    url = partialload_addFormDataToUrl(form.action, urlParams);
  31.112 -    var dataFromForm = partialload_encodeFormData(
  31.113 -      partialload_getFormKeyValuePairs(form)
  31.114 -    );
  31.115 -    if (form.method != null && form.method.search(/^POST$/i) >= 0) {
  31.116 -      method = "POST";
  31.117 -      data = partialload_mergeEncodedFormData(data, dataFromForm);
  31.118 -    } else {
  31.119 -      method = (postParams == NULL) ? "GET" : "POST";
  31.120 -      url = partialload_addFormDataToUrl(url, dataFromForm);
  31.121 -    }
  31.122 -  } else {
  31.123 -    // URL given
  31.124 -    url = partialload_addFormDataToUrl(url_or_form, urlParams);
  31.125 -    if (postParams == null) {
  31.126 -      method = "GET";
  31.127 -    } else {
  31.128 -      method = "POST";
  31.129 -      if (typeof(postParams) == "string") {
  31.130 -	data = postParams;
  31.131 -      } else {
  31.132 -	data = partialload_encodeFormData(postParams);
  31.133 -      }
  31.134 -    }
  31.135 -  }
  31.136 -  partialload_queue[partialload_queueWPos++] = {
  31.137 -    method:         method,
  31.138 -    url:            url,
  31.139 -    data:           data,
  31.140 -    successHandler: successHandler,
  31.141 -    failureHandler: failureHandler
  31.142 -  };
  31.143 -  if (partialload_queueRPos == 0) {
  31.144 -    partialload_startNextRequest();
  31.145 -  }
  31.146 -}
  31.147 -
  31.148 -function setHtmlContent(node, htmlWithScripts) {
  31.149 -  var uniquePrefix = "placeholder" + Math.floor(Math.random()*10e16) + "_";
  31.150 -  var i = 0;
  31.151 -  var scripts = [];
  31.152 -  var htmlWithPlaceholders = "";
  31.153 -  // NOTE: This function can not handle CDATA blocks at random positions.
  31.154 -  htmlWithPlaceholders = htmlWithScripts.replace(
  31.155 -    /<script[^>]*>(.*?)<\/script>/ig,
  31.156 -    function(all, inside) {
  31.157 -      scripts[i] = inside;
  31.158 -      var placeholder = '<span id="' + uniquePrefix + i + '"></span>';
  31.159 -      i++;
  31.160 -      return placeholder;
  31.161 -    }
  31.162 -  )
  31.163 -  node.innerHTML = htmlWithPlaceholders;
  31.164 -  var documentWriteBackup   = document.write;
  31.165 -  var documentWritelnBackup = document.writeln;
  31.166 -  var output;
  31.167 -  document.write   = function(str) { output += str; }
  31.168 -  document.writeln = function(str) { output += str + "\n"; }
  31.169 -  for (i=0; i<scripts.length; i++) {
  31.170 -    var placeholderNode = document.getElementById(uniquePrefix + i);
  31.171 -    output = "";
  31.172 -    eval(scripts[i]);
  31.173 -    if (output != "") {
  31.174 -      placeholderNode.innerHTML = output;
  31.175 -      while (placeholderNode.childNodes.length > 0) {
  31.176 -        var childNode = placeholderNode.childNodes[0];
  31.177 -        placeholderNode.removeChild(childNode);
  31.178 -        placeholderNode.parentNode.insertBefore(childNode, placeholderNode);
  31.179 -      }
  31.180 -    }
  31.181 -    placeholderNode.parentNode.removeChild(placeholderNode);
  31.182 -  }
  31.183 -  document.write   = documentWriteBackup;
  31.184 -  document.writeln = documentWritelnBackup;
  31.185 -}
  31.186 -
  31.187 -function partialLoad(
  31.188 -  node,
  31.189 -  tempLoadingContent,
  31.190 -  failureContent,
  31.191 -  url_or_form,
  31.192 -  urlParams,
  31.193 -  postParams,
  31.194 -  successHandler,
  31.195 -  failureHandler
  31.196 -) {
  31.197 -  if (typeof(node) == "string") node = document.getElementById(node);
  31.198 -  if (tempLoadingContent != null) setHtmlContent(node, tempLoadingContent);
  31.199 -  queuedHttpRequest(
  31.200 -    url_or_form,
  31.201 -    urlParams,
  31.202 -    postParams,
  31.203 -    function(response) {
  31.204 -      setHtmlContent(node, response);
  31.205 -      if (successHandler != null) successHandler();
  31.206 -    },
  31.207 -    function() {
  31.208 -      if (failureContent != null) setHtmlContent(node, failureContent);
  31.209 -      if (failureHandler != null) failureHandler();
  31.210 -    }
  31.211 -  );
  31.212 -}
  31.213 -
  31.214 -function partialMultiLoad(
  31.215 -  mapping,
  31.216 -  tempLoadingContents,
  31.217 -  failureContents,
  31.218 -  url_or_form,
  31.219 -  urlParams,
  31.220 -  postParams,
  31.221 -  successHandler,
  31.222 -  failureHandler
  31.223 -) {
  31.224 -  if (mapping instanceof Array) {
  31.225 -    var mappingHash = {}
  31.226 -    for (var i=0; i<mapping.length; i++) {
  31.227 -      mappingHash[mapping[i]] = mapping[i];
  31.228 -    }
  31.229 -    mapping = mappingHash;
  31.230 -  }
  31.231 -  if (typeof(tempLoadingContents) == "string") {
  31.232 -    for (var key in mapping) {
  31.233 -      var node = key;
  31.234 -      if (typeof(node) == "string") node = document.getElementById(node);
  31.235 -      setHtmlContent(node, tempLoadingContents);
  31.236 -    }
  31.237 -  } else if (tempLoadingContents != null) {
  31.238 -    for (var key in tempLoadingContents) {
  31.239 -      var node = key;
  31.240 -      if (typeof(node) == "string") node = document.getElementById(node);
  31.241 -      setHtmlContent(node, tempLoadingContents[key]);
  31.242 -    }
  31.243 -  }
  31.244 -  queuedHttpRequest(
  31.245 -    url_or_form,
  31.246 -    urlParams,
  31.247 -    postParams,
  31.248 -    function(response) {
  31.249 -      var data = eval("(" + response + ")");
  31.250 -      for (var key in mapping) {
  31.251 -        var node = key;
  31.252 -        if (typeof(node) == "string") node = document.getElementById(node);
  31.253 -        setHtmlContent(node, data[mapping[key]]);
  31.254 -      }
  31.255 -      if (successHandler != null) successHandler();
  31.256 -    },
  31.257 -    function() {
  31.258 -      if (typeof(failureContents) == "string") {
  31.259 -        for (var key in mapping) {
  31.260 -          var node = key;
  31.261 -          if (typeof(node) == "string") node = document.getElementById(node);
  31.262 -          setHtmlContent(node, failureContents);
  31.263 -        }
  31.264 -      } else if (failureContents != null) {
  31.265 -        for (var key in failureContents) {
  31.266 -          var node = key;
  31.267 -          if (typeof(node) == "string") node = document.getElementById(node);
  31.268 -          setHtmlContent(node, failureContents[key]);
  31.269 -        }
  31.270 -      }
  31.271 -      if (failureHandler != null) failureHandler();
  31.272 -    }
  31.273 -  );
  31.274 -}

Impressum / About Us