diff --git a/application/Espo/Core/Htmlizer/Htmlizer.php b/application/Espo/Core/Htmlizer/Htmlizer.php index 877bd63151..f262006447 100644 --- a/application/Espo/Core/Htmlizer/Htmlizer.php +++ b/application/Espo/Core/Htmlizer/Htmlizer.php @@ -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(""); + return new LightnCandy\SafeString(""); }, 'ifEqual' => function () { $args = func_get_args(); diff --git a/application/Espo/Resources/i18n/en_US/FieldManager.json b/application/Espo/Resources/i18n/en_US/FieldManager.json index 93aa69ad74..fb785afee6 100644 --- a/application/Espo/Resources/i18n/en_US/FieldManager.json +++ b/application/Espo/Resources/i18n/en_US/FieldManager.json @@ -68,7 +68,8 @@ "EAN2": "EAN-2", "UPC": "UPC (A)", "UPCE": "UPC (E)", - "pharmacode": "Pharmacode" + "pharmacode": "Pharmacode", + "QRcode": "QR code" } }, "tooltips": { diff --git a/application/Espo/Resources/metadata/fields/barcode.json b/application/Espo/Resources/metadata/fields/barcode.json index e8de6183a2..d9600f9f24 100644 --- a/application/Espo/Resources/metadata/fields/barcode.json +++ b/application/Espo/Resources/metadata/fields/barcode.json @@ -20,7 +20,8 @@ "UPC", "UPCE", "ITF14", - "pharmacode" + "pharmacode", + "QRcode" ], "translation": "FieldManager.options.barcodeType" }, diff --git a/client/res/templates/fields/barcode/detail.tpl b/client/res/templates/fields/barcode/detail.tpl index 0fc315a49f..1bd1655ed6 100644 --- a/client/res/templates/fields/barcode/detail.tpl +++ b/client/res/templates/fields/barcode/detail.tpl @@ -1,5 +1,10 @@ {{#if isNotEmpty}} + +{{#if viewObject.isSvg}} +{{else}} +
+{{/if}} {{else}} {{#if valueIsSet}}{{{translate 'None'}}}{{else}}...{{/if}} diff --git a/client/src/views/fields/barcode.js b/client/src/views/fields/barcode.js index 0961e12fa5..0a26da22d4 100644 --- a/client/src/views/fields/barcode.js +++ b/client/src/views/fields/barcode.js @@ -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(); }