Guest User

Untitled

a guest
Sep 24th, 2026
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 68.80 KB | None | 0 0
  1. (function ($) {
  2. "use strict";
  3.  
  4. $.fn.zakupBiletu = function (options) {
  5. const form = $("#zakup_biletu_form");
  6. const companionTicketNumber = $("#nr_biletu_osoby_towarzyszacej");
  7. const coachType = $("#rodzaj_wagonu");
  8. const wagonClass = $("#klasa_wagonu");
  9. const politicianMode = $("#tryb_posel");
  10.  
  11. const nextButton = $(".dalej_button");
  12. const previousConnectionButton = $(".przesiadka_prev");
  13. const nextConnectionButton = $(".przesiadka_next");
  14. const externalInfoArrow = $(".arrow_box_ext_info");
  15.  
  16. const constants = {
  17. section: {
  18. FIRST: 1,
  19. SECOND: 2
  20. },
  21.  
  22. seatType: {
  23. SEATED: 1
  24. },
  25.  
  26. coachType: {
  27. QUIET_ZONE: [52, 11],
  28. CHILD_UNDER_6: [3, 50]
  29. },
  30.  
  31. additionalTicket: {
  32. BICYCLE: 15
  33. },
  34.  
  35. discount: {
  36. NO_DISCOUNT: 1,
  37. RAILWAY_EMPLOYEE: 40,
  38. RAILWAY_PENSIONER: 41,
  39. RAILWAY_FAMILY: 42,
  40. RAILWAY_TECHNICAL_EMPLOYEE: 44,
  41. CHILD: [71, 77, 78]
  42. },
  43.  
  44. dogTicket: [17, 18, 19],
  45.  
  46. familyTicket: {
  47. MIN_PEOPLE: 2
  48. },
  49.  
  50. miniGroupDiscounts: [
  51. "36",
  52. "39",
  53. "40",
  54. "41",
  55. "42",
  56. "51"
  57. ]
  58. };
  59.  
  60. let transferStep = 0;
  61.  
  62. /*
  63. * ------------------------------------------------------------------
  64. * Generic helpers
  65. * ------------------------------------------------------------------
  66. */
  67.  
  68. function getInt(selector, defaultValue = 0) {
  69. const value = $(selector).val();
  70. const parsed = parseInt(value, 10);
  71.  
  72. return Number.isNaN(parsed) ? defaultValue : parsed;
  73. }
  74.  
  75. function getSelectedInt(selector, defaultValue = 0) {
  76. const value = $(selector).find("option:selected").val();
  77. const parsed = parseInt(value, 10);
  78.  
  79. return Number.isNaN(parsed) ? defaultValue : parsed;
  80. }
  81.  
  82. function isChecked(selector) {
  83. return $(selector).is(":checked");
  84. }
  85.  
  86. function isVisible(selector) {
  87. return $(selector).is(":visible");
  88. }
  89.  
  90. function exists(selector) {
  91. return $(selector).length > 0;
  92. }
  93.  
  94. function submitForm() {
  95. const element = form.get(0);
  96.  
  97. if (element) {
  98. element.submit();
  99. }
  100. }
  101.  
  102. function hideAllContinueModals() {
  103. $(".dalej_modal").hide();
  104. }
  105.  
  106. function getPassengerCount(includeThirdDiscount = true) {
  107. const selectors = [
  108. "#liczba_n",
  109. "#liczba_u",
  110. "#liczba_u_2"
  111. ];
  112.  
  113. if (includeThirdDiscount) {
  114. selectors.push("#liczba_u_3");
  115. }
  116.  
  117. return selectors.reduce(
  118. (total, selector) => total + getInt(selector),
  119. 0
  120. );
  121. }
  122.  
  123. function getDiscountSelectIds() {
  124. return [
  125. "kod_znizki",
  126. "kod_znizki_2",
  127. "kod_znizki_3"
  128. ];
  129. }
  130.  
  131. function getTransferDiscountSelectIds(transferIndex) {
  132. if (transferIndex === 1) {
  133. return [
  134. "kod_znizki_2_1",
  135. "kod_znizki_2_2",
  136. "kod_znizki_2_3"
  137. ];
  138. }
  139.  
  140. return [
  141. "kod_znizki_3_1",
  142. "kod_znizki_3_2",
  143. "kod_znizki_3_3"
  144. ];
  145. }
  146.  
  147. function setDefaultSelectValue(selector) {
  148. const element = $(selector);
  149.  
  150. if (!element.length) {
  151. return;
  152. }
  153.  
  154. element.val(element.find("option:first").val());
  155. }
  156.  
  157. /*
  158. * ------------------------------------------------------------------
  159. * Validation
  160. * ------------------------------------------------------------------
  161. */
  162.  
  163. function validateCompanionTicketNumber() {
  164. if (!companionTicketNumber.is(":visible")) {
  165. return true;
  166. }
  167.  
  168. const value = $.trim(companionTicketNumber.val());
  169. const error = $(".nr_osoba_towarz_error");
  170.  
  171. const isValid = /^[0-9]+$/.test(value);
  172.  
  173. error.find("span").toggle(!isValid);
  174.  
  175. return isValid;
  176. }
  177.  
  178. function validateSeatNumberFields(section) {
  179. const suffix = section > 1 ? `_${section}` : "";
  180.  
  181. const fields = [
  182. `#numer_wagonu${suffix}`,
  183. `#numer_miejsca${suffix}`
  184. ];
  185.  
  186. let hasError = false;
  187.  
  188. fields.forEach((selector) => {
  189. const input = $(selector);
  190.  
  191. if (!input.length || !input.val()) {
  192. return;
  193. }
  194.  
  195. const isValid = /^\d+$/.test(input.val());
  196.  
  197. input
  198. .toggleClass("error_input", !isValid)
  199. .closest(".form_wrapper_input")
  200. .find(".error_info_wskazane_zajete")
  201. .toggleClass("display-hide", isValid);
  202.  
  203. if (!isValid) {
  204. hasError = true;
  205. }
  206. });
  207.  
  208. return !hasError;
  209. }
  210.  
  211. function validMiejsceSasiadujaceWskazane(section) {
  212. const occupiedSeat = $("#rezerwacja_obok_miejsca_juz_zajetego");
  213. const selectedSeat = $(
  214. `#rezerwacja_miejsca_wskazanego${section > 1 ? `_${section}` : ""}`
  215. );
  216.  
  217. if (!occupiedSeat.is(":checked") && !selectedSeat.is(":checked")) {
  218. return true;
  219. }
  220.  
  221. return validateSeatNumberFields(section);
  222. }
  223.  
  224. /*
  225. * ------------------------------------------------------------------
  226. * Employee / railway discounts
  227. * ------------------------------------------------------------------
  228. */
  229.  
  230. function getRailwayEmployeeDiscountCount() {
  231. const railwayDiscounts = [
  232. constants.discount.RAILWAY_EMPLOYEE,
  233. constants.discount.RAILWAY_PENSIONER,
  234. constants.discount.RAILWAY_FAMILY,
  235. constants.discount.RAILWAY_TECHNICAL_EMPLOYEE
  236. ];
  237.  
  238. const discountIds = [
  239. "kod_znizki",
  240. "kod_znizki_2",
  241. "kod_znizki_3"
  242. ];
  243.  
  244. const passengerIds = [
  245. "liczba_u",
  246. "liczba_u_2",
  247. "liczba_u_3"
  248. ];
  249.  
  250. return discountIds.reduce((total, discountId, index) => {
  251. const discountCode = getSelectedInt(`#${discountId}`);
  252.  
  253. if (!railwayDiscounts.includes(discountCode)) {
  254. return total;
  255. }
  256.  
  257. return total + getSelectedInt(`#${passengerIds[index]}`);
  258. }, 0);
  259. }
  260.  
  261. function containsMixedRailwayDiscounts() {
  262. const employeeDiscounts = [40, 41];
  263. const familyDiscounts = [42, 44];
  264.  
  265. const discountIds = [
  266. "kod_znizki",
  267. "kod_znizki_2",
  268. "kod_znizki_3",
  269. "kod_znizki_2_1",
  270. "kod_znizki_2_2",
  271. "kod_znizki_2_3"
  272. ];
  273.  
  274. let hasEmployeeDiscount = false;
  275. let hasFamilyDiscount = false;
  276.  
  277. discountIds.forEach((id) => {
  278. const code = getSelectedInt(`#${id}`);
  279.  
  280. if (employeeDiscounts.includes(code)) {
  281. hasEmployeeDiscount = true;
  282. }
  283.  
  284. if (familyDiscounts.includes(code)) {
  285. hasFamilyDiscount = true;
  286. }
  287. });
  288.  
  289. return hasEmployeeDiscount && hasFamilyDiscount;
  290. }
  291.  
  292. /*
  293. * ------------------------------------------------------------------
  294. * Dog / additional ticket handling
  295. * ------------------------------------------------------------------
  296. */
  297.  
  298. function AdditionalTicketService() {
  299. function isSleepingOrCouchette() {
  300. return getSelectedInt(".rodzaj_miejsca") > 1;
  301. }
  302.  
  303. function hasDogTicket() {
  304. return $(".bilet_dodatkowy").toArray().some((element) => {
  305. return constants.dogTicket.includes(
  306. parseInt($(element).val(), 10)
  307. );
  308. });
  309. }
  310.  
  311. function getTotalPassengerCount() {
  312. return [
  313. "#liczba_n",
  314. "#liczba_u",
  315. "#liczba_u_2",
  316. "#liczba_u_3"
  317. ].reduce((total, selector) => {
  318. return total + getInt(selector);
  319. }, 0);
  320. }
  321.  
  322. function isWholeCompartmentRequiredForDog() {
  323. if (!isSleepingOrCouchette() || !hasDogTicket()) {
  324. return false;
  325. }
  326.  
  327. const compartmentCapacity = getInt("#przedzial");
  328. const beds = $("#llozek");
  329. const passengerCount = getTotalPassengerCount();
  330.  
  331. if (passengerCount < compartmentCapacity) {
  332. return true;
  333. }
  334.  
  335. return (
  336. beds.is(":visible") &&
  337. getInt("#llozek") < passengerCount
  338. );
  339. }
  340.  
  341. return {
  342. czyNieWybranoCalegoPrzedzialuDlaPsa:
  343. isWholeCompartmentRequiredForDog
  344. };
  345. }
  346.  
  347. /*
  348. * ------------------------------------------------------------------
  349. * Child / adult sleeping arrangement
  350. * ------------------------------------------------------------------
  351. */
  352.  
  353. function czyWybranoWspolneUsytuowanieNaJednymLozkuDzieckoOpiekun() {
  354. const beds = $("#llozek");
  355. const adults = $("#liczba_n");
  356.  
  357. if (
  358. getSelectedInt(".rodzaj_miejsca") ===
  359. constants.seatType.SEATED ||
  360. !beds.is(":visible")
  361. ) {
  362. return false;
  363. }
  364.  
  365. const childDiscounts = constants.discount.CHILD;
  366. const discountIds = [
  367. "kod_znizki",
  368. "kod_znizki_2",
  369. "kod_znizki_3"
  370. ];
  371.  
  372. const passengerIds = [
  373. "liczba_u",
  374. "liczba_u_2",
  375. "liczba_u_3"
  376. ];
  377.  
  378. let adultCount = getInt("#liczba_n");
  379. let childCount = 0;
  380.  
  381. const discountWrapper = "#rodzaj_ulgi_wrap_2";
  382.  
  383. discountIds.forEach((discountId, index) => {
  384. const discountSelector =
  385. index === 0
  386. ? `${discountWrapper} #${discountId}`
  387. : `#${discountId}`;
  388.  
  389. const discountCode = getInt(discountSelector);
  390. const passengerCount = getInt(
  391. `#${passengerIds[index]}`
  392. );
  393.  
  394. if (childDiscounts.includes(discountCode)) {
  395. childCount += passengerCount;
  396. } else if (
  397. discountCode !== constants.discount.NO_DISCOUNT
  398. ) {
  399. adultCount += passengerCount;
  400. }
  401. });
  402.  
  403. $("#osobne_lozko_dla_dziecka_wrapper").hide();
  404. $("#osobne_lozko_dla_dziecka").prop("checked", false);
  405.  
  406. const totalPassengers = adultCount + childCount;
  407. const bedCount = getInt("#llozek");
  408.  
  409. return bedCount > 0 && totalPassengers > bedCount;
  410. }
  411.  
  412. /*
  413. * ------------------------------------------------------------------
  414. * Child under 6 validation
  415. * ------------------------------------------------------------------
  416. */
  417.  
  418. function czyPrzedzialDlaOsobyZDzieckiemDoLat6() {
  419. return getInt("#rodzaj_wagonu") === 3;
  420. }
  421.  
  422. function showChildUnderSixModal(input) {
  423. hideAllContinueModals();
  424.  
  425. $("#dalej_modal_inform").hide();
  426. $("#dalej_modal_tak").hide();
  427. $("#dalej_modal_dla_podr_z_dzieckiem_do_lat_6").show();
  428. $("#dalej_modal_footer").show();
  429.  
  430. const modalOk = $("#dalej_modal_ok");
  431.  
  432. modalOk
  433. .val(modalOk.attr("v1"))
  434. .attr("type", "button")
  435. .addClass("js-modal-close")
  436. .off("click.zakupBiletu")
  437. .on("click.zakupBiletu", function () {
  438. submitForm();
  439. });
  440.  
  441. $(input).okienkoModalne().open();
  442. }
  443.  
  444. function czyWybranoDlaPodroznychZDziecmiDoLat6(
  445. input,
  446. childCoachTypes,
  447. startingCategory
  448. ) {
  449. const coachTypeForSection = getSelectedInt(
  450. "#rodzaj_wagonu_odcinek_2"
  451. );
  452.  
  453. if (!childCoachTypes.includes(coachTypeForSection)) {
  454. return false;
  455. }
  456.  
  457. const passengerCount = [
  458. "#liczba_n",
  459. "#liczba_u_2_1",
  460. "#liczba_u_2_2"
  461. ].reduce(
  462. (total, selector) => total + getSelectedInt(selector),
  463. 0
  464. );
  465.  
  466. if (passengerCount < 2) {
  467. return false;
  468. }
  469.  
  470. if (startingCategory === 81 && passengerCount > 4) {
  471. return false;
  472. }
  473.  
  474. showChildUnderSixModal(input);
  475.  
  476. return true;
  477. }
  478.  
  479. /*
  480. * ------------------------------------------------------------------
  481. * Modal service
  482. * ------------------------------------------------------------------
  483. */
  484.  
  485. function ModalService() {
  486. const modal = $("#dalej_modal_ok");
  487.  
  488. function prepareCommonModal() {
  489. $("#dalej_modal_footer").show();
  490. $("#dalej_modal_inform").hide();
  491. $("#dalej_modal_tak").hide();
  492. $("#dalej_modal_nie").hide();
  493. $("#dalej_modal_false").hide();
  494. $("#dalej_modal_header_informacja").show();
  495. $("#dalej_modal_header_uwaga").hide();
  496. }
  497.  
  498. function showAtention() {
  499. $("#dalej_modal_footer").show();
  500. $("#dalej_modal_pracownik_kolei").hide();
  501. $("#dalej_modal_kolejarz_przesiadka").show();
  502. $("#dalej_modal_inform").show();
  503. $("#dalej_modal_tak").hide();
  504. $("#dalej_modal_nie").hide();
  505. $("#dalej_modal_false").hide();
  506. modal.hide();
  507. $("#dalej_modal_header_informacja").hide();
  508. $("#dalej_modal_header_uwaga").show();
  509. }
  510.  
  511. function showDogCompartmentWarning() {
  512. prepareCommonModal();
  513.  
  514. $("#dalej_modal_pies_caly_przedzial").show();
  515.  
  516. modal
  517. .val(modal.attr("v4"))
  518. .attr("type", "button")
  519. .addClass("js-modal-close");
  520. }
  521.  
  522. function showChildAdultSharedBedWarning() {
  523. ZakupBiletuUtil().showOkienkoModalne(
  524. this,
  525. "dalej_modal_wspolne_usytuowanie_lozko_dziecko_opiekun"
  526. );
  527. }
  528.  
  529. function showChildAdultSharedBedCovidWarning() {
  530. prepareCommonModal();
  531.  
  532. $("#dalej_modal_wspolne_usytuowanie_lozko_dziecko_opiekunCOVID").show();
  533. $("#dalej_modal_false").show();
  534.  
  535. modal
  536. .val(modal.attr("v5"))
  537. .hide()
  538. .removeClass("js-modal-close");
  539. }
  540.  
  541. function showFalseModal() {
  542. prepareCommonModal();
  543.  
  544. $("#dalej_modal_false").show();
  545.  
  546. modal
  547. .attr("type", "submit")
  548. .removeClass("js-modal-close")
  549. .show();
  550. }
  551.  
  552. function showDefault() {
  553. prepareCommonModal();
  554.  
  555. modal
  556. .attr("type", "button")
  557. .addClass("js-modal-close");
  558. }
  559.  
  560. function showPossibleMiniGroup() {
  561. prepareCommonModal();
  562.  
  563. $("#dalej_modal_tak").show();
  564. $("#dalej_modal_nie").show();
  565.  
  566. modal
  567. .attr("type", "submit")
  568. .removeClass("js-modal-close")
  569. .hide();
  570. }
  571.  
  572. function showHiddenStation() {
  573. prepareCommonModal();
  574.  
  575. $("#dalej_modal_false").show();
  576.  
  577. modal
  578. .attr("type", "submit")
  579. .removeClass("js-modal-close")
  580. .val("Tak")
  581. .show();
  582. }
  583.  
  584. function showInternationalDateWarning() {
  585. ZakupBiletuUtil().showOkienkoModalne(
  586. this,
  587. "dalej_modal_wymiana_mm_niechronologiczne_daty"
  588. );
  589. }
  590.  
  591. function showMetropolitanChildWarning() {
  592. ZakupBiletuUtil().showOkienkoModalne(
  593. this,
  594. "dalej_modal_dziecko_metropol"
  595. );
  596. }
  597.  
  598. function showRailwayEmployeePolbusModal(element) {
  599. ZakupBiletuUtil().showModalInfo(
  600. element,
  601. "dalej_modal_kolejarz_przesiadka"
  602. );
  603. }
  604.  
  605. this.dalejModalAtention = showAtention;
  606. this.dalejModalBiletPiesCalyPrzedzial =
  607. showDogCompartmentWarning;
  608. this.dalejModalJednoLozkoDzieckoOpiekun =
  609. showChildAdultSharedBedWarning;
  610. this.dalejModalJednoLozkoDzieckoOpiekunCOVID =
  611. showChildAdultSharedBedCovidWarning;
  612. this.dalejModalFalse = showFalseModal;
  613. this.dalejModalDefault = showDefault;
  614. this.dalejModalMozliwaMiniGrupa =
  615. showPossibleMiniGroup;
  616. this.dalejModalStacjaNiejawna = showHiddenStation;
  617. this.dalejModalMiedzynarodowyNiechronologiczneDaty =
  618. showInternationalDateWarning;
  619. this.dalejModalMiedzynarodowyDzieckoMetropol =
  620. showMetropolitanChildWarning;
  621. this.modalZnizkiDlaKolejarzaPolbus =
  622. showRailwayEmployeePolbusModal;
  623. }
  624.  
  625. /*
  626. * ------------------------------------------------------------------
  627. * Transfer handling
  628. * ------------------------------------------------------------------
  629. */
  630.  
  631. function TransferService() {
  632. this.indexPrzesiadki = 0;
  633.  
  634. this.setIndexPrzesiadki = function (index) {
  635. this.indexPrzesiadki = index;
  636. };
  637.  
  638. this.getindexPrzesiadki = function () {
  639. return this.indexPrzesiadki;
  640. };
  641.  
  642. this.zablokujPolaDlaPrzesiadkiZakupowej =
  643. function (sectionIndex) {
  644. lockFieldsForTransfer.call(this, sectionIndex);
  645. };
  646.  
  647. this.odblokujPolaDlaPrzesiadkiZakupowej =
  648. function () {
  649. unlockFieldsAfterTransfer.call(this);
  650. };
  651.  
  652. this.aktywujDeaktywujElementy =
  653. function () {
  654. activateTransferSection.call(this);
  655. };
  656.  
  657. this.obslugaZnizkeDlaPrzesiadki =
  658. function () {
  659. handleTransferDiscounts.call(this);
  660. };
  661.  
  662. this.pobierzZnizkiDlaPrzesiadki =
  663. function (sectionIndex) {
  664. loadTransferDiscounts(sectionIndex);
  665. };
  666.  
  667. this.obslugaBiletRodzinny_DuzaRodzina =
  668. function () {
  669. handleFamilyTicketVisibility.call(this);
  670. };
  671. }
  672.  
  673. function lockFieldsForTransfer(sectionIndex) {
  674. const elementsToShow = sectionIndex > 1
  675. ? [
  676. ".submit_powrot_zakup_biletu",
  677. ".dalej_button",
  678. ".przesiadka_info2_parametry",
  679. "#rodzaj_wagonu_odcinek_3",
  680. "#usytuowanie_przesiadka_3"
  681. ]
  682. : [
  683. ".submit_powrot_zakup_biletu",
  684. ".dalej_button",
  685. ".przesiadka_info_parametry",
  686. "#rodzaj_wagonu_odcinek_2",
  687. "#usytuowanie_przesiadka_2"
  688. ];
  689.  
  690. const elementsToHide = sectionIndex > 1
  691. ? [
  692. ".przesiadka_info_parametry",
  693. "#rodzaj_wagonu_odcinek_2",
  694. "#usytuowanie_przesiadka_2"
  695. ]
  696. : [
  697. ".przesiadka_info2_parametry",
  698. "#rodzaj_wagonu_odcinek_3",
  699. "#usytuowanie_przesiadka_3"
  700. ];
  701.  
  702. $(".opcja_biletu_rodzinny").each(function () {
  703. _addInputKDFiBR(
  704. $(this),
  705. $(this).is(":checked") ? 1 : 0
  706. );
  707. });
  708.  
  709. $("#pokaz_kolorowa_karte").prop("disabled", true);
  710.  
  711. $(".rodzaj_miejsca")
  712. .not(":checked")
  713. .prop("disabled", true);
  714.  
  715. $(".remove_additional_ticket").hide();
  716.  
  717. _ustawMiejsceZajeteWskazaneMIejsce(sectionIndex);
  718. toggleTransferElements(
  719. {
  720. id: [
  721. "tr_rodzaj_miejsca",
  722. "tr_promocja",
  723. "tr_liczba_osob_n",
  724. "tr_kod_znizki",
  725. "tr_kod_znizki_2",
  726. "tr_kod_znizki_3",
  727. "tr_nr_taryfy_II",
  728. "tr_nr_taryfy_I",
  729. "tr_przedzial",
  730. "tr_plec",
  731. "tr_klasa",
  732. "tr_kolorowa_karta_ic",
  733. "tr_pokaz_kolorowa_karte",
  734. "tr_bilety_dodatkowe"
  735. ],
  736. class: ["bilet_karta_rodziny_main_wrapper"]
  737. },
  738. false
  739. );
  740.  
  741. elementsToHide.forEach((selector) => $(selector).hide());
  742. elementsToShow.forEach((selector) => $(selector).show());
  743.  
  744. $("#rodzaj_wagonu, #usytuowanie").hide();
  745.  
  746. this.obslugaZnizkeDlaPrzesiadki();
  747.  
  748. $("#tr_pokaz_karte_duzej_rodziny").hide();
  749. $("#tr_pokaz_bilet_rodzinny").hide();
  750. }
  751.  
  752. function unlockFieldsAfterTransfer() {
  753. const currentIndex = this.getindexPrzesiadki();
  754.  
  755. const elementsToHide = [
  756. ".submit_powrot_zakup_biletu",
  757. ".przesiadka_info_parametry",
  758. ".przesiadka_info2_parametry",
  759. "#rodzaj_wagonu_odcinek_2",
  760. "#rodzaj_wagonu_odcinek_3",
  761. "#usytuowanie_przesiadka_2",
  762. "#usytuowanie_przesiadka_3",
  763. "#tr_liczba_osob_n_2",
  764. "#liczba_u_2_1",
  765. "#liczba_u_2_2",
  766. "#liczba_u_2_3",
  767. "#tr_liczba_osob_n_3",
  768. "#liczba_u_3_1",
  769. "#liczba_u_3_2",
  770. "#liczba_u_3_3"
  771. ];
  772.  
  773. _removeInputKDRiBR();
  774.  
  775. $("#pokaz_kolorowa_karte").prop("disabled", false);
  776. $(".rodzaj_miejsca").prop("disabled", false);
  777. $(".remove_additional_ticket").show();
  778.  
  779. _ustawMiejsceZajeteWskazaneMIejsce(currentIndex);
  780.  
  781. toggleTransferElements(
  782. {
  783. id: [
  784. "tr_rodzaj_miejsca",
  785. "tr_promocja",
  786. "tr_liczba_osob_n",
  787. "tr_kod_znizki",
  788. "tr_kod_znizki_2",
  789. "tr_kod_znizki_3",
  790. "tr_nr_taryfy_II",
  791. "tr_nr_taryfy_I",
  792. "tr_przedzial",
  793. "tr_plec",
  794. "tr_klasa",
  795. "tr_kolorowa_karta_ic",
  796. "tr_pokaz_kolorowa_karte",
  797. "tr_bilety_dodatkowe"
  798. ],
  799. class: ["bilet_karta_rodziny_main_wrapper"]
  800. },
  801. true
  802. );
  803.  
  804. elementsToHide.forEach((selector) => $(selector).hide());
  805.  
  806. [
  807. "#liczba_u",
  808. "#liczba_u_2",
  809. "#liczba_u_3"
  810. ].forEach((selector) => {
  811. $(selector).removeClass("przesiadka_hide_elem");
  812. });
  813.  
  814. $("#rodzaj_wagonu, #usytuowanie").show();
  815.  
  816. this.obslugaZnizkeDlaPrzesiadki();
  817. }
  818.  
  819. function activateTransferSection() {
  820. const index = this.getindexPrzesiadki();
  821.  
  822. $(".przesiadka_linia_wrapper").each(function (elementIndex) {
  823. $(this)
  824. .toggleClass(
  825. "przesiadka_linia_active",
  826. elementIndex === index
  827. )
  828. .toggleClass(
  829. "przesiadka_linia_deactive",
  830. elementIndex !== index
  831. );
  832. });
  833.  
  834. $(".przesiadka_konfiguracja_wypis").each(function (
  835. elementIndex
  836. ) {
  837. $(this).toggle(elementIndex === index);
  838. });
  839.  
  840. $(".przesiadka_prev_bg").toggleClass(
  841. "przesiadka_aktywny_odcinek",
  842. index === 0
  843. );
  844.  
  845. $(".przesiadka_next_bg").toggleClass(
  846. "przesiadka_aktywny_odcinek",
  847. index === 1
  848. );
  849.  
  850. $(".przesiadka_next_next_bg").toggleClass(
  851. "przesiadka_aktywny_odcinek",
  852. index === 2
  853. );
  854.  
  855. if (index > 0) {
  856. $("#rodzaj_wagonu_msg").hide();
  857. }
  858.  
  859. $("#indexPrzesiadki").val(index);
  860.  
  861. $(".przesiadka_info_znizka_rozne_kategorie").hide();
  862.  
  863. this.obslugaBiletRodzinny_DuzaRodzina();
  864.  
  865. $(".znizki_przesiadki2_wrapper")
  866. .addClass("przesiadka_hide_elem");
  867. }
  868.  
  869. function handleFamilyTicketVisibility() {
  870. const currentIndex = this.getindexPrzesiadki();
  871.  
  872. [
  873. ["karta_duzej_rodziny", "tr_pokaz_karte_duzej_rodziny"],
  874. ["bilet_rodzinny", "tr_pokaz_bilet_rodzinny"]
  875. ].forEach(([inputId, rowId]) => {
  876. if (!isChecked(`#${inputId}`)) {
  877. return;
  878. }
  879.  
  880. $(`#${rowId} .form_wrapper_input`)
  881. .toggleClass(
  882. "przesiadka_hide_elem",
  883. currentIndex !== 1
  884. );
  885. });
  886. }
  887.  
  888. function handleTransferDiscounts() {
  889. const currentSection = this.getindexPrzesiadki();
  890.  
  891. if (currentSection > 0) {
  892. this.pobierzZnizkiDlaPrzesiadki(currentSection);
  893. return;
  894. }
  895.  
  896. const firstSectionDiscounts = getDiscountSelectIds();
  897.  
  898. [
  899. "#tr_kod_znizki",
  900. "#tr_kod_znizki_2",
  901. "#tr_kod_znizki_3"
  902. ].forEach((selector) => {
  903. const wrapper = $(selector);
  904.  
  905. wrapper
  906. .removeClass("przesiadka_hide_elem")
  907. .find(".znizki_wrapper_ulga_ilosc")
  908. .removeClass("przesiadka_hide_elem");
  909.  
  910. wrapper.find(".znizki_wrapper_ulga_nazwa div").each(
  911. function () {
  912. const element = $(this);
  913.  
  914. if (
  915. element.hasClass(
  916. "znizki_przesiadki_wrapper"
  917. )
  918. ) {
  919. element.hide();
  920. } else {
  921. element.removeClass(
  922. "przesiadka_hide_elem"
  923. );
  924. }
  925. }
  926. );
  927. });
  928.  
  929. const hasDiscount = firstSectionDiscounts.some(
  930. (selector) => getInt(`#${selector}`) > 1
  931. );
  932.  
  933. $("#tr_miejsce_wskazane").toggle(!hasDiscount);
  934.  
  935. $(".znizki_przesiadki_wrapper").hide();
  936. $("#kod_znizki_opis").removeClass("przesiadka_hide_elem");
  937. $(".przesiadka_info_brak_znizki").hide();
  938.  
  939. const selectedDiscount = getInt("#kod_znizki");
  940. const specialDiscounts = [77, 79, 84];
  941.  
  942. if (
  943. getInt("#liczba_n") === 0 &&
  944. getInt("#liczba_u") === 1 &&
  945. !specialDiscounts.includes(selectedDiscount)
  946. ) {
  947. $("#tr_miejsce_wskazane").show();
  948. }
  949. }
  950.  
  951. function loadTransferDiscounts(sectionIndex) {
  952. $.ajax({
  953. method: "GET",
  954. url: "/zakup-biletu-utils",
  955. cache: false,
  956. data: {
  957. nr_odc: sectionIndex,
  958. action: "pobierzZnizkiPrzesiadki",
  959. karta_duzej_rodziny: isChecked(
  960. "#karta_duzej_rodziny"
  961. ),
  962. bilet_rodzinny: isChecked("#bilet_rodzinny"),
  963. klasa_wagonu: $("#klasa_wagonu").val()
  964. },
  965.  
  966. beforeSend() {
  967. $(".zakup_biletu_form_main_wrapper")
  968. .append('<div class="loadmask"></div>');
  969. },
  970.  
  971. success(data) {
  972. let result;
  973.  
  974. try {
  975. result =
  976. typeof data === "string"
  977. ? JSON.parse(data)
  978. : data;
  979. } catch (error) {
  980. console.error(
  981. "Unable to parse transfer discounts response.",
  982. error
  983. );
  984. return;
  985. }
  986.  
  987. fillTransferDiscounts(result, sectionIndex);
  988. handleDiscountsForSection(sectionIndex);
  989. ObslugaKlopotliwychZnizek().run(sectionIndex);
  990. handleTransferElements();
  991. },
  992.  
  993. error(xhr, status, error) {
  994. console.error(
  995. "Unable to load transfer discounts.",
  996. status,
  997. error
  998. );
  999. },
  1000.  
  1001. complete() {
  1002. $(".loadmask").remove();
  1003. }
  1004. });
  1005. }
  1006.  
  1007. function fillTransferDiscounts(options, sectionIndex) {
  1008. const sourceDiscounts = getDiscountSelectIds();
  1009.  
  1010. const targetDiscounts =
  1011. sectionIndex === 2
  1012. ? [
  1013. "#kod_znizki_3_1",
  1014. "#kod_znizki_3_2",
  1015. "#kod_znizki_3_3"
  1016. ]
  1017. : [
  1018. "#kod_znizki_2_1",
  1019. "#kod_znizki_2_2",
  1020. "#kod_znizki_2_3"
  1021. ];
  1022.  
  1023. sourceDiscounts.forEach((sourceSelector, index) => {
  1024. const source = $(sourceSelector);
  1025.  
  1026. if (getInt(sourceSelector) <= 0) {
  1027. return;
  1028. }
  1029.  
  1030. const target = $(targetDiscounts[index]);
  1031. const discounts = options[`znizki_${index}`] || [];
  1032.  
  1033. target.empty();
  1034.  
  1035. discounts.forEach((discount) => {
  1036. target.append(discount.option);
  1037. });
  1038. });
  1039. }
  1040.  
  1041. function handleTransferElements() {
  1042. const sectionIndex = getInt("#indexPrzesiadki");
  1043.  
  1044. if (sectionIndex !== 1 && sectionIndex !== 2) {
  1045. return;
  1046. }
  1047.  
  1048. const discountIds =
  1049. getTransferDiscountSelectIds(sectionIndex);
  1050.  
  1051. const hasDiscount = discountIds.some(
  1052. (id) => getInt(`#${id}`) > 1
  1053. );
  1054.  
  1055. const suffix = sectionIndex === 1 ? "_2" : "_3";
  1056.  
  1057. if (hasDiscount) {
  1058. $(
  1059. `#tr_rezerwacja_obok_miejsca_juz_zajetego_wagon${suffix}`
  1060. ).hide();
  1061.  
  1062. $(
  1063. `#tr_rezerwacja_obok_miejsca_juz_zajetego_miejsce${suffix}`
  1064. ).hide();
  1065.  
  1066. $(
  1067. `#rezerwacja_miejsca_wskazanego${suffix}`
  1068. ).prop("checked", false);
  1069.  
  1070. $(`#numer_wagonu${suffix}`).val("");
  1071. $(`#numer_miejsca${suffix}`).val("");
  1072. } else {
  1073. $("#tr_miejsce_wskazane").show();
  1074. }
  1075. }
  1076.  
  1077. function handleDiscountsForSection(section) {
  1078. const firstSectionDiscounts =
  1079. section === 2
  1080. ? [
  1081. "#kod_znizki_2_1",
  1082. "#kod_znizki_2_2",
  1083. "#kod_znizki_2_3"
  1084. ]
  1085. : getDiscountSelectIds();
  1086.  
  1087. const secondSectionDiscounts =
  1088. section === 2
  1089. ? [
  1090. "#kod_znizki_3_1",
  1091. "#kod_znizki_3_2",
  1092. "#kod_znizki_3_3"
  1093. ]
  1094. : [
  1095. "#kod_znizki_2_1",
  1096. "#kod_znizki_2_2",
  1097. "#kod_znizki_2_3"
  1098. ];
  1099.  
  1100. const wrappers = [
  1101. "#tr_kod_znizki",
  1102. "#tr_kod_znizki_2",
  1103. "#tr_kod_znizki_3"
  1104. ];
  1105.  
  1106. const matchedDiscounts = [];
  1107. const missingDiscounts = [];
  1108.  
  1109. firstSectionDiscounts.forEach((selector, index) => {
  1110. const selectedOption = $(
  1111. `${selector} option:selected`
  1112. );
  1113.  
  1114. const code = selectedOption.val();
  1115. const name = $.trim(selectedOption.text());
  1116.  
  1117. if (parseInt(code, 10) <= 1) {
  1118. return;
  1119. }
  1120.  
  1121. const target = $(secondSectionDiscounts[index]);
  1122. let matchingOption = null;
  1123.  
  1124. target.find("option").each(function () {
  1125. if (
  1126. $.trim($(this).text()) === name
  1127. ) {
  1128. matchingOption = $(this);
  1129. return false;
  1130. }
  1131. });
  1132.  
  1133. if (matchingOption) {
  1134. matchedDiscounts[index] = {
  1135. id: matchingOption.val(),
  1136. name
  1137. };
  1138. } else {
  1139. missingDiscounts[index] = {
  1140. id: code,
  1141. name
  1142. };
  1143. }
  1144.  
  1145. const wrapper = $(wrappers[index]);
  1146.  
  1147. wrapper
  1148. .find(".znizki_wrapper_ulga_ilosc")
  1149. .addClass("przesiadka_hide_elem");
  1150.  
  1151. wrapper
  1152. .find(".znizki_wrapper_ulga_nazwa div")
  1153. .each(function () {
  1154. const element = $(this);
  1155.  
  1156. if (
  1157. element.hasClass(
  1158. "znizki_przesiadki_wrapper"
  1159. )
  1160. ) {
  1161. element.show();
  1162. } else {
  1163. element.addClass(
  1164. "przesiadka_hide_elem"
  1165. );
  1166. }
  1167. });
  1168. });
  1169.  
  1170. const missingDiscount =
  1171. missingDiscounts.find(Boolean);
  1172.  
  1173. if (missingDiscount) {
  1174. handleMissingTransferDiscount(
  1175. missingDiscount,
  1176. section
  1177. );
  1178. } else {
  1179. copyPassengerCounts(section);
  1180. }
  1181.  
  1182. matchedDiscounts.forEach((discount, index) => {
  1183. if (discount) {
  1184. $(secondSectionDiscounts[index]).val(
  1185. discount.id
  1186. );
  1187. }
  1188. });
  1189. }
  1190.  
  1191. function handleMissingTransferDiscount(
  1192. missingDiscount,
  1193. section
  1194. ) {
  1195. const categories =
  1196. section === 2
  1197. ? [
  1198. getInt("#train_category_2"),
  1199. getInt("#train_category_3")
  1200. ]
  1201. : [
  1202. getInt("#train_category_1"),
  1203. getInt("#train_category_2")
  1204. ];
  1205.  
  1206. const problematicDiscounts =
  1207. ObslugaKlopotliwychZnizek();
  1208.  
  1209. const isProblematicRoute =
  1210. problematicDiscounts.isPociagKat_EIP_EIC_AND_TLK_IC(
  1211. categories[0],
  1212. categories[1]
  1213. ) ||
  1214. problematicDiscounts.isPociagKat_TLK_IC_AND_EIP_EIC(
  1215. categories[0],
  1216. categories[1]
  1217. );
  1218.  
  1219. if (isProblematicRoute) {
  1220. const info = $(".przesiadka_info_brak_znizki");
  1221.  
  1222. info.show()
  1223. .find("span")
  1224. .text(`"${missingDiscount.name}"`);
  1225. }
  1226.  
  1227. $("#kod_znizki_opis").addClass(
  1228. "przesiadka_hide_elem"
  1229. );
  1230.  
  1231. const passengerCountId =
  1232. section === 2
  1233. ? "#tr_liczba_osob_n_3"
  1234. : "#tr_liczba_osob_n_2";
  1235.  
  1236. $(passengerCountId).show();
  1237.  
  1238. const countSuffix = section === 2 ? "_3" : "_2";
  1239.  
  1240. missingDiscountsForSection(section).forEach(
  1241. (_, index) => {
  1242. const wrapper = $(
  1243. `#tr_kod_znizki${index > 0 ? `_${index + 1}` : ""}`
  1244. );
  1245.  
  1246. wrapper.removeClass(
  1247. "przesiadka_hide_elem"
  1248. );
  1249.  
  1250. wrapper
  1251. .find(".znizki_wrapper_ulga_ilosc")
  1252. .removeClass("przesiadka_hide_elem");
  1253.  
  1254. $(
  1255. `#liczba_u${countSuffix}_${index + 1}`
  1256. ).show();
  1257. }
  1258. );
  1259. }
  1260.  
  1261. function missingDiscountsForSection(section) {
  1262. return getTransferDiscountSelectIds(section)
  1263. .map((id) => $(id))
  1264. .filter((element) => element.length);
  1265. }
  1266.  
  1267. function copyPassengerCounts(section) {
  1268. if (section === 2) {
  1269. $("#liczba_n_3").val($("#liczba_n_2").val());
  1270.  
  1271. const categories = [
  1272. getInt("#train_category_1"),
  1273. getInt("#train_category_3")
  1274. ];
  1275.  
  1276. const service =
  1277. ObslugaKlopotliwychZnizek();
  1278.  
  1279. const requiresAdditionalFields =
  1280. service.isPociagKat_EIP_EIC_AND_TLK_IC(
  1281. categories[0],
  1282. categories[1]
  1283. ) ||
  1284. service.isPociagKat_TLK_IC_AND_EIP_EIC(
  1285. categories[0],
  1286. categories[1]
  1287. );
  1288.  
  1289. if (requiresAdditionalFields) {
  1290. getDiscountSelectIds().forEach(
  1291. (_, index) => {
  1292. $(
  1293. `#tr_kod_znizki${index > 0 ? `_${index + 1}` : ""}`
  1294. )
  1295. .removeClass(
  1296. "przesiadka_hide_elem"
  1297. )
  1298. .find(
  1299. ".znizki_wrapper_ulga_ilosc"
  1300. )
  1301. .removeClass(
  1302. "przesiadka_hide_elem"
  1303. );
  1304.  
  1305. $(
  1306. `#liczba_u_3_${index + 1}`
  1307. ).show();
  1308. }
  1309. );
  1310.  
  1311. $("#tr_liczba_osob_n_3").toggle(
  1312. getDiscountSelectIds().some(
  1313. (id) => getInt(`#${id}`) > 1
  1314. )
  1315. );
  1316. }
  1317. } else {
  1318. $("#liczba_n_2").val($("#liczba_n").val());
  1319. }
  1320.  
  1321. const passengerMappings =
  1322. section === 2
  1323. ? [
  1324. ["liczba_u_2_1", "liczba_u_3_1"],
  1325. ["liczba_u_2_2", "liczba_u_3_2"],
  1326. ["liczba_u_2_3", "liczba_u_3_3"]
  1327. ]
  1328. : [
  1329. ["liczba_u", "liczba_u_2_1"],
  1330. ["liczba_u_2", "liczba_u_2_2"],
  1331. ["liczba_u_3", "liczba_u_2_3"]
  1332. ];
  1333.  
  1334. passengerMappings.forEach(([source, target]) => {
  1335. $(`#${target}`).val($(`#${source}`).val());
  1336. });
  1337. }
  1338. }
  1339.  
  1340. /*
  1341. * ----------------------------------------------------------------------
  1342. * Transfer helper functions
  1343. * ----------------------------------------------------------------------
  1344. */
  1345.  
  1346. function toggleTransferElements(elements, show) {
  1347. Object.entries(elements).forEach(([type, selectors]) => {
  1348. selectors.forEach((selector) => {
  1349. const elementsToToggle =
  1350. type === "id"
  1351. ? $(`#${selector}`)
  1352. : $(`.${selector}`);
  1353.  
  1354. elementsToToggle.toggleClass(
  1355. "przesiadka_hide_elem",
  1356. !show
  1357. );
  1358. });
  1359. });
  1360. }
  1361.  
  1362. function _addInputKDFiBR(element, value) {
  1363. form.append(
  1364. $("<input>", {
  1365. class:
  1366. "opcja_biletu_rodzinny_mock display-hide",
  1367. type: "checkbox",
  1368. name: element.attr("name"),
  1369. value
  1370. })
  1371. );
  1372. }
  1373.  
  1374. function _removeInputKDRiBR() {
  1375. form
  1376. .find(".opcja_biletu_rodzinny_mock")
  1377. .remove();
  1378. }
  1379.  
  1380. function _ustawMiejsceZajeteWskazaneMIejsce(section) {
  1381. const suffix =
  1382. section === 0
  1383. ? ""
  1384. : `_${section + 1}`;
  1385.  
  1386. const previousSuffixes = ["", "_2", "_3"];
  1387.  
  1388. const elementIds = [
  1389. "rezerwacja_obok_miejsca_juz_zajetego",
  1390. "rezerwacja_miejsca_wskazanego",
  1391. "tr_rezerwacja_obok_miejsca_juz_zajetego_wagon",
  1392. "tr_rezerwacja_obok_miejsca_juz_zajetego_miejsce"
  1393. ];
  1394.  
  1395. previousSuffixes.forEach((currentSuffix, index) => {
  1396. elementIds.forEach((id) => {
  1397. const element = $(`#${id}${currentSuffix}`);
  1398.  
  1399. if (!element.length) {
  1400. return;
  1401. }
  1402.  
  1403. element.toggle(index === section);
  1404. });
  1405. });
  1406.  
  1407. const wagonSection = $(
  1408. `#tr_rezerwacja_obok_miejsca_juz_zajetego_wagon${suffix}`
  1409. );
  1410.  
  1411. const seatSection = $(
  1412. `#tr_rezerwacja_obok_miejsca_juz_zajetego_miejsce${suffix}`
  1413. );
  1414.  
  1415. const occupiedSeat = $(
  1416. `#rezerwacja_obok_miejsca_juz_zajetego${suffix}`
  1417. );
  1418.  
  1419. const selectedSeat = $(
  1420. `#rezerwacja_miejsca_wskazanego${suffix}`
  1421. );
  1422.  
  1423. const shouldShow =
  1424. occupiedSeat.is(":checked") ||
  1425. selectedSeat.is(":checked");
  1426.  
  1427. wagonSection.toggle(shouldShow);
  1428. seatSection.toggle(shouldShow);
  1429.  
  1430. if (section === 0) {
  1431. wagonSection.removeClass(
  1432. "display-hide-important"
  1433. );
  1434. seatSection.removeClass(
  1435. "display-hide-important"
  1436. );
  1437. } else {
  1438. wagonSection.addClass(
  1439. "display-hide-important"
  1440. );
  1441. seatSection.addClass(
  1442. "display-hide-important"
  1443. );
  1444. }
  1445. }
  1446.  
  1447. /*
  1448. * ----------------------------------------------------------------------
  1449. * Main "Next" button logic
  1450. * ----------------------------------------------------------------------
  1451. */
  1452.  
  1453. function handleNextClick(event) {
  1454. event.preventDefault();
  1455.  
  1456. const button = $(this);
  1457.  
  1458. const quietZoneCoachTypes =
  1459. constants.coachType.QUIET_ZONE;
  1460.  
  1461. const childUnderSixCoachTypes =
  1462. constants.coachType.CHILD_UNDER_6;
  1463.  
  1464. const coachTypeValue =
  1465. getSelectedInt("#rodzaj_wagonu");
  1466.  
  1467. const transferCoachType1 =
  1468. getInt("#rodzaj_wagonu_odcinek_2");
  1469.  
  1470. const transferCoachType2 =
  1471. getInt("#rodzaj_wagonu_odcinek_3");
  1472.  
  1473. const isDomestic = button.attr("krajowy");
  1474. const startingCategory =
  1475. getInt(button, 0) ||
  1476. parseInt(button.attr("kat_poc"), 10);
  1477.  
  1478. const isFamilyCard =
  1479. isChecked("#karta_duzej_rodziny");
  1480.  
  1481. const isFamilyTicket =
  1482. isChecked("#bilet_rodzinny");
  1483.  
  1484. const isMiniGroup =
  1485. $("#mini_grupa").val() === "1";
  1486.  
  1487. const isTodayRelation =
  1488. $("#relacja_na_dzisiaj").val() === "1";
  1489.  
  1490. const minimumFamilyPassengers =
  1491. getInt("#bilet_rodzinny_min_liczba_osob");
  1492.  
  1493. let isTransfer =
  1494. ParamUtil.parseBoolean(
  1495. button.attr("przesiadka")
  1496. );
  1497.  
  1498. const hasTwoTransfers =
  1499. ParamUtil.parseBoolean(
  1500. button.attr("przesiadki2")
  1501. );
  1502.  
  1503. const ignoreSection =
  1504. ParamUtil.parseBoolean(
  1505. button.attr("ignoruj_odc")
  1506. );
  1507.  
  1508. if (ignoreSection) {
  1509. isTransfer = false;
  1510. }
  1511.  
  1512. /*
  1513. * Validate seat number fields before doing anything else.
  1514. */
  1515. if (
  1516. !validMiejsceSasiadujaceWskazane(
  1517. constants.section.FIRST
  1518. )
  1519. ) {
  1520. return;
  1521. }
  1522.  
  1523. if (!validateCompanionTicketNumber()) {
  1524. return;
  1525. }
  1526.  
  1527. hideAllContinueModals();
  1528.  
  1529. const modalState = {
  1530. open: false,
  1531. attention: false,
  1532. dogCompartment: false,
  1533. childAdultBed: false,
  1534. childAdultBedCovid: false,
  1535. internationalDates: false,
  1536. metropolitanChild: false,
  1537. possibleMiniGroup: false
  1538. };
  1539.  
  1540. /*
  1541. * --------------------------------------------------------------
  1542. * Domestic ticket validation
  1543. * --------------------------------------------------------------
  1544. */
  1545.  
  1546. if (isDomestic) {
  1547. /*
  1548. * Quiet zone
  1549. */
  1550. if (
  1551. (
  1552. quietZoneCoachTypes.includes(coachTypeValue) ||
  1553. quietZoneCoachTypes.includes(
  1554. transferCoachType1
  1555. )
  1556. ) &&
  1557. !isTransfer
  1558. ) {
  1559. modalState.open = true;
  1560. $("#dalej_modal_strefa_ciszy").show();
  1561. $("#dalej_modal_ok").val(
  1562. $("#dalej_modal_ok").attr("v1")
  1563. );
  1564. }
  1565.  
  1566. /*
  1567. * Passenger travelling with a child under 6.
  1568. */
  1569. if (
  1570. transferStep === 0 &&
  1571. childUnderSixCoachTypes.includes(coachTypeValue) &&
  1572. !AdditionalTicketService()
  1573. .czyNieWybranoCalegoPrzedzialuDlaPsa()
  1574. ) {
  1575. const passengerCount =
  1576. getPassengerCount();
  1577.  
  1578. if (
  1579. passengerCount >= 2 &&
  1580. (startingCategory !== 81 ||
  1581. passengerCount <= 4)
  1582. ) {
  1583. modalState.open = true;
  1584. $("#dalej_modal_dla_podr_z_dzieckiem_do_lat_6")
  1585. .show();
  1586.  
  1587. $("#dalej_modal_ok").val(
  1588. $("#dalej_modal_ok").attr("v1")
  1589. );
  1590. }
  1591. }
  1592.  
  1593. /*
  1594. * Family ticket.
  1595. */
  1596. if (isFamilyTicket) {
  1597. handleFamilyTicketValidation(
  1598. modalState,
  1599. isMiniGroup,
  1600. minimumFamilyPassengers
  1601. );
  1602. } else if (isFamilyCard) {
  1603. modalState.open = true;
  1604.  
  1605. $("#dalej_modal_duza_rodzina").show();
  1606. $("#dalej_modal_ok").val(
  1607. $("#dalej_modal_ok").attr("v2")
  1608. );
  1609. } else if (
  1610. isMiniGroup &&
  1611. !isTodayRelation
  1612. ) {
  1613. handlePossibleMiniGroup(
  1614. modalState,
  1615. minimumFamilyPassengers
  1616. );
  1617. }
  1618.  
  1619. /*
  1620. * Railway employees.
  1621. */
  1622. if (
  1623. getRailwayEmployeeDiscountCount() > 1 &&
  1624. !ZakupBiletuUtil().isPolbus()
  1625. ) {
  1626. modalState.open = true;
  1627. $("#dalej_modal_pracownik_kolei").show();
  1628. }
  1629.  
  1630. /*
  1631. * Dog compartment.
  1632. */
  1633. if (
  1634. AdditionalTicketService()
  1635. .czyNieWybranoCalegoPrzedzialuDlaPsa()
  1636. ) {
  1637. modalState.open = true;
  1638. modalState.dogCompartment = true;
  1639. }
  1640.  
  1641. /*
  1642. * Child + adult sharing one bed.
  1643. */
  1644. if (
  1645. czyWybranoWspolneUsytuowanieNaJednymLozkuDzieckoOpiekun()
  1646. ) {
  1647. modalState.open = true;
  1648.  
  1649. if (ZakupBiletuUtil().isCOVID()) {
  1650. modalState.childAdultBedCovid = true;
  1651. } else {
  1652. modalState.childAdultBed = true;
  1653. }
  1654. }
  1655.  
  1656. /*
  1657. * Child compartment.
  1658. */
  1659. if (czyPrzedzialDlaOsobyZDzieckiemDoLat6()) {
  1660. modalState.open = true;
  1661. $("#dalej_modal_przedzial_dla_osoby_z_dzieckiem_do_lat_6")
  1662. .show();
  1663. }
  1664. }
  1665.  
  1666. /*
  1667. * Metropolitan child.
  1668. */
  1669. if (exists("#dalej_modal_dziecko_metropol")) {
  1670. const adultCount = getInt("#liczba_n");
  1671. const reducedPassengerCount = getInt("#liczba_u");
  1672. const tariff = getInt("#nrTaryfyII");
  1673.  
  1674. if (
  1675. adultCount === 0 &&
  1676. reducedPassengerCount > 0 &&
  1677. tariff === 73
  1678. ) {
  1679. modalState.open = true;
  1680. modalState.metropolitanChild = true;
  1681. }
  1682. }
  1683.  
  1684. /*
  1685. * Bicycle ticket exception.
  1686. */
  1687. if (exists(".bilet_dodatkowy")) {
  1688. $(".bilet_dodatkowy").each(function () {
  1689. const selectedTicket = parseInt(
  1690. $(this).find("option:selected").val(),
  1691. 10
  1692. );
  1693.  
  1694. if (
  1695. selectedTicket ===
  1696. constants.additionalTicket.BICYCLE &&
  1697. !isFamilyTicket &&
  1698. !isMiniGroup
  1699. ) {
  1700. modalState.open = false;
  1701. }
  1702. });
  1703. }
  1704.  
  1705. /*
  1706. * International exchange with non-chronological dates.
  1707. */
  1708. if (
  1709. exists(
  1710. "#dalej_modal_wymiana_mm_niechronologiczne_daty"
  1711. )
  1712. ) {
  1713. modalState.open = true;
  1714. modalState.internationalDates = true;
  1715. }
  1716.  
  1717. /*
  1718. * Railway employee discount with different train categories.
  1719. */
  1720. if (
  1721. button.attr("przesiadka") === "true"
  1722. ) {
  1723. const category1 = button.attr("kat_1");
  1724. const category2 = button.attr("kat_2");
  1725.  
  1726. if (
  1727. category1 !== category2 &&
  1728. containsMixedRailwayDiscounts()
  1729. ) {
  1730. modalState.open = true;
  1731. modalState.attention = true;
  1732. }
  1733. }
  1734.  
  1735. /*
  1736. * --------------------------------------------------------------
  1737. * Show modal / continue with transfer / submit
  1738. * --------------------------------------------------------------
  1739. */
  1740.  
  1741. const modalService = new ModalService();
  1742.  
  1743. if (
  1744. modalState.open &&
  1745. transferStep === 0
  1746. ) {
  1747. showNextModal(
  1748. modalService,
  1749. modalState
  1750. );
  1751.  
  1752. if (isTransfer) {
  1753. configureTransferModal(button);
  1754. }
  1755.  
  1756. button.okienkoModalne().open();
  1757. return;
  1758. }
  1759.  
  1760. if (isTransfer) {
  1761. handleTransferContinue(
  1762. button,
  1763. hasTwoTransfers,
  1764. childUnderSixCoachTypes,
  1765. startingCategory,
  1766. transferCoachType1,
  1767. transferCoachType2
  1768. );
  1769.  
  1770. return;
  1771. }
  1772.  
  1773. submitOrShowHiddenStationModal(
  1774. button,
  1775. modalService
  1776. );
  1777. }
  1778.  
  1779. function handleFamilyTicketValidation(
  1780. modalState,
  1781. isMiniGroup,
  1782. minimumPassengers
  1783. ) {
  1784. const passengerCount =
  1785. getPassengerCount(true);
  1786.  
  1787. if (isMiniGroup) {
  1788. if (
  1789. isVisible("#dalej_modal_strefa_ciszy")
  1790. ) {
  1791. $("#dalej_modal_strefa_ciszy").hide();
  1792. $("#dalej_modal_bilet_rodzinny_strefa_ciszy")
  1793. .show();
  1794.  
  1795. $("#dalej_modal_ok").val(
  1796. $("#dalej_modal_ok").attr("v2")
  1797. );
  1798. } else if (
  1799. passengerCount < minimumPassengers
  1800. ) {
  1801. modalState.open = true;
  1802.  
  1803. $("#dalej_modal_bilet_rodzinny").show();
  1804. $("#dalej_modal_ok").val(
  1805. $("#dalej_modal_ok").attr("v2")
  1806. );
  1807. }
  1808.  
  1809. return;
  1810. }
  1811.  
  1812. const adults = getInt("#liczba_n");
  1813. const reduced1 = getInt("#liczba_u");
  1814. const reduced2 = getInt("#liczba_u_2");
  1815.  
  1816. const discount1 =
  1817. getInt("#rodzaj_ulgi_wrap_1 #kod_znizki");
  1818.  
  1819. const discount2 =
  1820. getInt("#rodzaj_ulgi_wrap_2 #kod_znizki_2");
  1821.  
  1822. const total = adults + reduced1 + reduced2;
  1823.  
  1824. if (
  1825. adults === 0 &&
  1826. reduced1 + reduced2 > 0
  1827. ) {
  1828. modalState.open = true;
  1829.  
  1830. $("#dalej_modal_bilet_rodzinny_bledna_liczba_osob")
  1831. .show();
  1832.  
  1833. $("#dalej_modal_ok").val(
  1834. $("#dalej_modal_ok").attr("v2")
  1835. );
  1836.  
  1837. return;
  1838. }
  1839.  
  1840. const hasExcludedDiscount =
  1841. (reduced1 > 0 && discount1 === 77) ||
  1842. (reduced2 > 0 && discount2 === 77);
  1843.  
  1844. const validPassengerCount =
  1845. total >= 2 && total <= 5;
  1846.  
  1847. if (
  1848. !hasExcludedDiscount &&
  1849. validPassengerCount &&
  1850. (
  1851. adults >= 2 ||
  1852. (reduced1 > 0 && discount1 > 1) ||
  1853. (reduced2 > 0 && discount2 > 1)
  1854. )
  1855. ) {
  1856. modalState.open = true;
  1857.  
  1858. $("#dalej_modal_bilet_rodzinny")
  1859. .show();
  1860.  
  1861. $("#dalej_modal_ok").val(
  1862. $("#dalej_modal_ok").attr("v2")
  1863. );
  1864. }
  1865.  
  1866. if (
  1867. isVisible("#dalej_modal_strefa_ciszy") &&
  1868. isVisible("#dalej_modal_bilet_rodzinny")
  1869. ) {
  1870. $("#dalej_modal_strefa_ciszy").hide();
  1871. $("#dalej_modal_bilet_rodzinny").hide();
  1872. $("#dalej_modal_bilet_rodzinny_strefa_ciszy")
  1873. .show();
  1874.  
  1875. $("#dalej_modal_ok").val(
  1876. $("#dalej_modal_ok").attr("v2")
  1877. );
  1878. }
  1879. }
  1880.  
  1881. function handlePossibleMiniGroup(
  1882. modalState,
  1883. minimumPassengers
  1884. ) {
  1885. if (
  1886. getPassengerCount() <
  1887. minimumPassengers
  1888. ) {
  1889. return;
  1890. }
  1891.  
  1892. const discountIds = [
  1893. "#kod_znizki",
  1894. "#kod_znizki_2",
  1895. "#kod_znizki_3"
  1896. ];
  1897.  
  1898. const hasAllowedDiscount =
  1899. discountIds.some((selector) => {
  1900. const value = $(selector).val();
  1901.  
  1902. return constants.miniGroupDiscounts.includes(
  1903. value
  1904. );
  1905. });
  1906.  
  1907. if (!hasAllowedDiscount) {
  1908. modalState.open = true;
  1909. modalState.possibleMiniGroup = true;
  1910.  
  1911. $("#mini_grupa_mozliwa").show();
  1912. $("#dalej_modal_ok").val(
  1913. $("#dalej_modal_ok").attr("v6")
  1914. );
  1915. }
  1916. }
  1917.  
  1918. function showNextModal(
  1919. modalService,
  1920. state
  1921. ) {
  1922. if (state.attention) {
  1923. modalService.dalejModalAtention();
  1924. } else if (state.dogCompartment) {
  1925. modalService.dalejModalBiletPiesCalyPrzedzial();
  1926. } else if (state.childAdultBed) {
  1927. modalService.dalejModalJednoLozkoDzieckoOpiekun();
  1928. } else if (state.childAdultBedCovid) {
  1929. modalService.dalejModalJednoLozkoDzieckoOpiekunCOVID();
  1930. } else if (state.internationalDates) {
  1931. modalService.dalejModalMiedzynarodowyNiechronologiczneDaty();
  1932. } else if (state.metropolitanChild) {
  1933. modalService.dalejModalMiedzynarodowyDzieckoMetropol();
  1934. } else if (state.possibleMiniGroup) {
  1935. modalService.dalejModalMozliwaMiniGrupa();
  1936. } else {
  1937. /*
  1938. * The original code used `dalej_modal_false = true`
  1939. * which made this branch effectively unconditional.
  1940. *
  1941. * This is now explicit.
  1942. */
  1943. modalService.dalejModalFalse();
  1944. }
  1945. }
  1946.  
  1947. function configureTransferModal(button) {
  1948. $("#dalej_modal_ok")
  1949. .attr("type", "button")
  1950. .off("click.zakupBiletu")
  1951. .on("click.zakupBiletu", function () {
  1952. transferStep++;
  1953. przesiadkiService(transferStep);
  1954.  
  1955. $(this)
  1956. .okienkoModalne()
  1957. .close();
  1958. });
  1959.  
  1960. $("#dalej_modal_nie")
  1961. .off("click.zakupBiletu")
  1962. .on("click.zakupBiletu", function () {
  1963. transferStep++;
  1964. przesiadkiService(transferStep);
  1965.  
  1966. $(this)
  1967. .okienkoModalne()
  1968. .close();
  1969. });
  1970. }
  1971.  
  1972. function handleTransferContinue(
  1973. button,
  1974. hasTwoTransfers,
  1975. childCoachTypes,
  1976. startingCategory,
  1977. transferCoachType1,
  1978. transferCoachType2
  1979. ) {
  1980. if (
  1981. ZakupBiletuUtil()
  1982. .czyWybranoZnizkiKolejarzaPolbus()
  1983. ) {
  1984. new ModalService()
  1985. .modalZnizkiDlaKolejarzaPolbus(button);
  1986.  
  1987. return;
  1988. }
  1989.  
  1990. if (
  1991. ObslugaKlopotliwychZnizek()
  1992. .validate(button)
  1993. ) {
  1994. return;
  1995. }
  1996.  
  1997. const isFirstSection =
  1998. transferStep === 0 ||
  1999. (
  2000. hasTwoTransfers &&
  2001. transferStep === 1
  2002. );
  2003.  
  2004. if (isFirstSection) {
  2005. const station =
  2006. transferStep === 0
  2007. ? button.attr("nr_poc_2")
  2008. : button.attr("nr_poc_3");
  2009.  
  2010. const departure =
  2011. transferStep === 0
  2012. ? button.attr("data_odj_2")
  2013. : button.attr("data_odj_3");
  2014.  
  2015. informacja_pasazerska(
  2016. station,
  2017. departure,
  2018. button.attr("lang")
  2019. );
  2020.  
  2021. transferStep++;
  2022. przesiadkiService(transferStep);
  2023.  
  2024. return;
  2025. }
  2026.  
  2027. const isSecondSection =
  2028. (
  2029. !hasTwoTransfers &&
  2030. transferStep === 1
  2031. ) ||
  2032. (
  2033. hasTwoTransfers &&
  2034. transferStep === 2
  2035. );
  2036.  
  2037. if (!isSecondSection) {
  2038. return;
  2039. }
  2040.  
  2041. if (
  2042. constants.coachType.QUIET_ZONE.includes(
  2043. transferCoachType1
  2044. ) ||
  2045. constants.coachType.QUIET_ZONE.includes(
  2046. transferCoachType2
  2047. )
  2048. ) {
  2049. const modalButton =
  2050. prepareStrefaCiszyPrzesiadkiModal();
  2051.  
  2052. modalButton
  2053. .off("click.zakupBiletu")
  2054. .on("click.zakupBiletu", function () {
  2055. transferStep++;
  2056. przesiadkiService(transferStep);
  2057.  
  2058. if (
  2059. (
  2060. !hasTwoTransfers &&
  2061. transferStep > 1
  2062. ) ||
  2063. (
  2064. hasTwoTransfers &&
  2065. transferStep > 2
  2066. )
  2067. ) {
  2068. submitForm();
  2069. }
  2070. });
  2071.  
  2072. button.okienkoModalne().open();
  2073. return;
  2074. }
  2075.  
  2076. if (
  2077. czyWybranoDlaPodroznychZDziecmiDoLat6(
  2078. button,
  2079. childCoachTypes,
  2080. startingCategory
  2081. )
  2082. ) {
  2083. return;
  2084. }
  2085.  
  2086. if (
  2087. !validMiejsceSasiadujaceWskazane(
  2088. constants.section.SECOND
  2089. )
  2090. ) {
  2091. return;
  2092. }
  2093.  
  2094. submitOrShowHiddenStationModal(
  2095. button,
  2096. new ModalService()
  2097. );
  2098. }
  2099.  
  2100. function prepareStrefaCiszyPrzesiadkiModal() {
  2101. $("#dalej_modal_inform").hide();
  2102. $("#dalej_modal_tak").hide();
  2103. $("#dalej_modal_strefa_ciszy").show();
  2104. $("#dalej_modal_footer").show();
  2105.  
  2106. const modal = $("#dalej_modal_ok");
  2107.  
  2108. modal
  2109. .val(modal.attr("v1"))
  2110. .attr("type", "button")
  2111. .addClass("js-modal-close");
  2112.  
  2113. return modal;
  2114. }
  2115.  
  2116. function submitOrShowHiddenStationModal(
  2117. button,
  2118. modalService
  2119. ) {
  2120. if (
  2121. $("#popup_metastacja_niejawna").val() === "1"
  2122. ) {
  2123. modalService.dalejModalStacjaNiejawna();
  2124. $("#dalej_metastacja_niejawna").show();
  2125.  
  2126. button.okienkoModalne().open();
  2127. return;
  2128. }
  2129.  
  2130. submitForm();
  2131. }
  2132.  
  2133. function przesiadkiService(index) {
  2134. const transfer = new PrzesiadkiZakupowe();
  2135.  
  2136. transfer.setIndexPrzesiadki(index);
  2137. transfer.zablokujPolaDlaPrzesiadkiZakupowej(index);
  2138. transfer.aktywujDeaktywujElementy();
  2139.  
  2140. ObslugaKlopotliwychZnizek()
  2141. .pokazKomunikatRozneKatPoc_Eip_TLK();
  2142. }
  2143.  
  2144. /*
  2145. * ----------------------------------------------------------------------
  2146. * Form / UI events
  2147. * ----------------------------------------------------------------------
  2148. */
  2149.  
  2150. function bindSeatNumberValidation() {
  2151. [
  2152. "#numer_wagonu",
  2153. "#numer_miejsca",
  2154. "#numer_wagonu_2",
  2155. "#numer_miejsca_2",
  2156. "#numer_wagonu_3",
  2157. "#numer_miejsca_3"
  2158. ].forEach((selector) => {
  2159. $(selector)
  2160. .off("blur.zakupBiletu")
  2161. .on("blur.zakupBiletu", function () {
  2162. validateSeatNumberFields(
  2163. selector.endsWith("_2") ? 2 :
  2164. selector.endsWith("_3") ? 3 : 1
  2165. );
  2166. });
  2167. });
  2168. }
  2169.  
  2170. function bindEvents() {
  2171. nextButton
  2172. .off("click.zakupBiletu")
  2173. .on("click.zakupBiletu", handleNextClick);
  2174.  
  2175. previousConnectionButton
  2176. .off("click.zakupBiletu")
  2177. .on("click.zakupBiletu", function () {
  2178. informacja_pasazerska(
  2179. $(this).attr("nr_poc_1"),
  2180. $(this).attr("data_odj_1"),
  2181. $(this).attr("lang")
  2182. );
  2183.  
  2184. transferStep = 0;
  2185.  
  2186. const transfer =
  2187. new PrzesiadkiZakupowe();
  2188.  
  2189. transfer.setIndexPrzesiadki(0);
  2190. transfer.odblokujPolaDlaPrzesiadkiZakupowej();
  2191. transfer.aktywujDeaktywujElementy();
  2192.  
  2193. $()
  2194. .obslugaUlgi()
  2195. .obslugaWieluZnizek();
  2196. });
  2197.  
  2198. nextConnectionButton
  2199. .off("click.zakupBiletu")
  2200. .on("click.zakupBiletu", function () {
  2201. const transfer =
  2202. new PrzesiadkiZakupowe();
  2203.  
  2204. if (transferStep === 0) {
  2205. transferStep++;
  2206.  
  2207. transfer.setIndexPrzesiadki(
  2208. transferStep
  2209. );
  2210.  
  2211. transfer.aktywujDeaktywujElementy();
  2212. }
  2213.  
  2214. transfer.zablokujPolaDlaPrzesiadkiZakupowej(
  2215. transferStep
  2216. );
  2217. });
  2218.  
  2219. externalInfoArrow
  2220. .off("click.zakupBiletu")
  2221. .on("click.zakupBiletu", function () {
  2222. $(this)
  2223. .closest(".data_box_section")
  2224. .find(".data_box_rwd")
  2225. .removeClass("data_box_hide")
  2226. .addClass("data_box_show");
  2227.  
  2228. $(this)
  2229. .removeClass("arrow_box_down")
  2230. .addClass("arrow_box_up");
  2231. });
  2232.  
  2233. form
  2234. .off("submit.zakupBiletu")
  2235. .on("submit.zakupBiletu", function () {
  2236. return validateCompanionTicketNumber();
  2237. });
  2238.  
  2239. coachType
  2240. .off("change.zakupBiletu")
  2241. .on("change.zakupBiletu", function () {
  2242. const value = $(this)
  2243. .find("option:selected")
  2244. .val();
  2245.  
  2246. rodzajWagonuOpis(value);
  2247. sprawdzRowerRodzajWagonu();
  2248. usunInformacjeWstepnaDlaPrzedzialDzieckoDo6Lat();
  2249. });
  2250.  
  2251. wagonClass
  2252. .off("change.zakupBiletu")
  2253. .on("change.zakupBiletu", function () {
  2254. if (!politicianMode.length) {
  2255. ustawKlasaWagonu();
  2256. }
  2257. });
  2258.  
  2259. bindSeatNumberValidation();
  2260. }
  2261.  
  2262. /*
  2263. * ----------------------------------------------------------------------
  2264. * Public plugin API
  2265. * ----------------------------------------------------------------------
  2266. */
  2267.  
  2268. function init() {
  2269. bindEvents();
  2270. }
  2271.  
  2272. init();
  2273.  
  2274. return {
  2275. init
  2276. };
  2277. };
  2278.  
  2279. })(jQuery);
Add Comment
Please, Sign In to add comment