Bladeren bron

[ADD] initial commit

Gogs 7 jaren geleden
commit
f05f2ae5f1
6 gewijzigde bestanden met toevoegingen van 58 en 0 verwijderingen
  1. 1 0
      __init__.py
  2. BIN
      __init__.pyc
  3. 12 0
      __openerp__.py
  4. BIN
      static/description/icon.png
  5. 35 0
      static/src/main.js
  6. 10 0
      templates.xml

+ 1 - 0
__init__.py

@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-

BIN
__init__.pyc


+ 12 - 0
__openerp__.py

@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "Eiru Input Formatter",
+    'description': "A tool for to format number inputs",
+    'author': "Robert Gauto",
+    'category': 'Uncategorized',
+    'version': '0.1',
+    'depends': ['base'],
+    'data': [
+        'templates.xml'
+    ]
+}

BIN
static/description/icon.png


+ 35 - 0
static/src/main.js

@@ -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, '.');
+            }
+        });
+    }
+}

+ 10 - 0
templates.xml

@@ -0,0 +1,10 @@
+<openerp>
+    <data>
+        <!-- Templates -->
+        <template id="eiru_input_formatter" inherit_id="web.assets_backend">
+             <xpath expr="." position="inside">
+                <script type="text/javascript" src="/eiru_input_formatter/static/src/main.js" />
+             </xpath>
+        </template>
+    </data>
+</openerp>