diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-17 12:35:16 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-17 12:35:16 +1300 |
commit | 843a370660646499c3007256be953506567f23fb (patch) | |
tree | bb912568b1dad621271a2016ba946634e8e93306 /web/app | |
parent | 60343748265c7fdc228bc7078d2defb877bf66e1 (diff) | |
download | trackermap-server-843a370660646499c3007256be953506567f23fb.tar.gz trackermap-server-843a370660646499c3007256be953506567f23fb.tar.bz2 trackermap-server-843a370660646499c3007256be953506567f23fb.zip |
Add linking and unlinking of devices
Diffstat (limited to 'web/app')
-rw-r--r-- | web/app/Application.js | 19 | ||||
-rw-r--r-- | web/app/view/UserDevices.js | 4 | ||||
-rw-r--r-- | web/app/view/UserDevicesController.js | 35 |
3 files changed, 53 insertions, 5 deletions
diff --git a/web/app/Application.js b/web/app/Application.js index e710b7ea2..83ca9e860 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -76,5 +76,24 @@ Ext.define('Traccar.Application', { getPreference: function (key, defaultValue) { return this.getUser().get(key) || this.getServer().get(key) || defaultValue; + }, + + getErrorHandler: function (scope, handler) { + return function (options, success, response) { + var result; + if (success) { + result = Ext.decode(response.responseText); + if (!result.success) { + Ext.Msg.alert(Strings.errorTitle, result.error); + } + handler.call(scope, options, success, response); + } else { + if (response.statusText) { + Ext.Msg.alert(Strings.errorTitle, response.statusText); + } else { + Ext.Msg.alert(Strings.errorTitle, response.status.toString()); // TODO: text message + } + } + } } }); diff --git a/web/app/view/UserDevices.js b/web/app/view/UserDevices.js index df03bca84..f9ab48266 100644 --- a/web/app/view/UserDevices.js +++ b/web/app/view/UserDevices.js @@ -32,7 +32,8 @@ Ext.define('Traccar.view.UserDevices', { }, listeners: { - selectionchange: 'onSelectionChange' + beforedeselect: 'onBeforeDeselect', + beforeselect: 'onBeforeSelect' }, columns: [{ @@ -43,4 +44,3 @@ Ext.define('Traccar.view.UserDevices', { dataIndex: 'uniqueId', flex: 1 }] }); -32
\ No newline at end of file diff --git a/web/app/view/UserDevicesController.js b/web/app/view/UserDevicesController.js index 20fb47f85..a50ab8c80 100644 --- a/web/app/view/UserDevicesController.js +++ b/web/app/view/UserDevicesController.js @@ -19,6 +19,7 @@ Ext.define('Traccar.view.UserDevicesController', { alias: 'controller.userDevices', init: function () { + this.userId = this.getView().user.getData().id; this.getView().getStore().load({ scope: this, callback: function (records, operation, success) { @@ -26,7 +27,7 @@ Ext.define('Traccar.view.UserDevicesController', { userStore.load({ params: { - userId: this.getView().user.getData().id + userId: this.userId }, scope: this, callback: function (records, operation, success) { @@ -43,7 +44,35 @@ Ext.define('Traccar.view.UserDevicesController', { }); }, - onSelectionChange: function (selected) { - console.log(selected); // TODO + onBeforeSelect: function (object, record, index) { + Ext.Ajax.request({ + scope: this, + url: '/api/device/link', + params: { + userId: this.userId, + deviceId: record.getData().id + }, + callback: Traccar.app.getErrorHandler(this, function (options, success, response) { + if (!success) { + // TODO deselect again + } + }) + }); + }, + + onBeforeDeselect: function (object, record, index) { + Ext.Ajax.request({ + scope: this, + url: '/api/device/unlink', + params: { + userId: this.userId, + deviceId: record.getData().id + }, + callback: Traccar.app.getErrorHandler(this, function (options, success, response) { + if (!success) { + // TODO select again + } + }) + }); } }); |