comparison mod_rest/jsonmap.lib.lua @ 3880:44c2d36c40a4

mod_rest: Add JSON to XML mapping of dataforms
author Kim Alvefur <zash@zash.se>
date Tue, 04 Feb 2020 22:34:19 +0100
parents 9a3dfe0bf9fd
children 5d7df207dc2b
comparison
equal deleted inserted replaced
3879:3b31ff7b4c7c 3880:44c2d36c40a4
45 fields:push(i); 45 fields:push(i);
46 end 46 end
47 return form; 47 return form;
48 end; 48 end;
49 function (x) 49 function (x)
50 -- TODO 50 if type(x) == "table" and x ~= json.null then
51 local form = st.stanza("x", { xmlns = "jabber:x:data", type = x.type });
52 if x.title then
53 form:text_tag("title", x.title);
54 end
55 if x.instructions then
56 form:text_tag("instructions", x.instructions);
57 end
58 if type(x.fields) == "table" then
59 for _, f in ipairs(x.fields) do
60 if type(f) == "table" then
61 form:tag("field", { var = f.var, type = f.type, label = f.label });
62 if f.desc then
63 form:text_tag("desc", f.desc);
64 end
65 if f.required == true then
66 form:tag("required"):up();
67 end
68 if type(f.value) == "string" then
69 form:text_tag("value", f.value);
70 elseif type(f.value) == "table" then
71 for _, v in ipairs(f.value) do
72 form:text_tag("value", v);
73 end
74 end
75 if type(f.options) == "table" then
76 for _, o in ipairs(f.value) do
77 if type(o) == "table" then
78 form:tag("option", { label = o.label });
79 form:text_tag("value", o.value);
80 form:up();
81 end
82 end
83 end
84 end
85 end
86 end
87 return form;
88 end
51 end; 89 end;
52 }; 90 };
53 91
54 local simple_types = { 92 local simple_types = {
55 -- basic message 93 -- basic message