This commit is contained in:
Yuri Kuznetsov
2019-11-26 11:36:08 +02:00
parent f029ea2c81
commit fe36d049af
5 changed files with 85 additions and 33 deletions
+44 -21
View File
@@ -339,32 +339,55 @@ class Htmlizer
"UPCE" => 'UPCE',
"ITF14" => 'I25',
"pharmacode" => 'PHARMA',
"QRcode" => 'QRCODE,H',
];
$params = [
$value,
$typeMap[$codeType] ?? null,
'', '',
$context['hash']['width'] ?? 60,
$context['hash']['height'] ?? 30,
0.4,
[
'position' => 'S',
'border' => false,
'padding' => $context['hash']['padding'] ?? 0,
'fgcolor' => $context['hash']['color'] ?? [0,0,0],
'bgcolor' => $context['hash']['bgcolor'] ?? [255,255,255],
'text' => $context['hash']['text'] ?? true,
'font' => 'helvetica',
'fontsize' => $context['hash']['fontsize'] ?? 14,
'stretchtext' => 4,
],
'N',
];
if ($codeType === 'QRcode') {
$function = 'write2DBarcode';
$params = [
$value,
$typeMap[$codeType] ?? null,
'', '',
$context['hash']['width'] ?? 40,
$context['hash']['height'] ?? 40,
[
'border' => false,
'vpadding' => $context['hash']['padding'] ?? 2,
'hpadding' => $context['hash']['padding'] ?? 2,
'fgcolor' => $context['hash']['color'] ?? [0,0,0],
'bgcolor' => $context['hash']['bgcolor'] ?? false,
'module_width' => 1,
'module_height' => 1,
],
'N',
];
} else {
$function = 'write1DBarcode';
$params = [
$value,
$typeMap[$codeType] ?? null,
'', '',
$context['hash']['width'] ?? 60,
$context['hash']['height'] ?? 30,
0.4,
[
'position' => 'S',
'border' => false,
'padding' => $context['hash']['padding'] ?? 0,
'fgcolor' => $context['hash']['color'] ?? [0,0,0],
'bgcolor' => $context['hash']['bgcolor'] ?? [255,255,255],
'text' => $context['hash']['text'] ?? true,
'font' => 'helvetica',
'fontsize' => $context['hash']['fontsize'] ?? 14,
'stretchtext' => 4,
],
'N',
];
}
$paramsString = urlencode(json_encode($params));
return new LightnCandy\SafeString("<tcpdf method=\"write1DBarcode\" params=\"{$paramsString}\" />");
return new LightnCandy\SafeString("<tcpdf method=\"{$function}\" params=\"{$paramsString}\" />");
},
'ifEqual' => function () {
$args = func_get_args();
@@ -68,7 +68,8 @@
"EAN2": "EAN-2",
"UPC": "UPC (A)",
"UPCE": "UPC (E)",
"pharmacode": "Pharmacode"
"pharmacode": "Pharmacode",
"QRcode": "QR code"
}
},
"tooltips": {
@@ -20,7 +20,8 @@
"UPC",
"UPCE",
"ITF14",
"pharmacode"
"pharmacode",
"QRcode"
],
"translation": "FieldManager.options.barcodeType"
},
@@ -1,5 +1,10 @@
{{#if isNotEmpty}}
{{#if viewObject.isSvg}}
<svg class="barcode"></svg>
{{else}}
<div class="barcode"></div>
{{/if}}
{{else}}
{{#if valueIsSet}}{{{translate 'None'}}}{{else}}...{{/if}}
+32 -10
View File
@@ -26,7 +26,8 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/fields/barcode', ['views/fields/varchar', 'lib!JsBarcode'], function (Dep, JsBarcode) {
define('views/fields/barcode', [
'views/fields/varchar', 'lib!JsBarcode', 'lib!client/lib/qrcode.min.js'], function (Dep, JsBarcode, Qrcode) {
return Dep.extend({
@@ -58,11 +59,14 @@ define('views/fields/barcode', ['views/fields/varchar', 'lib!JsBarcode'], functi
maxLength = 14; break;
case 'pharmacode':
maxLength = 6; break;
}
this.params.maxLength = maxLength;
if (this.params.codeType !== 'QRcode') {
this.isSvg = true;
}
Dep.prototype.setup.call(this);
$(window).on('resize.' + this.cid, function () {
@@ -75,20 +79,38 @@ define('views/fields/barcode', ['views/fields/varchar', 'lib!JsBarcode'], functi
$(window).off('resize.' + this.cid);
},
afterRender: function () {
Dep.prototype.afterRender.call(this);
if (this.mode === 'list' || this.mode === 'detail') {
var value = this.model.get(this.name);
if (value) {
JsBarcode(this.getSelector() + ' .barcode', value, {
format: this.params.codeType,
height: 50,
fontSize: 14,
margin: 0,
lastChar: this.params.lastChar,
});
if (this.params.codeType === 'QRcode') {
var size = 128;
if (this.isListMode()) {
size = 64;
}
var containerWidth = this.$el.width() ;
if (containerWidth < size && containerWidth) {
size = containerWidth;
}
var qrCode = new QRCode(this.$el.find('.barcode').get(0), {
text: value,
width: size,
height: size,
colorDark : '#000000',
colorLight : '#ffffff',
correctLevel : QRCode.CorrectLevel.H,
});
} else {
JsBarcode(this.getSelector() + ' .barcode', value, {
format: this.params.codeType,
height: 50,
fontSize: 14,
margin: 0,
lastChar: this.params.lastChar,
});
}
}
this.controlWidth();
}