Browse Source

fix: obscur wrong path on last commit. recreate portage from scratch.

pull/69/head
Nicolas JEUDY 10 years ago
parent
commit
ad7b019620
  1. 46
      __unported__/web_m2x_options/__openerp__.py
  2. 36
      web_m2x_options/README.rst
  3. 0
      web_m2x_options/__init__.py
  4. 14
      web_m2x_options/__openerp__.py
  5. 33
      web_m2x_options/static/description/index.html
  6. 78
      web_m2x_options/static/src/js/form.js
  7. 12
      web_m2x_options/views/view.xml

46
__unported__/web_m2x_options/__openerp__.py

@ -1,46 +0,0 @@
# -*- coding: utf-8 -*-
{
"name": 'web_m2x_options',
"version": "0.1",
"description":
"""
=====================================================
Add new options for many2one and many2manytags field:
=====================================================
- create: true/false -> disable "create" entry in dropdown panel
- create_edit: true/false -> disable "create and edit" entry in dropdown panel
- limit: 10 (int) -> change number of selected record return in dropdown panel
- m2o_dialog: true/false -> disable quick create M20Dialog triggered on error.
Example:
--------
<field name="partner_id" options="{'limit': 10, 'create': false, 'create_edit': false}"/>
Note:
-----
if one of those options are not set, many2one field use default many2one field options.
Thanks to:
----------
- Nicolas JEUDY <njeudy@tuxservices.com>
- Valentin LAB <valentin.lab@kalysto.org>
""",
"depends": [
'base',
'web',
],
"js": [
'static/src/js/form.js',
],
"author": "Tuxservices",
'installable' : False,
"active" : False,
}

36
__unported__/web_m2x_options/README.rst → web_m2x_options/README.rst

@ -6,10 +6,12 @@ Add new options for many2one field
Description
-----------
This modules modifies "many2one" form fields so as to add some new display
This modules modifies "many2one" and "many2manytags" form widgets so as to add some new display
control options.
** New: support many2manytags widget ! **
**New: support many2manytags widget !**
**New: support global option management with ir.config_parameter !**
Options provided includes possibility to remove "Create..." and/or "Create and
Edit..." entries from many2one drop down. You can also change default number of
@ -23,11 +25,11 @@ if the current user have no permission rights to create the related object.
Requirements
------------
Was tested on openerp v7.0
Was tested on openerp 8.0, trunk, saas-5 branch. New way to import js file. (thanks to tfossoul)
New option
----------
New options
-----------
``create`` *boolean* (Default: depends if user have create rights)
@ -45,6 +47,30 @@ 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 record 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
-------

0
__unported__/web_m2x_options/__init__.py → web_m2x_options/__init__.py

14
web_m2x_options/__openerp__.py

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
{
"name": 'web_m2x_options',
"version": "0.1",
"depends": [
'base',
'web',
],
'data': ['views/view.xml'],
"author": "0k.io",
"installable": True,
"active": False,
}

33
__unported__/web_m2x_options/static/description/index.html → web_m2x_options/static/description/index.html

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.11: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
<title>Add new options for many2one field</title>
<style type="text/css">
@ -343,9 +343,10 @@ ul.auto-toc {
<div class="section" id="description">
<h1>Description</h1>
<p>This modules modifies &quot;many2one&quot; form fields so as to add some new display
<p>This modules modifies &quot;many2one&quot; and &quot;many2manytags&quot; form widgets so as to add some new display
control options.</p>
<p>** New: support many2manytags widget ! **</p>
<p><strong>New: support many2manytags widget !</strong></p>
<p><strong>New: support global option management with ir.config_parameter !</strong></p>
<p>Options provided includes possibility to remove &quot;Create...&quot; and/or &quot;Create and
Edit...&quot; 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
@ -355,10 +356,10 @@ if the current user have no permission rights to create the related object.</p>
</div>
<div class="section" id="requirements">
<h1>Requirements</h1>
<p>Was tested on openerp v7.0</p>
<p>Was tested on openerp 8.0, trunk, saas-5 branch. New way to import js file. (thanks to tfossoul)</p>
</div>
<div class="section" id="new-option">
<h1>New option</h1>
<div class="section" id="new-options">
<h1>New options</h1>
<p><tt class="docutils literal">create</tt> <em>boolean</em> (Default: depends if user have create rights)</p>
<blockquote>
Whether to display the &quot;Create...&quot; entry in dropdown panel.</blockquote>
@ -372,6 +373,26 @@ Whether to display the many2one dialog in case of validation error.</blockquote>
<blockquote>
Number of displayed record in drop-down panel</blockquote>
</div>
<div class="section" id="ir-config-parameter-options">
<h1>ir.config_parameter options</h1>
<p>Now you can disable &quot;Create...&quot; and &quot;Create and Edit...&quot; entry for all widgets in the odoo instance.
If you disable one option, you can enable it for particular field by setting &quot;create: True&quot; option directly on the field definition.</p>
<p><tt class="docutils literal">web_m2x_options.create</tt> <em>boolean</em> (Default: depends if user have create rights)</p>
<blockquote>
Whether to display the &quot;Create...&quot; entry in dropdown panel for all fields in the odoo instance.</blockquote>
<p><tt class="docutils literal">web_m2x_options.create_edit</tt> <em>boolean</em> (Default: depends if user have create rights)</p>
<blockquote>
Whether to display &quot;Create and Edit...&quot; entry in dropdown panel for all fields in the odoo instance.</blockquote>
<p><tt class="docutils literal">web_m2x_options.limit</tt> <em>int</em> (Default: openerp default value is <tt class="docutils literal">7</tt>)</p>
<blockquote>
Number of displayed record in drop-down panel for all fields in the odoo instance</blockquote>
<p>To add these parameters go to Configuration -&gt; Technical -&gt; Parameters -&gt; System Parameters and add new parameters like:</p>
<ul class="simple">
<li>web_m2x_options.create: False</li>
<li>web_m2x_options.create_edit: False</li>
<li>web_m2x_options.limit: 10</li>
</ul>
</div>
<div class="section" id="example">
<h1>Example</h1>
<p>Your XML form view definition could contain:</p>

78
__unported__/web_m2x_options/static/src/js/form.js → web_m2x_options/static/src/js/form.js

@ -8,9 +8,36 @@ 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({
show_error_displayer: function () {
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) {
new instance.web.form.M2ODialog(this).open();
@ -18,11 +45,15 @@ openerp.web_m2x_options = function (instance) {
},
get_search_result: function (search_val) {
var def = $.Deferred();
var self = this;
// 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;
@ -47,10 +78,7 @@ openerp.web_m2x_options = function (instance) {
"check_access_rights", ["create", false]);
}
$.when(search_result, create_rights).then(function (_data, _can_create) {
var data = _data[0];
var can_create = _can_create ? _can_create[0] : null;
$.when(search_result, create_rights).then(function (data, can_create) {
self.can_create = can_create; // for ``.show_error_displayer()``
self.last_search = data;
@ -88,7 +116,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 &&
@ -108,7 +137,8 @@ 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 +168,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 +200,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 +242,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];});
@ -204,7 +261,8 @@ 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({

12
web_m2x_options/views/view.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
<data>
<template id="assets_backend" name="m2x options assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_m2x_options/static/src/js/form.js"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save