diff options
author | Abyss777 <abyss@fox5.ru> | 2016-09-27 15:27:09 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-09-27 15:27:09 +0500 |
commit | b1715a760cde09ec69a6756d7067a8c077d0fe2b (patch) | |
tree | 0439d7cfc6e00a7e219cffa02182e0e1a97bf397 /web/app/view/StateController.js | |
parent | ac4f0adf3b196b1a9af40be64b3e4e0fac91c1d6 (diff) | |
download | trackermap-web-b1715a760cde09ec69a6756d7067a8c077d0fe2b.tar.gz trackermap-web-b1715a760cde09ec69a6756d7067a8c077d0fe2b.tar.bz2 trackermap-web-b1715a760cde09ec69a6756d7067a8c077d0fe2b.zip |
-Remove plural of attribute
-Use ChainedStore in right way
-Use findBy instead of filter in StateController
Diffstat (limited to 'web/app/view/StateController.js')
-rw-r--r-- | web/app/view/StateController.js | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index c0f5b9a1..8a194940 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -44,7 +44,7 @@ Ext.define('Traccar.view.StateController', { '#Positions': { clear: 'clearReport' }, - '#AllAttributeAliases': { + '#AttributeAliases': { add: 'updateAliases', update: 'updateAliases' } @@ -52,6 +52,10 @@ Ext.define('Traccar.view.StateController', { } }, + init: function () { + this.aliasesStore = Ext.getStore('AttributeAliases'); + }, + keys: (function () { var i, list, result; result = {}; @@ -88,8 +92,12 @@ Ext.define('Traccar.view.StateController', { } }, + findAttribute: function (record) { + return record.get('deviceId') === this.position.get('deviceId') && record.get('attribute') === this.lookupAttribute; + }, + updatePosition: function () { - var attributes, store, key, aliasesStore, attributeAlias, name; + var attributes, store, key, aliasIndex, name; store = Ext.getStore('Attributes'); store.removeAll(); @@ -103,16 +111,14 @@ Ext.define('Traccar.view.StateController', { } } - aliasesStore = Ext.getStore('AllAttributeAliases'); - 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) { - name = attributeAlias.get('alias'); + this.lookupAttribute = key; + aliasIndex = this.aliasesStore.findBy(this.findAttribute, this); + if (aliasIndex !== -1) { + name = this.aliasesStore.getAt(aliasIndex).get('alias'); } else { name = key.replace(/^./, function (match) { return match.toUpperCase(); @@ -159,16 +165,18 @@ Ext.define('Traccar.view.StateController', { }, onAliasEditClick: function () { - var attribute, aliasesStore, attributeAlias, dialog; + var attribute, aliasIndex, attributeAlias, dialog; attribute = this.getView().getSelectionModel().getSelection()[0]; - aliasesStore = Ext.getStore('AllAttributeAliases'); - attributeAlias = aliasesStore.findRecord('attribute', attribute.get('attribute'), 0, false, true, true); - if (attributeAlias === null) { + this.lookupAttribute = attribute.get('attribute'); + aliasIndex = this.aliasesStore.findBy(this.findAttribute, this); + if (aliasIndex !== -1) { + attributeAlias = this.aliasesStore.getAt(aliasIndex); + } else { attributeAlias = Ext.create('Traccar.model.AttributeAlias', { deviceId: this.position.get('deviceId'), attribute: attribute.get('attribute') }); - attributeAlias.store = aliasesStore; + attributeAlias.store = this.aliasesStore; } dialog = Ext.create('Traccar.view.AttributeAliasDialog'); dialog.down('form').loadRecord(attributeAlias); |