Commit ca9bd36e authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: replace jQuery.paserXML by DOMParser.parseFromString

   This don't remove jQuery completly, but it allow us to clean up the remaing part
parent 8bd4212c
/*jslint nomen: true, maxlen: 200, indent: 2, unparam: true*/ /*jslint nomen: true, maxlen: 200, indent: 2, unparam: true*/
/*global rJS, console, window, document, RSVP, btoa, atob, $, XMLSerializer, /*global rJS, console, window, document, RSVP, btoa, atob, $, XMLSerializer,
jQuery, URI, vkbeautify, domsugar, Boolean */ DOMParser, URI, vkbeautify, domsugar, Boolean */
(function (window, document, rJS, $, XMLSerializer, jQuery, vkbeautify, (function (window, document, rJS, $, XMLSerializer, DOMParser, vkbeautify,
domsugar, Boolean) { domsugar, Boolean) {
"use strict"; "use strict";
var DISPLAY_JSON_FORM = 'display_json_form', var DISPLAY_JSON_FORM = 'display_json_form',
DISPLAY_RAW_XML = 'display_raw_xml'; DISPLAY_RAW_XML = 'display_raw_xml',
domparser = new DOMParser;
function jsonDictToParameterXML(json) { function jsonDictToParameterXML(json) {
var parameter_id, var parameter_id,
xml_output = $($.parseXML('<?xml version="1.0" encoding="UTF-8" ?><instance />')); xml_output = $((new DOMParser).parseFromString(
'<?xml version="1.0" encoding="UTF-8" ?><instance />', 'text/xml'));
// Used by serialisation XML // Used by serialisation XML
for (parameter_id in json) { for (parameter_id in json) {
if (json.hasOwnProperty(parameter_id)) { if (json.hasOwnProperty(parameter_id)) {
...@@ -28,8 +30,11 @@ ...@@ -28,8 +30,11 @@
} }
function jsonDictToParameterJSONInXML(json) { function jsonDictToParameterJSONInXML(json) {
var xml_output = $($.parseXML('<?xml version="1.0" encoding="UTF-8" ?><instance />')); var xml_output = $((new DOMParser).parseFromString(
// Used by serialisation XML '<?xml version="1.0" encoding="UTF-8" ?><instance />',
'text/xml'
));
// Used by serialisation XML
$('instance', xml_output).append( $('instance', xml_output).append(
$('<parameter />', xml_output) $('<parameter />', xml_output)
.text(vkbeautify.json(JSON.stringify(json))) .text(vkbeautify.json(JSON.stringify(json)))
...@@ -861,15 +866,19 @@ ...@@ -861,15 +866,19 @@
if (parameter_xml !== undefined) { if (parameter_xml !== undefined) {
if (serialisation === "json-in-xml") { if (serialisation === "json-in-xml") {
parameter_list = jQuery.parseXML( parameter_list = (new DOMParser()).parseFromString(
parameter_xml parameter_xml,
'text/xml'
).querySelectorAll("parameter"); ).querySelectorAll("parameter");
if (parameter_list.length > 1) { if (parameter_list.length > 1) {
throw new Error("The current parameter should contains only _ parameter (json-in-xml)."); throw new Error("The current parameter should contains only _ parameter (json-in-xml).");
} }
parameter_entry = jQuery.parseXML( parameter_entry = (new DOMParser()).parseFromString(
parameter_xml parameter_xml,
'text/xml'
).querySelector("parameter[id='_']"); ).querySelector("parameter[id='_']");
if (parameter_entry !== null) { if (parameter_entry !== null) {
parameter_dict = JSON.parse(parameter_entry.textContent); parameter_dict = JSON.parse(parameter_entry.textContent);
} else if (parameter_list.length === 1) { } else if (parameter_list.length === 1) {
...@@ -878,14 +887,18 @@ ...@@ -878,14 +887,18 @@
); );
} }
} else if (["", "xml"].indexOf(serialisation) >= 0) { } else if (["", "xml"].indexOf(serialisation) >= 0) {
parameter_entry = jQuery.parseXML( parameter_entry = (new DOMParser()).parseFromString(
parameter_xml parameter_xml,
'text/xml'
).querySelector("parameter[id='_']"); ).querySelector("parameter[id='_']");
if (parameter_entry !== null) { if (parameter_entry !== null) {
throw new Error("The current parameter values should NOT contains _ parameter (xml)."); throw new Error("The current parameter values should NOT contains _ parameter (xml).");
} }
$(jQuery.parseXML(parameter_xml) $((new DOMParser()).parseFromString(
.querySelectorAll("parameter")) parameter_xml,
'text/xml'
).querySelectorAll("parameter"))
.each(function (key, p) { .each(function (key, p) {
parameter_dict[p.id] = p.textContent; parameter_dict[p.id] = p.textContent;
}); });
...@@ -921,9 +934,8 @@ ...@@ -921,9 +934,8 @@
} }
for (i = 0; i < label_list.length; i = i + 1) { for (i = 0; i < label_list.length; i = i + 1) {
$(label_list[i]).addClass("slapos-parameter-dict-key-colapse"); label_list[i].classList.add("slapos-parameter-dict-key-colapse");
} }
return gadget.getContent();
}) })
.fail(function (error) { .fail(function (error) {
...@@ -1102,5 +1114,5 @@ ...@@ -1102,5 +1114,5 @@
}); });
}, {mutex: 'statechange'}); }, {mutex: 'statechange'});
}(window, document, rJS, $, XMLSerializer, jQuery, vkbeautify, }(window, document, rJS, $, XMLSerializer, DOMParser, vkbeautify,
domsugar, Boolean)); domsugar, Boolean));
\ No newline at end of file
...@@ -280,7 +280,7 @@ ...@@ -280,7 +280,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1003.49163.51970.27118</string> </value> <value> <string>1003.60531.19628.1092</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -298,7 +298,7 @@ ...@@ -298,7 +298,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1666206917.22</float> <float>1666889520.35</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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