Skip to content

Commit

Permalink
feat(district): Adds logic to upload file from multi-doc page
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Oct 1, 2024
1 parent 4975203 commit 5237e7e
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/content_delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,98 @@ ContentDelegate.prototype.handleCombinedPDFView = async function () {
return;
}

// Extract the URL from the `onclick` attribute of one of the "Download
// Documents" buttons
const inputs = [...document.getElementsByTagName('input')];
const targetInputs = inputs.filter((input) => input.type === 'button');
const url = targetInputs[0]
.getAttribute('onclick')
.replace(/p.*\//, '') // remove parent.location='/cgi-bin/
.replace(/\'(?=$)/, ''); // remove endquote

// Manipulate the dom elements without injecting a script
if (PACER.hasFilingCookie(document.cookie)) {
const inputs = [
...document.querySelectorAll("form > input[type='button']"),
];
inputs.map((input) => {
let button = createRecapButtonForFilers('Download and RECAP Document');
let spinner = createRecapSpinner();
button.addEventListener('click', (event) => {
event.preventDefault();

let spinners = document.querySelectorAll('.recap-btn-spinner-hidden');
for (const spinner of spinners) {
// Access and process each process result element here
spinner.classList.remove('recap-btn-spinner-hidden');
}

window.postMessage({ id: url });
});
// insert new button next to the "Download Documents" button
input.after(spinner);
input.after(document.createTextNode('\u00A0'));
input.after(button);
});
} else {
const forms = [...document.querySelectorAll('form')];
forms.map((form) => {
form.removeAttribute('action');
const input = form.querySelector('input');
input.removeAttribute('onclick');
input.disabled = true;
form.hidden = true;
const div = document.createElement('div');
const button = document.createElement('button');
button.textContent = 'View Document';
button.addEventListener('click', () => window.postMessage({ id: url }));
div.appendChild(button);
const parentNode = form.parentNode;
parentNode.insertBefore(div, form);
});
}
// When we receive the message from the above submit method, submit the form
// via fetch so we can get the document before the browser does.
window.addEventListener('message', this.onDownloadSubmit.bind(this));

await this.checkSingleDocInCombinedPDFPage();
};


ContentDelegate.prototype.onDownloadSubmit = async function () {
// Make the Back button redisplay the previous page.
window.onpopstate = function (event) {
if (event.state.content) {
document.documentElement.innerHTML = event.state.content;
}
};
history.replaceState({ content: document.documentElement.innerHTML }, '');
// tell the user to wait
$('body').css('cursor', 'wait');

let previousPageHtml = copyPDFDocumentPage();
let pdfData = PACER.parseDataFromReceipt();

const browserSpecificFetch =
navigator.userAgent.indexOf('Safari') +
navigator.userAgent.indexOf('Chrome') <
0
? fetch
: window.fetch;

const documentRequest = await browserSpecificFetch(event.data.id);
let documentBlob = await documentRequest.blob();

let requestHandler = handleDocFormResponse.bind(this);
requestHandler(
documentRequest.headers.get('Content-Type'),
documentBlob,
null,
previousPageHtml,
pdfData
);
};

// checks if a specific document within a combined PDF page is available in
// the Recap archive. The document is identified by its PACER document ID.
// If the document is found, it inserts a banner to inform the user of its
Expand Down

0 comments on commit 5237e7e

Please sign in to comment.