[ADD] barcodes/web: element button can use attribute barcode_trigger
A button can be triggered when a barcode corresponding to its attribute 'barcode_trigger' is scanned
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
odoo.define('barcode.InheritedFormWidgetButton', function (require) {
|
||||
"use strict";
|
||||
|
||||
var widgets = require('web.form_widgets');
|
||||
var BarcodeHandlerMixin = require('barcodes.BarcodeHandlerMixin');
|
||||
|
||||
// If the button has a barcode_trigger attribute, dynamically inherit
|
||||
// BarcodeHandlerMixin and redefine on_barcode_scanned
|
||||
|
||||
var ButtonBarcodeHandlerMixin = _.extend({}, BarcodeHandlerMixin, {
|
||||
init: function(field_manager, node) {
|
||||
if (node.attrs.barcode_trigger) {
|
||||
BarcodeHandlerMixin.init.call(this, field_manager, node);
|
||||
var self = this;
|
||||
this.on_barcode_scanned = function(barcode) {
|
||||
var match = barcode.match(/O-BTN\.(.+)/);
|
||||
if (match && match[1] === self.node.attrs.barcode_trigger && self.$el.is(':visible')) {
|
||||
self.on_click();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
this._super(field_manager, node);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
widgets.WidgetButton.include(ButtonBarcodeHandlerMixin);
|
||||
|
||||
});
|
||||
@@ -8,6 +8,7 @@
|
||||
<script type="text/javascript" src="/barcodes/static/src/js/barcode_events.js"></script>
|
||||
<script type="text/javascript" src="/barcodes/static/src/js/barcode_handler_mixin.js"></script>
|
||||
<script type="text/javascript" src="/barcodes/static/src/js/form_view_barcode_handler.js"></script>
|
||||
<script type="text/javascript" src="/barcodes/static/src/js/inherited_form_widget_button.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1663,7 +1663,8 @@ core.form_tag_registry.add('button', WidgetButton);
|
||||
|
||||
return {
|
||||
FieldChar: FieldChar,
|
||||
FieldMonetary: FieldMonetary
|
||||
FieldMonetary: FieldMonetary,
|
||||
WidgetButton: WidgetButton
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user