From ab4e85ea453b9b06687482ddef68b6d4ed37bd2e Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 27 Aug 2019 10:56:44 +0300 Subject: [PATCH] client field manager improvements --- client/src/app.js | 1 + client/src/field-manager.js | 35 ++++++++++++++++++++++++++++++--- client/src/views/record/list.js | 14 ++++--------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/client/src/app.js b/client/src/app.js index 1cdd9154f6..773cb47d7f 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -141,6 +141,7 @@ define( this.preferences = new Preferences(); this.preferences.settings = this.settings; this.acl = this.createAclManager(); + this.fieldManager.acl = this.acl; this.themeManager = new ThemeManager(this.settings, this.preferences, this.metadata); diff --git a/client/src/field-manager.js b/client/src/field-manager.js index a27d1ad6b2..cc45bf1928 100644 --- a/client/src/field-manager.js +++ b/client/src/field-manager.js @@ -28,9 +28,10 @@ define('field-manager', [], function () { - var FieldManager = function (defs, metadata) { + var FieldManager = function (defs, metadata, acl) { this.defs = defs || {}; this.metadata = metadata; + this.acl = acl || null; }; _.extend(FieldManager.prototype, { @@ -39,6 +40,8 @@ metadata: null, + acl: null, + getParamList: function (fieldType) { if (fieldType in this.defs) { return this.defs[fieldType].params || []; @@ -144,8 +147,34 @@ return _.union(this.getActualAttributeList(fieldType, fieldName), this.getNotActualAttributeList(fieldType, fieldName)); }, - getEntityTypeFieldList: function (entityType) { - return Object.keys(this.metadata.get(['entityDefs', entityType, 'fields']) || {}); + getEntityTypeFieldList: function (entityType, o) { + var list = Object.keys(this.metadata.get(['entityDefs', entityType, 'fields']) || {}); + + var typeList = o.typeList; + if (!typeList && o.type) typeList = [o.type]; + + if (typeList) { + list = list.filter(function (item) { + var type = this.metadata.get(['entityDefs', entityType, 'fields', item, 'type']); + return ~typeList.indexOf(type); + }, this); + } + + if (o.onlyAvailable || o.acl) { + list = list.filter(function (item) { + return this.isEntityTypeFieldAvailable(entityType, item); + }, this); + } + + if (o.acl) { + var level = o.acl || 'read'; + var forbiddenEditFieldList = this.acl.getScopeForbiddenFieldList(entityType, level); + list = list.filter(function (item) { + return !~forbiddenEditFieldList.indexOf(item); + }, this); + } + + return list; }, getScopeFieldList: function (entityType) { // TODO remove in 5.8.0 diff --git a/client/src/views/record/list.js b/client/src/views/record/list.js index 1513283245..dac718bf0a 100644 --- a/client/src/views/record/list.js +++ b/client/src/views/record/list.js @@ -1033,21 +1033,15 @@ define('views/record/list', 'view', function (Dep) { this.getAcl().checkScope(this.scope, 'edit') && this.getAcl().get('massUpdatePermission') === 'yes' ) { - var forbiddenEditFieldList = this.getAcl().getScopeForbiddenFieldList(this.scope, 'edit') - - var currencyFieldList = []; - this.getFieldManager().getEntityTypeFieldList(this.entityType).forEach(function (field) { - if (this.getMetadata().get(['entityDefs', this.entityType, 'fields', field, 'type']) !== 'currency') return; - if (~forbiddenEditFieldList.indexOf('field')) return; - if (!this.getFieldManager().isEntityTypeFieldAvailable(this.entityType, field)) return; - currencyFieldList.push(field); - }, this); + var currencyFieldList = this.getFieldManager().getEntityTypeFieldList(this.entityType, { + type: 'currency', + acl: 'edit', + }); if (currencyFieldList.length) this.addMassAction('convertCurrency', true); } - this.setupMassActionItems(); if (this.getUser().isAdmin()) {