Annotate

util/adhoc.lua @ 8845:c6b45cac9423

Added tag 0.9.14 for changeset 29c6d2681bad
author Matthew Wild <mwild1@gmail.com>
date Wed, 30 May 2018 21:51:15 +0100
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 };