aboutsummaryrefslogtreecommitdiff
path: root/web/app/view
diff options
context:
space:
mode:
Diffstat (limited to 'web/app/view')
-rw-r--r--web/app/view/BasePermissionsController.js (renamed from web/app/view/DeviceGeofencesController.js)41
-rw-r--r--web/app/view/DeviceGeofences.js4
-rw-r--r--web/app/view/DevicesController.js10
-rw-r--r--web/app/view/GroupGeofences.js4
-rw-r--r--web/app/view/GroupGeofencesController.js80
-rw-r--r--web/app/view/GroupsController.js11
-rw-r--r--web/app/view/UserDevices.js5
-rw-r--r--web/app/view/UserDevicesController.js79
-rw-r--r--web/app/view/UserGeofences.js5
-rw-r--r--web/app/view/UserGeofencesController.js79
-rw-r--r--web/app/view/UserGroups.js5
-rw-r--r--web/app/view/UserGroupsController.js79
-rw-r--r--web/app/view/Users.js2
-rw-r--r--web/app/view/UsersController.js23
14 files changed, 66 insertions, 361 deletions
diff --git a/web/app/view/DeviceGeofencesController.js b/web/app/view/BasePermissionsController.js
index c9d4b0aa9..713d91770 100644
--- a/web/app/view/DeviceGeofencesController.js
+++ b/web/app/view/BasePermissionsController.js
@@ -14,22 +14,23 @@
* limitations under the License.
*/
-Ext.define('Traccar.view.DeviceGeofencesController', {
+Ext.define('Traccar.view.BasePermissionsController', {
extend: 'Ext.app.ViewController',
- alias: 'controller.deviceGeofences',
+ alias: 'controller.basePermissionsController',
init: function () {
- var admin = Traccar.app.getUser().get('admin');
- this.deviceId = this.getView().device.getData().id;
- this.getView().setStore(Ext.getStore((admin) ? 'AllGeofences' : 'Geofences'));
+ var params = {};
+ params[this.getView().baseObjectName] = this.getView().baseObject;
+ var linkStoreName = this.getView().linkStoreName;
+ var storeName = this.getView().storeName;
+ linkStoreName = (typeof linkStoreName === 'undefined') ? storeName : linkStoreName;
+ this.getView().setStore(Ext.getStore(storeName));
this.getView().getStore().load({
scope: this,
callback: function (records, operation, success) {
- var deviceStore = Ext.create((admin) ? 'Traccar.store.AllGeofences' : 'Traccar.store.Geofences');
- deviceStore.load({
- params: {
- deviceId: this.deviceId
- },
+ var linkStore = Ext.create('Traccar.store.' + linkStoreName);
+ linkStore.load({
+ params: params,
scope: this,
callback: function (records, operation, success) {
var i, index;
@@ -46,13 +47,13 @@ Ext.define('Traccar.view.DeviceGeofencesController', {
},
onBeforeSelect: function (object, record, index) {
+ var data = {};
+ data[this.getView().baseObjectName] = this.getView().baseObject;
+ data[this.getView().linkObjectName] = record.getData().id;
Ext.Ajax.request({
scope: this,
- url: '/api/devices/geofences',
- jsonData: {
- deviceId: this.deviceId,
- geofenceId: record.getData().id
- },
+ url: this.getView().urlApi,
+ jsonData: Ext.util.JSON.encode(data),
callback: function (options, success, response) {
if (!success) {
Traccar.app.showError(response);
@@ -62,14 +63,14 @@ Ext.define('Traccar.view.DeviceGeofencesController', {
},
onBeforeDeselect: function (object, record, index) {
+ var data = {};
+ data[this.getView().baseObjectName] = this.getView().baseObject;
+ data[this.getView().linkObjectName] = record.getData().id;
Ext.Ajax.request({
scope: this,
method: 'DELETE',
- url: '/api/devices/geofences',
- jsonData: {
- deviceId: this.deviceId,
- geofenceId: record.getData().id
- },
+ url: this.getView().urlApi,
+ jsonData: Ext.util.JSON.encode(data),
callback: function (options, success, response) {
if (!success) {
Traccar.app.showError(response);
diff --git a/web/app/view/DeviceGeofences.js b/web/app/view/DeviceGeofences.js
index a309cc2ed..9e2c12a77 100644
--- a/web/app/view/DeviceGeofences.js
+++ b/web/app/view/DeviceGeofences.js
@@ -19,10 +19,10 @@ Ext.define('Traccar.view.DeviceGeofences', {
xtype: 'deviceGeofencesView',
requires: [
- 'Traccar.view.DeviceGeofencesController'
+ 'Traccar.view.BasePermissionsController'
],
- controller: 'deviceGeofences',
+ controller: 'basePermissionsController',
selModel: {
selType: 'checkboxmodel',
diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js
index d33368181..cf31dd7bb 100644
--- a/web/app/view/DevicesController.js
+++ b/web/app/view/DevicesController.js
@@ -86,13 +86,17 @@ Ext.define('Traccar.view.DevicesController', {
},
onGeofencesClick: function () {
- device = this.getView().getSelectionModel().getSelection()[0];
var admin = Traccar.app.getUser().get('admin');
+ var device = this.getView().getSelectionModel().getSelection()[0];
Ext.create('Traccar.view.BaseWindow', {
- title: Strings.settingsGeofences,
+ title: Strings.sharedGeofences,
items: {
xtype: 'deviceGeofencesView',
- device: device
+ baseObjectName: 'deviceId',
+ linkObjectName: 'geofenceId',
+ storeName: (admin) ? 'AllGeofences' : 'Geofences',
+ urlApi: '/api/devices/geofences',
+ baseObject: device.getData().id
}
}).show();
},
diff --git a/web/app/view/GroupGeofences.js b/web/app/view/GroupGeofences.js
index 9a46f3964..8ef2984ea 100644
--- a/web/app/view/GroupGeofences.js
+++ b/web/app/view/GroupGeofences.js
@@ -19,10 +19,10 @@ Ext.define('Traccar.view.GroupGeofences', {
xtype: 'groupGeofencesView',
requires: [
- 'Traccar.view.GroupGeofencesController'
+ 'Traccar.view.BasePermissionsController'
],
- controller: 'groupGeofences',
+ controller: 'basePermissionsController',
selModel: {
selType: 'checkboxmodel',
diff --git a/web/app/view/GroupGeofencesController.js b/web/app/view/GroupGeofencesController.js
deleted file mode 100644
index e8b2a6f52..000000000
--- a/web/app/view/GroupGeofencesController.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2016 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.GroupGeofencesController', {
- extend: 'Ext.app.ViewController',
- alias: 'controller.groupGeofences',
-
- init: function () {
- var admin = Traccar.app.getUser().get('admin');
- this.groupId = this.getView().group.getData().id;
- this.getView().setStore(Ext.getStore((admin) ? 'AllGeofences' : 'Geofences'));
- this.getView().getStore().load({
- scope: this,
- callback: function (records, operation, success) {
- var groupStore = Ext.create((admin) ? 'Traccar.store.AllGeofences' : 'Traccar.store.Geofences');
- groupStore.load({
- params: {
- groupId: this.groupId
- },
- scope: this,
- callback: function (records, operation, success) {
- var i, index;
- if (success) {
- for (i = 0; i < records.length; i++) {
- index = this.getView().getStore().find('id', records[i].getData().id);
- this.getView().getSelectionModel().select(index, true, true);
- }
- }
- }
- });
- }
- });
- },
-
- onBeforeSelect: function (object, record, index) {
- Ext.Ajax.request({
- scope: this,
- url: '/api/groups/geofences',
- jsonData: {
- groupId: this.groupId,
- geofenceId: record.getData().id
- },
- callback: function (options, success, response) {
- if (!success) {
- Traccar.app.showError(response);
- }
- }
- });
- },
-
- onBeforeDeselect: function (object, record, index) {
- Ext.Ajax.request({
- scope: this,
- method: 'DELETE',
- url: '/api/groups/geofences',
- jsonData: {
- groupId: this.groupId,
- geofenceId: record.getData().id
- },
- callback: function (options, success, response) {
- if (!success) {
- Traccar.app.showError(response);
- }
- }
- });
- }
-});
diff --git a/web/app/view/GroupsController.js b/web/app/view/GroupsController.js
index 396a28e7e..bc713bb6d 100644
--- a/web/app/view/GroupsController.js
+++ b/web/app/view/GroupsController.js
@@ -60,12 +60,17 @@ Ext.define('Traccar.view.GroupsController', {
},
onGeofencesClick: function () {
- group = this.getView().getSelectionModel().getSelection()[0];
+ var admin = Traccar.app.getUser().get('admin');
+ var group = this.getView().getSelectionModel().getSelection()[0];
Ext.create('Traccar.view.BaseWindow', {
- title: Strings.settingsGeofences,
+ title: Strings.sharedGeofences,
items: {
xtype: 'groupGeofencesView',
- group: group
+ baseObjectName: 'groupId',
+ linkObjectName: 'geofenceId',
+ storeName: (admin) ? 'AllGeofences' : 'Geofences',
+ urlApi: '/api/groups/geofences',
+ baseObject: group.getData().id
}
}).show();
},
diff --git a/web/app/view/UserDevices.js b/web/app/view/UserDevices.js
index fe16dd93a..6a1a718aa 100644
--- a/web/app/view/UserDevices.js
+++ b/web/app/view/UserDevices.js
@@ -19,11 +19,10 @@ Ext.define('Traccar.view.UserDevices', {
xtype: 'userDevicesView',
requires: [
- 'Traccar.view.UserDevicesController'
+ 'Traccar.view.BasePermissionsController'
],
- controller: 'userDevices',
- store: 'AllDevices',
+ controller: 'basePermissionsController',
selModel: {
selType: 'checkboxmodel',
diff --git a/web/app/view/UserDevicesController.js b/web/app/view/UserDevicesController.js
deleted file mode 100644
index e5dbbdbb8..000000000
--- a/web/app/view/UserDevicesController.js
+++ /dev/null
@@ -1,79 +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.UserDevicesController', {
- extend: 'Ext.app.ViewController',
- alias: 'controller.userDevices',
-
- init: function () {
- this.userId = this.getView().user.getData().id;
- this.getView().getStore().load({
- scope: this,
- callback: function (records, operation, success) {
- var userStore = Ext.create('Traccar.store.Devices');
-
- userStore.load({
- params: {
- userId: this.userId
- },
- scope: this,
- callback: function (records, operation, success) {
- var i, index;
- if (success) {
- for (i = 0; i < records.length; i++) {
- index = this.getView().getStore().find('id', records[i].getData().id);
- this.getView().getSelectionModel().select(index, true, true);
- }
- }
- }
- });
- }
- });
- },
-
- onBeforeSelect: function (object, record, index) {
- Ext.Ajax.request({
- scope: this,
- url: '/api/permissions/devices',
- jsonData: {
- userId: this.userId,
- deviceId: record.getData().id
- },
- callback: function (options, success, response) {
- if (!success) {
- Traccar.app.showError(response);
- }
- }
- });
- },
-
- onBeforeDeselect: function (object, record, index) {
- Ext.Ajax.request({
- scope: this,
- method: 'DELETE',
- url: '/api/permissions/devices',
- jsonData: {
- userId: this.userId,
- deviceId: record.getData().id
- },
- callback: function (options, success, response) {
- if (!success) {
- Traccar.app.showError(response);
- }
- }
- });
- }
-});
diff --git a/web/app/view/UserGeofences.js b/web/app/view/UserGeofences.js
index 83ded6665..03a02ff3b 100644
--- a/web/app/view/UserGeofences.js
+++ b/web/app/view/UserGeofences.js
@@ -19,11 +19,10 @@ Ext.define('Traccar.view.UserGeofences', {
xtype: 'userGeofencesView',
requires: [
- 'Traccar.view.UserGeofencesController'
+ 'Traccar.view.BasePermissionsController'
],
- controller: 'userGeofences',
- store: 'AllGeofences',
+ controller: 'basePermissionsController',
selModel: {
selType: 'checkboxmodel',
diff --git a/web/app/view/UserGeofencesController.js b/web/app/view/UserGeofencesController.js
deleted file mode 100644
index 5ce13b51e..000000000
--- a/web/app/view/UserGeofencesController.js
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2016 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.UserGeofencesController', {
- extend: 'Ext.app.ViewController',
- alias: 'controller.userGeofences',
-
- init: function () {
- this.userId = this.getView().user.getData().id;
- this.getView().getStore().load({
- scope: this,
- callback: function (records, operation, success) {
- var userStore = Ext.create('Traccar.store.Geofences');
-
- userStore.load({
- params: {
- userId: this.userId
- },
- scope: this,
- callback: function (records, operation, success) {
- var i, index;
- if (success) {
- for (i = 0; i < records.length; i++) {
- index = this.getView().getStore().find('id', records[i].getData().id);
- this.getView().getSelectionModel().select(index, true, true);
- }
- }
- }
- });
- }
- });
- },
-
- onBeforeSelect: function (object, record, index) {
- Ext.Ajax.request({
- scope: this,
- url: '/api/permissions/geofences',
- jsonData: {
- userId: this.userId,
- geofenceId: record.getData().id
- },
- callback: function (options, success, response) {
- if (!success) {
- Traccar.app.showError(response);
- }
- }
- });
- },
-
- onBeforeDeselect: function (object, record, index) {
- Ext.Ajax.request({
- scope: this,
- method: 'DELETE',
- url: '/api/permissions/geofences',
- jsonData: {
- userId: this.userId,
- geofenceId: record.getData().id
- },
- callback: function (options, success, response) {
- if (!success) {
- Traccar.app.showError(response);
- }
- }
- });
- }
-});
diff --git a/web/app/view/UserGroups.js b/web/app/view/UserGroups.js
index cb0f0bd5d..84032f021 100644
--- a/web/app/view/UserGroups.js
+++ b/web/app/view/UserGroups.js
@@ -19,11 +19,10 @@ Ext.define('Traccar.view.UserGroups', {
xtype: 'userGroupsView',
requires: [
- 'Traccar.view.UserGroupsController'
+ 'Traccar.view.BasePermissionsController'
],
- controller: 'userGroups',
- store: 'AllGroups',
+ controller: 'basePermissionsController',
selModel: {
selType: 'checkboxmodel',
diff --git a/web/app/view/UserGroupsController.js b/web/app/view/UserGroupsController.js
deleted file mode 100644
index 662508f0a..000000000
--- a/web/app/view/UserGroupsController.js
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2016 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.UserGroupsController', {
- extend: 'Ext.app.ViewController',
- alias: 'controller.userGroups',
-
- init: function () {
- this.userId = this.getView().user.getData().id;
- this.getView().getStore().load({
- scope: this,
- callback: function (records, operation, success) {
- var userStore = Ext.create('Traccar.store.Groups');
-
- userStore.load({
- params: {
- userId: this.userId
- },
- scope: this,
- callback: function (records, operation, success) {
- var i, index;
- if (success) {
- for (i = 0; i < records.length; i++) {
- index = this.getView().getStore().find('id', records[i].getData().id);
- this.getView().getSelectionModel().select(index, true, true);
- }
- }
- }
- });
- }
- });
- },
-
- onBeforeSelect: function (object, record, index) {
- Ext.Ajax.request({
- scope: this,
- url: '/api/permissions/groups',
- jsonData: {
- userId: this.userId,
- groupId: record.getData().id
- },
- callback: function (options, success, response) {
- if (!success) {
- Traccar.app.showError(response);
- }
- }
- });
- },
-
- onBeforeDeselect: function (object, record, index) {
- Ext.Ajax.request({
- scope: this,
- method: 'DELETE',
- url: '/api/permissions/groups',
- jsonData: {
- userId: this.userId,
- groupId: record.getData().id
- },
- callback: function (options, success, response) {
- if (!success) {
- Traccar.app.showError(response);
- }
- }
- });
- }
-});
diff --git a/web/app/view/Users.js b/web/app/view/Users.js
index 4c5b2a05b..b6301b38b 100644
--- a/web/app/view/Users.js
+++ b/web/app/view/Users.js
@@ -41,7 +41,7 @@ Ext.define('Traccar.view.Users', {
handler: 'onGroupsClick',
reference: 'userGroupsButton'
}, {
- text: Strings.settingsGeofences,
+ text: Strings.sharedGeofences,
disabled: true,
handler: 'onGeofencesClick',
reference: 'userGeofencesButton'
diff --git a/web/app/view/UsersController.js b/web/app/view/UsersController.js
index acf718c82..acba66b4d 100644
--- a/web/app/view/UsersController.js
+++ b/web/app/view/UsersController.js
@@ -72,7 +72,12 @@ Ext.define('Traccar.view.UsersController', {
title: Strings.deviceTitle,
items: {
xtype: 'userDevicesView',
- user: user
+ baseObjectName: 'userId',
+ linkObjectName: 'deviceId',
+ storeName: 'AllDevices',
+ linkStoreName: 'Devices',
+ urlApi: '/api/permissions/devices',
+ baseObject: user.getData().id
}
}).show();
},
@@ -83,7 +88,12 @@ Ext.define('Traccar.view.UsersController', {
title: Strings.settingsGroups,
items: {
xtype: 'userGroupsView',
- user: user
+ baseObjectName: 'userId',
+ linkObjectName: 'groupId',
+ storeName: 'AllGroups',
+ linkStoreName: 'Groups',
+ urlApi: '/api/permissions/groups',
+ baseObject: user.getData().id
}
}).show();
},
@@ -91,10 +101,15 @@ Ext.define('Traccar.view.UsersController', {
onGeofencesClick: function () {
var user = this.getView().getSelectionModel().getSelection()[0];
Ext.create('Traccar.view.BaseWindow', {
- title: Strings.settingsGeofences,
+ title: Strings.sharedGeofences,
items: {
xtype: 'userGeofencesView',
- user: user
+ baseObjectName: 'userId',
+ linkObjectName: 'geofenceId',
+ storeName: 'AllGeofences',
+ linkStoreName: 'Geofences',
+ urlApi: '/api/permissions/geofences',
+ baseObject: user.getData().id
}
}).show();
},