Commit a15aec35 authored by Holger Weiss's avatar Holger Weiss Committed by JC Brand

Assume "text-single" as default form field type

As per XEP-0004, the default "type" of data form fields is
"text-single", so a missing "type" attribute should not be treated
differently.

This fixes handling of CAPTCHAs offered by ejabberd.
parent 37800d92
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
- Upgrade to Backbone 1.4.0 - Upgrade to Backbone 1.4.0
- Fix "flashing" of roster filter when you have less than 5 roster contacts. - Fix "flashing" of roster filter when you have less than 5 roster contacts.
- Fix handling of CAPTCHAs offered by ejabberd.
- Allow setting of debug mode via URL with `/#converse?debug=true` - Allow setting of debug mode via URL with `/#converse?debug=true`
- New config setting [locked_muc_domain](https://conversejs.org/docs/html/configuration.html#locked-muc-domain) - New config setting [locked_muc_domain](https://conversejs.org/docs/html/configuration.html#locked-muc-domain)
- New config setting [show_client_info](https://conversejs.org/docs/html/configuration.html#show-client-info) - New config setting [show_client_info](https://conversejs.org/docs/html/configuration.html#show-client-info)
......
...@@ -96178,86 +96178,82 @@ _headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].xForm2webForm = fu ...@@ -96178,86 +96178,82 @@ _headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].xForm2webForm = fu
* Parameters: * Parameters:
* (XMLElement) field - the field to convert * (XMLElement) field - the field to convert
*/ */
if (field.getAttribute('type')) { if (field.getAttribute('type') === 'list-single' || field.getAttribute('type') === 'list-multi') {
if (field.getAttribute('type') === 'list-single' || field.getAttribute('type') === 'list-multi') { const values = _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.map(_headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].queryChildren(field, 'value'), _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.partial(_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get, _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a, 'textContent'));
const values = _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.map(_headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].queryChildren(field, 'value'), _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.partial(_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get, _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a, 'textContent'));
const options = _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.map(_headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].queryChildren(field, 'option'), function (option) { const options = _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.map(_headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].queryChildren(field, 'option'), function (option) {
const value = _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(option.querySelector('value'), 'textContent'); const value = _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(option.querySelector('value'), 'textContent');
return _templates_select_option_html__WEBPACK_IMPORTED_MODULE_14___default()({ return _templates_select_option_html__WEBPACK_IMPORTED_MODULE_14___default()({
'value': value, 'value': value,
'label': option.getAttribute('label'), 'label': option.getAttribute('label'),
'selected': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.includes(values, value), 'selected': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.includes(values, value),
'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required'))
});
});
return _templates_form_select_html__WEBPACK_IMPORTED_MODULE_9___default()({
'id': _headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].getUniqueId(),
'name': field.getAttribute('var'),
'label': field.getAttribute('label'),
'options': options.join(''),
'multiple': field.getAttribute('type') === 'list-multi',
'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required')) 'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required'))
}); });
} else if (field.getAttribute('type') === 'fixed') { });
const text = _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent');
return _templates_form_select_html__WEBPACK_IMPORTED_MODULE_9___default()({
return '<p class="form-help">' + text + '</p>'; 'id': _headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].getUniqueId(),
} else if (field.getAttribute('type') === 'jid-multi') { 'name': field.getAttribute('var'),
return _templates_form_textarea_html__WEBPACK_IMPORTED_MODULE_10___default()({ 'label': field.getAttribute('label'),
'name': field.getAttribute('var'), 'options': options.join(''),
'label': field.getAttribute('label') || '', 'multiple': field.getAttribute('type') === 'list-multi',
'value': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent'), 'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required'))
'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('type') === 'fixed') {
} else if (field.getAttribute('type') === 'boolean') { const text = _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent');
return _templates_form_checkbox_html__WEBPACK_IMPORTED_MODULE_7___default()({
'id': _headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].getUniqueId(), return '<p class="form-help">' + text + '</p>';
'name': field.getAttribute('var'), } else if (field.getAttribute('type') === 'jid-multi') {
'label': field.getAttribute('label') || '', return _templates_form_textarea_html__WEBPACK_IMPORTED_MODULE_10___default()({
'checked': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent') === "1" && 'checked="1"' || '', 'name': field.getAttribute('var'),
'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required')) 'label': field.getAttribute('label') || '',
}); 'value': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent'),
} else if (field.getAttribute('var') === 'url') { 'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required'))
return _templates_form_url_html__WEBPACK_IMPORTED_MODULE_11___default()({ });
'label': field.getAttribute('label') || '', } else if (field.getAttribute('type') === 'boolean') {
'value': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent') return _templates_form_checkbox_html__WEBPACK_IMPORTED_MODULE_7___default()({
}); 'id': _headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].getUniqueId(),
} else if (field.getAttribute('var') === 'username') { 'name': field.getAttribute('var'),
return _templates_form_username_html__WEBPACK_IMPORTED_MODULE_12___default()({ 'label': field.getAttribute('label') || '',
'domain': ' @' + domain, 'checked': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent') === "1" && 'checked="1"' || '',
'name': field.getAttribute('var'), 'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required'))
'type': XFORM_TYPE_MAP[field.getAttribute('type')], });
'label': field.getAttribute('label') || '', } else if (field.getAttribute('var') === 'url') {
'value': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent'), return _templates_form_url_html__WEBPACK_IMPORTED_MODULE_11___default()({
'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required')) 'label': field.getAttribute('label') || '',
}); 'value': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent')
} else { });
return _templates_form_input_html__WEBPACK_IMPORTED_MODULE_8___default()({ } else if (field.getAttribute('var') === 'username') {
'id': _headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].getUniqueId(), return _templates_form_username_html__WEBPACK_IMPORTED_MODULE_12___default()({
'label': field.getAttribute('label') || '', 'domain': ' @' + domain,
'name': field.getAttribute('var'), 'name': field.getAttribute('var'),
'placeholder': null, 'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required')), 'label': field.getAttribute('label') || '',
'type': XFORM_TYPE_MAP[field.getAttribute('type')], 'value': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent'),
'value': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent') 'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required'))
}); });
} } else if (field.getAttribute('var') === 'ocr') {
// Captcha
const uri = field.querySelector('uri');
const el = sizzle__WEBPACK_IMPORTED_MODULE_2___default()('data[cid="' + uri.textContent.replace(/^cid:/, '') + '"]', stanza)[0];
return _templates_form_captcha_html__WEBPACK_IMPORTED_MODULE_6___default()({
'label': field.getAttribute('label'),
'name': field.getAttribute('var'),
'data': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(el, 'textContent'),
'type': uri.getAttribute('type'),
'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required'))
});
} else { } else {
if (field.getAttribute('var') === 'ocr') { return _templates_form_input_html__WEBPACK_IMPORTED_MODULE_8___default()({
// Captcha 'id': _headless_utils_core__WEBPACK_IMPORTED_MODULE_16__["default"].getUniqueId(),
const uri = field.querySelector('uri'); 'label': field.getAttribute('label') || '',
const el = sizzle__WEBPACK_IMPORTED_MODULE_2___default()('data[cid="' + uri.textContent.replace(/^cid:/, '') + '"]', stanza)[0]; 'name': field.getAttribute('var'),
return _templates_form_captcha_html__WEBPACK_IMPORTED_MODULE_6___default()({ 'placeholder': null,
'label': field.getAttribute('label'), 'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required')),
'name': field.getAttribute('var'), 'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'data': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(el, 'textContent'), 'value': _headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.get(field.querySelector('value'), 'textContent')
'type': uri.getAttribute('type'), });
'required': !_headless_lodash_noconflict__WEBPACK_IMPORTED_MODULE_1___default.a.isNil(field.querySelector('required'))
});
}
} }
}; };
...@@ -539,89 +539,85 @@ u.xForm2webForm = function (field, stanza, domain) { ...@@ -539,89 +539,85 @@ u.xForm2webForm = function (field, stanza, domain) {
* Parameters: * Parameters:
* (XMLElement) field - the field to convert * (XMLElement) field - the field to convert
*/ */
if (field.getAttribute('type')) { if (field.getAttribute('type') === 'list-single' ||
if (field.getAttribute('type') === 'list-single' || field.getAttribute('type') === 'list-multi') {
field.getAttribute('type') === 'list-multi') {
const values = _.map(
const values = _.map( u.queryChildren(field, 'value'),
u.queryChildren(field, 'value'), _.partial(_.get, _, 'textContent')
_.partial(_.get, _, 'textContent') );
); const options = _.map(
const options = _.map( u.queryChildren(field, 'option'),
u.queryChildren(field, 'option'), function (option) {
function (option) { const value = _.get(option.querySelector('value'), 'textContent');
const value = _.get(option.querySelector('value'), 'textContent'); return tpl_select_option({
return tpl_select_option({ 'value': value,
'value': value, 'label': option.getAttribute('label'),
'label': option.getAttribute('label'), 'selected': _.includes(values, value),
'selected': _.includes(values, value), 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) })
}) }
} );
); return tpl_form_select({
return tpl_form_select({ 'id': u.getUniqueId(),
'id': u.getUniqueId(), 'name': field.getAttribute('var'),
'name': field.getAttribute('var'), 'label': field.getAttribute('label'),
'label': field.getAttribute('label'), 'options': options.join(''),
'options': options.join(''), 'multiple': (field.getAttribute('type') === 'list-multi'),
'multiple': (field.getAttribute('type') === 'list-multi'), 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('type') === 'fixed') {
} else if (field.getAttribute('type') === 'fixed') { const text = _.get(field.querySelector('value'), 'textContent');
const text = _.get(field.querySelector('value'), 'textContent'); return '<p class="form-help">'+text+'</p>';
return '<p class="form-help">'+text+'</p>'; } else if (field.getAttribute('type') === 'jid-multi') {
} else if (field.getAttribute('type') === 'jid-multi') { return tpl_form_textarea({
return tpl_form_textarea({ 'name': field.getAttribute('var'),
'name': field.getAttribute('var'), 'label': field.getAttribute('label') || '',
'label': field.getAttribute('label') || '', 'value': _.get(field.querySelector('value'), 'textContent'),
'value': _.get(field.querySelector('value'), 'textContent'), 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('type') === 'boolean') {
} else if (field.getAttribute('type') === 'boolean') { return tpl_form_checkbox({
return tpl_form_checkbox({ 'id': u.getUniqueId(),
'id': u.getUniqueId(), 'name': field.getAttribute('var'),
'name': field.getAttribute('var'), 'label': field.getAttribute('label') || '',
'label': field.getAttribute('label') || '', 'checked': _.get(field.querySelector('value'), 'textContent') === "1" && 'checked="1"' || '',
'checked': _.get(field.querySelector('value'), 'textContent') === "1" && 'checked="1"' || '', 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('var') === 'url') {
} else if (field.getAttribute('var') === 'url') { return tpl_form_url({
return tpl_form_url({ 'label': field.getAttribute('label') || '',
'label': field.getAttribute('label') || '', 'value': _.get(field.querySelector('value'), 'textContent')
'value': _.get(field.querySelector('value'), 'textContent') });
}); } else if (field.getAttribute('var') === 'username') {
} else if (field.getAttribute('var') === 'username') { return tpl_form_username({
return tpl_form_username({ 'domain': ' @'+domain,
'domain': ' @'+domain, 'name': field.getAttribute('var'),
'name': field.getAttribute('var'), 'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'type': XFORM_TYPE_MAP[field.getAttribute('type')], 'label': field.getAttribute('label') || '',
'label': field.getAttribute('label') || '', 'value': _.get(field.querySelector('value'), 'textContent'),
'value': _.get(field.querySelector('value'), 'textContent'), 'required': !_.isNil(field.querySelector('required'))
'required': !_.isNil(field.querySelector('required')) });
}); } else if (field.getAttribute('var') === 'ocr') { // Captcha
} else { const uri = field.querySelector('uri');
return tpl_form_input({ const el = sizzle('data[cid="'+uri.textContent.replace(/^cid:/, '')+'"]', stanza)[0];
'id': u.getUniqueId(), return tpl_form_captcha({
'label': field.getAttribute('label') || '', 'label': field.getAttribute('label'),
'name': field.getAttribute('var'), 'name': field.getAttribute('var'),
'placeholder': null, 'data': _.get(el, 'textContent'),
'required': !_.isNil(field.querySelector('required')), 'type': uri.getAttribute('type'),
'type': XFORM_TYPE_MAP[field.getAttribute('type')], 'required': !_.isNil(field.querySelector('required'))
'value': _.get(field.querySelector('value'), 'textContent') });
});
}
} else { } else {
if (field.getAttribute('var') === 'ocr') { // Captcha return tpl_form_input({
const uri = field.querySelector('uri'); 'id': u.getUniqueId(),
const el = sizzle('data[cid="'+uri.textContent.replace(/^cid:/, '')+'"]', stanza)[0]; 'label': field.getAttribute('label') || '',
return tpl_form_captcha({ 'name': field.getAttribute('var'),
'label': field.getAttribute('label'), 'placeholder': null,
'name': field.getAttribute('var'), 'required': !_.isNil(field.querySelector('required')),
'data': _.get(el, 'textContent'), 'type': XFORM_TYPE_MAP[field.getAttribute('type')],
'type': uri.getAttribute('type'), 'value': _.get(field.querySelector('value'), 'textContent')
'required': !_.isNil(field.querySelector('required')) });
});
}
} }
} }
export default u; export default u;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment