Annotate

util/adhoc.lua @ 8844:29c6d2681bad 0.9.14

mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
author Kim Alvefur <zash@zash.se>
date Fri, 25 May 2018 21:09:34 +0200
parent 5513:755f705f126a
child 7912:2c204ba8e52e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5513
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 local function new_simple_form(form, result_handler)
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2 return function(self, data, state)
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 if state then
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 if data.action == "cancel" then
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 return { status = "canceled" };
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6 end
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7 local fields, err = form:data(data.form);
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
8 return result_handler(fields, err, data);
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
9 else
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
10 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = form }, "executing";
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
11 end
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 end
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 end
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15 local function new_initial_data_form(form, initial_data, result_handler)
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 return function(self, data, state)
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17 if state then
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18 if data.action == "cancel" then
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19 return { status = "canceled" };
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 end
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21 local fields, err = form:data(data.form);
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22 return result_handler(fields, err, data);
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23 else
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24 return { status = "executing", actions = {"next", "complete", default = "complete"},
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25 form = { layout = form, values = initial_data() } }, "executing";
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26 end
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27 end
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28 end
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
29
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30 return { new_simple_form = new_simple_form,
755f705f126a util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
31 new_initial_data_form = new_initial_data_form };