Minimal qr reader implementation
This commit is contained in:
parent
1868dedad6
commit
a8a2dd3f60
3 changed files with 51 additions and 2 deletions
|
|
@ -47,6 +47,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
<div class="card-body text-center p-2">
|
<div class="card-body text-center p-2">
|
||||||
<span id="user_note"><i class="small">{% trans "Please select a note" %}</i></span>
|
<span id="user_note"><i class="small">{% trans "Please select a note" %}</i></span>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="qrreader"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -162,6 +163,53 @@ SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extrajavascript %}
|
{% block extrajavascript %}
|
||||||
|
<script>
|
||||||
|
function onScanSuccess(decodedText, decodedResult) {
|
||||||
|
// handle the scanned code as you like, for example:
|
||||||
|
// Add user if exist on sources_notes_display
|
||||||
|
$.getJSON('/api/note/consumer/?format=json&alias=' + decodedText + '&search=user|club',
|
||||||
|
function (consumers) {
|
||||||
|
if (consumers.count > 0) {
|
||||||
|
// Add the user to the list of sources
|
||||||
|
let consumer = consumers.results[0];
|
||||||
|
disp = {
|
||||||
|
name: consumer.name,
|
||||||
|
id: consumer.id,
|
||||||
|
note: consumer.note,
|
||||||
|
quantity: 1
|
||||||
|
}
|
||||||
|
sources_notes_display.push(disp);
|
||||||
|
// Display
|
||||||
|
const note_list = $('#' + 'source_note_list');
|
||||||
|
let html = ''
|
||||||
|
sources_notes_display.forEach(function (disp) {
|
||||||
|
html += li('source_note' + '_' + disp.id,
|
||||||
|
disp.name +
|
||||||
|
'<span class="badge badge-dark badge-pill">' +
|
||||||
|
disp.quantity + '</span>',
|
||||||
|
displayStyle(disp.note))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Emitters are displayed
|
||||||
|
note_list.html(html)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log(`Code matched = ${decodedText}`, decodedResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onScanFailure(error) {
|
||||||
|
// handle scan failure, usually better to ignore and keep scanning.
|
||||||
|
// for example:
|
||||||
|
console.warn(`Code scan error = ${error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let html5QrcodeScanner = new Html5QrcodeScanner(
|
||||||
|
"qrreader",
|
||||||
|
{ fps: 10, qrbox: {width: 250, height: 250} },
|
||||||
|
/* verbose= */ false);
|
||||||
|
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
|
||||||
|
</script>
|
||||||
<script>
|
<script>
|
||||||
TRANSFER_POLYMORPHIC_CTYPE = {{ polymorphic_ctype }};
|
TRANSFER_POLYMORPHIC_CTYPE = {{ polymorphic_ctype }};
|
||||||
SPECIAL_TRANSFER_POLYMORPHIC_CTYPE = {{ special_polymorphic_ctype }};
|
SPECIAL_TRANSFER_POLYMORPHIC_CTYPE = {{ special_polymorphic_ctype }};
|
||||||
|
|
|
||||||
|
|
@ -220,8 +220,8 @@ MEDIA_URL = '/media/'
|
||||||
# Use mailer in production to place emails in a queue before sending them to avoid spam
|
# Use mailer in production to place emails in a queue before sending them to avoid spam
|
||||||
EMAIL_BACKEND = 'mailer.backend.DbBackend'
|
EMAIL_BACKEND = 'mailer.backend.DbBackend'
|
||||||
MAILER_EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
MAILER_EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||||
EMAIL_USE_SSL = os.getenv('EMAIL_USE_SSL', False)
|
EMAIL_USE_SSL = (os.getenv('EMAIL_USE_SSL', "False")=="True")
|
||||||
EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS', True)
|
EMAIL_USE_TLS = (os.getenv('EMAIL_USE_TLS', "True")=="True")
|
||||||
EMAIL_HOST = os.getenv('EMAIL_HOST', 'smtp.example.org')
|
EMAIL_HOST = os.getenv('EMAIL_HOST', 'smtp.example.org')
|
||||||
EMAIL_PORT = os.getenv('EMAIL_PORT', 587)
|
EMAIL_PORT = os.getenv('EMAIL_PORT', 587)
|
||||||
EMAIL_HOST_USER = os.getenv('EMAIL_USER', None)
|
EMAIL_HOST_USER = os.getenv('EMAIL_USER', None)
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
<script src="{% static "js/turbolinks.js" %}"></script>
|
<script src="{% static "js/turbolinks.js" %}"></script>
|
||||||
<script src="{% static "js/base.js" %}"></script>
|
<script src="{% static "js/base.js" %}"></script>
|
||||||
<script src="{% static "js/konami.js" %}"></script>
|
<script src="{% static "js/konami.js" %}"></script>
|
||||||
|
<script src="https://unpkg.com/html5-qrcode" type="text/javascript"></script>
|
||||||
|
|
||||||
{# Translation in javascript files #}
|
{# Translation in javascript files #}
|
||||||
<script src="{% static "js/jsi18n/"|add:LANGUAGE_CODE|add:".js" %}"></script>
|
<script src="{% static "js/jsi18n/"|add:LANGUAGE_CODE|add:".js" %}"></script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue