From 34c878d014a065981d56859cb73564bfa2bc478e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 13 Jan 2017 09:26:24 +0500 Subject: Initial manager implementation --- web/app/view/AttributeAliasesController.js | 12 ++++---- web/app/view/Map.js | 2 +- web/app/view/MapController.js | 16 +++------- web/app/view/SettingsMenuController.js | 9 ++++-- web/app/view/StateController.js | 4 +-- web/app/view/UserDialog.js | 12 +++++++- web/app/view/UserDialogController.js | 10 ++++-- web/app/view/UserUsers.js | 49 ++++++++++++++++++++++++++++++ web/app/view/Users.js | 11 +++++-- web/app/view/UsersController.js | 26 +++++++++++++--- 10 files changed, 117 insertions(+), 34 deletions(-) create mode 100644 web/app/view/UserUsers.js (limited to 'web/app/view') diff --git a/web/app/view/AttributeAliasesController.js b/web/app/view/AttributeAliasesController.js index 367a32a3..1cbb735f 100644 --- a/web/app/view/AttributeAliasesController.js +++ b/web/app/view/AttributeAliasesController.js @@ -1,6 +1,6 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) - * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org) + * 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 @@ -26,8 +26,8 @@ Ext.define('Traccar.view.AttributeAliasesController', { ], init: function () { - var admin = Traccar.app.getUser().get('admin'); - this.lookupReference('deviceField').setStore(admin ? 'AllDevices' : 'Devices'); + var manager = Traccar.app.getUser().get('admin') || Traccar.app.getUser().get('userLimit') > 0; + this.lookupReference('deviceField').setStore(manager ? 'AllDevices' : 'Devices'); this.lookupReference('toolbarAddButton').setDisabled(true); this.lookupReference('toolbarEditButton').setDisabled(true); this.lookupReference('toolbarRemoveButton').setDisabled(true); @@ -88,11 +88,11 @@ Ext.define('Traccar.view.AttributeAliasesController', { }, onDeviceChange: function (combobox, newValue, oldValue) { - var admin = Traccar.app.getUser().get('admin'); + var manager = Traccar.app.getUser().get('admin') || Traccar.app.getUser().get('userLimit') > 0; this.onSelectionChange(''); if (newValue !== null) { this.getView().getStore().filter('deviceId', newValue); - if (admin && this.getView().getStore().getCount() === 0) { + if (manager && this.getView().getStore().getCount() === 0) { Ext.getStore('AttributeAliases').getProxy().setExtraParam('deviceId', newValue); Ext.getStore('AttributeAliases').load({ addRecords: true diff --git a/web/app/view/Map.js b/web/app/view/Map.js index 7f109fdf..b6f04446 100644 --- a/web/app/view/Map.js +++ b/web/app/view/Map.js @@ -44,7 +44,7 @@ Ext.define('Traccar.view.Map', { }, { xtype: 'button', tooltipType: 'title', - handler: 'showGeofences', + handler: 'updateGeofences', reference: 'showGeofencesButton', glyph: 'xf21d@FontAwesome', enableToggle: true, diff --git a/web/app/view/MapController.js b/web/app/view/MapController.js index 66d6809a..a9edee95 100644 --- a/web/app/view/MapController.js +++ b/web/app/view/MapController.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) + * 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 @@ -33,7 +33,7 @@ Ext.define('Traccar.view.MapController', { }, store: { '#Geofences': { - load: 'showGeofences', + load: 'updateGeofences', add: 'updateGeofences', update: 'updateGeofences', remove: 'updateGeofences' @@ -118,7 +118,8 @@ Ext.define('Traccar.view.MapController', { }); }, - showGeofences: function () { + updateGeofences: function () { + this.getView().getGeofencesSource().clear(); if (this.lookupReference('showGeofencesButton').pressed) { Ext.getStore('Geofences').each(function (geofence) { var feature = new ol.Feature(Traccar.GeofenceConverter @@ -128,15 +129,6 @@ Ext.define('Traccar.view.MapController', { this.getView().getGeofencesSource().addFeature(feature); return true; }, this); - } else { - this.getView().getGeofencesSource().clear(); - } - }, - - updateGeofences: function () { - if (this.lookupReference('showGeofencesButton').pressed) { - this.getView().getGeofencesSource().clear(); - this.showGeofences(); } } }); diff --git a/web/app/view/SettingsMenuController.js b/web/app/view/SettingsMenuController.js index 2f1685f0..1f5907d1 100644 --- a/web/app/view/SettingsMenuController.js +++ b/web/app/view/SettingsMenuController.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) + * 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 @@ -35,15 +35,18 @@ Ext.define('Traccar.view.SettingsMenuController', { ], init: function () { - var admin, readonly; + var admin, manager, readonly; admin = Traccar.app.getUser().get('admin'); + manager = Traccar.app.getUser().get('userLimit') > 0; readonly = Traccar.app.getPreference('readonly', false); if (admin) { this.lookupReference('settingsServerButton').setHidden(false); - this.lookupReference('settingsUsersButton').setHidden(false); this.lookupReference('settingsStatisticsButton').setHidden(false); this.lookupReference('settingsDeviceDistanceButton').setHidden(false); } + if (admin || manager) { + this.lookupReference('settingsUsersButton').setHidden(false); + } if (admin || !readonly) { this.lookupReference('settingsGroupsButton').setHidden(false); this.lookupReference('settingsGeofencesButton').setHidden(false); diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js index f9be1135..f84caac2 100644 --- a/web/app/view/StateController.js +++ b/web/app/view/StateController.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * 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 @@ -194,7 +194,7 @@ Ext.define('Traccar.view.StateController', { }, updateAliases: function () { - if (this.position !== null) { + if (this.position) { this.updatePosition(); } } diff --git a/web/app/view/UserDialog.js b/web/app/view/UserDialog.js index 02e7b2fc..8ab3f6b2 100644 --- a/web/app/view/UserDialog.js +++ b/web/app/view/UserDialog.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * 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 @@ -138,6 +138,12 @@ Ext.define('Traccar.view.UserDialog', { fieldLabel: Strings.userDeviceLimit, disabled: true, reference: 'deviceLimitField' + }, { + xtype: 'numberfield', + name: 'userLimit', + fieldLabel: Strings.userUserLimit, + disabled: true, + reference: 'userLimitField' }, { xtype: 'textfield', name: 'token', @@ -153,6 +159,10 @@ Ext.define('Traccar.view.UserDialog', { }] }, + listeners: { + show: 'onShow' + }, + buttons: [{ text: Strings.sharedAttributes, handler: 'showAttributesView' diff --git a/web/app/view/UserDialogController.js b/web/app/view/UserDialogController.js index f07031e3..2946a2a2 100644 --- a/web/app/view/UserDialogController.js +++ b/web/app/view/UserDialogController.js @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * 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 @@ -19,13 +19,17 @@ Ext.define('Traccar.view.UserDialogController', { extend: 'Traccar.view.MapPickerDialogController', alias: 'controller.userDialog', - init: function () { + onShow: function () { if (Traccar.app.getUser().get('admin')) { this.lookupReference('adminField').setHidden(false); + this.lookupReference('deviceLimitField').setDisabled(false); + this.lookupReference('userLimitField').setDisabled(false); + } + if (Traccar.app.getUser().get('admin') || + Traccar.app.getUser().getId() !== this.getView().down('form').getRecord().getId()) { this.lookupReference('readonlyField').setHidden(false); this.lookupReference('disabledField').setHidden(false); this.lookupReference('expirationTimeField').setDisabled(false); - this.lookupReference('deviceLimitField').setDisabled(false); this.lookupReference('tokenField').setDisabled(false); } }, diff --git a/web/app/view/UserUsers.js b/web/app/view/UserUsers.js new file mode 100644 index 00000000..265acc87 --- /dev/null +++ b/web/app/view/UserUsers.js @@ -0,0 +1,49 @@ +/* + * 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 . + */ + +Ext.define('Traccar.view.UserUsers', { + extend: 'Ext.grid.Panel', + xtype: 'userUsersView', + + requires: [ + 'Traccar.view.BasePermissionsController' + ], + + controller: 'basePermissionsController', + + selModel: { + selType: 'checkboxmodel', + checkOnly: true, + showHeaderCheckbox: false + }, + + listeners: { + beforedeselect: 'onBeforeDeselect', + beforeselect: 'onBeforeSelect' + }, + + forceFit: true, + + columns: { + items: [{ + text: Strings.sharedName, + minWidth: Traccar.Style.columnWidthNormal, + dataIndex: 'name' + }] + } +}); diff --git a/web/app/view/Users.js b/web/app/view/Users.js index 09a03cc2..2c0bbefa 100644 --- a/web/app/view/Users.js +++ b/web/app/view/Users.js @@ -1,6 +1,6 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) - * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org) + * Copyright 2015 - 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 @@ -53,6 +53,13 @@ Ext.define('Traccar.view.Users', { glyph: 'xf247@FontAwesome', tooltip: Strings.settingsGroups, tooltipType: 'title' + }, { + disabled: true, + handler: 'onUsersClick', + reference: 'userUsersButton', + glyph: 'xf0c0@FontAwesome', + tooltip: Strings.settingsUsers, + tooltipType: 'title' }, { disabled: true, handler: 'onNotificationsClick', diff --git a/web/app/view/UsersController.js b/web/app/view/UsersController.js index af9d47b2..8aaa8397 100644 --- a/web/app/view/UsersController.js +++ b/web/app/view/UsersController.js @@ -1,6 +1,6 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) - * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org) + * Copyright 2015 - 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 @@ -26,6 +26,7 @@ Ext.define('Traccar.view.UsersController', { 'Traccar.view.UserGroups', 'Traccar.view.UserGeofences', 'Traccar.view.UserCalendars', + 'Traccar.view.UserUsers', 'Traccar.view.Notifications', 'Traccar.view.BaseWindow', 'Traccar.model.User' @@ -33,6 +34,7 @@ Ext.define('Traccar.view.UsersController', { init: function () { Ext.getStore('Users').load(); + this.lookupReference('userUsersButton').setHidden(!Traccar.app.getUser().get('admin')); }, onAddClick: function () { @@ -147,8 +149,23 @@ Ext.define('Traccar.view.UsersController', { }).show(); }, - onSelectionChange: function (selected) { - var disabled = selected.length > 0; + onUsersClick: function () { + var user = this.getView().getSelectionModel().getSelection()[0]; + Ext.create('Traccar.view.BaseWindow', { + title: Strings.settingsUsers, + items: { + xtype: 'userUsersView', + baseObjectName: 'userId', + linkObjectName: 'managedUserId', + storeName: 'Users', + urlApi: 'api/permissions/users', + baseObject: user.getId() + } + }).show(); + }, + + onSelectionChange: function (selection, selected) { + var disabled = selected.length === 0; this.lookupReference('toolbarEditButton').setDisabled(disabled); this.lookupReference('toolbarRemoveButton').setDisabled(disabled); this.lookupReference('userDevicesButton').setDisabled(disabled); @@ -156,5 +173,6 @@ Ext.define('Traccar.view.UsersController', { this.lookupReference('userGeofencesButton').setDisabled(disabled); this.lookupReference('userNotificationsButton').setDisabled(disabled); this.lookupReference('userCalendarsButton').setDisabled(disabled); + this.lookupReference('userUsersButton').setDisabled(disabled || selected[0].get('userLimit') === 0); } }); -- cgit v1.2.3