From e3552166181a1e08458ce9cdfe45c27060713d6d Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Tue, 19 Mar 2024 10:03:17 +0100 Subject: [PATCH 1/2] refactor: add shipping method in config resolver for more flexibility --- src/Form/Type/ShippingSlotConfigsByMethod.php | 21 ++++++++++--------- src/Resolver/ShippingSlotConfigResolver.php | 16 +++++++++++++- .../ShippingSlotConfigResolverInterface.php | 3 ++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/Form/Type/ShippingSlotConfigsByMethod.php b/src/Form/Type/ShippingSlotConfigsByMethod.php index b59e346..5ceb648 100644 --- a/src/Form/Type/ShippingSlotConfigsByMethod.php +++ b/src/Form/Type/ShippingSlotConfigsByMethod.php @@ -13,7 +13,7 @@ namespace MonsieurBiz\SyliusShippingSlotPlugin\Form\Type; -use MonsieurBiz\SyliusShippingSlotPlugin\Entity\ShipmentInterface; +use MonsieurBiz\SyliusShippingSlotPlugin\Entity\ShippingMethodInterface as MonsieurBizShippingMethodInterface; use MonsieurBiz\SyliusShippingSlotPlugin\Resolver\ShippingSlotConfigResolverInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\Component\Shipping\Model\ShippingMethodInterface; @@ -48,15 +48,17 @@ public function __construct( public function buildForm(FormBuilderInterface $builder, array $options): void { $subject = $options['subject'] ?? null; - $currentShippingSlotConfig = $this->shippingSlotConfigResolver->getShippingSlotConfig($subject); - $currentShippingMethod = $this->getCurrentShippingMethod($subject); foreach ($this->getShippingMethods($subject) as $shippingMethod) { + if (!$this->isShippingSlotMethod($shippingMethod)) { + continue; + } + $builder->add($shippingMethod->getCode(), ChoiceType::class, [ 'choices' => $shippingMethod->getShippingSlotConfigs(), 'choice_label' => 'name', 'choice_value' => 'id', 'label' => false, - 'data' => $currentShippingMethod === $shippingMethod ? $currentShippingSlotConfig : null, + 'data' => $this->shippingSlotConfigResolver->getShippingSlotConfig($subject, $shippingMethod), ]); } } @@ -81,12 +83,11 @@ private function getShippingMethods(?ShippingSubjectInterface $subject): array return $this->repository->findAll(); } - private function getCurrentShippingMethod(?ShippingSubjectInterface $subject): ?ShippingMethodInterface + private function isShippingSlotMethod(ShippingMethodInterface $shippingMethod): bool { - if (!$subject instanceof ShipmentInterface) { - return null; - } - - return $subject->getMethod(); + return null !== $shippingMethod->getCode() + && $shippingMethod instanceof MonsieurBizShippingMethodInterface + && !$shippingMethod->getShippingSlotConfigs()->isEmpty() + ; } } diff --git a/src/Resolver/ShippingSlotConfigResolver.php b/src/Resolver/ShippingSlotConfigResolver.php index caf0f8f..cd2667b 100644 --- a/src/Resolver/ShippingSlotConfigResolver.php +++ b/src/Resolver/ShippingSlotConfigResolver.php @@ -16,15 +16,29 @@ use MonsieurBiz\SyliusShippingSlotPlugin\Entity\ShipmentInterface as MonsieurBizShipmentInterface; use MonsieurBiz\SyliusShippingSlotPlugin\Entity\ShippingSlotConfigInterface; use Sylius\Component\Core\Model\ShipmentInterface; +use Sylius\Component\Core\Model\ShippingMethodInterface; final class ShippingSlotConfigResolver implements ShippingSlotConfigResolverInterface { - public function getShippingSlotConfig(?ShipmentInterface $shipment): ?ShippingSlotConfigInterface + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getShippingSlotConfig(?ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod): ?ShippingSlotConfigInterface { if (!$shipment instanceof MonsieurBizShipmentInterface) { return null; } + $currentShippingMethod = $this->getCurrentShippingMethod($shipment); + if ($currentShippingMethod !== $shippingMethod) { + return null; + } return null !== $shipment->getSlot() ? $shipment->getSlot()->getShippingSlotConfig() : null; } + + private function getCurrentShippingMethod(?ShipmentInterface $subject): ?ShippingMethodInterface + { + /** @phpstan-ignore-next-line */ + return $subject->getMethod(); + } } diff --git a/src/Resolver/ShippingSlotConfigResolverInterface.php b/src/Resolver/ShippingSlotConfigResolverInterface.php index 2d064d2..93f4611 100644 --- a/src/Resolver/ShippingSlotConfigResolverInterface.php +++ b/src/Resolver/ShippingSlotConfigResolverInterface.php @@ -15,8 +15,9 @@ use MonsieurBiz\SyliusShippingSlotPlugin\Entity\ShippingSlotConfigInterface; use Sylius\Component\Core\Model\ShipmentInterface; +use Sylius\Component\Core\Model\ShippingMethodInterface; interface ShippingSlotConfigResolverInterface { - public function getShippingSlotConfig(?ShipmentInterface $shipment): ?ShippingSlotConfigInterface; + public function getShippingSlotConfig(?ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod): ?ShippingSlotConfigInterface; } From 5f22a70bee8121096f7e19bf85300fc6f81a82ac Mon Sep 17 00:00:00 2001 From: Maxime Leclercq Date: Tue, 19 Mar 2024 10:20:49 +0100 Subject: [PATCH 2/2] feat: add slot config container for more flexibility --- assets/js/app.js | 41 +++++++++++++------ src/Resources/public/js/shipping-slot-js.js | 2 +- .../ShippingSlot/_slotConfig.html.twig | 4 +- src/Resources/views/Shop/app.html.twig | 6 ++- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 3188750..4fd8562 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -19,7 +19,8 @@ global.MonsieurBizShippingSlotManager = class { saveSlotUrl, resetSlotUrl, slotSelectError, - shippingSlotConfigSelects, + shippingSlotConfigContainers, + shippingSlotConfigSelectSelector, ) { this.shippingMethodInputs = shippingMethodInputs; this.nextStepButtons = nextStepButtons; @@ -34,7 +35,8 @@ global.MonsieurBizShippingSlotManager = class { this.saveSlotUrl = saveSlotUrl; this.resetSlotUrl = resetSlotUrl; this.slotSelectError = slotSelectError; - this.shippingSlotConfigSelects = shippingSlotConfigSelects; + this.shippingSlotConfigContainers = shippingSlotConfigContainers; + this.shippingSlotConfigSelectSelector = shippingSlotConfigSelectSelector; this.previousSlot = null; this.initShippingMethodInputs(); } @@ -49,7 +51,12 @@ global.MonsieurBizShippingSlotManager = class { this.initShippingMethodInput(shippingMethodInput); } - this.shippingSlotConfigSelects.forEach(shippingSlotConfigSelect => { + this.shippingSlotConfigContainers.forEach(shippingSlotConfigContainer => { + let shippingSlotConfigSelect = shippingSlotConfigContainer.querySelector(this.shippingSlotConfigSelectSelector); + if (shippingSlotConfigSelect === null) { + return; + } + shippingSlotConfigSelect.addEventListener("change", function () { let checkedShippingMethodInput = Array.from(this.shippingMethodInputs).find(shippingMethodInput => shippingMethodInput.checked); if (checkedShippingMethodInput !== null) { @@ -94,9 +101,9 @@ global.MonsieurBizShippingSlotManager = class { let data = JSON.parse(this.responseText); - // Hide calendars and shipping slot config selects + // Hide calendars and shipping slot config containers shippingSlotManager.hideCalendars(); - shippingSlotManager.hideShippingSlotConfigSelects(); + shippingSlotManager.hideShippingSlotConfigContainers(); // Authorize user to go to next step if no slot needed if (typeof data.events === "undefined") { @@ -211,9 +218,9 @@ global.MonsieurBizShippingSlotManager = class { } } - hideShippingSlotConfigSelects() { - for (let shippingSlotConfigSelect of this.shippingSlotConfigSelects) { - shippingSlotConfigSelect.style.display = "none"; + hideShippingSlotConfigContainers() { + for (let shippingSlotConfigContainer of this.shippingSlotConfigContainers) { + shippingSlotConfigContainer.style.display = "none"; } } @@ -256,7 +263,12 @@ global.MonsieurBizShippingSlotManager = class { initCalendar(calendarContainer, events, timezone, shippingMethodCode, shippingSlotConfigSelect) { calendarContainer.style.display = "block"; if (shippingSlotConfigSelect) { - shippingSlotConfigSelect.style.display = "block"; + let currentShippingSlotConfigContainer = Array.from(this.shippingSlotConfigContainers).find( + shippingSlotConfigContainer => shippingSlotConfigContainer.classList.contains(shippingMethodCode) + ); + if (currentShippingSlotConfigContainer) { + currentShippingSlotConfigContainer.style.display = "block"; + } } let shippingSlotManager = this; let calendar = new Calendar( @@ -345,8 +357,13 @@ global.MonsieurBizShippingSlotManager = class { } getShippingSlotConfigSelect(shippingMethodCode) { - return Array.from(this.shippingSlotConfigSelects).find( - shippingSlotConfigSelect => shippingSlotConfigSelect.name.includes(shippingMethodCode) - ) ?? null; + for (let shippingSlotConfigContainer of this.shippingSlotConfigContainers) { + let shippingSlotConfigSelect = shippingSlotConfigContainer.querySelector(this.shippingSlotConfigSelectSelector); + if (shippingSlotConfigSelect !== null && shippingSlotConfigSelect.name.includes(shippingMethodCode)) { + return shippingSlotConfigSelect; + } + } + + return null; } }; diff --git a/src/Resources/public/js/shipping-slot-js.js b/src/Resources/public/js/shipping-slot-js.js index 3e18e71..5235d08 100644 --- a/src/Resources/public/js/shipping-slot-js.js +++ b/src/Resources/public/js/shipping-slot-js.js @@ -210,7 +210,7 @@ var t={0:"-чү",1:"-чи",2:"-чи",3:"-чү",4:"-чү",5:"-чи",6:"-чы",7:" //! moment.js locale configuration e.defineLocale("cv",{months:"кӑрлач_нарӑс_пуш_ака_май_ҫӗртме_утӑ_ҫурла_авӑн_юпа_чӳк_раштав".split("_"),monthsShort:"кӑр_нар_пуш_ака_май_ҫӗр_утӑ_ҫур_авн_юпа_чӳк_раш".split("_"),weekdays:"вырсарникун_тунтикун_ытларикун_юнкун_кӗҫнерникун_эрнекун_шӑматкун".split("_"),weekdaysShort:"выр_тун_ытл_юн_кӗҫ_эрн_шӑм".split("_"),weekdaysMin:"вр_тн_ыт_юн_кҫ_эр_шм".split("_"),longDateFormat:{LT:"HH:mm",LTS:"HH:mm:ss",L:"DD-MM-YYYY",LL:"YYYY [ҫулхи] MMMM [уйӑхӗн] D[-мӗшӗ]",LLL:"YYYY [ҫулхи] MMMM [уйӑхӗн] D[-мӗшӗ], HH:mm",LLLL:"dddd, YYYY [ҫулхи] MMMM [уйӑхӗн] D[-мӗшӗ], HH:mm"},calendar:{sameDay:"[Паян] LT [сехетре]",nextDay:"[Ыран] LT [сехетре]",lastDay:"[Ӗнер] LT [сехетре]",nextWeek:"[Ҫитес] dddd LT [сехетре]",lastWeek:"[Иртнӗ] dddd LT [сехетре]",sameElse:"L"},relativeTime:{future:function(e){return e+(/сехет$/i.exec(e)?"рен":/ҫул$/i.exec(e)?"тан":"ран")},past:"%s каялла",s:"пӗр-ик ҫеккунт",ss:"%d ҫеккунт",m:"пӗр минут",mm:"%d минут",h:"пӗр сехет",hh:"%d сехет",d:"пӗр кун",dd:"%d кун",M:"пӗр уйӑх",MM:"%d уйӑх",y:"пӗр ҫул",yy:"%d ҫул"},dayOfMonthOrdinalParse:/\d{1,2}-мӗш/,ordinal:"%d-мӗш",week:{dow:1,doy:7}})}(n("qW9H"))},nTVo:function(e,t,n){!function(e){"use strict"; //! moment.js locale configuration -e.defineLocale("mk",{months:"јануари_февруари_март_април_мај_јуни_јули_август_септември_октомври_ноември_декември".split("_"),monthsShort:"јан_фев_мар_апр_мај_јун_јул_авг_сеп_окт_ное_дек".split("_"),weekdays:"недела_понеделник_вторник_среда_четврток_петок_сабота".split("_"),weekdaysShort:"нед_пон_вто_сре_чет_пет_саб".split("_"),weekdaysMin:"нe_пo_вт_ср_че_пе_сa".split("_"),longDateFormat:{LT:"H:mm",LTS:"H:mm:ss",L:"D.MM.YYYY",LL:"D MMMM YYYY",LLL:"D MMMM YYYY H:mm",LLLL:"dddd, D MMMM YYYY H:mm"},calendar:{sameDay:"[Денес во] LT",nextDay:"[Утре во] LT",nextWeek:"[Во] dddd [во] LT",lastDay:"[Вчера во] LT",lastWeek:function(){switch(this.day()){case 0:case 3:case 6:return"[Изминатата] dddd [во] LT";case 1:case 2:case 4:case 5:return"[Изминатиот] dddd [во] LT"}},sameElse:"L"},relativeTime:{future:"за %s",past:"пред %s",s:"неколку секунди",ss:"%d секунди",m:"една минута",mm:"%d минути",h:"еден час",hh:"%d часа",d:"еден ден",dd:"%d дена",M:"еден месец",MM:"%d месеци",y:"една година",yy:"%d години"},dayOfMonthOrdinalParse:/\d{1,2}-(ев|ен|ти|ви|ри|ми)/,ordinal:function(e){var t=e%10,n=e%100;return 0===e?e+"-ев":0===n?e+"-ен":n>10&&n<20?e+"-ти":1===t?e+"-ви":2===t?e+"-ри":7===t||8===t?e+"-ми":e+"-ти"},week:{dow:1,doy:7}})}(n("qW9H"))},nYYG:function(e,t,n){"use strict";var a=n("Rpw/"),r=n("qW9H"),o=n.n(r),i=(n("/mDZ"),n("CtUX")),s=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Object(a.b)(t,e),t.prototype.offsetForArray=function(e){return o.a.tz(e,this.timeZoneName).utcOffset()},t.prototype.timestampToArray=function(e){return o.a.tz(e,this.timeZoneName).toArray()},t}(i.s),c=Object(i.X)({namedTimeZonedImpl:s});t.a=c},ng4s:function(e,t,n){"use strict";n.r(t),function(e){var t=n("xG4u"),a=n("kEfb"),r=n("iJY3"),o=n("jkVd"),i=n.n(o),s=n("nYYG");function c(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return d(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0,r=function(){};return{s:r,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,o=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw o}}}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n2&&void 0!==arguments[2]?arguments[2]:null;this.disableButtons();var a=this;this.initCalendarForAMethod(e.value,n,(function(){if(200===this.status){var r=JSON.parse(this.responseText);if(a.hideCalendars(),a.hideShippingSlotConfigSelects(),void 0!==r.events){var o,i=c(a.calendarContainers);try{for(i.s();!(o=i.n()).done;){var s=o.value;s.classList.contains(e.value)&&a.initCalendar(s,r.events,r.timezone,e.value,n)}}catch(e){i.e(e)}finally{i.f()}}else t?a.resetSlot(e,(function(){a.enableButtons()})):a.enableButtons()}else a.enableButtons()}))}},{key:"selectSlot",value:function(e){this.disableButtons();var t,n=this,a=c(this.shippingMethodInputs);try{for(a.s();!(t=a.n()).done;){var r=t.value;r.checked&&this.saveSlot(e,r,(function(){200===this.status?n.enableButtons():alert(n.slotSelectError)}))}}catch(e){a.e(e)}finally{a.f()}}},{key:"initCalendarForAMethod",value:function(e,t,n){var a=new XMLHttpRequest;a.onload=n;var r=this.initUrl.replace("__CODE__",e).replace("__CONFIG__",null!==t?t.value:"");a.open("get",r,!0),a.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.send()}},{key:"listSlots",value:function(e,t,n,a,r){var o=new XMLHttpRequest;o.onload=r;var i=this.listSlotsUrl.replace("__CODE__",e).replace("__FROM__",t).replace("__TO__",n).replace("__CONFIG__",null!==a?a.value:"");o.open("get",i,!0),o.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.send()}},{key:"saveSlot",value:function(e,t,n){var a=this.getShippingSlotConfigSelect(t.value),r=new XMLHttpRequest;r.onload=n,r.open("post",this.saveSlotUrl,!0),r.setRequestHeader("X-Requested-With","XMLHttpRequest");var o=new FormData;o.append("event",JSON.stringify(e.event)),o.append("shippingMethod",t.value),o.append("shipmentIndex",t.getAttribute("tabIndex")),o.append("shippingSlotConfig",null!==a?a.value:""),r.send(o)}},{key:"resetSlot",value:function(e,t){var n=new XMLHttpRequest;n.onload=t,n.open("post",this.resetSlotUrl,!0),n.setRequestHeader("X-Requested-With","XMLHttpRequest");var a=new FormData;a.append("shipmentIndex",e.getAttribute("tabIndex")),n.send(a)}},{key:"disableButtons",value:function(){var e,t=c(this.nextStepButtons);try{for(t.s();!(e=t.n()).done;){var n=e.value;n.disabled=!0,n.form.classList.add("loading")}}catch(e){t.e(e)}finally{t.f()}}},{key:"enableButtons",value:function(){var e,t=c(this.nextStepButtons);try{for(t.s();!(e=t.n()).done;){var n=e.value;n.disabled=!1,n.form.classList.remove("loading")}}catch(e){t.e(e)}finally{t.f()}}},{key:"hideCalendars",value:function(){var e,t=c(this.calendarContainers);try{for(t.s();!(e=t.n()).done;)e.value.style.display="none"}catch(e){t.e(e)}finally{t.f()}}},{key:"hideShippingSlotConfigSelects",value:function(){var e,t=c(this.shippingSlotConfigSelects);try{for(t.s();!(e=t.n()).done;)e.value.style.display="none"}catch(e){t.e(e)}finally{t.f()}}},{key:"applySlotStyle",value:function(e){null!==e.el.querySelector(".fc-event-main")?(e.el.querySelector(".fc-event-main").style.color=this.gridSlotStyle.textColor,e.el.style.borderColor=this.gridSlotStyle.borderColor,e.el.style.backgroundColor=this.gridSlotStyle.backgroundColor):null!==e.el.querySelector(".fc-list-event-time")&&(e.el.querySelector(".fc-list-event-time").style.color=this.listSlotStyle.textColor,e.el.style.borderColor=this.listSlotStyle.borderColor,e.el.style.backgroundColor=this.listSlotStyle.backgroundColor)}},{key:"applySelectedSlotStyle",value:function(e){null!==e.el.querySelector(".fc-event-main")?(e.el.querySelector(".fc-event-main").style.color=this.selectedGridSlotStyle.textColor,e.el.style.borderColor=this.selectedGridSlotStyle.borderColor,e.el.style.backgroundColor=this.selectedGridSlotStyle.backgroundColor):null!==e.el.querySelector(".fc-list-event-time")&&(e.el.querySelector(".fc-list-event-time").style.color=this.selectedListSlotStyle.textColor,e.el.style.borderColor=this.selectedListSlotStyle.borderColor,e.el.style.backgroundColor=this.selectedListSlotStyle.backgroundColor)}},{key:"hideSlot",value:function(e){e.el.style.display="none"}},{key:"initCalendar",value:function(e,n,o,d,u){e.style.display="block",u&&(u.style.display="block");var l=this;new t.a(e,Object.assign({timeZone:o,plugins:[a.a,r.a,s.a],locales:i.a,initialView:"timeGridWeek",contentHeight:"auto",allDaySlot:!1,headerToolbar:{left:"today prev,next",center:"title",right:"timeGridWeek,timeGridDay"},events:n,eventTextColor:this.gridSlotStyle.textColor,eventBackgroundColor:this.gridSlotStyle.backgroundColor,eventBorderColor:this.gridSlotStyle.borderColor,eventClick:function(e){l.applySelectedSlotStyle(e),null!==l.previousSlot&&null!==l.previousSlot.event&&l.previousSlot.event.start.valueOf()!==e.event.start.valueOf()&&l.applySlotStyle(l.previousSlot),l.previousSlot=e,l.selectSlot(e)},eventDidMount:function(e){null!==e.event&&!0===e.event.extendedProps.isCurrent?(l.applySelectedSlotStyle(e),l.previousSlot=e,l.enableButtons()):l.applySlotStyle(e)},datesSet:function(e){var t=this;l.disableButtons(),l.listSlots(d,e.startStr,e.endStr,u,(function(){if(200===this.status){var e,n=c(l.nextStepButtons);try{for(n.s();!(e=n.n()).done;)e.value.form.classList.remove("loading")}catch(e){n.e(e)}finally{n.f()}var a=JSON.parse(this.responseText);t.batchRendering((function(){var e,n=c(t.getEvents());try{for(n.s();!(e=n.n()).done;)e.value.remove()}catch(e){n.e(e)}finally{n.f()}var r,o=c(a);try{for(o.s();!(r=o.n()).done;){var i=r.value;t.addEvent(i)}}catch(e){o.e(e)}finally{o.f()}}))}else console.error("Error during slot list")}))}},this.fullCalendarConfig)).render()}},{key:"getShippingSlotConfigSelect",value:function(e){var t;return null!==(t=Array.from(this.shippingSlotConfigSelects).find((function(t){return t.name.includes(e)})))&&void 0!==t?t:null}}])&&u(n.prototype,o),d&&u(n,d),e}()}.call(this,n("2mad"))},nkld:function(e,t,n){!function(e){"use strict"; +e.defineLocale("mk",{months:"јануари_февруари_март_април_мај_јуни_јули_август_септември_октомври_ноември_декември".split("_"),monthsShort:"јан_фев_мар_апр_мај_јун_јул_авг_сеп_окт_ное_дек".split("_"),weekdays:"недела_понеделник_вторник_среда_четврток_петок_сабота".split("_"),weekdaysShort:"нед_пон_вто_сре_чет_пет_саб".split("_"),weekdaysMin:"нe_пo_вт_ср_че_пе_сa".split("_"),longDateFormat:{LT:"H:mm",LTS:"H:mm:ss",L:"D.MM.YYYY",LL:"D MMMM YYYY",LLL:"D MMMM YYYY H:mm",LLLL:"dddd, D MMMM YYYY H:mm"},calendar:{sameDay:"[Денес во] LT",nextDay:"[Утре во] LT",nextWeek:"[Во] dddd [во] LT",lastDay:"[Вчера во] LT",lastWeek:function(){switch(this.day()){case 0:case 3:case 6:return"[Изминатата] dddd [во] LT";case 1:case 2:case 4:case 5:return"[Изминатиот] dddd [во] LT"}},sameElse:"L"},relativeTime:{future:"за %s",past:"пред %s",s:"неколку секунди",ss:"%d секунди",m:"една минута",mm:"%d минути",h:"еден час",hh:"%d часа",d:"еден ден",dd:"%d дена",M:"еден месец",MM:"%d месеци",y:"една година",yy:"%d години"},dayOfMonthOrdinalParse:/\d{1,2}-(ев|ен|ти|ви|ри|ми)/,ordinal:function(e){var t=e%10,n=e%100;return 0===e?e+"-ев":0===n?e+"-ен":n>10&&n<20?e+"-ти":1===t?e+"-ви":2===t?e+"-ри":7===t||8===t?e+"-ми":e+"-ти"},week:{dow:1,doy:7}})}(n("qW9H"))},nYYG:function(e,t,n){"use strict";var a=n("Rpw/"),r=n("qW9H"),o=n.n(r),i=(n("/mDZ"),n("CtUX")),s=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Object(a.b)(t,e),t.prototype.offsetForArray=function(e){return o.a.tz(e,this.timeZoneName).utcOffset()},t.prototype.timestampToArray=function(e){return o.a.tz(e,this.timeZoneName).toArray()},t}(i.s),c=Object(i.X)({namedTimeZonedImpl:s});t.a=c},ng4s:function(e,t,n){"use strict";n.r(t),function(e){var t=n("xG4u"),a=n("kEfb"),r=n("iJY3"),o=n("jkVd"),i=n.n(o),s=n("nYYG");function c(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return d(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0,r=function(){};return{s:r,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,o=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw o}}}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n2&&void 0!==arguments[2]?arguments[2]:null;this.disableButtons();var a=this;this.initCalendarForAMethod(e.value,n,(function(){if(200===this.status){var r=JSON.parse(this.responseText);if(a.hideCalendars(),a.hideShippingSlotConfigContainers(),void 0!==r.events){var o,i=c(a.calendarContainers);try{for(i.s();!(o=i.n()).done;){var s=o.value;s.classList.contains(e.value)&&a.initCalendar(s,r.events,r.timezone,e.value,n)}}catch(e){i.e(e)}finally{i.f()}}else t?a.resetSlot(e,(function(){a.enableButtons()})):a.enableButtons()}else a.enableButtons()}))}},{key:"selectSlot",value:function(e){this.disableButtons();var t,n=this,a=c(this.shippingMethodInputs);try{for(a.s();!(t=a.n()).done;){var r=t.value;r.checked&&this.saveSlot(e,r,(function(){200===this.status?n.enableButtons():alert(n.slotSelectError)}))}}catch(e){a.e(e)}finally{a.f()}}},{key:"initCalendarForAMethod",value:function(e,t,n){var a=new XMLHttpRequest;a.onload=n;var r=this.initUrl.replace("__CODE__",e).replace("__CONFIG__",null!==t?t.value:"");a.open("get",r,!0),a.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.send()}},{key:"listSlots",value:function(e,t,n,a,r){var o=new XMLHttpRequest;o.onload=r;var i=this.listSlotsUrl.replace("__CODE__",e).replace("__FROM__",t).replace("__TO__",n).replace("__CONFIG__",null!==a?a.value:"");o.open("get",i,!0),o.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.send()}},{key:"saveSlot",value:function(e,t,n){var a=this.getShippingSlotConfigSelect(t.value),r=new XMLHttpRequest;r.onload=n,r.open("post",this.saveSlotUrl,!0),r.setRequestHeader("X-Requested-With","XMLHttpRequest");var o=new FormData;o.append("event",JSON.stringify(e.event)),o.append("shippingMethod",t.value),o.append("shipmentIndex",t.getAttribute("tabIndex")),o.append("shippingSlotConfig",null!==a?a.value:""),r.send(o)}},{key:"resetSlot",value:function(e,t){var n=new XMLHttpRequest;n.onload=t,n.open("post",this.resetSlotUrl,!0),n.setRequestHeader("X-Requested-With","XMLHttpRequest");var a=new FormData;a.append("shipmentIndex",e.getAttribute("tabIndex")),n.send(a)}},{key:"disableButtons",value:function(){var e,t=c(this.nextStepButtons);try{for(t.s();!(e=t.n()).done;){var n=e.value;n.disabled=!0,n.form.classList.add("loading")}}catch(e){t.e(e)}finally{t.f()}}},{key:"enableButtons",value:function(){var e,t=c(this.nextStepButtons);try{for(t.s();!(e=t.n()).done;){var n=e.value;n.disabled=!1,n.form.classList.remove("loading")}}catch(e){t.e(e)}finally{t.f()}}},{key:"hideCalendars",value:function(){var e,t=c(this.calendarContainers);try{for(t.s();!(e=t.n()).done;)e.value.style.display="none"}catch(e){t.e(e)}finally{t.f()}}},{key:"hideShippingSlotConfigContainers",value:function(){var e,t=c(this.shippingSlotConfigContainers);try{for(t.s();!(e=t.n()).done;)e.value.style.display="none"}catch(e){t.e(e)}finally{t.f()}}},{key:"applySlotStyle",value:function(e){null!==e.el.querySelector(".fc-event-main")?(e.el.querySelector(".fc-event-main").style.color=this.gridSlotStyle.textColor,e.el.style.borderColor=this.gridSlotStyle.borderColor,e.el.style.backgroundColor=this.gridSlotStyle.backgroundColor):null!==e.el.querySelector(".fc-list-event-time")&&(e.el.querySelector(".fc-list-event-time").style.color=this.listSlotStyle.textColor,e.el.style.borderColor=this.listSlotStyle.borderColor,e.el.style.backgroundColor=this.listSlotStyle.backgroundColor)}},{key:"applySelectedSlotStyle",value:function(e){null!==e.el.querySelector(".fc-event-main")?(e.el.querySelector(".fc-event-main").style.color=this.selectedGridSlotStyle.textColor,e.el.style.borderColor=this.selectedGridSlotStyle.borderColor,e.el.style.backgroundColor=this.selectedGridSlotStyle.backgroundColor):null!==e.el.querySelector(".fc-list-event-time")&&(e.el.querySelector(".fc-list-event-time").style.color=this.selectedListSlotStyle.textColor,e.el.style.borderColor=this.selectedListSlotStyle.borderColor,e.el.style.backgroundColor=this.selectedListSlotStyle.backgroundColor)}},{key:"hideSlot",value:function(e){e.el.style.display="none"}},{key:"initCalendar",value:function(e,n,o,d,u){if(e.style.display="block",u){var l=Array.from(this.shippingSlotConfigContainers).find((function(e){return e.classList.contains(d)}));l&&(l.style.display="block")}var M=this;new t.a(e,Object.assign({timeZone:o,plugins:[a.a,r.a,s.a],locales:i.a,initialView:"timeGridWeek",contentHeight:"auto",allDaySlot:!1,headerToolbar:{left:"today prev,next",center:"title",right:"timeGridWeek,timeGridDay"},events:n,eventTextColor:this.gridSlotStyle.textColor,eventBackgroundColor:this.gridSlotStyle.backgroundColor,eventBorderColor:this.gridSlotStyle.borderColor,eventClick:function(e){M.applySelectedSlotStyle(e),null!==M.previousSlot&&null!==M.previousSlot.event&&M.previousSlot.event.start.valueOf()!==e.event.start.valueOf()&&M.applySlotStyle(M.previousSlot),M.previousSlot=e,M.selectSlot(e)},eventDidMount:function(e){null!==e.event&&!0===e.event.extendedProps.isCurrent?(M.applySelectedSlotStyle(e),M.previousSlot=e,M.enableButtons()):M.applySlotStyle(e)},datesSet:function(e){var t=this;M.disableButtons(),M.listSlots(d,e.startStr,e.endStr,u,(function(){if(200===this.status){var e,n=c(M.nextStepButtons);try{for(n.s();!(e=n.n()).done;)e.value.form.classList.remove("loading")}catch(e){n.e(e)}finally{n.f()}var a=JSON.parse(this.responseText);t.batchRendering((function(){var e,n=c(t.getEvents());try{for(n.s();!(e=n.n()).done;)e.value.remove()}catch(e){n.e(e)}finally{n.f()}var r,o=c(a);try{for(o.s();!(r=o.n()).done;){var i=r.value;t.addEvent(i)}}catch(e){o.e(e)}finally{o.f()}}))}else console.error("Error during slot list")}))}},this.fullCalendarConfig)).render()}},{key:"getShippingSlotConfigSelect",value:function(e){var t,n=c(this.shippingSlotConfigContainers);try{for(n.s();!(t=n.n()).done;){var a=t.value.querySelector(this.shippingSlotConfigSelectSelector);if(null!==a&&a.name.includes(e))return a}}catch(e){n.e(e)}finally{n.f()}return null}}])&&u(n.prototype,o),d&&u(n,d),e}()}.call(this,n("2mad"))},nkld:function(e,t,n){!function(e){"use strict"; //! moment.js locale configuration e.defineLocale("ms-my",{months:"Januari_Februari_Mac_April_Mei_Jun_Julai_Ogos_September_Oktober_November_Disember".split("_"),monthsShort:"Jan_Feb_Mac_Apr_Mei_Jun_Jul_Ogs_Sep_Okt_Nov_Dis".split("_"),weekdays:"Ahad_Isnin_Selasa_Rabu_Khamis_Jumaat_Sabtu".split("_"),weekdaysShort:"Ahd_Isn_Sel_Rab_Kha_Jum_Sab".split("_"),weekdaysMin:"Ah_Is_Sl_Rb_Km_Jm_Sb".split("_"),longDateFormat:{LT:"HH.mm",LTS:"HH.mm.ss",L:"DD/MM/YYYY",LL:"D MMMM YYYY",LLL:"D MMMM YYYY [pukul] HH.mm",LLLL:"dddd, D MMMM YYYY [pukul] HH.mm"},meridiemParse:/pagi|tengahari|petang|malam/,meridiemHour:function(e,t){return 12===e&&(e=0),"pagi"===t?e:"tengahari"===t?e>=11?e:e+12:"petang"===t||"malam"===t?e+12:void 0},meridiem:function(e,t,n){return e<11?"pagi":e<15?"tengahari":e<19?"petang":"malam"},calendar:{sameDay:"[Hari ini pukul] LT",nextDay:"[Esok pukul] LT",nextWeek:"dddd [pukul] LT",lastDay:"[Kelmarin pukul] LT",lastWeek:"dddd [lepas pukul] LT",sameElse:"L"},relativeTime:{future:"dalam %s",past:"%s yang lepas",s:"beberapa saat",ss:"%d saat",m:"seminit",mm:"%d minit",h:"sejam",hh:"%d jam",d:"sehari",dd:"%d hari",M:"sebulan",MM:"%d bulan",y:"setahun",yy:"%d tahun"},week:{dow:1,doy:7}})}(n("qW9H"))},nmio:function(e,t,n){!function(e){"use strict"; //! moment.js locale configuration diff --git a/src/Resources/views/Shop/ShippingMethod/ShippingSlot/_slotConfig.html.twig b/src/Resources/views/Shop/ShippingMethod/ShippingSlot/_slotConfig.html.twig index e930cf6..c255451 100644 --- a/src/Resources/views/Shop/ShippingMethod/ShippingSlot/_slotConfig.html.twig +++ b/src/Resources/views/Shop/ShippingMethod/ShippingSlot/_slotConfig.html.twig @@ -1 +1,3 @@ -{{ form_row(form_shipping_slot_configurations, {'attr': {'class': 'slot-configs-' ~ method.code, 'style': 'display: none'}}) }} + diff --git a/src/Resources/views/Shop/app.html.twig b/src/Resources/views/Shop/app.html.twig index 756cf08..cf57aea 100644 --- a/src/Resources/views/Shop/app.html.twig +++ b/src/Resources/views/Shop/app.html.twig @@ -5,7 +5,8 @@ let shippingMethodInputs = document.querySelectorAll('input[type="radio"][name*="sylius_checkout_select_shipping"]'); let nextStepButtons = document.querySelectorAll('form[name="sylius_checkout_select_shipping"] button#next-step'); let calendarContainers = document.querySelectorAll('.monsieurbiz_shipping_slot_calendar'); - let shippingSlotConfigSelects = document.querySelectorAll('select[name^="sylius_checkout_select_shipping[shipments]"][name*="[shippingSlotConfigs]"]'); + let shippingSlotConfigContainers = document.querySelectorAll('.monsieurbiz_shipping_slot_config'); + let shippingSlotConfigSelectSelector = 'select[name*="[shippingSlotConfigs]"]'; let gridSlotStyle = { textColor: '#ffffff', borderColor: '#3788d8', @@ -49,7 +50,8 @@ '{{ url("monsieurbiz_shippingslot_checkout_saveslot")|e('js') }}', '{{ url("monsieurbiz_shippingslot_checkout_resetslot")|e('js') }}', '{{ 'monsieurbiz_shipping_slot.ui.slot_select_error' | trans | escape('js') }}', - shippingSlotConfigSelects + shippingSlotConfigContainers, + shippingSlotConfigSelectSelector ); });