From a5d36c62facad98c409b9fcd4f8b92c3d47601ab Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 12 Sep 2017 17:39:43 +0500 Subject: Implement Saved Commands --- web/app/view/edit/SavedCommands.js | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 web/app/view/edit/SavedCommands.js (limited to 'web/app/view/edit/SavedCommands.js') diff --git a/web/app/view/edit/SavedCommands.js b/web/app/view/edit/SavedCommands.js new file mode 100644 index 00000000..8f1f6b38 --- /dev/null +++ b/web/app/view/edit/SavedCommands.js @@ -0,0 +1,66 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org) + * + * 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.edit.SavedCommands', { + extend: 'Ext.grid.Panel', + xtype: 'savedCommandsView', + + requires: [ + 'Ext.grid.filters.Filters', + 'Traccar.view.edit.SavedCommandsController', + 'Traccar.view.edit.Toolbar' + ], + + plugins: 'gridfilters', + + controller: 'savedCommands', + store: 'Commands', + + tbar: { + xtype: 'editToolbar' + }, + + listeners: { + selectionchange: 'onSelectionChange' + }, + + columns: { + defaults: { + flex: 1, + minWidth: Traccar.Style.columnWidthNormal + }, + items: [{ + text: Strings.sharedDescription, + dataIndex: 'description', + filter: 'string' + }, { + text: Strings.sharedType, + dataIndex: 'name', + filter: { + type: 'list', + idField: 'name', + labelField: 'name', + store: 'AllCommandTypes' + } + }, { + text: Strings.notificationSms, + dataIndex: 'textChannel', + filter: 'boolean' + }] + } +}); -- cgit v1.2.3 From be47d612285d484e2d0a2aa43174fb8e36acd816 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 14 Sep 2017 09:38:14 +0500 Subject: Improve command type formatting --- web/app/AttributeFormatter.js | 7 +++++++ web/app/model/Command.js | 8 -------- web/app/model/KnownCommand.js | 3 +-- web/app/view/dialog/BaseEditController.js | 2 +- web/app/view/dialog/SendCommand.js | 2 +- web/app/view/dialog/SendCommandController.js | 9 ++++++--- web/app/view/edit/DevicesController.js | 1 - web/app/view/edit/SavedCommands.js | 7 ++++--- web/app/view/permissions/SavedCommands.js | 7 ++++--- web/l10n/en.json | 2 +- 10 files changed, 25 insertions(+), 23 deletions(-) (limited to 'web/app/view/edit/SavedCommands.js') diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js index 8a9e3dca..289aff91 100644 --- a/web/app/AttributeFormatter.js +++ b/web/app/AttributeFormatter.js @@ -130,6 +130,11 @@ Ext.define('Traccar.AttributeFormatter', { return null; }, + commandTypeFormatter: function (value) { + var name = Strings['command' + value.charAt(0).toUpperCase() + value.slice(1)]; + return name ? name : value; + }, + defaultFormatter: function (value) { if (typeof value === 'number') { return Number(value.toFixed(Traccar.Style.numberPrecision)); @@ -175,6 +180,8 @@ Ext.define('Traccar.AttributeFormatter', { return this.volumeFormatter; case 'driverUniqueId': return this.driverUniqueIdFormatter; + case 'commandType': + return this.commandTypeFormatter; default: return this.defaultFormatter; } diff --git a/web/app/model/Command.js b/web/app/model/Command.js index aa3dad14..f64d2a4b 100644 --- a/web/app/model/Command.js +++ b/web/app/model/Command.js @@ -31,14 +31,6 @@ Ext.define('Traccar.model.Command', { }, { name: 'type', type: 'string' - }, { - name: 'name', - convert: function (v, rec) { - var name = Strings['command' + rec.get('type').charAt(0).toUpperCase() + rec.get('type').slice(1)]; - return name ? name : rec.get('type'); - }, - depends: ['type'], - persist: false }, { name: 'textChannel', type: 'boolean' diff --git a/web/app/model/KnownCommand.js b/web/app/model/KnownCommand.js index 08213020..06610e32 100644 --- a/web/app/model/KnownCommand.js +++ b/web/app/model/KnownCommand.js @@ -25,8 +25,7 @@ Ext.define('Traccar.model.KnownCommand', { }, { name: 'name', convert: function (v, rec) { - var name = Strings['command' + rec.get('type').charAt(0).toUpperCase() + rec.get('type').slice(1)]; - return name ? name : rec.get('type'); + return Traccar.AttributeFormatter.getFormatter('commandType')(rec.get('type')); }, depends: ['type'] }, { diff --git a/web/app/view/dialog/BaseEditController.js b/web/app/view/dialog/BaseEditController.js index f58b6cb7..91379e2d 100644 --- a/web/app/view/dialog/BaseEditController.js +++ b/web/app/view/dialog/BaseEditController.js @@ -43,7 +43,7 @@ Ext.define('Traccar.view.dialog.BaseEditController', { } else { record.save(); } - button.up('window').close(); + this.closeView(); }, showAttributesView: function (button) { diff --git a/web/app/view/dialog/SendCommand.js b/web/app/view/dialog/SendCommand.js index 0bb7d610..f4224bec 100644 --- a/web/app/view/dialog/SendCommand.js +++ b/web/app/view/dialog/SendCommand.js @@ -29,7 +29,7 @@ Ext.define('Traccar.view.dialog.SendCommand', { items: [{ xtype: 'combobox', reference: 'commandsComboBox', - fieldLabel: Strings.sharedSavedCommand, + fieldLabel: Strings.deviceCommand, displayField: 'description', valueField: 'id', store: 'DeviceCommands', diff --git a/web/app/view/dialog/SendCommandController.js b/web/app/view/dialog/SendCommandController.js index 3bd2ad4a..0e9442ab 100644 --- a/web/app/view/dialog/SendCommandController.js +++ b/web/app/view/dialog/SendCommandController.js @@ -36,9 +36,7 @@ Ext.define('Traccar.view.dialog.SendCommandController', { Ext.Ajax.request({ scope: this, url: 'api/commands/send', - jsonData: record.getData({ - persist: true - }), + jsonData: record.getData(), callback: this.onSendResult }); }, @@ -89,5 +87,10 @@ Ext.define('Traccar.view.dialog.SendCommandController', { } else { Traccar.app.showError(response); } + }, + + closeView: function () { + this.lookupReference('commandsComboBox').getStore().removeAll(); + this.callParent(arguments); } }); diff --git a/web/app/view/edit/DevicesController.js b/web/app/view/edit/DevicesController.js index 43bab228..915f724a 100644 --- a/web/app/view/edit/DevicesController.js +++ b/web/app/view/edit/DevicesController.js @@ -126,7 +126,6 @@ Ext.define('Traccar.view.edit.DevicesController', { commandsStore = dialog.lookupReference('commandsComboBox').getStore(); commandsStore.getProxy().setExtraParam('deviceId', deviceId); - commandsStore.removeAll(); if (!Traccar.app.getPreference('limitCommands', false)) { commandsStore.add({ id: 0, diff --git a/web/app/view/edit/SavedCommands.js b/web/app/view/edit/SavedCommands.js index 8f1f6b38..869fbf9a 100644 --- a/web/app/view/edit/SavedCommands.js +++ b/web/app/view/edit/SavedCommands.js @@ -50,13 +50,14 @@ Ext.define('Traccar.view.edit.SavedCommands', { filter: 'string' }, { text: Strings.sharedType, - dataIndex: 'name', + dataIndex: 'type', filter: { type: 'list', - idField: 'name', + idField: 'type', labelField: 'name', store: 'AllCommandTypes' - } + }, + renderer: Traccar.AttributeFormatter.getFormatter('commandType') }, { text: Strings.notificationSms, dataIndex: 'textChannel', diff --git a/web/app/view/permissions/SavedCommands.js b/web/app/view/permissions/SavedCommands.js index 1c7ab775..106fad52 100644 --- a/web/app/view/permissions/SavedCommands.js +++ b/web/app/view/permissions/SavedCommands.js @@ -35,15 +35,16 @@ Ext.define('Traccar.view.permissions.SavedCommands', { filter: 'string' }, { text: Strings.sharedType, - dataIndex: 'name', + dataIndex: 'type', flex: 1, minWidth: Traccar.Style.columnWidthNormal, filter: { type: 'list', - idField: 'name', + idField: 'type', labelField: 'name', store: 'AllCommandTypes' - } + }, + renderer: Traccar.AttributeFormatter.getFormatter('commandType') }, { text: Strings.notificationSms, dataIndex: 'textChannel', diff --git a/web/l10n/en.json b/web/l10n/en.json index de0cb7ee..aeb20ddc 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -71,7 +71,7 @@ "sharedInfoTitle": "Info", "sharedSavedCommand": "Saved Command", "sharedSavedCommands": "Saved Commands", - "sharedNew": "New ...", + "sharedNew": "New…", "attributeSpeedLimit": "Speed Limit", "attributeReportIgnoreOdometer": "Report: Ignore Odometer", "attributeMaintenanceStart": "Maintenance: Start", -- cgit v1.2.3