diff options
Diffstat (limited to 'web/app/controller')
-rw-r--r-- | web/app/controller/Root.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index b4ab06b82..79827b8a6 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -85,5 +85,33 @@ Ext.define('Traccar.controller.Root', { } else { Ext.create('widget.main'); } + this.asyncUpdate(true); + }, + + asyncUpdate: function (first) { + Ext.Ajax.request({ + scope: this, + url: '/api/async', + params: { + first: first + }, + callback: Traccar.app.getErrorHandler(this, function (options, success, response) { + var i, store, data, position; + if (success) { + store = Ext.getStore('LatestPositions'); + data = Ext.decode(response.responseText).data; + + for (i = 0; i < data.length; i++) { + position = store.findRecord('deviceId', data[i].deviceId, 0, false, false, true); + if (position) { + position.set(data[i]); + } else { + store.add(Ext.create('Traccar.model.Position', data[i])); + } + } + this.asyncUpdate(false); + } + }) + }); } }); |