From bf68718e05f811ffeb2b4b57acab56dca3e7de56 Mon Sep 17 00:00:00 2001 From: Gábor Somogyi Date: Wed, 27 Apr 2016 22:22:08 +0200 Subject: Command framework ugly hack version --- web/app/Application.js | 5 +++-- web/app/model/SupportedCommand.js | 28 ++++++++++++++++++++++++++++ web/app/store/CommandTypes.js | 34 ---------------------------------- web/app/store/SupportedCommands.js | 33 +++++++++++++++++++++++++++++++++ web/app/view/CommandDialog.js | 2 +- web/app/view/DevicesController.js | 7 +++++-- 6 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 web/app/model/SupportedCommand.js delete mode 100644 web/app/store/CommandTypes.js create mode 100644 web/app/store/SupportedCommands.js (limited to 'web/app') diff --git a/web/app/Application.js b/web/app/Application.js index 69ce8f891..da3fdd505 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -30,7 +30,8 @@ Ext.define('Traccar.Application', { 'Device', 'Position', 'Attribute', - 'Command' + 'Command', + 'SupportedCommand' ], stores: [ @@ -45,7 +46,7 @@ Ext.define('Traccar.Application', { 'MapTypes', 'DistanceUnits', 'SpeedUnits', - 'CommandTypes', + 'SupportedCommands', 'TimeUnits', 'Languages' ], diff --git a/web/app/model/SupportedCommand.js b/web/app/model/SupportedCommand.js new file mode 100644 index 000000000..35c34c8cd --- /dev/null +++ b/web/app/model/SupportedCommand.js @@ -0,0 +1,28 @@ +/* + * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.model.SupportedCommand', { + extend: 'Ext.data.Model', + identifier: 'negative', + + fields: [{ + name: 'key', + type: 'string' + }, { + name: 'name', + type: 'string' + }] +}); diff --git a/web/app/store/CommandTypes.js b/web/app/store/CommandTypes.js deleted file mode 100644 index 3f5094266..000000000 --- a/web/app/store/CommandTypes.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -Ext.define('Traccar.store.CommandTypes', { - extend: 'Ext.data.Store', - fields: ['key', 'name'], - - data: [{ - key: 'positionPeriodic', - name: Strings.commandPositionPeriodic - }, { - key: 'positionStop', - name: Strings.commandPositionStop - }, { - key: 'engineStop', - name: Strings.commandEngineStop - }, { - key: 'engineResume', - name: Strings.commandEngineResume - }] -}); diff --git a/web/app/store/SupportedCommands.js b/web/app/store/SupportedCommands.js new file mode 100644 index 000000000..2b052b902 --- /dev/null +++ b/web/app/store/SupportedCommands.js @@ -0,0 +1,33 @@ +/* + * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.store.SupportedCommands', { + extend: 'Ext.data.Store', + model: 'Traccar.model.SupportedCommand', + + listeners: { + 'beforeload' : function(store, options) { + var proxy; + proxy = store.getProxy(); + proxy.setUrl('/api/devices/' + proxy.extraParams.deviceId + '/supportedcommands'); + } + }, + + proxy: { + type: 'rest', + url: '' + } +}); diff --git a/web/app/view/CommandDialog.js b/web/app/view/CommandDialog.js index 66cd190ea..e24105699 100644 --- a/web/app/view/CommandDialog.js +++ b/web/app/view/CommandDialog.js @@ -30,7 +30,7 @@ Ext.define('Traccar.view.CommandDialog', { xtype: 'combobox', name: 'type', fieldLabel: Strings.commandType, - store: 'CommandTypes', + store: 'SupportedCommands', displayField: 'name', valueField: 'key', listeners: { diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js index 10918c13a..9dee0ff7c 100644 --- a/web/app/view/DevicesController.js +++ b/web/app/view/DevicesController.js @@ -80,11 +80,14 @@ Ext.define('Traccar.view.DevicesController', { }, onCommandClick: function () { - var device, command, dialog; + var device, deviceId, command, dialog, comboStore; device = this.getView().getSelectionModel().getSelection()[0]; + deviceId = device.get('id'); command = Ext.create('Traccar.model.Command'); - command.set('deviceId', device.get('id')); + command.set('deviceId', deviceId); dialog = Ext.create('Traccar.view.CommandDialog'); + comboStore = dialog.down('form').down('combobox').getStore(); + comboStore.getProxy().setExtraParam('deviceId', deviceId); dialog.down('form').loadRecord(command); dialog.show(); }, -- cgit v1.2.3