diff options
Diffstat (limited to 'web/app/view/StateController.js')
-rw-r--r-- | web/app/view/StateController.js | 98 |
1 files changed, 41 insertions, 57 deletions
diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index 29f6a7c6d..01df6645d 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -25,58 +25,49 @@ Ext.define('Traccar.view.StateController', { selectDevice: 'selectDevice', selectReport: 'selectReport' } + }, + store: { + '#LatestPositions': { + add: 'updateLatest', + update: 'updateLatest' + }, + '#Positions': { + clear: 'clearReport' + } } } }, - init: function () { - var store = Ext.getStore('LatestPositions'); - store.on('add', this.add, this); - store.on('update', this.update, this); - }, + keys: (function () { + var i, list, result; + result = {}; + list = ['fixTime', 'latitude', 'longitude', 'valid', 'altitude', 'speed', 'course', 'address', 'protocol']; + for (i = 0; i < list.length; i++) { + result[list[i]] = { + priority: i, + name: Strings['position' + list[i].replace(/^\w/g, function (s) { + return s.toUpperCase(); + })] + }; + } + return result; + }()), - keys: { - fixTime: { - priority: 1, - name: Strings.positionTime - }, - latitude: { - priority: 2, - name: Strings.positionLatitude - }, - longitude: { - priority: 3, - name: Strings.positionLongitude - }, - valid: { - priority: 4, - name: Strings.positionValid - }, - altitude: { - priority: 5, - name: Strings.positionAltitude - }, - speed: { - priority: 6, - name: Strings.positionSpeed - }, - course: { - priority: 7, - name: Strings.positionCourse - }, - address: { - priority: 8, - name: Strings.positionAddress - }, - protocol: { - priority: 9, - name: Strings.positionProtocol + 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 value.toFixed(2); + return Number(value.toFixed(2)); } else { return value; } @@ -114,29 +105,22 @@ Ext.define('Traccar.view.StateController', { }, selectDevice: function (device) { - var found; + var position; this.deviceId = device.get('id'); - found = Ext.getStore('LatestPositions').query('deviceId', this.deviceId); - if (found.getCount() > 0) { - this.updatePosition(found.first()); + 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); }, - add: function (store, data) { - if (this.deviceId === data[0].get('deviceId')) { - this.updatePosition(data[0]); - } - }, - - update: function (store, data) { - if (this.deviceId === data.get('deviceId')) { - this.updatePosition(data); - } + clearReport: function (store) { + Ext.getStore('Attributes').removeAll(); } }); |