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/dialog/AttributeController.js | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'web/app/view/dialog/AttributeController.js') diff --git a/web/app/view/dialog/AttributeController.js b/web/app/view/dialog/AttributeController.js index 365a0df5..daa33be2 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 = [ + '
' + + '
' + + '
' + ]; + } 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); + } + } } }); -- cgit v1.2.3