* Получение массива объектов (разделены переносами)
*/
function getTaskObjectArray(task) {
return task.split(String.fromCharCode(13));
}
/**
* Вставка панели уведомлений
*/
jQuery(document).ready(function () {
var checkExist = setInterval(function () {
if (AS.OPTIONS.login && AS.OPTIONS.login != '') {
addPanel();
clearInterval(checkExist);
}
}, 100);
});
var notificationPanel = jQuery("<divclass='notification-container'></div>");
var showed = [];
var notShowed = [];
function addPanel() {
jQuery("body").append(notificationPanel)
notificationPanel.show(function () {
loadTasks(function (data) {
clearAllNotifications();
data.forEach(function (task) {
var taskObject = getTaskObjectArray(task.task);
if (isValidTask(taskObject)) {
var object = {
taskID: task.taskID,
taskObject: taskObject,
start: task.start,
task: task.task,
finish: task.finish
};
if (isTimeToShow(task.start)) {
showed.push(object);
} else {
notShowed.push(object);
}
}
});
checkTimeInArray();
showNotify();
});
});
}
//Иконка колокольчика
var ringBase64 = 'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAQAAABKfvVzAAAACXBIWXMAAAsTAAALEwEAmpwYAAADGGlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjaY2BgnuDo4uTKJMDAUFBUUuQe5BgZERmlwH6egY2BmYGBgYGBITG5uMAxIMCHgYGBIS8/L5UBFTAyMHy7xsDIwMDAcFnX0cXJlYE0wJpcUFTCwMBwgIGBwSgltTiZgYHhCwMDQ3p5SUEJAwNjDAMDg0hSdkEJAwNjAQMDg0h2SJAzAwNjCwMDE09JakUJAwMDg3N+QWVRZnpGiYKhpaWlgmNKflKqQnBlcUlqbrGCZ15yflFBflFiSWoKAwMD1A4GBgYGXpf8EgX3xMw8BSMDVQYqg4jIKAUICxE+CDEESC4tKoMHJQODAIMCgwGDA0MAQyJDPcMChqMMbxjFGV0YSxlXMN5jEmMKYprAdIFZmDmSeSHzGxZLlg6WW6x6rK2s99gs2aaxfWMPZ9/NocTRxfGFM5HzApcj1xZuTe4FPFI8U3mFeCfxCfNN45fhXyygI7BD0FXwilCq0A/hXhEVkb2i4aJfxCaJG4lfkaiQlJM8JpUvLS19QqZMVl32llyfvIv8H4WtioVKekpvldeqFKiaqP5UO6jepRGqqaT5QeuA9iSdVF0rPUG9V/pHDBYY1hrFGNuayJsym740u2C+02KJ5QSrOutcmzjbQDtXe2sHY0cdJzVnJRcFV3k3BXdlD3VPXS8Tbxsfd99gvwT//ID6wIlBS4N3hVwMfRnOFCEXaRUVEV0RMzN2T9yDBLZE3aSw5IaUNak30zkyLDIzs+ZmX8xlz7PPryjYVPiuWLskq3RV2ZsK/cqSql01jLVedVPrHzbqNdU0n22VaytsP9op3VXUfbpXta+x/+5Em0mzJ/+dGj/t8AyNmf2zvs9JmHt6vvmCpYtEFrcu+bYsc/m9lSGrTq9xWbtvveWGbZtMNm/ZarJt+w6rnft3u+45uy9s/4ODOYd+Hmk/Jn58xUnrU+fOJJ/9dX7SRe1LR68kXv13fc5Nm1t379TfU75/4mHeY7En+59lvhB5efB1/lv5dxc+NH0y/fzq64Lv4T8Ffp360/rP8f9/AA0ADzT6lvFdAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAADBSURBVHjazJSxDoIwEIa/Etkc9AEclAchrizMbMaEnTegr2GcfQPiyovgZgLv4FAXlQo9hRATb2rv7rvr31yrDOPMG5nP7LnY2l5FBJyx2pcfO0QUFERDj+QRAxC7on1XQkUKQEpFImp4WMoB9dqtOTHn+CbP2KJXXPA7JW5suEqis146+GSyhtB5Z6EMBE4gkIGFE1hOGo0/B7SYpV2AJheBvEXa0fjy9ErVHT41RXSNwVAPB/Y0NOxcIfXzX+M+ACEjIJk9xFSpAAAAAElFTkSuQmCC';
var list = getSocial('crm_form_account_socialNetworks', 'crm_form_account_socialNetworks_socialNetworks-b', 'crm_form_account_socialNetworks_socialNetworksCombo-b', data);
list.forEach(function (item) {
if (item.key == 'Facebook Messenger') {
createFacebookLink(item.value, parent);
}
if (item.key == 'Skype') {
createSkypeLink(item.value, parent);
}
})
list = getSocial('crm_form_account_phone', 'crm_form_account_phone_phone-b', 'crm_form_account_phone_phoneCombo-b', data);
list.forEach(function (item) {
if (item.key == 'Viber') {
createViberLink(item.value, parent);
}else if (item.key == 'Telegram') {
createTelegramLink(item.value, parent);
}else {
createTelephoneLink(item.value, parent);
}
})
list = getSocial('crm_form_account_email', 'crm_form_account_email_email-b', 'crm_form_account_email_emailCombo-b', data);
list.forEach(function (item) {
createMailLink(item.value, parent);
});
});
}
function createMailLink(value, parent){
if(value){
parent.append(jQuery('<divclass="social_element mail"><atarget="_blank"href="mailto:'+value+'">' + value + '</a></div>'));
}
}
function createViberLink(value, parent){
if(value){
parent.append(jQuery('<divclass="social_element viber"><atarget="_blank"href="viber://add?number='+value+'">' + value + '</a></div>'));
}
}
function createTelegramLink(value, parent){
if(value){
parent.append(jQuery('<divclass="social_element telegram"><atarget="_blank"href="https://telegram.me/'+value+'">' + value + '</a></div>'));
}
}
function createTelephoneLink(value, parent){
if(value){
parent.append(jQuery('<divclass="social_element tel"><atarget="_blank"href="tel:'+value+'">' + value + '</a></div>'));
}
}
function getSocial(idTable, valId, keyId, data) {
var found = data.data.filter(function (item) {
return item.id === idTable;
});
var list = [];
found[0].data.forEach(function (item) {
var id = item.id;
if (id.indexOf(valId) !== -1) {
var i = id.substring(id.indexOf(valId) + valId.length);
if (!list[i]) {
list[i] = {'value': item.value}
} else {
list[i].value = item.value;
}
}
if (id.indexOf(keyId) !== -1) {
var i = id.substring(id.indexOf(keyId) + keyId.length);
if (!list[i]) {
list[i] = {'key': item.value}
} else {
list[i].key = item.value;
}
}
});
return list;
}
function createFacebookLink(value, parent) {
var id;
if (value.indexOf("profile.php?id=") !== -1) {
id = value.substring(value.indexOf('profile.php?id=') + 'profile.php?id='.length);
} else {
id = value.substring(value.indexOf('facebook.com/') + 'facebook.com/'.length);
}
if (id) {
parent.append(jQuery('<divclass="social_element facebook"><atarget="_blank"href="http://m.me/' + id + '">' + value + '</a></div>'))
}
}
function createSkypeLink(value, parent) {
if(value){
parent.append(jQuery('<divclass="social_element skype"><atarget="_blank"href="skype:' + value + '?call">' + i18n.tr("Позвонить") + ' ' + value + '</a></div>'))
parent.append(jQuery('<divclass="social_element skype"><atarget="_blank"href="skype:' + value + '?chat">' + i18n.tr("Написать") + ' ' + value + '</a></div>'))
var list = getSocial('crm_form_contact_socialNetworks', 'crm_form_contact_socialNetworks_socialNetworks-b', 'crm_form_contact_socialNetworks_socialNetworksCombo-b', data);
list.forEach(function (item) {
if (item.key == 'Facebook Messenger') {
createFacebookLink(item.value, parent);
}
if (item.key == 'Skype') {
createSkypeLink(item.value, parent);
}
})
list = getSocial('crm_form_contact_phone', 'crm_form_contact_phone_phone-b', 'crm_form_contact_phone_phoneCombo-b', data);
list.forEach(function (item) {
if (item.key == 'Viber') {
createViberLink(item.value, parent);
}else if (item.key == 'Telegram') {
createTelegramLink(item.value, parent);
}else {
createTelephoneLink(item.value, parent);
}
})
list = getSocial('crm_form_contact_email', 'crm_form_contact_email_email-b', 'crm_form_contact_email_emailCombo-b', data);
list.forEach(function (item) {
createMailLink(item.value, parent);
});
});
}
function createMailLink(value, parent){
if(value){
parent.append(jQuery('<divclass="social_element mail"><atarget="_blank"href="mailto:'+value+'">' + value + '</a></div>'));
}
}
function createViberLink(value, parent){
if(value){
parent.append(jQuery('<divclass="social_element viber"><atarget="_blank"href="viber://add?number='+value+'">' + value + '</a></div>'));
}
}
function createTelegramLink(value, parent){
if(value){
parent.append(jQuery('<divclass="social_element telegram"><atarget="_blank"href="https://telegram.me/'+value+'">' + value + '</a></div>'));
}
}
function createTelephoneLink(value, parent){
if(value){
parent.append(jQuery('<divclass="social_element tel"><atarget="_blank"href="tel:'+value+'">' + value + '</a></div>'));
}
}
function getSocial(idTable, valId, keyId, data) {
var found = data.data.filter(function (item) {
return item.id === idTable;
});
var list = [];
found[0].data.forEach(function (item) {
var id = item.id;
if (id.indexOf(valId) !== -1) {
var i = id.substring(id.indexOf(valId) + valId.length);
if (!list[i]) {
list[i] = {'value': item.value}
} else {
list[i].value = item.value;
}
}
if (id.indexOf(keyId) !== -1) {
var i = id.substring(id.indexOf(keyId) + keyId.length);
if (!list[i]) {
list[i] = {'key': item.value}
} else {
list[i].key = item.value;
}
}
});
return list;
}
function createFacebookLink(value, parent) {
var id;
if (value.indexOf("profile.php?id=") !== -1) {
id = value.substring(value.indexOf('profile.php?id=') + 'profile.php?id='.length);
} else {
id = value.substring(value.indexOf('facebook.com/') + 'facebook.com/'.length);
}
if (id) {
parent.append(jQuery('<divclass="social_element facebook"><atarget="_blank"href="http://m.me/' + id + '">' + value + '</a></div>'))
}
}
function createSkypeLink(value, parent) {
if(value){
parent.append(jQuery('<divclass="social_element skype"><atarget="_blank"href="skype:' + value + '?call">' + i18n.tr("Позвонить") + ' ' + value + '</a></div>'))
parent.append(jQuery('<divclass="social_element skype"><atarget="_blank"href="skype:' + value + '?chat">' + i18n.tr("Написать") + ' ' + value + '</a></div>'))