Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function ($) {
- "use strict";
- $.fn.zakupBiletu = function (options) {
- const form = $("#zakup_biletu_form");
- const companionTicketNumber = $("#nr_biletu_osoby_towarzyszacej");
- const coachType = $("#rodzaj_wagonu");
- const wagonClass = $("#klasa_wagonu");
- const politicianMode = $("#tryb_posel");
- const nextButton = $(".dalej_button");
- const previousConnectionButton = $(".przesiadka_prev");
- const nextConnectionButton = $(".przesiadka_next");
- const externalInfoArrow = $(".arrow_box_ext_info");
- const constants = {
- section: {
- FIRST: 1,
- SECOND: 2
- },
- seatType: {
- SEATED: 1
- },
- coachType: {
- QUIET_ZONE: [52, 11],
- CHILD_UNDER_6: [3, 50]
- },
- additionalTicket: {
- BICYCLE: 15
- },
- discount: {
- NO_DISCOUNT: 1,
- RAILWAY_EMPLOYEE: 40,
- RAILWAY_PENSIONER: 41,
- RAILWAY_FAMILY: 42,
- RAILWAY_TECHNICAL_EMPLOYEE: 44,
- CHILD: [71, 77, 78]
- },
- dogTicket: [17, 18, 19],
- familyTicket: {
- MIN_PEOPLE: 2
- },
- miniGroupDiscounts: [
- "36",
- "39",
- "40",
- "41",
- "42",
- "51"
- ]
- };
- let transferStep = 0;
- /*
- * ------------------------------------------------------------------
- * Generic helpers
- * ------------------------------------------------------------------
- */
- function getInt(selector, defaultValue = 0) {
- const value = $(selector).val();
- const parsed = parseInt(value, 10);
- return Number.isNaN(parsed) ? defaultValue : parsed;
- }
- function getSelectedInt(selector, defaultValue = 0) {
- const value = $(selector).find("option:selected").val();
- const parsed = parseInt(value, 10);
- return Number.isNaN(parsed) ? defaultValue : parsed;
- }
- function isChecked(selector) {
- return $(selector).is(":checked");
- }
- function isVisible(selector) {
- return $(selector).is(":visible");
- }
- function exists(selector) {
- return $(selector).length > 0;
- }
- function submitForm() {
- const element = form.get(0);
- if (element) {
- element.submit();
- }
- }
- function hideAllContinueModals() {
- $(".dalej_modal").hide();
- }
- function getPassengerCount(includeThirdDiscount = true) {
- const selectors = [
- "#liczba_n",
- "#liczba_u",
- "#liczba_u_2"
- ];
- if (includeThirdDiscount) {
- selectors.push("#liczba_u_3");
- }
- return selectors.reduce(
- (total, selector) => total + getInt(selector),
- 0
- );
- }
- function getDiscountSelectIds() {
- return [
- "kod_znizki",
- "kod_znizki_2",
- "kod_znizki_3"
- ];
- }
- function getTransferDiscountSelectIds(transferIndex) {
- if (transferIndex === 1) {
- return [
- "kod_znizki_2_1",
- "kod_znizki_2_2",
- "kod_znizki_2_3"
- ];
- }
- return [
- "kod_znizki_3_1",
- "kod_znizki_3_2",
- "kod_znizki_3_3"
- ];
- }
- function setDefaultSelectValue(selector) {
- const element = $(selector);
- if (!element.length) {
- return;
- }
- element.val(element.find("option:first").val());
- }
- /*
- * ------------------------------------------------------------------
- * Validation
- * ------------------------------------------------------------------
- */
- function validateCompanionTicketNumber() {
- if (!companionTicketNumber.is(":visible")) {
- return true;
- }
- const value = $.trim(companionTicketNumber.val());
- const error = $(".nr_osoba_towarz_error");
- const isValid = /^[0-9]+$/.test(value);
- error.find("span").toggle(!isValid);
- return isValid;
- }
- function validateSeatNumberFields(section) {
- const suffix = section > 1 ? `_${section}` : "";
- const fields = [
- `#numer_wagonu${suffix}`,
- `#numer_miejsca${suffix}`
- ];
- let hasError = false;
- fields.forEach((selector) => {
- const input = $(selector);
- if (!input.length || !input.val()) {
- return;
- }
- const isValid = /^\d+$/.test(input.val());
- input
- .toggleClass("error_input", !isValid)
- .closest(".form_wrapper_input")
- .find(".error_info_wskazane_zajete")
- .toggleClass("display-hide", isValid);
- if (!isValid) {
- hasError = true;
- }
- });
- return !hasError;
- }
- function validMiejsceSasiadujaceWskazane(section) {
- const occupiedSeat = $("#rezerwacja_obok_miejsca_juz_zajetego");
- const selectedSeat = $(
- `#rezerwacja_miejsca_wskazanego${section > 1 ? `_${section}` : ""}`
- );
- if (!occupiedSeat.is(":checked") && !selectedSeat.is(":checked")) {
- return true;
- }
- return validateSeatNumberFields(section);
- }
- /*
- * ------------------------------------------------------------------
- * Employee / railway discounts
- * ------------------------------------------------------------------
- */
- function getRailwayEmployeeDiscountCount() {
- const railwayDiscounts = [
- constants.discount.RAILWAY_EMPLOYEE,
- constants.discount.RAILWAY_PENSIONER,
- constants.discount.RAILWAY_FAMILY,
- constants.discount.RAILWAY_TECHNICAL_EMPLOYEE
- ];
- const discountIds = [
- "kod_znizki",
- "kod_znizki_2",
- "kod_znizki_3"
- ];
- const passengerIds = [
- "liczba_u",
- "liczba_u_2",
- "liczba_u_3"
- ];
- return discountIds.reduce((total, discountId, index) => {
- const discountCode = getSelectedInt(`#${discountId}`);
- if (!railwayDiscounts.includes(discountCode)) {
- return total;
- }
- return total + getSelectedInt(`#${passengerIds[index]}`);
- }, 0);
- }
- function containsMixedRailwayDiscounts() {
- const employeeDiscounts = [40, 41];
- const familyDiscounts = [42, 44];
- const discountIds = [
- "kod_znizki",
- "kod_znizki_2",
- "kod_znizki_3",
- "kod_znizki_2_1",
- "kod_znizki_2_2",
- "kod_znizki_2_3"
- ];
- let hasEmployeeDiscount = false;
- let hasFamilyDiscount = false;
- discountIds.forEach((id) => {
- const code = getSelectedInt(`#${id}`);
- if (employeeDiscounts.includes(code)) {
- hasEmployeeDiscount = true;
- }
- if (familyDiscounts.includes(code)) {
- hasFamilyDiscount = true;
- }
- });
- return hasEmployeeDiscount && hasFamilyDiscount;
- }
- /*
- * ------------------------------------------------------------------
- * Dog / additional ticket handling
- * ------------------------------------------------------------------
- */
- function AdditionalTicketService() {
- function isSleepingOrCouchette() {
- return getSelectedInt(".rodzaj_miejsca") > 1;
- }
- function hasDogTicket() {
- return $(".bilet_dodatkowy").toArray().some((element) => {
- return constants.dogTicket.includes(
- parseInt($(element).val(), 10)
- );
- });
- }
- function getTotalPassengerCount() {
- return [
- "#liczba_n",
- "#liczba_u",
- "#liczba_u_2",
- "#liczba_u_3"
- ].reduce((total, selector) => {
- return total + getInt(selector);
- }, 0);
- }
- function isWholeCompartmentRequiredForDog() {
- if (!isSleepingOrCouchette() || !hasDogTicket()) {
- return false;
- }
- const compartmentCapacity = getInt("#przedzial");
- const beds = $("#llozek");
- const passengerCount = getTotalPassengerCount();
- if (passengerCount < compartmentCapacity) {
- return true;
- }
- return (
- beds.is(":visible") &&
- getInt("#llozek") < passengerCount
- );
- }
- return {
- czyNieWybranoCalegoPrzedzialuDlaPsa:
- isWholeCompartmentRequiredForDog
- };
- }
- /*
- * ------------------------------------------------------------------
- * Child / adult sleeping arrangement
- * ------------------------------------------------------------------
- */
- function czyWybranoWspolneUsytuowanieNaJednymLozkuDzieckoOpiekun() {
- const beds = $("#llozek");
- const adults = $("#liczba_n");
- if (
- getSelectedInt(".rodzaj_miejsca") ===
- constants.seatType.SEATED ||
- !beds.is(":visible")
- ) {
- return false;
- }
- const childDiscounts = constants.discount.CHILD;
- const discountIds = [
- "kod_znizki",
- "kod_znizki_2",
- "kod_znizki_3"
- ];
- const passengerIds = [
- "liczba_u",
- "liczba_u_2",
- "liczba_u_3"
- ];
- let adultCount = getInt("#liczba_n");
- let childCount = 0;
- const discountWrapper = "#rodzaj_ulgi_wrap_2";
- discountIds.forEach((discountId, index) => {
- const discountSelector =
- index === 0
- ? `${discountWrapper} #${discountId}`
- : `#${discountId}`;
- const discountCode = getInt(discountSelector);
- const passengerCount = getInt(
- `#${passengerIds[index]}`
- );
- if (childDiscounts.includes(discountCode)) {
- childCount += passengerCount;
- } else if (
- discountCode !== constants.discount.NO_DISCOUNT
- ) {
- adultCount += passengerCount;
- }
- });
- $("#osobne_lozko_dla_dziecka_wrapper").hide();
- $("#osobne_lozko_dla_dziecka").prop("checked", false);
- const totalPassengers = adultCount + childCount;
- const bedCount = getInt("#llozek");
- return bedCount > 0 && totalPassengers > bedCount;
- }
- /*
- * ------------------------------------------------------------------
- * Child under 6 validation
- * ------------------------------------------------------------------
- */
- function czyPrzedzialDlaOsobyZDzieckiemDoLat6() {
- return getInt("#rodzaj_wagonu") === 3;
- }
- function showChildUnderSixModal(input) {
- hideAllContinueModals();
- $("#dalej_modal_inform").hide();
- $("#dalej_modal_tak").hide();
- $("#dalej_modal_dla_podr_z_dzieckiem_do_lat_6").show();
- $("#dalej_modal_footer").show();
- const modalOk = $("#dalej_modal_ok");
- modalOk
- .val(modalOk.attr("v1"))
- .attr("type", "button")
- .addClass("js-modal-close")
- .off("click.zakupBiletu")
- .on("click.zakupBiletu", function () {
- submitForm();
- });
- $(input).okienkoModalne().open();
- }
- function czyWybranoDlaPodroznychZDziecmiDoLat6(
- input,
- childCoachTypes,
- startingCategory
- ) {
- const coachTypeForSection = getSelectedInt(
- "#rodzaj_wagonu_odcinek_2"
- );
- if (!childCoachTypes.includes(coachTypeForSection)) {
- return false;
- }
- const passengerCount = [
- "#liczba_n",
- "#liczba_u_2_1",
- "#liczba_u_2_2"
- ].reduce(
- (total, selector) => total + getSelectedInt(selector),
- 0
- );
- if (passengerCount < 2) {
- return false;
- }
- if (startingCategory === 81 && passengerCount > 4) {
- return false;
- }
- showChildUnderSixModal(input);
- return true;
- }
- /*
- * ------------------------------------------------------------------
- * Modal service
- * ------------------------------------------------------------------
- */
- function ModalService() {
- const modal = $("#dalej_modal_ok");
- function prepareCommonModal() {
- $("#dalej_modal_footer").show();
- $("#dalej_modal_inform").hide();
- $("#dalej_modal_tak").hide();
- $("#dalej_modal_nie").hide();
- $("#dalej_modal_false").hide();
- $("#dalej_modal_header_informacja").show();
- $("#dalej_modal_header_uwaga").hide();
- }
- function showAtention() {
- $("#dalej_modal_footer").show();
- $("#dalej_modal_pracownik_kolei").hide();
- $("#dalej_modal_kolejarz_przesiadka").show();
- $("#dalej_modal_inform").show();
- $("#dalej_modal_tak").hide();
- $("#dalej_modal_nie").hide();
- $("#dalej_modal_false").hide();
- modal.hide();
- $("#dalej_modal_header_informacja").hide();
- $("#dalej_modal_header_uwaga").show();
- }
- function showDogCompartmentWarning() {
- prepareCommonModal();
- $("#dalej_modal_pies_caly_przedzial").show();
- modal
- .val(modal.attr("v4"))
- .attr("type", "button")
- .addClass("js-modal-close");
- }
- function showChildAdultSharedBedWarning() {
- ZakupBiletuUtil().showOkienkoModalne(
- this,
- "dalej_modal_wspolne_usytuowanie_lozko_dziecko_opiekun"
- );
- }
- function showChildAdultSharedBedCovidWarning() {
- prepareCommonModal();
- $("#dalej_modal_wspolne_usytuowanie_lozko_dziecko_opiekunCOVID").show();
- $("#dalej_modal_false").show();
- modal
- .val(modal.attr("v5"))
- .hide()
- .removeClass("js-modal-close");
- }
- function showFalseModal() {
- prepareCommonModal();
- $("#dalej_modal_false").show();
- modal
- .attr("type", "submit")
- .removeClass("js-modal-close")
- .show();
- }
- function showDefault() {
- prepareCommonModal();
- modal
- .attr("type", "button")
- .addClass("js-modal-close");
- }
- function showPossibleMiniGroup() {
- prepareCommonModal();
- $("#dalej_modal_tak").show();
- $("#dalej_modal_nie").show();
- modal
- .attr("type", "submit")
- .removeClass("js-modal-close")
- .hide();
- }
- function showHiddenStation() {
- prepareCommonModal();
- $("#dalej_modal_false").show();
- modal
- .attr("type", "submit")
- .removeClass("js-modal-close")
- .val("Tak")
- .show();
- }
- function showInternationalDateWarning() {
- ZakupBiletuUtil().showOkienkoModalne(
- this,
- "dalej_modal_wymiana_mm_niechronologiczne_daty"
- );
- }
- function showMetropolitanChildWarning() {
- ZakupBiletuUtil().showOkienkoModalne(
- this,
- "dalej_modal_dziecko_metropol"
- );
- }
- function showRailwayEmployeePolbusModal(element) {
- ZakupBiletuUtil().showModalInfo(
- element,
- "dalej_modal_kolejarz_przesiadka"
- );
- }
- this.dalejModalAtention = showAtention;
- this.dalejModalBiletPiesCalyPrzedzial =
- showDogCompartmentWarning;
- this.dalejModalJednoLozkoDzieckoOpiekun =
- showChildAdultSharedBedWarning;
- this.dalejModalJednoLozkoDzieckoOpiekunCOVID =
- showChildAdultSharedBedCovidWarning;
- this.dalejModalFalse = showFalseModal;
- this.dalejModalDefault = showDefault;
- this.dalejModalMozliwaMiniGrupa =
- showPossibleMiniGroup;
- this.dalejModalStacjaNiejawna = showHiddenStation;
- this.dalejModalMiedzynarodowyNiechronologiczneDaty =
- showInternationalDateWarning;
- this.dalejModalMiedzynarodowyDzieckoMetropol =
- showMetropolitanChildWarning;
- this.modalZnizkiDlaKolejarzaPolbus =
- showRailwayEmployeePolbusModal;
- }
- /*
- * ------------------------------------------------------------------
- * Transfer handling
- * ------------------------------------------------------------------
- */
- function TransferService() {
- this.indexPrzesiadki = 0;
- this.setIndexPrzesiadki = function (index) {
- this.indexPrzesiadki = index;
- };
- this.getindexPrzesiadki = function () {
- return this.indexPrzesiadki;
- };
- this.zablokujPolaDlaPrzesiadkiZakupowej =
- function (sectionIndex) {
- lockFieldsForTransfer.call(this, sectionIndex);
- };
- this.odblokujPolaDlaPrzesiadkiZakupowej =
- function () {
- unlockFieldsAfterTransfer.call(this);
- };
- this.aktywujDeaktywujElementy =
- function () {
- activateTransferSection.call(this);
- };
- this.obslugaZnizkeDlaPrzesiadki =
- function () {
- handleTransferDiscounts.call(this);
- };
- this.pobierzZnizkiDlaPrzesiadki =
- function (sectionIndex) {
- loadTransferDiscounts(sectionIndex);
- };
- this.obslugaBiletRodzinny_DuzaRodzina =
- function () {
- handleFamilyTicketVisibility.call(this);
- };
- }
- function lockFieldsForTransfer(sectionIndex) {
- const elementsToShow = sectionIndex > 1
- ? [
- ".submit_powrot_zakup_biletu",
- ".dalej_button",
- ".przesiadka_info2_parametry",
- "#rodzaj_wagonu_odcinek_3",
- "#usytuowanie_przesiadka_3"
- ]
- : [
- ".submit_powrot_zakup_biletu",
- ".dalej_button",
- ".przesiadka_info_parametry",
- "#rodzaj_wagonu_odcinek_2",
- "#usytuowanie_przesiadka_2"
- ];
- const elementsToHide = sectionIndex > 1
- ? [
- ".przesiadka_info_parametry",
- "#rodzaj_wagonu_odcinek_2",
- "#usytuowanie_przesiadka_2"
- ]
- : [
- ".przesiadka_info2_parametry",
- "#rodzaj_wagonu_odcinek_3",
- "#usytuowanie_przesiadka_3"
- ];
- $(".opcja_biletu_rodzinny").each(function () {
- _addInputKDFiBR(
- $(this),
- $(this).is(":checked") ? 1 : 0
- );
- });
- $("#pokaz_kolorowa_karte").prop("disabled", true);
- $(".rodzaj_miejsca")
- .not(":checked")
- .prop("disabled", true);
- $(".remove_additional_ticket").hide();
- _ustawMiejsceZajeteWskazaneMIejsce(sectionIndex);
- toggleTransferElements(
- {
- id: [
- "tr_rodzaj_miejsca",
- "tr_promocja",
- "tr_liczba_osob_n",
- "tr_kod_znizki",
- "tr_kod_znizki_2",
- "tr_kod_znizki_3",
- "tr_nr_taryfy_II",
- "tr_nr_taryfy_I",
- "tr_przedzial",
- "tr_plec",
- "tr_klasa",
- "tr_kolorowa_karta_ic",
- "tr_pokaz_kolorowa_karte",
- "tr_bilety_dodatkowe"
- ],
- class: ["bilet_karta_rodziny_main_wrapper"]
- },
- false
- );
- elementsToHide.forEach((selector) => $(selector).hide());
- elementsToShow.forEach((selector) => $(selector).show());
- $("#rodzaj_wagonu, #usytuowanie").hide();
- this.obslugaZnizkeDlaPrzesiadki();
- $("#tr_pokaz_karte_duzej_rodziny").hide();
- $("#tr_pokaz_bilet_rodzinny").hide();
- }
- function unlockFieldsAfterTransfer() {
- const currentIndex = this.getindexPrzesiadki();
- const elementsToHide = [
- ".submit_powrot_zakup_biletu",
- ".przesiadka_info_parametry",
- ".przesiadka_info2_parametry",
- "#rodzaj_wagonu_odcinek_2",
- "#rodzaj_wagonu_odcinek_3",
- "#usytuowanie_przesiadka_2",
- "#usytuowanie_przesiadka_3",
- "#tr_liczba_osob_n_2",
- "#liczba_u_2_1",
- "#liczba_u_2_2",
- "#liczba_u_2_3",
- "#tr_liczba_osob_n_3",
- "#liczba_u_3_1",
- "#liczba_u_3_2",
- "#liczba_u_3_3"
- ];
- _removeInputKDRiBR();
- $("#pokaz_kolorowa_karte").prop("disabled", false);
- $(".rodzaj_miejsca").prop("disabled", false);
- $(".remove_additional_ticket").show();
- _ustawMiejsceZajeteWskazaneMIejsce(currentIndex);
- toggleTransferElements(
- {
- id: [
- "tr_rodzaj_miejsca",
- "tr_promocja",
- "tr_liczba_osob_n",
- "tr_kod_znizki",
- "tr_kod_znizki_2",
- "tr_kod_znizki_3",
- "tr_nr_taryfy_II",
- "tr_nr_taryfy_I",
- "tr_przedzial",
- "tr_plec",
- "tr_klasa",
- "tr_kolorowa_karta_ic",
- "tr_pokaz_kolorowa_karte",
- "tr_bilety_dodatkowe"
- ],
- class: ["bilet_karta_rodziny_main_wrapper"]
- },
- true
- );
- elementsToHide.forEach((selector) => $(selector).hide());
- [
- "#liczba_u",
- "#liczba_u_2",
- "#liczba_u_3"
- ].forEach((selector) => {
- $(selector).removeClass("przesiadka_hide_elem");
- });
- $("#rodzaj_wagonu, #usytuowanie").show();
- this.obslugaZnizkeDlaPrzesiadki();
- }
- function activateTransferSection() {
- const index = this.getindexPrzesiadki();
- $(".przesiadka_linia_wrapper").each(function (elementIndex) {
- $(this)
- .toggleClass(
- "przesiadka_linia_active",
- elementIndex === index
- )
- .toggleClass(
- "przesiadka_linia_deactive",
- elementIndex !== index
- );
- });
- $(".przesiadka_konfiguracja_wypis").each(function (
- elementIndex
- ) {
- $(this).toggle(elementIndex === index);
- });
- $(".przesiadka_prev_bg").toggleClass(
- "przesiadka_aktywny_odcinek",
- index === 0
- );
- $(".przesiadka_next_bg").toggleClass(
- "przesiadka_aktywny_odcinek",
- index === 1
- );
- $(".przesiadka_next_next_bg").toggleClass(
- "przesiadka_aktywny_odcinek",
- index === 2
- );
- if (index > 0) {
- $("#rodzaj_wagonu_msg").hide();
- }
- $("#indexPrzesiadki").val(index);
- $(".przesiadka_info_znizka_rozne_kategorie").hide();
- this.obslugaBiletRodzinny_DuzaRodzina();
- $(".znizki_przesiadki2_wrapper")
- .addClass("przesiadka_hide_elem");
- }
- function handleFamilyTicketVisibility() {
- const currentIndex = this.getindexPrzesiadki();
- [
- ["karta_duzej_rodziny", "tr_pokaz_karte_duzej_rodziny"],
- ["bilet_rodzinny", "tr_pokaz_bilet_rodzinny"]
- ].forEach(([inputId, rowId]) => {
- if (!isChecked(`#${inputId}`)) {
- return;
- }
- $(`#${rowId} .form_wrapper_input`)
- .toggleClass(
- "przesiadka_hide_elem",
- currentIndex !== 1
- );
- });
- }
- function handleTransferDiscounts() {
- const currentSection = this.getindexPrzesiadki();
- if (currentSection > 0) {
- this.pobierzZnizkiDlaPrzesiadki(currentSection);
- return;
- }
- const firstSectionDiscounts = getDiscountSelectIds();
- [
- "#tr_kod_znizki",
- "#tr_kod_znizki_2",
- "#tr_kod_znizki_3"
- ].forEach((selector) => {
- const wrapper = $(selector);
- wrapper
- .removeClass("przesiadka_hide_elem")
- .find(".znizki_wrapper_ulga_ilosc")
- .removeClass("przesiadka_hide_elem");
- wrapper.find(".znizki_wrapper_ulga_nazwa div").each(
- function () {
- const element = $(this);
- if (
- element.hasClass(
- "znizki_przesiadki_wrapper"
- )
- ) {
- element.hide();
- } else {
- element.removeClass(
- "przesiadka_hide_elem"
- );
- }
- }
- );
- });
- const hasDiscount = firstSectionDiscounts.some(
- (selector) => getInt(`#${selector}`) > 1
- );
- $("#tr_miejsce_wskazane").toggle(!hasDiscount);
- $(".znizki_przesiadki_wrapper").hide();
- $("#kod_znizki_opis").removeClass("przesiadka_hide_elem");
- $(".przesiadka_info_brak_znizki").hide();
- const selectedDiscount = getInt("#kod_znizki");
- const specialDiscounts = [77, 79, 84];
- if (
- getInt("#liczba_n") === 0 &&
- getInt("#liczba_u") === 1 &&
- !specialDiscounts.includes(selectedDiscount)
- ) {
- $("#tr_miejsce_wskazane").show();
- }
- }
- function loadTransferDiscounts(sectionIndex) {
- $.ajax({
- method: "GET",
- url: "/zakup-biletu-utils",
- cache: false,
- data: {
- nr_odc: sectionIndex,
- action: "pobierzZnizkiPrzesiadki",
- karta_duzej_rodziny: isChecked(
- "#karta_duzej_rodziny"
- ),
- bilet_rodzinny: isChecked("#bilet_rodzinny"),
- klasa_wagonu: $("#klasa_wagonu").val()
- },
- beforeSend() {
- $(".zakup_biletu_form_main_wrapper")
- .append('<div class="loadmask"></div>');
- },
- success(data) {
- let result;
- try {
- result =
- typeof data === "string"
- ? JSON.parse(data)
- : data;
- } catch (error) {
- console.error(
- "Unable to parse transfer discounts response.",
- error
- );
- return;
- }
- fillTransferDiscounts(result, sectionIndex);
- handleDiscountsForSection(sectionIndex);
- ObslugaKlopotliwychZnizek().run(sectionIndex);
- handleTransferElements();
- },
- error(xhr, status, error) {
- console.error(
- "Unable to load transfer discounts.",
- status,
- error
- );
- },
- complete() {
- $(".loadmask").remove();
- }
- });
- }
- function fillTransferDiscounts(options, sectionIndex) {
- const sourceDiscounts = getDiscountSelectIds();
- const targetDiscounts =
- sectionIndex === 2
- ? [
- "#kod_znizki_3_1",
- "#kod_znizki_3_2",
- "#kod_znizki_3_3"
- ]
- : [
- "#kod_znizki_2_1",
- "#kod_znizki_2_2",
- "#kod_znizki_2_3"
- ];
- sourceDiscounts.forEach((sourceSelector, index) => {
- const source = $(sourceSelector);
- if (getInt(sourceSelector) <= 0) {
- return;
- }
- const target = $(targetDiscounts[index]);
- const discounts = options[`znizki_${index}`] || [];
- target.empty();
- discounts.forEach((discount) => {
- target.append(discount.option);
- });
- });
- }
- function handleTransferElements() {
- const sectionIndex = getInt("#indexPrzesiadki");
- if (sectionIndex !== 1 && sectionIndex !== 2) {
- return;
- }
- const discountIds =
- getTransferDiscountSelectIds(sectionIndex);
- const hasDiscount = discountIds.some(
- (id) => getInt(`#${id}`) > 1
- );
- const suffix = sectionIndex === 1 ? "_2" : "_3";
- if (hasDiscount) {
- $(
- `#tr_rezerwacja_obok_miejsca_juz_zajetego_wagon${suffix}`
- ).hide();
- $(
- `#tr_rezerwacja_obok_miejsca_juz_zajetego_miejsce${suffix}`
- ).hide();
- $(
- `#rezerwacja_miejsca_wskazanego${suffix}`
- ).prop("checked", false);
- $(`#numer_wagonu${suffix}`).val("");
- $(`#numer_miejsca${suffix}`).val("");
- } else {
- $("#tr_miejsce_wskazane").show();
- }
- }
- function handleDiscountsForSection(section) {
- const firstSectionDiscounts =
- section === 2
- ? [
- "#kod_znizki_2_1",
- "#kod_znizki_2_2",
- "#kod_znizki_2_3"
- ]
- : getDiscountSelectIds();
- const secondSectionDiscounts =
- section === 2
- ? [
- "#kod_znizki_3_1",
- "#kod_znizki_3_2",
- "#kod_znizki_3_3"
- ]
- : [
- "#kod_znizki_2_1",
- "#kod_znizki_2_2",
- "#kod_znizki_2_3"
- ];
- const wrappers = [
- "#tr_kod_znizki",
- "#tr_kod_znizki_2",
- "#tr_kod_znizki_3"
- ];
- const matchedDiscounts = [];
- const missingDiscounts = [];
- firstSectionDiscounts.forEach((selector, index) => {
- const selectedOption = $(
- `${selector} option:selected`
- );
- const code = selectedOption.val();
- const name = $.trim(selectedOption.text());
- if (parseInt(code, 10) <= 1) {
- return;
- }
- const target = $(secondSectionDiscounts[index]);
- let matchingOption = null;
- target.find("option").each(function () {
- if (
- $.trim($(this).text()) === name
- ) {
- matchingOption = $(this);
- return false;
- }
- });
- if (matchingOption) {
- matchedDiscounts[index] = {
- id: matchingOption.val(),
- name
- };
- } else {
- missingDiscounts[index] = {
- id: code,
- name
- };
- }
- const wrapper = $(wrappers[index]);
- wrapper
- .find(".znizki_wrapper_ulga_ilosc")
- .addClass("przesiadka_hide_elem");
- wrapper
- .find(".znizki_wrapper_ulga_nazwa div")
- .each(function () {
- const element = $(this);
- if (
- element.hasClass(
- "znizki_przesiadki_wrapper"
- )
- ) {
- element.show();
- } else {
- element.addClass(
- "przesiadka_hide_elem"
- );
- }
- });
- });
- const missingDiscount =
- missingDiscounts.find(Boolean);
- if (missingDiscount) {
- handleMissingTransferDiscount(
- missingDiscount,
- section
- );
- } else {
- copyPassengerCounts(section);
- }
- matchedDiscounts.forEach((discount, index) => {
- if (discount) {
- $(secondSectionDiscounts[index]).val(
- discount.id
- );
- }
- });
- }
- function handleMissingTransferDiscount(
- missingDiscount,
- section
- ) {
- const categories =
- section === 2
- ? [
- getInt("#train_category_2"),
- getInt("#train_category_3")
- ]
- : [
- getInt("#train_category_1"),
- getInt("#train_category_2")
- ];
- const problematicDiscounts =
- ObslugaKlopotliwychZnizek();
- const isProblematicRoute =
- problematicDiscounts.isPociagKat_EIP_EIC_AND_TLK_IC(
- categories[0],
- categories[1]
- ) ||
- problematicDiscounts.isPociagKat_TLK_IC_AND_EIP_EIC(
- categories[0],
- categories[1]
- );
- if (isProblematicRoute) {
- const info = $(".przesiadka_info_brak_znizki");
- info.show()
- .find("span")
- .text(`"${missingDiscount.name}"`);
- }
- $("#kod_znizki_opis").addClass(
- "przesiadka_hide_elem"
- );
- const passengerCountId =
- section === 2
- ? "#tr_liczba_osob_n_3"
- : "#tr_liczba_osob_n_2";
- $(passengerCountId).show();
- const countSuffix = section === 2 ? "_3" : "_2";
- missingDiscountsForSection(section).forEach(
- (_, index) => {
- const wrapper = $(
- `#tr_kod_znizki${index > 0 ? `_${index + 1}` : ""}`
- );
- wrapper.removeClass(
- "przesiadka_hide_elem"
- );
- wrapper
- .find(".znizki_wrapper_ulga_ilosc")
- .removeClass("przesiadka_hide_elem");
- $(
- `#liczba_u${countSuffix}_${index + 1}`
- ).show();
- }
- );
- }
- function missingDiscountsForSection(section) {
- return getTransferDiscountSelectIds(section)
- .map((id) => $(id))
- .filter((element) => element.length);
- }
- function copyPassengerCounts(section) {
- if (section === 2) {
- $("#liczba_n_3").val($("#liczba_n_2").val());
- const categories = [
- getInt("#train_category_1"),
- getInt("#train_category_3")
- ];
- const service =
- ObslugaKlopotliwychZnizek();
- const requiresAdditionalFields =
- service.isPociagKat_EIP_EIC_AND_TLK_IC(
- categories[0],
- categories[1]
- ) ||
- service.isPociagKat_TLK_IC_AND_EIP_EIC(
- categories[0],
- categories[1]
- );
- if (requiresAdditionalFields) {
- getDiscountSelectIds().forEach(
- (_, index) => {
- $(
- `#tr_kod_znizki${index > 0 ? `_${index + 1}` : ""}`
- )
- .removeClass(
- "przesiadka_hide_elem"
- )
- .find(
- ".znizki_wrapper_ulga_ilosc"
- )
- .removeClass(
- "przesiadka_hide_elem"
- );
- $(
- `#liczba_u_3_${index + 1}`
- ).show();
- }
- );
- $("#tr_liczba_osob_n_3").toggle(
- getDiscountSelectIds().some(
- (id) => getInt(`#${id}`) > 1
- )
- );
- }
- } else {
- $("#liczba_n_2").val($("#liczba_n").val());
- }
- const passengerMappings =
- section === 2
- ? [
- ["liczba_u_2_1", "liczba_u_3_1"],
- ["liczba_u_2_2", "liczba_u_3_2"],
- ["liczba_u_2_3", "liczba_u_3_3"]
- ]
- : [
- ["liczba_u", "liczba_u_2_1"],
- ["liczba_u_2", "liczba_u_2_2"],
- ["liczba_u_3", "liczba_u_2_3"]
- ];
- passengerMappings.forEach(([source, target]) => {
- $(`#${target}`).val($(`#${source}`).val());
- });
- }
- }
- /*
- * ----------------------------------------------------------------------
- * Transfer helper functions
- * ----------------------------------------------------------------------
- */
- function toggleTransferElements(elements, show) {
- Object.entries(elements).forEach(([type, selectors]) => {
- selectors.forEach((selector) => {
- const elementsToToggle =
- type === "id"
- ? $(`#${selector}`)
- : $(`.${selector}`);
- elementsToToggle.toggleClass(
- "przesiadka_hide_elem",
- !show
- );
- });
- });
- }
- function _addInputKDFiBR(element, value) {
- form.append(
- $("<input>", {
- class:
- "opcja_biletu_rodzinny_mock display-hide",
- type: "checkbox",
- name: element.attr("name"),
- value
- })
- );
- }
- function _removeInputKDRiBR() {
- form
- .find(".opcja_biletu_rodzinny_mock")
- .remove();
- }
- function _ustawMiejsceZajeteWskazaneMIejsce(section) {
- const suffix =
- section === 0
- ? ""
- : `_${section + 1}`;
- const previousSuffixes = ["", "_2", "_3"];
- const elementIds = [
- "rezerwacja_obok_miejsca_juz_zajetego",
- "rezerwacja_miejsca_wskazanego",
- "tr_rezerwacja_obok_miejsca_juz_zajetego_wagon",
- "tr_rezerwacja_obok_miejsca_juz_zajetego_miejsce"
- ];
- previousSuffixes.forEach((currentSuffix, index) => {
- elementIds.forEach((id) => {
- const element = $(`#${id}${currentSuffix}`);
- if (!element.length) {
- return;
- }
- element.toggle(index === section);
- });
- });
- const wagonSection = $(
- `#tr_rezerwacja_obok_miejsca_juz_zajetego_wagon${suffix}`
- );
- const seatSection = $(
- `#tr_rezerwacja_obok_miejsca_juz_zajetego_miejsce${suffix}`
- );
- const occupiedSeat = $(
- `#rezerwacja_obok_miejsca_juz_zajetego${suffix}`
- );
- const selectedSeat = $(
- `#rezerwacja_miejsca_wskazanego${suffix}`
- );
- const shouldShow =
- occupiedSeat.is(":checked") ||
- selectedSeat.is(":checked");
- wagonSection.toggle(shouldShow);
- seatSection.toggle(shouldShow);
- if (section === 0) {
- wagonSection.removeClass(
- "display-hide-important"
- );
- seatSection.removeClass(
- "display-hide-important"
- );
- } else {
- wagonSection.addClass(
- "display-hide-important"
- );
- seatSection.addClass(
- "display-hide-important"
- );
- }
- }
- /*
- * ----------------------------------------------------------------------
- * Main "Next" button logic
- * ----------------------------------------------------------------------
- */
- function handleNextClick(event) {
- event.preventDefault();
- const button = $(this);
- const quietZoneCoachTypes =
- constants.coachType.QUIET_ZONE;
- const childUnderSixCoachTypes =
- constants.coachType.CHILD_UNDER_6;
- const coachTypeValue =
- getSelectedInt("#rodzaj_wagonu");
- const transferCoachType1 =
- getInt("#rodzaj_wagonu_odcinek_2");
- const transferCoachType2 =
- getInt("#rodzaj_wagonu_odcinek_3");
- const isDomestic = button.attr("krajowy");
- const startingCategory =
- getInt(button, 0) ||
- parseInt(button.attr("kat_poc"), 10);
- const isFamilyCard =
- isChecked("#karta_duzej_rodziny");
- const isFamilyTicket =
- isChecked("#bilet_rodzinny");
- const isMiniGroup =
- $("#mini_grupa").val() === "1";
- const isTodayRelation =
- $("#relacja_na_dzisiaj").val() === "1";
- const minimumFamilyPassengers =
- getInt("#bilet_rodzinny_min_liczba_osob");
- let isTransfer =
- ParamUtil.parseBoolean(
- button.attr("przesiadka")
- );
- const hasTwoTransfers =
- ParamUtil.parseBoolean(
- button.attr("przesiadki2")
- );
- const ignoreSection =
- ParamUtil.parseBoolean(
- button.attr("ignoruj_odc")
- );
- if (ignoreSection) {
- isTransfer = false;
- }
- /*
- * Validate seat number fields before doing anything else.
- */
- if (
- !validMiejsceSasiadujaceWskazane(
- constants.section.FIRST
- )
- ) {
- return;
- }
- if (!validateCompanionTicketNumber()) {
- return;
- }
- hideAllContinueModals();
- const modalState = {
- open: false,
- attention: false,
- dogCompartment: false,
- childAdultBed: false,
- childAdultBedCovid: false,
- internationalDates: false,
- metropolitanChild: false,
- possibleMiniGroup: false
- };
- /*
- * --------------------------------------------------------------
- * Domestic ticket validation
- * --------------------------------------------------------------
- */
- if (isDomestic) {
- /*
- * Quiet zone
- */
- if (
- (
- quietZoneCoachTypes.includes(coachTypeValue) ||
- quietZoneCoachTypes.includes(
- transferCoachType1
- )
- ) &&
- !isTransfer
- ) {
- modalState.open = true;
- $("#dalej_modal_strefa_ciszy").show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v1")
- );
- }
- /*
- * Passenger travelling with a child under 6.
- */
- if (
- transferStep === 0 &&
- childUnderSixCoachTypes.includes(coachTypeValue) &&
- !AdditionalTicketService()
- .czyNieWybranoCalegoPrzedzialuDlaPsa()
- ) {
- const passengerCount =
- getPassengerCount();
- if (
- passengerCount >= 2 &&
- (startingCategory !== 81 ||
- passengerCount <= 4)
- ) {
- modalState.open = true;
- $("#dalej_modal_dla_podr_z_dzieckiem_do_lat_6")
- .show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v1")
- );
- }
- }
- /*
- * Family ticket.
- */
- if (isFamilyTicket) {
- handleFamilyTicketValidation(
- modalState,
- isMiniGroup,
- minimumFamilyPassengers
- );
- } else if (isFamilyCard) {
- modalState.open = true;
- $("#dalej_modal_duza_rodzina").show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v2")
- );
- } else if (
- isMiniGroup &&
- !isTodayRelation
- ) {
- handlePossibleMiniGroup(
- modalState,
- minimumFamilyPassengers
- );
- }
- /*
- * Railway employees.
- */
- if (
- getRailwayEmployeeDiscountCount() > 1 &&
- !ZakupBiletuUtil().isPolbus()
- ) {
- modalState.open = true;
- $("#dalej_modal_pracownik_kolei").show();
- }
- /*
- * Dog compartment.
- */
- if (
- AdditionalTicketService()
- .czyNieWybranoCalegoPrzedzialuDlaPsa()
- ) {
- modalState.open = true;
- modalState.dogCompartment = true;
- }
- /*
- * Child + adult sharing one bed.
- */
- if (
- czyWybranoWspolneUsytuowanieNaJednymLozkuDzieckoOpiekun()
- ) {
- modalState.open = true;
- if (ZakupBiletuUtil().isCOVID()) {
- modalState.childAdultBedCovid = true;
- } else {
- modalState.childAdultBed = true;
- }
- }
- /*
- * Child compartment.
- */
- if (czyPrzedzialDlaOsobyZDzieckiemDoLat6()) {
- modalState.open = true;
- $("#dalej_modal_przedzial_dla_osoby_z_dzieckiem_do_lat_6")
- .show();
- }
- }
- /*
- * Metropolitan child.
- */
- if (exists("#dalej_modal_dziecko_metropol")) {
- const adultCount = getInt("#liczba_n");
- const reducedPassengerCount = getInt("#liczba_u");
- const tariff = getInt("#nrTaryfyII");
- if (
- adultCount === 0 &&
- reducedPassengerCount > 0 &&
- tariff === 73
- ) {
- modalState.open = true;
- modalState.metropolitanChild = true;
- }
- }
- /*
- * Bicycle ticket exception.
- */
- if (exists(".bilet_dodatkowy")) {
- $(".bilet_dodatkowy").each(function () {
- const selectedTicket = parseInt(
- $(this).find("option:selected").val(),
- 10
- );
- if (
- selectedTicket ===
- constants.additionalTicket.BICYCLE &&
- !isFamilyTicket &&
- !isMiniGroup
- ) {
- modalState.open = false;
- }
- });
- }
- /*
- * International exchange with non-chronological dates.
- */
- if (
- exists(
- "#dalej_modal_wymiana_mm_niechronologiczne_daty"
- )
- ) {
- modalState.open = true;
- modalState.internationalDates = true;
- }
- /*
- * Railway employee discount with different train categories.
- */
- if (
- button.attr("przesiadka") === "true"
- ) {
- const category1 = button.attr("kat_1");
- const category2 = button.attr("kat_2");
- if (
- category1 !== category2 &&
- containsMixedRailwayDiscounts()
- ) {
- modalState.open = true;
- modalState.attention = true;
- }
- }
- /*
- * --------------------------------------------------------------
- * Show modal / continue with transfer / submit
- * --------------------------------------------------------------
- */
- const modalService = new ModalService();
- if (
- modalState.open &&
- transferStep === 0
- ) {
- showNextModal(
- modalService,
- modalState
- );
- if (isTransfer) {
- configureTransferModal(button);
- }
- button.okienkoModalne().open();
- return;
- }
- if (isTransfer) {
- handleTransferContinue(
- button,
- hasTwoTransfers,
- childUnderSixCoachTypes,
- startingCategory,
- transferCoachType1,
- transferCoachType2
- );
- return;
- }
- submitOrShowHiddenStationModal(
- button,
- modalService
- );
- }
- function handleFamilyTicketValidation(
- modalState,
- isMiniGroup,
- minimumPassengers
- ) {
- const passengerCount =
- getPassengerCount(true);
- if (isMiniGroup) {
- if (
- isVisible("#dalej_modal_strefa_ciszy")
- ) {
- $("#dalej_modal_strefa_ciszy").hide();
- $("#dalej_modal_bilet_rodzinny_strefa_ciszy")
- .show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v2")
- );
- } else if (
- passengerCount < minimumPassengers
- ) {
- modalState.open = true;
- $("#dalej_modal_bilet_rodzinny").show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v2")
- );
- }
- return;
- }
- const adults = getInt("#liczba_n");
- const reduced1 = getInt("#liczba_u");
- const reduced2 = getInt("#liczba_u_2");
- const discount1 =
- getInt("#rodzaj_ulgi_wrap_1 #kod_znizki");
- const discount2 =
- getInt("#rodzaj_ulgi_wrap_2 #kod_znizki_2");
- const total = adults + reduced1 + reduced2;
- if (
- adults === 0 &&
- reduced1 + reduced2 > 0
- ) {
- modalState.open = true;
- $("#dalej_modal_bilet_rodzinny_bledna_liczba_osob")
- .show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v2")
- );
- return;
- }
- const hasExcludedDiscount =
- (reduced1 > 0 && discount1 === 77) ||
- (reduced2 > 0 && discount2 === 77);
- const validPassengerCount =
- total >= 2 && total <= 5;
- if (
- !hasExcludedDiscount &&
- validPassengerCount &&
- (
- adults >= 2 ||
- (reduced1 > 0 && discount1 > 1) ||
- (reduced2 > 0 && discount2 > 1)
- )
- ) {
- modalState.open = true;
- $("#dalej_modal_bilet_rodzinny")
- .show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v2")
- );
- }
- if (
- isVisible("#dalej_modal_strefa_ciszy") &&
- isVisible("#dalej_modal_bilet_rodzinny")
- ) {
- $("#dalej_modal_strefa_ciszy").hide();
- $("#dalej_modal_bilet_rodzinny").hide();
- $("#dalej_modal_bilet_rodzinny_strefa_ciszy")
- .show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v2")
- );
- }
- }
- function handlePossibleMiniGroup(
- modalState,
- minimumPassengers
- ) {
- if (
- getPassengerCount() <
- minimumPassengers
- ) {
- return;
- }
- const discountIds = [
- "#kod_znizki",
- "#kod_znizki_2",
- "#kod_znizki_3"
- ];
- const hasAllowedDiscount =
- discountIds.some((selector) => {
- const value = $(selector).val();
- return constants.miniGroupDiscounts.includes(
- value
- );
- });
- if (!hasAllowedDiscount) {
- modalState.open = true;
- modalState.possibleMiniGroup = true;
- $("#mini_grupa_mozliwa").show();
- $("#dalej_modal_ok").val(
- $("#dalej_modal_ok").attr("v6")
- );
- }
- }
- function showNextModal(
- modalService,
- state
- ) {
- if (state.attention) {
- modalService.dalejModalAtention();
- } else if (state.dogCompartment) {
- modalService.dalejModalBiletPiesCalyPrzedzial();
- } else if (state.childAdultBed) {
- modalService.dalejModalJednoLozkoDzieckoOpiekun();
- } else if (state.childAdultBedCovid) {
- modalService.dalejModalJednoLozkoDzieckoOpiekunCOVID();
- } else if (state.internationalDates) {
- modalService.dalejModalMiedzynarodowyNiechronologiczneDaty();
- } else if (state.metropolitanChild) {
- modalService.dalejModalMiedzynarodowyDzieckoMetropol();
- } else if (state.possibleMiniGroup) {
- modalService.dalejModalMozliwaMiniGrupa();
- } else {
- /*
- * The original code used `dalej_modal_false = true`
- * which made this branch effectively unconditional.
- *
- * This is now explicit.
- */
- modalService.dalejModalFalse();
- }
- }
- function configureTransferModal(button) {
- $("#dalej_modal_ok")
- .attr("type", "button")
- .off("click.zakupBiletu")
- .on("click.zakupBiletu", function () {
- transferStep++;
- przesiadkiService(transferStep);
- $(this)
- .okienkoModalne()
- .close();
- });
- $("#dalej_modal_nie")
- .off("click.zakupBiletu")
- .on("click.zakupBiletu", function () {
- transferStep++;
- przesiadkiService(transferStep);
- $(this)
- .okienkoModalne()
- .close();
- });
- }
- function handleTransferContinue(
- button,
- hasTwoTransfers,
- childCoachTypes,
- startingCategory,
- transferCoachType1,
- transferCoachType2
- ) {
- if (
- ZakupBiletuUtil()
- .czyWybranoZnizkiKolejarzaPolbus()
- ) {
- new ModalService()
- .modalZnizkiDlaKolejarzaPolbus(button);
- return;
- }
- if (
- ObslugaKlopotliwychZnizek()
- .validate(button)
- ) {
- return;
- }
- const isFirstSection =
- transferStep === 0 ||
- (
- hasTwoTransfers &&
- transferStep === 1
- );
- if (isFirstSection) {
- const station =
- transferStep === 0
- ? button.attr("nr_poc_2")
- : button.attr("nr_poc_3");
- const departure =
- transferStep === 0
- ? button.attr("data_odj_2")
- : button.attr("data_odj_3");
- informacja_pasazerska(
- station,
- departure,
- button.attr("lang")
- );
- transferStep++;
- przesiadkiService(transferStep);
- return;
- }
- const isSecondSection =
- (
- !hasTwoTransfers &&
- transferStep === 1
- ) ||
- (
- hasTwoTransfers &&
- transferStep === 2
- );
- if (!isSecondSection) {
- return;
- }
- if (
- constants.coachType.QUIET_ZONE.includes(
- transferCoachType1
- ) ||
- constants.coachType.QUIET_ZONE.includes(
- transferCoachType2
- )
- ) {
- const modalButton =
- prepareStrefaCiszyPrzesiadkiModal();
- modalButton
- .off("click.zakupBiletu")
- .on("click.zakupBiletu", function () {
- transferStep++;
- przesiadkiService(transferStep);
- if (
- (
- !hasTwoTransfers &&
- transferStep > 1
- ) ||
- (
- hasTwoTransfers &&
- transferStep > 2
- )
- ) {
- submitForm();
- }
- });
- button.okienkoModalne().open();
- return;
- }
- if (
- czyWybranoDlaPodroznychZDziecmiDoLat6(
- button,
- childCoachTypes,
- startingCategory
- )
- ) {
- return;
- }
- if (
- !validMiejsceSasiadujaceWskazane(
- constants.section.SECOND
- )
- ) {
- return;
- }
- submitOrShowHiddenStationModal(
- button,
- new ModalService()
- );
- }
- function prepareStrefaCiszyPrzesiadkiModal() {
- $("#dalej_modal_inform").hide();
- $("#dalej_modal_tak").hide();
- $("#dalej_modal_strefa_ciszy").show();
- $("#dalej_modal_footer").show();
- const modal = $("#dalej_modal_ok");
- modal
- .val(modal.attr("v1"))
- .attr("type", "button")
- .addClass("js-modal-close");
- return modal;
- }
- function submitOrShowHiddenStationModal(
- button,
- modalService
- ) {
- if (
- $("#popup_metastacja_niejawna").val() === "1"
- ) {
- modalService.dalejModalStacjaNiejawna();
- $("#dalej_metastacja_niejawna").show();
- button.okienkoModalne().open();
- return;
- }
- submitForm();
- }
- function przesiadkiService(index) {
- const transfer = new PrzesiadkiZakupowe();
- transfer.setIndexPrzesiadki(index);
- transfer.zablokujPolaDlaPrzesiadkiZakupowej(index);
- transfer.aktywujDeaktywujElementy();
- ObslugaKlopotliwychZnizek()
- .pokazKomunikatRozneKatPoc_Eip_TLK();
- }
- /*
- * ----------------------------------------------------------------------
- * Form / UI events
- * ----------------------------------------------------------------------
- */
- function bindSeatNumberValidation() {
- [
- "#numer_wagonu",
- "#numer_miejsca",
- "#numer_wagonu_2",
- "#numer_miejsca_2",
- "#numer_wagonu_3",
- "#numer_miejsca_3"
- ].forEach((selector) => {
- $(selector)
- .off("blur.zakupBiletu")
- .on("blur.zakupBiletu", function () {
- validateSeatNumberFields(
- selector.endsWith("_2") ? 2 :
- selector.endsWith("_3") ? 3 : 1
- );
- });
- });
- }
- function bindEvents() {
- nextButton
- .off("click.zakupBiletu")
- .on("click.zakupBiletu", handleNextClick);
- previousConnectionButton
- .off("click.zakupBiletu")
- .on("click.zakupBiletu", function () {
- informacja_pasazerska(
- $(this).attr("nr_poc_1"),
- $(this).attr("data_odj_1"),
- $(this).attr("lang")
- );
- transferStep = 0;
- const transfer =
- new PrzesiadkiZakupowe();
- transfer.setIndexPrzesiadki(0);
- transfer.odblokujPolaDlaPrzesiadkiZakupowej();
- transfer.aktywujDeaktywujElementy();
- $()
- .obslugaUlgi()
- .obslugaWieluZnizek();
- });
- nextConnectionButton
- .off("click.zakupBiletu")
- .on("click.zakupBiletu", function () {
- const transfer =
- new PrzesiadkiZakupowe();
- if (transferStep === 0) {
- transferStep++;
- transfer.setIndexPrzesiadki(
- transferStep
- );
- transfer.aktywujDeaktywujElementy();
- }
- transfer.zablokujPolaDlaPrzesiadkiZakupowej(
- transferStep
- );
- });
- externalInfoArrow
- .off("click.zakupBiletu")
- .on("click.zakupBiletu", function () {
- $(this)
- .closest(".data_box_section")
- .find(".data_box_rwd")
- .removeClass("data_box_hide")
- .addClass("data_box_show");
- $(this)
- .removeClass("arrow_box_down")
- .addClass("arrow_box_up");
- });
- form
- .off("submit.zakupBiletu")
- .on("submit.zakupBiletu", function () {
- return validateCompanionTicketNumber();
- });
- coachType
- .off("change.zakupBiletu")
- .on("change.zakupBiletu", function () {
- const value = $(this)
- .find("option:selected")
- .val();
- rodzajWagonuOpis(value);
- sprawdzRowerRodzajWagonu();
- usunInformacjeWstepnaDlaPrzedzialDzieckoDo6Lat();
- });
- wagonClass
- .off("change.zakupBiletu")
- .on("change.zakupBiletu", function () {
- if (!politicianMode.length) {
- ustawKlasaWagonu();
- }
- });
- bindSeatNumberValidation();
- }
- /*
- * ----------------------------------------------------------------------
- * Public plugin API
- * ----------------------------------------------------------------------
- */
- function init() {
- bindEvents();
- }
- init();
- return {
- init
- };
- };
- })(jQuery);
Add Comment
Please, Sign In to add comment