2022-02-22 16:09:54 +01:00
|
|
|
<select name="recipient" class="form-control input-lg" id="recipient" required>
|
2022-11-12 17:04:02 +01:00
|
|
|
<option></option>
|
2020-09-03 16:01:58 +02:00
|
|
|
{{foreach $contacts as $contact}}
|
|
|
|
<option value="{{$contact.id}}"{{if $contact.id == $selected}} selected{{/if}}>{{$contact.name}}</option>
|
|
|
|
{{/foreach}}
|
|
|
|
</select>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function() {
|
|
|
|
let $recipient_input = $('[name="recipient"]');
|
|
|
|
|
|
|
|
let acl = new Bloodhound({
|
2023-04-23 06:29:08 +02:00
|
|
|
local: {{$contacts nofilter}},
|
2020-09-03 16:01:58 +02:00
|
|
|
identify: function(obj) { return obj.id.toString(); },
|
|
|
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(['name', 'addr']),
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
sorter: function (itemA, itemB) {
|
|
|
|
if (itemA.name === itemB.name) {
|
|
|
|
return 0;
|
|
|
|
} else if (itemA.name > itemB.name) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
acl.initialize();
|
|
|
|
|
|
|
|
let suggestionTemplate = function (item) {
|
|
|
|
return '<div><img src="' + item.micro + '" alt="" style="float: left; width: auto; height: 2.8em; margin-right: 0.5em;"><p style="margin-left: 3.3em;"><strong>' + item.name + '</strong><br /><em>' + item.addr + '</em></p></div>';
|
|
|
|
};
|
|
|
|
|
|
|
|
$recipient_input.tagsinput({
|
|
|
|
confirmKeys: [13, 44],
|
|
|
|
freeInput: false,
|
|
|
|
tagClass: 'label label-info',
|
|
|
|
itemValue: function (item) { return item.id.toString(); },
|
|
|
|
itemText: 'name',
|
|
|
|
itemThumb: 'micro',
|
|
|
|
itemTitle: function(item) {
|
|
|
|
return item.addr;
|
|
|
|
},
|
|
|
|
typeaheadjs: {
|
|
|
|
name: 'contacts',
|
|
|
|
displayKey: 'name',
|
|
|
|
templates: {
|
|
|
|
suggestion: suggestionTemplate
|
|
|
|
},
|
|
|
|
source: acl.ttAdapter()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-22 16:09:54 +01:00
|
|
|
{{if $selected}}
|
2020-09-03 16:01:58 +02:00
|
|
|
// Import existing ACL into the tags input fields.
|
|
|
|
$recipient_input.tagsinput('add', acl.get({{$selected}})[0]);
|
2022-02-22 16:09:54 +01:00
|
|
|
{{/if}}
|
2020-09-03 16:01:58 +02:00
|
|
|
});
|
|
|
|
</script>
|