From ea38e23c5c19f953d5db5107a56d697d31deef95 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 8 Nov 2015 13:31:04 +1300 Subject: Display state info from reports --- web/app/view/StateController.js | 42 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index e2b80643d..01df6645d 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -28,8 +28,11 @@ Ext.define('Traccar.view.StateController', { }, store: { '#LatestPositions': { - add: 'update', - update: 'update' + add: 'updateLatest', + update: 'updateLatest' + }, + '#Positions': { + clear: 'clearReport' } } } @@ -50,6 +53,18 @@ Ext.define('Traccar.view.StateController', { return result; }()), + updateLatest: function (store, data) { + var i; + if (!Ext.isArray(data)) { + data = [data]; + } + for (i = 0; i < data.length; i++) { + if (this.deviceId === data[i].get('deviceId')) { + this.updatePosition(data[i]); + } + } + }, + formatValue: function (value) { if (typeof (id) === 'number') { return Number(value.toFixed(2)); @@ -90,29 +105,22 @@ Ext.define('Traccar.view.StateController', { }, selectDevice: function (device) { - var found; + var position; this.deviceId = device.get('id'); - found = Ext.getStore('LatestPositions').findRecord('deviceId', this.deviceId, 0, false, false, true); - if (found) { - this.updatePosition(found); + position = Ext.getStore('LatestPositions').findRecord('deviceId', this.deviceId, 0, false, false, true); + if (position) { + this.updatePosition(position); } else { Ext.getStore('Attributes').removeAll(); } }, selectReport: function (position) { - console.log(position); + this.deviceId = null; + this.updatePosition(position); }, - update: function (store, data) { - var i; - if (!Ext.isArray(data)) { - data = [data]; - } - for (i = 0; i < data.length; i++) { - if (this.deviceId === data[i].get('deviceId')) { - this.updatePosition(data[0]); - } - } + clearReport: function (store) { + Ext.getStore('Attributes').removeAll(); } }); -- cgit v1.2.3