diff options
| author | svs-odoo <svs@odoo.com> | 2019-10-23 10:02:46 +0000 |
|---|---|---|
| committer | svs-odoo <svs@odoo.com> | 2019-10-28 10:46:06 +0000 |
| commit | 49b5f30202cb5ab6d9f6d8c9f4773fa9d2bbee18 (patch) | |
| tree | 89401adc7de559c2e569e9f02d8c11a382e0c3ea /addons/web/static | |
| parent | 3116191e78bfd6b5cce8e92ae54e848965fd7811 (diff) | |
[MOV] web: signature_dialog
Remove SignatureDialog from `signature.js` to put it in its own file,
`signature_dialog.js`. The purpose of this change is to be able to
require SignatureDialog in any other file and to separate dialog and
field business.
task-1878607
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/src/js/fields/signature.js | 112 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/signature_dialog.js | 121 |
2 files changed, 122 insertions, 111 deletions
diff --git a/addons/web/static/src/js/fields/signature.js b/addons/web/static/src/js/fields/signature.js index e27ec36e01a..98911f76155 100644 --- a/addons/web/static/src/js/fields/signature.js +++ b/addons/web/static/src/js/fields/signature.js @@ -3,11 +3,10 @@ odoo.define('web.Signature', function (require) { var AbstractFieldBinary = require('web.basic_fields').AbstractFieldBinary; var core = require('web.core'); - var Dialog = require('web.Dialog'); var field_utils = require('web.field_utils'); - var NameAndSignature = require('web.name_and_signature').NameAndSignature; var registry = require('web.field_registry'); var session = require('web.session'); + const SignatureDialog = require('web.signature_dialog'); var utils = require('web.utils'); @@ -15,115 +14,6 @@ odoo.define('web.Signature', function (require) { var _t = core._t; var _lt = core._lt; -// The goal of this dialog is to ask the user a signature request. -// It uses @see SignNameAndSignature for the name and signature fields. -var SignatureDialog = Dialog.extend({ - template: 'web.signature_dialog', - xmlDependencies: Dialog.prototype.xmlDependencies.concat( - ['/web/static/src/xml/name_and_signature.xml'] - ), - custom_events: { - 'signature_changed': '_onChangeSignature', - }, - - /** - * @constructor - * @param {Widget} parent - * @param {Object} options - * @param {string} [options.title='Adopt Your Signature'] - modal title - * @param {string} [options.size='medium'] - modal size - * @param {Object} [options.nameAndSignatureOptions={}] - options for - * @see NameAndSignature.init() - */ - init: function (parent, options) { - var self = this; - options = options || {}; - - options.title = options.title || _t("Adopt Your Signature"); - options.size = options.size || 'medium'; - options.technical = false; - - if (!options.buttons) { - options.buttons = []; - options.buttons.push({text: _t("Adopt and Sign"), classes: "btn-primary", disabled: true, click: function (e) { - self._onConfirm(); - }}); - options.buttons.push({text: _t("Cancel"), close: true}); - } - - this._super(parent, options); - - this.nameAndSignature = new NameAndSignature(this, options.nameAndSignatureOptions); - }, - /** - * Start the nameAndSignature widget and wait for it. - * - * @override - */ - willStart: function () { - return Promise.all([ - this.nameAndSignature.appendTo($('<div>')), - this._super.apply(this, arguments) - ]); - }, - /** - * Initialize the name and signature widget when the modal is opened. - * - * @override - */ - start: function () { - var self = this; - this.$primaryButton = this.$footer.find('.btn-primary'); - - this.opened().then(function () { - self.$('.o_web_sign_name_and_signature').replaceWith(self.nameAndSignature.$el); - // initialize the signature area - self.nameAndSignature.resetSignature(); - }); - - return this._super.apply(this, arguments); - }, - - //---------------------------------------------------------------------- - // Public - //---------------------------------------------------------------------- - - /** - * Returns whether the drawing area is currently empty. - * - * @see NameAndSignature.isSignatureEmpty() - * @returns {boolean} Whether the drawing area is currently empty. - */ - isSignatureEmpty: function () { - return this.nameAndSignature.isSignatureEmpty(); - }, - - //---------------------------------------------------------------------- - // Handlers - //---------------------------------------------------------------------- - - /** - * Toggles the submit button depending on the signature state. - * - * @private - */ - _onChangeSignature: function () { - var isEmpty = this.nameAndSignature.isSignatureEmpty(); - this.$primaryButton.prop('disabled', isEmpty); - }, - /** - * Upload the signature image when confirm. - * - * @private - */ - _onConfirm: function (fct) { - this.trigger_up('upload_signature', { - name: this.nameAndSignature.getName(), - signatureImage: this.nameAndSignature.getSignatureImage(), - }); - }, -}); - var FieldBinarySignature = AbstractFieldBinary.extend({ description: _lt("Signature"), fieldDependencies: _.extend({}, AbstractFieldBinary.prototype.fieldDependencies, { diff --git a/addons/web/static/src/js/views/signature_dialog.js b/addons/web/static/src/js/views/signature_dialog.js new file mode 100644 index 00000000000..12bb18f4fb7 --- /dev/null +++ b/addons/web/static/src/js/views/signature_dialog.js @@ -0,0 +1,121 @@ +odoo.define('web.signature_dialog', function (require) { +"use strict"; + +var core = require('web.core'); +var Dialog = require('web.Dialog'); +var NameAndSignature = require('web.name_and_signature').NameAndSignature; + +var _t = core._t; + +// The goal of this dialog is to ask the user a signature request. +// It uses @see SignNameAndSignature for the name and signature fields. +var SignatureDialog = Dialog.extend({ + template: 'web.signature_dialog', + xmlDependencies: Dialog.prototype.xmlDependencies.concat( + ['/web/static/src/xml/name_and_signature.xml'] + ), + custom_events: { + 'signature_changed': '_onChangeSignature', + }, + + /** + * @constructor + * @param {Widget} parent + * @param {Object} options + * @param {string} [options.title='Adopt Your Signature'] - modal title + * @param {string} [options.size='medium'] - modal size + * @param {Object} [options.nameAndSignatureOptions={}] - options for + * @see NameAndSignature.init() + */ + init: function (parent, options) { + var self = this; + options = options || {}; + + options.title = options.title || _t("Adopt Your Signature"); + options.size = options.size || 'medium'; + options.technical = false; + + if (!options.buttons) { + options.buttons = []; + options.buttons.push({text: _t("Adopt and Sign"), classes: "btn-primary", disabled: true, click: function (e) { + self._onConfirm(); + }}); + options.buttons.push({text: _t("Cancel"), close: true}); + } + + this._super(parent, options); + + this.nameAndSignature = new NameAndSignature(this, options.nameAndSignatureOptions); + }, + /** + * Start the nameAndSignature widget and wait for it. + * + * @override + */ + willStart: function () { + return Promise.all([ + this.nameAndSignature.appendTo($('<div>')), + this._super.apply(this, arguments) + ]); + }, + /** + * Initialize the name and signature widget when the modal is opened. + * + * @override + */ + start: function () { + var self = this; + this.$primaryButton = this.$footer.find('.btn-primary'); + + this.opened().then(function () { + self.$('.o_web_sign_name_and_signature').replaceWith(self.nameAndSignature.$el); + // initialize the signature area + self.nameAndSignature.resetSignature(); + }); + + return this._super.apply(this, arguments); + }, + + //---------------------------------------------------------------------- + // Public + //---------------------------------------------------------------------- + + /** + * Returns whether the drawing area is currently empty. + * + * @see NameAndSignature.isSignatureEmpty() + * @returns {boolean} Whether the drawing area is currently empty. + */ + isSignatureEmpty: function () { + return this.nameAndSignature.isSignatureEmpty(); + }, + + //---------------------------------------------------------------------- + // Handlers + //---------------------------------------------------------------------- + + /** + * Toggles the submit button depending on the signature state. + * + * @private + */ + _onChangeSignature: function () { + var isEmpty = this.nameAndSignature.isSignatureEmpty(); + this.$primaryButton.prop('disabled', isEmpty); + }, + /** + * Upload the signature image when confirm. + * + * @private + */ + _onConfirm: function (fct) { + this.trigger_up('upload_signature', { + name: this.nameAndSignature.getName(), + signatureImage: this.nameAndSignature.getSignatureImage(), + }); + }, +}); + +return SignatureDialog; + +}); |
