• odoo javascript参考(八)


    list.many2one (ListFieldMany2One)
    list(tree)视图专用。
    特定用于LIST视图的many2one 字段,主要的原因是需要渲染 many2one字段(在只读模式)为一个text,且不允许打开相关的记录。
    支持的字段类型: many2one
    many2one_barcode (FieldMany2OneBarcode)
    Widget允许从移动设备(Android/iOS)打开摄像头来扫描条形码。
    允许用户使用本机摄像机扫描条形码。然后使用name_search来搜索该值。
    如果设置了此widget且用户未使用移动应用程序,则它将退回到常规ManyOne(FieldManyOne)
    支持的字段类型: many2one
    在这里插入图片描述
    many2one_avatar (Many2OneAvatar) avatar:化身
    这个 widget 只支持many2one 字段。 指向从“image.mixin”继承的模型.在只读模式下, 显示image在它的display_name旁边。 注意,在这种情况下,display_name不支持点击链接. 在编辑模式下, 它与常规的 many2one用法完全一致.
    支持的字段类型: many2one
    在这里插入图片描述
    many2one_avatar_user (Many2OneAvatarUser)
    这个widget是ManyOneAvatar的特殊用法. 点击它时, 会弹出对话窗口. 该 widget 只能设置在 many2one 字段且指向 ‘res.users’ model.

    支持的字段类型: many2one (指向 ‘res.users’)
    在这里插入图片描述
    效果:
    在这里插入图片描述
    点击头像,弹出对话窗口:
    在这里插入图片描述
    many2one_avatar_employee (Many2OneAvatarEmployee)
    类似Many2OneAvatarUser, 不过是针对 many2one 字段指向 ‘hr.employee’.
    支持的字段类型 many2one (指向 ‘hr.employee’)
    kanban.many2one (KanbanFieldMany2One)
    针对many2one 字段 (看板视图). 我们需要禁用看板视图中的所有编辑
    支持的字段类型: many2one
    many2many (FieldMany2Many)
    针对 many2many 字段.
    支持的字段类型: many2many
    属性:
    mode: 字符, 要显示的默认视图
    domain:按domain筛选数据
    选项:
    create_text:允许自定义添加新记录时显示的文本
    link: 确定是否可以将记录添加到关系的域(默认值:True)。
    unlink: 确定是否可以从关系中删除记录的域(默认值:True)。
    many2many_binary (FieldMany2ManyBinaryMultiFiles)
    这个widget帮助用户同时上传或删除一个或多个文件
    注意,此widget特定指向 ‘ir.attachment’.
    支持的字段类型: many2many
    选项:
    accepted_file_extensions: 用户可以从“文件输入”对话框中选择的文件扩展名(cf:accept属性on)
    many2many_tags (FieldMany2ManyTags)
    显示多个标签列表.
    支持的字段类型: many2many:
    选项:

    • create: 由domain决定是否可以创建新标记(默认值:True).
    <field name="category_id" widget="many2many_tags" options="{'create': [['some_other_field', '>', 24]]}"/>
    
    • 1
    • color_field: 数值字段的名称,应显示在视图中。将根据其值选择颜色.
    <field name="category_id" widget="many2many_tags" options="{'color_field': 'color'}"/>
    
    • 1

    在这里插入图片描述

    • no_edit_color: 设置为True以消除更改标记颜色的可能性(默认值:False).
    <field name="category_id" widget="many2many_tags" options="{'color_field': 'color', 'no_edit_color': True}"/>
    
    • 1

    在这里插入图片描述
    在这里插入图片描述

    form.many2many_tags (FormFieldMany2ManyTags)
    form.many2many_tags widget 是form视图专用. 它有一些额外的代码来允许编辑标签的颜色.
    支持的字段类型: many2many
    kanban.many2many_tags (KanbanFieldMany2ManyTags)
    kanban.many2many_tags widget 是kanban 视图专用.
    支持的字段类型: many2many
    many2many_checkboxes (FieldMany2ManyCheckBoxes)
    此字段显示一个checkboxes列表并且允许用户选择一个子项。请注意,显示的值限定在100个以内,且不可调整,它只允许处理极端情况,基于这些情况,列表视图更合适,因为它允许分页和过滤
    支持的字段类型: many2many
    one2many (FieldOne2Many)
    它通常在子列表视图或子看板视图中显示数据
    支持的字段类型: one2many
    选项:
    create: domain([[‘some_other_field’, ‘>’, 24]])决定是否可以创建记录 (默认: True).
    delete: domain 决定是否可以删除记录 (默认: True).

    <field name="turtles" options="{'create': [['some_other_field', '>', 24]]}"/>
    
    • 1

    create_text: 用于自定义“添加”标签/文本的字符串,注意用到了转义字符

    <field name="turtles" options="{\'create_text\': \'Add turtle\'}">
    
    • 1

    statusbar (FieldStatus)
    只适用于 form 视图. 为工作流的显示条,允许选择一个特定的状态
    支持的字段类型: selection, many2one
    reference (FieldReference)
    FieldReference是select(用于模型)和FieldManyOne(用于其值)的组合。它允许在任意模型上选择记录。
    支持的字段类型: char, reference
    选项:
    model_field: 包含可选择记录模型的FieldManyOne(“ir.model”)的名称
    设置此选项时,不会显示FieldReference的select部分。

    Widgets
    week_days (WeekDays)
    此字段显示一个星期的复选框列表,每天显示一个复选框,并允许用户选择选项的子集。

    <widget name="week_days">
    
    • 1

    客户端动作
    客户端操作的概念是一个集成在web client界面中的定制小部件,就像 act_window_action. 当您需要与现有视图或特定模型没有紧密链接的构件时,这非常有用. 例如, “讨论应用程序”(Discuss程序)实际上是一个客户端操作.
    client action 是一个具有多种含义的术语,依赖如下上下文:

    • 从服务器的角度来看,它是模型ir_action的记录,带有char类型的字段标记
    • 从web client的角度来讲,它是一个widget,继承自 AbstractAction类,

    并且应该在操作注册表中相应键下注册(来自字段char)
    Adding a client action增加一个client action
    客户端操作是一个widget,它将控制菜单栏下方的屏幕部分。如有必要,它可以有一个控制面板。定义客户端操作可以分为两个步骤:实现新的widget和在操作注册表中注册widget。
    控制面板:
    在这里插入图片描述
    执行一个新的client action.通过创建一个widget来实现

    var AbstractAction = require('web.AbstractAction');
    
    var ClientAction = AbstractAction.extend({
        hasControlPanel: true,
        ...
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    Registering the client action注册client action
    As usual, we need to make the web client aware of the mapping between client actions and the actual class:
    通常情况下,我们需要确保web client

    var core = require('web.core');
    
    core.action_registry.add('my-custom-action', ClientAction);
    
    • 1
    • 2
    • 3

    然后,要在web client中使用client action,我们需要创建一条client action记录(模型ir.actions.client中的记录)并配以合适的tag属性:

    <record id="my_client_action" model="ir.actions.client">
        <field name="name">Some Name</field>
        <field name="tag">my-custom-action</field>
    </record>
    
    • 1
    • 2
    • 3
    • 4

    Using the control panel 使用控制面板
    默认情况下,客户端操作不显示控制面板。为了做到这一点,应该执行几个步骤.

    在下面的代码中,设置 hasControlPanel 为 true.

    var MyClientAction = AbstractAction.extend({
        hasControlPanel: true,
        loadControlPanel: true, // default: false
        ...
    });
    
    • 1
    • 2
    • 3
    • 4
    • 5

    警告:
    当 loadControlPanel 设为 true, client action 将自动获取搜索视图或控制面板视图的内容 ,在这个例子中, 模型名字要像这样指定:

    init: function (parent, action, options) {
        ...
        this.controlPanelParams.modelName = 'model.name';
        ...
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 每当我们需要更新控制面板 ,需要调取updateControlPanel . 例如:
    var SomeClientAction = Widget.extend({
        hasControlPanel: true,
        ...
        start: function () {
            this._renderButtons();
            this._update_control_panel();
            ...
        },
        do_show: function () {
             ...
             this._update_control_panel();
        },
        _renderButtons: function () {
            this.$buttons = $(QWeb.render('SomeTemplate.Buttons'));
            this.$buttons.on('click', ...);
        },
        _update_control_panel: function () {
            this.updateControlPanel({
                cp_content: {
                   $buttons: this.$buttons,
                },
            });
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    其他应用(鼠标掠过头像,在旁边显示放大图):

    ![(https://img-blog.csdnimg.cn/c9c2833e3fc742e3869d569e8e09dd15.png)

                                   中亿丰数字  姜振建
    
    • 1
  • 相关阅读:
    蓝桥杯 vector
    苏州空天信息研究院前端一面
    【VS2022 编译UE5.1 错误 C4834 】
    MySQL之CRUD
    『互联网架构』埋点基础知识
    计算机网络考研笔记
    JavaScript基础知识13——运算符:一元运算符,二元运算符
    (179)Verilog HDL:设计一个数字表之Exams/ece241 2014 q7b
    SpringCloud 服务治理:Eureka、Consul、Nacos
    MongoDB初识(一)
  • 原文地址:https://blog.csdn.net/weixin_44565926/article/details/126058662