mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Extract script into separate file
This commit is contained in:
parent
76804fc37b
commit
d7944b1fa4
86
resources/js/clients/statements/view.js
vendored
Normal file
86
resources/js/clients/statements/view.js
vendored
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/**
|
||||||
|
* 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 Statement {
|
||||||
|
constructor() {
|
||||||
|
this.url = new URL(
|
||||||
|
document.querySelector('meta[name=pdf-url]').content
|
||||||
|
);
|
||||||
|
this.startDate = '';
|
||||||
|
this.endDate = '';
|
||||||
|
this.showPaymentsTable = false;
|
||||||
|
this.showAgingTable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bindEventListeners() {
|
||||||
|
[
|
||||||
|
'#date-from',
|
||||||
|
'#date-to',
|
||||||
|
'#show-payments-table',
|
||||||
|
'#show-aging-table',
|
||||||
|
].forEach((selector) => {
|
||||||
|
document
|
||||||
|
.querySelector(selector)
|
||||||
|
.addEventListener('change', (event) =>
|
||||||
|
this.handleValueChange(event)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleValueChange(event) {
|
||||||
|
if (event.target.type === 'checkbox') {
|
||||||
|
this[event.target.dataset.field] = event.target.checked;
|
||||||
|
} else {
|
||||||
|
this[event.target.dataset.field] = event.target.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updatePdf();
|
||||||
|
}
|
||||||
|
|
||||||
|
get composedUrl() {
|
||||||
|
this.url.search = '';
|
||||||
|
|
||||||
|
if (this.startDate.length > 0) {
|
||||||
|
this.url.searchParams.append('start_date', this.startDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.endDate.length > 0) {
|
||||||
|
this.url.searchParams.append('end_date', this.endDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.url.searchParams.append(
|
||||||
|
'show_payments_table',
|
||||||
|
+this.showPaymentsTable
|
||||||
|
);
|
||||||
|
this.url.searchParams.append('show_aging_table', +this.showAgingTable);
|
||||||
|
|
||||||
|
return this.url.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePdf() {
|
||||||
|
document.querySelector('meta[name=pdf-url]').content = this.composedUrl;
|
||||||
|
|
||||||
|
let iframe = document.querySelector('#pdf-iframe');
|
||||||
|
|
||||||
|
if (iframe) {
|
||||||
|
iframe.src = this.composedUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
document
|
||||||
|
.querySelector('meta[name=pdf-url]')
|
||||||
|
.dispatchEvent(new Event('change'));
|
||||||
|
}
|
||||||
|
|
||||||
|
handle() {
|
||||||
|
this.bindEventListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new Statement().handle();
|
@ -38,71 +38,5 @@
|
|||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('footer')
|
@push('footer')
|
||||||
<script>
|
<script src="{{ asset('js/clients/statements/view.js') }}"></script>
|
||||||
class Statement {
|
|
||||||
constructor() {
|
|
||||||
this.url = new URL(document.querySelector('meta[name=pdf-url]').content);
|
|
||||||
this.startDate = '';
|
|
||||||
this.endDate = '';
|
|
||||||
this.showPaymentsTable = false;
|
|
||||||
this.showAgingTable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bindEventListeners() {
|
|
||||||
['#date-from', '#date-to', '#show-payments-table', '#show-aging-table'].forEach(selector => {
|
|
||||||
document
|
|
||||||
.querySelector(selector)
|
|
||||||
.addEventListener('change', (event) => this.handleValueChange(event));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
handleValueChange(event) {
|
|
||||||
if (event.target.type === 'checkbox') {
|
|
||||||
console.log(1);
|
|
||||||
this[event.target.dataset.field] = event.target.checked;
|
|
||||||
} else {
|
|
||||||
this[event.target.dataset.field] = event.target.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updatePdf();
|
|
||||||
}
|
|
||||||
|
|
||||||
get composedUrl() {
|
|
||||||
this.url.search = '';
|
|
||||||
|
|
||||||
if (this.startDate.length > 0) {
|
|
||||||
this.url.searchParams.append('start_date', this.startDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.endDate.length > 0) {
|
|
||||||
this.url.searchParams.append('end_date', this.endDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.url.searchParams.append('show_payments_table', +this.showPaymentsTable);
|
|
||||||
this.url.searchParams.append('show_aging_table', +this.showAgingTable);
|
|
||||||
|
|
||||||
return this.url.href;
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePdf() {
|
|
||||||
document
|
|
||||||
.querySelector('meta[name=pdf-url]')
|
|
||||||
.content = this.composedUrl;
|
|
||||||
|
|
||||||
let iframe = document.querySelector('#pdf-iframe');
|
|
||||||
|
|
||||||
if (iframe) {
|
|
||||||
iframe.src = this.composedUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelector('meta[name=pdf-url]').dispatchEvent(new Event('change'));
|
|
||||||
}
|
|
||||||
|
|
||||||
handle() {
|
|
||||||
this.bindEventListeners();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new Statement().handle();
|
|
||||||
</script>
|
|
||||||
@endpush
|
@endpush
|
Loading…
x
Reference in New Issue
Block a user