$(window).ready(function() { /* Data */ var portList, peopleStat, reasonList, freightData, peopleList, transferList, claimData, timeout, dateInterval, portSelected, device; var isLoading = { 'portList' : false, 'peopleStat' : false, 'reasonList' : false, 'peopleList' : false, 'transferList': false, 'claimData' : false, 'peopleReg' : false, 'reasonSet' : false, 'phoneSet' : false, 'sessionSet' : false, 'exportXLS' : false, 'exportClaimJPG' : false, 'themeSet' : false, }; var isError = { //'freights': false, 'reg' : false, }; init(); /* Functions */ function initDevice() { // Определение устройства var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; if (w < 768) { device = 'mobile'; } else if (w >= 768 && w < 1024) { device = 'tablet'; } else { device = 'pc'; } } function init() { initDevice(); new WOW().init(); moment().format(); $(document).ajaxStart(function() { Pace.restart(); }); loadPorts(); loadPeopleStat(); loadReasonList(); } function sendAjax(extendedData, loadingType, extendedParams) { if (!isLoading[loadingType]) { var ajaxData = $.extend({c: 'airport', a: 'get'}, extendedData); var ajaxParams = $.extend({ async: true, type: 'POST', dataType: 'json', url: '/' + ROOT_PATH + 'index.php', data: ajaxData, beforeSend: function() { isLoading[loadingType] = true; }, complete: function(data) { isLoading[loadingType] = false; }, }, extendedParams); $.ajax(ajaxParams); } } function loadPorts() { sendAjax({m: 'get_ports'}, 'portList', { success: function(data) { //portList = JSON.parse(data); portList = data; portsAdd(portList); }, }); } function loadPeopleStat(update = false) { sendAjax({m: 'get_people_stat'}, 'peopleStat', { success: function(data) { peopleStat = data; if (!update) { loadFreights(); } else { freightSort(dateInterval, portSelected); } }, error: function(error) { $('.item-no-freights').show(); $('.item-freights').hide(); $('.item-tourists').hide(); $('.item-transfers').hide(); $('.freight-form').hide(); }, }); } function loadReasonList() { sendAjax({m: 'get_reason_list', l: lang}, 'reasonList', { success: function(data) { reasonList = data; reasonsAdd(); }, }); } function loadFreights() { sendAjax({m: 'get_freights', l: lang}, 'freightData', { success: function(data) { if (data.length) { freightData = data; freightsAdd(); } else { $('.item-no-freights').show(); $('.item-freights').hide(); $('.item-tourists').hide(); $('.item-transfers').hide(); $('.fd-box').hide(); } }, error: function() { $('.item-no-freights').show(); $('.item-freights').hide(); $('.item-tourists').hide(); $('.item-transfers').hide(); $('.fd-box').hide(); }, }); } function portsAdd(ports) { // Любой порт portEl = document.createElement('option'); $(portEl).val(0); $(portEl).text('ALL'); $('.inputPort').append(portEl); ports.forEach(function(port) { portEl = document.createElement('option'); $(portEl).val(port.inc); $(portEl).text(port.alias); $('.inputPort').append(portEl); }); $('select.inputPort').selectize({ create: true, dropdownParent: 'body' }); } function reasonsAdd() { reasonList.forEach(function(reason) { reasonEl = document.createElement('option'); $(reasonEl).val(reason.inc); $(reasonEl).text(reason.name); $('.inputReason').append(reasonEl); }); $('select.inputReason').selectize({ create: true, dropdownParent: 'body' }); } function freightsAdd() { $('.fd-box').css('display', 'inline-block'); var dateFromMidnight = { hours: moment().format('HH'), minutes: moment().format('mm') }; var dateToMidnight = { hours: 23 - moment().format('HH'), minutes: 59 - moment().format('mm') }; $(".inputDateRange").ionRangeSlider({ type: "double", min: +moment().subtract(1, "days").subtract(dateFromMidnight.hours, "hours").subtract(dateFromMidnight.minutes, "minutes").format("X"), max: +moment().add(1, "days").add(dateToMidnight.hours, "hours").add(dateToMidnight.minutes, "minutes").format("X"), /*from: +moment().subtract(24, "hours").format("X"), to: +moment().add(24, "hours").format("X"),*/ grid: true, grid_num: 2, //step: 100, force_edges: true, hide_min_max: true, prettify: function (num) { var m = moment(num, "X").locale(lang /*"ru"*/); return m.format("Do MMMM, HH:mm"); }, onFinish: function (data) { dateInterval = data; freightSort(dateInterval, portSelected); }, }); $('#inputPort').on('change', function() { portSelected = $('#inputPort :selected').text(); freightSort(dateInterval, portSelected); }); $('#inputPort-xs').on('change', function() { portSelected = $('#inputPort-xs :selected').text(); freightSort(dateInterval, portSelected); }); } function freightSort(date = null, port = 'ALL') { var freights = []; // id рейсов $('.item-freights .item-content .item-freight').each(function(index, el) { // Сбрасывать все рейсы, если они не соответствуют фильтру if ($(el).is('.active') && (port == 'ALL' || port == el.dataset.port)) { freights.push({ inc: el.dataset.freight, fdate: el.dataset.fdate }); } else if ($(el).is('.active')) { freightDetail(el); // Сбросить туристов и трансфер рейса $(el).remove(); } else { $(el).remove(); } }); freightData.forEach(function(curFreightData, curFreightIndex) { var tourists = { // туристы из peopleStat registered: 0, unregistered: 0 }; var tdate = moment(curFreightData.fdatetime, 'DD/MM/YYYY HH:mm').format('DD.MM.YYYY.HH.mm').split('.'); curFreightData.date = Math.floor(new Date(tdate[2], tdate[1] - 1, tdate[0], tdate[3], tdate[4]).getTime() / 1000); if (port == 'ALL' || port == curFreightData.port) { if (date && curFreightData.date >= date.from && curFreightData.date <= date.to || curFreightData.fdatetime === null) { var isAdded = freights.find(function(item) { if (item.inc == curFreightData.freight && moment(item.fdate, 'DD.MM.YYYY').isSame(moment(curFreightData.fdatetime, 'DD/MM/YYYY'))) { return true; } }); peopleStat.find(function(people) { if (people.freight == curFreightData.freight && moment(people.tdate, 'DD/MM/YYYY').isSame(moment(curFreightData.fdatetime, 'DD/MM/YYYY'))) { tourists.registered = people.registered; tourists.unregistered = people.unregistered; } }); var jstFreightsData = { freightView: device, freightActive: '', freightActiveXs: '', freightIndex: curFreightIndex, freightInc: curFreightData.freight, freightDt: curFreightData.freight.toString() + moment(curFreightData.fdatetime, 'DD/MM/YYYY HH:mm').format('DDMMYYYYHHmm').toString(), freightDate: moment(curFreightData.fdatetime, 'DD/MM/YYYY HH:mm').format('DD.MM.YYYY'), freightName: curFreightData.name, freightTime: moment(curFreightData.fdatetime, 'DD/MM/YYYY HH:mm').format('HH:mm'), freightFrom: curFreightData.sourcename, freightTo: curFreightData.targetname, freightPort: curFreightData.port, freightRegistered: tourists.registered, freightUnregistered: tourists.unregistered, }; // Если рейс не был добавлен if (!isAdded) { var h = new EJS({url: '/' + ROOT_PATH + 'jst/jst-freights.ejs'}).render(jstFreightsData); $('.item-freights .item-content').append(h); } // Если рейс был добавлен else { $('.item-freights .item-freight').each(function(index, el) { if (el.dataset.freight == jstFreightsData.freightInc && moment(el.dataset.fdate, 'DD.MM.YYYY').isSame(moment(jstFreightsData.freightDate, 'DD.MM.YYYY'))) { if ($(el).is('.visible-xs')) { jstFreightsData.freightActiveXs = 'active'; } else { jstFreightsData.freightActive = 'active'; } $(el).remove(); var h = new EJS({url: '/' + ROOT_PATH + 'jst/jst-freights.ejs'}).render(jstFreightsData); $('.item-freights .item-content').append(h); } }); } } } }); } function touristRegSort(sort = 'all', type = 'main') { switch (sort) { case 'all': reg = 'all'; break; case 'reg': reg = 'true'; break; case 'unreg': reg = 'false'; break; } switch (type) { case 'main': $('.item-tourists .item-content .item-tourist').each(function(index, tourist) { if (reg == 'all' || tourist.dataset.reg == reg) { $(tourist).show(); } else if (tourist.dataset.reg != reg) { $(tourist).hide(); } }); break; case 'claim': $('.claim-tourists .claim-tourist').each(function(index, tourist) { if (reg == 'all' || tourist.dataset.reg == reg) { $(tourist).show(); } else if (tourist.dataset.reg != reg) { $(tourist).hide(); } }); break; } } function freightDetail(curFreight, update = false) { if (!$(curFreight).is('.active') || update) { $(curFreight).addClass('active'); var curFreightData = freightData.find(function(item) { if (item.freight == curFreight.dataset.freight && moment(item.fdatetime, 'DD/MM/YYYY').isSame(moment(curFreight.dataset.fdate, 'DD/MM/YYYY'))) { return item; } }); if (curFreightData) { sendAjax({ m: 'get_people_list', date: moment(curFreightData.fdatetime, 'DD/MM/YYYY HH:mm').format('YYYYMMDD'), freight: curFreight.dataset.freight, l: lang, }, 'peopleList', { success: function(data) { peopleList = data; freightDetailShowPeople(curFreight, update); }, }); sendAjax({ m: 'get_transfer_list', date: moment(curFreightData.fdatetime, 'DD/MM/YYYY HH:mm').format('YYYYMMDD'), freight: curFreight.dataset.freight, l: lang, }, 'transferList', { success: function(data) { transferList = data; freightDetailShowTransfer(curFreight, update); }, }); } } else { $(curFreight).removeClass('active'); $('.item-transfers .item-content .item-transfer').each(function(index, transfer) { if (transfer.dataset.freight == curFreight.dataset.freight && transfer.dataset.item == curFreight.dataset.item) { $(transfer).remove(); } }); $('.item-tourists .item-content .item-tourist').each(function(index, tourist) { if (tourist.dataset.freight == curFreight.dataset.freight && tourist.dataset.item == curFreight.dataset.item) { $(tourist).remove(); } }); } } function freightDetailShowPeople(curFreight, update = false) { /* Сортировка массива A-Z */ /*peopleList.sort(function(a, b) { var compA = a.toUpperCase(); var compB = b.toUpperCase(); return (compA < compB) ? -1 : (compA > compB) ? 1 : 0; });*/ /* Добавление туристов */ peopleList.forEach(function(people) { var jstTouristsData = { freightIndex: curFreight.dataset.item, transferNumber: people.data.transferNumber, touristFreightInc: curFreight.dataset.freight, touristFreightDt: curFreight.dataset.freightdt, touristInc: people.data.peopleInc, touristReg: people.registered, touristColor: people.registered ? 'good' : 'danger', touristHuman: people.data.peopleHuman, touristName: people.data.peopleName, touristClaim: people.data.peopleClaim, touristClaimTo: people.data.peopleClaimTo, reasonName: people.data.reasonName, reasonComment: people.data.reasonComment, }; if (!update) { var h = new EJS({url: '/' + ROOT_PATH + 'jst/jst-tourists.ejs'}).render(jstTouristsData); $('.item-tourists .item-content').append(h); } else { $('.item-tourists .item-tourist').each(function(index, el) { if (el.dataset.inc == jstTouristsData.touristInc) { $(el).remove(); var h = new EJS({url: '/' + ROOT_PATH + 'jst/jst-tourists.ejs'}).render(jstTouristsData); $('.item-tourists .item-content').append(h); } }); } }); /* Сортировка туристов A-Z */ sortPeopleList($('.item-tourists .item-content .item-tourist')); } function freightDetailShowTransfer(curFreight, update = false) { /* Добавление трансферов */ transferList.forEach(function(transfer) { var jstTransfersData = { freightIndex: curFreight.dataset.item, transferFreightInc: curFreight.dataset.freight, transferFreightDt: curFreight.dataset.freightdt, transferInc: transfer.inc, transferIdent: transfer.ident, transferGuideName: transfer.guideName, transferGuideMobile: transfer.guideMobile, transferDriverName: transfer.driverName, transferRegistered: transfer.registered, transferUnregistered: transfer.unregistered, }; if (!update) { var h = new EJS({url: '/' + ROOT_PATH + 'jst/jst-transfers.ejs'}).render(jstTransfersData); $('.item-transfers .item-content').append(h); } else { $('.item-transfers .item-transfer').each(function(index, el) { if (el.dataset.inc == jstTransfersData.transferInc) { $(el).remove(); var h = new EJS({url: '/' + ROOT_PATH + 'jst/jst-transfers.ejs'}).render(jstTransfersData); $('.item-transfers .item-content').append(h); } }); } }); } function claimDetail(curClaim, update = false, autoreg = false) { //if (!$('.claims').is(':visible') || update) { if (!isLoading.claimData) { if ($('.claims').is(':visible') && !update) { $('.claims .claim-body .transfers-tabs').empty(); $('.claims .claim-body .transfers-container').empty(); } sendAjax({ m: 'get_claim', claim: curClaim, l: lang, }, 'claimData', { success: function(data) { claimData = data; //claimData.claimInc = curClaim; claimShow(curClaim, update, autoreg); $('body').css('overflow', 'hidden'); $('.message-warning').fadeOut(); }, error: function(error) { $('.message-warning').fadeIn(); setTimeout(function() { $('.message-warning').fadeOut(); }, 2500); }, }); } //} } function claimShow(curClaim = null, update = false, autoreg = false) { $('.claims .claim-header ._claimID').text(curClaim); $('.claims .claim-box').data('claim', curClaim); $('.claims .claim-header .claim-to').addClass('hide'); //$('.claims .claim-box').data('freight', curClaim); claimData.forEach(function(claim, claimIndex) { // Если рейс не сегодня, показывать предупреждение var transferToday = true; var tdate = moment(claim.transferDate, 'DD/MM/YYYY').format('DD.MM.YYYY').split('.'); var ndate = moment().format('DD.MM.YYYY').split('.'); tdate.forEach(function(item, i) { if (item != ndate[i]) { transferToday = false; } }); var jstClaimData = { claimInc: curClaim, claimId: claimIndex + 1, claimTO: claim.claimTO, showDangerDate: transferToday ? 'item-hidden' : '', showDangerReg: isError.reg ? '' : 'item-hidden', showTransferNumber: claim.transferNumber ? '' : 'item-hidden', activeClass: '', transferInc: claim.transferInc, transferIdent: claim.transferIdent, coachName: claim.coachName, guideName: claim.guideName, guideMobile: claim.guideMobile, driverName: claim.driverName, claimDatebeg: claim.claimDatebeg ? moment(claim.claimDatebeg, 'DD/MM/YYYY').format('DD.MM.YYYY') : '', claimDateend: claim.claimDateend ? moment(claim.claimDateend, 'DD/MM/YYYY').format('DD.MM.YYYY') : '', partnerName: claim.partnerName, transferNumber: claim.transferNumber, transferDate: claim.transferDate, transferType: claim.transferType, transferTypeAlias: claim.transferTypeAlias, transferTypeIco: claim.transferType == 0 ? 'fa-bus ico-grp' : 'fa-car ico-ind', sourceTown: claim.sourceTown, freightName: claim.freightName, targetTown: claim.targetTown, targetPort: claim.targetPort, hotelName: claim.hotelName, TOClaimGroupName: claim.TOClaimGroupName, TOClaimGroupPicture: claim.TOClaimGroupPicture ? claim.TOClaimGroupPicture : '', additionalNote: claim.additionalNote ? claim.additionalNote : '', people: [], messages: messages, }; claim.peoples.forEach(function(tourist, index) { jstClaimData.people[index] = { peopleReg: tourist.peopleReg, peopleInc: tourist.peopleInc, peopleName: tourist.peopleName, peopleHuman: tourist.peopleHuman, peopleColor: tourist.peopleReg ? 'good' : 'danger', peopleRegtime: tourist.peopleRegtime ? moment(tourist.peopleRegtime, 'DD/MM/YYYY HH:mm').format('DD.MM.YYYY HH:mm') : '', peopleAge: tourist.peopleAge, peopleBorn: moment(tourist.peopleBorn, 'DD/MM').format('DD/MM') == moment().format('DD/MM') ? '' : 'item-hidden', phoneNumber: tourist.hasPhoneNumber == '1' ? '' : 'item-hidden', infoGuideName: tourist.infoGuideName, infoDateTime: tourist.infoDateTime ? moment(tourist.infoDateTime, 'YYYY-MM-DD HH:mm:ss').format('DD.MM.YYYY HH:mm') : '', reasonName: tourist.reasonName, reasonComment: tourist.reasonComment, } }); if (!update) { // Если это первый трансфер, активировать таб if (claimIndex == 0) { jstClaimData.activeClass = 'active'; } if (jstClaimData.claimTO) { $('.claims .claim-header ._claimTO').text(jstClaimData.claimTO); $('.claims .claim-header .claim-to').removeClass('hide'); } if (jstClaimData.TOClaimGroupPicture !== '') { var $imgEl = $('') .addClass('claim-to-ico') .attr('src', 'data:image/png;base64,' + jstClaimData.TOClaimGroupPicture) .attr('title', jstClaimData.TOClaimGroupName); $('.claims .claim-header ._claimTOGroup').empty().append($imgEl); } else if (jstClaimData.TOClaimGroupName !== '') { $('.claims .claim-header ._claimTOGroup').empty().text(jstClaimData.TOClaimGroupName); } var h = new EJS({url: '/' + ROOT_PATH + 'jst/jst-claim.ejs'}).render(jstClaimData); $('.claims').show(); var autoregClaim = $('.claims .claim-body .transfers-container').append(h); var transfersTab = document.createElement('li'); $(transfersTab).attr('role', 'presentation').addClass(jstClaimData.activeClass); transfersTab.innerHTML = ''+messages.AIRPORT_TRANSFER+' #'+jstClaimData.claimId+' – '+jstClaimData.transferTypeAlias+' '+jstClaimData.additionalNote+''; $('.transfers-tabs').append(transfersTab); // Зарегистрировать, если режим быстрой регистрации if (autoreg && claimIndex == 0) { var touristsReg = getClaimPeopleCheck(autoregClaim); registerPeople(touristsReg, true); } } else { $('.claims .claim-body .transfer-item').each(function(index, el) { if (el.dataset.transfer == jstClaimData.transferInc) { if ($(el).is('.active')) { jstClaimData.activeClass = 'active'; } $(el).remove(); var h = new EJS({url: '/' + ROOT_PATH + 'jst/jst-claim.ejs'}).render(jstClaimData); $('.claims').show(); $('.claims .claim-body .transfers-container').append(h); } }); } }); } function claimUpdate(peoplesReg) { var curClaim = $('.claim-box').data('claim'); loadPeopleStat(true); claimDetail(curClaim, true); $('.item-tourists .item-content .item-tourist').each(function(index, el) { if ($(el).data('claim') == curClaim) { curFreight = $(el).data('freightdt'); $('.item-freights .item-content .item-freight').each(function(freightIndex, freightEl) { if ($(freightEl).data('freightdt') == curFreight) { freightDetail(freightEl, true); return false; } }); } }); } function getClaimPeopleCheck(curClaimBox) { var peopleCheck = []; curClaimBox.find('.transfer-item.active .claim-tourist').each(function(index, tourist) { if ($(tourist).find('.checkbox input').is(':checked')) { peopleCheck.push(tourist.dataset.inc); } }); return peopleCheck; } function getPeopleFromClaim(curClaim) { var peopleClaim = []; claimData.forEach(function(claim, claimIndex) { if (claim.claimInc == curClaim) { peopleClaim = claim.peoples; } }); return peopleClaim; } function registerPeople(people, action = true) { sendAjax({ m: 'reg_people', reg: people.join(','), unreg: action, l: lang, }, 'peopleReg', { success: function(data) { if (data.length) { claimUpdate(data); isError.reg = false; } else { isError.reg = true; } }, }); } function sortPeopleList(targetDiv) { var touristsList = targetDiv.get(); touristsList.sort(function(a, b) { var compA = $(a).find('._toursitName').text().toUpperCase(); var compB = $(b).find('._toursitName').text().toUpperCase(); return (compA < compB) ? -1 : (compA > compB) ? 1 : 0; }) $.each(touristsList, function(index, el) { targetDiv.parent().append(el); }); } function setReason(people, reason, comment) { sendAjax({ m: 'set_reason', people: people.join(','), reason: reason, comment: comment, l: lang, }, 'reasonSet', { success: function(data) { claimUpdate(data); }, }); } function setPhone(people, phone) { sendAjax({ m: 'set_phone', peopleInc: people.peopleInc, phone: phone, l: lang, }, 'phoneSet', { success: function(data) { claimUpdate(); }, }); } function callPrint(printContent) { var printWin = window.open('','','left=50,top=50,width=800,height=640,toolbar=0,scrollbars=1,status=0'); printWin.document.write(printContent[0].innerHTML); printWin.document.close(); printWin.focus(); printWin.print(); printWin.close(); } function sessionSet(key, value) { sendAjax({ m: 'set_session', key: key, value: value, l: lang, }, 'sessionSet', { success: function(data) {}, }); } function parseInput(inpString) { if (inpString) { if (inpString == 'CONFIRM') { if ($('.claims').is(':visible')) { var curClaimBox = $('.claim-box'); var touristsReg = getClaimPeopleCheck(curClaimBox); registerPeople(touristsReg, true); } } else { // поиск в массиве _prefix начало строки claim, digitsId - индекс соответствия между _prefix и _digits var digitsId = _prefix.findIndex(function(item, index) { if (item == inpString.slice(0, item.length)) { return true; } }); if (digitsId !== -1 && inpString.length == _digits[digitsId]) { // введен номер телефона if ($('.claims').is(':visible')) { var curClaim = $('.claim-box').data('claim'); var touristsList = getPeopleFromClaim(curClaim); setPhone(touristsList[0], inpString); } } else { // введен номер заявки var autoreg = $('.autoreg input').is(':checked'); claimDetail(inpString, false, autoreg); $('body').css('overflow', 'hidden'); } } } } function exportXLS(action) { if (!isLoading.exportXLS) { var exportData = []; if (action == 'unregistered') { var printData = []; $('.item-freights .item-content .item-freight').each(function(index, el) { if ($(el).is('.active')) { // el.dataset.fdate.replace(/\./g, '-') var fdateTemp = el.dataset.fdate.split('.'); fdateTemp = fdateTemp[2] + '-' + fdateTemp[1] + '-' + fdateTemp[0]; printData.push({ inc: el.dataset.freight, fdate: fdateTemp }); } }); document.location.href = '/' + ROOT_PATH + 'index.php?c=airport&a=get&m=print_report&data=' + JSON.stringify(printData); } } } function exportClaimJPG(action) { if( ! isLoading.exportClaimJPG ) { var exportData = []; var printData = {inc:$('._claimID').html()}; var location = '/' + ROOT_PATH + 'index.php?c=airport&a=get&m=print_claim_report&data=' + JSON.stringify(printData); var printWin = window.open(location,'','left=50,top=50,width=800,height=640,toolbar=0,scrollbars=1,status=0'); printWin.addEventListener('load', function(){ printWin.focus(); printWin.print(); setTimeout(function(){ printWin.close(); }, 1000); }); } } function filterTourists(inpString) { $('.item-tourists .item-content .item-tourist').show(); $('.item-tourists .item-content .item-tourist').each(function(index, tourist) { var touristClaim = tourist.dataset.claim, touristClaimTo = tourist.dataset.claimto.toLowerCase(), touristFullname = $(tourist).find('._toursitName').text().trim().toLowerCase(); if (touristClaim.indexOf(inpString) == -1 && touristClaimTo.indexOf(inpString.toLowerCase()) == -1 && touristFullname.indexOf(inpString.toLowerCase()) == -1) { $(tourist).hide(); } }); } function setTheme(theme) { var theme = theme ? 1 : 0; sendAjax({ m: 'set_theme', theme: theme, l: lang, }, 'themeSet', { success: function(data) {}, }); } /* Events */ // Фильтрация туристов $('.item-tourists .tourist-type-all').on('click', function() { touristRegSort('all', 'main'); $('.item-tourists .tourist-type p').removeClass('active'); $(this).addClass('active'); }); $('.item-tourists .tourist-type-reg').on('click', function() { touristRegSort('reg', 'main'); $('.item-tourists .tourist-type p').removeClass('active'); $(this).addClass('active'); }); $('.item-tourists .tourist-type-unreg').on('click', function() { touristRegSort('unreg', 'main'); $('.item-tourists .tourist-type p').removeClass('active'); $(this).addClass('active'); }); // Фильтрация туристов в заявке $('body').on('click', '.claim-tourists .tourist-type-all', function() { touristRegSort('all', 'claim'); $('.claim-tourists .tourist-type p').removeClass('active'); $(this).addClass('active'); }); $('body').on('click', '.claim-tourists .tourist-type-reg', function() { touristRegSort('reg', 'claim'); $('.claim-tourists .tourist-type p').removeClass('active'); $(this).addClass('active'); }); $('body').on('click', '.claim-tourists .tourist-type-unreg', function() { touristRegSort('unreg', 'claim'); $('.claim-tourists .tourist-type p').removeClass('active'); $(this).addClass('active'); }); // Показать детали рейса $('body').on('click', '.item-freight', function() { if (!isLoading.peopleList && !isLoading.transferList) { freightDetail(this); touristRegSort('all', 'main'); $('.item-tourists .tourist-type p').removeClass('active'); } }); // Открыть заявку $('body').on('click', '.item-tourist', function() { claimDetail(this.dataset.claim); }); // Найти заявку $('.claim-search .btn-action').on('click', function() { var claim = $(this).closest('.claim-search').find('.samo-input').val(); $(this).closest('.claim-search').find('.samo-input').val(''); if (claim) { parseInput(claim); } }); $('.claim-search .samo-input').keyup(function(event) { if (event.keyCode == 13) { var claim = $(this).val(); $(this).val(''); if (claim) { parseInput(claim); } return false; } }); // Фильтр туристов по имени или номеру заявки $('.item-tourists ._searchTourists').on('keyup', function() { var query = $(this).val(); filterTourists(query); }); // Фокус на поле поиска заявки $('body').keydown(function() { if (!$('.inputComment').is(':focus') && !$('._searchTourists').is(':focus')) { $('.claim-search .samo-input').focus(); } }); // Закрыть заявку (модальное окно) $('body').on('click', '.samo-modal-close', function() { $('.claims .claim-body .transfers-tabs').empty(); $('.claims .claim-body .transfers-container').empty(); $('.samo-modal-bg').addClass('animated'); $('.samo-modal-bg').hide(); $('body').css('overflow', 'auto'); }); // Регистрация туристов $('body').on('click', '.btn-claim-reg', function() { var curClaimBox = $(this).closest('.claim-box'); var touristsReg = getClaimPeopleCheck(curClaimBox); registerPeople(touristsReg, true); }); // Отмена регистрации $('body').on('click', '.btn-claim-unreg', function() { var curClaimBox = $(this).closest('.claim-box'); var touristsUnreg = getClaimPeopleCheck(curClaimBox); registerPeople(touristsUnreg, false); }); // Оставить комментарий $('body').on('click', '.btn-claim-reason', function() { var commentBox = '.item-comment'; if (!$(commentBox).is(':visible')) { $(commentBox).slideDown(); } else { $(commentBox).slideUp(); } }); $('body').on('click', '.btn-claim-comment', function() { var curClaimBox = $(this).closest('.claim-box'); var tourists = getClaimPeopleCheck(curClaimBox); var reason = $(curClaimBox).find('.inputReason').val(); var comment = $(curClaimBox).find('.inputComment').val(); setReason(tourists, reason, comment); }); $('body').on('click', '.btn-claim-uncomment', function() { var curClaimBox = $(this).closest('.claim-box'); var tourists = getClaimPeopleCheck(curClaimBox); var reason = 'null'; var comment = 'null'; setReason(tourists, reason, comment); }); // Скрывать окно трасфера и туристов, если они пустые var observerTargetTourists = document.getElementById('content-tourists'); if (observerTargetTourists) { var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (!$('#content-tourists').children().length) { $('.item-tourists').addClass('animated'); $('.item-tourists').slideUp(); } else { $('.item-tourists').show(); } }); }); var observerConfig = { attributes: true, childList: true, characterData: true }; observer.observe(observerTargetTourists, observerConfig); } var observerTargetTransfers = document.getElementById('content-transfers'); if (observerTargetTransfers) { var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (!$('#content-transfers').children().length) { $('.item-transfers').addClass('animated'); $('.item-transfers').slideUp(); } else { $('.item-transfers').show(); } }); }); var observerConfig = { attributes: true, childList: true, characterData: true }; observer.observe(observerTargetTransfers, observerConfig); } // Скрывать кнопку "Искать", если поле пустое $('.claim-search .samo-input').on('keyup', function() { if ($(this).val()) { $('.claim-search .btn-action').css({ display: 'inline-block' }); } else { $('.claim-search .btn-action').hide().addClass('animated'); } }); // Открыть печать кода $('.btn-show-code').click(function() { $('.print-code-box').show(); $('body').css('overflow', 'hidden'); }); // Печать кода $('.btn-code-print').click(function() { callPrint($('.print-content')); }); // Открыть "Что нового?" $('.btn-show-about').click(function() { // Добавление истории изменений var versions = messages.versions; var $whatsnewBox = $('._whats-new'); $whatsnewBox.empty(); versions.forEach(function(version) { var versionText = '

'+version.title+'

'+version.info+'

'; $whatsnewBox.prepend(versionText); }); $('.about-box').show(); $('body').css('overflow', 'hidden'); }); // Сброс анимации всплывающего меню пользователя $('body').on('click', '.dropdown', function() { $(this).find('.dropdown-menu').addClass('animated'); }); // Сохранение режима регистрации в $_SESSION['autoreg'] $('.autoreg input').change(function() { var autoreg = $(this).is(':checked'); sessionSet('autoreg', autoreg); return false; }); // Экспорт незарегистрированных туристов в xls $('.btn-export').click(function() { exportXLS($(this).data('export')); }); // Экспорт туристов в xls $('body').on('click','.btn-claim-print', function() { exportClaimJPG($(this).data('export')); }); $('._darkmode input').change(function () { var darkmode = $(this).is(':checked'); if (darkmode) { $('body').addClass('darkmode'); //var darktheme = ''; //$('._darktheme').append(darktheme); } else { $('body').removeClass('darkmode'); //$('._darktheme').empty(); } setTheme(darkmode); }).trigger('change'); /* Don't touch */ $('.tick').css('animation', 'heart 1s infinite ease-in-out'); });