From d16121684ecae7646aa87616a64d60978d087bc0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 3 Oct 2015 20:39:14 +1300 Subject: Move remaining classes to view --- web/.jscsrc | 3 +- web/app/ErrorManager.js | 5 +- web/app/LoginManager.js | 8 +-- web/app/store/Languages.js | 8 +-- web/app/view/DeviceController.js | 6 +- web/app/view/Map.js | 6 +- web/app/view/User.js | 60 +++++++++++++++++++ web/app/view/UserController.js | 84 ++++++++++++++++++++++++++ web/app/view/UserDialog.js | 87 +++++++++++++++++++++++++++ web/app/view/UserDialogController.js | 47 +++++++++++++++ web/app/view/user/User.js | 61 ------------------- web/app/view/user/UserController.js | 84 -------------------------- web/app/view/user/UserDialog.js | 99 ------------------------------- web/app/view/user/UserDialogController.js | 52 ---------------- 14 files changed, 296 insertions(+), 314 deletions(-) create mode 100644 web/app/view/User.js create mode 100644 web/app/view/UserController.js create mode 100644 web/app/view/UserDialog.js create mode 100644 web/app/view/UserDialogController.js delete mode 100644 web/app/view/user/User.js delete mode 100644 web/app/view/user/UserController.js delete mode 100644 web/app/view/user/UserDialog.js delete mode 100644 web/app/view/user/UserDialogController.js diff --git a/web/.jscsrc b/web/.jscsrc index ac17b5dc9..7d924ab96 100644 --- a/web/.jscsrc +++ b/web/.jscsrc @@ -1,3 +1,4 @@ { - "preset": "crockford" + "preset": "crockford", + "maxErrors": 100 } diff --git a/web/app/ErrorManager.js b/web/app/ErrorManager.js index e8b29a319..e809fa382 100644 --- a/web/app/ErrorManager.js +++ b/web/app/ErrorManager.js @@ -16,10 +16,11 @@ Ext.define('Traccar.ErrorManager', { singleton: true, - + check: function (success, response) { + var result; if (success) { - var result = Ext.decode(response.responseText); + result = Ext.decode(response.responseText); if (result.success || result.error === undefined) { return true; } else { diff --git a/web/app/LoginManager.js b/web/app/LoginManager.js index 5a9615183..07445fc15 100644 --- a/web/app/LoginManager.js +++ b/web/app/LoginManager.js @@ -16,7 +16,7 @@ Ext.define('Traccar.LoginManager', { singleton: true, - + server: function (options) { Ext.Ajax.request({ scope: this, @@ -45,16 +45,16 @@ Ext.define('Traccar.LoginManager', { original: options }); }, - + onSessionReturn: function (options, success, response) { + var result; options = options.original; if (Traccar.ErrorManager.check(success, response)) { - var result = Ext.decode(response.responseText); + result = Ext.decode(response.responseText); if (result.success) { Traccar.app.setUser(result.data); } Ext.callback(options.callback, options.scope, [result.success]); } } - }); diff --git a/web/app/store/Languages.js b/web/app/store/Languages.js index 658b7bc21..22685173a 100644 --- a/web/app/store/Languages.js +++ b/web/app/store/Languages.js @@ -18,9 +18,9 @@ Ext.define('Traccar.store.Languages', { extend: 'Ext.data.Store', fields: ['code', 'name'], - data: function () { - var data = []; - for (var code in availableLanguages) { + data: (function () { + var code, data = []; + for (code in availableLanguages) { if (availableLanguages.hasOwnProperty(code)) { data.push({ code: code, @@ -29,5 +29,5 @@ Ext.define('Traccar.store.Languages', { } } return data; - }() + }()) }); diff --git a/web/app/view/DeviceController.js b/web/app/view/DeviceController.js index 64b3b8826..2e2fdb2a6 100644 --- a/web/app/view/DeviceController.js +++ b/web/app/view/DeviceController.js @@ -21,8 +21,8 @@ Ext.define('Traccar.view.DeviceController', { requires: [ 'Traccar.view.CommandDialog', 'Traccar.view.DeviceDialog', - 'Traccar.view.user.UserDialog', - 'Traccar.view.user.User', + 'Traccar.view.UserDialog', + 'Traccar.view.User', 'Traccar.view.LoginController' ], @@ -106,7 +106,7 @@ Ext.define('Traccar.view.DeviceController', { }, onUserClick: function () { - var dialog = Ext.create('Traccar.view.user.UserDialog'); + var dialog = Ext.create('Traccar.view.UserDialog'); dialog.down('form').loadRecord(Traccar.app.getUser()); dialog.show(); }, diff --git a/web/app/view/Map.js b/web/app/view/Map.js index 63be7f666..f7a763b9d 100644 --- a/web/app/view/Map.js +++ b/web/app/view/Map.js @@ -29,7 +29,6 @@ Ext.define('Traccar.view.Map', { listeners: { afterrender: function () { - var user = Traccar.app.getUser(); var server = Traccar.app.getServer(); @@ -67,14 +66,14 @@ Ext.define('Traccar.view.Map', { var zoom = user.get('zoom') || server.get('zoom') || styles.mapDefaultZoom; this.mapView = new ol.View({ - center: ol.proj.fromLonLat([ lon, lat ]), + center: ol.proj.fromLonLat([lon, lat]), zoom: zoom, maxZoom: styles.mapMaxZoom }); this.map = new ol.Map({ target: this.body.dom.id, - layers: [ layer, vectorLayer ], + layers: [layer, vectorLayer], view: this.mapView }); }, @@ -83,5 +82,4 @@ Ext.define('Traccar.view.Map', { this.map.updateSize(); } } - }); diff --git a/web/app/view/User.js b/web/app/view/User.js new file mode 100644 index 000000000..807095ebe --- /dev/null +++ b/web/app/view/User.js @@ -0,0 +1,60 @@ +/* + * 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.User', { + extend: 'Ext.grid.Panel', + xtype: 'userView', + + requires: [ + 'Traccar.view.UserController' + ], + + controller: 'user', + store: 'Users', + + selType: 'rowmodel', + + tbar: [{ + text: strings.sharedAdd, + handler: 'onAddClick', + reference: 'deviceAddButton' + }, { + text: strings.sharedEdit, + disabled: true, + handler: 'onEditClick', + reference: 'userEditButton' + }, { + text: strings.sharedRemove, + disabled: true, + handler: 'onRemoveClick', + reference: 'userRemoveButton' + }, { + text: strings.deviceTitle, + disabled: true, + handler: 'onDevicesClick', + reference: 'userDevicesButton' + }], + + listeners: { + selectionchange: 'onSelectionChange' + }, + + columns: [ + { text: strings.userName, dataIndex: 'name', flex: 1 }, + { text: strings.userEmail, dataIndex: 'email', flex: 1 }, + { text: strings.userAdmin, dataIndex: 'admin', flex: 1 } + ] +}); diff --git a/web/app/view/UserController.js b/web/app/view/UserController.js new file mode 100644 index 000000000..f541914e4 --- /dev/null +++ b/web/app/view/UserController.js @@ -0,0 +1,84 @@ +/* + * 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.UserController', { + extend: 'Ext.app.ViewController', + alias: 'controller.user', + + requires: [ + 'Traccar.view.UserDialog' + ], + + init: function () { + Ext.getStore('Users').load(); + }, + + onAddClick: function () { + var user = Ext.create('Traccar.model.User'); + var dialog = Ext.create('Traccar.view.UserDialog'); + dialog.down('form').loadRecord(user); + dialog.show(); + }, + + onEditClick: function () { + var user = this.getView().getSelectionModel().getSelection()[0]; + var dialog = Ext.create('Traccar.view.UserDialog'); + dialog.down('form').loadRecord(user); + dialog.show(); + }, + + onRemoveClick: function () { + var user = this.getView().getSelectionModel().getSelection()[0]; + Ext.Msg.show({ + title: strings.settingsUser, + message: strings.sharedRemoveConfirm, + buttons: Ext.Msg.YESNO, + buttonText: { + yes: strings.sharedRemove, + no: strings.sharedCancel + }, + fn: function (btn) { + if (btn === 'yes') { + var store = Ext.getStore('Users'); + store.remove(user); + store.sync(); + } + } + }); + }, + + onDevicesClick: function () { + // TODO show devices + /*Ext.create('Ext.window.Window', { + title: strings.settingsUsers, + width: styles.windowWidth, + height: styles.windowHeight, + layout: 'fit', + modal: true, + items: { + xtype: 'userView' + } + }).show();*/ + }, + + onSelectionChange: function (selected) { + var disabled = selected.length > 0; + this.lookupReference('userEditButton').setDisabled(disabled); + this.lookupReference('userRemoveButton').setDisabled(disabled); + this.lookupReference('userDevicesButton').setDisabled(disabled); + } + +}); diff --git a/web/app/view/UserDialog.js b/web/app/view/UserDialog.js new file mode 100644 index 000000000..0c5914ce0 --- /dev/null +++ b/web/app/view/UserDialog.js @@ -0,0 +1,87 @@ +/* + * 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.UserDialog', { + extend: 'Traccar.view.BaseEditDialog', + + requires: [ + 'Traccar.view.UserDialogController' + ], + + controller: 'userDialog', + + title: strings.settingsUser, + + items: { + xtype: 'form', + items: [{ + xtype: 'textfield', + name: 'name', + fieldLabel: strings.userName + }, { + xtype: 'textfield', + name: 'email', + fieldLabel: strings.userEmail, + allowBlank: false + }, { + xtype: 'textfield', + name: 'password', + fieldLabel: strings.userPassword, + inputType: 'password', + allowBlank: false + }, { + xtype: 'checkboxfield', + name: 'admin', + fieldLabel: strings.userAdmin, + allowBlank: false, + disabled: true, + reference: 'adminField' + }, { + xtype: 'combobox', + name: 'map', + fieldLabel: strings.mapLayer, + store: 'MapTypes', + displayField: 'name', + valueField: 'key' + }, { + xtype: 'combobox', + name: 'distanceUnit', + fieldLabel: strings.settingsDistanceUnit, + store: 'DistanceUnits', + displayField: 'name', + valueField: 'key' + }, { + xtype: 'combobox', + name: 'speedUnit', + fieldLabel: strings.settingsSpeedUnit, + store: 'SpeedUnits', + displayField: 'name', + valueField: 'key' + }, { + xtype: 'numberfield', + name: 'latitude', + fieldLabel: strings.positionLatitude + }, { + xtype: 'numberfield', + name: 'longitude', + fieldLabel: strings.positionLongitude + }, { + xtype: 'numberfield', + name: 'zoom', + fieldLabel: strings.serverZoom + }] + } +}); diff --git a/web/app/view/UserDialogController.js b/web/app/view/UserDialogController.js new file mode 100644 index 000000000..0bd9d87e3 --- /dev/null +++ b/web/app/view/UserDialogController.js @@ -0,0 +1,47 @@ +/* + * 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.UserDialogController', { + extend: 'Ext.app.ViewController', + alias: 'controller.userDialog', + + init: function () { + if (Traccar.app.getUser().get('admin')) { + this.lookupReference('adminField').setDisabled(false); + } + }, + + onSaveClick: function (button) { + var dialog = button.up('window').down('form'); + dialog.updateRecord(); + var record = dialog.getRecord(); + if (record === Traccar.app.getUser()) { + record.save(); + } else { + var store = Ext.getStore('Users'); + if (record.phantom) { + store.add(record); + } + store.sync({ + failure: function (batch) { + store.rejectChanges(); // TODO + Traccar.ErrorManager.check(true, batch.exceptions[0].getResponse()); + } + }); + } + button.up('window').close(); + } +}); diff --git a/web/app/view/user/User.js b/web/app/view/user/User.js deleted file mode 100644 index b5d216aea..000000000 --- a/web/app/view/user/User.js +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.user.User', { - extend: 'Ext.grid.Panel', - xtype: 'userView', - - requires: [ - 'Traccar.view.user.UserController' - ], - - controller: 'user', - store: 'Users', - - selType: 'rowmodel', - - tbar: [{ - text: strings.sharedAdd, - handler: 'onAddClick', - reference: 'deviceAddButton' - }, { - text: strings.sharedEdit, - disabled: true, - handler: 'onEditClick', - reference: 'userEditButton' - }, { - text: strings.sharedRemove, - disabled: true, - handler: 'onRemoveClick', - reference: 'userRemoveButton' - }, { - text: strings.deviceTitle, - disabled: true, - handler: 'onDevicesClick', - reference: 'userDevicesButton' - }], - - listeners: { - selectionchange: 'onSelectionChange' - }, - - columns: [ - { text: strings.userName, dataIndex: 'name', flex: 1 }, - { text: strings.userEmail, dataIndex: 'email', flex: 1 }, - { text: strings.userAdmin, dataIndex: 'admin', flex: 1 } - ] - -}); diff --git a/web/app/view/user/UserController.js b/web/app/view/user/UserController.js deleted file mode 100644 index 507fd5a5c..000000000 --- a/web/app/view/user/UserController.js +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.user.UserController', { - extend: 'Ext.app.ViewController', - alias: 'controller.user', - - requires: [ - 'Traccar.view.user.UserDialog' - ], - - init: function () { - Ext.getStore('Users').load(); - }, - - onAddClick: function () { - var user = Ext.create('Traccar.model.User'); - var dialog = Ext.create('Traccar.view.user.UserDialog'); - dialog.down('form').loadRecord(user); - dialog.show(); - }, - - onEditClick: function () { - var user = this.getView().getSelectionModel().getSelection()[0]; - var dialog = Ext.create('Traccar.view.user.UserDialog'); - dialog.down('form').loadRecord(user); - dialog.show(); - }, - - onRemoveClick: function () { - var user = this.getView().getSelectionModel().getSelection()[0]; - Ext.Msg.show({ - title: strings.settingsUser, - message: strings.sharedRemoveConfirm, - buttons: Ext.Msg.YESNO, - buttonText: { - yes: strings.sharedRemove, - no: strings.sharedCancel - }, - fn: function (btn) { - if (btn === 'yes') { - var store = Ext.getStore('Users'); - store.remove(user); - store.sync(); - } - } - }); - }, - - onDevicesClick: function () { - // TODO show devices - /*Ext.create('Ext.window.Window', { - title: strings.settingsUsers, - width: styles.windowWidth, - height: styles.windowHeight, - layout: 'fit', - modal: true, - items: { - xtype: 'userView' - } - }).show();*/ - }, - - onSelectionChange: function (selected) { - var disabled = selected.length > 0; - this.lookupReference('userEditButton').setDisabled(disabled); - this.lookupReference('userRemoveButton').setDisabled(disabled); - this.lookupReference('userDevicesButton').setDisabled(disabled); - } - -}); diff --git a/web/app/view/user/UserDialog.js b/web/app/view/user/UserDialog.js deleted file mode 100644 index d1bc68f96..000000000 --- a/web/app/view/user/UserDialog.js +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.user.UserDialog', { - extend: 'Ext.window.Window', - - requires: [ - 'Traccar.view.user.UserDialogController' - ], - - controller: 'userDialog', - - bodyPadding: styles.panelPadding, - title: strings.settingsUser, - resizable: false, - modal: true, - - items: { - xtype: 'form', - items: [{ - xtype: 'textfield', - name: 'name', - fieldLabel: strings.userName - }, { - xtype: 'textfield', - name: 'email', - fieldLabel: strings.userEmail, - allowBlank: false - }, { - xtype: 'textfield', - name: 'password', - fieldLabel: strings.userPassword, - inputType: 'password', - allowBlank: false - }, { - xtype: 'checkboxfield', - name: 'admin', - fieldLabel: strings.userAdmin, - allowBlank: false, - disabled: true, - reference: 'adminField' - }, { - xtype: 'combobox', - name: 'map', - fieldLabel: strings.mapLayer, - store: 'MapTypes', - displayField: 'name', - valueField: 'key' - }, { - xtype: 'combobox', - name: 'distanceUnit', - fieldLabel: strings.settingsDistanceUnit, - store: 'DistanceUnits', - displayField: 'name', - valueField: 'key' - }, { - xtype: 'combobox', - name: 'speedUnit', - fieldLabel: strings.settingsSpeedUnit, - store: 'SpeedUnits', - displayField: 'name', - valueField: 'key' - }, { - xtype: 'numberfield', - name: 'latitude', - fieldLabel: strings.positionLatitude - }, { - xtype: 'numberfield', - name: 'longitude', - fieldLabel: strings.positionLongitude - }, { - xtype: 'numberfield', - name: 'zoom', - fieldLabel: strings.serverZoom - }] - }, - - buttons: [{ - text: strings.sharedSave, - handler: 'onSaveClick' - }, { - text: strings.sharedCancel, - handler: 'onCancelClick' - }] - -}); diff --git a/web/app/view/user/UserDialogController.js b/web/app/view/user/UserDialogController.js deleted file mode 100644 index 40f938b5c..000000000 --- a/web/app/view/user/UserDialogController.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.user.UserDialogController', { - extend: 'Ext.app.ViewController', - alias: 'controller.userDialog', - - init: function () { - if (Traccar.app.getUser().get('admin')) { - this.lookupReference('adminField').setDisabled(false); - } - }, - - onSaveClick: function (button) { - var dialog = button.up('window').down('form'); - dialog.updateRecord(); - var record = dialog.getRecord(); - if (record === Traccar.app.getUser()) { - record.save(); - } else { - var store = Ext.getStore('Users'); - if (record.phantom) { - store.add(record); - } - store.sync({ - failure: function (batch) { - store.rejectChanges(); // TODO - Traccar.ErrorManager.check(true, batch.exceptions[0].getResponse()); - } - }); - } - button.up('window').close(); - }, - - onCancelClick: function (button) { - button.up('window').close(); - } - -}); -- cgit v1.2.3