描述
简而言之,客户端操作通过注册一组小部件来绑定特定操作。
从服务器的角度来看,客户端操作只是保存在 ir_action 模型中的一条记录;从 Web 客户端的角度来看,它是一个继承自 AbstractAction 类的控件。
在使用客户端操作之前,您需要在注册表中注册它们 (core.action_registry.add(’’, ‘’))
var AbstractAction = require('web.AbstractAction');
var core = require('web.core');
var TongjiPage = AbstractAction.extend({
template: 'MainTongjiPage',
init: function(){
return this._super.apply(this, arguments);
},
}),
客户操作登记
首先,我们需要 Web 客户端与 TongjiPage 之间的映射
core.action_registry.add('tongji.page.main', TongjiPage);
然后,我们需要在 ir.actions.client 中定义一个带有 tag 属性 tongji.page.main 的记录
<record id="action_tongji_page" model="ir.actions.client">
<field name="name">统计</field>
<field name="tag">tongji.page.main</field>
</record>
## 控制面板(ControlPanelMixin)所以问题是,什么是控制面板?
如下所示的红框区域 ↓↓↓
那么,我们如何将 Odoo 的默认控制面板添加到我们的自定义界面中呢?首先,重要的是要了解默认的 AbstractAction 类不支持控制面板。
为新 Widget 添加控制面板的格式如下:
var ControlPanelMixin = require('web.ControlPanelMixin');
var TongjiPage = AbstractAction.extend(ControlPanelMixin, {
template: 'MainTongjiPage',
init: function(){
return this._super.apply(this, arguments);
},
}),
每次更新控制面板时,都需要调用 _updateControlPanel 方法(官方示例):
var SomeClientAction = Widget.extend(ControlPanelMixin, {
...
start: function () {
this._renderButtons();
this._updateControlPanel();
...
},
do_show: function () {
...
this._updateControlPanel();
},
_renderButtons: function () {
this.$buttons = $(QWeb.render('SomeTemplate.Buttons'));
this.$buttons.on('click', ...);
},
_updateControlPanel: function () {
this.update_control_panel({
cp_content: {
$buttons: this.$buttons,
},
});
