From 318ad837e5e9b26a8320c93114806514fc629166 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 21 Sep 2015 16:22:28 +1200 Subject: Refactor commands dialog classes --- web/app/view/BaseDialogController.js | 23 ++++++++ web/app/view/BaseEditDialogController.js | 6 +-- web/app/view/CommandDialog.js | 67 +++++++++++++++++++++++ web/app/view/CommandDialogController.js | 57 ++++++++++++++++++++ web/app/view/command/CommandDialog.js | 72 ------------------------- web/app/view/command/CommandDialogController.js | 62 --------------------- web/app/view/device/DeviceController.js | 4 +- 7 files changed, 150 insertions(+), 141 deletions(-) create mode 100644 web/app/view/BaseDialogController.js create mode 100644 web/app/view/CommandDialog.js create mode 100644 web/app/view/CommandDialogController.js delete mode 100644 web/app/view/command/CommandDialog.js delete mode 100644 web/app/view/command/CommandDialogController.js (limited to 'web') diff --git a/web/app/view/BaseDialogController.js b/web/app/view/BaseDialogController.js new file mode 100644 index 000000000..4bf23d94e --- /dev/null +++ b/web/app/view/BaseDialogController.js @@ -0,0 +1,23 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.BaseDialogController', { + extend: 'Ext.app.ViewController', + + onCancelClick: function(button) { + button.up('window').close(); + } +}); diff --git a/web/app/view/BaseEditDialogController.js b/web/app/view/BaseEditDialogController.js index ca090f714..df4db0e50 100644 --- a/web/app/view/BaseEditDialogController.js +++ b/web/app/view/BaseEditDialogController.js @@ -15,7 +15,7 @@ */ Ext.define('Traccar.view.BaseEditDialogController', { - extend: 'Ext.app.ViewController', + extend: 'Traccar.view.BaseDialogController', alias: 'controller.baseEditDialog', onSaveClick: function(button) { @@ -23,9 +23,5 @@ Ext.define('Traccar.view.BaseEditDialogController', { dialog.updateRecord(); dialog.getRecord().save(); button.up('window').close(); - }, - - onCancelClick: function(button) { - button.up('window').close(); } }); diff --git a/web/app/view/CommandDialog.js b/web/app/view/CommandDialog.js new file mode 100644 index 000000000..1cc96b195 --- /dev/null +++ b/web/app/view/CommandDialog.js @@ -0,0 +1,67 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.CommandDialog', { + extend: 'Traccar.view.BaseDialog', + + requires: [ + 'Traccar.view.CommandDialogController' + ], + + controller: 'commandDialog', + title: strings.commandTitle, + + items: { + xtype: 'form', + items: [{ + xtype: 'combobox', + name: 'type', + fieldLabel: strings.commandType, + store: 'CommandTypes', + displayField: 'name', + valueField: 'key', + listeners: { + select: 'onSelect' + } + }, { + 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' + }] + }] + }, + + buttons: [{ + text: strings.commandSend, + handler: 'onSendClick' + }, { + text: strings.sharedCancel, + handler: 'onCancelClick' + }] +}); diff --git a/web/app/view/CommandDialogController.js b/web/app/view/CommandDialogController.js new file mode 100644 index 000000000..66a10bbb6 --- /dev/null +++ b/web/app/view/CommandDialogController.js @@ -0,0 +1,57 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.CommandDialogController', { + extend: 'Traccar.view.BaseDialogController', + alias: 'controller.commandDialog', + + onSelect: function(selected) { + this.lookupReference('paramPositionPeriodic').setHidden( + selected.getValue() !== 'positionPeriodic'); + }, + + onSendClick: function(button) { + var attributes, value, record, form; + + form = button.up('window').down('form'); + form.updateRecord(); + record = form.getRecord(); + + if (record.get('type') === 'positionPeriodic') { + attributes = this.lookupReference('paramPositionPeriodic'); + value = attributes.down('numberfield[name="frequency"]').getValue(); + value *= attributes.down('combobox[name="unit"]').getValue(); + + record.set('attributes', { + frequency: value + }); + } + + Ext.Ajax.request({ + scope: this, + url: '/api/command/send', + jsonData: record.getData(), + callback: this.onSendResult + }); + }, + + onSendResult: function(options, success, response) { + if (Traccar.ErrorManager.check(success, response)) { + Ext.toast(strings.commandSent); + this.closeView(); + } + } +}); diff --git a/web/app/view/command/CommandDialog.js b/web/app/view/command/CommandDialog.js deleted file mode 100644 index 8f567a74a..000000000 --- a/web/app/view/command/CommandDialog.js +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -Ext.define('Traccar.view.command.CommandDialog', { - extend: 'Ext.window.Window', - - requires: [ - 'Traccar.view.command.CommandDialogController' - ], - - controller: 'commandDialog', - - bodyPadding: styles.panelPadding, - title: strings.commandTitle, - resizable: false, - modal: true, - - items: { - xtype: 'form', - items: [{ - xtype: 'combobox', - name: 'type', - fieldLabel: strings.commandType, - store: 'CommandTypes', - displayField: 'name', - valueField: 'key', - listeners: { - select: 'onSelect' - } - }, { - 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' - }] - }] - }, - - buttons: [{ - text: strings.commandSend, - handler: 'onSendClick' - }, { - text: strings.sharedCancel, - handler: 'onCancelClick' - }] - -}); diff --git a/web/app/view/command/CommandDialogController.js b/web/app/view/command/CommandDialogController.js deleted file mode 100644 index 8c13ea1e1..000000000 --- a/web/app/view/command/CommandDialogController.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -Ext.define('Traccar.view.command.CommandDialogController', { - extend: 'Ext.app.ViewController', - alias: 'controller.commandDialog', - - onSelect: function(selected) { - this.lookupReference('paramPositionPeriodic').setHidden( - selected.getValue() !== 'positionPeriodic'); - }, - - onSendClick: function(button) { - var attributes, value, record, form; - - form = button.up('window').down('form'); - form.updateRecord(); - record = form.getRecord(); - - if (record.get('type') === 'positionPeriodic') { - attributes = this.lookupReference('paramPositionPeriodic'); - value = attributes.down('numberfield[name="frequency"]').getValue(); - value *= attributes.down('combobox[name="unit"]').getValue(); - - record.set('attributes', { - frequency: value - }); - } - - Ext.Ajax.request({ - scope: this, - url: '/api/command/send', - jsonData: record.getData(), - callback: this.onSendReturn - }); - }, - - onSendReturn: function(options, success, response) { - if (Traccar.ErrorManager.check(success, response)) { - Ext.toast(strings.commandSent); - this.closeView(); - } - }, - - onCancelClick: function(button) { - button.up('window').close(); - } - -}); diff --git a/web/app/view/device/DeviceController.js b/web/app/view/device/DeviceController.js index d7cade414..58386596d 100644 --- a/web/app/view/device/DeviceController.js +++ b/web/app/view/device/DeviceController.js @@ -20,7 +20,7 @@ Ext.define('Traccar.view.device.DeviceController', { requires: [ 'Traccar.view.device.DeviceDialog', - 'Traccar.view.command.CommandDialog', + 'Traccar.view.CommandDialog', 'Traccar.view.user.UserDialog', 'Traccar.view.ServerDialog', 'Traccar.view.user.User', @@ -90,7 +90,7 @@ Ext.define('Traccar.view.device.DeviceController', { device = this.getView().getSelectionModel().getSelection()[0]; command = Ext.create('Traccar.model.Command'); command.set('deviceId', device.get('id')); - dialog = Ext.create('Traccar.view.command.CommandDialog'); + dialog = Ext.create('Traccar.view.CommandDialog'); dialog.down('form').loadRecord(command); dialog.show(); }, -- cgit v1.2.3