aboutsummaryrefslogtreecommitdiff
path: root/web/app/view
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-09-04 09:44:54 +0500
committerAbyss777 <abyss@fox5.ru>2017-09-04 09:44:54 +0500
commit44806acd0e4fa1618e66ac61f2cc6e0505dc9c92 (patch)
tree65d0be5bc4746457727b18c8c9490d018b814483 /web/app/view
parent6a9bbe6624bf65fafe11378caf485ba5612f407c (diff)
downloadetbsa-traccar-web-44806acd0e4fa1618e66ac61f2cc6e0505dc9c92.tar.gz
etbsa-traccar-web-44806acd0e4fa1618e66ac61f2cc6e0505dc9c92.tar.bz2
etbsa-traccar-web-44806acd0e4fa1618e66ac61f2cc6e0505dc9c92.zip
Improve commands
Diffstat (limited to 'web/app/view')
-rw-r--r--web/app/view/CustomNumberField.js34
-rw-r--r--web/app/view/dialog/Command.js88
-rw-r--r--web/app/view/dialog/CommandController.js127
3 files changed, 94 insertions, 155 deletions
diff --git a/web/app/view/CustomNumberField.js b/web/app/view/CustomNumberField.js
index 887e5c9..9144b52 100644
--- a/web/app/view/CustomNumberField.js
+++ b/web/app/view/CustomNumberField.js
@@ -20,7 +20,7 @@ Ext.define('Traccar.view.CustomNumberField', {
xtype: 'customNumberField',
beforeEl: '<div style="width:100%;display:inline-table;">',
- unitEl: '<div style="display:table-cell;padding-left:10px;vertical-align:middle;">',
+ unitEl: '<div id="unitEl" style="display:table-cell;padding-left:10px;vertical-align:middle;width:30%">',
constructor: function (config) {
var unit;
@@ -44,6 +44,38 @@ Ext.define('Traccar.view.CustomNumberField', {
config.valueToRaw = function (value) {
return Ext.getStore('DistanceUnits').convertValue(value, Traccar.app.getPreference('distanceUnit', 'km'));
};
+ } else if (config.dataType === 'frequency') {
+ config.beforeSubTpl = this.beforeEl;
+ config.afterSubTpl = this.unitEl + '</div></div>';
+ config.listeners = {
+ afterrender: function (numberField) {
+ if (!numberField.timeUnits) {
+ numberField.timeUnits = Ext.create({
+ xtype: 'combobox',
+ renderTo: 'unitEl',
+ store: 'TimeUnits',
+ displayField: 'name',
+ valueField: 'factor',
+ value: 1,
+ width: 70
+ });
+ }
+ }
+ };
+ config.rawToValue = function (rawValue) {
+ if (this.timeUnits) {
+ return rawValue * this.timeUnits.getValue();
+ } else {
+ return rawValue;
+ }
+ };
+ config.valueToRaw = function (value) {
+ if (this.timeUnits) {
+ return value / this.timeUnits.getValue();
+ } else {
+ return value;
+ }
+ };
}
this.callParent(arguments);
}
diff --git a/web/app/view/dialog/Command.js b/web/app/view/dialog/Command.js
index ec98b29..ce5b75b 100644
--- a/web/app/view/dialog/Command.js
+++ b/web/app/view/dialog/Command.js
@@ -27,6 +27,9 @@ Ext.define('Traccar.view.dialog.Command', {
items: {
xtype: 'form',
+ listeners: {
+ validitychange: 'onValidityChange'
+ },
items: [{
xtype: 'checkboxfield',
name: 'textChannel',
@@ -51,94 +54,13 @@ Ext.define('Traccar.view.dialog.Command', {
}
}, {
xtype: 'fieldcontainer',
- reference: 'paramPositionPeriodic',
- name: 'attributes',
- hidden: true,
-
- items: [{
- xtype: 'numberfield',
- fieldLabel: Strings.commandFrequency,
- name: 'frequency'
- }, {
- xtype: 'combobox',
- fieldLabel: Strings.commandUnit,
- name: 'unit',
- store: 'TimeUnits',
- displayField: 'name',
- valueField: 'factor'
- }]
- }, {
- xtype: 'fieldcontainer',
- reference: 'paramOutputControl',
- name: 'attributes',
- hidden: true,
-
- items: [{
- xtype: 'numberfield',
- fieldLabel: Strings.commandIndex,
- name: 'index',
- allowBlank: false
- }, {
- xtype: 'textfield',
- fieldLabel: Strings.commandData,
- name: 'data'
- }]
- }, {
- xtype: 'fieldcontainer',
- reference: 'paramSendSmsUssd',
- name: 'attributes',
- hidden: true,
-
- items: [{
- xtype: 'textfield',
- fieldLabel: Strings.commandPhone,
- name: 'phone'
- }, {
- xtype: 'textfield',
- reference: 'paramSmsMessage',
- fieldLabel: Strings.commandMessage,
- name: 'message',
- hidden: true
- }]
- }, {
- xtype: 'fieldcontainer',
- reference: 'paramSetTimezone',
- name: 'attributes',
- hidden: true,
-
- items: [{
- xtype: 'numberfield',
- fieldLabel: Strings.commandTimezone,
- name: 'timezone',
- minValue: -12,
- step: 0.5,
- maxValue: +14
- }]
- }, {
- xtype: 'fieldcontainer',
- reference: 'paramSetIndicator',
- name: 'attributes',
- hidden: true,
-
- items: [{
- xtype: 'numberfield',
- fieldLabel: Strings.commandData,
- name: 'data',
- minValue: 0,
- maxValue: 99
- }]
- }, {
- xtype: 'textfield',
- reference: 'paramCustom',
- fieldLabel: Strings.commandCustom,
- name: 'customCommand',
- hidden: true,
- allowBlank: false
+ reference: 'parameters'
}]
},
buttons: [{
text: Strings.commandSend,
+ reference: 'sendButton',
handler: 'onSendClick'
}, {
text: Strings.sharedCancel,
diff --git a/web/app/view/dialog/CommandController.js b/web/app/view/dialog/CommandController.js
index 3fdc7b0..4ab5184 100644
--- a/web/app/view/dialog/CommandController.js
+++ b/web/app/view/dialog/CommandController.js
@@ -19,87 +19,68 @@ Ext.define('Traccar.view.dialog.CommandController', {
extend: 'Ext.app.ViewController',
alias: 'controller.command',
+ defaultFieldConfig: {
+ allowBlank: false
+ },
+
onSelect: function (selected) {
- this.lookupReference('paramPositionPeriodic').setHidden(
- selected.getValue() !== 'positionPeriodic');
- this.lookupReference('paramOutputControl').setHidden(
- selected.getValue() !== 'outputControl');
- this.lookupReference('paramSendSmsUssd').setHidden(
- selected.getValue() !== 'sendSms' && selected.getValue() !== 'sendUssd');
- this.lookupReference('paramSmsMessage').setHidden(
- selected.getValue() !== 'sendSms');
- this.lookupReference('paramSetTimezone').setHidden(
- selected.getValue() !== 'setTimezone');
- this.lookupReference('paramSetIndicator').setHidden(
- selected.getValue() !== 'setIndicator');
- this.lookupReference('paramCustom').setHidden(
- selected.getValue() !== 'custom');
+ var i, config, command, parameters, parameter;
+ this.lookupReference('parameters').removeAll();
+ command = Ext.getStore('KnownCommands').getById(selected.getValue());
+ if (command && command.get('parameters')) {
+ parameters = command.get('parameters');
+ for (i = 0; i < parameters.length; i++) {
+ parameter = new Traccar.model.KnownAttribute(parameters[i]);
+ config = Ext.clone(this.defaultFieldConfig);
+ config.key = parameter.get('key');
+ config.fieldLabel = parameter.get('name');
+ switch (parameter.get('valueType')) {
+ case 'number':
+ config.xtype = 'customNumberField';
+ if (parameter.get('allowDecimals') !== undefined) {
+ config.allowDecimals = parameter.get('allowDecimals');
+ } else {
+ config.allowDecimals = true;
+ }
+ config.dataType = parameter.get('dataType');
+ config.maxValue = parameter.get('maxValue');
+ config.minValue = parameter.get('minValue');
+ break;
+ case 'boolean':
+ config.xtype = 'checkboxfield';
+ config.inputValue = true;
+ config.uncheckedValue = false;
+ break;
+ default:
+ if (parameter.get('dataType') && parameter.get('dataType') === 'timezone') {
+ config.xtype = 'combobox';
+ config.queryMode = 'local';
+ config.displayField = 'key';
+ config.editable = false;
+ config.store = 'AllTimezones';
+ } else {
+ config.xtype = 'textfield';
+ }
+ }
+ this.lookupReference('parameters').add(config);
+ }
+ }
},
onSendClick: function (button) {
- var attributes, value, record, form, index, phone;
+ var i, record, form, parameters, attributes = {};
form = button.up('window').down('form');
form.updateRecord();
record = form.getRecord();
+ parameters = this.lookupReference('parameters').items.items;
- switch (record.get('type')) {
- case 'positionPeriodic':
- attributes = this.lookupReference('paramPositionPeriodic');
- value = attributes.down('numberfield[name="frequency"]').getValue();
- value *= attributes.down('combobox[name="unit"]').getValue();
- record.set('attributes', {
- frequency: value
- });
- break;
- case 'outputControl':
- attributes = this.lookupReference('paramOutputControl');
- index = attributes.down('numberfield[name="index"]').getValue();
- value = attributes.down('textfield[name="data"]').getValue();
- record.set('attributes', {
- index: index,
- data: value
- });
- break;
- case 'sendUssd':
- attributes = this.lookupReference('paramSendSmsUssd');
- phone = attributes.down('textfield[name="phone"]').getValue();
- record.set('attributes', {
- phone: phone
- });
- break;
- case 'sendSms':
- attributes = this.lookupReference('paramSendSmsUssd');
- phone = attributes.down('textfield[name="phone"]').getValue();
- value = attributes.down('textfield[name="message"]').getValue();
- record.set('attributes', {
- phone: phone,
- message: value
- });
- break;
- case 'setTimezone':
- attributes = this.lookupReference('paramSetTimezone');
- value = attributes.down('numberfield[name="timezone"]').getValue();
- record.set('attributes', {
- timezone: value * 3600
- });
- break;
- case 'setIndicator':
- attributes = this.lookupReference('paramSetIndicator');
- value = attributes.down('numberfield[name="data"]').getValue();
- record.set('attributes', {
- data: value
- });
- break;
- case 'custom':
- value = this.lookupReference('paramCustom').getValue();
- record.set('attributes', {
- data: value
- });
- break;
- default:
- break;
+ if (parameters.length > 0) {
+ for (i = 0; i < parameters.length; i++) {
+ attributes[parameters[i].key] = parameters[i].getValue();
+ }
}
+ record.set('attributes', attributes);
Ext.Ajax.request({
scope: this,
@@ -109,6 +90,10 @@ Ext.define('Traccar.view.dialog.CommandController', {
});
},
+ onValidityChange: function (form, valid) {
+ this.lookupReference('sendButton').setDisabled(!valid);
+ },
+
onTextChannelChange: function (checkbox, newValue) {
var typesStore = this.lookupReference('commandType').getStore();
typesStore.getProxy().setExtraParam('textChannel', newValue);