2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Client side QR Codes (#4357)

* Add JS for qrcodejs

Ref: https://davidshimjs.github.io/qrcodejs/

* Simple function for rendering a QR code

* Refactor QR code view for Part

* Replace QR code view for SupplierPart

* Refactor QR codes for stock item and stock location models

* Remove base QRCodeView entirely
This commit is contained in:
Oliver
2023-02-17 13:33:36 +11:00
committed by GitHub
parent 0f445ea6e4
commit cde2050236
15 changed files with 56 additions and 161 deletions

View File

@ -15,6 +15,7 @@
getFieldValue,
reloadFieldOptions,
showModalImage,
showQRDialog,
showQuestionDialog,
showModalSpinner,
*/
@ -590,19 +591,18 @@ function renderErrorMessage(xhr) {
}
/* Display a modal dialog message box.
*
* title - Title text
* content - HTML content of the dialog window
*/
function showAlertDialog(title, content, options={}) {
/* Display a modal dialog message box.
*
* title - Title text
* content - HTML content of the dialog window
*/
if (options.alert_style) {
// Wrap content in an alert block
content = `<div class='alert alert-block alert-${options.alert_style}'>${content}</div>`;
}
var modal = createNewModal({
title: title,
closeText: '{% trans "Close" %}',
@ -612,6 +612,36 @@ function showAlertDialog(title, content, options={}) {
modalSetContent(modal, content);
$(modal).modal('show');
if (options.after_render) {
options.after_render(modal);
}
}
/*
* Display a simple modal window with a QR code
*/
function showQRDialog(title, data, options={}) {
let content = `
<div id='qrcode-container' style='margin: auto; width: 256px; padding: 25px;'>
<div id='qrcode'></div>
</div>`;
options.after_render = function(modal) {
let qrcode = new QRCode('qrcode', {
width: 256,
height: 256,
});
qrcode.makeCode(data);
};
showAlertDialog(
title,
content,
options
);
}

View File

@ -35,3 +35,4 @@
<script defer type='text/javascript' src="{% static 'easymde/easymde.min.js' %}"></script>
<script defer type='text/javascript' src="{% static 'script/randomColor.min.js' %}"></script>
<script defer type='text/javascript' src="{% static 'script/html5-qrcode.min.js' %}"></script>
<script defer type='text/javascript' src="{% static 'script/qrcode.min.js' %}"></script>