[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
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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;
|
||||
|
||||
});
|
||||
@@ -323,6 +323,7 @@
|
||||
<script type="text/javascript" src="/web/static/src/js/views/search_panel.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/field_manager_mixin.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/select_create_controllers_registry.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/signature_dialog.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/standalone_field_manager_mixin.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/view_registry.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/view_dialogs.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user