From 23caf567db0eb658910bdde7303353d4468960cf Mon Sep 17 00:00:00 2001 From: Nikolina Todorova Date: Wed, 27 May 2015 15:19:19 +0200 Subject: [PATCH 1/7] 7.0 add web text widget --- web_text_widget/__init__.py | 21 ++++++ web_text_widget/__openerp__.py | 62 +++++++++++++++++ .../static/src/css/text_limited.css | 8 +++ web_text_widget/static/src/js/text_limited.js | 68 +++++++++++++++++++ .../static/src/xml/text_limited.xml | 8 +++ 5 files changed, 167 insertions(+) create mode 100644 web_text_widget/__init__.py create mode 100644 web_text_widget/__openerp__.py create mode 100644 web_text_widget/static/src/css/text_limited.css create mode 100644 web_text_widget/static/src/js/text_limited.js create mode 100644 web_text_widget/static/src/xml/text_limited.xml diff --git a/web_text_widget/__init__.py b/web_text_widget/__init__.py new file mode 100644 index 00000000..78003df6 --- /dev/null +++ b/web_text_widget/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2015 OpenERP s.a. (). +# Copyright (C) 2015 initOS GmbH & Co. KG (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## diff --git a/web_text_widget/__openerp__.py b/web_text_widget/__openerp__.py new file mode 100644 index 00000000..5baf6e41 --- /dev/null +++ b/web_text_widget/__openerp__.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2015 OpenERP s.a. (). +# Copyright (C) 2015 initOS GmbH & Co. KG (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Web text limited widget', + 'version': '0.1.0', + 'author': 'initOS GmbH & Co. KG', + 'category': '', + 'description': """ + +* Add new 'text_limited' widget for TextField, but data are limited to +10 lines or 500 characters (by default). +You can change default values by context varibles 'limit_lines' and +'limit_chars'. +If data contains more characters or lines, it will be cut. +Example of usage: + +""", + 'website': 'http://www.initos.com', + 'license': 'AGPL-3', + 'images': [], + 'depends': [ + 'web', + ], + 'data': [], + 'update_xml': [], + 'js': [ + 'static/src/js/text_limited.js', + ], + 'qweb': [ + 'static/src/xml/text_limited.xml', + ], + 'css': [ + 'static/src/css/text_limited.css', + ], + 'demo': [], + 'test': [], + 'active': False, + 'installable': True, + 'auto_install': True, +} diff --git a/web_text_widget/static/src/css/text_limited.css b/web_text_widget/static/src/css/text_limited.css new file mode 100644 index 00000000..c01c56bd --- /dev/null +++ b/web_text_widget/static/src/css/text_limited.css @@ -0,0 +1,8 @@ +div.oe_form_field.oe_form_field_text { + position: relative; +} + +span.length_limit { + position: absolute; + right: 0; +} diff --git a/web_text_widget/static/src/js/text_limited.js b/web_text_widget/static/src/js/text_limited.js new file mode 100644 index 00000000..d10305d9 --- /dev/null +++ b/web_text_widget/static/src/js/text_limited.js @@ -0,0 +1,68 @@ +openerp.web_text_widget = function (instance) +{ + +var QWeb = instance.web.qweb; +var _t = instance.web._t; + + +instance.web_text_widget.FieldTextLimited = instance.web.form.FieldText.extend( + instance.web.form.ReinitializeFieldMixin, { + template: 'FieldText', + LIMIT_LINES_CONTEXT_KEY: 'limit_lines', + LIMIT_LINES_DEFAULT: 10, + LIMIT_CHARS_CONTEXT_KEY: 'limit_chars', + LIMIT_CHARS_DEFAULT: 500, + + events: { + 'keyup': function (e) { + if (e.which === $.ui.keyCode.ENTER) { + e.stopPropagation(); + } + this.limit_value($(e.target)); + }, + 'change textarea': 'store_dom_value', + }, + + limit_value: function($textarea) + { + var ctx = this.build_context().eval(); + var limit_lines = ctx[this.LIMIT_LINES_CONTEXT_KEY]*1 + if (!limit_lines){ + limit_lines = this.LIMIT_LINES_DEFAULT; + console.log("No default values found for limit lines in '" + + this.name + "' field. Default value " + limit_lines + + " will be used."); + } + + var limit_chars = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 + if (!limit_chars){ + limit_chars = this.LIMIT_CHARS_DEFAULT; + console.log("No default values found for limit chars in '" + + this.name + "' field. Default value " + limit_chars + + " will be used."); + } + + var value = $textarea.val(); + var lines = value.split("\n"); + if (lines.length > limit_lines){ + $textarea.val(lines.slice(0, limit_lines).join("\n")); + } + if (value.length > limit_chars){ + $textarea.val(value.slice(0, limit_chars)); + } + this.$el.find('span.length_limit').html(value.length + '/' + limit_chars); + }, + + initialize_content: function() { + return this._super(); + }, + + store_dom_value: function () { + this.limit_value(this.$textarea); + return this._super(); + }, +}); + +instance.web.form.widgets.add('text_limited', + 'instance.web_text_widget.FieldTextLimited'); +}; diff --git a/web_text_widget/static/src/xml/text_limited.xml b/web_text_widget/static/src/xml/text_limited.xml new file mode 100644 index 00000000..314a12f2 --- /dev/null +++ b/web_text_widget/static/src/xml/text_limited.xml @@ -0,0 +1,8 @@ + + + + + + + + From e2dfadf713463e8f7476260ba0bbf4819645a620 Mon Sep 17 00:00:00 2001 From: Nikolina Todorova Date: Thu, 8 Oct 2015 10:59:36 +0200 Subject: [PATCH 2/7] Add the functionality to the text widget --- web_text_widget/__openerp__.py | 3 +-- web_text_widget/static/src/js/text_limited.js | 16 ++-------------- web_text_widget/static/src/xml/text_limited.xml | 8 -------- 3 files changed, 3 insertions(+), 24 deletions(-) delete mode 100644 web_text_widget/static/src/xml/text_limited.xml diff --git a/web_text_widget/__openerp__.py b/web_text_widget/__openerp__.py index 5baf6e41..164b3cd8 100644 --- a/web_text_widget/__openerp__.py +++ b/web_text_widget/__openerp__.py @@ -26,7 +26,7 @@ 'category': '', 'description': """ -* Add new 'text_limited' widget for TextField, but data are limited to +* Add new functionality for TextField, but data are limited to 10 lines or 500 characters (by default). You can change default values by context varibles 'limit_lines' and 'limit_chars'. @@ -49,7 +49,6 @@ Example of usage: 'static/src/js/text_limited.js', ], 'qweb': [ - 'static/src/xml/text_limited.xml', ], 'css': [ 'static/src/css/text_limited.css', diff --git a/web_text_widget/static/src/js/text_limited.js b/web_text_widget/static/src/js/text_limited.js index d10305d9..c676d0ae 100644 --- a/web_text_widget/static/src/js/text_limited.js +++ b/web_text_widget/static/src/js/text_limited.js @@ -5,8 +5,7 @@ var QWeb = instance.web.qweb; var _t = instance.web._t; -instance.web_text_widget.FieldTextLimited = instance.web.form.FieldText.extend( - instance.web.form.ReinitializeFieldMixin, { +instance.web.form.FieldText.include({ template: 'FieldText', LIMIT_LINES_CONTEXT_KEY: 'limit_lines', LIMIT_LINES_DEFAULT: 10, @@ -53,16 +52,5 @@ instance.web_text_widget.FieldTextLimited = instance.web.form.FieldText.extend( this.$el.find('span.length_limit').html(value.length + '/' + limit_chars); }, - initialize_content: function() { - return this._super(); - }, - - store_dom_value: function () { - this.limit_value(this.$textarea); - return this._super(); - }, }); - -instance.web.form.widgets.add('text_limited', - 'instance.web_text_widget.FieldTextLimited'); -}; +} \ No newline at end of file diff --git a/web_text_widget/static/src/xml/text_limited.xml b/web_text_widget/static/src/xml/text_limited.xml deleted file mode 100644 index 314a12f2..00000000 --- a/web_text_widget/static/src/xml/text_limited.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - From a9ea234f56ccfc74a1391d7296d4bf74a635fb82 Mon Sep 17 00:00:00 2001 From: Nikolina Todorova Date: Sat, 17 Oct 2015 18:37:16 +0200 Subject: [PATCH 3/7] Improve code according to the comments --- web_text_widget/__openerp__.py | 14 ++--- web_text_widget/static/src/js/text_limited.js | 60 +++++++++++-------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/web_text_widget/__openerp__.py b/web_text_widget/__openerp__.py index 164b3cd8..bdf6561f 100644 --- a/web_text_widget/__openerp__.py +++ b/web_text_widget/__openerp__.py @@ -21,20 +21,18 @@ ############################################################################## { 'name': 'Web text limited widget', - 'version': '0.1.0', + 'version': '7.0.1.0.0', 'author': 'initOS GmbH & Co. KG', - 'category': '', + 'category': 'web', 'description': """ -* Add new functionality for TextField, but data are limited to -10 lines or 500 characters (by default). -You can change default values by context varibles 'limit_lines' and -'limit_chars'. +* Add new functionality for TextField. +You can change default values by context varibles 'maxlines' and +'maxlength'. If data contains more characters or lines, it will be cut. Example of usage: """, 'website': 'http://www.initos.com', diff --git a/web_text_widget/static/src/js/text_limited.js b/web_text_widget/static/src/js/text_limited.js index c676d0ae..84f548b1 100644 --- a/web_text_widget/static/src/js/text_limited.js +++ b/web_text_widget/static/src/js/text_limited.js @@ -7,10 +7,8 @@ var _t = instance.web._t; instance.web.form.FieldText.include({ template: 'FieldText', - LIMIT_LINES_CONTEXT_KEY: 'limit_lines', - LIMIT_LINES_DEFAULT: 10, - LIMIT_CHARS_CONTEXT_KEY: 'limit_chars', - LIMIT_CHARS_DEFAULT: 500, + LIMIT_LINES_CONTEXT_KEY: 'maxlines', + LIMIT_CHARS_CONTEXT_KEY: 'maxlength', events: { 'keyup': function (e) { @@ -25,31 +23,45 @@ instance.web.form.FieldText.include({ limit_value: function($textarea) { var ctx = this.build_context().eval(); - var limit_lines = ctx[this.LIMIT_LINES_CONTEXT_KEY]*1 - if (!limit_lines){ - limit_lines = this.LIMIT_LINES_DEFAULT; - console.log("No default values found for limit lines in '" - + this.name + "' field. Default value " + limit_lines - + " will be used."); - } - - var limit_chars = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 - if (!limit_chars){ - limit_chars = this.LIMIT_CHARS_DEFAULT; - console.log("No default values found for limit chars in '" - + this.name + "' field. Default value " + limit_chars - + " will be used."); - } + var maxlines = ctx[this.LIMIT_LINES_CONTEXT_KEY]*1 + var maxlength = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 var value = $textarea.val(); var lines = value.split("\n"); - if (lines.length > limit_lines){ - $textarea.val(lines.slice(0, limit_lines).join("\n")); + + if (maxlines && lines.length > maxlines){ + $textarea.val(lines.slice(0, maxlines).join("\n")); } - if (value.length > limit_chars){ - $textarea.val(value.slice(0, limit_chars)); + if (maxlength && value.length > maxlength){ + $textarea.val(value.slice(0, maxlength)); + } + this.$el.find('span.length_limit').html(value.length + '/' + maxlength); + }, + +}); + +instance.web.form.FieldChar.include({ + template: 'FieldChar', + LIMIT_CHARS_CONTEXT_KEY: 'maxlength', + + events: { + 'keyup': function (e) { + this.limit_value($(e.target)); + }, + 'change textarea': 'store_dom_value', + }, + + limit_value: function($textarea) + { + var ctx = this.build_context().eval(); + var maxlength = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 + + var value = $textarea.val(); + + if (maxlength && value.length > maxlength){ + $textarea.val(value.slice(0, maxlength)); } - this.$el.find('span.length_limit').html(value.length + '/' + limit_chars); + this.$el.find('span.length_limit').html(value.length + '/' + maxlength); }, }); From 79254f1f2daadf0841f8de83b814b27a40848d1b Mon Sep 17 00:00:00 2001 From: Nikolina Todorova Date: Fri, 23 Oct 2015 09:03:13 +0200 Subject: [PATCH 4/7] Chnage company name --- web_text_widget/__init__.py | 2 +- web_text_widget/__openerp__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web_text_widget/__init__.py b/web_text_widget/__init__.py index 78003df6..4b46d480 100644 --- a/web_text_widget/__init__.py +++ b/web_text_widget/__init__.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # Copyright (C) 2010-2015 OpenERP s.a. (). -# Copyright (C) 2015 initOS GmbH & Co. KG (). +# Copyright (C) 2015 initOS GmbH (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/web_text_widget/__openerp__.py b/web_text_widget/__openerp__.py index bdf6561f..91ebd1f7 100644 --- a/web_text_widget/__openerp__.py +++ b/web_text_widget/__openerp__.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # Copyright (C) 2010-2015 OpenERP s.a. (). -# Copyright (C) 2015 initOS GmbH & Co. KG (). +# Copyright (C) 2015 initOS GmbH (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as From ecdb46e199eab3a1d5ddf9afd272eb050519f616 Mon Sep 17 00:00:00 2001 From: Nikolina Todorova Date: Fri, 23 Oct 2015 09:08:47 +0200 Subject: [PATCH 5/7] change company name --- web_text_widget/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_text_widget/__openerp__.py b/web_text_widget/__openerp__.py index 91ebd1f7..a0fa0832 100644 --- a/web_text_widget/__openerp__.py +++ b/web_text_widget/__openerp__.py @@ -22,7 +22,7 @@ { 'name': 'Web text limited widget', 'version': '7.0.1.0.0', - 'author': 'initOS GmbH & Co. KG', + 'author': 'initOS GmbH', 'category': 'web', 'description': """ From 517897231b377c91bde44c8b0372644146c01dae Mon Sep 17 00:00:00 2001 From: Nikolina Todorova Date: Fri, 8 Jan 2016 15:55:54 +0100 Subject: [PATCH 6/7] Change module name --- web_text_widget/__init__.py | 21 ------ web_text_widget/__openerp__.py | 59 ---------------- .../static/src/css/text_limited.css | 8 --- web_text_widget/static/src/js/text_limited.js | 68 ------------------- 4 files changed, 156 deletions(-) delete mode 100644 web_text_widget/__init__.py delete mode 100644 web_text_widget/__openerp__.py delete mode 100644 web_text_widget/static/src/css/text_limited.css delete mode 100644 web_text_widget/static/src/js/text_limited.js diff --git a/web_text_widget/__init__.py b/web_text_widget/__init__.py deleted file mode 100644 index 4b46d480..00000000 --- a/web_text_widget/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2010-2015 OpenERP s.a. (). -# Copyright (C) 2015 initOS GmbH (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## diff --git a/web_text_widget/__openerp__.py b/web_text_widget/__openerp__.py deleted file mode 100644 index a0fa0832..00000000 --- a/web_text_widget/__openerp__.py +++ /dev/null @@ -1,59 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2010-2015 OpenERP s.a. (). -# Copyright (C) 2015 initOS GmbH (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -{ - 'name': 'Web text limited widget', - 'version': '7.0.1.0.0', - 'author': 'initOS GmbH', - 'category': 'web', - 'description': """ - -* Add new functionality for TextField. -You can change default values by context varibles 'maxlines' and -'maxlength'. -If data contains more characters or lines, it will be cut. -Example of usage: - -""", - 'website': 'http://www.initos.com', - 'license': 'AGPL-3', - 'images': [], - 'depends': [ - 'web', - ], - 'data': [], - 'update_xml': [], - 'js': [ - 'static/src/js/text_limited.js', - ], - 'qweb': [ - ], - 'css': [ - 'static/src/css/text_limited.css', - ], - 'demo': [], - 'test': [], - 'active': False, - 'installable': True, - 'auto_install': True, -} diff --git a/web_text_widget/static/src/css/text_limited.css b/web_text_widget/static/src/css/text_limited.css deleted file mode 100644 index c01c56bd..00000000 --- a/web_text_widget/static/src/css/text_limited.css +++ /dev/null @@ -1,8 +0,0 @@ -div.oe_form_field.oe_form_field_text { - position: relative; -} - -span.length_limit { - position: absolute; - right: 0; -} diff --git a/web_text_widget/static/src/js/text_limited.js b/web_text_widget/static/src/js/text_limited.js deleted file mode 100644 index 84f548b1..00000000 --- a/web_text_widget/static/src/js/text_limited.js +++ /dev/null @@ -1,68 +0,0 @@ -openerp.web_text_widget = function (instance) -{ - -var QWeb = instance.web.qweb; -var _t = instance.web._t; - - -instance.web.form.FieldText.include({ - template: 'FieldText', - LIMIT_LINES_CONTEXT_KEY: 'maxlines', - LIMIT_CHARS_CONTEXT_KEY: 'maxlength', - - events: { - 'keyup': function (e) { - if (e.which === $.ui.keyCode.ENTER) { - e.stopPropagation(); - } - this.limit_value($(e.target)); - }, - 'change textarea': 'store_dom_value', - }, - - limit_value: function($textarea) - { - var ctx = this.build_context().eval(); - var maxlines = ctx[this.LIMIT_LINES_CONTEXT_KEY]*1 - var maxlength = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 - - var value = $textarea.val(); - var lines = value.split("\n"); - - if (maxlines && lines.length > maxlines){ - $textarea.val(lines.slice(0, maxlines).join("\n")); - } - if (maxlength && value.length > maxlength){ - $textarea.val(value.slice(0, maxlength)); - } - this.$el.find('span.length_limit').html(value.length + '/' + maxlength); - }, - -}); - -instance.web.form.FieldChar.include({ - template: 'FieldChar', - LIMIT_CHARS_CONTEXT_KEY: 'maxlength', - - events: { - 'keyup': function (e) { - this.limit_value($(e.target)); - }, - 'change textarea': 'store_dom_value', - }, - - limit_value: function($textarea) - { - var ctx = this.build_context().eval(); - var maxlength = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 - - var value = $textarea.val(); - - if (maxlength && value.length > maxlength){ - $textarea.val(value.slice(0, maxlength)); - } - this.$el.find('span.length_limit').html(value.length + '/' + maxlength); - }, - -}); -} \ No newline at end of file From d3bc12696a23dfd34b89f8988b20cf72f9fcba5f Mon Sep 17 00:00:00 2001 From: Nikolina Todorova Date: Fri, 8 Jan 2016 16:02:14 +0100 Subject: [PATCH 7/7] Change module name --- web_widget_fieldtext_options/__init__.py | 21 ++++++ web_widget_fieldtext_options/__openerp__.py | 59 ++++++++++++++++ .../static/src/css/text_limited.css | 8 +++ .../static/src/js/text_limited.js | 68 +++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 web_widget_fieldtext_options/__init__.py create mode 100644 web_widget_fieldtext_options/__openerp__.py create mode 100644 web_widget_fieldtext_options/static/src/css/text_limited.css create mode 100644 web_widget_fieldtext_options/static/src/js/text_limited.js diff --git a/web_widget_fieldtext_options/__init__.py b/web_widget_fieldtext_options/__init__.py new file mode 100644 index 00000000..4b46d480 --- /dev/null +++ b/web_widget_fieldtext_options/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2015 OpenERP s.a. (). +# Copyright (C) 2015 initOS GmbH (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## diff --git a/web_widget_fieldtext_options/__openerp__.py b/web_widget_fieldtext_options/__openerp__.py new file mode 100644 index 00000000..a0fa0832 --- /dev/null +++ b/web_widget_fieldtext_options/__openerp__.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2015 OpenERP s.a. (). +# Copyright (C) 2015 initOS GmbH (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Web text limited widget', + 'version': '7.0.1.0.0', + 'author': 'initOS GmbH', + 'category': 'web', + 'description': """ + +* Add new functionality for TextField. +You can change default values by context varibles 'maxlines' and +'maxlength'. +If data contains more characters or lines, it will be cut. +Example of usage: + +""", + 'website': 'http://www.initos.com', + 'license': 'AGPL-3', + 'images': [], + 'depends': [ + 'web', + ], + 'data': [], + 'update_xml': [], + 'js': [ + 'static/src/js/text_limited.js', + ], + 'qweb': [ + ], + 'css': [ + 'static/src/css/text_limited.css', + ], + 'demo': [], + 'test': [], + 'active': False, + 'installable': True, + 'auto_install': True, +} diff --git a/web_widget_fieldtext_options/static/src/css/text_limited.css b/web_widget_fieldtext_options/static/src/css/text_limited.css new file mode 100644 index 00000000..c01c56bd --- /dev/null +++ b/web_widget_fieldtext_options/static/src/css/text_limited.css @@ -0,0 +1,8 @@ +div.oe_form_field.oe_form_field_text { + position: relative; +} + +span.length_limit { + position: absolute; + right: 0; +} diff --git a/web_widget_fieldtext_options/static/src/js/text_limited.js b/web_widget_fieldtext_options/static/src/js/text_limited.js new file mode 100644 index 00000000..83d4c768 --- /dev/null +++ b/web_widget_fieldtext_options/static/src/js/text_limited.js @@ -0,0 +1,68 @@ +openerp.web_widget_fieldtext_options = function (instance) +{ + +var QWeb = instance.web.qweb; +var _t = instance.web._t; + + +instance.web.form.FieldText.include({ + template: 'FieldText', + LIMIT_LINES_CONTEXT_KEY: 'maxlines', + LIMIT_CHARS_CONTEXT_KEY: 'maxlength', + + events: { + 'keyup': function (e) { + if (e.which === $.ui.keyCode.ENTER) { + e.stopPropagation(); + } + this.limit_value($(e.target)); + }, + 'change textarea': 'store_dom_value', + }, + + limit_value: function($textarea) + { + var ctx = this.build_context().eval(); + var maxlines = ctx[this.LIMIT_LINES_CONTEXT_KEY]*1 + var maxlength = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 + + var value = $textarea.val(); + var lines = value.split("\n"); + + if (maxlines && lines.length > maxlines){ + $textarea.val(lines.slice(0, maxlines).join("\n")); + } + if (maxlength && value.length > maxlength){ + $textarea.val(value.slice(0, maxlength)); + } + this.$el.find('span.length_limit').html(value.length + '/' + maxlength); + }, + +}); + +instance.web.form.FieldChar.include({ + template: 'FieldChar', + LIMIT_CHARS_CONTEXT_KEY: 'maxlength', + + events: { + 'keyup': function (e) { + this.limit_value($(e.target)); + }, + 'change textarea': 'store_dom_value', + }, + + limit_value: function($textarea) + { + var ctx = this.build_context().eval(); + var maxlength = ctx[this.LIMIT_CHARS_CONTEXT_KEY]*1 + + var value = $textarea.val(); + + if (maxlength && value.length > maxlength){ + $textarea.val(value.slice(0, maxlength)); + } + this.$el.find('span.length_limit').html(value.length + '/' + maxlength); + }, + +}); +} \ No newline at end of file