|
@@ -0,0 +1,35 @@
|
|
|
|
+openerp.eiru_input_formatter = function (instance) {
|
|
|
|
+
|
|
|
|
+ if (instance.web.form && instance.web.form.FieldFloat) {
|
|
|
|
+ instance.web.form.FieldFloat.include({
|
|
|
|
+ start: function () {
|
|
|
|
+ this._super.apply(this, arguments);
|
|
|
|
+ this.getParent().on('change:actual_mode', this, this.on_change_parent_mode)
|
|
|
|
+ },
|
|
|
|
+ on_change_parent_mode: function () {
|
|
|
|
+ if(this.getParent().get('actual_mode') === 'edit') {
|
|
|
|
+ this.$el.find('input:first').keyup(this.on_changing_format_value);
|
|
|
|
+ } else {
|
|
|
|
+ this.$el.find('input:first').off('keyup');
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ on_changing_format_value: function (e) {
|
|
|
|
+ var value = $(e.target).val();
|
|
|
|
+
|
|
|
|
+ if (value.indexOf(',') !== -1) {
|
|
|
|
+ value = value.split(',');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var selectionPosition = $(e.target)[0].selectionEnd;
|
|
|
|
+
|
|
|
|
+ value = value instanceof Array ? this.group_by_thousands(value[0]).concat(',').concat(value[1]) : this.group_by_thousands(value);
|
|
|
|
+
|
|
|
|
+ $(e.target).val(value);
|
|
|
|
+ $(e.target)[0].setSelectionRange(selectionPosition, selectionPosition);
|
|
|
|
+ },
|
|
|
|
+ group_by_thousands: function (value) {
|
|
|
|
+ return value.replace(/\./g, '').replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+}
|