mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Merge used libraries for Barcode/QR-Code generation
This commit is contained in:
@@ -185,20 +185,18 @@ function RandomString()
|
||||
return Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
|
||||
}
|
||||
|
||||
function getQRCodeForContent(url)
|
||||
function QrCodeImgHtml(text)
|
||||
{
|
||||
var qr = qrcode(0, 'L');
|
||||
qr.addData(url);
|
||||
qr.make();
|
||||
return qr.createImgTag(10, 5);
|
||||
}
|
||||
var dummyCanvas = document.createElement("canvas");
|
||||
var img = document.createElement("img");
|
||||
|
||||
function getQRCodeForAPIKey(apikey_type, apikey_key)
|
||||
{
|
||||
var content = U('/api') + '|' + apikey_key;
|
||||
if (apikey_type === 'special-purpose-calendar-ical')
|
||||
{
|
||||
content = U('/api/calendar/ical?secret=' + apikey_key);
|
||||
}
|
||||
return getQRCodeForContent(content);
|
||||
bwipjs.toCanvas(dummyCanvas, {
|
||||
bcid: "qrcode",
|
||||
text: text,
|
||||
scale: 4,
|
||||
includetext: false
|
||||
});
|
||||
img.src = dummyCanvas.toDataURL("image/png");
|
||||
|
||||
return img.outerHTML;
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ $("#ical-button").on("click", function(e)
|
||||
bootbox.alert({
|
||||
title: __t('Share/Integrate calendar (iCal)'),
|
||||
message: __t('Use the following (public) URL to share or integrate the calendar in iCal format') + '<input type="text" class="form-control form-control-sm mt-2 easy-link-copy-textbox" value="' + result.url + '"><p class="text-center mt-4">'
|
||||
+ getQRCodeForContent(result.url) + "</p>",
|
||||
+ QrCodeImgHtml(result.url) + "</p>",
|
||||
closeButton: false
|
||||
});
|
||||
},
|
||||
|
@@ -67,9 +67,21 @@ $(document).on('click', '.apikey-delete-button', function(e)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function QrCodeForApiKey(apiKeyType, apiKey)
|
||||
{
|
||||
var content = U('/api') + '|' + apiKey;
|
||||
if (apiKeyType === 'special-purpose-calendar-ical')
|
||||
{
|
||||
content = U('/api/calendar/ical?secret=' + apiKey);
|
||||
}
|
||||
|
||||
return QrCodeImgHtml(content);
|
||||
}
|
||||
|
||||
$('.apikey-show-qr-button').on('click', function()
|
||||
{
|
||||
var qrcodeHtml = getQRCodeForAPIKey($(this).data('apikey-type'), $(this).data('apikey-key'));
|
||||
var qrcodeHtml = QrCodeForApiKey($(this).data('apikey-type'), $(this).data('apikey-key'));
|
||||
bootbox.alert({
|
||||
title: __t('API key'),
|
||||
message: "<p class='text-center'>" + qrcodeHtml + "</p>",
|
||||
|
Reference in New Issue
Block a user