From 8c4337fb90487ce9986ab67fcb695a53e90f74d9 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 4 Apr 2017 17:16:05 +0500 Subject: Implement known attributes --- web/app/view/edit/AttributesController.js | 60 +++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 6 deletions(-) (limited to 'web/app/view/edit') 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]); } }); -- cgit v1.2.3 From 22b764a71a450e4f4e8ad1a0439cf708e6bcd952 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 17 Apr 2017 15:52:22 +0500 Subject: Translate known attributes --- web/app/model/KnownAttribute.js | 3 +++ web/app/store/DeviceAttributes.js | 7 ++++++ web/app/store/GeofenceAttributes.js | 1 + web/app/store/GroupAttributes.js | 5 ++++ web/app/store/ServerAttributes.js | 4 +++ web/app/store/UserAttributes.js | 12 +++++++++ web/app/view/edit/Attributes.js | 9 ++++++- web/app/view/edit/AttributesController.js | 42 ++++++++++++++----------------- web/l10n/en.json | 20 +++++++++++++++ 9 files changed, 79 insertions(+), 24 deletions(-) (limited to 'web/app/view/edit') diff --git a/web/app/model/KnownAttribute.js b/web/app/model/KnownAttribute.js index 8e578d9..9bb14db 100644 --- a/web/app/model/KnownAttribute.js +++ b/web/app/model/KnownAttribute.js @@ -22,6 +22,9 @@ Ext.define('Traccar.model.KnownAttribute', { fields: [{ name: 'key', type: 'string' + }, { + name: 'name', + type: 'string' }, { name: 'type', type: 'string' diff --git a/web/app/store/DeviceAttributes.js b/web/app/store/DeviceAttributes.js index 9f1ec50..341a769 100644 --- a/web/app/store/DeviceAttributes.js +++ b/web/app/store/DeviceAttributes.js @@ -22,24 +22,31 @@ Ext.define('Traccar.store.DeviceAttributes', { data: [{ key: 'speedLimit', + name: Strings.sharedAttributeSpeedLimit, type: 'number' }, { key: 'report.ignoreOdometer', + name: Strings.sharedAttributeReportIgnoreOdometer, type: 'boolean' }, { key: 'maintenance.start', + name: Strings.sharedAttributeMaintenanceStart, type: 'number' }, { key: 'maintenance.interval', + name: Strings.sharedAttributeMaintenanceInterval, type: 'number' }, { key: 'web.reportColor', + name: Strings.sharedAttributeWebReportColor, type: 'color' }, { key: 'devicePassword', + name: Strings.sharedAttributeDevicePassword, type: 'string' }, { key: 'processing.copyAttributes', + name: Strings.sharedAttributeProcessingCopyAttributes, type: 'string' }] }); diff --git a/web/app/store/GeofenceAttributes.js b/web/app/store/GeofenceAttributes.js index 79217f6..d8c8bb9 100644 --- a/web/app/store/GeofenceAttributes.js +++ b/web/app/store/GeofenceAttributes.js @@ -22,6 +22,7 @@ Ext.define('Traccar.store.GeofenceAttributes', { data: [{ key: 'color', + name: Strings.sharedAttributeColor, type: 'color' }] }); diff --git a/web/app/store/GroupAttributes.js b/web/app/store/GroupAttributes.js index baf2286..5ef2aa0 100644 --- a/web/app/store/GroupAttributes.js +++ b/web/app/store/GroupAttributes.js @@ -22,18 +22,23 @@ Ext.define('Traccar.store.GroupAttributes', { data: [{ key: 'speedLimit', + name: Strings.sharedAttributeSpeedLimit, type: 'number' }, { key: 'report.ignoreOdometer', + name: Strings.sharedAttributeReportIgnoreOdometer, type: 'boolean' }, { key: 'maintenance.start', + name: Strings.sharedAttributeMaintenanceStart, type: 'number' }, { key: 'maintenance.interval', + name: Strings.sharedAttributeMaintenanceInterval, type: 'number' }, { key: 'processing.copyAttributes', + name: Strings.sharedAttributeProcessingCopyAttributes, type: 'string' }] }); diff --git a/web/app/store/ServerAttributes.js b/web/app/store/ServerAttributes.js index aca81f2..3443142 100644 --- a/web/app/store/ServerAttributes.js +++ b/web/app/store/ServerAttributes.js @@ -22,15 +22,19 @@ Ext.define('Traccar.store.ServerAttributes', { data: [{ key: 'speedLimit', + name: Strings.sharedAttributeSpeedLimit, type: 'number' }, { key: 'maintenance.start', + name: Strings.sharedAttributeMaintenanceStart, type: 'number' }, { key: 'maintenance.interval', + name: Strings.sharedAttributeMaintenanceInterval, type: 'number' }, { key: 'web.liveRouteLength', + name: Strings.sharedAttributeWebLiveRouteLength, type: 'number', allowDecimals: false }] diff --git a/web/app/store/UserAttributes.js b/web/app/store/UserAttributes.js index 80ded0d..f286d1b 100644 --- a/web/app/store/UserAttributes.js +++ b/web/app/store/UserAttributes.js @@ -22,42 +22,54 @@ Ext.define('Traccar.store.UserAttributes', { data: [{ key: 'mail.smtp.host', + name: Strings.sharedAttributeMailSmtpHost, type: 'string' }, { key: 'mail.smtp.port', + name: Strings.sharedAttributeMailSmtpPort, type: 'number', allowDecimals: false, minValue: 1, maxValue: 65535 }, { key: 'mail.smtp.starttls.enable', + name: Strings.sharedAttributeMailSmtpStarttlsEnable, type: 'boolean' }, { key: 'mail.smtp.starttls.required', + name: Strings.sharedAttributeMailSmtpStarttlsRequired, type: 'boolean' }, { key: 'mail.smtp.ssl.enable', + name: Strings.sharedAttributeMailSmtpSslEnable, type: 'boolean' }, { key: 'mail.smtp.ssl.trust', + name: Strings.sharedAttributeMailSmtpSslTrust, type: 'string' }, { key: 'mail.smtp.ssl.protocols', + name: Strings.sharedAttributeMailSmtpSslProtocols, type: 'string' }, { key: 'mail.smtp.from', + name: Strings.sharedAttributeMailSmtpFrom, type: 'string' }, { key: 'mail.smtp.auth', + name: Strings.sharedAttributeMailSmtpAuth, type: 'boolean' }, { key: 'mail.smtp.username', + name: Strings.sharedAttributeMailSmtpUsername, type: 'string' }, { key: 'mail.smtp.password', + name: Strings.sharedAttributeMailSmtpPassword, type: 'string' }, { key: 'web.liveRouteLength', + name: Strings.sharedAttributeWebLiveRouteLength, type: 'number', allowDecimals: false }] diff --git a/web/app/view/edit/Attributes.js b/web/app/view/edit/Attributes.js index 93e5a3a..8008319 100644 --- a/web/app/view/edit/Attributes.js +++ b/web/app/view/edit/Attributes.js @@ -41,7 +41,14 @@ Ext.define('Traccar.view.edit.Attributes', { }, items: [{ text: Strings.sharedName, - dataIndex: 'name' + dataIndex: 'name', + renderer: function (value, metaData) { + var result; + if (this.attributesStore) { + result = Ext.getStore(this.attributesStore).getById(value); + } + return result && result.get('name') ? result.get('name') : value; + } }, { text: Strings.stateValue, dataIndex: 'value' diff --git a/web/app/view/edit/AttributesController.js b/web/app/view/edit/AttributesController.js index cf4f64c..235f2c5 100644 --- a/web/app/view/edit/AttributesController.js +++ b/web/app/view/edit/AttributesController.js @@ -69,6 +69,17 @@ Ext.define('Traccar.view.edit.AttributesController', { }, this); this.getView().setStore(store); + if (this.getView().record instanceof Traccar.model.Device) { + this.getView().attributesStore = 'DeviceAttributes'; + } else if (this.getView().record instanceof Traccar.model.Geofence) { + this.getView().attributesStore = 'GeofenceAttributes'; + } else if (this.getView().record instanceof Traccar.model.Group) { + this.getView().attributesStore = 'GroupAttributes'; + } else if (this.getView().record instanceof Traccar.model.Server) { + this.getView().attributesStore = 'ServerAttributes'; + } else if (this.getView().record instanceof Traccar.model.User) { + this.getView().attributesStore = 'UserAttributes'; + } }, comboConfig: { @@ -76,36 +87,21 @@ Ext.define('Traccar.view.edit.AttributesController', { reference: 'nameComboField', name: 'name', fieldLabel: Strings.sharedName, - displayField: 'key', + displayField: 'name', + valueField: '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); + var nameTextField, dialog = Ext.create('Traccar.view.dialog.Attribute'); + if (this.getView().attributesStore) { + this.comboConfig.store = this.getView().attributesStore; + nameTextField = dialog.lookupReference('nameTextField'); + dialog.down('form').insert(0, this.comboConfig); + dialog.down('form').remove(nameTextField); } dialog.down('form').loadRecord(record); dialog.show(); diff --git a/web/l10n/en.json b/web/l10n/en.json index f494978..68106e9 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -54,6 +54,26 @@ "sharedPermissions": "Permissions", "sharedExtra": "Extra", "sharedTimezone": "Timezone", + "sharedAttributeSpeedLimit": "Speed Limit", + "sharedAttributeReportIgnoreOdometer": "Report: Ignore Odometer", + "sharedAttributeMaintenanceStart": "Maintenance: Start", + "sharedAttributeMaintenanceInterval": "Maintenance: Interval", + "sharedAttributeWebReportColor": "Web: Report Color", + "sharedAttributeDevicePassword": "Device Password", + "sharedAttributeProcessingCopyAttributes": "Processing: Copy Attributes", + "sharedAttributeColor": "Color", + "sharedAttributeWebLiveRouteLength": "Web: Live Route Length", + "sharedAttributeMailSmtpHost": "Mail: SMTP Host", + "sharedAttributeMailSmtpPort": "Mail: SMTP Port", + "sharedAttributeMailSmtpStarttlsEnable": "Mail: SMTP STARTTLS Enable", + "sharedAttributeMailSmtpStarttlsRequired": "Mail: SMTP STARTTLS Required", + "sharedAttributeMailSmtpSslEnable": "Mail: SMTP SSL Enable", + "sharedAttributeMailSmtpSslTrust": "Mail: SMTP SSL Trust", + "sharedAttributeMailSmtpSslProtocols": "Mail: SMTP SSL Protocols", + "sharedAttributeMailSmtpFrom": "Mail: SMTP From", + "sharedAttributeMailSmtpAuth": "Mail: SMTP Auth Enable", + "sharedAttributeMailSmtpUsername": "Mail: SMTP Username", + "sharedAttributeMailSmtpPassword": "Mail: SMTP Password", "errorTitle": "Error", "errorUnknown": "Unknown error", "errorConnection": "Connection error", -- cgit v1.2.3