diff options
Diffstat (limited to 'legacy/web/app/view/dialog')
37 files changed, 2898 insertions, 0 deletions
diff --git a/legacy/web/app/view/dialog/Attribute.js b/legacy/web/app/view/dialog/Attribute.js new file mode 100644 index 00000000..a85cad05 --- /dev/null +++ b/legacy/web/app/view/dialog/Attribute.js @@ -0,0 +1,65 @@ +/* + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Attribute', { + extend: 'Traccar.view.dialog.Base', + + requires: [ + 'Traccar.view.dialog.AttributeController', + 'Traccar.view.ColorPicker', + 'Traccar.view.CustomNumberField', + 'Traccar.view.UnescapedTextField' + ], + + controller: 'attribute', + title: Strings.sharedAttribute, + + items: { + xtype: 'form', + listeners: { + validitychange: 'onValidityChange' + }, + items: [{ + xtype: 'unescapedTextField', + reference: 'nameTextField', + name: 'name', + allowBlank: false, + fieldLabel: Strings.sharedName + }, { + xtype: 'textfield', + name: 'value', + reference: 'valueField', + allowBlank: false, + fieldLabel: Strings.stateValue + }] + }, + + buttons: [{ + glyph: 'xf00c@FontAwesome', + reference: 'saveButton', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/AttributeController.js b/legacy/web/app/view/dialog/AttributeController.js new file mode 100644 index 00000000..9fd452a4 --- /dev/null +++ b/legacy/web/app/view/dialog/AttributeController.js @@ -0,0 +1,126 @@ +/* + * Copyright 2016 - 2018 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.AttributeController', { + extend: 'Ext.app.ViewController', + alias: 'controller.attribute', + + onSaveClick: function (button) { + var dialog, store, record; + dialog = button.up('window').down('form'); + dialog.updateRecord(); + record = dialog.getRecord(); + store = record.store; + if (store) { + if (record.phantom) { + store.add(record); + } + store.sync({ + failure: function (batch) { + store.rejectChanges(); + Traccar.app.showError(batch.exceptions[0].getError().response); + } + }); + } else { + record.save(); + } + button.up('window').close(); + }, + + onValidityChange: function (form, valid) { + this.lookupReference('saveButton').setDisabled(!valid); + }, + + defaultFieldConfig: { + name: 'value', + reference: 'valueField', + allowBlank: false, + fieldLabel: Strings.stateValue + }, + + onNameChange: function (combobox, newValue) { + var config, attribute, valueField = this.lookupReference('valueField'); + attribute = combobox.getStore().getById(newValue); + if (attribute) { + config = Ext.clone(this.defaultFieldConfig); + switch (attribute.get('valueType')) { + case 'number': + config.xtype = 'customNumberField'; + if (attribute.get('allowDecimals') !== undefined) { + config.allowDecimals = attribute.get('allowDecimals'); + } else { + config.allowDecimals = true; + } + config.dataType = attribute.get('dataType'); + config.maxValue = attribute.get('maxValue'); + config.minValue = attribute.get('minValue'); + break; + case 'boolean': + config.xtype = 'checkboxfield'; + config.inputValue = true; + config.uncheckedValue = false; + break; + case 'color': + config.xtype = 'customcolorpicker'; + break; + default: + if (attribute.get('dataType')) { + config.xtype = 'combobox'; + config.queryMode = 'local'; + config.editable = false; + switch (attribute.get('dataType')) { + case 'distanceUnit': + config.store = 'DistanceUnits'; + config.displayField = 'name'; + config.valueField = 'key'; + break; + case 'speedUnit': + config.store = 'SpeedUnits'; + config.displayField = 'name'; + config.valueField = 'key'; + break; + case 'volumeUnit': + config.store = 'VolumeUnits'; + config.displayField = 'fullName'; + config.valueField = 'key'; + break; + case 'timezone': + config.store = 'AllTimezones'; + config.displayField = 'key'; + break; + default: + break; + } + } else { + config.xtype = 'textfield'; + } + break; + } + if (valueField.getXType() !== config.xtype || + config.xtype === 'customNumberField' && valueField.dataType !== config.dataType) { + this.getView().down('form').insert(this.getView().down('form').items.indexOf(valueField), config); + this.getView().down('form').remove(valueField); + } else if (config.xtype === 'customNumberField') { + valueField.setConfig(config); + valueField.validate(); + } else if (config.xtype === 'combobox') { + valueField.setConfig(config); + valueField.setValue(); + } + } + } +}); diff --git a/legacy/web/app/view/dialog/Base.js b/legacy/web/app/view/dialog/Base.js new file mode 100644 index 00000000..6affb370 --- /dev/null +++ b/legacy/web/app/view/dialog/Base.js @@ -0,0 +1,32 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Base', { + extend: 'Ext.window.Window', + + bodyPadding: Traccar.Style.normalPadding, + resizable: false, + scrollable: true, + constrain: true, + + initComponent: function () { + if (window.innerHeight) { + this.maxHeight = window.innerHeight - Traccar.Style.normalPadding * 2; + } + this.callParent(); + } +}); diff --git a/legacy/web/app/view/dialog/BaseEdit.js b/legacy/web/app/view/dialog/BaseEdit.js new file mode 100644 index 00000000..286afba5 --- /dev/null +++ b/legacy/web/app/view/dialog/BaseEdit.js @@ -0,0 +1,46 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.BaseEdit', { + extend: 'Traccar.view.dialog.Base', + + requires: [ + 'Traccar.view.dialog.BaseEditController' + ], + + controller: 'baseEdit', + + buttons: [{ + text: Strings.sharedAttributes, + handler: 'showAttributesView' + }, { + xtype: 'tbfill' + }, { + glyph: 'xf00c@FontAwesome', + reference: 'saveButton', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/BaseEditController.js b/legacy/web/app/view/dialog/BaseEditController.js new file mode 100644 index 00000000..91379e2d --- /dev/null +++ b/legacy/web/app/view/dialog/BaseEditController.js @@ -0,0 +1,61 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.BaseEditController', { + extend: 'Ext.app.ViewController', + alias: 'controller.baseEdit', + + requires: [ + 'Traccar.view.BaseWindow', + 'Traccar.view.edit.Attributes' + ], + + onSaveClick: function (button) { + var dialog, store, record; + dialog = button.up('window').down('form'); + dialog.updateRecord(); + record = dialog.getRecord(); + store = record.store; + if (store) { + if (record.phantom) { + store.add(record); + } + store.sync({ + failure: function (batch) { + store.rejectChanges(); + Traccar.app.showError(batch.exceptions[0].getError().response); + } + }); + } else { + record.save(); + } + this.closeView(); + }, + + showAttributesView: function (button) { + var dialog, record; + dialog = button.up('window').down('form'); + record = dialog.getRecord(); + Ext.create('Traccar.view.BaseWindow', { + title: Strings.sharedAttributes, + items: { + xtype: 'attributesView', + record: record + } + }).show(); + } +}); diff --git a/legacy/web/app/view/dialog/Calendar.js b/legacy/web/app/view/dialog/Calendar.js new file mode 100644 index 00000000..5f00a8be --- /dev/null +++ b/legacy/web/app/view/dialog/Calendar.js @@ -0,0 +1,63 @@ +/* + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Calendar', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.dialog.CalendarController', + 'Traccar.view.UnescapedTextField' + ], + + controller: 'calendar', + title: Strings.sharedCalendar, + + items: { + xtype: 'form', + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'unescapedTextField', + name: 'name', + fieldLabel: Strings.sharedName, + allowBlank: false + }, { + xtype: 'filefield', + name: 'file', + fieldLabel: Strings.sharedFile, + allowBlank: false, + buttonConfig: { + glyph: 'xf093@FontAwesome', + text: '', + tooltip: Strings.sharedSelectFile, + tooltipType: 'title', + minWidth: 0 + }, + listeners: { + change: 'onFileChange' + } + }] + }, { + xtype: 'hiddenfield', + name: 'data', + allowBlank: false, + reference: 'dataField' + }] + } +}); diff --git a/legacy/web/app/view/dialog/CalendarController.js b/legacy/web/app/view/dialog/CalendarController.js new file mode 100644 index 00000000..fb8cbff6 --- /dev/null +++ b/legacy/web/app/view/dialog/CalendarController.js @@ -0,0 +1,37 @@ +/* + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.CalendarController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.calendar', + + onFileChange: function (fileField) { + var reader; + if (fileField.fileInputEl.dom.files.length > 0) { + reader = new FileReader(); + reader.onload = function (event) { + fileField.up('window').lookupReference('dataField').setValue( + event.target.result.substr(event.target.result.indexOf(',') + 1)); + }; + reader.onerror = function (event) { + Traccar.app.showError(event.target.error); + }; + reader.readAsDataURL(fileField.fileInputEl.dom.files[0]); + } + } +}); diff --git a/legacy/web/app/view/dialog/ComputedAttribute.js b/legacy/web/app/view/dialog/ComputedAttribute.js new file mode 100644 index 00000000..adae7f7b --- /dev/null +++ b/legacy/web/app/view/dialog/ComputedAttribute.js @@ -0,0 +1,84 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.ComputedAttribute', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.dialog.ComputedAttributeController', + 'Traccar.view.UnescapedTextField', + 'Traccar.view.UnescapedTextAreaField' + ], + + controller: 'computedAttribute', + title: Strings.sharedComputedAttribute, + + items: { + xtype: 'form', + items: [{ + xtype: 'unescapedTextField', + name: 'description', + fieldLabel: Strings.sharedDescription + }, { + xtype: 'combobox', + name: 'attribute', + fieldLabel: Strings.sharedAttribute, + store: 'PositionAttributes', + displayField: 'name', + valueField: 'key', + listeners: { + change: 'onAttributeChange' + } + }, { + xtype: 'unescapedTextAreaField', + reference: 'expressionField', + name: 'expression', + fieldLabel: Strings.sharedExpression, + allowBlank: false + }, { + xtype: 'combobox', + name: 'type', + reference: 'typeComboField', + store: 'AttributeValueTypes', + fieldLabel: Strings.sharedType, + displayField: 'name', + valueField: 'id', + editable: false + }] + }, + + buttons: [{ + glyph: 'xf128@FontAwesome', + tooltip: Strings.sharedCheckComputedAttribute, + tooltipType: 'title', + minWidth: 0, + handler: 'onCheckClick' + }, { + glyph: 'xf00c@FontAwesome', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/ComputedAttributeController.js b/legacy/web/app/view/dialog/ComputedAttributeController.js new file mode 100644 index 00000000..f680b1b5 --- /dev/null +++ b/legacy/web/app/view/dialog/ComputedAttributeController.js @@ -0,0 +1,45 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.ComputedAttributeController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.computedAttribute', + + requires: [ + 'Traccar.view.dialog.SelectDevice' + ], + + onAttributeChange: function (combobox, newValue) { + var attribute = Ext.getStore('PositionAttributes').getById(newValue); + if (attribute) { + this.getView().lookupReference('typeComboField').setValue(attribute.get('valueType')); + this.getView().lookupReference('typeComboField').setReadOnly(true); + } else { + this.getView().lookupReference('typeComboField').setReadOnly(false); + } + }, + + onCheckClick: function (button) { + var dialog, form; + dialog = Ext.create('Traccar.view.dialog.SelectDevice'); + form = button.up('window').down('form'); + form.updateRecord(); + dialog.record = form.getRecord(); + dialog.show(); + } +}); diff --git a/legacy/web/app/view/dialog/Device.js b/legacy/web/app/view/dialog/Device.js new file mode 100644 index 00000000..60a8f716 --- /dev/null +++ b/legacy/web/app/view/dialog/Device.js @@ -0,0 +1,99 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Device', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.ClearableComboBox', + 'Traccar.view.dialog.DeviceController', + 'Traccar.view.UnescapedTextField' + ], + + controller: 'device', + title: Strings.sharedDevice, + + items: { + xtype: 'form', + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'unescapedTextField', + name: 'name', + fieldLabel: Strings.sharedName, + allowBlank: false + }, { + xtype: 'unescapedTextField', + name: 'uniqueId', + fieldLabel: Strings.deviceIdentifier, + allowBlank: false + }] + }, { + xtype: 'fieldset', + title: Strings.sharedExtra, + collapsible: true, + collapsed: true, + items: [{ + xtype: 'clearableComboBox', + name: 'groupId', + fieldLabel: Strings.groupParent, + store: 'Groups', + queryMode: 'local', + displayField: 'name', + valueField: 'id' + }, { + xtype: 'unescapedTextField', + name: 'phone', + fieldLabel: Strings.sharedPhone + }, { + xtype: 'unescapedTextField', + name: 'model', + fieldLabel: Strings.deviceModel + }, { + xtype: 'unescapedTextField', + name: 'contact', + fieldLabel: Strings.deviceContact + }, { + xtype: 'combobox', + name: 'category', + fieldLabel: Strings.deviceCategory, + store: 'DeviceImages', + queryMode: 'local', + displayField: 'name', + valueField: 'key', + editable: false, + listConfig: { + getInnerTpl: function () { + return '<table><tr valign="middle" ><td><div align="center" style="width:40px;height:40px;" >' + + '{[new XMLSerializer().serializeToString(Traccar.DeviceImages.getImageSvg(' + + 'Traccar.Style.mapColorOnline, false, 0, values.key))]}</div></td>' + + '<td>{name}</td></tr></table>'; + } + } + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'disabled', + fieldLabel: Strings.sharedDisabled, + hidden: true, + reference: 'disabledField' + }] + }] + } +}); diff --git a/legacy/web/app/view/dialog/DeviceAccumulators.js b/legacy/web/app/view/dialog/DeviceAccumulators.js new file mode 100644 index 00000000..eaa4e9f5 --- /dev/null +++ b/legacy/web/app/view/dialog/DeviceAccumulators.js @@ -0,0 +1,55 @@ +/* + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.DeviceAccumulators', { + extend: 'Traccar.view.dialog.Base', + + requires: [ + 'Traccar.view.dialog.DeviceAccumulatorsController' + ], + + controller: 'deviceAccumulators', + title: Strings.sharedDeviceAccumulators, + + items: [{ + xtype: 'customNumberField', + dataType: 'distance', + reference: 'totalDistance', + fieldLabel: Strings.deviceTotalDistance + }, { + xtype: 'customNumberField', + dataType: 'hours', + reference: 'hours', + fieldLabel: Strings.positionHours + }], + + buttons: [{ + reference: 'setButton', + glyph: 'xf00c@FontAwesome', + tooltip: Strings.sharedSet, + tooltipType: 'title', + minWidth: 0, + handler: 'onSetClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/DeviceAccumulatorsController.js b/legacy/web/app/view/dialog/DeviceAccumulatorsController.js new file mode 100644 index 00000000..2fdae6c5 --- /dev/null +++ b/legacy/web/app/view/dialog/DeviceAccumulatorsController.js @@ -0,0 +1,48 @@ +/* + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2018 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.DeviceAccumulatorsController', { + extend: 'Ext.app.ViewController', + alias: 'controller.deviceAccumulators', + + onSetClick: function () { + var totalDistance, hours, data = { + deviceId: this.getView().deviceId + }; + totalDistance = this.lookupReference('totalDistance'); + if (!isNaN(totalDistance.getRawValue())) { + data.totalDistance = totalDistance.getValue(); + } + hours = this.lookupReference('hours'); + if (!isNaN(hours.getRawValue())) { + data.hours = hours.getValue(); + } + Ext.Ajax.request({ + scope: this, + method: 'PUT', + url: 'api/devices/' + data.deviceId + '/accumulators', + jsonData: Ext.util.JSON.encode(data), + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + this.closeView(); + } +}); diff --git a/legacy/web/app/view/dialog/DeviceController.js b/legacy/web/app/view/dialog/DeviceController.js new file mode 100644 index 00000000..d7a4493b --- /dev/null +++ b/legacy/web/app/view/dialog/DeviceController.js @@ -0,0 +1,29 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.DeviceController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.device', + + init: function () { + if (Traccar.app.getUser().get('administrator')) { + this.lookupReference('disabledField').setHidden(false); + } + } + +}); diff --git a/legacy/web/app/view/dialog/Driver.js b/legacy/web/app/view/dialog/Driver.js new file mode 100644 index 00000000..9b1c17b5 --- /dev/null +++ b/legacy/web/app/view/dialog/Driver.js @@ -0,0 +1,46 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Driver', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.UnescapedTextField' + ], + + title: Strings.sharedDriver, + + items: { + xtype: 'form', + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'unescapedTextField', + name: 'name', + fieldLabel: Strings.sharedName, + allowBlank: false + }, { + xtype: 'unescapedTextField', + name: 'uniqueId', + fieldLabel: Strings.deviceIdentifier, + allowBlank: false + }] + }] + } +}); diff --git a/legacy/web/app/view/dialog/Geofence.js b/legacy/web/app/view/dialog/Geofence.js new file mode 100644 index 00000000..1e22cd7b --- /dev/null +++ b/legacy/web/app/view/dialog/Geofence.js @@ -0,0 +1,89 @@ +/* + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Geofence', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.ClearableComboBox', + 'Traccar.view.dialog.GeofenceController', + 'Traccar.view.UnescapedTextField' + ], + + controller: 'geofence', + title: Strings.sharedGeofence, + + items: { + xtype: 'form', + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'unescapedTextField', + name: 'name', + fieldLabel: Strings.sharedName + }] + }, { + xtype: 'fieldset', + title: Strings.sharedExtra, + collapsible: true, + collapsed: true, + items: [{ + xtype: 'unescapedTextField', + name: 'description', + fieldLabel: Strings.sharedDescription + }, { + xtype: 'clearableComboBox', + reference: 'calendarCombo', + name: 'calendarId', + store: 'Calendars', + queryMode: 'local', + displayField: 'name', + valueField: 'id', + fieldLabel: Strings.sharedCalendar + }, { + xtype: 'hiddenfield', + name: 'area', + allowBlank: false, + reference: 'areaField' + }] + }] + }, + + buttons: [{ + text: Strings.sharedArea, + glyph: 'xf21d@FontAwesome', + handler: 'onAreaClick' + }, { + text: Strings.sharedAttributes, + handler: 'showAttributesView' + }, { + xtype: 'tbfill' + }, { + glyph: 'xf00c@FontAwesome', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/GeofenceController.js b/legacy/web/app/view/dialog/GeofenceController.js new file mode 100644 index 00000000..e4ac5a2e --- /dev/null +++ b/legacy/web/app/view/dialog/GeofenceController.js @@ -0,0 +1,58 @@ +/* + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.GeofenceController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.geofence', + + requires: [ + 'Traccar.view.BaseWindow', + 'Traccar.view.map.GeofenceMap' + ], + + config: { + listen: { + controller: { + '*': { + savearea: 'saveArea' + } + } + } + }, + + init: function () { + this.lookupReference('calendarCombo').setHidden( + Traccar.app.getBooleanAttributePreference('ui.disableCalendars')); + }, + + saveArea: function (value) { + this.lookupReference('areaField').setValue(value); + }, + + onAreaClick: function (button) { + var dialog, record; + dialog = button.up('window').down('form'); + record = dialog.getRecord(); + Ext.create('Traccar.view.BaseWindow', { + title: Strings.sharedArea, + items: { + xtype: 'geofenceMapView', + area: record.get('area') + } + }).show(); + } +}); diff --git a/legacy/web/app/view/dialog/Group.js b/legacy/web/app/view/dialog/Group.js new file mode 100644 index 00000000..61ca193d --- /dev/null +++ b/legacy/web/app/view/dialog/Group.js @@ -0,0 +1,55 @@ +/* + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Group', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.ClearableComboBox', + 'Traccar.view.UnescapedTextField' + ], + + title: Strings.groupDialog, + + items: { + xtype: 'form', + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'unescapedTextField', + name: 'name', + fieldLabel: Strings.sharedName, + allowBlank: false + }] + }, { + xtype: 'fieldset', + title: Strings.sharedExtra, + collapsible: true, + collapsed: true, + items: [{ + xtype: 'clearableComboBox', + name: 'groupId', + fieldLabel: Strings.groupParent, + store: 'Groups', + queryMode: 'local', + displayField: 'name', + valueField: 'id' + }] + }] + } +}); diff --git a/legacy/web/app/view/dialog/Login.js b/legacy/web/app/view/dialog/Login.js new file mode 100644 index 00000000..592efb33 --- /dev/null +++ b/legacy/web/app/view/dialog/Login.js @@ -0,0 +1,151 @@ +/* + * Copyright 2015 - 2023 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Login', { + extend: 'Traccar.view.dialog.Base', + alias: 'widget.login', + + requires: [ + 'Traccar.view.dialog.LoginController' + ], + + controller: 'login', + + header: false, + closable: false, + + items: { + xtype: 'form', + reference: 'form', + + autoEl: { + tag: 'form', + method: 'POST', + action: 'fake-login.html', + target: 'submitTarget' + }, + + items: [{ + xtype: 'image', + src: 'logo.svg', + alt: Strings.loginLogo, + width: 240, + height: 64, + style: { + display: 'block', + margin: '10px auto 25px' + } + }, { + xtype: 'pickerfield', + fieldLabel: Strings.settingsServer, + editable: false, + value: window.location.host, + hidden: !window.appInterface && !(window.webkit && window.webkit.messageHandlers.appInterface), + createPicker: function () { + var self = this, popup = Ext.create({ + xtype: 'window', + closeAction: 'hide', + referenceHolder: true, + minWidth: 204, + layout: 'form', + header: false, + resizable: true, + items: [{ + xtype: 'textfield', + anchor: '100%', + reference: 'serverAddress', + value: window.location.href + }], + fbar: [{ + text: Strings.sharedSet, + handler: function () { + var message = 'server|' + popup.lookupReference('serverAddress').getValue(); + if (window.webkit && window.webkit.messageHandlers.appInterface) { + window.webkit.messageHandlers.appInterface.postMessage(message); + } + if (window.appInterface) { + window.appInterface.postMessage(message); + } + } + }, { + text: Strings.sharedCancel, + handler: function () { + self.collapse(); + } + }] + }); + return popup; + } + }, { + xtype: 'combobox', + name: 'language', + fieldLabel: Strings.loginLanguage, + store: 'Languages', + displayField: 'name', + valueField: 'code', + editable: false, + submitValue: false, + listeners: { + select: 'onSelectLanguage' + }, + reference: 'languageField' + }, { + xtype: 'textfield', + name: 'email', + reference: 'userField', + fieldLabel: Strings.userEmail, + allowBlank: false, + enableKeyEvents: true, + listeners: { + specialKey: 'onSpecialKey', + afterrender: 'onAfterRender' + }, + inputAttrTpl: ['autocomplete="on" autocapitalize="none"'] + }, { + xtype: 'textfield', + name: 'password', + reference: 'passwordField', + fieldLabel: Strings.userPassword, + inputType: 'password', + allowBlank: false, + enableKeyEvents: true, + listeners: { + specialKey: 'onSpecialKey' + }, + inputAttrTpl: ['autocomplete="on"'] + }, { + xtype: 'component', + html: '<iframe id="submitTarget" name="submitTarget" style="display:none"></iframe>' + }, { + xtype: 'component', + html: '<input type="submit" id="submitButton" style="display:none">' + }] + }, + + buttons: [{ + text: Strings.loginReset, + handler: 'onResetClick', + reference: 'resetButton' + }, { + text: Strings.loginRegister, + handler: 'onRegisterClick', + reference: 'registerButton' + }, { + text: Strings.loginLogin, + handler: 'onLoginClick' + }] +}); diff --git a/legacy/web/app/view/dialog/LoginController.js b/legacy/web/app/view/dialog/LoginController.js new file mode 100644 index 00000000..a21866eb --- /dev/null +++ b/legacy/web/app/view/dialog/LoginController.js @@ -0,0 +1,132 @@ +/* + * Copyright 2015 - 2023 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.LoginController', { + extend: 'Ext.app.ViewController', + alias: 'controller.login', + + requires: [ + 'Traccar.view.dialog.Register' + ], + + init: function () { + this.lookupReference('resetButton').setHidden(!Traccar.app.getServer().get('emailEnabled')); + this.lookupReference('registerButton').setDisabled(!Traccar.app.getServer().get('registration')); + this.lookupReference('languageField').setValue(Locale.language); + }, + + login: function () { + var form = this.lookupReference('form'); + if (form.isValid()) { + Ext.get('spinner').setVisible(true); + this.getView().setVisible(false); + Ext.Ajax.request({ + scope: this, + method: 'POST', + url: 'api/session', + params: form.getValues(), + callback: function (options, success, response) { + Ext.get('spinner').setVisible(false); + if (success) { + Traccar.app.setUser(Ext.decode(response.responseText)); + this.fireViewEvent('login'); + } else { + this.getView().setVisible(true); + if (response.status === 401) { + Traccar.app.showError(Strings.loginFailed); + } else { + Traccar.app.showError(response.responseText); + } + } + } + }); + } + }, + + logout: function () { + Ext.util.Cookies.clear('user'); + Ext.util.Cookies.clear('password'); + Ext.Ajax.request({ + scope: this, + method: 'DELETE', + url: 'api/session', + callback: function () { + window.location.reload(); + } + }); + }, + + onSelectLanguage: function (selected) { + var paramName, paramValue, url, prefix, suffix; + paramName = 'locale'; + paramValue = selected.getValue(); + url = window.location.href; + if (url.indexOf(paramName + '=') >= 0) { + prefix = url.substring(0, url.indexOf(paramName)); + suffix = url.substring(url.indexOf(paramName)); + suffix = suffix.substring(suffix.indexOf('=') + 1); + suffix = suffix.indexOf('&') >= 0 ? suffix.substring(suffix.indexOf('&')) : ''; + url = prefix + paramName + '=' + paramValue + suffix; + } else if (url.indexOf('?') < 0) { + url += '?' + paramName + '=' + paramValue; + } else { + url += '&' + paramName + '=' + paramValue; + } + window.location.href = url; + }, + + onAfterRender: function (field) { + field.focus(); + }, + + onSpecialKey: function (field, e) { + if (e.getKey() === e.ENTER) { + this.login(); + } + }, + + onLoginClick: function () { + Ext.getElementById('submitButton').click(); + this.login(); + }, + + onRegisterClick: function () { + Ext.create('Traccar.view.dialog.Register').show(); + }, + + onResetClick: function () { + Ext.Msg.prompt(Strings.loginReset, Strings.userEmail, function (btn, text) { + if (btn === 'ok') { + Ext.Ajax.request({ + scope: this, + method: 'POST', + url: 'api/password/reset', + params: { + email: text + }, + callback: function (options, success, response) { + if (success) { + Traccar.app.showToast(Strings.loginResetSuccess); + } else { + Traccar.app.showError(response.responseText); + } + } + }); + } + }); + } +}); diff --git a/legacy/web/app/view/dialog/Maintenance.js b/legacy/web/app/view/dialog/Maintenance.js new file mode 100644 index 00000000..d844d259 --- /dev/null +++ b/legacy/web/app/view/dialog/Maintenance.js @@ -0,0 +1,75 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Maintenance', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.dialog.MaintenanceController', + 'Traccar.view.CustomNumberField', + 'Traccar.view.UnescapedTextField' + ], + + controller: 'maintenance', + + title: Strings.sharedMaintenance, + + items: { + xtype: 'form', + listeners: { + validitychange: 'onValidityChange' + }, + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'unescapedTextField', + name: 'name', + fieldLabel: Strings.sharedName, + allowBlank: false + }, { + xtype: 'combobox', + name: 'type', + reference: 'typeComboField', + fieldLabel: Strings.sharedType, + displayField: 'name', + valueField: 'key', + allowBlank: false, + queryMode: 'local', + store: 'MaintenanceTypes', + listeners: { + change: 'onNameChange' + } + }, { + xtype: 'customNumberField', + name: 'start', + reference: 'startField', + fieldLabel: Strings.maintenanceStart + }, { + xtype: 'customNumberField', + name: 'period', + reference: 'periodField', + allowBlank: false, + fieldLabel: Strings.maintenancePeriod, + validator: function (value) { + return this.parseValue(value) !== 0 ? true : Strings.errorZero; + } + }] + }] + } +}); diff --git a/legacy/web/app/view/dialog/MaintenanceController.js b/legacy/web/app/view/dialog/MaintenanceController.js new file mode 100644 index 00000000..d5a27b54 --- /dev/null +++ b/legacy/web/app/view/dialog/MaintenanceController.js @@ -0,0 +1,65 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.MaintenanceController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.maintenance', + + init: function () { + this.startConfig = Ext.clone(this.lookupReference('startField').initialConfig); + this.startConfig.value = 0; + this.periodConfig = Ext.clone(this.lookupReference('periodField').initialConfig); + this.periodConfig.value = 0; + this.lookupReference('saveButton').setDisabled(true); + }, + + onValidityChange: function (form, valid) { + this.lookupReference('saveButton').setDisabled(!valid); + }, + + updateFieldConfig: function (fieldReference, initialConfig, newConfig) { + var field = this.lookupReference(fieldReference); + if (field.dataType !== newConfig.dataType) { + this.getView().down('fieldset').insert(this.getView().down('fieldset').items.indexOf(field), + Ext.merge({}, initialConfig, newConfig)); + this.getView().down('fieldset').remove(field); + this.lookupReference(fieldReference).validate(); + } else { + field.setConfig(newConfig); + field.validate(); + } + }, + + onNameChange: function (combobox, newValue) { + var attribute, config = {}; + attribute = combobox.getStore().getById(newValue); + if (attribute) { + if (attribute.get('allowDecimals') !== undefined) { + config.allowDecimals = attribute.get('allowDecimals'); + } else { + config.allowDecimals = true; + } + config.dataType = attribute.get('dataType'); + config.maxValue = attribute.get('maxValue'); + config.minValue = attribute.get('minValue'); + } + + this.updateFieldConfig('startField', this.startConfig, config); + this.updateFieldConfig('periodField', this.periodConfig, config); + } +}); diff --git a/legacy/web/app/view/dialog/MapPickerController.js b/legacy/web/app/view/dialog/MapPickerController.js new file mode 100644 index 00000000..8641e377 --- /dev/null +++ b/legacy/web/app/view/dialog/MapPickerController.js @@ -0,0 +1,42 @@ +/* + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.MapPickerController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.mapPicker', + + config: { + listen: { + controller: { + '*': { + mapstate: 'setMapState' + } + } + } + }, + + getMapState: function () { + this.fireEvent('mapstaterequest'); + }, + + setMapState: function (lat, lon, zoom) { + this.lookupReference('latitude').setValue(lat); + this.lookupReference('longitude').setValue(lon); + this.lookupReference('zoom').setValue(zoom); + } +}); diff --git a/legacy/web/app/view/dialog/Notification.js b/legacy/web/app/view/dialog/Notification.js new file mode 100644 index 00000000..51af5b8e --- /dev/null +++ b/legacy/web/app/view/dialog/Notification.js @@ -0,0 +1,95 @@ +/* + * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Notification', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.ClearableComboBox', + 'Traccar.view.dialog.NotificationController' + ], + + controller: 'notification', + title: Strings.sharedNotification, + + items: { + xtype: 'form', + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'combobox', + name: 'type', + fieldLabel: Strings.sharedType, + store: 'AllNotificationTypes', + queryMode: 'local', + displayField: 'name', + valueField: 'type', + editable: false, + allowBlank: false, + listeners: { + change: 'onTypeChange' + } + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'always', + fieldLabel: Strings.notificationAlways + }, { + xtype: 'tagfield', + reference: 'alarmsField', + fieldLabel: Strings.sharedAlarms, + maxWidth: Traccar.Style.formFieldWidth, + store: 'AlarmTypes', + valueField: 'key', + displayField: 'name', + queryMode: 'local', + hidden: true, + listeners: { + beforerender: 'onAlarmsLoad', + change: 'onAlarmsChange' + } + }, { + xtype: 'tagfield', + fieldLabel: Strings.notificationNotificators, + name: 'notificators', + maxWidth: Traccar.Style.formFieldWidth, + store: 'AllNotificators', + valueField: 'type', + displayField: 'name', + queryMode: 'local' + }] + }, { + xtype: 'fieldset', + title: Strings.sharedExtra, + collapsible: true, + collapsed: true, + items: [{ + xtype: 'clearableComboBox', + reference: 'calendarCombo', + name: 'calendarId', + store: 'Calendars', + queryMode: 'local', + displayField: 'name', + valueField: 'id', + fieldLabel: Strings.sharedCalendar + }] + }] + } +}); diff --git a/legacy/web/app/view/dialog/NotificationController.js b/legacy/web/app/view/dialog/NotificationController.js new file mode 100644 index 00000000..5da669a4 --- /dev/null +++ b/legacy/web/app/view/dialog/NotificationController.js @@ -0,0 +1,53 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.NotificationController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.notification', + + init: function () { + this.lookupReference('calendarCombo').setHidden( + Traccar.app.getBooleanAttributePreference('ui.disableCalendars')); + }, + + onTypeChange: function (view, value) { + this.lookupReference('alarmsField').setHidden(value !== 'alarm'); + }, + + onAlarmsLoad: function (view) { + var attributes, record = view.up('form').getRecord(); + attributes = record.get('attributes') || {}; + if (attributes['alarms']) { + view.suspendEvents(false); + view.setValue(attributes['alarms'].split(',')); + view.resumeEvents(); + } + }, + + onAlarmsChange: function (view, value) { + var attributes, record = view.up('window').down('form').getRecord(); + attributes = record.get('attributes') || {}; + + value = value.join(); + if (attributes['alarms'] !== value) { + attributes['alarms'] = value; + record.set('attributes', attributes); + record.dirty = true; + } + } +}); diff --git a/legacy/web/app/view/dialog/Register.js b/legacy/web/app/view/dialog/Register.js new file mode 100644 index 00000000..f9608cef --- /dev/null +++ b/legacy/web/app/view/dialog/Register.js @@ -0,0 +1,67 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Register', { + extend: 'Traccar.view.dialog.Base', + + requires: [ + 'Traccar.view.dialog.RegisterController' + ], + + controller: 'register', + + title: Strings.loginRegister, + + items: { + xtype: 'form', + reference: 'form', + jsonSubmit: true, + + items: [{ + xtype: 'textfield', + name: 'name', + fieldLabel: Strings.sharedName, + allowBlank: false + }, { + xtype: 'textfield', + name: 'email', + fieldLabel: Strings.userEmail, + validator: function (val) { + if (/(.+)@(.+)\.(.{2,})/.test(val)) { + return true; + } else { + return Ext.form.field.VTypes.emailText; + } + }, + allowBlank: false + }, { + xtype: 'textfield', + name: 'password', + fieldLabel: Strings.userPassword, + inputType: 'password', + allowBlank: false + }] + }, + + buttons: [{ + text: Strings.sharedSave, + handler: 'onCreateClick' + }, { + text: Strings.sharedCancel, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/RegisterController.js b/legacy/web/app/view/dialog/RegisterController.js new file mode 100644 index 00000000..c102581e --- /dev/null +++ b/legacy/web/app/view/dialog/RegisterController.js @@ -0,0 +1,44 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.RegisterController', { + extend: 'Ext.app.ViewController', + alias: 'controller.register', + + onCreateClick: function () { + var form = this.lookupReference('form'); + if (form.isValid()) { + Ext.Ajax.request({ + scope: this, + method: 'POST', + url: 'api/users', + jsonData: form.getValues(), + callback: this.onCreateReturn + }); + } + }, + + onCreateReturn: function (options, success, response) { + if (success) { + this.closeView(); + Traccar.app.showToast(Strings.loginCreated); + } else { + Traccar.app.showError(response); + } + } + +}); diff --git a/legacy/web/app/view/dialog/ReportConfig.js b/legacy/web/app/view/dialog/ReportConfig.js new file mode 100644 index 00000000..35cc95b4 --- /dev/null +++ b/legacy/web/app/view/dialog/ReportConfig.js @@ -0,0 +1,136 @@ +/* + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.ReportConfig', { + extend: 'Traccar.view.dialog.Base', + + requires: [ + 'Traccar.view.dialog.ReportConfigController', + 'Traccar.view.CustomTimeField' + ], + + controller: 'reportConfig', + title: Strings.reportConfigure, + + items: [{ + fieldLabel: Strings.reportDevice, + xtype: 'tagfield', + reference: 'deviceField', + maxWidth: Traccar.Style.formFieldWidth, + store: 'Devices', + valueField: 'id', + displayField: 'name', + queryMode: 'local' + }, { + fieldLabel: Strings.reportGroup, + xtype: 'tagfield', + reference: 'groupField', + maxWidth: Traccar.Style.formFieldWidth, + store: 'Groups', + valueField: 'id', + displayField: 'name', + queryMode: 'local' + }, { + fieldLabel: Strings.reportEventTypes, + xtype: 'tagfield', + reference: 'eventTypeField', + maxWidth: Traccar.Style.formFieldWidth, + store: 'ReportEventTypes', + hidden: true, + valueField: 'type', + displayField: 'name', + queryMode: 'local' + }, { + fieldLabel: Strings.reportChartType, + xtype: 'combobox', + reference: 'chartTypeField', + store: 'ReportChartTypes', + hidden: true, + value: 'speed', + valueField: 'key', + displayField: 'name', + queryMode: 'local' + }, { + fieldLabel: Strings.reportShowMarkers, + xtype: 'checkbox', + reference: 'showMarkersField', + inputValue: true, + uncheckedValue: false, + value: false + }, { + fieldLabel: Strings.reportPeriod, + reference: 'periodField', + xtype: 'combobox', + store: 'ReportPeriods', + editable: false, + valueField: 'key', + displayField: 'name', + queryMode: 'local', + listeners: { + change: 'onPeriodChange' + } + }, { + xtype: 'fieldcontainer', + layout: 'vbox', + reference: 'fromContainer', + hidden: true, + fieldLabel: Strings.reportFrom, + items: [{ + xtype: 'datefield', + reference: 'fromDateField', + startDay: Traccar.Style.weekStartDay, + format: Traccar.Style.dateFormat, + value: new Date(new Date().getTime() - 30 * 60 * 1000) + }, { + xtype: 'customTimeField', + reference: 'fromTimeField', + value: new Date(new Date().getTime() - 30 * 60 * 1000) + }] + }, { + xtype: 'fieldcontainer', + layout: 'vbox', + reference: 'toContainer', + hidden: true, + fieldLabel: Strings.reportTo, + items: [{ + xtype: 'datefield', + reference: 'toDateField', + startDay: Traccar.Style.weekStartDay, + format: Traccar.Style.dateFormat, + value: new Date() + }, { + xtype: 'customTimeField', + reference: 'toTimeField', + value: new Date() + }] + }], + + buttons: [{ + glyph: 'xf00c@FontAwesome', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/ReportConfigController.js b/legacy/web/app/view/dialog/ReportConfigController.js new file mode 100644 index 00000000..6d029428 --- /dev/null +++ b/legacy/web/app/view/dialog/ReportConfigController.js @@ -0,0 +1,99 @@ +/* + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.ReportConfigController', { + extend: 'Ext.app.ViewController', + alias: 'controller.reportConfig', + + requires: [ + 'Traccar.store.ReportEventTypes', + 'Traccar.store.AllNotifications' + ], + + onSaveClick: function (button) { + var eventType, callingPanel; + callingPanel = this.getView().callingPanel; + + callingPanel.deviceId = this.lookupReference('deviceField').getValue(); + callingPanel.groupId = this.lookupReference('groupField').getValue(); + eventType = this.lookupReference('eventTypeField').getValue(); + if (eventType.indexOf(Traccar.store.ReportEventTypes.allEvents) > -1) { + eventType = [Traccar.store.ReportEventTypes.allEvents]; + } else if (eventType.length === this.lookupReference('eventTypeField').getStore().getCount() - 1) { + eventType = [Traccar.store.ReportEventTypes.allEvents]; + } + callingPanel.eventType = eventType; + callingPanel.chartType = this.lookupReference('chartTypeField').getValue(); + callingPanel.showMarkers = this.lookupReference('showMarkersField').getValue(); + callingPanel.fromDate = this.lookupReference('fromDateField').getValue(); + callingPanel.fromTime = this.lookupReference('fromTimeField').getValue(); + callingPanel.toDate = this.lookupReference('toDateField').getValue(); + callingPanel.toTime = this.lookupReference('toTimeField').getValue(); + callingPanel.period = this.lookupReference('periodField').getValue(); + callingPanel.updateButtons(); + button.up('window').close(); + }, + + onPeriodChange: function (combobox, newValue) { + var day, first, from, to, custom = newValue === 'custom'; + this.lookupReference('fromContainer').setHidden(!custom); + this.lookupReference('toContainer').setHidden(!custom); + if (!custom) { + from = new Date(); + to = new Date(); + switch (newValue) { + case 'today': + to.setDate(to.getDate() + 1); + break; + case 'yesterday': + from.setDate(to.getDate() - 1); + break; + case 'thisWeek': + day = from.getDay(); + first = from.getDate() - day + (day === 0 ? -6 : 1); + from.setDate(first); + to.setDate(first + 7); + break; + case 'previousWeek': + day = from.getDay(); + first = from.getDate() - day + (day === 0 ? -6 : 1); + from.setDate(first - 7); + to.setDate(first); + break; + case 'thisMonth': + from.setDate(1); + to.setDate(1); + to.setMonth(from.getMonth() + 1); + break; + case 'previousMonth': + from.setDate(1); + from.setMonth(from.getMonth() - 1); + to.setDate(1); + break; + default: + break; + } + from.setHours(0, 0, 0, 0); + to.setHours(0, 0, 0, 0); + this.lookupReference('fromDateField').setValue(from); + this.lookupReference('fromTimeField').setValue(from); + this.lookupReference('toDateField').setValue(to); + this.lookupReference('toTimeField').setValue(to); + } + } +}); diff --git a/legacy/web/app/view/dialog/SavedCommand.js b/legacy/web/app/view/dialog/SavedCommand.js new file mode 100644 index 00000000..b1aeae73 --- /dev/null +++ b/legacy/web/app/view/dialog/SavedCommand.js @@ -0,0 +1,83 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.SavedCommand', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.dialog.SavedCommandController', + 'Traccar.view.UnescapedTextField' + ], + + controller: 'savedCommand', + title: Strings.sharedSavedCommand, + + items: [{ + xtype: 'form', + listeners: { + validitychange: 'onValidityChange' + }, + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'unescapedTextField', + name: 'description', + fieldLabel: Strings.sharedDescription + }, { + xtype: 'checkboxfield', + name: 'textChannel', + inputValue: true, + uncheckedValue: false, + fieldLabel: Strings.commandSendSms + }, { + xtype: 'combobox', + name: 'type', + reference: 'commandType', + fieldLabel: Strings.sharedType, + store: 'AllCommandTypes', + queryMode: 'local', + displayField: 'name', + valueField: 'type', + editable: false, + allowBlank: false, + listeners: { + change: 'onTypeChange' + } + }, { + xtype: 'fieldcontainer', + reference: 'parameters' + }] + }] + }], + + buttons: [{ + glyph: 'xf00c@FontAwesome', + reference: 'saveButton', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + disabled: true, + handler: 'onSaveClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/SavedCommandController.js b/legacy/web/app/view/dialog/SavedCommandController.js new file mode 100644 index 00000000..37c56603 --- /dev/null +++ b/legacy/web/app/view/dialog/SavedCommandController.js @@ -0,0 +1,99 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.SavedCommandController', { + extend: 'Traccar.view.dialog.BaseEditController', + alias: 'controller.savedCommand', + + defaultFieldConfig: { + allowBlank: false + }, + + onTypeChange: function (combo, newValue) { + var i, config, command, parameters, parameter, record; + record = combo.up('window').down('form').getRecord(); + this.lookupReference('parameters').removeAll(); + command = Ext.getStore('KnownCommands').getById(newValue); + 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'); + if (record.get('attributes')) { + config.value = record.get('attributes')[parameter.get('key')]; + } + config.disabled = combo.isDisabled(); + 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') === '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); + } + } + }, + + fillAttributes: function (button) { + var i, form, record, parameters, attributes = {}; + + form = button.up('window').down('form'); + form.updateRecord(); + record = form.getRecord(); + parameters = this.lookupReference('parameters').items.items; + + for (i = 0; i < parameters.length; i++) { + attributes[parameters[i].key] = parameters[i].getValue(); + } + + record.set('attributes', attributes); + }, + + onSaveClick: function (button) { + this.fillAttributes(button); + this.callParent(arguments); + }, + + onValidityChange: function (form, valid) { + this.lookupReference('saveButton').setDisabled(!valid); + } + +}); diff --git a/legacy/web/app/view/dialog/SelectDevice.js b/legacy/web/app/view/dialog/SelectDevice.js new file mode 100644 index 00000000..5b11c03f --- /dev/null +++ b/legacy/web/app/view/dialog/SelectDevice.js @@ -0,0 +1,59 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +Ext.define('Traccar.view.dialog.SelectDevice', { + extend: 'Traccar.view.dialog.Base', + + requires: [ + 'Traccar.view.dialog.SelectDeviceController' + ], + + controller: 'selectDevice', + title: Strings.sharedDevice, + + items: { + xtype: 'form', + items: [{ + xtype: 'combobox', + reference: 'deviceField', + store: 'Devices', + queryMode: 'local', + displayField: 'name', + valueField: 'id', + editable: false, + listeners: { + change: 'onDeviceChange' + } + }] + }, + + buttons: [{ + glyph: 'xf00c@FontAwesome', + reference: 'saveButton', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick', + disabled: true + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/SelectDeviceController.js b/legacy/web/app/view/dialog/SelectDeviceController.js new file mode 100644 index 00000000..9437991c --- /dev/null +++ b/legacy/web/app/view/dialog/SelectDeviceController.js @@ -0,0 +1,45 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.SelectDeviceController', { + extend: 'Ext.app.ViewController', + alias: 'controller.selectDevice', + + onSaveClick: function (button) { + var deviceId, record; + deviceId = this.lookupReference('deviceField').getValue(); + record = this.getView().record.data; + Ext.Ajax.request({ + url: 'api/attributes/computed/test?deviceId=' + deviceId, + method: 'POST', + jsonData: Ext.util.JSON.encode(record), + callback: function (options, success, response) { + if (success) { + Ext.Msg.alert(Strings.sharedInfoTitle, response.responseText || response.statusText); + } else { + Traccar.app.showError(response); + } + } + }); + button.up('window').close(); + }, + + onDeviceChange: function (combobox, newValue) { + this.lookupReference('saveButton').setDisabled(newValue === null); + } +}); diff --git a/legacy/web/app/view/dialog/SendCommand.js b/legacy/web/app/view/dialog/SendCommand.js new file mode 100644 index 00000000..79954739 --- /dev/null +++ b/legacy/web/app/view/dialog/SendCommand.js @@ -0,0 +1,98 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.SendCommand', { + extend: 'Traccar.view.dialog.Base', + + requires: [ + 'Traccar.view.dialog.SendCommandController' + ], + + controller: 'sendCommand', + title: Strings.commandTitle, + + items: [{ + xtype: 'combobox', + reference: 'commandsComboBox', + fieldLabel: Strings.deviceCommand, + displayField: 'description', + valueField: 'id', + store: 'DeviceCommands', + queryMode: 'local', + editable: false, + allowBlank: false, + listeners: { + select: 'onCommandSelect' + } + }, { + xtype: 'form', + listeners: { + validitychange: 'onValidityChange' + }, + items: [{ + xtype: 'fieldset', + reference: 'newCommandFields', + disabled: true, + items: [{ + xtype: 'checkboxfield', + name: 'textChannel', + reference: 'textChannelCheckBox', + inputValue: true, + uncheckedValue: false, + fieldLabel: Strings.commandSendSms, + listeners: { + change: 'onTextChannelChange' + } + }, { + xtype: 'combobox', + name: 'type', + reference: 'commandType', + fieldLabel: Strings.sharedType, + store: 'CommandTypes', + displayField: 'name', + valueField: 'type', + editable: false, + allowBlank: false, + listeners: { + change: 'onTypeChange' + } + }, { + xtype: 'fieldcontainer', + reference: 'parameters' + }] + }] + }], + + buttons: [{ + xtype: 'tbfill' + }, { + glyph: 'xf093@FontAwesome', + tooltip: Strings.sharedSend, + tooltipType: 'title', + minWidth: 0, + disabled: true, + reference: 'sendButton', + handler: 'onSendClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/SendCommandController.js b/legacy/web/app/view/dialog/SendCommandController.js new file mode 100644 index 00000000..c6351587 --- /dev/null +++ b/legacy/web/app/view/dialog/SendCommandController.js @@ -0,0 +1,78 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.SendCommandController', { + extend: 'Traccar.view.dialog.SavedCommandController', + alias: 'controller.sendCommand', + + requires: [ + 'Traccar.view.permissions.SavedCommands' + ], + + onSendClick: function (button) { + var record; + this.fillAttributes(button); + record = button.up('window').down('form').getRecord(); + + Ext.Ajax.request({ + scope: this, + url: 'api/commands/send', + jsonData: record.getData(), + callback: this.onSendResult + }); + }, + + onValidityChange: function (form, valid) { + this.lookupReference('sendButton').setDisabled(!valid || + this.lookupReference('commandsComboBox').getValue() === null); + }, + + onTextChannelChange: function (checkbox, newValue) { + var typesStore = this.lookupReference('commandType').getStore(); + typesStore.getProxy().setExtraParam('textChannel', newValue); + typesStore.reload(); + }, + + onCommandSelect: function (selected) { + var record, form, command = selected.getStore().getById(selected.getValue()); + command.set('deviceId', this.getView().deviceId); + form = selected.up('window').down('form'); + record = form.getRecord(); + form.loadRecord(command); + if (record && command.get('type') === record.get('type')) { + this.onTypeChange(this.lookupReference('commandType'), command.get('type')); + } + + this.lookupReference('newCommandFields').setDisabled(command.getId() !== 0); + this.lookupReference('sendButton').setDisabled(command.getId() === 0); + }, + + onSendResult: function (options, success, response) { + if (success) { + this.closeView(); + Traccar.app.showToast(response.status === 202 ? Strings.commandQueued : Strings.commandSent); + } else { + Traccar.app.showError(response); + } + }, + + closeView: function () { + this.lookupReference('commandsComboBox').getStore().removeAll(); + this.callParent(arguments); + } +}); diff --git a/legacy/web/app/view/dialog/Server.js b/legacy/web/app/view/dialog/Server.js new file mode 100644 index 00000000..6ee250b6 --- /dev/null +++ b/legacy/web/app/view/dialog/Server.js @@ -0,0 +1,159 @@ +/* + * Copyright 2015 - 2018 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.Server', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.ClearableComboBox', + 'Traccar.view.dialog.MapPickerController', + 'Traccar.view.UnescapedTextField' + ], + + controller: 'mapPicker', + title: Strings.serverTitle, + + items: { + xtype: 'form', + items: [{ + xtype: 'fieldset', + title: Strings.sharedPreferences, + items: [{ + xtype: 'clearableComboBox', + name: 'map', + fieldLabel: Strings.mapLayer, + store: 'MapTypes', + displayField: 'name', + valueField: 'key' + }, { + xtype: 'unescapedTextField', + name: 'bingKey', + fieldLabel: Strings.mapBingKey + }, { + xtype: 'unescapedTextField', + reference: 'mapUrlField', + name: 'mapUrl', + fieldLabel: Strings.mapCustomLabel + }, { + xtype: 'numberfield', + reference: 'latitude', + name: 'latitude', + fieldLabel: Strings.positionLatitude, + decimalPrecision: Traccar.Style.coordinatePrecision + }, { + xtype: 'numberfield', + reference: 'longitude', + name: 'longitude', + fieldLabel: Strings.positionLongitude, + decimalPrecision: Traccar.Style.coordinatePrecision + }, { + xtype: 'numberfield', + reference: 'zoom', + name: 'zoom', + fieldLabel: Strings.serverZoom + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'twelveHourFormat', + fieldLabel: Strings.settingsTwelveHourFormat + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'forceSettings', + fieldLabel: Strings.serverForceSettings + }, { + xtype: 'clearableComboBox', + name: 'coordinateFormat', + fieldLabel: Strings.settingsCoordinateFormat, + store: 'CoordinateFormats', + displayField: 'name', + valueField: 'key' + }, { + xtype: 'unescapedTextField', + name: 'poiLayer', + fieldLabel: Strings.mapPoiLayer + }, { + xtype: 'unescapedTextField', + name: 'announcement', + fieldLabel: Strings.serverAnnouncement + }] + }, { + xtype: 'fieldset', + title: Strings.sharedPermissions, + collapsible: true, + collapsed: true, + items: [{ + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'registration', + fieldLabel: Strings.serverRegistration + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'readonly', + fieldLabel: Strings.serverReadonly + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'deviceReadonly', + fieldLabel: Strings.userDeviceReadonly + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'limitCommands', + fieldLabel: Strings.userLimitCommands + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'disableReports', + fieldLabel: Strings.userDisableReports + }] + }] + }, + + buttons: [{ + text: Strings.sharedAttributes, + handler: 'showAttributesView' + }, { + glyph: 'xf041@FontAwesome', + minWidth: 0, + handler: 'getMapState', + tooltip: Strings.sharedGetMapState, + tooltipType: 'title' + }, { + xtype: 'tbfill' + }, { + glyph: 'xf00c@FontAwesome', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/User.js b/legacy/web/app/view/dialog/User.js new file mode 100644 index 00000000..5da56424 --- /dev/null +++ b/legacy/web/app/view/dialog/User.js @@ -0,0 +1,211 @@ +/* + * Copyright 2015 - 2018 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.User', { + extend: 'Traccar.view.dialog.BaseEdit', + + requires: [ + 'Traccar.view.ClearableComboBox', + 'Traccar.view.dialog.UserController', + 'Traccar.view.UnescapedTextField' + ], + + controller: 'user', + title: Strings.settingsUser, + + items: { + xtype: 'form', + items: [{ + xtype: 'fieldset', + title: Strings.sharedRequired, + items: [{ + xtype: 'unescapedTextField', + name: 'name', + fieldLabel: Strings.sharedName + }, { + xtype: 'unescapedTextField', + name: 'email', + fieldLabel: Strings.userEmail, + allowBlank: false + }, { + xtype: 'textfield', + name: 'password', + fieldLabel: Strings.userPassword, + inputType: 'password', + allowBlank: false + }] + }, { + xtype: 'fieldset', + title: Strings.sharedPreferences, + collapsible: true, + collapsed: true, + items: [{ + xtype: 'unescapedTextField', + name: 'phone', + fieldLabel: Strings.sharedPhone + }, { + xtype: 'clearableComboBox', + name: 'map', + fieldLabel: Strings.mapLayer, + store: 'MapTypes', + displayField: 'name', + valueField: 'key' + }, { + xtype: 'numberfield', + reference: 'latitude', + name: 'latitude', + fieldLabel: Strings.positionLatitude, + decimalPrecision: Traccar.Style.coordinatePrecision + }, { + xtype: 'numberfield', + reference: 'longitude', + name: 'longitude', + fieldLabel: Strings.positionLongitude, + decimalPrecision: Traccar.Style.coordinatePrecision + }, { + xtype: 'numberfield', + reference: 'zoom', + name: 'zoom', + fieldLabel: Strings.serverZoom + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'twelveHourFormat', + fieldLabel: Strings.settingsTwelveHourFormat + }, { + xtype: 'clearableComboBox', + name: 'coordinateFormat', + fieldLabel: Strings.settingsCoordinateFormat, + store: 'CoordinateFormats', + displayField: 'name', + valueField: 'key' + }, { + xtype: 'unescapedTextField', + name: 'poiLayer', + fieldLabel: Strings.mapPoiLayer + }] + }, { + xtype: 'fieldset', + title: Strings.sharedPermissions, + collapsible: true, + collapsed: true, + items: [{ + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'disabled', + fieldLabel: Strings.sharedDisabled, + disabled: true, + reference: 'disabledField' + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'administrator', + fieldLabel: Strings.userAdmin, + disabled: true, + reference: 'adminField' + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'readonly', + fieldLabel: Strings.serverReadonly, + disabled: true, + reference: 'readonlyField' + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'deviceReadonly', + fieldLabel: Strings.userDeviceReadonly, + disabled: true, + reference: 'deviceReadonlyField' + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'limitCommands', + fieldLabel: Strings.userLimitCommands, + disabled: true, + reference: 'limitCommandsField' + }, { + xtype: 'checkboxfield', + inputValue: true, + uncheckedValue: false, + name: 'disableReports', + fieldLabel: Strings.userDisableReports, + disabled: true, + reference: 'disableReportsField' + }, { + xtype: 'datefield', + name: 'expirationTime', + fieldLabel: Strings.userExpirationTime, + disabled: true, + reference: 'expirationTimeField', + startDay: Traccar.Style.weekStartDay, + format: Traccar.Style.dateFormat + }, { + xtype: 'numberfield', + name: 'deviceLimit', + fieldLabel: Strings.userDeviceLimit, + disabled: true, + reference: 'deviceLimitField' + }, { + xtype: 'numberfield', + name: 'userLimit', + fieldLabel: Strings.userUserLimit, + disabled: true, + reference: 'userLimitField' + }] + }] + }, + + buttons: [{ + text: Strings.sharedAttributes, + handler: 'showAttributesView' + }, { + glyph: 'xf041@FontAwesome', + minWidth: 0, + handler: 'getMapState', + tooltip: Strings.sharedGetMapState, + tooltipType: 'title' + }, { + glyph: 'xf003@FontAwesome', + minWidth: 0, + handler: 'testNotification', + hidden: true, + reference: 'testNotificationButton', + tooltip: Strings.sharedTestNotification, + tooltipType: 'title' + }, { + xtype: 'tbfill' + }, { + glyph: 'xf00c@FontAwesome', + tooltip: Strings.sharedSave, + tooltipType: 'title', + minWidth: 0, + handler: 'onSaveClick' + }, { + glyph: 'xf00d@FontAwesome', + tooltip: Strings.sharedCancel, + tooltipType: 'title', + minWidth: 0, + handler: 'closeView' + }] +}); diff --git a/legacy/web/app/view/dialog/UserController.js b/legacy/web/app/view/dialog/UserController.js new file mode 100644 index 00000000..0d620614 --- /dev/null +++ b/legacy/web/app/view/dialog/UserController.js @@ -0,0 +1,69 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +Ext.define('Traccar.view.dialog.UserController', { + extend: 'Traccar.view.dialog.MapPickerController', + alias: 'controller.user', + + init: function () { + if (Traccar.app.getUser().get('administrator')) { + this.lookupReference('adminField').setDisabled(false); + this.lookupReference('deviceLimitField').setDisabled(false); + this.lookupReference('userLimitField').setDisabled(false); + } + if (Traccar.app.getUser().get('administrator') || !this.getView().selfEdit) { + this.lookupReference('readonlyField').setDisabled(false); + this.lookupReference('disabledField').setDisabled(false); + this.lookupReference('expirationTimeField').setDisabled(false); + this.lookupReference('deviceReadonlyField').setDisabled(false); + this.lookupReference('limitCommandsField').setDisabled(false); + this.lookupReference('disableReportsField').setDisabled(false); + } + }, + + testNotification: function () { + Ext.Ajax.request({ + url: 'api/notifications/test', + method: 'POST', + failure: function (response) { + Traccar.app.showError(response); + } + }); + }, + + onSaveClick: function (button) { + var dialog, record, store; + dialog = button.up('window').down('form'); + dialog.updateRecord(); + record = dialog.getRecord(); + if (record === Traccar.app.getUser()) { + record.save(); + } else { + store = Ext.getStore('Users'); + if (record.phantom) { + store.add(record); + } + store.sync({ + failure: function (batch) { + store.rejectChanges(); + Traccar.app.showError(batch.exceptions[0].getError().response); + } + }); + } + button.up('window').close(); + } +}); |