Browse Source

New module 'web_one2many_list_action'

+ Enable tree_but_open interface to be used for list views embedded into
form views for one2many relational fields.
pull/326/head
Peter Hahn 9 years ago
parent
commit
2844a62a3d
  1. 85
      web_one2many_list_action/README.rst
  2. 1
      web_one2many_list_action/__init__.py
  3. 19
      web_one2many_list_action/__openerp__.py
  4. 10
      web_one2many_list_action/assets.xml
  5. BIN
      web_one2many_list_action/static/description/icon.png
  6. 42
      web_one2many_list_action/static/src/js/views.js

85
web_one2many_list_action/README.rst

@ -0,0 +1,85 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
========================
Web One2many List Action
========================
This module extends the list view used for one2many fields inside form views to
use the 'tree_but_open' interface to define actions for rows.
To use this just specify a 'tree_but_open' action on the target model of the
one2many field relation.
Example
::
<!-- server action retrieves ir.actions.act_window to open row specific popup -->
<record model="ir.actions.server" id="message_index_list_view_delegate_open">
<field name="name">message_index_list_view_delegate_open</field>
<field name="model_id" ref="model_message_index"/>
<field name="code">action = object.button_popup_delegate()</field>
</record>
<!-- tree_but_open key -- delegates to a server action to execute on row clicked -->
<record id="message_index_list_view_open" model="ir.values">
<field name="model">message.index</field>
<field name="key2">tree_but_open</field>
<field name="name">message_index_list_view</field>
<field eval="'ir.actions.server,%d'%message_index_list_view_delegate_open" name="value"/>
<field name="res_id" eval="0"/>
</record>
Installation
============
To install this module, just follow basic steps to install an Odoo module.
Configuration
=============
No configuration needed.
Usage
=====
To use this module, you need to:
* go to ...
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/web/8.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/web/issues/new?body=module:web_one2many_list_actionversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Peter Hahn <peter.hahn@initos.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 https://odoo-community.org.

1
web_one2many_list_action/__init__.py

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

19
web_one2many_list_action/__openerp__.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
{
'name': 'web_one2many_list_action',
'summary': 'Enable tree_but_open action for One2ManyListView rows.',
'version': '8.0.1.0.0',
'author': 'initOS GmbH, Odoo Community Association (OCA)',
'license': 'AGPL-3',
'application': False,
'installable': True,
'auto_install': False,
'depends': [
'web',
],
'data': [
'assets.xml',
],
'images': [],
}

10
web_one2many_list_action/assets.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_one2many_list_action/static/src/js/views.js"></script>
</xpath>
</template>
</data>
</openerp>

BIN
web_one2many_list_action/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

42
web_one2many_list_action/static/src/js/views.js

@ -0,0 +1,42 @@
/*global openerp, _, $ */
openerp.web_one2many_list_action = function (instance) {
instance.web.form.One2ManyListView.include({
do_activate_record: function(index, id) {
var self = this;
var _func = self._super
var _args = arguments
var local_context = {
active_model: self.o2m.field.relation,
active_id: id,
active_ids: [id]
};
var ctx = instance.web.pyeval.eval(
'context', new instance.web.CompoundContext(
self.o2m.build_context(), local_context));
this.rpc('/web/treeview/action', {
id: id,
model: self.o2m.field.relation,
context: ctx
}).then(function (actions) {
if (actions.length) {
// execute action
var action = actions[0][2];
var c = new instance.web.CompoundContext(local_context).set_eval_context(ctx);
if (action.context) {
c.add(action.context);
}
action.context = c;
self.do_action(action);
} else {
// if no action configured apply default behaviour
_func.apply(self, _args);
}
});
},
});
}
Loading…
Cancel
Save