Skip to content
Snippets Groups Projects
Commit 044134b1 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

change the way the qr code is displayed

Closes #995

Merge request studip/studip!583
parent f8529970
No related branches found
No related tags found
No related merge requests found
jQuery(document).on('click', 'a[data-qr-code]', STUDIP.QRCode.show); jQuery(document).on('click', 'a[data-qr-code]', function (event) {
const data = $(this).data();
STUDIP.QRCode.show(this.href, {
print: data.qrCodePrint ?? false,
title: data.qrTitle ?? null,
description: data.qrCode || null,
});
event.preventDefault();
});
STUDIP.ready((event) => { STUDIP.ready((event) => {
$('code.qr', event.target).each(function () { $('code.qr', event.target).each(function () {
......
import QRCodeGenerator from "../vendor/qrcode-04f46c6.js" import QRCodeGenerator from "../vendor/qrcode-04f46c6.js"
import { $gettext } from "./gettext.js";
import Dialog from "./dialog.js";
const QRCode = { const QRCode = {
show: function() { defaultOptions: {
jQuery('#qr_code').remove(); title: false,
jQuery("<div id='qr_code'/>").appendTo('body'); },
var title = jQuery(this).data('qr-title'); show(text, options = {}) {
if (title) { options = Object.assign({}, QRCode.defaultOptions, options);
jQuery('#qr_code').append('<h1 class="title">' + title + '</h1>');
} else { // Prepare content
jQuery('#qr_code').append("<div class='header'/>"); const content = $('<div class="qr-code-display"/>');
$('<img/>').attr('src', STUDIP.ASSETS_URL + 'images/logos/logoklein.png').appendTo(content);
if (options.title) {
$('<h1>').text(options.title).appendTo(content);
}
const code = $('<div class="code"/>').appendTo(content);
const url = $('<div class="url"/>').appendTo(content);
$('<a/>', {
href: text,
target: '_blank'
}).text(text).appendTo(url);
if (options.description) {
const description = $('<div class="description"/>').text(options.description).appendTo(content);
} }
jQuery('#qr_code').append("<div class='code'/>");
jQuery('#qr_code').append("<div class='url'/>");
jQuery('#qr_code').append("<div class='description'/>");
var code = new QRCodeGenerator(jQuery('#qr_code .code')[0], { // Actually generate code
text: jQuery(this).attr('href'), new QRCodeGenerator(code[0], {
text: text,
width: 1280, width: 1280,
height: 1280, height: 1280,
correctLevel: 3 correctLevel: 3
}); });
jQuery('#qr_code .url').text(jQuery(this).attr('href')); // Prepare dialog
jQuery('#qr_code .description').text(jQuery(this).data('qr-code')); let buttons = {
var print_button_enabled = jQuery(this).data('qr-code-print'); fullscreen: {
if (print_button_enabled) { text: $gettext('Vollbild'),
var icon_path = STUDIP.URLHelper.getURL( 'class': 'fullscreen',
'assets/images/icons/blue/print.svg' click () {
); if (content[0].requestFullscreen) {
var print_element = jQuery('<img></img>'); content[0].requestFullscreen();
jQuery(print_element).attr('src', icon_path); } else if (content[0].msRequestFullscreen) {
jQuery(print_element).addClass('PrintAction'); content[0].msRequestFullscreen();
jQuery('#qr_code').append(print_element); } else if (content[0].mozRequestFullScreen) {
} content[0].mozRequestFullScreen();
} else if (content[0].webkitRequestFullscreen) {
content[0].webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
}
},
cancel: {
text: $gettext('Schließen'),
'class': 'cancel',
click () {
Dialog.close();
}
},
};
//jQuery("#qr_code .code").html(jQuery(this).find(".qrcode_image").clone()); if (options.print) {
var qr = jQuery('#qr_code')[0]; buttons = Object.assign({
if (qr.requestFullscreen) { print: {
qr.requestFullscreen(); text: $gettext('Drucken'),
} else if (qr.msRequestFullscreen) { 'class': 'print',
qr.msRequestFullscreen(); click () {
} else if (qr.mozRequestFullScreen) { var openWindow = window.open("", '_blank');
qr.mozRequestFullScreen(); openWindow.document.write(`<body style="text-align: center;">${content.html()}</body>`);
} else if (qr.webkitRequestFullscreen) { openWindow.document.close();
qr.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); openWindow.focus();
openWindow.print();
openWindow.close();
}
},
}, buttons);
} }
return false;
Dialog.show(content, {
title: options.title ?? $gettext('QR-Code'),
size: 'big',
buttons
});
}, },
generate: function (element, text, options = {}) { generate: function (element, text, options = {}) {
options.text = text; options.text = text;
......
@media print {
div#qr_code {
text-align: center;
h1.title {
margin-bottom: 10mm;
}
div.code img {
width: 170mm;
height: 170mm;
}
.PrintAction {
display: none;
}
div.url {
margin-top: 10mm;
font-size: 14px;
font-weight: bold;
}
}
}
#qr_code { .qr-code-display {
display: none; display: flex;
background-color: white;
width: 100%;
height: 100%;
flex-direction: column; flex-direction: column;
justify-content: space-around;
align-items: center; align-items: center;
color: #444444; justify-content: center;
height: 100%;
.code > div { width: 100%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.code img { h1 {
width: 70vh; display: none;
height: 70vh;
} }
.header { .code {
background-image: url("@{image-path}/logos/logoklein.png"); flex: 0 1 auto;
height: 100px; max-height: 90%; // TODO This will not scale well if description grows
width: 100%; width: 100%;
background-repeat: no-repeat;
background-position: center center; img {
margin: auto;
max-height: 100%;
object-fit: contain;
}
} }
h1 { .url,
text-align: center; .description {
font-size: 1.5em; flex: 0 0 auto;
margin-top: 1em;
} }
&.print-view { &:fullscreen {
.code img { background: var(--white);
width: 170mm;
height: 170mm;
}
.PrintAction { h1 {
display: none; display: initial;
font-size: 3em;
} }
.url { .code {
font-size: 14px; max-height: 80%;
} }
} }
}
#qr_code:-moz-full-screen { @media not print {
display: flex; & > img {
} display: none;
}
#qr_code:-webkit-full-screen { }
display: flex;
}
#qr_code:-ms-fullscreen {
display: flex;
}
#qr_code:fullscreen {
display: flex;
} }
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
@import "less/visibility.less"; @import "less/visibility.less";
@import "less/fullcalendar-print.less"; @import "less/fullcalendar-print.less";
@import "less/resources-print.less"; @import "less/resources-print.less";
@import "less/qrcode-print.less";
@import (reference) "less/schedule.less"; @import (reference) "less/schedule.less";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment