rumine-web/static/wagtailadmin/js/bulk-actions.js

1 line
5.5 KiB
JavaScript
Raw Normal View History

2024-03-13 07:49:06 +01:00
(()=>{"use strict";var e,t={3684:(e,t,c)=>{var n=c(3947);const o="[data-bulk-action-checkbox]",r="[data-bulk-action-select-all-checkbox]",d="[data-bulk-action-footer]",a="[data-bulk-action-num-objects]",l="[data-bulk-action-num-objects-in-listing]";let i={};function s(e){return wagtailConfig.STRINGS.BULK_ACTIONS[wagtailConfig.BULK_ACTION_ITEM_TYPE]?wagtailConfig.STRINGS.BULK_ACTIONS[wagtailConfig.BULK_ACTION_ITEM_TYPE][e]:wagtailConfig.STRINGS.BULK_ACTIONS.ITEM[e]}function u(e){document.querySelectorAll(r).forEach((t=>{t.checked=e.target.checked}));const t=new Event("change");document.querySelectorAll(o).forEach((c=>{c.checked!==e.target.checked&&(c.checked=e.target.checked,e.target.checked?c.dispatchEvent(t):c.classList.remove("show"))})),e.target.checked||(i.checkedObjects.clear(),document.querySelector(d).classList.add("hidden"))}function h(e){if(e.shiftKey&&i.prevCheckedObject){const t=[...document.querySelectorAll(o)],c=t.findIndex((e=>e.dataset.objectId===i.prevCheckedObject)),r=t.findIndex((t=>t.dataset.objectId===e.target.dataset.objectId)),d=(c>r?r:c)+1,a=c<=r?r:c;(0,n.w)(d,a).forEach((e=>{const n=new Event("change");t[e].checked=t[c].checked,t[e].dispatchEvent(n)})),i.prevCheckedObject=e.target.dataset.objectId}}function f(e){i.selectAllInListing&&(i.selectAllInListing=!1);const t=i.checkedObjects.size;e.target.checked?i.checkedObjects.add(e.target.dataset.objectId):(document.querySelectorAll(r).forEach((e=>{e.checked=!1})),i.checkedObjects.delete(e.target.dataset.objectId));const c=i.checkedObjects.size;if(0===c?(document.querySelector(d).classList.add("hidden"),document.querySelectorAll(o).forEach((e=>e.classList.remove("show")))):1===c&&0===t&&(document.querySelectorAll(o).forEach((e=>{e.classList.add("show")})),document.querySelector(d).classList.remove("hidden")),c===i.numObjects?(document.querySelectorAll(r).forEach((e=>{e.checked=!0})),i.shouldShowAllInListingText&&document.querySelector(l).classList.remove("w-hidden")):i.shouldShowAllInListingText&&document.querySelector(l).classList.add("w-hidden"),c>0){let e="";e=1===c?s("SINGULAR"):c===i.numObjects?s("ALL").replace("%(objects)s",c):s("PLURAL").replace("%(objects)s",c),document.querySelector(a).textContent=e}i.prevCheckedObject=e.target.dataset.objectId}function b(e){e.preventDefault(),i.selectAllInListing=!0,document.querySelector(a).textContent=`${s("ALL_IN_LISTING")}.`,document.querySelector(l).classList.add("w-hidden")}function g(e){e.preventDefault();const t=e.target.getAttribute("href"),c=new URLSearchParams(window.location.search);if(i.selectAllInListing){c.append("id","all");const e=document.querySelector("[data-bulk-action-parent-id]");if(e){const t=e.dataset.bulkActionParentId;c.append("childOf",t)}}else i.checkedObjects.forEach((e=>{c.append("id",e)}));window.location.href=`${t}&${c.toString()}`}document.addEventListener("DOMContentLoaded",(function(){i={checkedObjects:new Set,numObjects:0,selectAllInListing:!1,shouldShowAllInListingText:!0,prevCheckedObject:null};const e=new Event("change");document.querySelectorAll(o).forEach((e=>{i.numObjects+=1,e.addEventListener("change",f),e.addEventListener("click",h)})),document.querySelectorAll(r).forEach((e=>{e.addEventListener("change",u)})),document.querySelectorAll(`${d} [data-bulk-action-button]`).forEach((e=>e.addEventListener("click",g))),document.addEventListener("w-dropdown:shown",(()=>{document.querySelectorAll(`${d} [data-bulk-action-button]`).forEach((e=>{e.removeEventListener("click",g),e.addEventListener("click",g)}))}));const t=document.querySelector(l);t?t.addEventListener("click",b):i.shouldShowAllInListingText=!1,document.querySelectorAll(o).forEach((t=>{t.checked&&t.dispatchEvent(e)}))})),document.addEventListener("w-swap:success",(function(){document.querySelectorAll(r).forEach((e=>{e.checked=!1})),document.querySelector(d).classList.add("hidden"),document.querySelectorAll(r).forEach((e=>{e.removeEventListener("change",u),e.addEventListener("change",u)})),i.checkedObjects.clear(),i.numObjects=0,document.querySelectorAll(o).forEach((e=>{i.numObjects+=1,e.addEventListener("change