odoo.define('web.Signature', function (require) { "use strict"; var AbstractFieldBinary = require('web.basic_fields').AbstractFieldBinary; var core = require('web.core'); var field_utils = require('web.field_utils'); var registry = require('web.field_registry'); var session = require('web.session'); const SignatureDialog = require('web.signature_dialog'); var utils = require('web.utils'); var qweb = core.qweb; var _t = core._t; var _lt = core._lt; var FieldBinarySignature = AbstractFieldBinary.extend({ description: _lt("Signature"), fieldDependencies: _.extend({}, AbstractFieldBinary.prototype.fieldDependencies, { __last_update: {type: 'datetime'}, }), resetOnAnyFieldChange: true, custom_events: _.extend({}, AbstractFieldBinary.prototype.custom_events, { upload_signature: '_onUploadSignature', }), events: _.extend({}, AbstractFieldBinary.prototype.events, { 'click .o_signature': '_onClickSignature', }), template: null, supportedFieldTypes: ['binary'], file_type_magic_word: { '/': 'jpg', 'R': 'gif', 'i': 'png', 'P': 'svg+xml', }, //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- /** * This widget must always have render even if there are no signature. * In edit mode, the real value is return to manage required fields. * * @override */ isSet: function () { if (this.mode === 'edit') { return this.value; } return true; }, //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- /** * Renders an empty signature or the saved signature. Both must have the same size. * * @override * @private */ _render: function () { var self = this; var displaySignatureRatio = 3; var url; var $img; var width = this.nodeOptions.size ? this.nodeOptions.size[0] : this.attrs.width; var height = this.nodeOptions.size ? this.nodeOptions.size[1] : this.attrs.height; if (this.value) { if (!utils.is_bin_size(this.value)) { // Use magic-word technique for detecting image type url = 'data:image/' + (this.file_type_magic_word[this.value[0]] || 'png') + ';base64,' + this.value; } else { url = session.url('/web/image', { model: this.model, id: JSON.stringify(this.res_id), field: this.nodeOptions.preview_image || this.name, // unique forces a reload of the image when the record has been updated unique: field_utils.format.datetime(this.recordData.__last_update).replace(/[^0-9]/g, ''), }); } $img = $(qweb.render("FieldBinarySignature-img", {widget: this, url: url})); } else { $img = $('
' + _t('SIGNATURE') + '