forked from 2sic/app-qr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRCode.cshtml
53 lines (46 loc) · 1.87 KB
/
QRCode.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@inherits Custom.Hybrid.RazorTyped
@using ToSic.Razor.Blade;
@{
// Get the QR-Code settings from the current item
var qrSettings = MyItem;
// The view identifier determines if the code should be visible or only on printing
var printOnly = MyView.Identifier == "print";
// sets qrlink to specified url
var qrLink = qrSettings.Bool("LinkCurrentPage")
? Link.To(parameters: MyPage.Parameters)
: qrSettings.Url("Link");
// This ID is used to identify our unique code in the HTML DOM
var qrDomId = "qr-code-js" + UniqueKey;
}
@* Add Infos for URL and Title to generate a QR Code *@
<div @Kit.Edit.TagToolbar(qrSettings) class='@(printOnly ? "app-qrcode2-print-only" : "")'>
<a class="@qrDomId" href='@qrLink' target="_blank"></a>
@if (qrSettings.Bool("DisplayLinkOrTitle")) {
var displayText = Text.First(qrSettings.String("Title"), qrSettings.String("Link"));
<div>@displayText</div>
}
</div>
@* Show a special message to admins if the QR-Code is invisible otherwise *@
@if (printOnly && MyUser.IsContentAdmin) {
<div class="alert alert-info app-qrcode2-noprint" @Kit.Edit.TagToolbar(qrSettings)>
@App.Resources.String("PrintQrAdminHint")
</div>
}
@* Generate the QR Code *@
@{
// Get the settings from the current item, or fallback to App Settings
var qrParams = qrSettings.Child("QrCodeSettings") ?? App.Settings.Child("QrCodeSettings");
var size = qrParams.Int("Size");
var data = new {
domId = qrDomId,
options = new {
color = "#" + qrParams.String("Color").Trim('#'),
width = size,
height = size
}
};
}
@* When the page is ready, run appQr2 to init JS *@
@Kit.Page.TurnOn("window.appQr2.init()", data: data)
<script type="text/javascript" src="@App.Folder.Url/dist/scripts.min.js" @Kit.Page.AssetAttributes(position: "bottom")></script>
<link rel="stylesheet" href="@App.Folder.Url/dist/styles.min.css">