diff options
Diffstat (limited to 'web/app/view/StateController.js')
-rw-r--r-- | web/app/view/StateController.js | 71 |
1 files changed, 60 insertions, 11 deletions
diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index d92201b9..4bd43de6 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -28,8 +28,9 @@ Ext.define('Traccar.view.StateController', { listen: { controller: { '*': { - selectDevice: 'selectDevice', - selectReport: 'selectReport' + selectdevice: 'selectDevice', + selectreport: 'selectReport', + updatealiases: 'updateAliases' } }, store: { @@ -39,6 +40,10 @@ Ext.define('Traccar.view.StateController', { }, '#Positions': { clear: 'clearReport' + }, + '#AllAttributesAliases': { + add: 'updateAliases', + update: 'updateAliases' } } } @@ -66,7 +71,8 @@ Ext.define('Traccar.view.StateController', { } for (i = 0; i < data.length; i++) { if (this.deviceId === data[i].get('deviceId')) { - this.updatePosition(data[i]); + this.position = data[i]; + this.updatePosition(); } } }, @@ -79,30 +85,41 @@ Ext.define('Traccar.view.StateController', { } }, - updatePosition: function (position) { - var attributes, store, key; + updatePosition: function () { + var attributes, store, key, aliasesStore, attributeAlias, alias; store = Ext.getStore('Attributes'); store.removeAll(); - for (key in position.data) { - if (position.data.hasOwnProperty(key) && this.keys[key] !== undefined) { + for (key in this.position.data) { + if (this.position.data.hasOwnProperty(key) && this.keys[key] !== undefined) { store.add(Ext.create('Traccar.model.Attribute', { priority: this.keys[key].priority, name: this.keys[key].name, - value: Traccar.AttributeFormatter.getFormatter(key)(position.get(key)) + value: Traccar.AttributeFormatter.getFormatter(key)(this.position.get(key)) })); } } - attributes = position.get('attributes'); + aliasesStore = Ext.getStore('AllAttributesAliases'); + aliasesStore.filter('deviceId', this.position.get('deviceId')); + + attributes = this.position.get('attributes'); if (attributes instanceof Object) { for (key in attributes) { if (attributes.hasOwnProperty(key)) { + attributeAlias = aliasesStore.findRecord('attribute', key, 0, false, true, true); + if (attributeAlias !== null) { + alias = attributeAlias.get('alias'); + } else { + alias = ''; + } store.add(Ext.create('Traccar.model.Attribute', { priority: 1024, name: key.replace(/^./, function (match) { return match.toUpperCase(); }), + attribute: key, + alias: alias, value: Traccar.AttributeFormatter.getFormatter(key)(attributes[key]) })); } @@ -115,18 +132,50 @@ Ext.define('Traccar.view.StateController', { this.deviceId = device.get('id'); position = Ext.getStore('LatestPositions').findRecord('deviceId', this.deviceId, 0, false, false, true); if (position) { - this.updatePosition(position); + this.position = position; + this.updatePosition(); } else { + this.position = null; Ext.getStore('Attributes').removeAll(); } }, selectReport: function (position) { this.deviceId = null; - this.updatePosition(position); + this.position = position; + this.updatePosition(); }, clearReport: function (store) { + this.position = null; Ext.getStore('Attributes').removeAll(); + }, + + onSelectionChange: function (selected, records) { + var enabled = selected.getCount() > 0 && records[0].get('attribute') !== ''; + this.lookupReference('aliasEditButton').setDisabled(!enabled); + }, + + onAliasEditClick: function () { + var attribute, aliasesStore, attributeAlias, dialog; + attribute = this.getView().getSelectionModel().getSelection()[0]; + aliasesStore = Ext.getStore('AllAttributesAliases'); + attributeAlias = aliasesStore.findRecord('attribute', attribute.get('attribute'), 0, false, true, true); + if (attributeAlias === null) { + attributeAlias = Ext.create('Traccar.model.AttributeAlias', { + deviceId: this.position.get('deviceId'), + attribute: attribute.get('attribute') + }); + attributeAlias.store = aliasesStore; + } + dialog = Ext.create('Traccar.view.AttributeAliasDialog'); + dialog.down('form').loadRecord(attributeAlias); + dialog.show(); + }, + + updateAliases: function () { + if (this.position !== null) { + this.updatePosition(); + } } }); |