This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5909 from willy-b/payment-history-receipt-pdf-reb…
…ase-11-28 Replace Payment History CSV export with Contribution Statement PDF (rebased)
- Loading branch information
Showing
20 changed files
with
1,013 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="availableLanguages" content=""> | ||
<meta name="defaultLanguage" content="en-US"> | ||
<meta name='theme-color' content='#ff5000'> | ||
<link rel="shortcut icon"type="image/x-icon" href="data:image/x-icon;,"> | ||
<title data-l10n-id="contributionStatement"></title> | ||
<script src='js/about.js'></script> | ||
<script src="ext/l20n.min.js" async></script> | ||
<link rel="localization" href="locales/{locale}/preferences.properties"> | ||
<link rel="localization" href="locales/{locale}/common.properties"> | ||
<link rel="localization" href="locales/{locale}/bravery.properties"> | ||
<link rel="localization" href="locales/{locale}/error.properties"> | ||
<link rel="localization" href="locales/{locale}/errorMessages.properties"> | ||
</head> | ||
<body> | ||
<div id="appContainer"/> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'use strict' | ||
|
||
const electron = require('electron') | ||
const BrowserWindow = electron.BrowserWindow | ||
|
||
const renderUrlToPdf = (appState, action, testingMode) => { | ||
let url = action.url | ||
let savePath = action.savePath | ||
let openAfterwards = action.openAfterwards | ||
|
||
let currentBw = BrowserWindow.getFocusedWindow() | ||
|
||
let bw = new BrowserWindow({show: !!testingMode, backgroundColor: '#ffffff'}) | ||
|
||
let wv = bw.webContents | ||
|
||
let whenReadyToGeneratePDF = () => { | ||
wv.printToPDF({}, function (err, data) { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
let pdfDataURI = 'data:application/pdf;base64,' + data.toString('base64') | ||
|
||
// need to put our event handler first so we can set filename | ||
// specifically, needs to execute ahead of app/filtering.js:registerForDownloadListener (which opens the dialog box) | ||
let listeners = wv.session.listeners('will-download') | ||
wv.session.removeAllListeners('will-download') | ||
|
||
wv.downloadURL(pdfDataURI) | ||
wv.session.once('will-download', function (event, item) { | ||
if (savePath) { | ||
item.setSavePath(savePath) | ||
} | ||
|
||
item.once('done', function (event, state) { | ||
if (state === 'completed') { | ||
let finalSavePath = item && item.getSavePath() | ||
|
||
if (openAfterwards && savePath) { | ||
currentBw.webContents.loadURL('file://' + finalSavePath) | ||
} | ||
|
||
if (bw && !testingMode) { | ||
try { | ||
bw.close() | ||
} catch (exc) {} | ||
} | ||
} | ||
}) | ||
}) | ||
// add back other event handlers (esp. add/filtering.js:registerForDownloadListener which opens the dialog box) | ||
listeners.forEach(function (listener) { | ||
wv.session.on('will-download', listener) | ||
}) | ||
}) | ||
} | ||
|
||
let afterLoaded = () => { | ||
let removeCharEncodingArtifactJS = 'document.body.outerHTML = document.body.outerHTML.replace(/Â/g, "")' | ||
wv.executeJavaScript(removeCharEncodingArtifactJS, whenReadyToGeneratePDF) | ||
} | ||
|
||
bw.loadURL(url) | ||
wv.on('did-finish-load', afterLoaded) | ||
|
||
return appState | ||
} | ||
|
||
module.exports = { | ||
renderUrlToPdf | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.