From d243caa095ece5c130250d02e4f3ae7632a9db36 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 23 May 2017 14:45:18 +0500 Subject: Implement testing computedAttribute --- web/app/Application.js | 17 +++++-- web/app/view/dialog/ComputedAttribute.js | 6 +++ web/app/view/dialog/ComputedAttributeController.js | 13 +++++ web/app/view/dialog/SelectDevice.js | 59 ++++++++++++++++++++++ web/app/view/dialog/SelectDeviceController.js | 41 +++++++++++++++ 5 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 web/app/view/dialog/SelectDevice.js create mode 100644 web/app/view/dialog/SelectDeviceController.js (limited to 'web/app') diff --git a/web/app/Application.js b/web/app/Application.js index d73378c..0125cd0 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -164,15 +164,24 @@ Ext.define('Traccar.Application', { } }, - showError: function (error) { + showError: function (error, success) { + var title, general; + if (success) { + title = Strings.infoTitle; + general = Strings.infoGeneral; + } else { + title = Strings.errorTitle; + general = Strings.errorGeneral; + } + if (Ext.isString(error)) { - Ext.Msg.alert(Strings.errorTitle, error); + Ext.Msg.alert(title, error); } else if (error.responseText) { - Ext.Msg.alert(Strings.errorTitle, Strings.errorGeneral + + Ext.Msg.alert(title, general + '

'); } else if (error.statusText) { - Ext.Msg.alert(Strings.errorTitle, error.statusText); + Ext.Msg.alert(title, error.statusText); } else { Ext.Msg.alert(Strings.errorTitle, Strings.errorConnection); } diff --git a/web/app/view/dialog/ComputedAttribute.js b/web/app/view/dialog/ComputedAttribute.js index 90234b5..ef6269b 100644 --- a/web/app/view/dialog/ComputedAttribute.js +++ b/web/app/view/dialog/ComputedAttribute.js @@ -60,6 +60,12 @@ Ext.define('Traccar.view.dialog.ComputedAttribute', { }, buttons: [{ + glyph: 'xf128@FontAwesome', + tooltip: Strings.sharedCheckComputedAttribute, + tooltipType: 'title', + minWidth: 0, + handler: 'onCheckClick' + }, { glyph: 'xf00c@FontAwesome', tooltip: Strings.sharedSave, tooltipType: 'title', diff --git a/web/app/view/dialog/ComputedAttributeController.js b/web/app/view/dialog/ComputedAttributeController.js index 807653a..f680b1b 100644 --- a/web/app/view/dialog/ComputedAttributeController.js +++ b/web/app/view/dialog/ComputedAttributeController.js @@ -20,6 +20,10 @@ Ext.define('Traccar.view.dialog.ComputedAttributeController', { extend: 'Traccar.view.dialog.BaseEditController', alias: 'controller.computedAttribute', + requires: [ + 'Traccar.view.dialog.SelectDevice' + ], + onAttributeChange: function (combobox, newValue) { var attribute = Ext.getStore('PositionAttributes').getById(newValue); if (attribute) { @@ -28,5 +32,14 @@ Ext.define('Traccar.view.dialog.ComputedAttributeController', { } else { this.getView().lookupReference('typeComboField').setReadOnly(false); } + }, + + onCheckClick: function (button) { + var dialog, form; + dialog = Ext.create('Traccar.view.dialog.SelectDevice'); + form = button.up('window').down('form'); + form.updateRecord(); + dialog.record = form.getRecord(); + dialog.show(); } }); diff --git a/web/app/view/dialog/SelectDevice.js b/web/app/view/dialog/SelectDevice.js new file mode 100644 index 0000000..8037453 --- /dev/null +++ b/web/app/view/dialog/SelectDevice.js @@ -0,0 +1,59 @@ +/* + * 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.dialog.SelectDevice', { + extend: 'Traccar.view.dialog.Base', + + requires: [ + 'Traccar.view.dialog.SelectDeviceController' + ], + + controller: 'selectDevice', + title: Strings.sharedSelectDevice, + + items: { + xtype: 'form', + items: [{ + xtype: 'combobox', + reference: 'deviceField', + store: 'Devices', + queryMode: 'local', + displayField: 'name', + valueField: 'id', + editable: false, + listeners: { + change: 'onDeviceChange' + } + }] + }, + + buttons: [{ + glyph: 'xf00c@FontAwesome', + reference: 'saveButton', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick', + disabled: true + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/web/app/view/dialog/SelectDeviceController.js b/web/app/view/dialog/SelectDeviceController.js new file mode 100644 index 0000000..4336c48 --- /dev/null +++ b/web/app/view/dialog/SelectDeviceController.js @@ -0,0 +1,41 @@ +/* + * 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.dialog.SelectDeviceController', { + extend: 'Ext.app.ViewController', + alias: 'controller.selectDevice', + + onSaveClick: function (button) { + var deviceId, record; + deviceId = this.lookupReference('deviceField').getValue(); + record = this.getView().record.data; + Ext.Ajax.request({ + url: 'api/attributes/computed?deviceId=' + deviceId, + method: 'POST', + jsonData: Ext.util.JSON.encode(record), + callback: function (options, success, response) { + Traccar.app.showError(response, success); + } + }); + button.up('window').close(); + }, + + onDeviceChange: function (combobox, newValue) { + this.lookupReference('saveButton').setDisabled(newValue === null); + } +}); -- cgit v1.2.3 From 7f1a29d1f6606cd7d6469f769fd0e303badcd591 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 23 May 2017 15:23:07 +0500 Subject: - Revert showError function - Fix strings --- web/app/Application.js | 17 ++++------------- web/app/view/dialog/SelectDevice.js | 2 +- web/app/view/dialog/SelectDeviceController.js | 12 +++++++++++- web/l10n/en.json | 5 ++--- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'web/app') diff --git a/web/app/Application.js b/web/app/Application.js index 0125cd0..d73378c 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -164,24 +164,15 @@ Ext.define('Traccar.Application', { } }, - showError: function (error, success) { - var title, general; - if (success) { - title = Strings.infoTitle; - general = Strings.infoGeneral; - } else { - title = Strings.errorTitle; - general = Strings.errorGeneral; - } - + showError: function (error) { if (Ext.isString(error)) { - Ext.Msg.alert(title, error); + Ext.Msg.alert(Strings.errorTitle, error); } else if (error.responseText) { - Ext.Msg.alert(title, general + + Ext.Msg.alert(Strings.errorTitle, Strings.errorGeneral + '

'); } else if (error.statusText) { - Ext.Msg.alert(title, error.statusText); + Ext.Msg.alert(Strings.errorTitle, error.statusText); } else { Ext.Msg.alert(Strings.errorTitle, Strings.errorConnection); } diff --git a/web/app/view/dialog/SelectDevice.js b/web/app/view/dialog/SelectDevice.js index 8037453..5b11c03 100644 --- a/web/app/view/dialog/SelectDevice.js +++ b/web/app/view/dialog/SelectDevice.js @@ -23,7 +23,7 @@ Ext.define('Traccar.view.dialog.SelectDevice', { ], controller: 'selectDevice', - title: Strings.sharedSelectDevice, + title: Strings.sharedDevice, items: { xtype: 'form', diff --git a/web/app/view/dialog/SelectDeviceController.js b/web/app/view/dialog/SelectDeviceController.js index 4336c48..d8cd5d3 100644 --- a/web/app/view/dialog/SelectDeviceController.js +++ b/web/app/view/dialog/SelectDeviceController.js @@ -29,7 +29,17 @@ Ext.define('Traccar.view.dialog.SelectDeviceController', { method: 'POST', jsonData: Ext.util.JSON.encode(record), callback: function (options, success, response) { - Traccar.app.showError(response, success); + if (success) { + if (response.responseText) { + Ext.Msg.alert(Strings.sharedInfoTitle, Strings.sharedInfoGeneral + + '

'); + } else if (response.statusText) { + Ext.Msg.alert(Strings.sharedInfoTitle, response.statusText); + } + } else { + Traccar.app.showError(response); + } } }); button.up('window').close(); diff --git a/web/l10n/en.json b/web/l10n/en.json index 6e78e5c..024f147 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -50,7 +50,6 @@ "sharedExpression": "Expression", "sharedDeviceDistance": "Device Distance", "sharedDevice": "Device", - "sharedSelectDevice": "Select Device", "sharedTestNotification": "Send Test Notification", "sharedCalendar": "Calendar", "sharedCalendars": "Calendars", @@ -65,6 +64,8 @@ "sharedTypeNumber": "Number", "sharedTypeBoolean": "Boolean", "sharedTimezone": "Timezone", + "sharedInfoTitle": "Info", + "sharedInfoGeneral": "Responce", "attributeSpeedLimit": "Speed Limit", "attributeReportIgnoreOdometer": "Report: Ignore Odometer", "attributeMaintenanceStart": "Maintenance: Start", @@ -89,8 +90,6 @@ "errorGeneral": "Invalid parameters or constraints violation", "errorConnection": "Connection error", "errorSocket": "Web socket connection error", - "infoTitle": "Info", - "infoGeneral": "Responce", "userEmail": "Email", "userPassword": "Password", "userAdmin": "Admin", -- cgit v1.2.3 From 0b2fa6cd0c1221e559bbe48bffea6ce8ba7e749a Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 23 May 2017 15:32:10 +0500 Subject: Simple show response --- web/app/view/dialog/SelectDeviceController.js | 4 +--- web/l10n/en.json | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'web/app') diff --git a/web/app/view/dialog/SelectDeviceController.js b/web/app/view/dialog/SelectDeviceController.js index d8cd5d3..7b7277c 100644 --- a/web/app/view/dialog/SelectDeviceController.js +++ b/web/app/view/dialog/SelectDeviceController.js @@ -31,9 +31,7 @@ Ext.define('Traccar.view.dialog.SelectDeviceController', { callback: function (options, success, response) { if (success) { if (response.responseText) { - Ext.Msg.alert(Strings.sharedInfoTitle, Strings.sharedInfoGeneral + - '

'); + Ext.Msg.alert(Strings.sharedInfoTitle, response.responseText); } else if (response.statusText) { Ext.Msg.alert(Strings.sharedInfoTitle, response.statusText); } diff --git a/web/l10n/en.json b/web/l10n/en.json index 024f147..754295e 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -65,7 +65,6 @@ "sharedTypeBoolean": "Boolean", "sharedTimezone": "Timezone", "sharedInfoTitle": "Info", - "sharedInfoGeneral": "Responce", "attributeSpeedLimit": "Speed Limit", "attributeReportIgnoreOdometer": "Report: Ignore Odometer", "attributeMaintenanceStart": "Maintenance: Start", -- cgit v1.2.3 From dbf31c907fb261dbc02463e2582a1c1a05ab3657 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 23 May 2017 15:43:07 +0500 Subject: If optimization --- web/app/view/dialog/SelectDeviceController.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'web/app') diff --git a/web/app/view/dialog/SelectDeviceController.js b/web/app/view/dialog/SelectDeviceController.js index 7b7277c..9ed5e21 100644 --- a/web/app/view/dialog/SelectDeviceController.js +++ b/web/app/view/dialog/SelectDeviceController.js @@ -30,11 +30,7 @@ Ext.define('Traccar.view.dialog.SelectDeviceController', { jsonData: Ext.util.JSON.encode(record), callback: function (options, success, response) { if (success) { - if (response.responseText) { - Ext.Msg.alert(Strings.sharedInfoTitle, response.responseText); - } else if (response.statusText) { - Ext.Msg.alert(Strings.sharedInfoTitle, response.statusText); - } + Ext.Msg.alert(Strings.sharedInfoTitle, response.responseText || response.statusText); } else { Traccar.app.showError(response); } -- cgit v1.2.3