PDF editor: Allow arbitrary fields in QR codes

This commit is contained in:
Raphael Michel
2022-03-13 14:25:41 +01:00
committed by Raphael Michel
parent c2f2e157d7
commit 4ae7cc9f50
4 changed files with 44 additions and 17 deletions

View File

@@ -202,6 +202,11 @@ DEFAULT_VARIABLES = OrderedDict((
"editor_sample": 'foo@bar.com',
"evaluate": lambda op, order, ev: op.attendee_email or (op.addon_to.attendee_email if op.addon_to else '')
}),
("pseudonymization_id", {
"label": _("Pseudonymization ID (lead scanning)"),
"editor_sample": "GG89JUJDTA",
"evaluate": lambda orderposition, order, event: orderposition.pseudonymization_id,
}),
("event_name", {
"label": _("Event name"),
"editor_sample": _("Sample event name"),
@@ -616,12 +621,12 @@ class Renderer:
preserveAspectRatio=True, anchor='n',
mask='auto')
def _draw_barcodearea(self, canvas: Canvas, op: OrderPosition, o: dict):
def _draw_barcodearea(self, canvas: Canvas, op: OrderPosition, order: Order, o: dict):
content = o.get('content', 'secret')
if content == 'secret':
content = op.secret
elif content == 'pseudonymization_id':
content = op.pseudonymization_id
else:
content = self._get_text_content(op, order, o)
level = 'H'
if len(content) > 32:
@@ -767,7 +772,7 @@ class Renderer:
if o.get('page', 1) != page + 1:
continue
if o['type'] == "barcodearea":
self._draw_barcodearea(canvas, op, o)
self._draw_barcodearea(canvas, op, order, o)
elif o['type'] == "imagearea":
self._draw_imagearea(canvas, op, order, o)
elif o['type'] == "textarea":

View File

@@ -367,9 +367,9 @@
</select>
</div>
</div>
<div class="row control-group text">
<div class="row control-group text textcontent">
<div class="col-sm-12">
<label>{% trans "Text content" %}</label><br>
<label>{% trans "Content" %}</label><br>
<select class="input-block-level form-control" id="toolbox-content">
{% for varname, var in variables.items %}
<option data-sample="{{ var.editor_sample }}" value="{{ varname }}">{{ var.label }}</option>
@@ -411,6 +411,12 @@
<span class="fa fa-qrcode"></span>
{% trans "QR code for Lead Scanning" %}
</button>
<button class="btn btn-default btn-block" id="editor-add-qrcode-other"
data-content="secret"
disabled>
<span class="fa fa-qrcode"></span>
{% trans "Other QR code" %}
</button>
<button class="btn btn-default btn-block" id="editor-add-poweredby"
data-content="dark"
disabled>

View File

@@ -66,9 +66,11 @@ fabric.Barcodearea = fabric.util.createClass(fabric.Rect, {
ctx.font = '16px Helvetica';
ctx.fillStyle = '#fff';
if (this.content === "pseudonymization_id") {
ctx.fillText(gettext('Lead Scan QR'), -this.width / 2, -this.height / 2 + 20);
} else {
ctx.fillText(this.content, -this.width / 2, -this.height / 2 + 20);
} else if (!this.content || this.content === "secret") {
ctx.fillText(gettext('Check-in QR'), -this.width / 2, -this.height / 2 + 20);
} else {
ctx.fillText(this.content, -this.width / 2, -this.height / 2 + 20);
}
},
});
@@ -478,14 +480,18 @@ var editor = {
$("#toolbox").find("button[data-action=right]").toggleClass('active', o.textAlign === 'right');
$("#toolbox-textwidth").val(editor._px2mm(o.width).toFixed(2));
$("#toolbox-textrotation").val((o.angle || 0.0).toFixed(1));
if (o.type === "textarea") {
$("#toolbox-content").val(o.content);
$("#toolbox-content-other").toggle($("#toolbox-content").val() === "other");
if (o.content === "other") {
$("#toolbox-content-other").val(o.text);
} else {
$("#toolbox-content-other").val("");
}
}
if (o.type === "textarea" || o.type === "barcodearea") {
if (!o.content && o.type == "barcodearea") {
o.content = "secret";
}
$("#toolbox-content").val(o.content);
$("#toolbox-content-other").toggle($("#toolbox-content").val() === "other");
if (o.content === "other") {
$("#toolbox-content-other").val(o.text);
} else {
$("#toolbox-content-other").val("");
}
}
},
@@ -517,6 +523,14 @@ var editor = {
o.setScaleY(1);
o.set('top', new_top)
o.nowhitespace = $("#toolbox-qrwhitespace").prop("checked") || false;
$("#toolbox-content-other").toggle($("#toolbox-content").val() === "other");
o.content = $("#toolbox-content").val();
if ($("#toolbox-content").val() === "other") {
o.text = $("#toolbox-content-other").val();
} else {
o.text = editor._get_text_sample($("#toolbox-content").val());
}
} else if (o.type === "imagearea") {
var new_w = editor._mm2px($("#toolbox-width").val());
var new_h = editor._mm2px($("#toolbox-height").val());
@@ -674,6 +688,7 @@ var editor = {
lockUniScaling: true,
fill: '#666',
content: $(this).attr("data-content"),
text: '',
nowhitespace: true,
});
rect.setControlsVisibility({'mtr': false});
@@ -931,7 +946,7 @@ var editor = {
editor.$fcv = $("#fabric-canvas");
editor.$cva = $("#editor-canvas-area");
editor._load_pdf();
$("#editor-add-qrcode, #editor-add-qrcode-lead").click(editor._add_qrcode);
$("#editor-add-qrcode, #editor-add-qrcode-lead, #editor-add-qrcode-other").click(editor._add_qrcode);
$("#editor-add-image").click(editor._add_imagearea);
$("#editor-add-text").click(editor._add_text);
$("#editor-add-poweredby").click(function() {editor._add_poweredby("dark")});

View File

@@ -25,6 +25,7 @@ body {
}
#toolbox[data-type] .position,
#toolbox[data-type=barcodearea] .squaresize,
#toolbox[data-type=barcodearea] .textcontent,
#toolbox[data-type=imagearea] .rectsize,
#toolbox[data-type=imagearea] .imagecontent,
#toolbox[data-type=poweredby] .poweredby,