2017-08-16 15:19:41 +02:00
|
|
|
// Converse.js (A browser based XMPP chat client)
|
|
|
|
// http://conversejs.org
|
|
|
|
//
|
|
|
|
// This is the utilities module.
|
|
|
|
//
|
2018-07-25 12:59:12 +02:00
|
|
|
// Copyright (c) 2013-2018, Jan-Carel Brand <jc@opkode.com>
|
2017-08-16 15:19:41 +02:00
|
|
|
// Licensed under the Mozilla Public License (MPLv2)
|
|
|
|
//
|
2018-10-22 13:59:06 +02:00
|
|
|
/*global define */
|
2017-08-16 15:19:41 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2018-10-08 01:10:01 +02:00
|
|
|
"../lodash.noconflict",
|
|
|
|
"./core",
|
2018-10-22 13:59:06 +02:00
|
|
|
"../templates/field.html"
|
2017-08-16 15:19:41 +02:00
|
|
|
], factory);
|
2018-10-22 13:59:06 +02:00
|
|
|
}(this, function (_, u, tpl_field) {
|
2017-08-16 15:19:41 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
u.webForm2xForm = function (field) {
|
|
|
|
/* Takes an HTML DOM and turns it into an XForm field.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (DOMElement) field - the field to convert
|
|
|
|
*/
|
|
|
|
let value;
|
|
|
|
if (field.getAttribute('type') === 'checkbox') {
|
|
|
|
value = field.checked && 1 || 0;
|
2018-05-12 16:45:40 +02:00
|
|
|
} else if (field.tagName == "TEXTAREA") {
|
2017-08-16 15:19:41 +02:00
|
|
|
value = _.filter(field.value.split('\n'), _.trim);
|
2018-05-12 16:45:40 +02:00
|
|
|
} else if (field.tagName == "SELECT") {
|
|
|
|
value = u.getSelectValues(field);
|
2017-08-16 15:19:41 +02:00
|
|
|
} else {
|
|
|
|
value = field.value;
|
|
|
|
}
|
2018-01-02 21:44:46 +01:00
|
|
|
return u.stringToNode(
|
2017-08-16 15:19:41 +02:00
|
|
|
tpl_field({
|
2018-06-04 10:26:44 +02:00
|
|
|
'name': field.getAttribute('name'),
|
|
|
|
'value': value
|
2017-08-16 15:19:41 +02:00
|
|
|
})
|
2018-01-02 21:44:46 +01:00
|
|
|
);
|
2017-08-16 15:19:41 +02:00
|
|
|
};
|
|
|
|
return u;
|
|
|
|
}));
|