Allow contacts and groups with same ID in ACL selector

This commit is contained in:
Hypolite Petovan 2019-12-07 05:50:15 -05:00
parent 7cfe05f849
commit 74cc9d00fa

View file

@ -130,19 +130,19 @@
// Custom visibility tags inputs // Custom visibility tags inputs
let acl_groups = new Bloodhound({ let acl_groups = new Bloodhound({
local: {{$acl_groups|@json_encode nofilter}}, local: {{$acl_groups|@json_encode nofilter}},
identify: function(obj) { return obj.id; }, identify: function(obj) { return obj.type + '-' + obj.id.toString(); },
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name']), datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name']),
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
}); });
let acl_contacts = new Bloodhound({ let acl_contacts = new Bloodhound({
local: {{$acl_contacts|@json_encode nofilter}}, local: {{$acl_contacts|@json_encode nofilter}},
identify: function(obj) { return obj.id; }, identify: function(obj) { return obj.type + '-' + obj.id.toString(); },
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']), datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']),
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
}); });
let acl = new Bloodhound({ let acl = new Bloodhound({
local: {{$acl_list|@json_encode nofilter}}, local: {{$acl_list|@json_encode nofilter}},
identify: function(obj) { return obj.id; }, identify: function(obj) { return obj.type + '-' + obj.id.toString(); },
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']), datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']),
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
}); });
@ -163,7 +163,7 @@
return 'label label-info'; return 'label label-info';
} }
}, },
itemValue: 'id', itemValue: function (item) { return item.type + '-' + item.id.toString(); },
itemText: 'name', itemText: 'name',
itemThumb: 'micro', itemThumb: 'micro',
itemTitle: function(item) { itemTitle: function(item) {
@ -191,7 +191,7 @@
return 'label label-info'; return 'label label-info';
} }
}, },
itemValue: 'id', itemValue: function (item) { return item.type + '-' + item.id.toString(); },
itemText: 'name', itemText: 'name',
itemThumb: 'micro', itemThumb: 'micro',
itemTitle: function(item) { itemTitle: function(item) {
@ -209,17 +209,17 @@
// Import existing ACL into the tags input fields. // Import existing ACL into the tags input fields.
$group_allow_input.val().split(',').forEach(function (val) { $group_allow_input.val().split(',').forEach(function (group_id) {
$acl_allow_input.tagsinput('add', acl_groups.get(val)[0]); $acl_allow_input.tagsinput('add', acl_groups.get('group-' + group_id)[0]);
}); });
$contact_allow_input.val().split(',').forEach(function (val) { $contact_allow_input.val().split(',').forEach(function (contact_id) {
$acl_allow_input.tagsinput('add', acl_contacts.get(val)[0]); $acl_allow_input.tagsinput('add', acl_contacts.get('contact-' + contact_id)[0]);
}); });
$group_deny_input.val().split(',').forEach(function (val) { $group_deny_input.val().split(',').forEach(function (group_id) {
$acl_deny_input.tagsinput('add', acl_groups.get(val)[0]); $acl_deny_input.tagsinput('add', acl_groups.get('group-' + group_id)[0]);
}); });
$contact_deny_input.val().split(',').forEach(function (val) { $contact_deny_input.val().split(',').forEach(function (contact_id) {
$acl_deny_input.tagsinput('add', acl_contacts.get(val)[0]); $acl_deny_input.tagsinput('add', acl_contacts.get('contact-' + contact_id)[0]);
}); });
// Anti-duplicate callback + acl fields value generation // Anti-duplicate callback + acl fields value generation