---------- JS文件--------------
我可以使用Jsignature库创建自定义pos弹出窗口小部件7,用于绘制签名。 var SaleSignPopupWidget = PopupWidget.extend({ 模板:'SaleSignPopupWidget', 占位符:“/ static/src/img/placeholder.png”,
show: function() {
var self = this;
this.renderElement();
this.$el.find('> img').remove();
this.$el.find('.signature > canvas').remove();
var sign_options = {'lineWidth':'3','decor-color' : '#D1D0CE', 'color': '#000', 'background-color': '#fff','height':'150','width':'450'};
this.$el.find(".signature").jSignature("init",sign_options);
this.$el.find(".signature").attr({"tabindex": "0",'height':"100"});
this.empty_sign = this.$el.find(".signature").jSignature("getData",'image');
this.$el.find('#sign_clean').click(this.on_clear_sign);
this.$el.find('#save_sign').click(this.on_save_sign);
},
on_clear_sign: function() {
var self = this;
this.$el.find(".signature > canvas").remove();
this.$el.find('> img').remove();
this.$el.find(".signature").attr("tabindex", "0");
var sign_options = {'decor-color' : '#D1D0CE', 'color': '#000', 'background-color': '#fff','height':'150','width':'550','clear': true};
this.$el.find(".signature").jSignature(sign_options);
this.$el.find(".signature").focus();
self.set('value', false);
},
on_save_sign: function(value_) {
var self = this;
this.$el.find('> img').remove();
var signature = self.$el.find(".signature").jSignature("getData","base30");
var is_empty = signature
? self.empty_sign[1] === signature[1]
: false;
if (! is_empty && typeof signature !== "undefined" && signature[1]) {
self.set('value',signature[1]);
}
---------- XML文件---------------
<t t-name="SaleSignPopupWidget">
<div class="modal-dialog">
<div class="popup" id="drawsign">
<div class="header">
<strong>Draw your signature</strong>
<div class="signature"></div>
</div>
<div class="footer">
<div class="button confirm" id="save_sign">
Save
</div>
<div class="button" id="sign_clean">
Clear
</div>
<div class="button cancel">
Cancel
</div>
</div>
</div>
</div>
</t>
<t t-name="FieldBinaryImage-extend">
<img t-att-src='url'
t-att-border="widget.readonly ? 0 : 1"
t-att-name="widget.name"
t-att-width="widget.node.attrs.img_width || widget.node.attrs.width"
t-att-height="widget.node.attrs.img_height || widget.node.attrs.height"
t-att-tabindex="widget.node.attrs.img_tabindex || widget.node.attrs.tabindex"
/>
</t>