diff options
author | Abyss777 <abyss@fox5.ru> | 2017-04-04 17:16:05 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-04-04 17:16:05 +0500 |
commit | 8c4337fb90487ce9986ab67fcb695a53e90f74d9 (patch) | |
tree | a0447f3dec02b4a2ebd6090ea3c739087668d828 | |
parent | 247a6bd4193077bd77608aca87d4e912f2c028ac (diff) | |
download | etbsa-traccar-web-8c4337fb90487ce9986ab67fcb695a53e90f74d9.tar.gz etbsa-traccar-web-8c4337fb90487ce9986ab67fcb695a53e90f74d9.tar.bz2 etbsa-traccar-web-8c4337fb90487ce9986ab67fcb695a53e90f74d9.zip |
Implement known attributes
-rw-r--r-- | web/app.css | 5 | ||||
-rw-r--r-- | web/app/Application.js | 10 | ||||
-rw-r--r-- | web/app/model/KnownAttribute.js | 29 | ||||
-rw-r--r-- | web/app/store/DeviceAttributes.js | 45 | ||||
-rw-r--r-- | web/app/store/GeofenceAttributes.js | 27 | ||||
-rw-r--r-- | web/app/store/GroupAttributes.js | 39 | ||||
-rw-r--r-- | web/app/store/ServerAttributes.js | 36 | ||||
-rw-r--r-- | web/app/store/UserAttributes.js | 62 | ||||
-rw-r--r-- | web/app/view/dialog/Attribute.js | 8 | ||||
-rw-r--r-- | web/app/view/dialog/AttributeController.js | 52 | ||||
-rw-r--r-- | web/app/view/edit/AttributesController.js | 60 | ||||
-rw-r--r-- | web/load.js | 3 |
12 files changed, 368 insertions, 8 deletions
diff --git a/web/app.css b/web/app.css index cb9d2bc..73398cd 100644 --- a/web/app.css +++ b/web/app.css @@ -12,6 +12,11 @@ background-color: #5fa2dd !important; } +/* workaround for https://www.sencha.com/forum/showthread.php?330718-6-2-ColorField-color-preview-doesn-t-match-color */ +.custom-color-picker-swatch { + z-index: 10 !important; +} + body.x-border-layout-ct, div.x-border-layout-ct { background-color: #bbbbbb !important; } diff --git a/web/app/Application.js b/web/app/Application.js index 9b45046..1658e7d 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -38,7 +38,8 @@ Ext.define('Traccar.Application', { 'AttributeAlias', 'ReportSummary', 'ReportTrip', - 'Calendar' + 'Calendar', + 'KnownAttribute' ], stores: [ @@ -77,7 +78,12 @@ Ext.define('Traccar.Application', { 'AllCalendars', 'AllTimezones', 'VisibleDevices', - 'DeviceStatuses' + 'DeviceStatuses', + 'DeviceAttributes', + 'GeofenceAttributes', + 'GroupAttributes', + 'ServerAttributes', + 'UserAttributes' ], controllers: [ diff --git a/web/app/model/KnownAttribute.js b/web/app/model/KnownAttribute.js new file mode 100644 index 0000000..8e578d9 --- /dev/null +++ b/web/app/model/KnownAttribute.js @@ -0,0 +1,29 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ +Ext.define('Traccar.model.KnownAttribute', { + extend: 'Ext.data.Model', + idProperty: 'key', + + fields: [{ + name: 'key', + type: 'string' + }, { + name: 'type', + type: 'string' + }] +}); diff --git a/web/app/store/DeviceAttributes.js b/web/app/store/DeviceAttributes.js new file mode 100644 index 0000000..9f1ec50 --- /dev/null +++ b/web/app/store/DeviceAttributes.js @@ -0,0 +1,45 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ +Ext.define('Traccar.store.DeviceAttributes', { + extend: 'Ext.data.Store', + model: 'Traccar.model.KnownAttribute', + proxy: 'memory', + + data: [{ + key: 'speedLimit', + type: 'number' + }, { + key: 'report.ignoreOdometer', + type: 'boolean' + }, { + key: 'maintenance.start', + type: 'number' + }, { + key: 'maintenance.interval', + type: 'number' + }, { + key: 'web.reportColor', + type: 'color' + }, { + key: 'devicePassword', + type: 'string' + }, { + key: 'processing.copyAttributes', + type: 'string' + }] +}); diff --git a/web/app/store/GeofenceAttributes.js b/web/app/store/GeofenceAttributes.js new file mode 100644 index 0000000..79217f6 --- /dev/null +++ b/web/app/store/GeofenceAttributes.js @@ -0,0 +1,27 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ +Ext.define('Traccar.store.GeofenceAttributes', { + extend: 'Ext.data.Store', + model: 'Traccar.model.KnownAttribute', + proxy: 'memory', + + data: [{ + key: 'color', + type: 'color' + }] +}); diff --git a/web/app/store/GroupAttributes.js b/web/app/store/GroupAttributes.js new file mode 100644 index 0000000..baf2286 --- /dev/null +++ b/web/app/store/GroupAttributes.js @@ -0,0 +1,39 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ +Ext.define('Traccar.store.GroupAttributes', { + extend: 'Ext.data.Store', + model: 'Traccar.model.KnownAttribute', + proxy: 'memory', + + data: [{ + key: 'speedLimit', + type: 'number' + }, { + key: 'report.ignoreOdometer', + type: 'boolean' + }, { + key: 'maintenance.start', + type: 'number' + }, { + key: 'maintenance.interval', + type: 'number' + }, { + key: 'processing.copyAttributes', + type: 'string' + }] +}); diff --git a/web/app/store/ServerAttributes.js b/web/app/store/ServerAttributes.js new file mode 100644 index 0000000..23755ba --- /dev/null +++ b/web/app/store/ServerAttributes.js @@ -0,0 +1,36 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ +Ext.define('Traccar.store.ServerAttributes', { + extend: 'Ext.data.Store', + model: 'Traccar.model.KnownAttribute', + proxy: 'memory', + + data: [{ + key: 'speedLimit', + type: 'number' + }, { + key: 'maintenance.start', + type: 'number' + }, { + key: 'maintenance.interval', + type: 'number' + }, { + key: 'web.liveRouteLength', + type: 'number' + }] +}); diff --git a/web/app/store/UserAttributes.js b/web/app/store/UserAttributes.js new file mode 100644 index 0000000..3720475 --- /dev/null +++ b/web/app/store/UserAttributes.js @@ -0,0 +1,62 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + */ +Ext.define('Traccar.store.UserAttributes', { + extend: 'Ext.data.Store', + model: 'Traccar.model.KnownAttribute', + proxy: 'memory', + + data: [{ + key: 'mail.smtp.host', + type: 'string' + }, { + key: 'mail.smtp.port', + type: 'number', + minValue: 1, + maxValue: 65535 + }, { + key: 'mail.smtp.starttls.enable', + type: 'boolean' + }, { + key: 'mail.smtp.starttls.required', + type: 'boolean' + }, { + key: 'mail.smtp.ssl.enable', + type: 'boolean' + }, { + key: 'mail.smtp.ssl.trust', + type: 'string' + }, { + key: 'mail.smtp.ssl.protocols', + type: 'string' + }, { + key: 'mail.smtp.from', + type: 'string' + }, { + key: 'mail.smtp.auth', + type: 'boolean' + }, { + key: 'mail.smtp.username', + type: 'string' + }, { + key: 'mail.smtp.password', + type: 'string' + }, { + key: 'web.liveRouteLength', + type: 'number' + }] +}); diff --git a/web/app/view/dialog/Attribute.js b/web/app/view/dialog/Attribute.js index 993c2b1..7f0de78 100644 --- a/web/app/view/dialog/Attribute.js +++ b/web/app/view/dialog/Attribute.js @@ -27,19 +27,27 @@ Ext.define('Traccar.view.dialog.Attribute', { items: { xtype: 'form', + listeners: { + validitychange: 'onValidityChange' + }, items: [{ xtype: 'textfield', + reference: 'nameTextField', name: 'name', + allowBlank: false, fieldLabel: Strings.sharedName }, { xtype: 'textfield', name: 'value', + reference: 'valueField', + allowBlank: false, fieldLabel: Strings.stateValue }] }, buttons: [{ glyph: 'xf00c@FontAwesome', + reference: 'saveButton', tooltip: Strings.sharedSave, tooltipType: 'title', minWidth: 0, diff --git a/web/app/view/dialog/AttributeController.js b/web/app/view/dialog/AttributeController.js index 365a0df..daa33be 100644 --- a/web/app/view/dialog/AttributeController.js +++ b/web/app/view/dialog/AttributeController.js @@ -39,5 +39,57 @@ Ext.define('Traccar.view.dialog.AttributeController', { record.save(); } button.up('window').close(); + }, + + onValidityChange: function (form, valid) { + this.lookupReference('saveButton').setDisabled(!valid); + }, + + defaultFieldConfig: { + name: 'value', + reference: 'valueField', + allowBlank: false, + fieldLabel: Strings.stateValue + }, + + onNameChange: function (combobox, newValue) { + var type, config, valueField = this.lookupReference('valueField'), + attribute = combobox.getStore().getById(newValue); + if (attribute) { + type = attribute.get('type'); + config = Ext.clone(this.defaultFieldConfig); + if (type === 'number') { + config.xtype = 'numberfield'; + config.allowDecimals = false; + if (attribute.get('maxValue')) { + config.maxValue = attribute.get('maxValue'); + } + if (attribute.get('minValue')) { + config.minValue = attribute.get('minValue'); + } + } else if (type === 'boolean') { + config.xtype = 'checkboxfield'; + config.inputValue = true; + config.uncheckedValue = false; + } else if (type === 'color') { + config.xtype = 'colorfield'; + config.format = '#hex6'; + config.beforeBodyEl = [ + '<div class="' + Ext.baseCSSPrefix + 'colorpicker-field-swatch custom-color-picker-swatch">' + + '<div id="{id}-swatchEl" data-ref="swatchEl" class="' + Ext.baseCSSPrefix + + 'colorpicker-field-swatch-inner"></div>' + + '</div>' + ]; + } else { + config.xtype = 'textfield'; + } + if (valueField.getXType() !== config.xtype) { + this.getView().down('form').insert(this.getView().down('form').items.indexOf(valueField), config); + this.getView().down('form').remove(valueField); + } else if (config.xtype === 'numberfield') { + valueField.setMinValue(config.minValue); + valueField.setMaxValue(config.maxValue); + } + } } }); diff --git a/web/app/view/edit/AttributesController.js b/web/app/view/edit/AttributesController.js index 1ae32c7..cf4f64c 100644 --- a/web/app/view/edit/AttributesController.js +++ b/web/app/view/edit/AttributesController.js @@ -25,8 +25,6 @@ Ext.define('Traccar.view.edit.AttributesController', { 'Traccar.model.Attribute' ], - objectModel: 'Traccar.model.Attribute', - objectDialog: 'Traccar.view.dialog.Attribute', removeTitle: Strings.stateName, init: function () { @@ -42,18 +40,18 @@ Ext.define('Traccar.view.edit.AttributesController', { store.add(Ext.create('Traccar.model.Attribute', { priority: i++, name: propertyName, - value: this.getView().record.get('attributes')[propertyName] + value: attributes[propertyName] })); } } - store.addListener('add', function (store, records, index, eOpts) { + store.addListener('add', function (store, records) { var i; for (i = 0; i < records.length; i++) { this.getView().record.get('attributes')[records[i].get('name')] = records[i].get('value'); } this.getView().record.dirty = true; }, this); - store.addListener('update', function (store, record, operation, modifiedFieldNames, details, eOpts) { + store.addListener('update', function (store, record, operation) { if (operation === Ext.data.Model.EDIT) { if (record.modified.name !== record.get('name')) { delete this.getView().record.get('attributes')[record.modified.name]; @@ -62,7 +60,7 @@ Ext.define('Traccar.view.edit.AttributesController', { this.getView().record.dirty = true; } }, this); - store.addListener('remove', function (store, records, index, isMove, eOpts) { + store.addListener('remove', function (store, records) { var i; for (i = 0; i < records.length; i++) { delete this.getView().record.get('attributes')[records[i].get('name')]; @@ -71,5 +69,55 @@ Ext.define('Traccar.view.edit.AttributesController', { }, this); this.getView().setStore(store); + }, + + comboConfig: { + xtype: 'combobox', + reference: 'nameComboField', + name: 'name', + fieldLabel: Strings.sharedName, + displayField: 'key', + allowBlank: false, + listeners: { + change: 'onNameChange' + } + }, + + replaceNameField: function (dialog, config) { + var nameTextField = dialog.lookupReference('nameTextField'); + dialog.down('form').insert(0, config); + dialog.down('form').remove(nameTextField); + }, + + initDialog: function (record) { + var dialog = Ext.create('Traccar.view.dialog.Attribute'); + if (this.getView().record instanceof Traccar.model.Device) { + this.comboConfig.store = 'DeviceAttributes'; + this.replaceNameField(dialog, this.comboConfig); + } else if (this.getView().record instanceof Traccar.model.Geofence) { + this.comboConfig.store = 'GeofenceAttributes'; + this.replaceNameField(dialog, this.comboConfig); + } else if (this.getView().record instanceof Traccar.model.Group) { + this.comboConfig.store = 'GroupAttributes'; + this.replaceNameField(dialog, this.comboConfig); + } else if (this.getView().record instanceof Traccar.model.Server) { + this.comboConfig.store = 'ServerAttributes'; + this.replaceNameField(dialog, this.comboConfig); + } else if (this.getView().record instanceof Traccar.model.User) { + this.comboConfig.store = 'UserAttributes'; + this.replaceNameField(dialog, this.comboConfig); + } + dialog.down('form').loadRecord(record); + dialog.show(); + }, + + onAddClick: function () { + var objectInstance = Ext.create('Traccar.model.Attribute'); + objectInstance.store = this.getView().getStore(); + this.initDialog(objectInstance); + }, + + onEditClick: function () { + this.initDialog(this.getView().getSelectionModel().getSelection()[0]); } }); diff --git a/web/load.js b/web/load.js index fc676b7..b6cec03 100644 --- a/web/load.js +++ b/web/load.js @@ -124,9 +124,11 @@ if (debugMode) { addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/ext-all-debug.js'); addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/packages/charts/classic/charts-debug.js'); + addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/packages/ux/classic/ux-debug.js'); } else { addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/ext-all.js'); addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/packages/charts/classic/charts.js'); + addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/packages/ux/classic/ux.js'); } addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/classic/locale/locale-' + locale.languages[locale.language].code + '.js'); @@ -134,6 +136,7 @@ addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/classic/theme-triton/theme-triton.js'); addStyleFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/packages/charts/classic/triton/resources/charts-all.css'); + addStyleFile('//cdnjs.cloudflare.com/ajax/libs/extjs/' + extjsVersion + '/packages/ux/classic/triton/resources/ux-all.css'); addStyleFile('//cdnjs.cloudflare.com/ajax/libs/font-awesome/' + fontAwesomeVersion + '/css/font-awesome.min.css'); |