Files
1sonhador 8542395fbe Add public campaign analytics functionality
- Add PublicCampaignsController for public campaign analytics
- Add public routes for /public/analytics/{slug} and /api/campaigns/{slug}
- Add public campaign analytics view with charts and KPIs
- Support for campaign sharing via custom slugs
- Real-time analytics with ApexCharts integration
2025-10-15 00:30:00 +01:00

1 line
4.7 KiB
JavaScript

export default()=>({init(){console.log("formInputSpin component initialized"),this.setupSpinInputs()},setupSpinInputs(){document.querySelectorAll(".plus").forEach((t,e)=>{t.addEventListener("click",t=>{this.incrementValue(t.target)})}),document.querySelectorAll(".minus").forEach((t,e)=>{t.addEventListener("click",t=>{this.decrementValue(t.target)})}),document.querySelectorAll("[data-spin]").forEach((t,e)=>{this.setupCustomSpinInput(t,e)}),document.querySelectorAll(".product").forEach((t,e)=>{this.setupProductInput(t,e)})},setupCustomSpinInput(t,e){const n=this.parseSpinConfig(t),s=`custom_${e}`;this.spinInputs[s]={element:t,config:n,value:parseInt(t.value)||n.default||0},this.currentValues[s]=this.spinInputs[s].value,t.nextElementSibling&&t.nextElementSibling.classList.contains("spin-buttons")||this.createSpinButtons(t,s)},setupProductInput(t,e){const n=`product_${e}`;this.spinInputs[n]={element:t,config:{min:parseInt(t.getAttribute("min"))||0,max:parseInt(t.getAttribute("max"))||999,step:parseInt(t.getAttribute("step"))||1,default:parseInt(t.value)||0},value:parseInt(t.value)||0},this.currentValues[n]=this.spinInputs[n].value,t.addEventListener("input",t=>{this.updateProductQuantity(t.target)})},parseSpinConfig:t=>({min:parseInt(t.getAttribute("data-min"))||0,max:parseInt(t.getAttribute("data-max"))||999,step:parseInt(t.getAttribute("data-step"))||1,default:parseInt(t.getAttribute("data-default"))||0,decimals:parseInt(t.getAttribute("data-decimals"))||0}),createSpinButtons(t,e){const n=document.createElement("div");n.className="spin-buttons d-flex flex-column",n.style.cssText="position: absolute; right: 0; top: 0; height: 100%; z-index: 10;";const s=document.createElement("button");s.type="button",s.className="btn btn-sm btn-outline-secondary plus-spin",s.innerHTML='<i class="bx bx-plus"></i>',s.style.cssText="border-radius: 0; border-left: 0; border-bottom: 0; flex: 1;";const a=document.createElement("button");a.type="button",a.className="btn btn-sm btn-outline-secondary minus-spin",a.innerHTML='<i class="bx bx-minus"></i>',a.style.cssText="border-radius: 0; border-left: 0; flex: 1;",n.appendChild(s),n.appendChild(a);const i=t.parentElement;i&&(i.style.position="relative",i.appendChild(n)),s.addEventListener("click",()=>{this.incrementCustomValue(e)}),a.addEventListener("click",()=>{this.decrementCustomValue(e)})},incrementValue(t){const e=t.previousElementSibling;if(e){const n=parseInt(e.value)||0;n<(parseInt(e.getAttribute("max"))||999)&&(e.value=n+1,this.updateQuantity(t))}},decrementValue(t){const e=t.nextElementSibling;if(e){const n=parseInt(e.value)||0;n>(parseInt(e.getAttribute("min"))||0)&&(e.value=n-1,this.updateQuantity(t))}},incrementCustomValue(t){const e=this.spinInputs[t];if(e){const n=e.value+e.config.step;n<=e.config.max&&(e.value=n,e.element.value=this.formatValue(n,e.config.decimals),this.currentValues[t]=n,this.triggerChangeEvent(e.element))}},decrementCustomValue(t){const e=this.spinInputs[t];if(e){const n=e.value-e.config.step;n>=e.config.min&&(e.value=n,e.element.value=this.formatValue(n,e.config.decimals),this.currentValues[t]=n,this.triggerChangeEvent(e.element))}},formatValue:(t,e)=>e>0?t.toFixed(e):t.toString(),updateQuantity(t){document.querySelectorAll(".product").forEach(t=>{this.updateProductQuantity(t)})},updateProductQuantity(t){const e=parseInt(t.value)||0,n=parseInt(t.getAttribute("min"))||0,s=parseInt(t.getAttribute("max"))||999;e<n?t.value=n:e>s&&(t.value=s),this.updateProductCalculations(t)},updateProductCalculations(t){const e=t.closest(".product-row, tr, .item-row");if(e){const n=parseInt(t.value)||0,s=e.querySelector(".product-price, .price"),a=e.querySelector(".product-total, .total");if(s&&a){const t=n*(parseFloat(s.getAttribute("data-price")||s.textContent.replace(/[^\d.-]/g,""))||0);a.textContent=this.formatCurrency(t),a.setAttribute("data-total",t)}}this.updateCartTotal()},updateCartTotal(){const t=document.querySelectorAll("[data-total]");let e=0;t.forEach(t=>{const n=parseFloat(t.getAttribute("data-total"))||0;e+=n});const n=document.querySelector(".cart-total, .total-amount");n&&(n.textContent=this.formatCurrency(e))},formatCurrency:t=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t),triggerChangeEvent(t){const e=new Event("change",{bubbles:!0});t.dispatchEvent(e)},setValue(t,e){const n=this.spinInputs[t];if(n){const s=n.config,a=Math.max(s.min,Math.min(s.max,e));n.value=a,n.element.value=this.formatValue(a,s.decimals),this.currentValues[t]=a,this.triggerChangeEvent(n.element)}},getValue(t){return this.currentValues[t]||0},resetToDefault(t){const e=this.spinInputs[t];e&&this.setValue(t,e.config.default)},setSpinEnabled(t,e){const n=this.spinInputs[t];n&&(n.element.disabled=!e,n.element.parentElement.querySelectorAll(".plus-spin, .minus-spin").forEach(t=>{t.disabled=!e}))}});