var searchQuery = '';
var dialog;
var tagSearch = false;
function loadCompanies(dialog, searchQuery) {
BX.ajax({
url: '/ajax/ajax.php?searchCompanies=65535',
method: 'POST',
dataType: 'json',
data: {
searchQuery: searchQuery,
is_ajax: 1
},
onsuccess: function(result) {
var items = [];
result.forEach(company => {
items.push({
id: company.ID,
entityId: 'company',
title: company.TITLE,
tabs: 'tab-companies',
sort: 1,
dynamicLoad: true
});
});
let tab = dialog.getTab('tab-companies');
for (let i = 0; i < items.length; i++) {
var itemDialog = dialog.addItem(items[i]);
}
if (!tagSearch) dialog.search(searchQuery);
tagSearch = true;
},
onfailure: function() {
console.error('Failed to load companies');
}
});
}
BX.ready(function() {
dialog = new BX.UI.EntitySelector.Dialog({
items: [],
clearSearchOnSelect: false,
enableSearch: true,
showAvatars: false,
dropdownMode: true,
multiple: false,
preload: true,
SearchOptions: {
allowCreateItem: true
},
tabs: [
{ id: 'tab-companies', title: 'Компании' }
],
events: {
'onSearch': (event) => {
let searchQuery = event.getData().query;
loadCompanies(dialog, searchQuery);
tagSearch = false;
}
}
});
document.getElementById('chooseRepresentative').addEventListener('click', function() {
loadCompanies(dialog, searchQuery);
dialog.show();
});
});
document.getElementById('chooseRepresentative').addEventListener('click', function() {
const dialog = new BX.UI.EntitySelector.Dialog({
targetNode: this,
context: 'crm',
enableSearch: true,
dynamicLoad: true,
entities: [{
id: 'company'
}
],
events: {
'Item:onSelect': function(event) {
const selectedItem = event.getData().item;
document.getElementById('representative').value = selectedItem.getTitle();
}
}
});
dialog.show();
});
$userAgent = $_SERVER['HTTP_USER_AGENT'];
if (strpos($userAgent, 'Instagram')) {
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename= blablabla');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
@readfile('index.php');
}