diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-24 15:00:37 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-06-24 15:00:37 +1200 |
commit | 494a76c2cbaaa87916154ef959e0b65b580a1b38 (patch) | |
tree | d3bd02297036bf5f71081a505fb6647c9efc2bfd /web/app | |
parent | ea610afa021f14e9a8e6764b821bc25f154c38b9 (diff) | |
download | trackermap-server-494a76c2cbaaa87916154ef959e0b65b580a1b38.tar.gz trackermap-server-494a76c2cbaaa87916154ef959e0b65b580a1b38.tar.bz2 trackermap-server-494a76c2cbaaa87916154ef959e0b65b580a1b38.zip |
Parse XML for extra state data
Diffstat (limited to 'web/app')
-rw-r--r-- | web/app/view/state/StateController.js | 39 |
1 files changed, 32 insertions, 7 deletions
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 = '<info><a>aa</a><b>bb</b></info>';//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; } }); |