Mercurial > psgxs
comparison forms.js @ 23:5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 31 Oct 2010 23:58:07 +0100 |
parents | efe8dbd34780 |
children | 023f767662d3 |
comparison
equal
deleted
inserted
replaced
22:0f42c9c8085a | 23:5fc4ee90c1bc |
---|---|
31 | 31 |
32 if (typeof desc == 'string') | 32 if (typeof desc == 'string') |
33 desc = service_configuration[desc]; | 33 desc = service_configuration[desc]; |
34 | 34 |
35 if (desc._TITLE) | 35 if (desc._TITLE) |
36 x.s('title').t(desc._TITLE); | 36 x.c('title').t(desc._TITLE).up(); |
37 else if (title) | 37 else if (title) |
38 x.s('title').t(title); | 38 x.c('title').t(title).up(); |
39 | 39 |
40 if (desc._INSTRUCTIONS) | 40 if (desc._INSTRUCTIONS) |
41 x.s('instructions').t(desc._INSTRUCTIONS); | 41 x.c('instructions').t(desc._INSTRUCTIONS).up(); |
42 else if (instructions) | 42 else if (instructions) |
43 x.s('instructions').t(instructions); | 43 x.c('instructions').t(instructions).up(); |
44 | 44 |
45 if (content == 'default') { | 45 if (content == 'default') { |
46 content = {}; | 46 content = {}; |
47 for (var i in desc) | 47 for (var i in desc) |
48 content[i] = desc[i].value; | 48 content[i] = desc[i].value; |
58 if (desc[i].type) | 58 if (desc[i].type) |
59 fieldAttr.type = desc[i].type; | 59 fieldAttr.type = desc[i].type; |
60 if (desc[i].label) | 60 if (desc[i].label) |
61 fieldAttr.label = desc[i].label; | 61 fieldAttr.label = desc[i].label; |
62 } | 62 } |
63 var field = xmpp.stanza('field', fieldAttr); | 63 x.c('field', fieldAttr); |
64 | 64 |
65 if (labels && | 65 if (labels && |
66 (desc[i].type == 'list-multi' || | 66 (desc[i].type == 'list-multi' || |
67 desc[i].type == 'list-single')) { | 67 desc[i].type == 'list-single')) { |
68 for (var j in desc[i].options) { | 68 for (var j in desc[i].options) { |
69 var optAttr = {}; | 69 var optAttr = {}; |
70 if (desc[i].options[j].label) | 70 if (desc[i].options[j].label) |
71 optAttr.label = desc[i].options[j].label; | 71 optAttr.label = desc[i].options[j].label; |
72 field.s('option', optAttr).c('value').t(j); | 72 x.c('option', optAttr).c('value').t(j).up().up(); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 if (i == 'FORM_TYPE') | 76 if (i == 'FORM_TYPE') |
77 field.s('value').t(desc[i].value); | 77 x.c('value').t(desc[i].value).up(); |
78 else if (typeof content[i] != 'undefined') { | 78 else if (typeof content[i] != 'undefined') { |
79 var md = content[i]; | 79 var md = content[i]; |
80 if (desc[i].type == 'jid-multi' || | 80 if (desc[i].type == 'jid-multi' || |
81 desc[i].type == 'list-multi' || | 81 desc[i].type == 'list-multi' || |
82 desc[i].type == 'text-multi') { | 82 desc[i].type == 'text-multi') { |
83 for (var j=0; j<md.length; j++) | 83 for (var j=0; j<md.length; j++) |
84 field.s('value') | 84 x.c('value') |
85 .t(md[j].toString()); | 85 .t(md[j].toString()).up(); |
86 } else | 86 } else |
87 field.s('value').t(md.toString()); | 87 x.c('value').t(md.toString()).up(); |
88 } | 88 } |
89 | 89 |
90 x.cnode(field); | 90 x.up(); |
91 } | 91 } |
92 if (field) | 92 return x; |
93 return x; | |
94 return -1; //FIXME | |
95 } | 93 } |
96 | 94 |
97 exports.parse = function(x, params) { | 95 exports.parse = function(x, params) { |
98 var form = {}; | 96 var form = {}; |
99 | 97 |