annotate forms.js @ 57:addbf6bbfaa8

Various fixes for the migration to ltx.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 12 Sep 2011 23:45:00 +0200
parents 99bd1d1ac071
children b98e545a94f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 /*
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 * This file is part of PSĜS, a PubSub server written in JavaScript.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 * PSĜS is free software: you can redistribute it and/or modify
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 * it under the terms of the GNU Affero General Public License as
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 * License.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 * PSĜS is distributed in the hope that it will be useful,
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 * GNU Affero General Public License for more details.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 *
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 * You should have received a copy of the GNU Affero General Public License
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>.
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 */
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19
43
023f767662d3 Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 23
diff changeset
20 'use strict';
023f767662d3 Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 23
diff changeset
21
56
99bd1d1ac071 Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 43
diff changeset
22 var Element = require('ltx').Element;
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 var service_configuration = require('./configuration').service_configuration;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 var parseBoolean = function(b) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 if (b == 'true' || b == 'True' || b == 'TRUE' || b == '1')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 return true;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 return false;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 exports.build = function(type, desc, content, labels, title, instructions) {
56
99bd1d1ac071 Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 43
diff changeset
32 var x = new Element('x', {xmlns: 'jabber:x:data', type: type});
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 if (typeof desc == 'string')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 desc = service_configuration[desc];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 if (desc._TITLE)
23
5fc4ee90c1bc A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
38 x.c('title').t(desc._TITLE).up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 else if (title)
23
5fc4ee90c1bc A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
40 x.c('title').t(title).up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 if (desc._INSTRUCTIONS)
23
5fc4ee90c1bc A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
43 x.c('instructions').t(desc._INSTRUCTIONS).up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 else if (instructions)
23
5fc4ee90c1bc A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
45 x.c('instructions').t(instructions).up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 if (content == 'default') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 content = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 for (var i in desc)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 content[i] = desc[i].value;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 for (var i in desc) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 if (i[0] == '_')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 continue;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 var fieldAttr = {'var': i};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 if (labels) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 if (desc[i].type)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 fieldAttr.type = desc[i].type;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 if (desc[i].label)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 fieldAttr.label = desc[i].label;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 }
57
addbf6bbfaa8 Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
65
addbf6bbfaa8 Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
66 var field = new Element('field', fieldAttr);
addbf6bbfaa8 Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
67 x.cnode(field);
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 if (labels &&
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 (desc[i].type == 'list-multi' ||
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 desc[i].type == 'list-single')) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 for (var j in desc[i].options) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 var optAttr = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 if (desc[i].options[j].label)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 optAttr.label = desc[i].options[j].label;
57
addbf6bbfaa8 Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
76 field.c('option', optAttr).c('value').t(j).up().up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 if (i == 'FORM_TYPE')
57
addbf6bbfaa8 Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
81 field.c('value').t(desc[i].value).up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 else if (typeof content[i] != 'undefined') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 var md = content[i];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 if (desc[i].type == 'jid-multi' ||
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 desc[i].type == 'list-multi' ||
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 desc[i].type == 'text-multi') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 for (var j=0; j<md.length; j++)
57
addbf6bbfaa8 Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
88 field.c('value')
23
5fc4ee90c1bc A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
89 .t(md[j].toString()).up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 } else
57
addbf6bbfaa8 Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 56
diff changeset
91 field.c('value').t(md.toString()).up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
23
5fc4ee90c1bc A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
94 x.up();
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 }
23
5fc4ee90c1bc A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 8
diff changeset
96 return x;
0
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 exports.parse = function(x, params) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 var form = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 if (!params) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 var type = x.getAttribute('type');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 if (type)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 form.type = type;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 var title = x.getChild('title');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 if (title)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 form.title = title;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 var instructions = x.getChild('instructions');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112 if (instructions)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 form.instructions = instructions;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 form.fields = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 for (var i in x.tags) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 var field = x.tags[i];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 var name = field.getAttribute('var');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 if (params && name == 'FORM_TYPE')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 continue;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 if (params) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 var type = field.getAttribute('type');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 if (type == 'jid-multi' || type == 'list-multi' || type == 'text-multi') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 form.fields[name] = [];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 for (var j in field.tags) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 var elem = field.tags[j];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 if (elem.name == 'value')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 form.fields[name].push(elem.getText());
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 } else if (type == 'boolean') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 var value = field.getChild('value');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 if (value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 form.fields[name] = parseBoolean(value.getText());
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 } else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 var value = field.getChild('value');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 if (value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 form.fields[name] = value.getText();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 } else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 form.fields[name] = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144 var label = field.getAttribute('label');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 if (label)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 form.fields[name].label = label;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148 var type = field.getAttribute('type');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 if (type)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 form.fields[name].type = type;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152 if (type == 'jid-multi' || type == 'list-multi' || type == 'text-multi') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 form.fields[name].options = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 form.fields[name].values = [];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 for (var j in field.tags) {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 var elem = field.tags[j];
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 if (elem.name == 'option') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 var value = elem.getChild('value');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 if (!value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 continue;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 value = value.getText();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 if (!value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 continue;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 form.fields[name].options[value] = {};
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 label = elem.getAttribute('label')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 if (label)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 form.fields[name].options[value].label = label;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 } else if (elem.name == 'value')
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 form.fields[name].values.push(elem.getText());
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 } else if (type == 'boolean') {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 var value = field.getChild('value');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 if (value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 form.fields[name].value = parseBoolean(value.getText());
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 } else {
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 var value = field.getChild('value');
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 if (value)
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 form.fields[name].value = value.getText();
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 }
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 return form;
9ee956af41e3 Initial commit
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 }