1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/public/build/assets/view-2c82be5f.js
2023-09-26 08:24:51 +10:00

10 lines
1.7 KiB
JavaScript
Vendored

/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/class a{constructor(){this.url=new URL(document.querySelector("meta[name=pdf-url]").content),this.startDate="",this.endDate="",this.showPaymentsTable=!1,this.showAgingTable=!1,this.status=""}bindEventListeners(){["#date-from","#date-to","#show-payments-table","#show-aging-table","#status"].forEach(e=>{document.querySelector(e).addEventListener("change",t=>this.handleValueChange(t))})}handleValueChange(e){e.target.type==="checkbox"?this[e.target.dataset.field]=e.target.checked:this[e.target.dataset.field]=e.target.value,this.updatePdf()}get composedUrl(){return this.url.search="",this.startDate.length>0&&this.url.searchParams.append("start_date",this.startDate),this.endDate.length>0&&this.url.searchParams.append("end_date",this.endDate),this.url.searchParams.append("status",document.getElementById("status").value),this.url.searchParams.append("show_payments_table",+this.showPaymentsTable),this.url.searchParams.append("show_aging_table",+this.showAgingTable),this.url.href}updatePdf(){document.querySelector("meta[name=pdf-url]").content=this.composedUrl;let e=document.querySelector("#pdf-iframe");e&&(e.src=this.composedUrl),document.querySelector("meta[name=pdf-url]").dispatchEvent(new Event("change"))}handle(){this.bindEventListeners(),document.querySelector("#pdf-download").addEventListener("click",()=>{let e=new URL(this.composedUrl);e.searchParams.append("download",1),window.location.href=e.href})}}new a().handle();