From 76182895c619c7815a82de006919ef9ba74c08e7 Mon Sep 17 00:00:00 2001 From: mac Date: Sun, 21 Jun 2026 09:11:22 +0300 Subject: [PATCH] add tab deal in client edit --- js/crm.js | 2354 +++++++++++++++++++++------------------- js/deals_client_vue.js | 60 + templates/footer.php | 77 +- 3 files changed, 1375 insertions(+), 1116 deletions(-) create mode 100644 js/deals_client_vue.js diff --git a/js/crm.js b/js/crm.js index 947a595..a85ec4a 100644 --- a/js/crm.js +++ b/js/crm.js @@ -42,8 +42,8 @@ var phone2Index = 0; $(function () { var lastScrollTop = 0; - - kanbanScrollHandler = async function () { + + kanbanScrollHandler = async function () { var st = $('#kanban___list').scrollTop(); if (st < lastScrollTop) { @@ -56,30 +56,30 @@ $(function () { var skroll_top = $('.kanban').scrollTop(); var hw = $('.kanban').height(); var top_kanban = $('.kanban__items-lists').offset().top; - + var hk = $('.kanban__items-lists').height(); const divUl = $('.kanban__items-lists').find('.kanban__items-list'); - + if(divUl){ for(let i=0; i= heigthLi && add_knban) { + + + if (skroll_top + hw >= heigthLi && add_knban) { console.log('clients li'); add_knban = false; page_kanban++; get_list(); lastScrollTop = st; - + } } } @@ -87,7 +87,7 @@ $(function () { if (document.location.pathname === '/clients.php') { if (skroll_top + hw >= hk && add_knban) { - + console.log('clients'); add_knban = false; page_kanban++; @@ -276,7 +276,7 @@ function get_mes_clients() { } } else { let objects = $('.confirm_mess .object-confirm').length; - //console.log(objects); + //console.log(objects); if (objects == 0) { $('.confirm_mess').html(''); } @@ -547,7 +547,7 @@ function get_objects_list(page, sort, param = {}) { param.sort_order = sort; } } - console.log(param); + console.log(param); $.post('/ajax/getObjectsView.php', param, function(data) { $('#objects').html(data); @@ -627,7 +627,7 @@ function getNoClientsForObjects(hiddenObjects = []){ const allowEdit = $(this).attr("data-allow-edit"); if (objectId) { const shouldHideButton = hiddenObjectsSet.has(objectId); - + if($(this).find('.obj_client').length == 0 && allowEdit > 0 && !shouldHideButton && !isSalePage) { let html = ''; html += `
`; @@ -956,9 +956,9 @@ function get_params(){ param.page = page; } - - // sort_order = 0; - param.sort_order = 0; + + // sort_order = 0; + param.sort_order = 0; //} //$('#sortOrder select[name="sort_order"]').prop('selectedIndex', sort_order); @@ -986,14 +986,14 @@ function get_params(){ function get_count_clients(){ let param = get_params(); $.post('/ajax/getClientsView.php', param, function(data) { - + if(data){ let count = $('.kanban__rails[data-count]').data('count') || $('.clients[data-count]').data('count') || $('.crm__table[data-count]').data('count'); let res_count = JSON.parse(data); - + Object.entries(res_count).forEach(([key, value]) => { let index = key; - //$('.kanban__head').eq(index).find('.task-count').text(value); + //$('.kanban__head').eq(index).find('.task-count').text(value); let countTd = parseInt(value); let rawPercent = (countTd / count) * 100 || 0; const percent = Number.isInteger(rawPercent) ? rawPercent.toString() : rawPercent.toFixed(2) || 0; @@ -1007,7 +1007,7 @@ function get_count_clients(){
${countTd}
`; $('.stage-step-'+index).find('.task-count-holder').html(htmlTd); - }); + }); } }); } @@ -1202,7 +1202,7 @@ function get_list(page, sort_order, preloader) { $('.object-content__preloader').hide();*/ if ($('.view-kanban.active').length > 0 && page_kanban == 1) { - + if($('#clients_list').length > 0){ $('#clients_list').html(data); @@ -1251,11 +1251,11 @@ function get_list(page, sort_order, preloader) { delete param.get_list; param.get_list_count = 1; $.post('/ajax/getClientsView.php', param, function(data) { - + if(data){ let count = $('.kanban__rails[data-count]').data('count') || $('.clients[data-count]').data('count') || $('.crm__table[data-count]').data('count'); let res_count = JSON.parse(data); - + Object.entries(res_count).forEach(([key, value]) => { let index = key - 1; //$('.kanban__head').eq(index).find('.task-count').text(value); @@ -1273,8 +1273,8 @@ function get_list(page, sort_order, preloader) { `; $('.kanban__head').eq(index).find('.task-count-holder').html(htmlTd); }); - - + + } }); }); @@ -1346,15 +1346,15 @@ function get_list(page, sort_order, preloader) { } let count = $('.kanban__rails[data-count]').data('count') || $('.clients[data-count]').data('count') || $('.crm__table[data-count]').data('count'); - - + + document.querySelectorAll('td.task-count').forEach(td => { const countTd = parseFloat(td.textContent) || 0; const newTd = document.createElement('td'); newTd.className = 'task-count-holder'; let rawPercent = (countTd / count) * 100 || 0; const percent = Number.isInteger(rawPercent) ? rawPercent.toString() : rawPercent.toFixed(2) || 0; - const color = window.getComputedStyle(td).backgroundColor || '#00aaff'; + const color = window.getComputedStyle(td).backgroundColor || '#00aaff'; newTd.innerHTML = `
'+value.name+'' + - '' + - '' + - '' + - '' + - '' + - 'Удалить' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' + + 'Удалить' + + '' + + '' + + '' $('.probank ul').append(li); } }); @@ -2655,14 +2661,14 @@ function editClientNew(id, funnelId) { Object.entries(resolve).forEach(([key, value]) => { if(!isEmpty(value)){ let li = '
  • ' + - ''+value.name+'' + - '' + - '' + - '' + - 'Удалить' + - '' + - '' + - '
  • '; + ''+value.name+'' + + '' + + '' + + '' + + 'Удалить' + + '' + + '' + + ''; $('#proresolve-yes').append(li); } }); @@ -2742,15 +2748,15 @@ function editClientNew(id, funnelId) { $('.persone_no_ip').addClass('hidden'); } // console.log(data.persone_info_bank,"vot zdes"); - + function normalizeContactText(rawHtml) { return rawHtml - .replace(//gi, '\n') - .replace(/[^\S\r\n]{2,}/g, ' ') - .replace(/[\r\n]{2,}/g, '\n') - .replace(/[^\w\sА-Яа-яёЁ.,:()\-+]/g, '') - .trim(); - } + .replace(//gi, '\n') + .replace(/[^\S\r\n]{2,}/g, ' ') + .replace(/[\r\n]{2,}/g, '\n') + .replace(/[^\w\sА-Яа-яёЁ.,:()\-+]/g, '') + .trim(); + } @@ -3079,8 +3085,8 @@ function advertsSwitch(elemn) { $('#advertisings__' + object_id + ' .action-button').removeClass('active'); switchToAdvert(object_id, user_id, +state); } else { - - $(elemn).prop("checked", true); + + $(elemn).prop("checked", true); } return false; } else if (state) { @@ -3359,12 +3365,12 @@ function confirmOnClients(clients) { var clients_id = clients; axios.post('/ajax/ajax_vue_requisitions.php', { - request: 'confirm_on_clients', - clients_id: clients_id, - user_id: user_id, - all: all, + request: 'confirm_on_clients', + clients_id: clients_id, + user_id: user_id, + all: all, - }, ) + }, ) .then((response) => { console.log(response.data); let funnel_id = $('#funnelIdClients').val(); @@ -3387,13 +3393,13 @@ function confirmOnClients(clients) { } function open_stagebars_funnels(reqId){ - if($('#funnels_adjacent_a_req_'+reqId).hasClass('active_show')){ - close_stagebars_funnels(reqId); - } else { - $('#funnels_adjacent_a_req_'+reqId).addClass('active_show'); - $('#funnels_adjacent_list_req_'+reqId).show(); + if($('#funnels_adjacent_a_req_'+reqId).hasClass('active_show')){ + close_stagebars_funnels(reqId); + } else { + $('#funnels_adjacent_a_req_'+reqId).addClass('active_show'); + $('#funnels_adjacent_list_req_'+reqId).show(); - } + } } function close_stagebars_funnels(reqId){ @@ -3415,33 +3421,33 @@ function get_select_who_work_task(selector, section, id){ $(selector+" .check_who_work").html(''); if(id > 0) { - //if ($(selector+" .check_who_work .who_work_tasks").length < 1) { + //if ($(selector+" .check_who_work .who_work_tasks").length < 1) { axios.post('/ajax/select_form_who_work_tasks.php', - { - id: id, - section: section - } + { + id: id, + section: section + } ).then((response) => { - $(selector+" .check_who_work").html(response.data); - // $(selector+" .check_who_work .who_work_tasks").val(who_work); - $(selector+" .check_who_work .who_work_tasks").fastselect({ - placeholder: 'Ответственный', - // onItemCreate: function() { $(this).find('.fstQueryInput').hide() }, - }); - }) + $(selector+" .check_who_work").html(response.data); + // $(selector+" .check_who_work .who_work_tasks").val(who_work); + $(selector+" .check_who_work .who_work_tasks").fastselect({ + placeholder: 'Ответственный', + // onItemCreate: function() { $(this).find('.fstQueryInput').hide() }, + }); + }) .catch(function(error) { console.log(error); }); - /* } else { - $(selector+" .check_who_work .who_work_tasks").fastselect().data('fastselect').destroy(); - //$('#req-new-client-work-input').html(html); - //$(selector+" .check_who_work .who_work_tasks").val(who_work); - $(selector+" .check_who_work .who_work_tasks").fastselect({ - placeholder: 'Ответственный', - onItemCreate: function() { $(this).find('.fstQueryInput').hide() }, - }); - }*/ + /* } else { + $(selector+" .check_who_work .who_work_tasks").fastselect().data('fastselect').destroy(); + //$('#req-new-client-work-input').html(html); + //$(selector+" .check_who_work .who_work_tasks").val(who_work); + $(selector+" .check_who_work .who_work_tasks").fastselect({ + placeholder: 'Ответственный', + onItemCreate: function() { $(this).find('.fstQueryInput').hide() }, + }); + }*/ } } @@ -3454,7 +3460,7 @@ function show_advert_all(){ $('#checkdox_free_feed_all').prop('checked', true); $('#checkdox_jcat_feed_all').prop('checked', true); $('#checkdox_advert_all').prop('checked', true); - + //$('#cian_promo_price_all').val('').attr('disabled', 'disabled'); } @@ -3778,7 +3784,7 @@ $(document).ready(function() { if (ellada === '0' && agencyID != 8257 && agencyID != 7384 && agencyID != 11082 && agencyID != 11082 && agencyID != 12556 && agencyID != 13154 && agencyID != 14134 && agencyID != 11417 - && agencyID != 12028 && agencyID != 18237 && agencyID != 19111 + && agencyID != 12028 && agencyID != 18237 && agencyID != 19111 && agencyID != 19794 && agencyID != 22666) { if (agencyID == 8435 && funnel_id == 283) { @@ -4105,7 +4111,7 @@ $(document).ready(function() { save_client(params, funnel_id, poles); } /**/ - + } else { $('#addEditNew .load-bar').removeClass('hidden'); $('#newClient').addClass('hidden'); @@ -4113,61 +4119,61 @@ $(document).ready(function() { $.post('/ajax/addEditClient.php', params, function(data) { - // console.log(data); - // console.log(funnel_id); - if (data > 1) { - //console.log(funnel_id); - if ($('.view-kanban.active').length > 0) { - if (id && id !== undefined) { - if (funnel_id != 0) { - stage = $('#kanban_item_li_' + id).closest('.kanban__sortable').data("stage"); - //console.log(stage); - } - if(document.location.pathname == '/clients.php'){ - get_kanban_li(id, stage, priority); - // console.log(funnel_id); - let globalFunnel = $('#funnelIdClients').val(); - if(funnel_id != globalFunnel){ - $(`#kanban_item_li_${id}`).hide(); - get_count_clients(); + // console.log(data); + // console.log(funnel_id); + if (data > 1) { + //console.log(funnel_id); + if ($('.view-kanban.active').length > 0) { + if (id && id !== undefined) { + if (funnel_id != 0) { + stage = $('#kanban_item_li_' + id).closest('.kanban__sortable').data("stage"); + //console.log(stage); } + if(document.location.pathname == '/clients.php'){ + get_kanban_li(id, stage, priority); + // console.log(funnel_id); + let globalFunnel = $('#funnelIdClients').val(); + if(funnel_id != globalFunnel){ + $(`#kanban_item_li_${id}`).hide(); + get_count_clients(); + } + } + } else { + let sort_order = $('select[name=sort_order]').val(); + get_list(null, sort_order, false); } } else { let sort_order = $('select[name=sort_order]').val(); - get_list(null, sort_order, false); - } - } else { - let sort_order = $('select[name=sort_order]').val(); - if ($('.pagination li.active a').text()) { - get_list($('.pagination li.active a').text(), sort_order, false); - } else { - get_list(null, sort_order, false); - } - } - //Сохранение кастомных полей - - if (typeof client_fields != "undefined") { - client_fields.addEditFields(poles, data); - } - // console.log(id_reqs.split(',')); - if (id_reqs != '') { - if (document.location.pathname == '/requisitions.php') { - var reqs = id_reqs.split(','); - for (var req_id in reqs) { - if (!isNaN(parseInt(reqs[req_id]))) { - var req_client = requisitions.req['req' + reqs[req_id]]; - - if (req_client && !isEmpty(req_client.client)) { - requisitions.req['req' + reqs[req_id]].client.fio = fio; - } - } - + if ($('.pagination li.active a').text()) { + get_list($('.pagination li.active a').text(), sort_order, false); + } else { + get_list(null, sort_order, false); } - //requisitions.getList(); - //console.log() - //getClient(data, JSON.parse(id_reqs)[0]); } - axios.post('/ajax/ajax_vue_requisitions.php', { + //Сохранение кастомных полей + + if (typeof client_fields != "undefined") { + client_fields.addEditFields(poles, data); + } + // console.log(id_reqs.split(',')); + if (id_reqs != '') { + if (document.location.pathname == '/requisitions.php') { + var reqs = id_reqs.split(','); + for (var req_id in reqs) { + if (!isNaN(parseInt(reqs[req_id]))) { + var req_client = requisitions.req['req' + reqs[req_id]]; + + if (req_client && !isEmpty(req_client.client)) { + requisitions.req['req' + reqs[req_id]].client.fio = fio; + } + } + + } + //requisitions.getList(); + //console.log() + //getClient(data, JSON.parse(id_reqs)[0]); + } + axios.post('/ajax/ajax_vue_requisitions.php', { request: 'update_req', req_id: id_reqs, object_id: objects, @@ -4176,72 +4182,72 @@ $(document).ready(function() { }, ) - .then((response) => { - //console.log(response.data); - // var res = response.data; - // this.closeReqform(); + .then((response) => { + //console.log(response.data); + // var res = response.data; + // this.closeReqform(); - }) - .catch(function(error) { - console.log(error); - }); - } + }) + .catch(function(error) { + console.log(error); + }); + } - if (window.location.pathname == '/add-object.php') { + if (window.location.pathname == '/add-object.php') { - getSelectClients(data); - add_object_new_client_input_vue(data); + getSelectClients(data); + add_object_new_client_input_vue(data); - } + } - if (window.location.pathname == '/my-objects.php' || window.location.pathname == '/agency-objects.php') { + if (window.location.pathname == '/my-objects.php' || window.location.pathname == '/agency-objects.php') { - add_object_new_client_input_vue(data); + add_object_new_client_input_vue(data); - } + } - if ($('#client-history__bg').css("display") == 'block') { - - if(document.location.pathname == '/requisitions.php'){ - if(parseInt($("#client_history").attr("data-active-req")) == id){ + if ($('#client-history__bg').css("display") == 'block') { + + if(document.location.pathname == '/requisitions.php'){ + if(parseInt($("#client_history").attr("data-active-req")) == id){ + openClientEventsWindowNew(id, $('#session_to_send').val()); + } + } else { openClientEventsWindowNew(id, $('#session_to_send').val()); } - } else { - openClientEventsWindowNew(id, $('#session_to_send').val()); } - } - $('#send_bg_new').fadeOut(500); - $("#send_bg_new .edit-modal").toggle(10); - $("body").removeClass("lock"); - var komy = 0; - $('#komy option').each(function() { - if ($(this).val() == email) komy++; - }); - if (komy == 0) { - $('#komy').prepend(''); + $('#send_bg_new').fadeOut(500); + $("#send_bg_new .edit-modal").toggle(10); + $("body").removeClass("lock"); + var komy = 0; + $('#komy option').each(function() { + if ($(this).val() == email) komy++; + }); + if (komy == 0) { + $('#komy').prepend(''); + } + + if (typeof req_form == 'object') { + if (req_form.isClientForm) { + req_form.clientId = parseInt(data); + req_form.isClientForm = false; + req_form.openReqForm(1); + $('#req_form').removeAttr("style"); + } + } + $('#addEditNew .load-bar').addClass('hidden'); + $('#newClient').removeClass('hidden'); + } else { + $('#addEditNew .error_msg').html(data).show(); + //$('#addEditNew .error_msg').next().text('Клиент '+fio); + $('#addEditNew .modal-title').text('Клиент ' + fio); + $(".full_modal-bg").stop().animate({ scrollTop: 0 }, 500); + $('#addEditNew .load-bar').addClass('hidden'); + $('#newClient').removeClass('hidden'); } - if (typeof req_form == 'object') { - if (req_form.isClientForm) { - req_form.clientId = parseInt(data); - req_form.isClientForm = false; - req_form.openReqForm(1); - $('#req_form').removeAttr("style"); - } - } - $('#addEditNew .load-bar').addClass('hidden'); - $('#newClient').removeClass('hidden'); - } else { - $('#addEditNew .error_msg').html(data).show(); - //$('#addEditNew .error_msg').next().text('Клиент '+fio); - $('#addEditNew .modal-title').text('Клиент ' + fio); - $(".full_modal-bg").stop().animate({ scrollTop: 0 }, 500); - $('#addEditNew .load-bar').addClass('hidden'); - $('#newClient').removeClass('hidden'); - } - - }); + }); } } @@ -4312,6 +4318,7 @@ $(document).ready(function() { $('#liGlobal').removeClass('active'); $('#liIpoteka').removeClass('active'); $('#liCredit').removeClass('active'); + $('#liDeals').removeClass('active'); $('#liInnerDocs').removeClass('active'); $(this).addClass('active'); $('#addEditNew .tabs__content').hide(); @@ -4322,6 +4329,21 @@ $(document).ready(function() { }); + $('body').on('click', '#liDeals', function() { + $('#liObject').removeClass('active'); + $('#liGlobal').removeClass('active'); + $('#liIpoteka').removeClass('active'); + $('#liCredit').removeClass('active'); + $('#liReq').removeClass('active'); + $('#liInnerDocs').removeClass('active'); + $(this).addClass('active'); + $('#addEditNew .tabs__content').hide(); + $('#addEditNew .tabs__content:eq(5)').show(); + if (typeof deals_client == 'object') { + deals_client.getList(); + } + }); + $('body').on('click', '#liInnerDocs', function() { $('#liObject').removeClass('active'); $('#liGlobal').removeClass('active'); @@ -4413,15 +4435,15 @@ $(document).ready(function() { }); }); - + // Кнопка inssmart - $("body").on('click', '.openInssmartModule', () => { - $('#inssmart_modal').show(); + $("body").on('click', '.openInssmartModule', () => { + $('#inssmart_modal').show(); $('#inssmart_modal').css('zIndex', '99987000'); }); - - $("body").on('click', '.ti-close', () => { + + $("body").on('click', '.ti-close', () => { $("#inssmart_modal").hide(); }); @@ -4435,18 +4457,18 @@ $(document).ready(function() { $.post("/ajax/getFunnelFirst.php", function(dataf) { console.log(dataf); var res_funnels = JSON.parse(dataf); - - + + if(res_funnels.is_stage == 0){ - + $('#is_show_funnel_null').val(0); } else { $('#is_show_funnel_null').val(1); } - + }) - } + } var req_id = 0; if ($(this).attr("data-req")) { @@ -5075,7 +5097,7 @@ $(document).ready(function() { $('#filter_source').fastselect({ placeholder: 'Источник', onItemCreate: function(item, model) { - + if ($('#filter_source').find('option[value=' + model.value + ']').hasClass('bolt')) { $(item).addClass('bolt'); } @@ -5650,7 +5672,7 @@ $(document).ready(function() { } $('#popup__clients .closed_all').show(); $('.confirm__clients').show(); - + if ((document.location.pathname == '/sale.php' || document.location.pathname == '/main.php')) { console.log($("#popup__" + id + ' a').length); var show = false; @@ -5665,16 +5687,16 @@ $(document).ready(function() { $("#popup__" + id).toggleClass("show"); } } else { - + $("#popup__" + id).toggleClass("show"); if($('#user_allow_edit_all').length > 0 && $('#user_allow_edit_all').val() == 0){ - + if(document.location.pathname == '/requisitions.php' && id == 'reqs'){ if(typeof filtr !== undefined){ if(filtr.filtr.stages.ahency > 0){ $('.confirm__reqs').hide(); $('.closed_all').hide(); - } + } } } else if (document.location.pathname == '/clients.php' && id == 'clients'){ if($('#filter_work_ahency').length > 0 && $('#filter_work_ahency').hasClass('active')){ @@ -5685,7 +5707,7 @@ $(document).ready(function() { } else { if (document.location.pathname == '/clients.php' && id == 'clients'){ if($('#filter_work_ahency').length > 0 && $('#filter_work_ahency').hasClass('active')){ - + $('.closed_all').hide(); } } @@ -5755,7 +5777,7 @@ $(document).ready(function() { if ($(".view-kanban.active").length > 0) { $('.view-kanban').removeClass('active'); $('.view-list').addClass('active'); - + } window.history.pushState(null, null, "clients.php?funnelId=all"); $(".crm__filter-popup").addClass("is__hide").removeClass("is__show"); @@ -6329,10 +6351,10 @@ $(document).ready(function() { $("body").removeClass("lock"); if (confirm("При закрытии этого окна этап будет открыт!!!")) { axios.post('/ajax/ajax_vue_clients.php', { - request: 'openPrevStep', - client_id: id_client, - req_id: id_req, - }, ) + request: 'openPrevStep', + client_id: id_client, + req_id: id_req, + }, ) .then(function(response) { //console.log(response.data); ac.stepPrev = response.data; @@ -6533,6 +6555,9 @@ $(document).ready(function() { if (typeof requisitions_client == 'object') { requisitions_client.clientId = id; } + if (typeof deals_client == 'object') { + deals_client.clientId = id; + } //console.log(id); $('#liGlobal').removeClass('active').show(); $('#liObject').click(); @@ -7075,12 +7100,21 @@ $(document).ready(function() { var text = $(mainId + ' .tabs__content.call #callComment').val(); var date = $(mainId + ' .tabs__content.call #showDatetime').datepicker().val(); + + var users_id = $(mainId + ' .tabs__content.call .ms-crm-client-work').val(); + + // при редактировании (data-id задан и не 0) поле «Ответственный» скрыто и не меняется — не требуем его + var isEdit = $(this).attr("data-id") !== undefined && $(this).attr("data-id") !== '0'; + + $(mainId + ' .tabs__content.call #showDatetime').removeClass('invalid'); + $(mainId + ' .tabs__content.call .otvetstven').removeClass('invalid'); //console.log(date); - if (date && $.trim(date)) { + + if (date && $.trim(date) && (isEdit || !isEmpty(users_id))) { var id_client = $(mainId + ' .tabs__content.call .ms-big-add-client').val(); - var users_id = $(mainId + ' .tabs__content.call .ms-crm-client-work').val(); + var data = { - "client_id": JSON.stringify(id_client), + "client_id": (!isEmpty(id_client) ? JSON.stringify(id_client) : ''), "comment": text, "schedule_date": date, "users_id": JSON.stringify(users_id), @@ -7107,7 +7141,7 @@ $(document).ready(function() { method: "post", data: data, success: function(d) { - //console.log(data); + console.log(d); $("#addTaskBg").hide(); $("#addTask").hide(); $("#addEventBg").hide(); @@ -7117,6 +7151,14 @@ $(document).ready(function() { getCalendar(); } }); + } else { + if(isEmpty($.trim(date))){ + $(mainId + ' .tabs__content.call #showDatetime').addClass('invalid'); + } + + if(!isEdit && isEmpty(users_id)){ + $(mainId + ' .tabs__content.call .otvetstven').addClass('invalid'); + } } @@ -7133,13 +7175,21 @@ $(document).ready(function() { var date = $(mainId + ' .tabs__content.show #meetDatetime').datepicker().val(); + var users_id = $(mainId + ' .tabs__content.show .ms-crm-client-work').val(); + + // при редактировании (data-id задан и не 0) поле «Ответственный» скрыто и не меняется — не требуем его + var isEdit = $(this).attr("data-id") !== undefined && $(this).attr("data-id") !== '0'; + var address = $(mainId + ' .tabs__content.show #meetAddress').val(); + $(mainId + ' .tabs__content.show #meetDatetime').removeClass('invalid'); + $(mainId + ' .tabs__content.show .otvetstven').removeClass('invalid'); + //console.log(date); - if (date && $.trim(date)) { + if (date && $.trim(date) && (isEdit || !isEmpty(users_id))) { var id_client = $(mainId + ' .tabs__content.show .ms-big-add-client').val(); - var users_id = $(mainId + ' .tabs__content.show .ms-crm-client-work').val(); + var data = { - "client_id": JSON.stringify(id_client), + "client_id": (!isEmpty(id_client) ? JSON.stringify(id_client) : ''), "comment": text, "schedule_date": date, "users_id": JSON.stringify(users_id), @@ -7163,7 +7213,7 @@ $(document).ready(function() { url: '/ajax/addEventsCabinet.php', method: "post", data: data, - success: function(d) { + success: function(d) { $("#addTaskBg").hide(); $("#addTask").hide(); $("#addEventBg").hide(); @@ -7173,6 +7223,14 @@ $(document).ready(function() { getCalendar(); } }); + } else { + if(isEmpty($.trim(date))){ + $(mainId + ' .tabs__content.show #meetDatetime').addClass('invalid'); + } + + if(!isEdit && isEmpty(users_id)){ + $(mainId + ' .tabs__content.show .otvetstven').addClass('invalid'); + } } @@ -7189,13 +7247,21 @@ $(document).ready(function() { var date = $(mainId + ' .tabs__content.meet #meetDatetime').datepicker().val(); + var users_id = $(mainId + ' .tabs__content.meet .ms-crm-client-work').val(); + + // при редактировании (data-id задан и не 0) поле «Ответственный» скрыто и не меняется — не требуем его + var isEdit = $(this).attr("data-id") !== undefined && $(this).attr("data-id") !== '0'; + var address = $(mainId + ' .tabs__content.meet #meetAddress').val(); + + $(mainId + ' .tabs__content.meet #meetDatetime').removeClass('invalid'); + $(mainId + ' .tabs__content.meet .otvetstven').removeClass('invalid'); //console.log(date); - if (date && $.trim(date)) { + if (date && $.trim(date) && (isEdit || !isEmpty(users_id))) { var id_client = $(mainId + ' .tabs__content.meet .ms-big-add-client').val(); - var users_id = $(mainId + ' .tabs__content.meet .ms-crm-client-work').val(); + var data = { - "client_id": JSON.stringify(id_client), + "client_id": (!isEmpty(id_client) ? JSON.stringify(id_client) : ''), "comment": text, "schedule_date": date, "users_id": JSON.stringify(users_id), @@ -7227,6 +7293,14 @@ $(document).ready(function() { getCalendar(); } }); + } else { + if(isEmpty($.trim(date))){ + $(mainId + ' .tabs__content.meet #meetDatetime').addClass('invalid'); + } + + if(!isEdit && isEmpty(users_id)){ + $(mainId + ' .tabs__content.meet .otvetstven').addClass('invalid'); + } } return false; @@ -7241,13 +7315,21 @@ $(document).ready(function() { var date = $(mainId + ' .tabs__content.deal #dealDatetime').datepicker().val(); + var users_id = $(mainId + ' .tabs__content.deal .ms-crm-client-work').val(); + + // при редактировании (data-id задан и не 0) поле «Ответственный» скрыто и не меняется — не требуем его + var isEdit = $(this).attr("data-id") !== undefined && $(this).attr("data-id") !== '0'; + var sum = $(mainId + ' .tabs__content.deal #dealSum').val(); + + $(mainId + ' .tabs__content.deal #dealDatetime').removeClass('invalid'); + $(mainId + ' .tabs__content.deal .otvetstven').removeClass('invalid'); // console.log(date); - if (date && $.trim(date)) { + if (date && $.trim(date) && (isEdit || !isEmpty(users_id))) { var id_client = $(mainId + ' .tabs__content.deal .ms-big-add-client').val(); - var users_id = $(mainId + ' .tabs__content.deal .ms-crm-client-work').val(); + var data = { - "client_id": JSON.stringify(id_client), + "client_id": (!isEmpty(id_client) ? JSON.stringify(id_client) : ''), "comment": text, "schedule_date": date, "users_id": JSON.stringify(users_id), @@ -7280,6 +7362,14 @@ $(document).ready(function() { getCalendar(); } }); + } else { + if(isEmpty($.trim(date))){ + $(mainId + ' .tabs__content.deal #dealDatetime').addClass('invalid'); + } + + if(!isEdit && isEmpty(users_id)){ + $(mainId + ' .tabs__content.deal .otvetstven').addClass('invalid'); + } } return false; @@ -7296,12 +7386,20 @@ $(document).ready(function() { var date = $(mainId + ' .tabs__content.event #dealDatetime').datepicker().val(); var name = $(mainId + ' .tabs__content.event #eventName').val(); + + var users_id = $(mainId + ' .tabs__content.event .ms-crm-client-work').val(); + + // при редактировании (data-id задан и не 0) поле «Ответственный» скрыто и не меняется — не требуем его + var isEdit = $(this).attr("data-id") !== undefined && $(this).attr("data-id") !== '0'; + + $(mainId + ' .tabs__content.event #dealDatetime').removeClass('invalid'); + $(mainId + ' .tabs__content.event .otvetstven').removeClass('invalid'); //console.log(mainId); - if (date && $.trim(date)) { + if (date && $.trim(date) && (isEdit || !isEmpty(users_id) || !isEmpty($('#addTask .who_work_tasks').val()))) { var id_client = $(mainId + ' .tabs__content.event .ms-big-add-client').val(); - var users_id = $(mainId + ' .tabs__content.event .ms-crm-client-work').val(); + var data = { - "client_id": JSON.stringify(id_client), + "client_id": (!isEmpty(id_client) ? JSON.stringify(id_client) : ''), "comment": text, "schedule_date": date, "users_id": JSON.stringify(users_id), @@ -7334,7 +7432,7 @@ $(document).ready(function() { if($('#addTask .event .otvetstven1').is(":visible") && $('#addTask .who_work_tasks').val()){ data.who_work = $('#addTask .who_work_tasks').val(); } - console.log(data); + //console.log(data); $.ajax({ url: '/ajax/addEventsCabinet.php', @@ -7370,6 +7468,14 @@ $(document).ready(function() { }); } }); + } else { + if(isEmpty($.trim(date))){ + $(mainId + ' .tabs__content.event #dealDatetime').addClass('invalid'); + } + + if(!isEdit && isEmpty(users_id)){ + $(mainId + ' .tabs__content.event .otvetstven').addClass('invalid'); + } } return false; @@ -7559,9 +7665,9 @@ $(document).ready(function() { placeholder: 'Банк', }); - /* $('#ms-new-client-bank-issue').fastselect({ - placeholder: 'Банк выдачи', - });*/ + /* $('#ms-new-client-bank-issue').fastselect({ + placeholder: 'Банк выдачи', + });*/ /*$('#ms-new-client-bank-revisal').fastselect({ @@ -8123,31 +8229,31 @@ $(document).ready(function() { '0%' ); $('#fileupload').fileupload({ - url: url, - dataType: 'json', - done: function(e, data) { - console.log(data.result); - $.each(data.result.files, function(index, file) { - if (file.error) { - alert(file.error); - } else { - $('

    ').text(file.name).appendTo('#files'); - } - }); - $.post('/ajax/folders.php', { save_files: id_folder, files: JSON.stringify(data.result.files) }, function(data) { - // console.log(data); - get_folders(id_folder); - }); + url: url, + dataType: 'json', + done: function(e, data) { + console.log(data.result); + $.each(data.result.files, function(index, file) { + if (file.error) { + alert(file.error); + } else { + $('

    ').text(file.name).appendTo('#files'); + } + }); + $.post('/ajax/folders.php', { save_files: id_folder, files: JSON.stringify(data.result.files) }, function(data) { + // console.log(data); + get_folders(id_folder); + }); - }, - progressall: function(e, data) { - var progress = parseInt(data.loaded / data.total * 100, 10); - $('#progress .progress-bar').css( - 'width', - progress + '%' - ); - } - }).prop('disabled', !$.support.fileInput) + }, + progressall: function(e, data) { + var progress = parseInt(data.loaded / data.total * 100, 10); + $('#progress .progress-bar').css( + 'width', + progress + '%' + ); + } + }).prop('disabled', !$.support.fileInput) .parent().addClass($.support.fileInput ? undefined : 'disabled'); $('#files_upload').show(10); $('#file_upload').show(10); @@ -8207,13 +8313,13 @@ $(document).ready(function() { if(id == 0 && $(this).attr("data-stage") == 0){ $('.view-kanban').addClass('hidden'); if($('.view-kanban.active').length > 0){ - $('.view-kanban').removeClass('active'); - $('.view-list').addClass('active'); - } + $('.view-kanban').removeClass('active'); + $('.view-list').addClass('active'); + } } else { $('.view-kanban').removeClass('hidden'); } - + //requisitions.funnel_id = id; //requisitions.page = 1; get_list(); @@ -8269,7 +8375,7 @@ $(document).ready(function() { // Если первый этап доступен (main == 1), то открываем его if (firstMain == 1) { - $.post('/ajax/funnel_step_close.php', { 'step': firstStage, 'client': firstClient }, function(res) { + $.post('/ajax/funnel_step_close.php', { 'step': firstStage, 'client': firstClient, 'req': req }, function(res) { ac.closesStep = true; ac.step = JSON.parse(res); ac.clientId = firstClient; @@ -8307,7 +8413,7 @@ $(document).ready(function() { return; } - $.post('/ajax/funnel_step_close.php', { 'step': stage, 'client': client }, function(res) { + $.post('/ajax/funnel_step_close.php', { 'step': stage, 'client': client, 'req': req }, function(res) { ac.closesStep = true; ac.step = JSON.parse(res); ac.clientId = client; @@ -8328,7 +8434,7 @@ $(document).ready(function() { var nextReq = $nextStep.attr("data-req"); var nextAdjacent = $nextStep.attr("data-adjacent"); - $.post('/ajax/funnel_step_close.php', { 'step': nextStage, 'client': nextClient }, function(res) { + $.post('/ajax/funnel_step_close.php', { 'step': nextStage, 'client': nextClient, 'req': req }, function(res) { ac.closesStep = true; ac.step = JSON.parse(res); ac.clientId = nextClient; @@ -8543,9 +8649,9 @@ $(document).ready(function() { clientsId.push('all'); } - $("#del_client_all").find('input[name="id_del_clients"]').val(JSON.stringify(clientsId)); - $("#del_client_all").find('input[name="id_del_reqs"]').val(0); - open_confirmation__req_client('client', 'close_all', ''); + $("#del_client_all").find('input[name="id_del_clients"]').val(JSON.stringify(clientsId)); + $("#del_client_all").find('input[name="id_del_reqs"]').val(0); + open_confirmation__req_client('client', 'close_all', ''); } } else { @@ -8558,9 +8664,9 @@ $(document).ready(function() { } - $("#del_client_all").find('input[name="id_del_clients"]').val(0); - $("#del_client_all").find('input[name="id_del_reqs"]').val(JSON.stringify(reqsId)); - open_confirmation__req_client('req', 'close_all', ''); + $("#del_client_all").find('input[name="id_del_clients"]').val(0); + $("#del_client_all").find('input[name="id_del_reqs"]').val(JSON.stringify(reqsId)); + open_confirmation__req_client('req', 'close_all', ''); } } @@ -8592,13 +8698,13 @@ $(document).ready(function() { alert("Нет выбранных клиентов"); } else { - open_confirmation__req_client('client', 'renew_all', ''); + open_confirmation__req_client('client', 'renew_all', ''); //renewClients(clientsId); } } else { - open_confirmation__req_client('client', 'renew_all', ''); + open_confirmation__req_client('client', 'renew_all', ''); } @@ -8827,7 +8933,7 @@ $(document).ready(function() { $("body").on('input', '.change_cian_bet', function(e) { var object_id = this.getAttribute('data-id'); - // console.log(object_id); + // console.log(object_id); if (!is_change_cian_bet) { is_change_cian_bet = true; @@ -8865,7 +8971,7 @@ $(document).ready(function() { $("body").on('input', '.change_price', function(e) { var object_id = this.getAttribute('data-id'); - // console.log(object_id); + // console.log(object_id); var place = $(this).attr('data-place'); console.log(place); if (!is_change_price) { @@ -9159,7 +9265,7 @@ $(document).ready(function() { } else { $(`.commission--agency--${data.id}`).html( - new Intl.NumberFormat('ru-RU').format(price) + ' ' + currency + '' + new Intl.NumberFormat('ru-RU').format(price) + ' ' + currency + '' ) } }, @@ -9171,7 +9277,7 @@ $(document).ready(function() { $('body').on('click', '#edit_expected_commission_req', function(){ - + $('#edit_expected_commission_req').hide(); $('#edit_expected_commission_req_input').show(); $('#edit_expected_commission_req_save').show(); @@ -9181,24 +9287,24 @@ $(document).ready(function() { let req_id = $(this).attr("data-id"); let value = $('#edit_expected_commission_req_input').val(); axios.post('/ajax/ajax_vue_requisitions.php', { - request: 'edit_req_finance_info', - field: 'expected_commission', - user_id: $('#session_user_id').val(), - req_id: req_id, - value: value - }) - .then(function(response) { - console.log(response.data); - get_finance_info(req_id); - }) - .catch(function(error) { - consle.error(error); - }); - //get_finance_info(req_id); + request: 'edit_req_finance_info', + field: 'expected_commission', + user_id: $('#session_user_id').val(), + req_id: req_id, + value: value + }) + .then(function(response) { + console.log(response.data); + get_finance_info(req_id); + }) + .catch(function(error) { + consle.error(error); + }); + //get_finance_info(req_id); }) $('body').on('click', '#edit_deposit_req', function(){ - + $('#edit_deposit_req').hide(); $('#edit_deposit_req_input').show(); $('#edit_deposit_req_save').show(); @@ -9209,28 +9315,28 @@ $(document).ready(function() { let value = $('#edit_deposit_req_input').val(); let deposit_id = $(this).attr("data-deposit"); axios.post('/ajax/ajax_vue_requisitions.php', { - request: 'edit_req_finance_info', - field: 'deposit', - user_id: $('#session_user_id').val(), - req_id: req_id, - value: value, - deposit_id: deposit_id - }) - .then(function(response) { - console.log(response.data); - get_finance_info(req_id); - }) - .catch(function(error) { - consle.error(error); - }); - //get_finance_info(req_id); + request: 'edit_req_finance_info', + field: 'deposit', + user_id: $('#session_user_id').val(), + req_id: req_id, + value: value, + deposit_id: deposit_id + }) + .then(function(response) { + console.log(response.data); + get_finance_info(req_id); + }) + .catch(function(error) { + consle.error(error); + }); + //get_finance_info(req_id); }) $('body').on('click', '#toggle_block_expenses', function(){ console.log($('#div_toggle_block_expenses').css('display')); if($('#div_toggle_block_expenses').css('display') == 'none') $('#div_toggle_block_expenses').show(); - else + else $('#div_toggle_block_expenses').hide(); }) @@ -9245,26 +9351,26 @@ $(document).ready(function() { $('body').on('click', '.edit_expense_req_save', function(){ let req_id = $(this).attr("data-id"); - + let expense_id = $(this).attr("data-expense"); let value = $('#edit_expense_req_input_'+expense_id).val(); let comment = $('#edit_expense_req_textarea_'+expense_id).val(); axios.post('/ajax/ajax_vue_requisitions.php', { - request: 'edit_req_finance_info', - field: 'expense', - user_id: $('#session_user_id').val(), - req_id: req_id, - value: value, - comment: comment, - expense_id: expense_id - }) - .then(function(response) { - console.log(response.data); - get_finance_info(req_id); - }) - .catch(function(error) { - consle.error(error); - }); + request: 'edit_req_finance_info', + field: 'expense', + user_id: $('#session_user_id').val(), + req_id: req_id, + value: value, + comment: comment, + expense_id: expense_id + }) + .then(function(response) { + console.log(response.data); + get_finance_info(req_id); + }) + .catch(function(error) { + consle.error(error); + }); }) @@ -9308,12 +9414,12 @@ function view_changer_client(view){ axios.post('/ajax/ajax_vue_clients.php', { request: 'set_view_page', view: view, - }, ).then((response) => { - console.log(response.data); - //this.steps = response.data; - }).catch(function(error) { - console.error(error); - }) + }, ).then((response) => { + console.log(response.data); + //this.steps = response.data; + }).catch(function(error) { + console.error(error); + }) } } @@ -9589,7 +9695,7 @@ $(document).ready(function() { $('body').on('click', '.openClientReqBind', function() { if(typeof client_req_bind === 'object'){ let objectId = $(this).closest('.object_clients').attr("data-oid"); - + client_req_bind.objectId = parseInt(objectId); client_req_bind.open(); } @@ -9711,29 +9817,29 @@ function editPartner(id, form) { } //if (data.show_complexes == 1){ - $(form).find('[name="show_complexes"]').prop('checked', true); - $('#ms-new-client-work-partner-input').closest('.form-block').show(); - $('#ms-new-funnel-partner-input').closest('.form-block').show(); - $('#ms-new-client-work-client-partner-input').closest('.form-block').show(); - $('#ms-new-funnel-client-partner-input').closest('.form-block').show(); - var who_user, who_user_client = $('#session_user_id').val(); - var funnel_id, funnel_id_client = 0; - if(!isEmpty(data.funnel_id_req)){ - funnel_id = data.funnel_id_req; - } - if(!isEmpty(data.who_work_req)){ - who_user = data.who_work_req; - } - if(!isEmpty(data.funnel_id_client)){ - funnel_id_client = data.funnel_id_client; - } - if(!isEmpty(data.who_work_client)){ - who_user_client = data.who_work_client; - } - setSelectsFastselect('ms-new-client-work-partner', who_user, 'select_form_client-work.php', 'Ответственный'); - setSelectsFastselect('ms-new-funnel-partner', funnel_id, 'select_form_funnel.php', 'Воронка', 'req'); - setSelectsFastselect('ms-new-client-work-client-partner', who_user_client, 'select_form_client-work.php', 'Ответственный'); - setSelectsFastselect('ms-new-funnel-client-partner', funnel_id_client, 'select_form_funnel.php', 'Воронка', 'client'); + $(form).find('[name="show_complexes"]').prop('checked', true); + $('#ms-new-client-work-partner-input').closest('.form-block').show(); + $('#ms-new-funnel-partner-input').closest('.form-block').show(); + $('#ms-new-client-work-client-partner-input').closest('.form-block').show(); + $('#ms-new-funnel-client-partner-input').closest('.form-block').show(); + var who_user, who_user_client = $('#session_user_id').val(); + var funnel_id, funnel_id_client = 0; + if(!isEmpty(data.funnel_id_req)){ + funnel_id = data.funnel_id_req; + } + if(!isEmpty(data.who_work_req)){ + who_user = data.who_work_req; + } + if(!isEmpty(data.funnel_id_client)){ + funnel_id_client = data.funnel_id_client; + } + if(!isEmpty(data.who_work_client)){ + who_user_client = data.who_work_client; + } + setSelectsFastselect('ms-new-client-work-partner', who_user, 'select_form_client-work.php', 'Ответственный'); + setSelectsFastselect('ms-new-funnel-partner', funnel_id, 'select_form_funnel.php', 'Воронка', 'req'); + setSelectsFastselect('ms-new-client-work-client-partner', who_user_client, 'select_form_client-work.php', 'Ответственный'); + setSelectsFastselect('ms-new-funnel-client-partner', funnel_id_client, 'select_form_funnel.php', 'Воронка', 'client'); //} if (data.instagram) @@ -9756,14 +9862,14 @@ function editPartner(id, form) { $(form).find('#partner_files_list').empty(); data.files.forEach(function(file, indx) { let file_html = - '

  • ' + + '
  • ' + '' + ' ' + file.filename + '' + '' + ' ' + '' + '' + - '
  • '; + ''; $(form).find('#partner_files_list').append($(file_html)); }); } @@ -10139,14 +10245,14 @@ $(document).on('click', '#addNewPartner .delFile, #addNewEmployee .delFile', fun var $btn = $(this); var id = $btn.data('id'); if (!id) return; - $.get('/ajax/delPartnerFile.php', { id: id }, function (results) { + $.get('/ajax/delPartnerFile.php', { id: id }, function (results) { var data = null; - try { data = JSON.parse(results); } catch (e) {} + try { data = JSON.parse(results); } catch (e) {} - if (data === true || (data && data.ok === true)) { - $btn.closest('li.file').remove(); - } - }); + if (data === true || (data && data.ok === true)) { + $btn.closest('li.file').remove(); + } + }); }); $(document).delegate('#addNewPartner input[name="phone"], #addNewEmployee input[name="phone"]', 'change', function(event) { @@ -10488,137 +10594,181 @@ function save_client(params, funnel_id, poles){ params, function(data) { // console.log(data); - + if (data > 1) { - //console.log(funnel_id); - if ($('.view-kanban.active').length > 0) { - if (typeof id != 'undefined') { - if (funnel_id != 0) { - stage = $('#kanban_item_li_' + id).closest('.kanban__sortable').data("stage"); - //console.log(stage); - } - if(document.location.pathname == '/clients.php'){ - get_kanban_li(id, stage, priority); - // console.log(funnel_id); - let globalFunnel = $('#funnelIdClients').val(); - if(funnel_id != globalFunnel){ - $(`#kanban_item_li_${id}`).hide(); - get_count_clients(); - } - } - } else { - let sort_order = $('select[name=sort_order]').val(); - get_list(null, sort_order, false); - } - } else { - let sort_order = $('select[name=sort_order]').val(); - if ($('.pagination li.active a').text()) { - get_list($('.pagination li.active a').text(), sort_order, false); - } else { - get_list(null, sort_order, false); + //console.log(funnel_id); + if ($('.view-kanban.active').length > 0) { + if (typeof id != 'undefined') { + if (funnel_id != 0) { + stage = $('#kanban_item_li_' + id).closest('.kanban__sortable').data("stage"); + //console.log(stage); + } + if(document.location.pathname == '/clients.php'){ + get_kanban_li(id, stage, priority); + // console.log(funnel_id); + let globalFunnel = $('#funnelIdClients').val(); + if(funnel_id != globalFunnel){ + $(`#kanban_item_li_${id}`).hide(); + get_count_clients(); } } - //Сохранение кастомных полей - - if (typeof client_fields != "undefined") { - client_fields.addEditFields(poles, data); - } - // console.log(id_reqs.split(',')); - if (params.id_reqs != '') { - if (document.location.pathname == '/requisitions.php') { - var reqs = params.id_reqs.split(','); - for (var req_id in reqs) { - if (!isNaN(parseInt(reqs[req_id]))) { - var req_client = requisitions.req['req' + reqs[req_id]]; - - if (req_client && !isEmpty(req_client.client)) { - requisitions.req['req' + reqs[req_id]].client.fio = fio; - } - } - - } - //requisitions.getList(); - //console.log() - //getClient(data, JSON.parse(id_reqs)[0]); - } - axios.post('/ajax/ajax_vue_requisitions.php', { - request: 'update_req', - req_id: params.id_reqs, - object_id: params.objects, - client_id: data, - - }, - - ) - .then((response) => { - //console.log(response.data); - // var res = response.data; - // this.closeReqform(); - - - }) - .catch(function(error) { - console.log(error); - }); - } - - if (window.location.pathname == '/add-object.php') { - - getSelectClients(data); - add_object_new_client_input_vue(data); - - } - - if (window.location.pathname == '/my-objects.php' || window.location.pathname == '/agency-objects.php') { - - add_object_new_client_input_vue(data); - - } - - if ($('#client-history__bg').css("display") == 'block') { - - if(document.location.pathname == '/requisitions.php'){ - if(parseInt($("#client_history").attr("data-active-req")) == id){ - openClientEventsWindowNew(id, $('#session_to_send').val()); - } - } else { - openClientEventsWindowNew(id, $('#session_to_send').val()); - } - } - $('#send_bg_new').fadeOut(500); - $("#send_bg_new .edit-modal").toggle(10); - $("body").removeClass("lock"); - var komy = 0; - $('#komy option').each(function() { - if ($(this).val() == params.email) komy++; - }); - if (komy == 0) { - $('#komy').prepend(''); - } - - if (typeof req_form == 'object') { - if (req_form.isClientForm) { - req_form.clientId = parseInt(data); - req_form.isClientForm = false; - req_form.openReqForm(1); - $('#req_form').removeAttr("style"); - } - } - $('#addEditNew .load-bar').addClass('hidden'); - $('#newClient').removeClass('hidden'); } else { - $('#addEditNew .error_msg').html(data).show(); - //$('#addEditNew .error_msg').next().text('Клиент '+fio); - $('#addEditNew .modal-title').text('Клиент ' + fio); - $(".full_modal-bg").stop().animate({ scrollTop: 0 }, 500); - $('#addEditNew .load-bar').addClass('hidden'); - $('#newClient').removeClass('hidden'); + let sort_order = $('select[name=sort_order]').val(); + get_list(null, sort_order, false); } + } else { + let sort_order = $('select[name=sort_order]').val(); + if ($('.pagination li.active a').text()) { + get_list($('.pagination li.active a').text(), sort_order, false); + } else { + get_list(null, sort_order, false); + } + } + //Сохранение кастомных полей + if (typeof client_fields != "undefined") { + client_fields.addEditFields(poles, data); + } + // console.log(id_reqs.split(',')); + if (params.id_reqs != '') { + if (document.location.pathname == '/requisitions.php') { + var reqs = params.id_reqs.split(','); + for (var req_id in reqs) { + if (!isNaN(parseInt(reqs[req_id]))) { + var req_client = requisitions.req['req' + reqs[req_id]]; + + if (req_client && !isEmpty(req_client.client)) { + requisitions.req['req' + reqs[req_id]].client.fio = fio; + } + } + + } + //requisitions.getList(); + //console.log() + //getClient(data, JSON.parse(id_reqs)[0]); + } + axios.post('/ajax/ajax_vue_requisitions.php', { + request: 'update_req', + req_id: params.id_reqs, + object_id: params.objects, + client_id: data, + + }, + + ) + .then((response) => { + //console.log(response.data); + // var res = response.data; + // this.closeReqform(); + + + }) + .catch(function(error) { + console.log(error); + }); + } + + if (window.location.pathname == '/add-object.php') { + + getSelectClients(data); + add_object_new_client_input_vue(data); + + } + + if (window.location.pathname == '/my-objects.php' || window.location.pathname == '/agency-objects.php') { + + add_object_new_client_input_vue(data); + + } + + if ($('#client-history__bg').css("display") == 'block') { + + if(document.location.pathname == '/requisitions.php'){ + if(parseInt($("#client_history").attr("data-active-req")) == id){ + openClientEventsWindowNew(id, $('#session_to_send').val()); + } + } else { + openClientEventsWindowNew(id, $('#session_to_send').val()); + } + } + $('#send_bg_new').fadeOut(500); + $("#send_bg_new .edit-modal").toggle(10); + $("body").removeClass("lock"); + var komy = 0; + $('#komy option').each(function() { + if ($(this).val() == params.email) komy++; }); + if (komy == 0) { + $('#komy').prepend(''); + } + + if (typeof req_form == 'object') { + if (req_form.isClientForm) { + req_form.clientId = parseInt(data); + req_form.isClientForm = false; + req_form.openReqForm(1); + $('#req_form').removeAttr("style"); + } + } + $('#addEditNew .load-bar').addClass('hidden'); + $('#newClient').removeClass('hidden'); + } else { + $('#addEditNew .error_msg').html(data).show(); + //$('#addEditNew .error_msg').next().text('Клиент '+fio); + $('#addEditNew .modal-title').text('Клиент ' + fio); + $(".full_modal-bg").stop().animate({ scrollTop: 0 }, 500); + $('#addEditNew .load-bar').addClass('hidden'); + $('#newClient').removeClass('hidden'); + } + + }); +} + +/** + * hide_client_contacts: переключает состояние полей контактов клиента в модалке #send_new. + * + * Модалка #send_new / #addEditNew используется и для создания нового клиента (add_client_new), + * и для редактирования существующего (editClientNew). PHP-рендер задаёт статически disabled+warning + * для hide-юзера — это корректно для edit, но мешает create. Здесь динамически переключаем. + * + * mode='add' → enable полей email/phone/national_phone, hide warning, навешиваем phoneMask + * mode='edit' → если hide-юзер: disable полей + show warning + снимаем phoneMask (значение пишется + * "+X *** *** ** **", плагин маски его сломал бы). + * + * Зависит от window.shouldHideContacts() (см. js/contacts_visibility.js). + */ +function setAddEditNewContactsState(mode) { + var isHide = (typeof window.shouldHideContacts === 'function') && window.shouldHideContacts(); + if (!isHide) return; // обычным юзерам нечего переключать — PHP отрендерил всё открытым + var $email = $('#addEditNew [name="email"]'); + var $phone = $('#addEditNew #phoneClient'); + var $natPh = $('#addEditNew [name="national_phone"]'); + var $warning = $('#hideContactsWarning'); + var disabledTitle = 'Контакты клиента скрыты для вашей учётной записи'; + if (mode === 'add') { + $email.prop('disabled', false).removeAttr('title'); + $phone.prop('disabled', false).removeAttr('title'); + $natPh.prop('disabled', false); + $warning.hide(); + // навешиваем jQuery-маску +7 для ручного ввода в новой форме + if (!$phone.hasClass('phoneMask')) { + $phone.addClass('phoneMask'); + } + try { $phone.unmask(); } catch (e) {} + $phone.mask('+79999999999'); + } else { // mode === 'edit' + $email.prop('disabled', true).attr('title', disabledTitle); + $phone.prop('disabled', true).attr('title', disabledTitle); + $natPh.prop('disabled', true); + $warning.show(); + // снимаем маску, чтобы серверное "+X *** *** ** **" не превратилось в "+7" + try { $phone.unmask(); } catch (e) {} + $phone.removeClass('phoneMask'); + } } function add_client_new(object, add_user, req_id, client_name) { + setAddEditNewContactsState('add'); if (req_id) { if (typeof req_form == 'object') { $('#req_form').css('zIndex', '99987'); @@ -10768,10 +10918,10 @@ function add_client_new(object, add_user, req_id, client_name) { //console.log(dataf); var res_funnels = JSON.parse(dataf); //if (funnel_id === undefined) - funnel_id = parseInt(res_funnels.funnel_id); - + funnel_id = parseInt(res_funnels.funnel_id); + if(res_funnels.is_stage == 0){ - + $('#is_show_funnel_null').val(0); } else { $('#is_show_funnel_null').val(1); @@ -10837,7 +10987,7 @@ function add_client_new(object, add_user, req_id, client_name) { } ); - + $('#addEditNew #confirm').val("0"); $('#addEditNew .error_msg').hide(); $('#addEditNew .modal-title').text('Новый клиент'); @@ -10856,21 +11006,21 @@ function setSelectsFastselect(selector, value, ajaxScript, name, section) { $('#filter_charts_funnel-input').html(''); } //if ($('#' + selector).length < 1) { - axios.post('/ajax/' + ajaxScript, - params, - ) - .then((response) => { + axios.post('/ajax/' + ajaxScript, + params, + ) + .then((response) => { - $('#' + selector + '-input').html(response.data); - if (value) { - $("#" + selector).val(value); - } - setFastselectPost(selector, name); - setSelectPost(selector); - }) - .catch(function(error) { - console.log(error); - }); + $('#' + selector + '-input').html(response.data); + if (value) { + $("#" + selector).val(value); + } + setFastselectPost(selector, name); + setSelectPost(selector); + }) + .catch(function(error) { + console.log(error); + }); /*} else { $('#' + selector).fastselect().data('fastselect').destroy(); @@ -10887,31 +11037,31 @@ function setSelectsFastselect(selector, value, ajaxScript, name, section) { function setSelectPost(selector) { switch (selector) { case 'ms-new-funnel': - { - console.log($("#" + selector).val()); - if ($("#" + selector).val() > 0) { - $('#addEditNew .stepsTable').hide(); - } else { - if ($("#" + selector).val() == 0) { - if($('#is_show_funnel_null').val() > 0){ - $('#addEditNew .stepsTable').show(); - } else { - $('#addEditNew .stepsTable').hide(); - } + { + console.log($("#" + selector).val()); + if ($("#" + selector).val() > 0) { + $('#addEditNew .stepsTable').hide(); + } else { + if ($("#" + selector).val() == 0) { + if($('#is_show_funnel_null').val() > 0){ + $('#addEditNew .stepsTable').show(); + } else { + $('#addEditNew .stepsTable').hide(); } } - break; } + break; + } case 'ms-new-client-partner': - { - let partner_label = $("#" + selector + " option:selected").data("label"); - if (partner_label) - $("#" + selector).closest(".inputs").find(".fstToggleBtn").text(partner_label); + { + let partner_label = $("#" + selector + " option:selected").data("label"); + if (partner_label) + $("#" + selector).closest(".inputs").find(".fstToggleBtn").text(partner_label); - $("#" + selector).closest(".inputs").find(".fstControls input.hidenClass").attr('type', "text"); - $("#" + selector).closest(".inputs").find(".fstControls input.hidenClass").removeClass('hidenClass'); - break; - } + $("#" + selector).closest(".inputs").find(".fstControls input.hidenClass").attr('type', "text"); + $("#" + selector).closest(".inputs").find(".fstControls input.hidenClass").removeClass('hidenClass'); + break; + } } } @@ -10920,63 +11070,63 @@ function setSelectPost(selector) { function setFastselectPost(selector, name) { switch (selector) { case 'ms-new-client-work': - { - $('#' + selector).fastselect({ - placeholder: name, - onItemCreate: function() { $(this).find('.fstQueryInput').hide() }, - onItemSelect: function() { - $('#addEditNew [name=confirm]').val("0"); - } - }); - break; - } + { + $('#' + selector).fastselect({ + placeholder: name, + onItemCreate: function() { $(this).find('.fstQueryInput').hide() }, + onItemSelect: function() { + $('#addEditNew [name=confirm]').val("0"); + } + }); + break; + } case 'ms-new-client-partner': - { - $("#ms-new-client-partner").fastselect({ - placeholder: name, - onItemCreate: function($item, itemModel) { - let partner_name = $("#" + selector + " option[value=" + itemModel.value + "]").data('partner'); - itemModel.text = itemModel.text + ' '; + { + $("#ms-new-client-partner").fastselect({ + placeholder: name, + onItemCreate: function($item, itemModel) { + let partner_name = $("#" + selector + " option[value=" + itemModel.value + "]").data('partner'); + itemModel.text = itemModel.text + ' '; - $(this).find(".fstControls input.hidenClass").attr('type', "text"); - $(this).find(".fstControls input.hidenClass").removeClass('hidenClass'); - }, - onItemSelect: function($item, itemModel) { - console.log($item, itemModel); + $(this).find(".fstControls input.hidenClass").attr('type', "text"); + $(this).find(".fstControls input.hidenClass").removeClass('hidenClass'); + }, + onItemSelect: function($item, itemModel) { + console.log($item, itemModel); - let partner_label = $("#" + selector + " option:selected").data("label"); - if (partner_label) - $("#" + selector).closest(".inputs").find(".fstToggleBtn").text(partner_label); + let partner_label = $("#" + selector + " option:selected").data("label"); + if (partner_label) + $("#" + selector).closest(".inputs").find(".fstToggleBtn").text(partner_label); - $(this).find(".fstControls input.hidenClass").attr('type', "text"); - $(this).find(".fstControls input.hidenClass").removeClass('hidenClass'); - } - }); - break; - } + $(this).find(".fstControls input.hidenClass").attr('type', "text"); + $(this).find(".fstControls input.hidenClass").removeClass('hidenClass'); + } + }); + break; + } case 'filter_charts_funnel': - { - $('#' + selector).fastselect({ - placeholder: name, - onItemSelect: function() { - show_options_search_charts(); - //get_sourse_filter(); - }, - onItemDelete: function() { - show_options_search_charts(); - //get_sourse_filter(); - } - }); - break; - } + { + $('#' + selector).fastselect({ + placeholder: name, + onItemSelect: function() { + show_options_search_charts(); + //get_sourse_filter(); + }, + onItemDelete: function() { + show_options_search_charts(); + //get_sourse_filter(); + } + }); + break; + } default: - { - $('#' + selector).fastselect({ - placeholder: name, + { + $('#' + selector).fastselect({ + placeholder: name, - }); - break; - } + }); + break; + } } } @@ -11105,7 +11255,7 @@ function funnelClients(clientsId) { method: "post", data: { "clientsId": clientsId, - + }, success: function(data) { $("#funnel__user_bg").html(data); @@ -11238,20 +11388,20 @@ function openChangeTags(id) { let instance = popup.attr('data-for'); let tagsView = $('.jw__object.item#item' + id + ' .tags .tags-title'); let poapTagsView = $(`.jw__object.item#item${id} #popup__tags_list_${id} .inputs`); - + if (instance == "clients"){ tagsView = $('.client#client__' + id + ' .tags .tags-title'); poapTagsView = $(`.client#client__${id} #popup__tags_list_${id} .inputs`); } - + let activities = tagsList.val(); - + $.post('/ajax/addActivities.php', { id: id, activities: activities, instance: instance }, function(data) { - + let result = JSON.parse(data); if (result.length > 0) { tagsView.empty(); @@ -11263,62 +11413,62 @@ function openChangeTags(id) { if (result[i]['id'] && result[i]['name']) { let htmlTag = ''; - if(i<3){ - htmlTag += '
    ' + - '' + - ''+result[i]['name']+'
    ' + - '
    '; - } - htmlPoup += ' data-id="'+result[i]['id']+'">'+result[i]['name']+'
    ' + - ''; - if(i<3){ - tagsView.append(htmlTag); - tags_visible++; - } - - poapTagsView.append(htmlPoup); - + if(!isEmpty(result[i]['color'])) { + if(i<3){ + htmlTag += '; border: solid 1px '+ result[i]['color']; + } + htmlPoup += 'style="border: solid 1px '+ result[i]['color']+'"'; + } + if(i<3){ + htmlTag +='">' + + '
    ' + + '' + + ''+result[i]['name']+'
    ' + + ''; + } + htmlPoup += ' data-id="'+result[i]['id']+'">'+result[i]['name']+'' + + ''; + if(i<3){ + tagsView.append(htmlTag); + tags_visible++; + } + + + poapTagsView.append(htmlPoup); + + - } tag_key++; } @@ -11326,13 +11476,13 @@ function openChangeTags(id) { if((tags_visible) < result.length){ let rest_tags = result.length - tags_visible; htmlTag = '
    '+ - '
    и ещё '+rest_tags+' шт.
    '+ - '
    '; + '
    и ещё '+rest_tags+' шт.
    '+ + ''; tagsView.append(htmlTag); } - $('.jw__object.item#item' + id + ' .tags').removeClass('hidden'); - $('.client#client__' + id + ' .tags').removeClass('hidden'); + $('.jw__object.item#item' + id + ' .tags').removeClass('hidden'); + $('.client#client__' + id + ' .tags').removeClass('hidden'); } else { tagsView.empty(); $('.jw__object.item#item' + id + ' .tags').addClass('hidden'); @@ -11398,10 +11548,10 @@ function get_contracts_client(client_id) { $("#list_contracts_client_form").html(''); if (client_id > 0) { axios.post('/ajax/ajax_vue_requisitions.php', { - request: 'get_contracts', - parent_id: client_id, - type: 'client', - }, ) + request: 'get_contracts', + parent_id: client_id, + type: 'client', + }, ) .then((response) => { var res = response.data; @@ -11475,11 +11625,11 @@ function bindObjReq(clientId) { if (object_id > 0) { axios.post('/ajax/ajax_vue_requisitions.php', { - request: 'check_object', - agency_id: $('#session_agency_id').val(), - object_id: object_id, - req_id: $('#object-new-client-req [name=sobstv_object_req]').val(), - }) + request: 'check_object', + agency_id: $('#session_agency_id').val(), + object_id: object_id, + req_id: $('#object-new-client-req [name=sobstv_object_req]').val(), + }) .then((response) => { //console.log(response.data); var res = response.data; @@ -11679,16 +11829,16 @@ function open_confirmation__req_client(razdel, event, selector, confirm_obj=null razdel: razdel, ids_exception: ids, }, ) - .then((response) => { - console.log(response.data); - total_item = response.data; - $('#confirmation__req_client .total_item').text(total_item); - $('#confirmation__req_client .loader').hide(); - $('#confirmation__req_client .no-loader').show(); - }) - .catch(function(error) { - console.log(error); - }); + .then((response) => { + console.log(response.data); + total_item = response.data; + $('#confirmation__req_client .total_item').text(total_item); + $('#confirmation__req_client .loader').hide(); + $('#confirmation__req_client .no-loader').show(); + }) + .catch(function(error) { + console.log(error); + }); } @@ -11743,7 +11893,7 @@ function yes_confirmation(){ var event = $('#confirmation__req_client .yes_confirmation').attr('data-event'); var selector = $('#confirmation__req_client .yes_confirmation').attr('data-selectort'); var confirm_obj = $('#confirmation__req_client .yes_confirmation').attr('data-confirm-obj'); - + console.log(razdel); console.log(event); @@ -11882,14 +12032,14 @@ function yes_confirmation(){ } else { console.log(reqsId); - requisitions.renewReqs(reqsId); + requisitions.renewReqs(reqsId); } } else { var user_id = $('#session_user_id').val(); - requisitions.renewReqs(reqsId); + requisitions.renewReqs(reqsId); } @@ -11919,7 +12069,7 @@ function yes_confirmation(){ } } else { - renewClients(clientsId); + renewClients(clientsId); } } @@ -11984,10 +12134,10 @@ function save_key_telegramm(){ var key = $("#key_telegramm").val(); var user_id = $('#session_user_id').val(); axios.post('/ajax/ajax_vue_settings.php', { - request: 'save_key_telegramm', - key_telegramm: key, - user_id: user_id, - }) + request: 'save_key_telegramm', + key_telegramm: key, + user_id: user_id, + }) .then(function(response) { alert("Код сохранен"); @@ -12001,10 +12151,10 @@ function save_key_max(){ var key = $("#key_max").val(); var user_id = $('#session_user_id').val(); axios.post('/ajax/ajax_vue_settings.php', { - request: 'save_key_max', - key_max: key, - user_id: user_id, - }) + request: 'save_key_max', + key_max: key, + user_id: user_id, + }) .then(function(response) { alert("Код сохранен"); @@ -12051,9 +12201,9 @@ const defaultParams = { hasFocusClass: 'has-focus', isDisabledClass: 'is-disabled', isOpenClass: 'is-open', - }; +}; - function builder(el, builderParams) { +function builder(el, builderParams) { const containerClass = 'customSelect'; let isOpen = false; let uId = ''; @@ -12074,229 +12224,229 @@ const defaultParams = { // Sets the focused element with the neccessary classes substitutions function setFocusedElement(cstOption) { - if (focusedElement) { - focusedElement.classList.remove(builderParams.hasFocusClass); - } - if (typeof cstOption !== 'undefined') { - focusedElement = cstOption; - focusedElement.classList.add(builderParams.hasFocusClass); - // Offset update: checks if the focused element is in the visible part of the panelClass - // if not dispatches a custom event - if (isOpen) { - if (cstOption.offsetTop < cstOption.offsetParent.scrollTop - || cstOption.offsetTop > - (cstOption.offsetParent.scrollTop + cstOption.offsetParent.clientHeight) - - cstOption.clientHeight) { - cstOption.dispatchEvent(new CustomEvent('custom-select:focus-outside-panel', { bubbles: true })); - } + if (focusedElement) { + focusedElement.classList.remove(builderParams.hasFocusClass); + } + if (typeof cstOption !== 'undefined') { + focusedElement = cstOption; + focusedElement.classList.add(builderParams.hasFocusClass); + // Offset update: checks if the focused element is in the visible part of the panelClass + // if not dispatches a custom event + if (isOpen) { + if (cstOption.offsetTop < cstOption.offsetParent.scrollTop + || cstOption.offsetTop > + (cstOption.offsetParent.scrollTop + cstOption.offsetParent.clientHeight) + - cstOption.clientHeight) { + cstOption.dispatchEvent(new CustomEvent('custom-select:focus-outside-panel', { bubbles: true })); + } + } + } else { + focusedElement = undefined; } - } else { - focusedElement = undefined; - } } // Reassigns the focused and selected custom option // Updates the opener text // IMPORTANT: the setSelectedElement function doesn't change the select value! function setSelectedElement(cstOption) { - if (selectedElement) { - selectedElement.classList.remove(builderParams.isSelectedClass); - selectedElement.removeAttribute('id'); - opener.removeAttribute('aria-activedescendant'); - } - if (typeof cstOption !== 'undefined') { - cstOption.classList.add(builderParams.isSelectedClass); - cstOption.setAttribute('id', `${containerClass}-${uId}-selectedOption`); - opener.setAttribute('aria-activedescendant', `${containerClass}-${uId}-selectedOption`); - selectedElement = cstOption; - opener.children[0].textContent = selectedElement.customSelectOriginalOption.text; - } else { - selectedElement = undefined; - opener.children[0].textContent = ''; - } - setFocusedElement(cstOption); + if (selectedElement) { + selectedElement.classList.remove(builderParams.isSelectedClass); + selectedElement.removeAttribute('id'); + opener.removeAttribute('aria-activedescendant'); + } + if (typeof cstOption !== 'undefined') { + cstOption.classList.add(builderParams.isSelectedClass); + cstOption.setAttribute('id', `${containerClass}-${uId}-selectedOption`); + opener.setAttribute('aria-activedescendant', `${containerClass}-${uId}-selectedOption`); + selectedElement = cstOption; + opener.children[0].textContent = selectedElement.customSelectOriginalOption.text; + } else { + selectedElement = undefined; + opener.children[0].textContent = ''; + } + setFocusedElement(cstOption); } function setValue(value) { - // Gets the option with the provided value - let toSelect = select.querySelector(`option[value='${value}']`); - // If no option has the provided value get the first - if (!toSelect) { - [toSelect] = select.options; - } - // The option with the provided value becomes the selected one - // And changes the select current value - toSelect.selected = true; + // Gets the option with the provided value + let toSelect = select.querySelector(`option[value='${value}']`); + // If no option has the provided value get the first + if (!toSelect) { + [toSelect] = select.options; + } + // The option with the provided value becomes the selected one + // And changes the select current value + toSelect.selected = true; - setSelectedElement(select.options[select.selectedIndex].customSelectCstOption); + setSelectedElement(select.options[select.selectedIndex].customSelectCstOption); } function moveFocuesedElement(direction) { - // Get all the .custom-select-options - // Get the index of the current focused one - const currentFocusedIndex = - [].indexOf.call(select.options, focusedElement.customSelectOriginalOption); - // If the next or prev custom option exist - // Sets it as the new focused one - if (select.options[currentFocusedIndex + direction]) { - setFocusedElement(select.options[currentFocusedIndex + direction].customSelectCstOption); - } + // Get all the .custom-select-options + // Get the index of the current focused one + const currentFocusedIndex = + [].indexOf.call(select.options, focusedElement.customSelectOriginalOption); + // If the next or prev custom option exist + // Sets it as the new focused one + if (select.options[currentFocusedIndex + direction]) { + setFocusedElement(select.options[currentFocusedIndex + direction].customSelectCstOption); + } } // Open/Close function (toggle) function open(bool) { - // Open - if (bool || typeof bool === 'undefined') { - // If present closes an opened instance of the plugin - // Only one at time can be open - const openedCustomSelect = - document.querySelector(`.${containerClass}.${builderParams.isOpenClass}`); - if (openedCustomSelect) { - openedCustomSelect.customSelect.open = false; + // Open + if (bool || typeof bool === 'undefined') { + // If present closes an opened instance of the plugin + // Only one at time can be open + const openedCustomSelect = + document.querySelector(`.${containerClass}.${builderParams.isOpenClass}`); + if (openedCustomSelect) { + openedCustomSelect.customSelect.open = false; + } + + // Opens only the clicked one + container.classList.add(builderParams.isOpenClass); + + // aria-expanded update + container.classList.add(builderParams.isOpenClass); + opener.setAttribute('aria-expanded', 'true'); + + // Updates the scrollTop position of the panel in relation with the focused option + if (selectedElement) { + panel.scrollTop = selectedElement.offsetTop; + } + + // Dispatches the custom event open + container.dispatchEvent(new CustomEvent('custom-select:open')); + + // Sets the global state + isOpen = true; + + // Close + } else { + // Removes the css classes + container.classList.remove(builderParams.isOpenClass); + + // aria-expanded update + opener.setAttribute('aria-expanded', 'false'); + + // Sets the global state + isOpen = false; + + // When closing the panel the focused custom option must be the selected one + setFocusedElement(selectedElement); + + // Dispatches the custom event close + container.dispatchEvent(new CustomEvent('custom-select:close')); } - - // Opens only the clicked one - container.classList.add(builderParams.isOpenClass); - - // aria-expanded update - container.classList.add(builderParams.isOpenClass); - opener.setAttribute('aria-expanded', 'true'); - - // Updates the scrollTop position of the panel in relation with the focused option - if (selectedElement) { - panel.scrollTop = selectedElement.offsetTop; - } - - // Dispatches the custom event open - container.dispatchEvent(new CustomEvent('custom-select:open')); - - // Sets the global state - isOpen = true; - - // Close - } else { - // Removes the css classes - container.classList.remove(builderParams.isOpenClass); - - // aria-expanded update - opener.setAttribute('aria-expanded', 'false'); - - // Sets the global state - isOpen = false; - - // When closing the panel the focused custom option must be the selected one - setFocusedElement(selectedElement); - - // Dispatches the custom event close - container.dispatchEvent(new CustomEvent('custom-select:close')); - } - return isOpen; + return isOpen; } function clickEvent(e) { - // Opener click - if (e.target === opener || opener.contains(e.target)) { - if (isOpen) { - open(false); - } else { - open(); + // Opener click + if (e.target === opener || opener.contains(e.target)) { + if (isOpen) { + open(false); + } else { + open(); + } + // Custom Option click + } else if ( + e.target.classList + && e.target.classList.contains(builderParams.optionClass) + && panel.contains(e.target)) { + setSelectedElement(e.target); + // Sets the corrisponding select's option to selected updating the select's value too + selectedElement.customSelectOriginalOption.selected = true; + open(false); + // Triggers the native change event of the select + select.dispatchEvent(new CustomEvent('change')); + // click on label or select (click on label corrispond to select click) + } else if (e.target === select) { + // if the original select is focusable (for any external reason) let the focus + // else trigger the focus on opener + if (opener !== document.activeElement && select !== document.activeElement) { + opener.focus(); + } + // Click outside the container closes the panel + } else if (isOpen && !container.contains(e.target)) { + open(false); } - // Custom Option click - } else if ( - e.target.classList - && e.target.classList.contains(builderParams.optionClass) - && panel.contains(e.target)) { - setSelectedElement(e.target); - // Sets the corrisponding select's option to selected updating the select's value too - selectedElement.customSelectOriginalOption.selected = true; - open(false); - // Triggers the native change event of the select - select.dispatchEvent(new CustomEvent('change')); - // click on label or select (click on label corrispond to select click) - } else if (e.target === select) { - // if the original select is focusable (for any external reason) let the focus - // else trigger the focus on opener - if (opener !== document.activeElement && select !== document.activeElement) { - opener.focus(); - } - // Click outside the container closes the panel - } else if (isOpen && !container.contains(e.target)) { - open(false); - } } function mouseoverEvent(e) { - // On mouse move over and options it bacames the focused one - if (e.target.classList && e.target.classList.contains(builderParams.optionClass)) { - setFocusedElement(e.target); - } + // On mouse move over and options it bacames the focused one + if (e.target.classList && e.target.classList.contains(builderParams.optionClass)) { + setFocusedElement(e.target); + } } function keydownEvent(e) { - if (!isOpen) { - // On "Arrow down", "Arrow up" and "Space" keys opens the panel - if (e.keyCode === 40 || e.keyCode === 38 || e.keyCode === 32) { - open(); - } - } else { - switch (e.keyCode) { - case 13: - case 32: - // On "Enter" or "Space" selects the focused element as the selected one - setSelectedElement(focusedElement); - // Sets the corrisponding select's option to selected updating the select's value too - selectedElement.customSelectOriginalOption.selected = true; - // Triggers the native change event of the select - select.dispatchEvent(new CustomEvent('change')); - open(false); - break; - case 27: - // On "Escape" closes the panel - open(false); - break; - - case 38: - // On "Arrow up" set focus to the prev option if present - moveFocuesedElement(-1); - break; - case 40: - // On "Arrow down" set focus to the next option if present - moveFocuesedElement(+1); - break; - default: - // search in panel (autocomplete) - if (e.keyCode >= 48 && e.keyCode <= 90) { - // clear existing reset timeout - if (resetSearchTimeout) { - clearTimeout(resetSearchTimeout); - } - - // reset timeout for empty search key - resetSearchTimeout = setTimeout(() => { - searchKey = ''; - }, 1500); - - // update search keyword appending the current key - searchKey += String.fromCharCode(e.keyCode); - - // search the element - for (let i = 0, l = select.options.length; i < l; i++) { - // removed cause not supported by IE: - // if (options[i].text.startsWith(searchKey)) - if (select.options[i].text.toUpperCase().substr(0, searchKey.length) === searchKey) { - setFocusedElement(select.options[i].customSelectCstOption); - break; - } - } + if (!isOpen) { + // On "Arrow down", "Arrow up" and "Space" keys opens the panel + if (e.keyCode === 40 || e.keyCode === 38 || e.keyCode === 32) { + open(); + } + } else { + switch (e.keyCode) { + case 13: + case 32: + // On "Enter" or "Space" selects the focused element as the selected one + setSelectedElement(focusedElement); + // Sets the corrisponding select's option to selected updating the select's value too + selectedElement.customSelectOriginalOption.selected = true; + // Triggers the native change event of the select + select.dispatchEvent(new CustomEvent('change')); + open(false); + break; + case 27: + // On "Escape" closes the panel + open(false); + break; + + case 38: + // On "Arrow up" set focus to the prev option if present + moveFocuesedElement(-1); + break; + case 40: + // On "Arrow down" set focus to the next option if present + moveFocuesedElement(+1); + break; + default: + // search in panel (autocomplete) + if (e.keyCode >= 48 && e.keyCode <= 90) { + // clear existing reset timeout + if (resetSearchTimeout) { + clearTimeout(resetSearchTimeout); + } + + // reset timeout for empty search key + resetSearchTimeout = setTimeout(() => { + searchKey = ''; + }, 1500); + + // update search keyword appending the current key + searchKey += String.fromCharCode(e.keyCode); + + // search the element + for (let i = 0, l = select.options.length; i < l; i++) { + // removed cause not supported by IE: + // if (options[i].text.startsWith(searchKey)) + if (select.options[i].text.toUpperCase().substr(0, searchKey.length) === searchKey) { + setFocusedElement(select.options[i].customSelectCstOption); + break; + } + } + } + break; } - break; } - } } function changeEvent() { - const index = select.selectedIndex; - const element = index === -1 ? undefined : select.options[index].customSelectCstOption; + const index = select.selectedIndex; + const element = index === -1 ? undefined : select.options[index].customSelectCstOption; setSelectedElement(element); if($(select).attr('data-id')){ var object_id = $(select).attr('data-id'); @@ -12312,210 +12462,210 @@ const defaultParams = { // with useCapture set to true // and stopPropagation function scrollToFocused(e) { - const currPanel = e.currentTarget; - const currOption = e.target; - // Up - if (currOption.offsetTop < currPanel.scrollTop) { - currPanel.scrollTop = currOption.offsetTop; - // Down - } else { - currPanel.scrollTop = (currOption.offsetTop + currOption.clientHeight) - - currPanel.clientHeight; - } + const currPanel = e.currentTarget; + const currOption = e.target; + // Up + if (currOption.offsetTop < currPanel.scrollTop) { + currPanel.scrollTop = currOption.offsetTop; + // Down + } else { + currPanel.scrollTop = (currOption.offsetTop + currOption.clientHeight) + - currPanel.clientHeight; + } } function addEvents() { - document.addEventListener('click', clickEvent); - panel.addEventListener('mouseover', mouseoverEvent); - panel.addEventListener('custom-select:focus-outside-panel', scrollToFocused); - select.addEventListener('change', changeEvent); - container.addEventListener('keydown', keydownEvent); + document.addEventListener('click', clickEvent); + panel.addEventListener('mouseover', mouseoverEvent); + panel.addEventListener('custom-select:focus-outside-panel', scrollToFocused); + select.addEventListener('change', changeEvent); + container.addEventListener('keydown', keydownEvent); } function removeEvents() { - document.removeEventListener('click', clickEvent); - panel.removeEventListener('mouseover', mouseoverEvent); - panel.removeEventListener('custom-select:focus-outside-panel', scrollToFocused); - select.removeEventListener('change', changeEvent); - container.removeEventListener('keydown', keydownEvent); + document.removeEventListener('click', clickEvent); + panel.removeEventListener('mouseover', mouseoverEvent); + panel.removeEventListener('custom-select:focus-outside-panel', scrollToFocused); + select.removeEventListener('change', changeEvent); + container.removeEventListener('keydown', keydownEvent); } function disabled(bool) { - if (bool && !select.disabled) { - container.classList.add(builderParams.isDisabledClass); - select.disabled = true; - opener.removeAttribute('tabindex'); - container.dispatchEvent(new CustomEvent('custom-select:disabled')); - removeEvents(); - } else if (!bool && select.disabled) { - container.classList.remove(builderParams.isDisabledClass); - select.disabled = false; - opener.setAttribute('tabindex', '0'); - container.dispatchEvent(new CustomEvent('custom-select:enabled')); - addEvents(); - } + if (bool && !select.disabled) { + container.classList.add(builderParams.isDisabledClass); + select.disabled = true; + opener.removeAttribute('tabindex'); + container.dispatchEvent(new CustomEvent('custom-select:disabled')); + removeEvents(); + } else if (!bool && select.disabled) { + container.classList.remove(builderParams.isDisabledClass); + select.disabled = false; + opener.setAttribute('tabindex', '0'); + container.dispatchEvent(new CustomEvent('custom-select:enabled')); + addEvents(); + } } // Form a given select children DOM tree (options and optgroup), // Creates the corresponding custom HTMLElements list (divs with different classes and attributes) function parseMarkup(children) { - const nodeList = children; - const cstList = []; + const nodeList = children; + const cstList = []; - if (typeof nodeList.length === 'undefined') { - throw new TypeError('Invalid Argument'); - } - - for (let i = 0, li = nodeList.length; i < li; i++) { - if (nodeList[i] instanceof HTMLElement && nodeList[i].tagName.toUpperCase() === 'OPTGROUP') { - const cstOptgroup = document.createElement('div'); - cstOptgroup.classList.add(builderParams.optgroupClass); - cstOptgroup.setAttribute('data-label', nodeList[i].label); - - // IMPORTANT: Stores in a property of the created custom option group - // a hook to the the corrisponding select's option group - cstOptgroup.customSelectOriginalOptgroup = nodeList[i]; - - // IMPORTANT: Stores in a property of select's option group - // a hook to the created custom option group - nodeList[i].customSelectCstOptgroup = cstOptgroup; - - const subNodes = parseMarkup(nodeList[i].children); - for (let j = 0, lj = subNodes.length; j < lj; j++) { - cstOptgroup.appendChild(subNodes[j]); - } - - cstList.push(cstOptgroup); - } else if (nodeList[i] instanceof HTMLElement - && nodeList[i].tagName.toUpperCase() === 'OPTION') { - const cstOption = document.createElement('div'); - cstOption.classList.add(builderParams.optionClass); - cstOption.textContent = nodeList[i].text; - cstOption.setAttribute('data-value', nodeList[i].value); - cstOption.setAttribute('role', 'option'); - - // IMPORTANT: Stores in a property of the created custom option - // a hook to the the corrisponding select's option - cstOption.customSelectOriginalOption = nodeList[i]; - - // IMPORTANT: Stores in a property of select's option - // a hook to the created custom option - nodeList[i].customSelectCstOption = cstOption; - - // If the select's option is selected - if (nodeList[i].selected) { - setSelectedElement(cstOption); - } - cstList.push(cstOption); - } else { - throw new TypeError('Invalid Argument'); + if (typeof nodeList.length === 'undefined') { + throw new TypeError('Invalid Argument'); } - } - return cstList; + + for (let i = 0, li = nodeList.length; i < li; i++) { + if (nodeList[i] instanceof HTMLElement && nodeList[i].tagName.toUpperCase() === 'OPTGROUP') { + const cstOptgroup = document.createElement('div'); + cstOptgroup.classList.add(builderParams.optgroupClass); + cstOptgroup.setAttribute('data-label', nodeList[i].label); + + // IMPORTANT: Stores in a property of the created custom option group + // a hook to the the corrisponding select's option group + cstOptgroup.customSelectOriginalOptgroup = nodeList[i]; + + // IMPORTANT: Stores in a property of select's option group + // a hook to the created custom option group + nodeList[i].customSelectCstOptgroup = cstOptgroup; + + const subNodes = parseMarkup(nodeList[i].children); + for (let j = 0, lj = subNodes.length; j < lj; j++) { + cstOptgroup.appendChild(subNodes[j]); + } + + cstList.push(cstOptgroup); + } else if (nodeList[i] instanceof HTMLElement + && nodeList[i].tagName.toUpperCase() === 'OPTION') { + const cstOption = document.createElement('div'); + cstOption.classList.add(builderParams.optionClass); + cstOption.textContent = nodeList[i].text; + cstOption.setAttribute('data-value', nodeList[i].value); + cstOption.setAttribute('role', 'option'); + + // IMPORTANT: Stores in a property of the created custom option + // a hook to the the corrisponding select's option + cstOption.customSelectOriginalOption = nodeList[i]; + + // IMPORTANT: Stores in a property of select's option + // a hook to the created custom option + nodeList[i].customSelectCstOption = cstOption; + + // If the select's option is selected + if (nodeList[i].selected) { + setSelectedElement(cstOption); + } + cstList.push(cstOption); + } else { + throw new TypeError('Invalid Argument'); + } + } + return cstList; } function append(nodePar, appendIntoOriginal, targetPar) { - let target; - if (typeof targetPar === 'undefined' - || (targetPar === select)) { - target = panel; - } else if (targetPar instanceof HTMLElement - && targetPar.tagName.toUpperCase() === 'OPTGROUP' - && select.contains(targetPar)) { - target = targetPar.customSelectCstOptgroup; - } else { - throw new TypeError('Invalid Argument'); - } - - // If the node provided is a single HTMLElement it is stored in an array - const node = nodePar instanceof HTMLElement ? [nodePar] : nodePar; - - // Injects the options|optgroup in the select - if (appendIntoOriginal) { - for (let i = 0, l = node.length; i < l; i++) { - if (target === panel) { - select.appendChild(node[i]); - } else { - target.customSelectOriginalOptgroup.appendChild(node[i]); - } + let target; + if (typeof targetPar === 'undefined' + || (targetPar === select)) { + target = panel; + } else if (targetPar instanceof HTMLElement + && targetPar.tagName.toUpperCase() === 'OPTGROUP' + && select.contains(targetPar)) { + target = targetPar.customSelectCstOptgroup; + } else { + throw new TypeError('Invalid Argument'); } - } - // The custom markup to append - const markupToInsert = parseMarkup(node); + // If the node provided is a single HTMLElement it is stored in an array + const node = nodePar instanceof HTMLElement ? [nodePar] : nodePar; - // Injects the created DOM content in the panel - for (let i = 0, l = markupToInsert.length; i < l; i++) { - target.appendChild(markupToInsert[i]); - } + // Injects the options|optgroup in the select + if (appendIntoOriginal) { + for (let i = 0, l = node.length; i < l; i++) { + if (target === panel) { + select.appendChild(node[i]); + } else { + target.customSelectOriginalOptgroup.appendChild(node[i]); + } + } + } - return node; + // The custom markup to append + const markupToInsert = parseMarkup(node); + + // Injects the created DOM content in the panel + for (let i = 0, l = markupToInsert.length; i < l; i++) { + target.appendChild(markupToInsert[i]); + } + + return node; } function insertBefore(node, targetPar) { - let target; - if (targetPar instanceof HTMLElement - && targetPar.tagName.toUpperCase() === 'OPTION' - && select.contains(targetPar)) { - target = targetPar.customSelectCstOption; - } else if (targetPar instanceof HTMLElement - && targetPar.tagName.toUpperCase() === 'OPTGROUP' - && select.contains(targetPar)) { - target = targetPar.customSelectCstOptgroup; - } else { - throw new TypeError('Invalid Argument'); - } + let target; + if (targetPar instanceof HTMLElement + && targetPar.tagName.toUpperCase() === 'OPTION' + && select.contains(targetPar)) { + target = targetPar.customSelectCstOption; + } else if (targetPar instanceof HTMLElement + && targetPar.tagName.toUpperCase() === 'OPTGROUP' + && select.contains(targetPar)) { + target = targetPar.customSelectCstOptgroup; + } else { + throw new TypeError('Invalid Argument'); + } - // The custom markup to append - const markupToInsert = parseMarkup(node.length ? node : [node]); + // The custom markup to append + const markupToInsert = parseMarkup(node.length ? node : [node]); - target.parentNode.insertBefore(markupToInsert[0], target); + target.parentNode.insertBefore(markupToInsert[0], target); - // Injects the option or optgroup node in the original select and returns the injected node - return targetPar.parentNode.insertBefore(node.length ? node[0] : node, targetPar); + // Injects the option or optgroup node in the original select and returns the injected node + return targetPar.parentNode.insertBefore(node.length ? node[0] : node, targetPar); } function remove(node) { - let cstNode; - if (node instanceof HTMLElement - && node.tagName.toUpperCase() === 'OPTION' - && select.contains(node)) { - cstNode = node.customSelectCstOption; - } else if (node instanceof HTMLElement - && node.tagName.toUpperCase() === 'OPTGROUP' - && select.contains(node)) { - cstNode = node.customSelectCstOptgroup; - } else { - throw new TypeError('Invalid Argument'); - } - cstNode.parentNode.removeChild(cstNode); - const removedNode = node.parentNode.removeChild(node); - changeEvent(); - return removedNode; + let cstNode; + if (node instanceof HTMLElement + && node.tagName.toUpperCase() === 'OPTION' + && select.contains(node)) { + cstNode = node.customSelectCstOption; + } else if (node instanceof HTMLElement + && node.tagName.toUpperCase() === 'OPTGROUP' + && select.contains(node)) { + cstNode = node.customSelectCstOptgroup; + } else { + throw new TypeError('Invalid Argument'); + } + cstNode.parentNode.removeChild(cstNode); + const removedNode = node.parentNode.removeChild(node); + changeEvent(); + return removedNode; } function empty() { - const removed = []; - while (select.children.length) { - panel.removeChild(panel.children[0]); - removed.push(select.removeChild(select.children[0])); - } - setSelectedElement(); - return removed; + const removed = []; + while (select.children.length) { + panel.removeChild(panel.children[0]); + removed.push(select.removeChild(select.children[0])); + } + setSelectedElement(); + return removed; } function destroy() { - for (let i = 0, l = select.options.length; i < l; i++) { - delete select.options[i].customSelectCstOption; - } - const optGroup = select.getElementsByTagName('optgroup'); - for (let i = 0, l = optGroup.length; i < l; i++) { - delete optGroup.customSelectCstOptgroup; - } + for (let i = 0, l = select.options.length; i < l; i++) { + delete select.options[i].customSelectCstOption; + } + const optGroup = select.getElementsByTagName('optgroup'); + for (let i = 0, l = optGroup.length; i < l; i++) { + delete optGroup.customSelectCstOptgroup; + } - removeEvents(); + removeEvents(); - return container.parentNode.replaceChild(select, container); + return container.parentNode.replaceChild(select, container); } // // Custom Select DOM tree creation @@ -12542,7 +12692,7 @@ const defaultParams = { // Create random id const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; for (let i = 0; i < 5; i++) { - uId += possible.charAt(Math.floor(Math.random() * possible.length)); + uId += possible.charAt(Math.floor(Math.random() * possible.length)); } panel.id = `${containerClass}-${uId}-panel`; panel.className = builderParams.panelClass; @@ -12559,48 +12709,48 @@ const defaultParams = { // ARIA labelledby - label if (document.querySelector(`label[for="${select.id}"]`)) { - currLabel = document.querySelector(`label[for="${select.id}"]`); + currLabel = document.querySelector(`label[for="${select.id}"]`); } else if (container.parentNode.tagName.toUpperCase() === 'LABEL') { - currLabel = container.parentNode; + currLabel = container.parentNode; } if (typeof currLabel !== 'undefined') { - currLabel.setAttribute('id', `${containerClass}-${uId}-label`); - opener.setAttribute('aria-labelledby', `${containerClass}-${uId}-label`); + currLabel.setAttribute('id', `${containerClass}-${uId}-label`); + opener.setAttribute('aria-labelledby', `${containerClass}-${uId}-label`); } // Event Init if (select.disabled) { - container.classList.add(builderParams.isDisabledClass); + container.classList.add(builderParams.isDisabledClass); } else { - opener.setAttribute('tabindex', '0'); - select.setAttribute('tabindex', '-1'); - addEvents(); + opener.setAttribute('tabindex', '0'); + select.setAttribute('tabindex', '-1'); + addEvents(); } // Stores the plugin public exposed methods and properties, directly in the container HTMLElement container.customSelect = { - get pluginOptions() { return builderParams; }, - get open() { return isOpen; }, - set open(bool) { - open(bool); - }, - get disabled() { return select.disabled; }, - set disabled(bool) { - disabled(bool); - }, - get value() { return select.value; }, - set value(val) { - setValue(val); - }, - append: (node, target) => append(node, true, target), - insertBefore: (node, target) => insertBefore(node, target), - remove, - empty, - destroy, - opener, - select, - panel, - container, + get pluginOptions() { return builderParams; }, + get open() { return isOpen; }, + set open(bool) { + open(bool); + }, + get disabled() { return select.disabled; }, + set disabled(bool) { + disabled(bool); + }, + get value() { return select.value; }, + set value(val) { + setValue(val); + }, + append: (node, target) => append(node, true, target), + insertBefore: (node, target) => insertBefore(node, target), + remove, + empty, + destroy, + opener, + select, + panel, + container, }; // Stores the plugin directly in the original select @@ -12608,48 +12758,48 @@ const defaultParams = { // Returns the plugin instance, with the public exposed methods and properties return container.customSelect; - } +} - function customSelect(element, customParams) { +function customSelect(element, customParams) { // Overrides the default options with the ones provided by the user const nodeList = []; const selects = []; return (function init() { - // The plugin is called on a single HTMLElement - if (element && element instanceof HTMLElement && element.tagName.toUpperCase() === 'SELECT') { - nodeList.push(element); - // The plugin is called on a selector - } else if (element && typeof element === 'string') { - const elementsList = document.querySelectorAll(element); - for (let i = 0, l = elementsList.length; i < l; ++i) { - if (elementsList[i] instanceof HTMLElement - && elementsList[i].tagName.toUpperCase() === 'SELECT') { - nodeList.push(elementsList[i]); - } + // The plugin is called on a single HTMLElement + if (element && element instanceof HTMLElement && element.tagName.toUpperCase() === 'SELECT') { + nodeList.push(element); + // The plugin is called on a selector + } else if (element && typeof element === 'string') { + const elementsList = document.querySelectorAll(element); + for (let i = 0, l = elementsList.length; i < l; ++i) { + if (elementsList[i] instanceof HTMLElement + && elementsList[i].tagName.toUpperCase() === 'SELECT') { + nodeList.push(elementsList[i]); + } + } + // The plugin is called on any HTMLElements list (NodeList, HTMLCollection, Array, etc.) + } else if (element && element.length) { + for (let i = 0, l = element.length; i < l; ++i) { + if (element[i] instanceof HTMLElement + && element[i].tagName.toUpperCase() === 'SELECT') { + nodeList.push(element[i]); + } + } } - // The plugin is called on any HTMLElements list (NodeList, HTMLCollection, Array, etc.) - } else if (element && element.length) { - for (let i = 0, l = element.length; i < l; ++i) { - if (element[i] instanceof HTMLElement - && element[i].tagName.toUpperCase() === 'SELECT') { - nodeList.push(element[i]); - } + + // Launches the plugin over every HTMLElement + // And stores every plugin instance + for (let i = 0, l = nodeList.length; i < l; ++i) { + selects.push(builder(nodeList[i], Object.assign({}, defaultParams, customParams))); } - } - // Launches the plugin over every HTMLElement - // And stores every plugin instance - for (let i = 0, l = nodeList.length; i < l; ++i) { - selects.push(builder(nodeList[i], Object.assign({}, defaultParams, customParams))); - } - - // Returns all plugin instances - return selects; + // Returns all plugin instances + return selects; }()); - } +} - function change_promo(object_id, val){ +function change_promo(object_id, val){ console.log(object_id, val); var params = {}; @@ -12705,29 +12855,29 @@ const defaultParams = { params.domclick_price = form.find('input[name="domclick_price"]').val();*/ - $.ajax({ - url: '/ajax/addPromotion.php', - method: "post", - data: params, - success: function(data) { - // console.log(data); - //let results = JSON.parse(data); + $.ajax({ + url: '/ajax/addPromotion.php', + method: "post", + data: params, + success: function(data) { + // console.log(data); + //let results = JSON.parse(data); - if(val == 'cian_bet'){ - is_change_cian_bet = false; - } - /*$("#addPromotionBg").hide(); - $("#addPromotionBg").empty(); - $("#addPromotion").hide(); - $("body").removeClass("lock");*/ - - //console.log(results); - - }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - console.log("eRROR: " + errorThrown + "; status:" + textStatus); + if(val == 'cian_bet'){ + is_change_cian_bet = false; } - }); + /*$("#addPromotionBg").hide(); + $("#addPromotionBg").empty(); + $("#addPromotion").hide(); + $("body").removeClass("lock");*/ + + //console.log(results); + + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + console.log("eRROR: " + errorThrown + "; status:" + textStatus); + } + }); } } diff --git a/js/deals_client_vue.js b/js/deals_client_vue.js new file mode 100644 index 0000000..f825067 --- /dev/null +++ b/js/deals_client_vue.js @@ -0,0 +1,60 @@ +Vue.config.devtools = true; + +var deals_client = new Vue({ + el: '#deals_list_client', + name: 'deals_list_client', + data() { + return { + dealsList: [], + isDealsClient: 0, + clientId: 0, + } + }, + methods: { + getList() { + if (this.clientId > 0) { + this.dealsList = []; + this.isDealsClient = 0; + + axios.post('/ajax/ajax_vue_requisitions.php', { + request: 'get_deal_by_client', + client_id: this.clientId, + }) + .then((response) => { + var res = response.data; + if (res.deals && res.deals.length > 0) { + var promises = res.deals.map(dealId => { + return axios.get('/api/deals/' + dealId).then(r => r.data.data).catch(() => null); + }); + Promise.all(promises).then(results => { + deals_client.dealsList = results.filter(d => d !== null); + deals_client.isDealsClient = deals_client.dealsList.length > 0 ? 1 : 2; + }); + } else { + this.isDealsClient = 2; + } + }) + .catch(function(error) { + console.log(error); + deals_client.isDealsClient = 2; + }); + } + }, + openDealFromClient(dealId) { + if (typeof window.editDeal === 'function') { + window.editDeal(0, dealId); + } else { + console.error('editDeal not available'); + } + }, + isEmpty(obj) { + for (var key in obj) { + if (obj.hasOwnProperty(key)) return false; + } + return true; + } + }, + mounted() { + // Автоматически загружаем список при монтировании + } +}); diff --git a/templates/footer.php b/templates/footer.php index 530bd8a..7cb02b1 100644 --- a/templates/footer.php +++ b/templates/footer.php @@ -1787,6 +1787,16 @@ $user_id = $_SESSION['id']; 6 Для документов + + +
  • + 7 + Сделки +
  • +
    @@ -3209,6 +3219,45 @@ $user_id = $_SESSION['id']; по эл. почте Вашему клиенту или просто вывести на печать.
    + + +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    {{ item.title }}
    +
    + {{ item.side_one }} / {{ item.side_two }} +
    +
    Дата: {{ item.deal_date }}
    +
    Сумма: {{ Number(item.contract_price).toLocaleString('ru-RU') }} руб.
    +
    + +
    + + + +
    +
    +
    +
    +
    +
    +

    +

    Сделок не найдено

    +
    +
    +
    +
    +
    @@ -5331,23 +5380,22 @@ $user_id = $_SESSION['id'];
    @@ -6071,6 +6119,7 @@ require($_SERVER['DOCUMENT_ROOT']."/templates/files_list.php"); +