2022-02-22 15:09:54 +00:00
|
|
|
<select name="recipient" class="form-control input-lg" id="recipient" required>
|
2022-11-12 16:04:02 +00:00
|
|
|
<option></option>
|
2020-09-03 14:01:58 +00: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({
|
|
|
|
local: {{$contacts|@json_encode nofilter}},
|
|
|
|
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 15:09:54 +00:00
|
|
|
{{if $selected}}
|
2020-09-03 14:01:58 +00:00
|
|
|
// Import existing ACL into the tags input fields.
|
|
|
|
$recipient_input.tagsinput('add', acl.get({{$selected}})[0]);
|
2022-02-22 15:09:54 +00:00
|
|
|
{{/if}}
|
2020-09-03 14:01:58 +00:00
|
|
|
});
|
|
|
|
</script>
|