client field manager improvements

This commit is contained in:
yuri
2019-08-27 10:56:44 +03:00
parent 7d7d2d4276
commit ab4e85ea45
3 changed files with 37 additions and 13 deletions
+1
View File
@@ -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);
+32 -3
View File
@@ -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
+4 -10
View File
@@ -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()) {