# HG changeset patch # User jbe # Date 1425070140 -3600 # Node ID 32ec28229bb5446259032c334e6060620f33f007 # Parent 38e5399718cabf51a8059bf6a12a52a8b5fb28fb Finished removing all references to cgi module (except demo-app); Removed partial loading mechanism diff -r 38e5399718ca -r 32ec28229bb5 framework/bin/webmcp_shell --- a/framework/bin/webmcp_shell Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -#!/bin/sh -export WEBMCP_APP_BASEPATH="`pwd`" -export WEBMCP_CONFIG_NAME="$1" -export WEBMCP_INTERACTIVE="yes" -if [ "$WEBMCP_CONFIG_NAME" = "" ]; then - echo "Error: No config name given." > /dev/stderr - exit 1 -fi -cd "`dirname "$0"`/../cgi-bin" -exec lua -i webmcp.lua diff -r 38e5399718ca -r 32ec28229bb5 framework/env/auth/openid/initiate.lua --- a/framework/env/auth/openid/initiate.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/auth/openid/initiate.lua Fri Feb 27 21:49:00 2015 +0100 @@ -30,8 +30,8 @@ return nil, errmsg, errcode end -- TODO: Use request.redirect once it supports external URLs - cgi.set_status("303 See Other") - cgi.add_header( + request.set_status("303 See Other") + request.add_header( "Location: " .. encode.url{ external = dd.op_endpoint, @@ -51,6 +51,7 @@ } } ) - cgi.send_data() - exit() + error("Not implemented") -- TODO + --cgi.send_data() + --exit() end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/auth/openid/verify.lua --- a/framework/env/auth/openid/verify.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/auth/openid/verify.lua Fri Feb 27 21:49:00 2015 +0100 @@ -11,12 +11,12 @@ function auth.openid.verify(args) local args = args or {} - if cgi.params["openid.ns"] ~= "http://specs.openid.net/auth/2.0" then + if request.get_param{name="openid.ns"} ~= "http://specs.openid.net/auth/2.0" then return nil, "No indirect OpenID 2.0 message received." end - local mode = cgi.params["openid.mode"] + local mode = request.get_param{name="openid.mode"} if mode == "id_res" then - local return_to_url = cgi.params["openid.return_to"] + local return_to_url = request.get_param{name="openid.return_to"} if not return_to_url then return nil, "No return_to URL received in answer." end @@ -28,7 +28,7 @@ return nil, "return_to URL not matching." end local discovery_args = table.new(args) - local claimed_identifier = cgi.params["openid.claimed_id"] + local claimed_identifier = request.get_param{name="openid.claimed_id"} if not claimed_identifier then return nil, "No claimed identifier received." end @@ -53,7 +53,7 @@ if dd.claimed_identifier ~= cropped_identifier then return nil, "Claimed identifier does not match." end - local nonce = cgi.params["openid.response_nonce"] + local nonce = request.get_param{name="openid.response_nonce"} if not nonce then return nil, "Did not receive a response nonce." end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/auth/openid/xrds_header.lua --- a/framework/env/auth/openid/xrds_header.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/auth/openid/xrds_header.lua Fri Feb 27 21:49:00 2015 +0100 @@ -50,5 +50,5 @@ --]]-- function auth.openid.xrds_header(args) - cgi.add_header("X-XRDS-Location: " .. encode.url(args)) + request.add_header("X-XRDS-Location: " .. encode.url(args)) end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/encode/json.lua --- a/framework/env/encode/json.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/encode/json.lua Fri Feb 27 21:49:00 2015 +0100 @@ -8,6 +8,8 @@ TODO: can't distinguish unambiguously between empty object and empty list! +TODO: replace with JSON library + --]]-- -- TODO: check if numeric representations are JSON compatible diff -r 38e5399718ca -r 32ec28229bb5 framework/env/execute/config.lua --- a/framework/env/execute/config.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/execute/config.lua Fri Feb 27 21:49:00 2015 +0100 @@ -4,7 +4,7 @@ ) Executes a configuration file of the application. -This function is only used by by the webmcp.lua file in the cgi-bin/ directory. +This function is only used by by the mcp.lua file in the bin/ directory. --]]-- diff -r 38e5399718ca -r 32ec28229bb5 framework/env/param/get.lua --- a/framework/env/param/get.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/param/get.lua Fri Feb 27 21:49:00 2015 +0100 @@ -18,8 +18,8 @@ end return value else - local str = cgi.params[key] - local format_info = cgi.params[key .. "__format"] + local str = request.get_param{ name = key } + local format_info = request.get_param{ name = key .. "__format" } if not str then if not format_info then return nil diff -r 38e5399718ca -r 32ec28229bb5 framework/env/param/get_all_cgi.lua --- a/framework/env/param/get_all_cgi.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ ---[[-- -params = -param.get_all_cgi() - -Deprecated. Alias for request.get_param_strings(). - ---]]-- - --- TODO: Remove this function. - -function param.get_all_cgi() - return request.get_param_strings() -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/param/get_id_cgi.lua --- a/framework/env/param/get_id_cgi.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ ---[[-- -value = -- id as string (or other type after if params.exchange(...) has been used), or nil -param.get_id_cgi() - -Deprecated. Alias for request.get_id_string(). - ---]]-- - --- TODO: Remove this function. - -function param.get_id_cgi() - return request.get_id_string() -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/param/get_list.lua --- a/framework/env/param/get_list.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/param/get_list.lua Fri Feb 27 21:49:00 2015 +0100 @@ -23,9 +23,9 @@ end return values else - local format_info = cgi.params[key .. "__format"] + local format_info = request.get_param{ name = key .. "__format" } local parser = param._get_parser(format_info, param_type) - local raw_values = cgi.params[key .. "[]"] + local raw_values = request.get_param{ name = key .. "[]", multiple = true } local values = {} if raw_values then for idx, value in ipairs(raw_values) do diff -r 38e5399718ca -r 32ec28229bb5 framework/env/request/__init.lua --- a/framework/env/request/__init.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/request/__init.lua Fri Feb 27 21:49:00 2015 +0100 @@ -11,7 +11,6 @@ request._force_absolute_baseurl = false request._perm_params = {} request._csrf_secret = nil -request._json_requests_allowed = false request._params = {} diff -r 38e5399718ca -r 32ec28229bb5 framework/env/request/get_json_request_slots.lua --- a/framework/env/request/get_json_request_slots.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ ---[[-- -slot_idents = -- list of names of slots to be returned as JSON data -request.get_json_request_slots() - -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. - ---]]-- - -function request.get_json_request_slots(slot_idents) - if not cgi then return end - local slot_idents = cgi.params["_webmcp_json_slots[]"] - if slot_idents and not request._json_requests_allowed then - error("JSON requests have not been allowed using request.set_allowed_json_request_slots(...).") - end - return slot_idents -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/request/get_status.lua --- a/framework/env/request/get_status.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ ---[[-- -status_string = -request.get_status() - -Returns a HTTP status previously set with request.set_status(...). - ---]]-- - -function request.get_status() - return request._status -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/request/is_post.lua --- a/framework/env/request/is_post.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/request/is_post.lua Fri Feb 27 21:49:00 2015 +0100 @@ -10,6 +10,6 @@ if request._forward_processed then return false else - return cgi.method == "POST" + return request._http_request.method == "POST" end end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/request/process.lua --- a/framework/env/request/process.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/request/process.lua Fri Feb 27 21:49:00 2015 +0100 @@ -66,7 +66,7 @@ assert(routing_view, "Routing information has no view.") if routing_mode == "redirect" then local routing_params = {} - for key, value in request.get_param_strings{method="POST", include_internal=true} do + for key, value in request.get_param_strings{ method="POST", include_internal=true } do local status, stripped_key = string.match( key, "^_webmcp_routing%.([^%.]*)%.params%.(.*)$" ) @@ -140,8 +140,8 @@ if not success then trace.error{} end - -- laufzeitermittlung - trace.exectime{ real = extos.monotonic_hires_time(), cpu = os.clock() } + -- TODO: extend trace system to generally monitor execution time + -- trace.exectime{ real = extos.monotonic_hires_time(), cpu = os.clock() } slot.select('trace', trace.render) -- render trace information @@ -151,8 +151,8 @@ if not success then local errobj = error_info.errobj local stacktrace = error_info.stacktrace - if not request.get_status() and not request.get_json_request_slots() then - request.set_status("500 Internal Server Error") + if not request._status then + request._status = "500 Internal Server Error" end slot.set_layout('system_error') slot.select('system_error', function() @@ -180,11 +180,9 @@ if slot_dump ~= "" then redirect_params.tempstore = tempstore.save(slot_dump) end - local json_request_slots = request.get_json_request_slots() - if json_request_slots then - redirect_params["_webmcp_json_slots[]"] = json_request_slots - end - cgi.redirect( + request._http_request:send_status("303 See Other") + request._http_request:send_header( + "Location", encode.url{ base = request.get_absolute_baseurl(), module = redirect_data.module, @@ -194,28 +192,18 @@ anchor = redirect_data.anchor } ) - cgi.send_data() + request._http_request:finish() end if not success or not redirect_data then - local http_status = request.get_status() - if http_status then - cgi.set_status(http_status) + request._http_request:send_status(request._status or "200 OK") + for i, header in ipairs(request._response_headers) do + request._http_request:send_header(header[1], header[2]) end - - local json_request_slots = request.get_json_request_slots() - if json_request_slots then - cgi.set_content_type('application/json') - local data = {} - for idx, slot_ident in ipairs(json_request_slots) do - data[slot_ident] = slot.get_content(slot_ident) - end - cgi.send_data(encode.json(data)) - else - cgi.set_content_type(slot.get_content_type()) - cgi.send_data(slot.render_layout()) - end + request._http_request:send_header("Content-Type", slot.get_content_type()) + request._http_request:send_data(slot.render_layout()) + request._http_request:finish() end end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/request/set_allowed_json_request_slots.lua --- a/framework/env/request/set_allowed_json_request_slots.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ ---[[-- -request.set_allowed_json_request_slots( - slot_idents -- list of names of slots which can be requested in JSON format -) - -This function enables JSON requests. The given list of names of slots selects, which slots may be requestd in JSON format (without layout). - ---]]-- - -function request.set_allowed_json_request_slots(slot_idents) - if cgi then -- do nothing, when being in interactive mode - local hash = {} - for idx, slot_ident in ipairs(slot_idents) do - hash[slot_ident] = true - end - if cgi.params["_webmcp_json_slots[]"] then - for idx, slot_ident in ipairs(cgi.params["_webmcp_json_slots[]"]) do - if not hash[slot_ident] then - error('Requesting slot "' .. slot_ident .. '" is forbidden.') - end - end - end - request._json_requests_allowed = true - end -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/request/set_cookie.lua --- a/framework/env/request/set_cookie.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/request/set_cookie.lua Fri Feb 27 21:49:00 2015 +0100 @@ -12,32 +12,45 @@ --]]-- function request.set_cookie(args) - local path = args.path - if not path then - path = string.match( + local args = table.new(args) + if not args.path then + args.path = string.match( request.get_absolute_baseurl(), "://[^/]*(.*)" ) - if path == nil or path == "" then + if path == nil then path = "/" end end - local secure = args.secure - if secure == nil then + if args.secure == nil then if string.find( string.lower(request.get_absolute_baseurl()), "^https://" ) then - secure = true + args.secure = true else - secure = false + args.secure = false end end - cgi.set_cookie{ - name = args.name, - value = args.value, - domain = args.domain, - path = path, - secure = secure - } + assert(string.find(args.name, "^[0-9A-Za-z%%._~-]+$"), "Illegal cookie name") + assert(string.find(args.value, "^[0-9A-Za-z%%._~-]+$"), "Illegal cookie value") + local parts = {args.name .. "=" .. args.value} + if args.domain then + assert( + string.find(args.path, "^[0-9A-Za-z%%/._~-]+$"), + "Illegal cookie domain" + ) + parts[#parts+1] = "domain=" .. args.domain + end + if args.path then + assert( + string.find(args.path, "^[0-9A-Za-z%%/._~-]+$"), + "Illegal cookie path" + ) + parts[#parts+1] = "path=" .. args.path + end + if args.secure then + parts[#parts+1] = "secure" + end + request.add_header("Set-Cookie", table.concat(parts, "; ")) end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/request/set_csrf_secret.lua --- a/framework/env/request/set_csrf_secret.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/request/set_csrf_secret.lua Fri Feb 27 21:49:00 2015 +0100 @@ -10,7 +10,7 @@ function request.set_csrf_secret(secret) if request.get_action() and - cgi.params._webmcp_csrf_secret ~= secret + request._http_request.post_params["_webmcp_csrf_secret"] ~= secret then error("Cross-Site Request Forgery attempt detected"); end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/trace/_render_sub_tree.lua --- a/framework/env/trace/_render_sub_tree.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/trace/_render_sub_tree.lua Fri Feb 27 21:49:00 2015 +0100 @@ -166,6 +166,7 @@ open_head(node) slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) close_with_children() + --[[ elseif node_type == "exectime" then open("exectime") open_head(node) @@ -177,6 +178,7 @@ ' ms CPU)' ) close_with_children() + --]] elseif node_type == "sql" then open("sql") if node.error_position then diff -r 38e5399718ca -r 32ec28229bb5 framework/env/trace/exectime.lua --- a/framework/env/trace/exectime.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ ---[[-- -trace.exectime{ - real = real, -- physical time in seconds - cpu = cpu -- CPU time in seconds -} - -This function is called automatically to log the execution time of the handling of a request. - ---]]-- - -function trace.exectime(args) - if not trace._disabled then - local real = args.real - local cpu = args.cpu - if type(real) ~= "number" then - error("Called trace.exectime{...} without numeric 'real' argument.") - end - if type(cpu) ~= "number" then - error("Called trace.exectime{...} without numeric 'cpu' argument.") - end - trace._new_entry{ type = "exectime", real = args.real, cpu = args.cpu } - end -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/__init.lua --- a/framework/env/ui/__init.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -ui._partial_loading_enabled = false -ui._partial_state = nil diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/_partial_load_js.lua --- a/framework/env/ui/_partial_load_js.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ ---[[-- -ui._partial_load_js( - { - module = module, - view = view, - id = id, - params = params, - target = target - }, - mode = mode -} - -This function is not supposed to be called directly, but only to be used by -ui.link{...} and ui.form{...}. - -It returns a JavaScript which can be used for onclick or onsubmit -attributes in HTML to cause a partial load of contents. Behaviour differs -for the following cases: -a) module, view and target (and optionally id) are given as parameters -b) neither module, view, id, nor target are given as parameters - -In case of a) the function will create a JavaScript which requests the -given view (optionally with the given id and params) as JSON data. - -In case of b) the function will create a JavaScript requesting the view -specified by the next outer ui.partial{...} call as JSON data. Request -parameters specified by previous calls of add_partial_param_names({...}) -are copied from the GET/POST parameters of the current request, while they -can be overwritten using the "params" argument to this function. - -If there is no outer ui.partial{...} call in case b), then this function -returns nil. - -The called URL contains "_webmcp_json_slots[]" as GET parameters to -indicate that slot contents should be returned as a JSON object, instead of -being inserted to a page layout. - -TODO: Currently the slots requested are "default", "trace" and -"system_error". The target for the slot "default" is passed as argument to -this function or to ui.partial{...}. The targets for the slots "trace" and -"system_error" are "trace" and "system_error". This is hardcoded and should -be possible to change in future. The JavaScript will fail, if there are no -HTML elements with id's "trace" and "system_error". - -A mode can be passed as second parameter to this function. When this mode -is "nil" or non existent, the function creates JavaScript code to be used -as onclick event for normal (GET) links. When mode is set to "form_normal" -or "form_action", the returned code can be used as onsubmit event of web -forms. "form_normal" is used when the form calls a view, "form_action" is -used when the form calls an action. - ---]]-- - -function ui._partial_load_js(args, mode) - local args = args or {} - local module - local view - local id - local params = {} - local target - if args.view and args.target then - module = args.module - view = args.view - id = args.id - target = args.target - elseif not args.view and not args.target then - if not ui._partial_state then - return nil - end - module = ui._partial_state.module - view = ui._partial_state.view - id = ui._partial_state.id - target = ui._partial_state.target - else - error("Unexpected arguments passed to ui._partial_load_js{...}") - end - - if ui._partial_state then - -- TODO: do this only if args.view and args.target are unset!? - if ui._partial_state.params then - for key, value in pairs(ui._partial_state.params) do - params[key] = value - end - end - for param_name, dummy in pairs(ui._partial_state.param_name_hash) do - params[param_name] = cgi.params[param_name] - end - end - if args.params then - for key, value in pairs(args.params) do - params[key] = value - end - end - local encoded_url = encode.json( - encode.url{ - module = module, - view = view, - id = id, - params = params - } - ) - - if mode == "form_normal" then - -- NOTE: action in "action_mode" refers to WebMCP actions, while action - -- in "this.action" refers to the action attribute of HTML forms - slot.put('this.action = ', encoded_url, '; ') - end - - return slot.use_temporary(function() - slot.put( - 'partialMultiLoad({', - -- mapping: - '"trace": "trace", "system_error": "system_error", ', - encode.json(target), ': "default" }, ', - -- tempLoadingContents: - '{}, ', - -- failureContents: - '"error", ', - -- url: - (mode == "form_normal" or mode == "form_action") and ( - 'this' - ) or ( - encoded_url - ), ', ', - -- urlParams: - '"_webmcp_json_slots[]=default&_webmcp_json_slots[]=trace&_webmcp_json_slots[]=system_error", ', - -- postParams: - '{}, ', - -- successHandler: - 'function() {}, ', - -- failureHandler: - 'function() {} ', - '); ', - 'return false;' - ) - end) -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/add_partial_param_names.lua --- a/framework/env/ui/add_partial_param_names.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ ---[[-- -ui.add_partial_param_names( - name_list -) - -This function adds names of GET/POST parameters to the list of parameters -which are to be copied when calling ui._partial_load_js{...} or -ui.link{..., partial = {...}} or ui.form{..., partial = {...}}. - ---]]-- - -function ui.add_partial_param_names(name_list) - if ui._partial_state then - for idx, param_name in ipairs(name_list) do - ui._partial_state.param_name_hash[param_name] = true - end - end -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/enable_partial_loading.lua --- a/framework/env/ui/enable_partial_loading.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ ---[[-- -ui.enable_partial_loading() - -This function tells subsequent calls of ui.link{...} and ui.form{...} that -partial loading should be enabled when requested by passing "partial" -arguments to ui.link or ui.form. - -NOTE: To use partial loading, the slots being requested need to be -white-listed by calling request.set_allowed_json_request_slots({...}) -in the application configuration file. TODO: By now, at least the slot -names "default", "trace" and "system_error" need to be white-listed, as -these slots are currently hardwired in ui._partial_load_js(...). - ---]]-- - -function ui.enable_partial_loading() - ui._partial_loading_enabled = true - request.force_absolute_baseurl() -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/filters.lua --- a/framework/env/ui/filters.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/ui/filters.lua Fri Feb 27 21:49:00 2015 +0100 @@ -55,7 +55,7 @@ local current_options = {} for idx, filter in ipairs(args) do local filter_name = filter.name or "filter" - local current_option = atom.string:load(cgi.params[filter_name]) + local current_option = atom.string:load(request.get_param{name=filter_name}) if not current_option then current_option = param.get(filter_name) end @@ -90,7 +90,7 @@ content = function() for idx, filter in ipairs(args) do local filter_name = filter.name or "filter" - local current_option = atom.string:load(cgi.params[filter_name]) + local current_option = atom.string:load(request.get_param{name=filter_name}) if not current_option then current_option = param.get(filter_name) end @@ -116,12 +116,7 @@ view = request.get_view(), id = id, params = params, - text = option.label, - partial = { - params = { - [filter_name] = option.name - } - } + text = option.label } end end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/form.lua --- a/framework/env/ui/form.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/ui/form.lua Fri Feb 27 21:49:00 2015 +0100 @@ -20,13 +20,6 @@ error = { ... }, -- routing when "error" is returned by the called action ... = { ... } -- routing when "..." is returned by the called action }, - partial = { -- parameters for partial loading, see below - module = module, - view = view, - id = id, - params = params, - target = target - }, content = function() ... -- code creating the contents of the form end @@ -34,10 +27,6 @@ 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. -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 -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 -further documentation. - --]]-- local function prepare_routing_params(params, routing, default_module) @@ -99,45 +88,6 @@ action = args.action, } attr.method = args.method and string.upper(args.method) or "POST" - if ui.is_partial_loading_enabled() and args.partial then - attr.onsubmit = slot.use_temporary(function() - local partial_mode = "form_normal" - if args.action then - partial_mode = "form_action" - slot.put( - 'var element; ', - 'var formElements = []; ', - 'for (var i=0; i= 0) { ', - 'element.parentNode.removeChild(element); ', - '} ', - '}' - ) - local routing_params = {} - prepare_routing_params( - routing_params, - args.partial.routing, - args.partial.module - ) - for key, value in pairs(routing_params) do - slot.put( - ' ', - 'element = document.createElement("input"); ', - 'element.setAttribute("type", "hidden"); ', - 'element.setAttribute("name", ', encode.json(key), '); ', - 'element.setAttribute("value", ', encode.json(value), '); ', - 'this.appendChild(element);' - ) - end - slot.put(' ') - end - slot.put(ui._partial_load_js(args.partial, partial_mode)) - end) - end if slot_state.form_opened then error("Cannot open a non-readonly form inside a non-readonly form.") end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/is_partial_loading_enabled.lua --- a/framework/env/ui/is_partial_loading_enabled.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ ---[[-- -result = -ui.is_partial_loading_enabled() - -This function returns true, if partial loading has been enabled by calling -ui.enable_partial_loading(). - ---]]-- - -function ui.is_partial_loading_enabled() - return ui._partial_loading_enabled -end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/link.lua --- a/framework/env/ui/link.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/ui/link.lua Fri Feb 27 21:49:00 2015 +0100 @@ -13,23 +13,11 @@ routing = routing, -- optional routing information for action links, as described for ui.form{...} anchor = anchor, -- for views: anchor in destination URL text = text, -- link text - content = content, -- link content (overrides link text, except for submit buttons for action calls without JavaScript) - partial = { -- parameters for partial loading, see below - module = module, - view = view, - id = id, - params = params, - target = target - } + content = content -- link content (overrides link text, except for submit buttons for action calls without JavaScript) } 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). -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 -used to create an onclick event (onsubmit event for action links). The -"partial" setting table is passed to ui._partial_load_js as first argument. -See ui._partial_load_js(...) for further documentation. - --]]-- function ui.link(args) @@ -67,7 +55,6 @@ id = args.id, params = args.params, routing = args.routing, - partial = args.partial, attr = form_attr, content = function() ui.submit{ text = args.text, attr = args.submit_attr } @@ -105,9 +92,6 @@ params = args.params, anchor = args.anchor } - if ui.is_partial_loading_enabled() and args.partial then - a_attr.onclick = ui._partial_load_js(args.partial) - end return ui.tag{ tag = "a", attr = a_attr, content = wrapped_content } end end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/paginate.lua --- a/framework/env/ui/paginate.lua Fri Feb 27 17:18:08 2015 +0100 +++ b/framework/env/ui/paginate.lua Fri Feb 27 21:49:00 2015 +0100 @@ -11,7 +11,7 @@ end } -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. +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,7 +29,7 @@ if count > 0 then page_count = math.floor((count - 1) / per_page) + 1 end - local current_page = atom.integer:load(cgi.params[name]) or 1 + local current_page = atom.integer:load(request.get_param{name=name}) or 1 if current_page > page_count then current_page = page_count end @@ -48,14 +48,6 @@ if current_page == page then attr.class = "active" end - local partial - if ui.is_partial_loading_enabled() then - partial = { - params = { - [name] = tostring(page) - } - } - end ui.link{ attr = attr, module = request.get_module(), @@ -63,8 +55,7 @@ id = id, params = params, anchor = args.anchor, - text = tostring(page), - partial = partial + text = tostring(page) } end end diff -r 38e5399718ca -r 32ec28229bb5 framework/env/ui/partial.lua --- a/framework/env/ui/partial.lua Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ ---[[-- -ui.partial{ - module = module, -- module to be used to reload inner contents - view = view, -- view to be used to reload inner contents - id = id, -- id to be used to reload inner contents - params = params, -- params to be used to reload inner contents - target = target, -- id of HTML element containing contents to be replaced - content = function() - ... - end -} - -Calling this function declares that the inner contents can be requested -directly via the given module, view, id and params. The parameter "target" -specifies the id of the HTML element, which should be replaced when -reloading partially. - -The function has an effect on inner calls of ui.link{..., partial = {...}} -and ui.form{..., partial = {...}}. - ---]]-- - -function ui.partial(args) - local old_state = ui._partial_state - ui._partial_state = table.new(args) - ui._partial_state.param_name_hash = {} - if args.param_names then - ui.add_partial_param_names(args.param_names) - end - args.content() - ui._partial_state = old_state -end diff -r 38e5399718ca -r 32ec28229bb5 framework/js/partialload.js --- a/framework/js/partialload.js Fri Feb 27 17:18:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,271 +0,0 @@ - -partialload_queue = []; -partialload_queueRPos = 0; -partialload_queueWPos = 0; - -function partialload_getFormKeyValuePairs(form) { - var result = {}; - for (var i=0; i= 0) { - if (url.search(/&$/) >= 0) { - url = url + params; - } else { - url = url + "&" + params; - } - } else { - url = url + "?" + params; - } - } - return url; -} - -function partialload_mergeEncodedFormData(data1, data2) { - if (data2 == null || data2 == "") return data1; - if (data1 == null || data1 == "") return data2; - return data1 + "&" + data2; -} - -function partialload_startNextRequest() { - var entry = partialload_queue[partialload_queueRPos++]; - var req = new XMLHttpRequest(); - req.open(entry.method, entry.url, true); - req.onreadystatechange = function() { - if (req.readyState == 4) { - if (req.status == 200) { - if (entry.successHandler != null) entry.successHandler(req.responseText); - } else { - if (entry.failureHandler != null) entry.failureHandler(); - } - if (partialload_queue[partialload_queueRPos]) { - partialload_startNextRequest(); - } else { - partialload_queue = []; - partialload_queueRPos = 0; - partialload_queueWPos = 0; - } - } - } - if (entry.data) { - req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - } - req.send(entry.data); -} - -function queuedHttpRequest( - url_or_form, - urlParams, - postParams, - successHandler, - failureHandler -) { - var method; - var data = null; - if (typeof(postParams) == "string") { - data = postParams; - } else if (postParams != null) { - data = partialload_encodeFormData(postParams); - } - var url; - if (typeof(url_or_form) == "object") { - // form element given - var form = url_or_form; - url = partialload_addFormDataToUrl(form.action, urlParams); - var dataFromForm = partialload_encodeFormData( - partialload_getFormKeyValuePairs(form) - ); - if (form.method != null && form.method.search(/^POST$/i) >= 0) { - method = "POST"; - data = partialload_mergeEncodedFormData(data, dataFromForm); - } else { - method = (postParams == NULL) ? "GET" : "POST"; - url = partialload_addFormDataToUrl(url, dataFromForm); - } - } else { - // URL given - url = partialload_addFormDataToUrl(url_or_form, urlParams); - if (postParams == null) { - method = "GET"; - } else { - method = "POST"; - if (typeof(postParams) == "string") { - data = postParams; - } else { - data = partialload_encodeFormData(postParams); - } - } - } - partialload_queue[partialload_queueWPos++] = { - method: method, - url: url, - data: data, - successHandler: successHandler, - failureHandler: failureHandler - }; - if (partialload_queueRPos == 0) { - partialload_startNextRequest(); - } -} - -function setHtmlContent(node, htmlWithScripts) { - var uniquePrefix = "placeholder" + Math.floor(Math.random()*10e16) + "_"; - var i = 0; - var scripts = []; - var htmlWithPlaceholders = ""; - // NOTE: This function can not handle CDATA blocks at random positions. - htmlWithPlaceholders = htmlWithScripts.replace( - /]*>(.*?)<\/script>/ig, - function(all, inside) { - scripts[i] = inside; - var placeholder = ''; - i++; - return placeholder; - } - ) - node.innerHTML = htmlWithPlaceholders; - var documentWriteBackup = document.write; - var documentWritelnBackup = document.writeln; - var output; - document.write = function(str) { output += str; } - document.writeln = function(str) { output += str + "\n"; } - for (i=0; i 0) { - var childNode = placeholderNode.childNodes[0]; - placeholderNode.removeChild(childNode); - placeholderNode.parentNode.insertBefore(childNode, placeholderNode); - } - } - placeholderNode.parentNode.removeChild(placeholderNode); - } - document.write = documentWriteBackup; - document.writeln = documentWritelnBackup; -} - -function partialLoad( - node, - tempLoadingContent, - failureContent, - url_or_form, - urlParams, - postParams, - successHandler, - failureHandler -) { - if (typeof(node) == "string") node = document.getElementById(node); - if (tempLoadingContent != null) setHtmlContent(node, tempLoadingContent); - queuedHttpRequest( - url_or_form, - urlParams, - postParams, - function(response) { - setHtmlContent(node, response); - if (successHandler != null) successHandler(); - }, - function() { - if (failureContent != null) setHtmlContent(node, failureContent); - if (failureHandler != null) failureHandler(); - } - ); -} - -function partialMultiLoad( - mapping, - tempLoadingContents, - failureContents, - url_or_form, - urlParams, - postParams, - successHandler, - failureHandler -) { - if (mapping instanceof Array) { - var mappingHash = {} - for (var i=0; i