From 7db1c1cdcf617e146e927c4aadde239959a9d3de Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 7 Mar 2017 15:32:22 +0500 Subject: Implement SMS commands --- web/app/model/Command.js | 5 ++++- web/app/store/CommandTypes.js | 16 +++++++--------- web/app/view/CommandDialog.js | 13 ++++++++++++- web/app/view/CommandDialogController.js | 13 +++++++++++-- web/app/view/DevicesController.js | 10 ++++++---- 5 files changed, 40 insertions(+), 17 deletions(-) (limited to 'web/app') diff --git a/web/app/model/Command.js b/web/app/model/Command.js index b298028f..789c3647 100644 --- a/web/app/model/Command.js +++ b/web/app/model/Command.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,9 @@ Ext.define('Traccar.model.Command', { }, { name: 'type', type: 'string' + }, { + name: 'textChannel', + type: 'boolean' }, { name: 'attributes' }] diff --git a/web/app/store/CommandTypes.js b/web/app/store/CommandTypes.js index ad5faba2..445f937d 100644 --- a/web/app/store/CommandTypes.js +++ b/web/app/store/CommandTypes.js @@ -1,5 +1,6 @@ /* * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com) + * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,17 +20,9 @@ Ext.define('Traccar.store.CommandTypes', { extend: 'Ext.data.Store', fields: ['type', 'name'], - listeners: { - 'beforeload' : function (store) { - var proxy; - proxy = store.getProxy(); - proxy.setUrl('api/commandtypes?deviceId' + proxy.extraParams.deviceId); - } - }, - proxy: { type: 'rest', - url: '', + url: 'api/commandtypes', reader: { type: 'json', getData: function (data) { @@ -46,6 +39,11 @@ Ext.define('Traccar.store.CommandTypes', { }); return data; } + }, + listeners: { + 'exception' : function (proxy, response) { + Traccar.app.showError(response); + } } } }); diff --git a/web/app/view/CommandDialog.js b/web/app/view/CommandDialog.js index 24e0e191..ef486c41 100644 --- a/web/app/view/CommandDialog.js +++ b/web/app/view/CommandDialog.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,8 +28,19 @@ Ext.define('Traccar.view.CommandDialog', { items: { xtype: 'form', items: [{ + xtype: 'checkboxfield', + name: 'textChannel', + reference: 'textChannelCheckBox', + inputValue: true, + uncheckedValue: false, + fieldLabel: Strings.notificationSms, + listeners: { + change: 'onTextChannelChange' + } + }, { xtype: 'combobox', name: 'type', + reference: 'commandType', fieldLabel: Strings.sharedType, store: 'CommandTypes', displayField: 'name', diff --git a/web/app/view/CommandDialogController.js b/web/app/view/CommandDialogController.js index 6e809fa1..c2859d0a 100644 --- a/web/app/view/CommandDialogController.js +++ b/web/app/view/CommandDialogController.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -113,9 +113,18 @@ Ext.define('Traccar.view.CommandDialogController', { }); }, + onTextChannelChange: function (checkbox, newValue) { + var typesStore = this.lookupReference('commandType').getStore(); + typesStore.getProxy().setExtraParam('textChannel', newValue); + typesStore.reload(); + }, + onSendResult: function (options, success, response) { if (success) { - Ext.toast(Strings.commandSent); + Ext.toast({ + html: Strings.commandSent, + align: 'br' + }); this.closeView(); } else { Traccar.app.showError(response); diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js index ad0dd363..d65055e7 100644 --- a/web/app/view/DevicesController.js +++ b/web/app/view/DevicesController.js @@ -74,28 +74,30 @@ Ext.define('Traccar.view.DevicesController', { }, onCommandClick: function () { - var device, deviceId, command, dialog, comboStore; + var device, deviceId, command, dialog, comboStore, online; device = this.getView().getSelectionModel().getSelection()[0]; + online = device.get('status') === 'online'; deviceId = device.get('id'); command = Ext.create('Traccar.model.Command'); command.set('deviceId', deviceId); + command.set('textChannel', !online); dialog = Ext.create('Traccar.view.CommandDialog'); comboStore = dialog.down('form').down('combobox').getStore(); comboStore.getProxy().setExtraParam('deviceId', deviceId); dialog.down('form').loadRecord(command); + dialog.lookupReference('textChannelCheckBox').setDisabled(!online); dialog.show(); }, updateButtons: function (selected) { - var readonly, deviceReadonly, empty, online; + var readonly, deviceReadonly, empty; deviceReadonly = Traccar.app.getPreference('deviceReadonly', false) && !Traccar.app.getUser().get('admin'); readonly = Traccar.app.getPreference('readonly', false) && !Traccar.app.getUser().get('admin'); empty = selected.getCount() === 0; - online = selected.getLastSelected().get('status') === 'online'; this.lookupReference('toolbarEditButton').setDisabled(empty || readonly || deviceReadonly); this.lookupReference('toolbarRemoveButton').setDisabled(empty || readonly || deviceReadonly); this.lookupReference('toolbarGeofencesButton').setDisabled(empty || readonly); - this.lookupReference('deviceCommandButton').setDisabled(empty || readonly || !online); + this.lookupReference('deviceCommandButton').setDisabled(empty || readonly); }, onSelectionChange: function (selected) { -- cgit v1.2.3 From f30f6961890371e026cd548874a31292e2de3c21 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 8 Mar 2017 09:06:46 +0500 Subject: Organize onCommandClick function --- web/app/view/DevicesController.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'web/app') diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js index d65055e7..742077b2 100644 --- a/web/app/view/DevicesController.js +++ b/web/app/view/DevicesController.js @@ -74,16 +74,20 @@ Ext.define('Traccar.view.DevicesController', { }, onCommandClick: function () { - var device, deviceId, command, dialog, comboStore, online; + var device, deviceId, command, dialog, typesStore, online; device = this.getView().getSelectionModel().getSelection()[0]; online = device.get('status') === 'online'; deviceId = device.get('id'); + command = Ext.create('Traccar.model.Command'); command.set('deviceId', deviceId); command.set('textChannel', !online); + dialog = Ext.create('Traccar.view.CommandDialog'); - comboStore = dialog.down('form').down('combobox').getStore(); - comboStore.getProxy().setExtraParam('deviceId', deviceId); + + typesStore = dialog.lookupReference('commandType').getStore(); + typesStore.getProxy().setExtraParam('deviceId', deviceId); + dialog.down('form').loadRecord(command); dialog.lookupReference('textChannelCheckBox').setDisabled(!online); dialog.show(); -- cgit v1.2.3