From 494a76c2cbaaa87916154ef959e0b65b580a1b38 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 24 Jun 2015 15:00:37 +1200 Subject: Parse XML for extra state data --- web/app/view/state/StateController.js | 39 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'web/app/view') diff --git a/web/app/view/state/StateController.js b/web/app/view/state/StateController.js index fc23bbe96..eeb04bb6d 100644 --- a/web/app/view/state/StateController.js +++ b/web/app/view/state/StateController.js @@ -84,13 +84,19 @@ Ext.define('Traccar.view.state.StateController', { } } - // TODO: decode XML - var xml = position.get('other'); - store.add(Ext.create('Traccar.model.Parameter', { - priority: 99, - name: 'Other', - value: xml - })); + var xml = 'aabb';//position.get('other'); + var other = this.parseXml(xml); + for (var key in other) { + if (other.hasOwnProperty(key)) { + store.add(Ext.create('Traccar.model.Parameter', { + priority: 999, + name: key.replace(/^./, function (match) { + return match.toUpperCase(); + }), + value: other[key] + })); + } + } }, selectDevice: function(device) { @@ -111,6 +117,25 @@ Ext.define('Traccar.view.state.StateController', { if (this.deviceId === data.get('deviceId')) { this.updatePosition(data); } + }, + + parseXml: function(xml) { + var dom = null; + if (window.DOMParser) { + dom = (new DOMParser()).parseFromString(xml, "text/xml"); + } else if (window.ActiveXObject) { + dom = new ActiveXObject('Microsoft.XMLDOM'); + dom.async = false; + dom.loadXML(xml); + } + + var result = {}; + var length = dom.childNodes[0].childNodes.length; + for(var i = 0; i < length; i++) { + var node = dom.childNodes[0].childNodes[i]; + result[node.nodeName] = node.innerHTML; // use textContent in future + } + return result; } }); -- cgit v1.2.3