From 7f35b89560276d2ae23fb1164a429283fb64ff45 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Sun, 23 Oct 2016 10:58:06 +0500 Subject: - Implement reset device distance dialog - Add label to device selector in AttributeAliases --- web/app/view/AttributeAliases.js | 1 + web/app/view/DeviceDialog.js | 2 +- web/app/view/DeviceDistanceController.js | 44 +++++++++++++++++++++++++ web/app/view/DeviceDistanceDialog.js | 55 ++++++++++++++++++++++++++++++++ web/app/view/SettingsMenu.js | 5 +++ web/app/view/SettingsMenuController.js | 7 ++++ 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 web/app/view/DeviceDistanceController.js create mode 100644 web/app/view/DeviceDistanceDialog.js (limited to 'web/app/view') diff --git a/web/app/view/AttributeAliases.js b/web/app/view/AttributeAliases.js index 182a9cd..706c575 100644 --- a/web/app/view/AttributeAliases.js +++ b/web/app/view/AttributeAliases.js @@ -33,6 +33,7 @@ Ext.define('Traccar.view.AttributeAliases', { xtype: 'editToolbar', items: ['-', { xtype: 'combobox', + fieldLabel: Strings.sharedDevice, reference: 'deviceField', store: 'Devices', displayField: 'name', diff --git a/web/app/view/DeviceDialog.js b/web/app/view/DeviceDialog.js index ab602b8..d746fa7 100644 --- a/web/app/view/DeviceDialog.js +++ b/web/app/view/DeviceDialog.js @@ -23,7 +23,7 @@ Ext.define('Traccar.view.DeviceDialog', { ], controller: 'baseEditDialog', - title: Strings.deviceDialog, + title: Strings.sharedDevice, items: { xtype: 'form', diff --git a/web/app/view/DeviceDistanceController.js b/web/app/view/DeviceDistanceController.js new file mode 100644 index 0000000..0ce80a5 --- /dev/null +++ b/web/app/view/DeviceDistanceController.js @@ -0,0 +1,44 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +Ext.define('Traccar.view.DeviceDistanceController', { + extend: 'Ext.app.ViewController', + alias: 'controller.deviceDistanceDialog', + + onDeviceChange: function (combobox, newValue) { + this.lookupReference('setButton').setDisabled(newValue === null); + }, + + onSetClick: function (button) { + var data = {}; + data.deviceId = this.lookupReference('deviceId').getValue(); + data.totalDistance = this.lookupReference('totalDistance').getValue(); + Ext.Ajax.request({ + scope: this, + method: 'PUT', + url: 'api/devices/' + data.deviceId + '/distance', + jsonData: Ext.util.JSON.encode(data), + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + button.up('window').close(); + } +}); diff --git a/web/app/view/DeviceDistanceDialog.js b/web/app/view/DeviceDistanceDialog.js new file mode 100644 index 0000000..2b643c0 --- /dev/null +++ b/web/app/view/DeviceDistanceDialog.js @@ -0,0 +1,55 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +Ext.define('Traccar.view.DeviceDistanceDialog', { + extend: 'Traccar.view.BaseDialog', + + requires: [ + 'Traccar.view.DeviceDistanceController' + ], + + controller: 'deviceDistanceDialog', + title: Strings.sharedDeviceDistance, + + items: [{ + xtype: 'combobox', + reference: 'deviceId', + fieldLabel: Strings.sharedDevice, + store: 'AllDevices', + displayField: 'name', + valueField: 'id', + listeners: { + change: 'onDeviceChange' + } + }, { + xtype: 'numberfield', + reference: 'totalDistance', + fieldLabel: Strings.deviceTotalDistance, + value: 0 + }], + + buttons: [{ + text: Strings.sharedSet, + disabled: true, + reference: 'setButton', + handler: 'onSetClick' + }, { + text: Strings.sharedCancel, + handler: 'closeView' + }] +}); diff --git a/web/app/view/SettingsMenu.js b/web/app/view/SettingsMenu.js index c494572..aa0d18b 100644 --- a/web/app/view/SettingsMenu.js +++ b/web/app/view/SettingsMenu.js @@ -61,6 +61,11 @@ Ext.define('Traccar.view.SettingsMenu', { text: Strings.sharedAttributeAliases, handler: 'onAttributeAliasesClick', reference: 'settingsAttributeAliasesButton' + }, { + hidden: true, + text: Strings.sharedDeviceDistance, + handler: 'onDeviceDistanceClick', + reference: 'settingsDeviceDistanceButton' }, { hidden: true, text: Strings.statisticsTitle, diff --git a/web/app/view/SettingsMenuController.js b/web/app/view/SettingsMenuController.js index 9d547c5..12630dd 100644 --- a/web/app/view/SettingsMenuController.js +++ b/web/app/view/SettingsMenuController.js @@ -29,6 +29,7 @@ Ext.define('Traccar.view.SettingsMenuController', { 'Traccar.view.Notifications', 'Traccar.view.AttributeAliases', 'Traccar.view.Statistics', + 'Traccar.view.DeviceDistanceDialog', 'Traccar.view.BaseWindow' ], @@ -40,6 +41,7 @@ Ext.define('Traccar.view.SettingsMenuController', { this.lookupReference('settingsServerButton').setHidden(false); this.lookupReference('settingsUsersButton').setHidden(false); this.lookupReference('settingsStatisticsButton').setHidden(false); + this.lookupReference('settingsDeviceDistanceButton').setHidden(false); } if (admin || !readonly) { this.lookupReference('settingsGroupsButton').setHidden(false); @@ -122,6 +124,11 @@ Ext.define('Traccar.view.SettingsMenuController', { }).show(); }, + onDeviceDistanceClick: function () { + var dialog = Ext.create('Traccar.view.DeviceDistanceDialog'); + dialog.show(); + }, + onLogoutClick: function () { Ext.create('Traccar.view.LoginController').logout(); } -- cgit v1.2.3