summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-11-14 08:51:42 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-11-14 10:31:59 +0200
commit8e9a0ca00b7437402f80d10290c972fa1c07446a (patch)
tree54c2e0d239b760b05ed7eab57514d5ffe19aec47
parentbaca93fa10b7c9f7f59b87a737e150038fa90b07 (diff)
downloadacf2-8e9a0ca00b7437402f80d10290c972fa1c07446a.tar.bz2
acf2-8e9a0ca00b7437402f80d10290c972fa1c07446a.tar.xz
combine choice and ui_choice properties of fields
-rw-r--r--acf2/model/field.lua14
-rw-r--r--protocol.txt5
-rw-r--r--web/client.js7
3 files changed, 13 insertions, 13 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua
index 809fdc3..409c004 100644
--- a/acf2/model/field.lua
+++ b/acf2/model/field.lua
@@ -27,7 +27,8 @@ end
function M.Member:auto_ui_name(name)
if not name then return end
- return (name:sub(1, 1):upper()..name:sub(2)):gsub('-', ' ')
+ local res = (name:sub(1, 1):upper()..name:sub(2)):gsub('-', ' ')
+ return res
end
function M.Member:meta(context)
@@ -46,9 +47,11 @@ function M.Field:init(params)
if self.editable == nil then self.editable = not self.compute end
- if self.choice and not self.ui_choice then
- self.ui_choice = util.map(
- function(name) return self:auto_ui_name(name) end,
+ if self.choice then
+ self.choice = util.map(
+ function(ch)
+ return type(ch) == 'table' and ch or {ch, self:auto_ui_name(ch)}
+ end,
self.choice
)
end
@@ -69,7 +72,6 @@ function M.Field:meta(context)
res.default = self.default
res.choice = self.choice
res.widget = self.widget
- res['ui-choice'] = self.ui_choice
return res
end
@@ -94,7 +96,7 @@ function M.Field:_validate(context, value)
raise(context.path, 'Required value not set')
end
if self.choice and value ~= nil and not util.contains(
- self.choice, value
+ util.map(function(ch) return ch[1] end, self.choice), value
) then
raise(context.path, 'Invalid value')
end
diff --git a/protocol.txt b/protocol.txt
index 9f94c53..f0ad9cb 100644
--- a/protocol.txt
+++ b/protocol.txt
@@ -62,9 +62,8 @@ resp: JSON object, with the following attributes:
- required (boolean)
- default
- max-length
- - choices (optional array of allowed values)
- - ui-choices (user-friendly choices to be shown in combo
- boxes)
+ - choices (optional array of allowed values, which are
+ tuples of actual values and user-friendly versions)
- fields (model only): array of field metadata JSON
objects
- members (collections and sets only): metadata for
diff --git a/web/client.js b/web/client.js
index c8ce06e..3ed4fe2 100644
--- a/web/client.js
+++ b/web/client.js
@@ -575,7 +575,7 @@ $(function() {
opt("", "(none)", value == null)
_.each(
- _.zip(meta.choice, meta["ui-choice"]),
+ meta.choice,
function(choice) {
opt(choice[0], choice[1], value == choice[0]);
}
@@ -990,9 +990,8 @@ $(function() {
Reference.requestData = function(value, meta) {
var def = $.Deferred();
txnMgr.query(meta.scope).done(function(data) {
- meta.choice = _.values(data.data);
- meta["ui-choice"] = _.map(meta.choice, function(path) {
- return split(path).pop();
+ meta.choice = _.map(_.values(data.data), function(path) {
+ return [path, split(path).pop()];
});
def.resolve(value, meta);
});