comparison plugins/disco.js @ 58:bcb5b7c2c3d3

Add a dataforms plugin and make disco#info use this one.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 01 Feb 2012 17:23:08 +0100
parents aaad98b33f86
children fdd1ae375067
comparison
equal deleted inserted replaced
57:91f18fdc0e2c 58:bcb5b7c2c3d3
117 117
118 var children = stanza.DOM.firstChild.childNodes; 118 var children = stanza.DOM.firstChild.childNodes;
119 var length = children.length; 119 var length = children.length;
120 120
121 for (var i = 0; i < length; i++) { 121 for (var i = 0; i < length; i++) {
122 var child = children[i];
123 var ns = child.namespaceURI;
124 var name = child.localName;
122 125
123 if (children[i].localName === 'feature') 126 if (ns === Lightstring.namespaces['disco#info'] && name === 'feature')
124 features.push(children[i].getAttributeNS(null, 'var')); 127 features.push(child.getAttributeNS(null, 'var'));
125 128
126 else if (children[i].localName === 'identity') { 129 else if (ns === Lightstring.namespaces['disco#info'] && name === 'identity') {
127 var identity = { 130 var identity = {
128 category: children[i].getAttributeNS(null, 'category'), 131 category: child.getAttributeNS(null, 'category'),
129 type: children[i].getAttributeNS(null, 'type') 132 type: child.getAttributeNS(null, 'type')
130 }; 133 };
131 var name = children[i].getAttributeNS(null, 'name'); 134 var name = child.getAttributeNS(null, 'name');
132 if (name) 135 if (name)
133 identity.name = name; 136 identity.name = name;
134 identities.push(identity); 137 identities.push(identity);
135 } 138 }
136 139
137 else if (children[i].localName === 'x') { 140 else if (ns === Lightstring.namespaces['dataforms'] && name === 'x')
138 for (var j = 0; j < children[i].childNodes.length; j++) { 141 this.disco.parse(child); //TODO: check if that plugin is enabled.
139 var child = children[i].childNodes[j];
140 var field = {
141 type: child.getAttribute('type')
142 };
143 142
144 var _var = child.getAttribute('var'); 143 else
145 144 ; //TODO: emit a warning.
146 var label = child.getAttribute('label');
147 if (label)
148 field.label = label;
149
150 for (var y = 0; y < child.childNodes.length; y++) {
151 if(child.childNodes[y].localName === 'desc')
152 field.desc = child.childNodes[y].textContent;
153 else if(child.childNodes[y].localName === 'required')
154 field.required = true;
155 else if(child.childNodes[y].localName === 'value')
156 field.value = child.childNodes[y].textContent;
157 }
158
159 fields[_var] = field;
160 }
161 }
162 } 145 }
163 146
164 stanza.identities = identities; 147 stanza.identities = identities;
165 stanza.features = features; 148 stanza.features = features;
166 stanza.fields = fields; 149 stanza.fields = fields;