Annotate

util/adhoc.lua @ 8029:e859f279add4

mod_storage_sql: Remove compat for argument order change
author Kim Alvefur <zash@zash.se>
date Sat, 01 Apr 2017 19:02:27 +0200
parent 7912:2c204ba8e52e
child 8382:e5d00bf4a4d5
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"},
7912
2c204ba8e52e util.adhoc: Pass command data to initial_data callback in order to allow loading per-user settings
Kim Alvefur <zash@zash.se>
parents: 5513
diff changeset
25 form = { layout = form, values = initial_data(data) } }, "executing";
5513
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 };