Browse Source

7.0 add web text widget

pull/218/head
Nikolina Todorova 9 years ago
parent
commit
23caf567db
  1. 21
      web_text_widget/__init__.py
  2. 62
      web_text_widget/__openerp__.py
  3. 8
      web_text_widget/static/src/css/text_limited.css
  4. 68
      web_text_widget/static/src/js/text_limited.js
  5. 8
      web_text_widget/static/src/xml/text_limited.xml

21
web_text_widget/__init__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2015 OpenERP s.a. (<http://openerp.com>).
# Copyright (C) 2015 initOS GmbH & Co. KG (<http://www.initos.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################

62
web_text_widget/__openerp__.py

@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2015 OpenERP s.a. (<http://openerp.com>).
# Copyright (C) 2015 initOS GmbH & Co. KG (<http://www.initos.com>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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:
<field name="some_text_field"
widget="text_limited"
context="{'limit_lines': 8, 'limit_chars': 400}"
/>
""",
'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,
}

8
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;
}

68
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');
};

8
web_text_widget/static/src/xml/text_limited.xml

@ -0,0 +1,8 @@
<?xml version='1.0' encoding='UTF-8' ?>
<templates id="template" xml:space="preserve">
<t t-extend="FieldText">
<t t-jquery=".oe_form_field_text" t-operation="append">
<span class="length_limit"></span>
</t>
</t>
</templates>
Loading…
Cancel
Save