aboutsummaryrefslogtreecommitdiff
path: root/web/app/view
diff options
context:
space:
mode:
Diffstat (limited to 'web/app/view')
-rw-r--r--web/app/view/dialog/Attribute.js8
-rw-r--r--web/app/view/dialog/AttributeController.js52
-rw-r--r--web/app/view/edit/AttributesController.js60
3 files changed, 114 insertions, 6 deletions
diff --git a/web/app/view/dialog/Attribute.js b/web/app/view/dialog/Attribute.js
index 993c2b12..7f0de788 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 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 = [
+ '<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 1ae32c78..cf4f64c6 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]);
}
});