From 7925028c138228f369180adbd857f4cd986a6346 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 15 Oct 2015 14:49:15 +1300 Subject: Refactor some web interface classes --- web/app/view/Device.js | 61 -------------------- web/app/view/DeviceController.js | 101 --------------------------------- web/app/view/Devices.js | 61 ++++++++++++++++++++ web/app/view/DevicesController.js | 99 ++++++++++++++++++++++++++++++++ web/app/view/Main.js | 4 +- web/app/view/MainMobile.js | 4 +- web/app/view/SettingsMenuController.js | 7 ++- web/app/view/User.js | 58 ------------------- web/app/view/UserController.js | 78 ------------------------- web/app/view/UserDeviceDialog.js | 42 -------------- web/app/view/UserDevices.js | 58 +++++++++++++++++++ web/app/view/Users.js | 58 +++++++++++++++++++ web/app/view/UsersController.js | 76 +++++++++++++++++++++++++ 13 files changed, 361 insertions(+), 346 deletions(-) delete mode 100644 web/app/view/Device.js delete mode 100644 web/app/view/DeviceController.js create mode 100644 web/app/view/Devices.js create mode 100644 web/app/view/DevicesController.js delete mode 100644 web/app/view/User.js delete mode 100644 web/app/view/UserController.js delete mode 100644 web/app/view/UserDeviceDialog.js create mode 100644 web/app/view/UserDevices.js create mode 100644 web/app/view/Users.js create mode 100644 web/app/view/UsersController.js (limited to 'web') diff --git a/web/app/view/Device.js b/web/app/view/Device.js deleted file mode 100644 index e23151100..000000000 --- a/web/app/view/Device.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.Device', { - extend: 'Ext.grid.Panel', - xtype: 'deviceView', - - requires: [ - 'Traccar.view.DeviceController', - 'Traccar.view.EditToolbar', - 'Traccar.view.SettingsMenu' - ], - - controller: 'device', - store: 'Devices', - - title: Strings.deviceTitle, - selType: 'rowmodel', - - tbar: { - xtype: 'editToolbar', - items: [{ - disabled: true, - handler: 'onCommandClick', - reference: 'deviceCommandButton', - glyph: 'xf093@FontAwesome', - tooltip: Strings.deviceCommand, - tooltipType: 'title' - }, { - xtype: 'tbfill' - }, { - xtype: 'settingsMenu' - }] - }, - - listeners: { - selectionchange: 'onSelectionChange' - }, - - columns: [{ - text: Strings.deviceName, - dataIndex: 'name', flex: 1 - }, { - text: Strings.deviceIdentifier, - dataIndex: 'uniqueId', flex: 1 - }] - -}); diff --git a/web/app/view/DeviceController.js b/web/app/view/DeviceController.js deleted file mode 100644 index a7e90da40..000000000 --- a/web/app/view/DeviceController.js +++ /dev/null @@ -1,101 +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.DeviceController', { - extend: 'Ext.app.ViewController', - alias: 'controller.device', - - requires: [ - 'Traccar.view.CommandDialog', - 'Traccar.view.DeviceDialog', - 'Traccar.view.UserDialog', - 'Traccar.view.User' - ], - - config: { - listen: { - controller: { - '*': { - selectReport: 'selectReport' - } - } - } - }, - - onAddClick: function () { - var device, dialog; - device = Ext.create('Traccar.model.Device'); - device.store = this.getView().getStore(); - dialog = Ext.create('Traccar.view.DeviceDialog'); - dialog.down('form').loadRecord(device); - dialog.show(); - }, - - onEditClick: function () { - var device, dialog; - device = this.getView().getSelectionModel().getSelection()[0]; - dialog = Ext.create('Traccar.view.DeviceDialog'); - dialog.down('form').loadRecord(device); - dialog.show(); - }, - - onRemoveClick: function () { - var device = this.getView().getSelectionModel().getSelection()[0]; - Ext.Msg.show({ - title: Strings.deviceDialog, - message: Strings.sharedRemoveConfirm, - buttons: Ext.Msg.YESNO, - buttonText: { - yes: Strings.sharedRemove, - no: Strings.sharedCancel - }, - fn: function (btn) { - var store; - if (btn === 'yes') { - store = Ext.getStore('Devices'); - store.remove(device); - store.sync(); - } - } - }); - }, - - onCommandClick: function () { - var device, command, dialog; - device = this.getView().getSelectionModel().getSelection()[0]; - command = Ext.create('Traccar.model.Command'); - command.set('deviceId', device.get('id')); - dialog = Ext.create('Traccar.view.CommandDialog'); - dialog.down('form').loadRecord(command); - dialog.show(); - }, - - onSelectionChange: function (selected) { - var empty = selected.getCount() === 0; - this.lookupReference('toolbarEditButton').setDisabled(empty); - this.lookupReference('toolbarRemoveButton').setDisabled(empty); - this.lookupReference('deviceCommandButton').setDisabled(empty); - if (!empty) { - this.fireEvent('selectDevice', selected.getLastSelected()); - } - }, - - selectReport: function (position) { - if (position !== undefined) { - this.getView().getSelectionModel().deselectAll(); - } - } -}); diff --git a/web/app/view/Devices.js b/web/app/view/Devices.js new file mode 100644 index 000000000..9dcd76a55 --- /dev/null +++ b/web/app/view/Devices.js @@ -0,0 +1,61 @@ +/* + * 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.Devices', { + extend: 'Ext.grid.Panel', + xtype: 'devicesView', + + requires: [ + 'Traccar.view.DevicesController', + 'Traccar.view.EditToolbar', + 'Traccar.view.SettingsMenu' + ], + + controller: 'devices', + store: 'Devices', + + title: Strings.deviceTitle, + selType: 'rowmodel', + + tbar: { + xtype: 'editToolbar', + items: [{ + disabled: true, + handler: 'onCommandClick', + reference: 'deviceCommandButton', + glyph: 'xf093@FontAwesome', + tooltip: Strings.deviceCommand, + tooltipType: 'title' + }, { + xtype: 'tbfill' + }, { + xtype: 'settingsMenu' + }] + }, + + listeners: { + selectionchange: 'onSelectionChange' + }, + + columns: [{ + text: Strings.deviceName, + dataIndex: 'name', flex: 1 + }, { + text: Strings.deviceIdentifier, + dataIndex: 'uniqueId', flex: 1 + }] + +}); diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js new file mode 100644 index 000000000..dd3ca5a05 --- /dev/null +++ b/web/app/view/DevicesController.js @@ -0,0 +1,99 @@ +/* + * 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.DevicesController', { + extend: 'Ext.app.ViewController', + alias: 'controller.devices', + + requires: [ + 'Traccar.view.CommandDialog', + 'Traccar.view.DeviceDialog' + ], + + config: { + listen: { + controller: { + '*': { + selectReport: 'selectReport' + } + } + } + }, + + onAddClick: function () { + var device, dialog; + device = Ext.create('Traccar.model.Device'); + device.store = this.getView().getStore(); + dialog = Ext.create('Traccar.view.DeviceDialog'); + dialog.down('form').loadRecord(device); + dialog.show(); + }, + + onEditClick: function () { + var device, dialog; + device = this.getView().getSelectionModel().getSelection()[0]; + dialog = Ext.create('Traccar.view.DeviceDialog'); + dialog.down('form').loadRecord(device); + dialog.show(); + }, + + onRemoveClick: function () { + var device = this.getView().getSelectionModel().getSelection()[0]; + Ext.Msg.show({ + title: Strings.deviceDialog, + message: Strings.sharedRemoveConfirm, + buttons: Ext.Msg.YESNO, + buttonText: { + yes: Strings.sharedRemove, + no: Strings.sharedCancel + }, + fn: function (btn) { + var store; + if (btn === 'yes') { + store = Ext.getStore('Devices'); + store.remove(device); + store.sync(); + } + } + }); + }, + + onCommandClick: function () { + var device, command, dialog; + device = this.getView().getSelectionModel().getSelection()[0]; + command = Ext.create('Traccar.model.Command'); + command.set('deviceId', device.get('id')); + dialog = Ext.create('Traccar.view.CommandDialog'); + dialog.down('form').loadRecord(command); + dialog.show(); + }, + + onSelectionChange: function (selected) { + var empty = selected.getCount() === 0; + this.lookupReference('toolbarEditButton').setDisabled(empty); + this.lookupReference('toolbarRemoveButton').setDisabled(empty); + this.lookupReference('deviceCommandButton').setDisabled(empty); + if (!empty) { + this.fireEvent('selectDevice', selected.getLastSelected()); + } + }, + + selectReport: function (position) { + if (position !== undefined) { + this.getView().getSelectionModel().deselectAll(); + } + } +}); diff --git a/web/app/view/Main.js b/web/app/view/Main.js index fc29d43aa..156e0b970 100644 --- a/web/app/view/Main.js +++ b/web/app/view/Main.js @@ -19,7 +19,7 @@ Ext.define('Traccar.view.Main', { alias: 'widget.main', requires: [ - 'Traccar.view.Device', + 'Traccar.view.Devices', 'Traccar.view.State', 'Traccar.view.Report', 'Traccar.view.Map' @@ -45,7 +45,7 @@ Ext.define('Traccar.view.Main', { items: [{ region: 'center', - xtype: 'deviceView' + xtype: 'devicesView' }, { region: 'south', xtype: 'stateView' diff --git a/web/app/view/MainMobile.js b/web/app/view/MainMobile.js index e42fc7f7f..f3d0b6339 100644 --- a/web/app/view/MainMobile.js +++ b/web/app/view/MainMobile.js @@ -19,7 +19,7 @@ Ext.define('Traccar.view.MainMobile', { alias: 'widget.mainMobile', requires: [ - 'Traccar.view.Device', + 'Traccar.view.Devices', 'Traccar.view.State', 'Traccar.view.Map' ], @@ -43,7 +43,7 @@ Ext.define('Traccar.view.MainMobile', { flex: 2 }, { region: 'south', - xtype: 'deviceView', + xtype: 'devicesView', flex: 1 }] }); diff --git a/web/app/view/SettingsMenuController.js b/web/app/view/SettingsMenuController.js index b63cf42f8..920356010 100644 --- a/web/app/view/SettingsMenuController.js +++ b/web/app/view/SettingsMenuController.js @@ -19,7 +19,10 @@ Ext.define('Traccar.view.SettingsMenuController', { alias: 'controller.settings', requires: [ - 'Traccar.view.LoginController' + 'Traccar.view.LoginController', + 'Traccar.view.UserDialog', + 'Traccar.view.ServerDialog', + 'Traccar.view.Users' ], init: function () { @@ -49,7 +52,7 @@ Ext.define('Traccar.view.SettingsMenuController', { layout: 'fit', modal: true, items: { - xtype: 'userView' + xtype: 'usersView' } }).show(); }, diff --git a/web/app/view/User.js b/web/app/view/User.js deleted file mode 100644 index 67a290f73..000000000 --- a/web/app/view/User.js +++ /dev/null @@ -1,58 +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', { - extend: 'Ext.grid.Panel', - xtype: 'userView', - - requires: [ - 'Traccar.view.UserController', - 'Traccar.view.EditToolbar' - ], - - controller: 'user', - store: 'Users', - - selType: 'rowmodel', - - tbar: { - xtype: 'editToolbar', - items: [{ - 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 deleted file mode 100644 index 4ebc0d27c..000000000 --- a/web/app/view/UserController.js +++ /dev/null @@ -1,78 +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.UserController', { - extend: 'Ext.app.ViewController', - alias: 'controller.user', - - requires: [ - 'Traccar.view.UserDialog', - 'Traccar.view.UserDeviceDialog' - ], - - init: function () { - Ext.getStore('Users').load(); - }, - - onAddClick: function () { - var user, dialog; - user = Ext.create('Traccar.model.User'); - dialog = Ext.create('Traccar.view.UserDialog'); - dialog.down('form').loadRecord(user); - dialog.show(); - }, - - onEditClick: function () { - var user, dialog; - user = this.getView().getSelectionModel().getSelection()[0]; - 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 () { - var dialog = Ext.create('Traccar.view.UserDeviceDialog'); - dialog.show(); - }, - - onSelectionChange: function (selected) { - var disabled = selected.length > 0; - this.lookupReference('toolbarEditButton').setDisabled(disabled); - this.lookupReference('toolbarRemoveButton').setDisabled(disabled); - this.lookupReference('userDevicesButton').setDisabled(disabled); - } - -}); diff --git a/web/app/view/UserDeviceDialog.js b/web/app/view/UserDeviceDialog.js deleted file mode 100644 index 7e0b1eb88..000000000 --- a/web/app/view/UserDeviceDialog.js +++ /dev/null @@ -1,42 +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.UserDeviceDialog', { - extend: 'Traccar.view.BaseEditDialog', - - requires: [ - 'Traccar.view.BaseEditDialogController' - ], - - controller: 'baseEditDialog', - title: Strings.deviceTitle, - - width: Traccar.Style.windowWidth, - - items: { - xtype: 'form', - items: [{ - xtype: 'itemselectorfield', - anchor: '100%', - store: 'Languages', - displayField: 'name', - valueField: 'id', - fromTitle: 'Available', - toTitle: 'Selected', - maxHeight: Traccar.Style.windowHeight - }] - } -}); diff --git a/web/app/view/UserDevices.js b/web/app/view/UserDevices.js new file mode 100644 index 000000000..5eeaac39b --- /dev/null +++ b/web/app/view/UserDevices.js @@ -0,0 +1,58 @@ +/* + * 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.UserDevices', { + extend: 'Ext.grid.Panel', + xtype: 'userDevicesView', + + requires: [ + 'Traccar.view.UsersController', + 'Traccar.view.EditToolbar' + ], + + controller: 'users', + store: 'Users', + + selType: 'rowmodel', + + tbar: { + xtype: 'editToolbar', + items: [{ + 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/Users.js b/web/app/view/Users.js new file mode 100644 index 000000000..f4ef332b4 --- /dev/null +++ b/web/app/view/Users.js @@ -0,0 +1,58 @@ +/* + * 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.Users', { + extend: 'Ext.grid.Panel', + xtype: 'usersView', + + requires: [ + 'Traccar.view.UsersController', + 'Traccar.view.EditToolbar' + ], + + controller: 'users', + store: 'Users', + + selType: 'rowmodel', + + tbar: { + xtype: 'editToolbar', + items: [{ + 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/UsersController.js b/web/app/view/UsersController.js new file mode 100644 index 000000000..c8fd137ed --- /dev/null +++ b/web/app/view/UsersController.js @@ -0,0 +1,76 @@ +/* + * 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.UsersController', { + extend: 'Ext.app.ViewController', + alias: 'controller.users', + + requires: [ + 'Traccar.view.UserDialog' + ], + + init: function () { + Ext.getStore('Users').load(); + }, + + onAddClick: function () { + var user, dialog; + user = Ext.create('Traccar.model.User'); + dialog = Ext.create('Traccar.view.UserDialog'); + dialog.down('form').loadRecord(user); + dialog.show(); + }, + + onEditClick: function () { + var user, dialog; + user = this.getView().getSelectionModel().getSelection()[0]; + 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 () { + //var dialog = Ext.create('Traccar.view.UserDeviceDialog'); + //dialog.show(); + }, + + onSelectionChange: function (selected) { + var disabled = selected.length > 0; + this.lookupReference('toolbarEditButton').setDisabled(disabled); + this.lookupReference('toolbarRemoveButton').setDisabled(disabled); + this.lookupReference('userDevicesButton').setDisabled(disabled); + } +}); -- cgit v1.2.3