From 9c46d4cffe47dab99e87111a5e33aa5246c771ab Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 22 Sep 2015 23:01:39 +1200 Subject: Move device dialog to view folder --- web/app/view/BaseEditDialogController.js | 22 ++++++++++- web/app/view/DeviceDialog.js | 41 ++++++++++++++++++++ web/app/view/device/DeviceController.js | 8 ++-- web/app/view/device/DeviceDialog.js | 54 --------------------------- web/app/view/device/DeviceDialogController.js | 45 ---------------------- 5 files changed, 64 insertions(+), 106 deletions(-) create mode 100644 web/app/view/DeviceDialog.js delete mode 100644 web/app/view/device/DeviceDialog.js delete mode 100644 web/app/view/device/DeviceDialogController.js diff --git a/web/app/view/BaseEditDialogController.js b/web/app/view/BaseEditDialogController.js index df4db0e50..863a75dcb 100644 --- a/web/app/view/BaseEditDialogController.js +++ b/web/app/view/BaseEditDialogController.js @@ -19,9 +19,27 @@ Ext.define('Traccar.view.BaseEditDialogController', { alias: 'controller.baseEditDialog', onSaveClick: function(button) { - var dialog = button.up('window').down('form'); + var dialog, store, record; + dialog = button.up('window').down('form'); dialog.updateRecord(); - dialog.getRecord().save(); + record = dialog.getRecord(); + store = record.store; + if (store) { + if (record.phantom) { + store.add(record); + } + store.sync({ + success: function() { + store.reload(); // workaround for selection problem + }, + failure: function(batch) { + store.rejectChanges(); + Traccar.ErrorManager.check(true, batch.exceptions[0].getResponse()); + } + }); + } else { + record.save(); + } button.up('window').close(); } }); diff --git a/web/app/view/DeviceDialog.js b/web/app/view/DeviceDialog.js new file mode 100644 index 000000000..759fade6d --- /dev/null +++ b/web/app/view/DeviceDialog.js @@ -0,0 +1,41 @@ +/* + * 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.DeviceDialog', { + extend: 'Traccar.view.BaseEditDialog', + + requires: [ + 'Traccar.view.BaseEditDialogController' + ], + + controller: 'baseEditDialog', + title: strings.deviceDialog, + + items: { + xtype: 'form', + items: [{ + xtype: 'textfield', + name: 'name', + fieldLabel: strings.deviceName, + allowBlank: false + }, { + xtype: 'textfield', + name: 'uniqueId', + fieldLabel: strings.deviceIdentifier, + allowBlank: false + }] + } +}); diff --git a/web/app/view/device/DeviceController.js b/web/app/view/device/DeviceController.js index 58386596d..e2e82448d 100644 --- a/web/app/view/device/DeviceController.js +++ b/web/app/view/device/DeviceController.js @@ -19,10 +19,8 @@ Ext.define('Traccar.view.device.DeviceController', { alias: 'controller.device', requires: [ - 'Traccar.view.device.DeviceDialog', 'Traccar.view.CommandDialog', 'Traccar.view.user.UserDialog', - 'Traccar.view.ServerDialog', 'Traccar.view.user.User', 'Traccar.view.login.LoginController' ], @@ -51,7 +49,8 @@ Ext.define('Traccar.view.device.DeviceController', { onAddClick: function() { var device, dialog; device = Ext.create('Traccar.model.Device'); - dialog = Ext.create('Traccar.view.device.DeviceDialog'); + device.store = this.getView().getStore(); + dialog = Ext.create('Traccar.view.DeviceDialog'); dialog.down('form').loadRecord(device); dialog.show(); }, @@ -59,7 +58,7 @@ Ext.define('Traccar.view.device.DeviceController', { onEditClick: function() { var device, dialog; device = this.getView().getSelectionModel().getSelection()[0]; - dialog = Ext.create('Traccar.view.device.DeviceDialog'); + dialog = Ext.create('Traccar.view.DeviceDialog'); dialog.down('form').loadRecord(device); dialog.show(); }, @@ -135,5 +134,4 @@ Ext.define('Traccar.view.device.DeviceController', { this.getView().getSelectionModel().deselectAll(); } } - }); diff --git a/web/app/view/device/DeviceDialog.js b/web/app/view/device/DeviceDialog.js deleted file mode 100644 index 5c5042587..000000000 --- a/web/app/view/device/DeviceDialog.js +++ /dev/null @@ -1,54 +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.device.DeviceDialog', { - extend: 'Ext.window.Window', - - requires: [ - 'Traccar.view.device.DeviceDialogController' - ], - - controller: 'deviceDialog', - - bodyPadding: styles.panelPadding, - title: strings.deviceDialog, - resizable: false, - modal: true, - - items: { - xtype: 'form', - items: [{ - xtype: 'textfield', - name: 'name', - fieldLabel: strings.deviceName, - allowBlank: false - }, { - xtype: 'textfield', - name: 'uniqueId', - fieldLabel: strings.deviceIdentifier, - allowBlank: false - }] - }, - - buttons: [{ - text: strings.sharedSave, - handler: 'onSaveClick' - }, { - text: strings.sharedCancel, - handler: 'onCancelClick' - }] - -}); diff --git a/web/app/view/device/DeviceDialogController.js b/web/app/view/device/DeviceDialogController.js deleted file mode 100644 index 0fcb1efb3..000000000 --- a/web/app/view/device/DeviceDialogController.js +++ /dev/null @@ -1,45 +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.device.DeviceDialogController', { - extend: 'Ext.app.ViewController', - alias: 'controller.deviceDialog', - - onSaveClick: function(button) { - var dialog = button.up('window').down('form'); - dialog.updateRecord(); - var store = Ext.getStore('Devices'); - var device = dialog.getRecord(); - if (device.phantom) { - store.add(device); - } - store.sync({ - success: function() { - store.reload(); // workaround for selection problem - }, - failure: function(batch) { - store.rejectChanges(); // TODO - Traccar.ErrorManager.check(true, batch.exceptions[0].getResponse()); - } - }); - button.up('window').close(); - }, - - onCancelClick: function(button) { - button.up('window').close(); - } - -}); -- cgit v1.2.3