comparison plugins/dataforms.js @ 80:50d36b093e3a

Lightstring.namespaces/NS has been renamed by Lightstring.ns.
author Sonny Piers <sonny.piers@gmail.com>
date Tue, 07 Feb 2012 18:42:09 +0100
parents 5dbf93cef55d
children 7500bc048dbc
comparison
equal deleted inserted replaced
79:2290321f5c8b 80:50d36b093e3a
43 43
44 var _var = child.getAttributeNS(null, 'var'); 44 var _var = child.getAttributeNS(null, 'var');
45 if (_var) 45 if (_var)
46 field.var = _var; 46 field.var = _var;
47 47
48 var desc = child.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'desc'); 48 var desc = child.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'desc');
49 if (desc.length > 1) 49 if (desc.length > 1)
50 ; //TODO: emit a warning if there is more than one. 50 ; //TODO: emit a warning if there is more than one.
51 if (0 in desc) 51 if (0 in desc)
52 field.desc = desc[0]; 52 field.desc = desc[0];
53 53
54 var required = child.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'required'); 54 var required = child.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'required');
55 if (required.length > 1) 55 if (required.length > 1)
56 ; //TODO: emit a warning if there is more than one. 56 ; //TODO: emit a warning if there is more than one.
57 field.required = (0 in required) 57 field.required = (0 in required)
58 58
59 var values = child.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'value'); 59 var values = child.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'value');
60 if (values.length) { 60 if (values.length) {
61 field.values = []; 61 field.values = [];
62 for (var j = 0; j < values.length; j++) 62 for (var j = 0; j < values.length; j++)
63 field.values.push(values[j].textContent); 63 field.values.push(values[j].textContent);
64 } 64 }
65 65
66 var options = child.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'option'); 66 var options = child.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'option');
67 if (options.length) { 67 if (options.length) {
68 field.options = []; 68 field.options = [];
69 for (var j = 0; j < options.length; j++) { 69 for (var j = 0; j < options.length; j++) {
70 var option = {}; 70 var option = {};
71 71
72 var opt = options[j]; 72 var opt = options[j];
73 73
74 var val = opt.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'value'); 74 var val = opt.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'value');
75 if (val.length > 1) 75 if (val.length > 1)
76 ; //TODO: emit a warning if there is more than one. 76 ; //TODO: emit a warning if there is more than one.
77 if (0 in val) 77 if (0 in val)
78 option.value = val[0]; 78 option.value = val[0];
79 79
95 namespaces: { 95 namespaces: {
96 dataforms: 'jabber:x:data' 96 dataforms: 'jabber:x:data'
97 }, 97 },
98 methods: { 98 methods: {
99 parse: function(x) { 99 parse: function(x) {
100 if (x.namespaceURI !== Lightstring.namespaces['dataforms'] || x.localName !== 'x') 100 if (x.namespaceURI !== Lightstring.ns['dataforms'] || x.localName !== 'x')
101 return null; 101 return null;
102 102
103 var form = {}; 103 var form = {};
104 104
105 var type = x.getAttributeNS(null, 'type'); 105 var type = x.getAttributeNS(null, 'type');
106 if (form_types.indexOf(type) === -1) 106 if (form_types.indexOf(type) === -1)
107 return; //TODO: emit a warning too? 107 return; //TODO: emit a warning too?
108 form.type = type; 108 form.type = type;
109 109
110 var title = x.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'title'); 110 var title = x.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'title');
111 if (title.length > 1) 111 if (title.length > 1)
112 ; //TODO: emit a warning if there is more than one. 112 ; //TODO: emit a warning if there is more than one.
113 else if (0 in title) 113 else if (0 in title)
114 form.title = title[0]; 114 form.title = title[0];
115 115
116 var fields = parseFields(x.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'fields')); 116 var fields = parseFields(x.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'field'));
117 if (fields) 117 if (fields)
118 form.fields = fields 118 form.fields = fields
119 119
120 var reported = x.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'reported'); 120 var reported = x.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'reported');
121 if (reported.length > 1) 121 if (reported.length > 1)
122 ; //TODO: emit a warning if there is more than one. 122 ; //TODO: emit a warning if there is more than one.
123 else if (0 in reported) { 123 else if (0 in reported) {
124 var fields = parseFields(reported[0].getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'fields')); 124 var fields = parseFields(reported[0].getElementsByTagNameNS(Lightstring.ns['dataforms'], 'field'));
125 if (fields) 125 if (fields)
126 form.reported = fields 126 form.reported = fields
127 } 127 }
128 128
129 var itemsList = x.getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'item'); 129 var itemsList = x.getElementsByTagNameNS(Lightstring.ns['dataforms'], 'item');
130 if (itemsList) { 130 if (itemsList.length) {
131 var fields = parseFields(itemsList[0].getElementsByTagNameNS(Lightstring.namespaces['dataforms'], 'fields')); 131 var fields = parseFields(itemsList[0].getElementsByTagNameNS(Lightstring.ns['dataforms'], 'fields'));
132 if (fields) 132 if (fields)
133 form.items = fields; 133 form.items = fields;
134 } 134 }
135 135
136 return form; 136 return form;