diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-03 13:39:53 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-03 13:39:53 +1300 |
commit | 001424d7ada69390fd7ebea8e585fb0408e147ac (patch) | |
tree | d4bac262bbb0cc2122626004b95eb2d57e089937 | |
parent | 00ebfd00f204bdfbd8e66254b79c7b8814d7ee3b (diff) | |
download | traccar-server-001424d7ada69390fd7ebea8e585fb0408e147ac.tar.gz traccar-server-001424d7ada69390fd7ebea8e585fb0408e147ac.tar.bz2 traccar-server-001424d7ada69390fd7ebea8e585fb0408e147ac.zip |
More clean up for web interface
-rwxr-xr-x | tools/jscheck.sh | 5 | ||||
-rw-r--r-- | tools/jshint.json | 93 | ||||
-rw-r--r-- | web/app/Application.js | 124 | ||||
-rw-r--r-- | web/app/controller/Root.js | 2 | ||||
-rw-r--r-- | web/app/view/BaseEditDialog.js | 2 | ||||
-rw-r--r-- | web/app/view/BaseEditDialogController.js | 2 | ||||
-rw-r--r-- | web/app/view/CommandDialog.js | 2 | ||||
-rw-r--r-- | web/app/view/CommandDialogController.js | 2 | ||||
-rw-r--r-- | web/app/view/DeviceController.js | 4 | ||||
-rw-r--r-- | web/app/view/Login.js (renamed from web/app/view/login/Login.js) | 10 | ||||
-rw-r--r-- | web/app/view/LoginController.js (renamed from web/app/view/login/LoginController.js) | 5 | ||||
-rw-r--r-- | web/app/view/Main.js | 4 | ||||
-rw-r--r-- | web/app/view/MainMobile.js | 2 | ||||
-rw-r--r-- | web/app/view/Map.js (renamed from web/app/view/map/Map.js) | 6 | ||||
-rw-r--r-- | web/app/view/MapController.js (renamed from web/app/view/map/MapController.js) | 2 | ||||
-rw-r--r-- | web/app/view/Register.js (renamed from web/app/view/login/Register.js) | 12 | ||||
-rw-r--r-- | web/app/view/RegisterController.js (renamed from web/app/view/login/RegisterController.js) | 2 | ||||
-rw-r--r-- | web/app/view/Report.js (renamed from web/app/view/report/Report.js) | 4 | ||||
-rw-r--r-- | web/app/view/ReportController.js (renamed from web/app/view/report/ReportController.js) | 21 | ||||
-rw-r--r-- | web/app/view/State.js (renamed from web/app/view/BaseDialogController.js) | 26 | ||||
-rw-r--r-- | web/app/view/StateController.js | 137 |
21 files changed, 356 insertions, 111 deletions
diff --git a/tools/jscheck.sh b/tools/jscheck.sh new file mode 100755 index 000000000..b85ddf2ed --- /dev/null +++ b/tools/jscheck.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +cd $(dirname $0)/../web + +jshint --config ../tools/jshint.json . diff --git a/tools/jshint.json b/tools/jshint.json new file mode 100644 index 000000000..e7befc289 --- /dev/null +++ b/tools/jshint.json @@ -0,0 +1,93 @@ +{ + + "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) + "camelcase" : true, // true: Identifiers must be in camelCase + "curly" : true, // true: Require {} for every new block or scope + "eqeqeq" : true, // true: Require triple equals (===) for comparison + "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() + "freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc. + "immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` + "indent" : 4, // {int} Number of spaces to use for indentation + "latedef" : true, // true: Require variables/functions to be defined before being used + "newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()` + "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` + "noempty" : true, // true: Prohibit use of empty blocks + "nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters. + "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment) + "plusplus" : false, // true: Prohibit use of `++` and `--` + "quotmark" : "single", // Quotation mark consistency: + // false : do nothing (default) + // true : ensure whatever is used is consistent + // "single" : require single quotes + // "double" : require double quotes + "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) + "unused" : true, // Unused variables: + // true : all variables, last function parameter + // "vars" : all variables only + // "strict" : all variables, all function parameters + "strict" : true, // true: Requires all functions run in ES5 Strict Mode + "maxparams" : false, // {int} Max number of formal params allowed per function + "maxdepth" : false, // {int} Max depth of nested blocks (within functions) + "maxstatements" : false, // {int} Max number statements per function + "maxcomplexity" : false, // {int} Max cyclomatic complexity per function + "maxlen" : false, // {int} Max number of characters per line + "varstmt" : false, // true: Disallow any var statements. Only `let` and `const` are allowed. + + // Relaxing + "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) + "boss" : false, // true: Tolerate assignments where comparisons would be expected + "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. + "eqnull" : false, // true: Tolerate use of `== null` + "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) + "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) + // (ex: `for each`, multiple try/catch, function expression…) + "evil" : false, // true: Tolerate use of `eval` and `new Function()` + "expr" : false, // true: Tolerate `ExpressionStatement` as Programs + "funcscope" : false, // true: Tolerate defining variables inside control statements + "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') + "iterator" : false, // true: Tolerate using the `__iterator__` property + "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block + "laxbreak" : false, // true: Tolerate possibly unsafe line breakings + "laxcomma" : false, // true: Tolerate comma-first style coding + "loopfunc" : false, // true: Tolerate functions being defined in loops + "multistr" : false, // true: Tolerate multi-line strings + "noyield" : false, // true: Tolerate generator functions with no yield statement in them. + "notypeof" : false, // true: Tolerate invalid typeof operator values + "proto" : false, // true: Tolerate using the `__proto__` property + "scripturl" : false, // true: Tolerate script-targeted URLs + "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` + "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation + "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` + "validthis" : false, // true: Tolerate using this in a non-constructor function + + // Environments + "browser" : true, // Web Browser (window, document, etc) + "browserify" : false, // Browserify (node.js code in the browser) + "couch" : false, // CouchDB + "devel" : true, // Development/debugging (alert, confirm, etc) + "dojo" : false, // Dojo Toolkit + "jasmine" : false, // Jasmine + "jquery" : false, // jQuery + "mocha" : false, // Mocha + "mootools" : false, // MooTools + "node" : false, // Node.js + "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) + "phantom" : false, // PhantomJS + "prototypejs" : false, // Prototype and Scriptaculous + "qunit" : false, // QUnit + "rhino" : false, // Rhino + "shelljs" : false, // ShellJS + "typed" : false, // Globals for typed array constructions + "worker" : false, // Web Workers + "wsh" : false, // Windows Scripting Host + "yui" : false, // Yahoo User Interface + + // Custom Globals + "globals" : { + "Ext" : false, + "ol" : false, + "styles" : false, + "strings" : false + } + +} diff --git a/web/app/Application.js b/web/app/Application.js index 67dc96536..def000f04 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -13,67 +13,71 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +(function() { + "use strict"; -Ext.define('Traccar.Application', { - extend: 'Ext.app.Application', - name: 'Traccar', + Ext.define('Traccar.Application', { + extend: 'Ext.app.Application', + name: 'Traccar', - requires: [ - 'Traccar.Resources', - 'Traccar.ErrorManager', - 'Traccar.AttributeFormatter' - ], - - models: [ - 'Server', - 'User', - 'Device', - 'Position', - 'Attribute', - 'Command' - ], - - stores: [ - 'Devices', - 'Positions', - 'LatestPositions', - 'Users', - 'Attributes', - 'MapTypes', - 'DistanceUnits', - 'SpeedUnits', - 'CommandTypes', - 'TimeUnits', - 'Languages' - ], + requires: [ + 'Traccar.Resources', + 'Traccar.ErrorManager', + 'Traccar.AttributeFormatter' + ], - controllers: [ - 'Root' - ], - - setUser: function(data) { - var reader = Ext.create('Ext.data.reader.Json', { - model: 'Traccar.model.User' - }); - this.user = reader.readRecords(data).getRecords()[0]; - }, - - getUser: function() { - return this.user; - }, - - setServer: function(data) { - var reader = Ext.create('Ext.data.reader.Json', { - model: 'Traccar.model.Server' - }); - this.server = reader.readRecords(data).getRecords()[0]; - }, - - getServer: function() { - return this.server; - }, + models: [ + 'Server', + 'User', + 'Device', + 'Position', + 'Attribute', + 'Command' + ], - getPreference: function(key, defaultValue) { - return this.getUser().get(key) || this.getServer().get(key) || defaultValue; - } -}); + stores: [ + 'Devices', + 'Positions', + 'LatestPositions', + 'Users', + 'Attributes', + 'MapTypes', + 'DistanceUnits', + 'SpeedUnits', + 'CommandTypes', + 'TimeUnits', + 'Languages' + ], + + controllers: [ + 'Root' + ], + + setUser: function(data) { + var reader = Ext.create('Ext.data.reader.Json', { + model: 'Traccar.model.User' + }); + this.user = reader.readRecords(data).getRecords()[0]; + }, + + getUser: function() { + return this.user; + }, + + setServer: function(data) { + var reader = Ext.create('Ext.data.reader.Json', { + model: 'Traccar.model.Server' + }); + this.server = reader.readRecords(data).getRecords()[0]; + }, + + getServer: function() { + return this.server; + }, + + getPreference: function(key, defaultValue) { + return this.getUser().get(key) || this.getServer().get(key) || defaultValue; + } + }); + +})(); diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index d4b3e794d..490019b1a 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -19,7 +19,7 @@ Ext.define('Traccar.controller.Root', { requires: [ 'Traccar.LoginManager', - 'Traccar.view.login.Login', + 'Traccar.view.Login', 'Traccar.view.Main', 'Traccar.view.MainMobile' ], diff --git a/web/app/view/BaseEditDialog.js b/web/app/view/BaseEditDialog.js index df8bfda93..0788c30d2 100644 --- a/web/app/view/BaseEditDialog.js +++ b/web/app/view/BaseEditDialog.js @@ -22,6 +22,6 @@ Ext.define('Traccar.view.BaseEditDialog', { handler: 'onSaveClick' }, { text: strings.sharedCancel, - handler: 'onCancelClick' + handler: 'closeView' }] }); diff --git a/web/app/view/BaseEditDialogController.js b/web/app/view/BaseEditDialogController.js index 863a75dcb..0c45b3097 100644 --- a/web/app/view/BaseEditDialogController.js +++ b/web/app/view/BaseEditDialogController.js @@ -15,7 +15,7 @@ */ Ext.define('Traccar.view.BaseEditDialogController', { - extend: 'Traccar.view.BaseDialogController', + extend: 'Ext.app.ViewController', alias: 'controller.baseEditDialog', onSaveClick: function(button) { diff --git a/web/app/view/CommandDialog.js b/web/app/view/CommandDialog.js index 1cc96b195..5d37f3173 100644 --- a/web/app/view/CommandDialog.js +++ b/web/app/view/CommandDialog.js @@ -62,6 +62,6 @@ Ext.define('Traccar.view.CommandDialog', { handler: 'onSendClick' }, { text: strings.sharedCancel, - handler: 'onCancelClick' + handler: 'closeView' }] }); diff --git a/web/app/view/CommandDialogController.js b/web/app/view/CommandDialogController.js index 66a10bbb6..6aba4a6f1 100644 --- a/web/app/view/CommandDialogController.js +++ b/web/app/view/CommandDialogController.js @@ -15,7 +15,7 @@ */ Ext.define('Traccar.view.CommandDialogController', { - extend: 'Traccar.view.BaseDialogController', + extend: 'Ext.app.ViewController', alias: 'controller.commandDialog', onSelect: function(selected) { diff --git a/web/app/view/DeviceController.js b/web/app/view/DeviceController.js index e315d6f8d..d714d89d4 100644 --- a/web/app/view/DeviceController.js +++ b/web/app/view/DeviceController.js @@ -23,7 +23,7 @@ Ext.define('Traccar.view.DeviceController', { 'Traccar.view.DeviceDialog', 'Traccar.view.user.UserDialog', 'Traccar.view.user.User', - 'Traccar.view.login.LoginController' + 'Traccar.view.LoginController' ], config: { @@ -44,7 +44,7 @@ Ext.define('Traccar.view.DeviceController', { }, onLogoutClick: function() { - Ext.create('Traccar.view.login.LoginController').logout(); + Ext.create('Traccar.view.LoginController').logout(); }, onAddClick: function() { diff --git a/web/app/view/login/Login.js b/web/app/view/Login.js index a2d53fdf1..23f813c66 100644 --- a/web/app/view/login/Login.js +++ b/web/app/view/Login.js @@ -14,20 +14,17 @@ * limitations under the License. */ -Ext.define('Traccar.view.login.Login', { - extend: 'Ext.window.Window', +Ext.define('Traccar.view.Login', { + extend: 'Traccar.view.BaseDialog', alias: 'widget.login', requires: [ - 'Traccar.view.login.LoginController' + 'Traccar.view.LoginController' ], controller: 'login', - bodyPadding: styles.panelPadding, - title: strings.loginTitle, closable: false, - resizable: false, items: { xtype: 'form', @@ -91,5 +88,4 @@ Ext.define('Traccar.view.login.Login', { text: strings.loginLogin, handler: 'onLoginClick' }] - }); diff --git a/web/app/view/login/LoginController.js b/web/app/view/LoginController.js index 0344f5542..f6b2fe228 100644 --- a/web/app/view/login/LoginController.js +++ b/web/app/view/LoginController.js @@ -14,12 +14,12 @@ * limitations under the License. */ -Ext.define('Traccar.view.login.LoginController', { +Ext.define('Traccar.view.LoginController', { extend: 'Ext.app.ViewController', alias: 'controller.login', requires: [ - 'Traccar.view.login.Register' + 'Traccar.view.Register' ], init: function() { @@ -101,5 +101,4 @@ Ext.define('Traccar.view.login.LoginController', { onRegisterClick: function() { Ext.create('Traccar.view.login.Register').show(); } - }); diff --git a/web/app/view/Main.js b/web/app/view/Main.js index 781cfad6b..ee1073e92 100644 --- a/web/app/view/Main.js +++ b/web/app/view/Main.js @@ -21,8 +21,8 @@ Ext.define('Traccar.view.Main', { requires: [ 'Traccar.view.Device', 'Traccar.view.State', - 'Traccar.view.report.Report', - 'Traccar.view.map.Map' + 'Traccar.view.Report', + 'Traccar.view.Map' ], layout: 'border', diff --git a/web/app/view/MainMobile.js b/web/app/view/MainMobile.js index 0562edb70..e42fc7f7f 100644 --- a/web/app/view/MainMobile.js +++ b/web/app/view/MainMobile.js @@ -21,7 +21,7 @@ Ext.define('Traccar.view.MainMobile', { requires: [ 'Traccar.view.Device', 'Traccar.view.State', - 'Traccar.view.map.Map' + 'Traccar.view.Map' ], layout: 'border', diff --git a/web/app/view/map/Map.js b/web/app/view/Map.js index 6e8ab6fad..5d2fd579c 100644 --- a/web/app/view/map/Map.js +++ b/web/app/view/Map.js @@ -14,12 +14,12 @@ * limitations under the License. */ -Ext.define('Traccar.view.map.Map', { +Ext.define('Traccar.view.Map', { extend: 'Ext.form.Panel', xtype: 'mapView', requires: [ - 'Traccar.view.map.MapController' + 'Traccar.view.MapController' ], controller: 'map', @@ -36,7 +36,7 @@ Ext.define('Traccar.view.map.Map', { var layer; var mapLayer = user.get('map') || server.get('map'); - var bingKey = server.get('bingKey') || 'AseEs0DLJhLlTNoxbNXu7DGsnnH4UoWuGue7-irwKkE3fffaClwc9q_Mr6AyHY8F'; + var bingKey = server.get('bingKey'); if (mapLayer === 'custom') { layer = new ol.layer.Tile({ source: new ol.source.XYZ({ diff --git a/web/app/view/map/MapController.js b/web/app/view/MapController.js index b0d8b8f39..4979cd920 100644 --- a/web/app/view/map/MapController.js +++ b/web/app/view/MapController.js @@ -14,7 +14,7 @@ * limitations under the License. */ -Ext.define('Traccar.view.map.MapController', { +Ext.define('Traccar.view.MapController', { extend: 'Ext.app.ViewController', alias: 'controller.map', diff --git a/web/app/view/login/Register.js b/web/app/view/Register.js index 91a5775a1..464b7bb1f 100644 --- a/web/app/view/login/Register.js +++ b/web/app/view/Register.js @@ -14,20 +14,15 @@ * limitations under the License. */ -Ext.define('Traccar.view.login.Register', { - extend: 'Ext.window.Window', +Ext.define('Traccar.view.Register', { + extend: 'Traccar.view.BaseDialog', requires: [ - 'Traccar.view.login.RegisterController' + 'Traccar.view.RegisterController' ], controller: 'register', - bodyPadding: styles.panelPadding, - title: strings.loginRegister, - resizable: false, - modal: true, - items: { xtype: 'form', reference: 'form', @@ -60,5 +55,4 @@ Ext.define('Traccar.view.login.Register', { text: strings.sharedCancel, handler: 'closeView' }] - }); diff --git a/web/app/view/login/RegisterController.js b/web/app/view/RegisterController.js index b1957ba8f..b470aa343 100644 --- a/web/app/view/login/RegisterController.js +++ b/web/app/view/RegisterController.js @@ -14,7 +14,7 @@ * limitations under the License. */ -Ext.define('Traccar.view.login.RegisterController', { +Ext.define('Traccar.view.RegisterController', { extend: 'Ext.app.ViewController', alias: 'controller.register', diff --git a/web/app/view/report/Report.js b/web/app/view/Report.js index 720de698f..060c9c46a 100644 --- a/web/app/view/report/Report.js +++ b/web/app/view/Report.js @@ -14,12 +14,12 @@ * limitations under the License. */ -Ext.define('Traccar.view.report.Report', { +Ext.define('Traccar.view.Report', { extend: 'Ext.grid.Panel', xtype: 'reportView', requires: [ - 'Traccar.view.report.ReportController' + 'Traccar.view.ReportController' ], controller: 'report', diff --git a/web/app/view/report/ReportController.js b/web/app/view/ReportController.js index 64c89867d..0b3e30f17 100644 --- a/web/app/view/report/ReportController.js +++ b/web/app/view/ReportController.js @@ -14,7 +14,7 @@ * limitations under the License. */ -Ext.define('Traccar.view.report.ReportController', { +Ext.define('Traccar.view.ReportController', { extend: 'Ext.app.ViewController', alias: 'controller.report', @@ -29,23 +29,25 @@ Ext.define('Traccar.view.report.ReportController', { }, onShowClick: function() { - var deviceId = this.lookupReference('deviceField').getValue(); + var deviceId, fromDate, fromTime, from, toDate, toTime, to, store; - var fromDate = this.lookupReference('fromDateField').getValue(); - var fromTime = this.lookupReference('fromTimeField').getValue(); + deviceId = this.lookupReference('deviceField').getValue(); - var from = new Date( + fromDate = this.lookupReference('fromDateField').getValue(); + fromTime = this.lookupReference('fromTimeField').getValue(); + + from = new Date( fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate(), fromTime.getHours(), fromTime.getMinutes(), fromTime.getSeconds(), fromTime.getMilliseconds()); - var toDate = this.lookupReference('toDateField').getValue(); - var toTime = this.lookupReference('toTimeField').getValue(); + toDate = this.lookupReference('toDateField').getValue(); + toTime = this.lookupReference('toTimeField').getValue(); - var to = new Date( + to = new Date( toDate.getFullYear(), toDate.getMonth(), toDate.getDate(), toTime.getHours(), toTime.getMinutes(), toTime.getSeconds(), toTime.getMilliseconds()); - var store = Ext.getStore('Positions'); + store = Ext.getStore('Positions'); store.load({ params:{ deviceId: deviceId, @@ -75,5 +77,4 @@ Ext.define('Traccar.view.report.ReportController', { this.getView().getSelectionModel().deselectAll(); } } - }); diff --git a/web/app/view/BaseDialogController.js b/web/app/view/State.js index 4bf23d94e..0804234f9 100644 --- a/web/app/view/BaseDialogController.js +++ b/web/app/view/State.js @@ -14,10 +14,26 @@ * limitations under the License. */ -Ext.define('Traccar.view.BaseDialogController', { - extend: 'Ext.app.ViewController', +Ext.define('Traccar.view.State', { + extend: 'Ext.grid.Panel', + xtype: 'stateView', + + requires: [ + 'Traccar.view.StateController' + ], + + controller: 'state', + store: 'Attributes', - onCancelClick: function(button) { - button.up('window').close(); - } + title: strings.stateTitle, + + columns: [{ + text: strings.stateName, + dataIndex: 'name', + flex: 1 + }, { + text: strings.stateValue, + dataIndex: 'value', + flex: 1 + }] }); diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js new file mode 100644 index 000000000..dc2ddfb2b --- /dev/null +++ b/web/app/view/StateController.js @@ -0,0 +1,137 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.StateController', { + extend: 'Ext.app.ViewController', + alias: 'controller.state', + + config: { + listen: { + controller: { + '*': { + selectDevice: 'selectDevice' + } + } + } + }, + + init: function() { + var store = Ext.getStore('LatestPositions'); + store.on('add', this.add, this); + store.on('update', this.update, this); + }, + + 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 + } + }, + + formatValue: function(value) { + if (typeof(id) === 'number') { + return value.toFixed(2); + } else { + return value; + } + }, + + updatePosition: function(position) { + var attributes, value, unit, store, key; + store = Ext.getStore('Attributes'); + store.removeAll(); + + for (key in position.data) { + if (position.data.hasOwnProperty(key) && this.keys[key] !== undefined) { + store.add(Ext.create('Traccar.model.Attribute', { + priority: this.keys[key].priority, + name: this.keys[key].name, + value: Traccar.AttributeFormatter.getFormatter(key)(position.get(key)) + })); + } + } + + attributes = position.get('attributes'); + if (attributes instanceof Object) { + for (key in attributes) { + if (attributes.hasOwnProperty(key)) { + store.add(Ext.create('Traccar.model.Attribute', { + priority: 1024, + name: key.replace(/^./, function (match) { + return match.toUpperCase(); + }), + value: Traccar.AttributeFormatter.getFormatter(key)(attributes[key]) + })); + } + } + } + }, + + selectDevice: function(device) { + var found; + this.deviceId = device.get('id'); + found = Ext.getStore('LatestPositions').query('deviceId', this.deviceId); + if (found.getCount() > 0) { + this.updatePosition(found.first()); + } else { + Ext.getStore('Attributes').removeAll(); + } + }, + + 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); + } + } +}); |