Merge branch '7.0' of https://github.com/OCA/web into 7.0-web_dashboard_tile-improve
|
@ -19,6 +19,7 @@
|
|||
#
|
||||
##############################################################################
|
||||
import time
|
||||
import json
|
||||
from openerp.osv.orm import TransientModel
|
||||
from openerp.osv import fields, expression
|
||||
from openerp.tools.safe_eval import safe_eval
|
||||
|
@ -41,7 +42,7 @@ class IrFiltersCombineWithExisting(TransientModel):
|
|||
def button_save(self, cr, uid, ids, context=None):
|
||||
assert len(ids) == 1
|
||||
this = self.browse(cr, uid, ids[0], context=context)
|
||||
domain = safe_eval(this.domain)
|
||||
domain = json.loads(this.domain)
|
||||
is_frozen = (len(domain) == 1 and
|
||||
expression.is_leaf(domain[0]) and
|
||||
domain[0][0] == 'id')
|
||||
|
|
|
@ -6,15 +6,17 @@ Add new options for many2one field
|
|||
Description
|
||||
-----------
|
||||
|
||||
This modules modifies "many2one" form fields so as to add some new display
|
||||
control options.
|
||||
This module changes "many2one" and "many2manytags" form widgets, so as to
|
||||
add some new display control options.
|
||||
|
||||
** New: support many2manytags widget ! **
|
||||
|
||||
Options provided includes possibility to remove "Create..." and/or "Create and
|
||||
Edit..." entries from many2one drop down. You can also change default number of
|
||||
proposition appearing in the drop-down. Or prevent the dialog box poping in
|
||||
case of validation error.
|
||||
** New: support global option management with ir.config_parameter ! **
|
||||
|
||||
The options provided include the possibility to remove "Create..." and/or
|
||||
"Create and Edit..." entries from many2one and many2many drop down lists. You
|
||||
can also change the default number of entries appearing in the drop-down, or
|
||||
prevent the dialog box poping in case of validation error occurring.
|
||||
|
||||
If not specified, the module will avoid proposing any of the create options
|
||||
if the current user have no permission rights to create the related object.
|
||||
|
@ -46,6 +48,31 @@ New option
|
|||
Number of displayed record in drop-down panel
|
||||
|
||||
|
||||
ir.config_parameter options
|
||||
---------------------------
|
||||
|
||||
Now you can disable "Create..." and "Create and Edit..." entry for all widgets in the odoo instance.
|
||||
If you disable one option, you can enable it for particular field by setting "create: True" option directly on the field definition.
|
||||
|
||||
``web_m2x_options.create`` *boolean* (Default: depends if user have create rights)
|
||||
|
||||
Whether to display the "Create..." entry in dropdown panel for all fields in the odoo instance.
|
||||
|
||||
``web_m2x_options.create_edit`` *boolean* (Default: depends if user have create rights)
|
||||
|
||||
Whether to display "Create and Edit..." entry in dropdown panel for all fields in the odoo instance.
|
||||
|
||||
``web_m2x_options.limit`` *int* (Default: openerp default value is ``7``)
|
||||
|
||||
Number of displayed records in drop-down panel for all fields in the odoo instance
|
||||
|
||||
To add these parameters go to Configuration -> Technical -> Parameters -> System Parameters and add new parameters like:
|
||||
|
||||
- web_m2x_options.create: False
|
||||
- web_m2x_options.create_edit: False
|
||||
- web_m2x_options.limit: 10
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
|
@ -59,5 +86,5 @@ Note
|
|||
----
|
||||
|
||||
Double check that you have no inherited view that remote ``options`` you set on a field !
|
||||
If nothing work, add a debugger in the first ligne of ``get_search_result method`` and enable debug mode in OpenERP. When you write something in a many2one field, javascript debugger should pause. If not verify your installation.
|
||||
If nothing work, add a debugger in the first line of ``get_search_result`` method and enable debug mode in OpenERP. When you write something in a many2one field, javascript debugger should pause. If not verify your installation.
|
||||
|
||||
|
|
|
@ -8,8 +8,35 @@ openerp.web_m2x_options = function (instance) {
|
|||
_t = instance.web._t,
|
||||
_lt = instance.web._lt;
|
||||
|
||||
var OPTIONS = ['web_m2x_options.create',
|
||||
'web_m2x_options.create_edit',
|
||||
'web_m2x_options.limit',];
|
||||
|
||||
instance.web.form.FieldMany2One.include({
|
||||
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
return this.get_options();
|
||||
},
|
||||
|
||||
get_options: function() {
|
||||
var self = this;
|
||||
if (!_.isUndefined(this.view) && _.isUndefined(this.view.ir_options_loaded)) {
|
||||
this.view.ir_options_loaded = $.Deferred();
|
||||
this.view.ir_options = {};
|
||||
(new instance.web.Model("ir.config_parameter"))
|
||||
.query(["key", "value"]).filter([['key', 'in', OPTIONS]])
|
||||
.all().then(function(records) {
|
||||
_(records).each(function(record) {
|
||||
self.view.ir_options[record.key] = record.value;
|
||||
});
|
||||
self.view.ir_options_loaded.resolve();
|
||||
});
|
||||
return this.view.ir_options_loaded;
|
||||
}
|
||||
return $.when();
|
||||
},
|
||||
|
||||
show_error_displayer: function () {
|
||||
if ((typeof this.options.m2o_dialog === 'undefined' && this.can_create) ||
|
||||
this.options.m2o_dialog) {
|
||||
|
@ -24,6 +51,12 @@ openerp.web_m2x_options = function (instance) {
|
|||
// add options limit used to change number of selections record
|
||||
// returned.
|
||||
|
||||
if (_.isUndefined(this.view))
|
||||
return this._super.apply(this, arguments);
|
||||
if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) {
|
||||
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']);
|
||||
}
|
||||
|
||||
if (typeof this.options.limit === 'number') {
|
||||
this.limit = this.options.limit;
|
||||
}
|
||||
|
@ -65,7 +98,7 @@ openerp.web_m2x_options = function (instance) {
|
|||
};
|
||||
});
|
||||
|
||||
// search more... if more results that max
|
||||
// search more... if more results than max
|
||||
|
||||
if (values.length > self.limit) {
|
||||
values = values.slice(0, self.limit);
|
||||
|
@ -88,7 +121,8 @@ openerp.web_m2x_options = function (instance) {
|
|||
return x[1];
|
||||
});
|
||||
|
||||
if ((typeof self.options.create === 'undefined' && can_create) ||
|
||||
if ((_.isUndefined(self.options.create) && _.isUndefined(self.view.ir_options['web_m2x_options.create']) && can_create) ||
|
||||
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create'] == "True") ||
|
||||
self.options.create) {
|
||||
|
||||
if (search_val.length > 0 &&
|
||||
|
@ -106,9 +140,11 @@ openerp.web_m2x_options = function (instance) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// create...
|
||||
|
||||
if ((typeof self.options.create_edit === 'undefined' && can_create) ||
|
||||
if ((_.isUndefined(self.options.create_edit) && _.isUndefined(self.view.ir_options['web_m2x_options.create_edit']) && can_create) ||
|
||||
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create_edit'] == "True") ||
|
||||
self.options.create_edit) {
|
||||
|
||||
values.push({
|
||||
|
@ -138,6 +174,28 @@ openerp.web_m2x_options = function (instance) {
|
|||
}
|
||||
},
|
||||
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
return this.get_options();
|
||||
},
|
||||
|
||||
get_options: function() {
|
||||
var self = this;
|
||||
if (_.isUndefined(this.view.ir_options_loaded)) {
|
||||
this.view.ir_options_loaded = $.Deferred();
|
||||
this.view.ir_options = {};
|
||||
(new instance.web.Model("ir.config_parameter"))
|
||||
.query(["key", "value"]).filter([['key', 'in', OPTIONS]])
|
||||
.all().then(function(records) {
|
||||
_(records).each(function(record) {
|
||||
self.view.ir_options[record.key] = record.value;
|
||||
});
|
||||
self.view.ir_options_loaded.resolve();
|
||||
});
|
||||
}
|
||||
return this.view.ir_options_loaded;
|
||||
},
|
||||
|
||||
/**
|
||||
* Call this method to search using a string.
|
||||
*/
|
||||
|
@ -148,6 +206,10 @@ openerp.web_m2x_options = function (instance) {
|
|||
// add options limit used to change number of selections record
|
||||
// returned.
|
||||
|
||||
if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) {
|
||||
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']);
|
||||
}
|
||||
|
||||
if (typeof this.options.limit === 'number') {
|
||||
this.limit = this.options.limit;
|
||||
}
|
||||
|
@ -186,7 +248,8 @@ openerp.web_m2x_options = function (instance) {
|
|||
}
|
||||
// quick create
|
||||
|
||||
if ((typeof self.options.create === 'undefined') ||
|
||||
if ((_.isUndefined(self.options.create) && _.isUndefined(self.view.ir_options['web_m2x_options.create'])) ||
|
||||
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create'] == 'True') ||
|
||||
self.options.create) {
|
||||
|
||||
var raw_result = _(data.result).map(function(x) {return x[1];});
|
||||
|
@ -201,10 +264,10 @@ openerp.web_m2x_options = function (instance) {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
// create...
|
||||
|
||||
if ((typeof self.options.create_edit === 'undefined') ||
|
||||
if ((_.isUndefined(self.options.create_edit === 'undefined') && _.isUndefined(self.view.ir_options['web_m2x_options.create_edit'])) ||
|
||||
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create_edit'] == 'True') ||
|
||||
self.options.create_edit) {
|
||||
|
||||
values.push({
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
############################################################################
|
||||
#
|
||||
# Odoo, Open Source Web Color
|
||||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
|
||||
# Copyright (C) 2014 Anybox <http://anybox.fr>
|
||||
# Copyright (C) 2015 Taktik SA <http://taktik.be>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU 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 General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @author Étienne Beaudry Auger <etienne.b.auger@savoirfairelinux.com>
|
||||
# @author Adil Houmadi <ah@taktik.be>
|
||||
#
|
||||
##############################################################################
|
|
@ -0,0 +1,140 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
############################################################################
|
||||
#
|
||||
# Odoo, Open Source Web Widget Color
|
||||
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
|
||||
# Copyright (C) 2014 Anybox <http://anybox.fr>
|
||||
# Copyright (C) 2015 Taktik SA <http://taktik.be>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU 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 General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# @author Étienne Beaudry Auger <etienne.b.auger@savoirfairelinux.com>
|
||||
# @author Adil Houmadi <ah@taktik.be>
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
'name': "Web Widget Color",
|
||||
'category': "web",
|
||||
'version': "1.0",
|
||||
'depends': ['base', 'web'],
|
||||
'description': '''
|
||||
Color widget for Odoo web client
|
||||
================================
|
||||
|
||||
This module aims to add a color picker to Odoo.
|
||||
|
||||
It's a `jsColor <http://jscolor.com/>`_ lib integration.
|
||||
|
||||
|
||||
Features
|
||||
========
|
||||
|
||||
* The picker allow the user to quickly select a color on edit mode
|
||||
|
||||
|picker|
|
||||
|
||||
.. note::
|
||||
|
||||
Notice how html code and the background color is updating when selecting
|
||||
a color.
|
||||
|
||||
|
||||
* Display the color on form view when you are not editing it
|
||||
|
||||
|formview|
|
||||
|
||||
* Display the color on list view to quickly find what's wrong!
|
||||
|
||||
|listview|
|
||||
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
||||
This module has been ported to 8.0
|
||||
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
You need to declare a char field of at least size 7::
|
||||
|
||||
_columns = {
|
||||
'color': fields.char(
|
||||
u"Couleur",
|
||||
help=u"Toutes couleur valid css, exemple blue ou #f57900"
|
||||
),
|
||||
}
|
||||
|
||||
OR
|
||||
|
||||
color = fields.Char(
|
||||
string="Color",
|
||||
help="Choose your color"
|
||||
)
|
||||
|
||||
|
||||
In the view declaration, put widget='color' attribute in the field tag::
|
||||
|
||||
...
|
||||
<field name="arch" type="xml">
|
||||
<tree string="View name">
|
||||
...
|
||||
<field name="name"/>
|
||||
<field name="color" widget="color"/>
|
||||
...
|
||||
</tree>
|
||||
</field>
|
||||
...
|
||||
|
||||
.. |picker| image:: /web_widget_color/static/src/img/picker.png
|
||||
.. |formview| image:: /web_widget_color/static/src/img/form_view.png
|
||||
.. |listview| image:: /web_widget_color/static/src/img/list_view.png
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Adil Houmadi <adil.houmadi@gmail.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: http://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: http://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit http://odoo-community.org.''',
|
||||
'qweb': [
|
||||
'static/src/xml/widget.xml',
|
||||
],
|
||||
'css': [
|
||||
'static/src/css/widget.css',
|
||||
],
|
||||
'js': [
|
||||
'static/lib/jscolor/jscolor.js',
|
||||
'static/src/js/widget.js',
|
||||
],
|
||||
'auto_install': False,
|
||||
'installable': True,
|
||||
'web_preload': True,
|
||||
}
|
After Width: | Height: | Size: 66 B |
After Width: | Height: | Size: 83 B |
|
@ -0,0 +1,12 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>jscolor demo</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript" src="jscolor.js"></script>
|
||||
|
||||
Click here: <input class="color" value="66ff00">
|
||||
|
||||
</body>
|
||||
</html>
|
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.8 KiB |
|
@ -0,0 +1,23 @@
|
|||
.openerp .oe_form .oe_form_field_color input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.openerp .oe_form .oe_form_field_color div {
|
||||
border: 1px solid;
|
||||
display: inline-block;
|
||||
height: 14px;
|
||||
margin-right: 10px;
|
||||
position: relative;
|
||||
top: 3px;
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.oe_list_field_color div {
|
||||
border: 1px solid;
|
||||
display: inline-block;
|
||||
height: 14px;
|
||||
margin-right: 10px;
|
||||
position: relative;
|
||||
top: 3px;
|
||||
width: 40px;
|
||||
}
|
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 5.9 KiB |
|
@ -0,0 +1,59 @@
|
|||
openerp.web_widget_color = function (instance) {
|
||||
|
||||
var _super_getDir = jscolor.getDir.prototype;
|
||||
jscolor.getDir = function () {
|
||||
var dir = _super_getDir.constructor();
|
||||
if (dir.indexOf('web_widget_color') === -1) {
|
||||
jscolor.dir = 'web_widget_color/static/lib/jscolor/';
|
||||
}
|
||||
return jscolor.dir;
|
||||
};
|
||||
|
||||
instance.web.form.widgets.add('color', 'instance.web.form.FieldColor');
|
||||
|
||||
instance.web.search.fields.add('color', 'instance.web.search.CharField');
|
||||
|
||||
instance.web.form.FieldColor = instance.web.form.FieldChar.extend({
|
||||
template: 'FieldColor',
|
||||
widget_class: 'oe_form_field_color',
|
||||
is_syntax_valid: function () {
|
||||
var $input = this.$('input');
|
||||
if (!this.get("effective_readonly") && $input.size() > 0) {
|
||||
var val = $input.val();
|
||||
var isOk = /^#[0-9A-F]{6}$/i.test(val);
|
||||
if (!isOk) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
this.parse_value(this.$('input').val(), '');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
render_value: function () {
|
||||
var show_value = this.format_value(this.get('value'), '');
|
||||
if (!this.get("effective_readonly")) {
|
||||
var $input = this.$el.find('input');
|
||||
$input.val(show_value);
|
||||
$input.css("background-color", show_value)
|
||||
jscolor.init(this.$el[0]);
|
||||
} else {
|
||||
this.$(".oe_form_char_content").text(show_value);
|
||||
this.$('div').css("background-color", show_value)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Init jscolor for each editable mode on view form
|
||||
*/
|
||||
instance.web.FormView.include({
|
||||
to_edit_mode: function () {
|
||||
this._super();
|
||||
jscolor.init(this.$el[0]);
|
||||
}
|
||||
});
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-name="FieldColor">
|
||||
<span t-att-class="'oe_form_field '+widget.widget_class" t-att-style="widget.node.attrs.style">
|
||||
<t t-if="!widget.get('effective_readonly')">
|
||||
<input type="text"
|
||||
t-att-id="widget.id_for_label"
|
||||
t-att-tabindex="widget.node.attrs.tabindex"
|
||||
t-att-autofocus="widget.node.attrs.autofocus"
|
||||
t-att-placeholder="widget.node.attrs.placeholder"
|
||||
t-att-maxlength="widget.field.size"
|
||||
class="color {hash:true}"
|
||||
/>
|
||||
</t>
|
||||
<t t-if="widget.get('effective_readonly')">
|
||||
<div/>
|
||||
<span class="oe_form_char_content"></span>
|
||||
</t>
|
||||
</span>
|
||||
</t>
|
||||
<tr t-extend="ListView.row">
|
||||
<t t-jquery="t td t" t-operation="replace"><t t-if="column.widget =='color' || column.type == 'color'"><div t-att-style="'background-color:' + render_cell(record, column)"/></t><t t-raw="render_cell(record, column)"/></t>
|
||||
</tr>
|
||||
</templates>
|