From 4154c2cd31f23c5d5fb336dfcd68ba192b297f93 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 16 Sep 2015 22:45:14 +1200 Subject: More JavaScript code cleanup --- web/app/LoginManager.js | 6 ++---- web/app/view/device/Device.js | 11 +++++++---- web/app/view/device/DeviceController.js | 28 +++++++++++++++------------- web/app/view/login/LoginController.js | 2 +- web/app/view/map/Map.js | 4 ++-- web/app/view/user/UserDialogController.js | 4 ++-- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/web/app/LoginManager.js b/web/app/LoginManager.js index 93b3e913c..34069574b 100644 --- a/web/app/LoginManager.js +++ b/web/app/LoginManager.js @@ -21,8 +21,7 @@ Ext.define('Traccar.LoginManager', { var reader = Ext.create('Ext.data.reader.Json', { model: 'Traccar.model.User' }); - Traccar.getApplication().setUser( - reader.readRecords(data).getRecords()[0]); + Traccar.app.setUser(reader.readRecords(data).getRecords()[0]); }, server: function(options) { @@ -42,8 +41,7 @@ Ext.define('Traccar.LoginManager', { var reader = Ext.create('Ext.data.reader.Json', { model: 'Traccar.model.Server' }); - Traccar.getApplication().setServer( - reader.readRecords(result.data).getRecords()[0]); + Traccar.app.setServer(reader.readRecords(result.data).getRecords()[0]); } Ext.callback(options.callback, options.scope, [result.success]); } diff --git a/web/app/view/device/Device.js b/web/app/view/device/Device.js index 9cb2123dd..d77f405bd 100644 --- a/web/app/view/device/Device.js +++ b/web/app/view/device/Device.js @@ -82,9 +82,12 @@ Ext.define('Traccar.view.device.Device', { selectionchange: 'onSelectionChange' }, - columns: [ - { text: strings.deviceName, dataIndex: 'name', flex: 1 }, - { text: strings.deviceIdentifier, dataIndex: 'uniqueId', flex: 1 } - ] + columns: [{ + text: strings.deviceName, + dataIndex: 'name', flex: 1 + }, { + text: strings.deviceIdentifier, + dataIndex: 'uniqueId', flex: 1 + }] }); diff --git a/web/app/view/device/DeviceController.js b/web/app/view/device/DeviceController.js index 31caa5147..59b777f8b 100644 --- a/web/app/view/device/DeviceController.js +++ b/web/app/view/device/DeviceController.js @@ -37,7 +37,7 @@ Ext.define('Traccar.view.device.DeviceController', { }, init: function() { - if (Traccar.getApplication().getUser().get('admin')) { + if (Traccar.app.getUser().get('admin')) { this.lookupReference('settingsServerButton').setHidden(false); this.lookupReference('settingsUsersButton').setHidden(false); } @@ -48,15 +48,17 @@ Ext.define('Traccar.view.device.DeviceController', { }, onAddClick: function() { - var device = Ext.create('Traccar.model.Device'); - var dialog = Ext.create('Traccar.view.device.DeviceDialog'); + var device, dialog; + device = Ext.create('Traccar.model.Device'); + dialog = Ext.create('Traccar.view.device.DeviceDialog'); dialog.down('form').loadRecord(device); dialog.show(); }, onEditClick: function() { - var device = this.getView().getSelectionModel().getSelection()[0]; - var dialog = Ext.create('Traccar.view.device.DeviceDialog'); + var device, dialog; + device = this.getView().getSelectionModel().getSelection()[0]; + dialog = Ext.create('Traccar.view.device.DeviceDialog'); dialog.down('form').loadRecord(device); dialog.show(); }, @@ -72,8 +74,9 @@ Ext.define('Traccar.view.device.DeviceController', { no: strings.sharedCancel }, fn: function(btn) { + var store; if (btn === 'yes') { - var store = Ext.getStore('Devices'); + store = Ext.getStore('Devices'); store.remove(device); store.sync(); } @@ -82,10 +85,11 @@ Ext.define('Traccar.view.device.DeviceController', { }, onCommandClick: function() { - var device = this.getView().getSelectionModel().getSelection()[0]; - var command = Ext.create('Traccar.model.Command'); + var device, command, dialog; + device = this.getView().getSelectionModel().getSelection()[0]; + command = Ext.create('Traccar.model.Command'); command.set('deviceId', device.get('id')); - var dialog = Ext.create('Traccar.view.command.CommandDialog'); + dialog = Ext.create('Traccar.view.command.CommandDialog'); dialog.down('form').loadRecord(command); dialog.show(); }, @@ -101,16 +105,14 @@ Ext.define('Traccar.view.device.DeviceController', { }, onUserClick: function() { - var user = Traccar.getApplication().getUser(); var dialog = Ext.create('Traccar.view.user.UserDialog'); - dialog.down('form').loadRecord(user); + dialog.down('form').loadRecord(Traccar.app.getUser()); dialog.show(); }, onServerClick: function() { - var server = Traccar.getApplication().getServer(); var dialog = Ext.create('Traccar.view.admin.ServerDialog'); - dialog.down('form').loadRecord(server); + dialog.down('form').loadRecord(Traccar.app.getServer()); dialog.show(); }, diff --git a/web/app/view/login/LoginController.js b/web/app/view/login/LoginController.js index e809b0fbc..48a4aa0f7 100644 --- a/web/app/view/login/LoginController.js +++ b/web/app/view/login/LoginController.js @@ -24,7 +24,7 @@ Ext.define('Traccar.view.login.LoginController', { init: function() { this.lookupReference('registerButton').setDisabled( - !Traccar.getApplication().getServer().get('registration') + !Traccar.app.getServer().get('registration') ); this.lookupReference('languageField').setValue(language); diff --git a/web/app/view/map/Map.js b/web/app/view/map/Map.js index e70af0918..6e8ab6fad 100644 --- a/web/app/view/map/Map.js +++ b/web/app/view/map/Map.js @@ -30,8 +30,8 @@ Ext.define('Traccar.view.map.Map', { listeners: { afterrender: function() { - var user = Traccar.getApplication().getUser(); - var server = Traccar.getApplication().getServer(); + var user = Traccar.app.getUser(); + var server = Traccar.app.getServer(); var layer; var mapLayer = user.get('map') || server.get('map'); diff --git a/web/app/view/user/UserDialogController.js b/web/app/view/user/UserDialogController.js index cd37f70cf..dd3109d37 100644 --- a/web/app/view/user/UserDialogController.js +++ b/web/app/view/user/UserDialogController.js @@ -19,7 +19,7 @@ Ext.define('Traccar.view.user.UserDialogController', { alias: 'controller.userDialog', init: function() { - if (Traccar.getApplication().getUser().get('admin')) { + if (Traccar.app.getUser().get('admin')) { this.lookupReference('adminField').setDisabled(false); } }, @@ -28,7 +28,7 @@ Ext.define('Traccar.view.user.UserDialogController', { var dialog = button.up('window').down('form'); dialog.updateRecord(); var record = dialog.getRecord(); - if (record === Traccar.getApplication().getUser()) { + if (record === Traccar.app.getUser()) { record.save(); } else { var store = Ext.getStore('Users'); -- cgit v1.2.3