首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在js文件odoo 9中重写

如何在js文件odoo 9中重写
EN

Stack Overflow用户
提问于 2016-12-08 14:52:06
回答 1查看 943关注 0票数 0

我需要在下面的函数中覆盖ASC到DESC

代码语言:javascript
复制
render: function (messages, options) {
        clearTimeout(this.auto_render_timeout);
        var self = this;
        var msgs = _.map(messages, this._preprocess_message.bind(this));
        if (this.options.display_order === ORDER.ASC) {
            msgs.reverse();
        }

源代码:https://postimg.org/image/9mxw6ksy7/67729f63/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-09 03:29:14

您需要替换该函数,然后调用_super()。将方法包含在实现此函数的类中。一个类似的问题发布在HERE上,具体的实现已经过测试。我下面的例子还没有经过充分的测试。请记住安装您的插件并更新它以查看您的更改。

代码语言:javascript
复制
}
'name': "asc_desc",

'summary': """
    Short (1 phrase/line) summary of the module's purpose, used as
    subtitle on modules listing or apps.openerp.com""",

'description': """
    Long description of module's purpose
""",

'author': "My Company",
'website': "http://www.yourcompany.com",

# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',

# any module necessary for this one to work correctly
'depends': ['base'],

# always loaded
'data': [
    # 'security/ir.model.access.csv',
    'views.xml',
    'templates.xml',
    'javascript_import.xml',
],
# only loaded in demonstration mode
'demo': [
    'demo.xml',
],
}

javascript_import.xml

代码语言:javascript
复制
 <?xml version="1.0" encoding="UTF-8"?>
 <openerp>
     <data>
         <template id="assets_backend_asc_desc" name="assets_backend_asc_desc" inherit_id="web.assets_backend">
             <xpath expr="script[last()]" position="after">
                 <script type="text/javascript" src="/asc_desc/static/src/js/asc.js"></script>
             </xpath>
         </template>
     </data>
 </openerp>

asc.js

代码语言:javascript
复制
odoo.define('asc_desc.ChatThread', function(require){
"use strict"
var core = require('web.core');
var QWeb = core.qweb;
var thread = require('mail.ChatThread');

var ORDER = {
    DESC: -1,
    ASC: 1,
}

thread.include({
    render: function (messages, options) {
        console.log("TEST");
        var msgs = _.map(messages, this._preprocess_message.bind(this));
        if (this.options.display_order === ORDER.DESC) {
            msgs.reverse();
        }
        options = _.extend({}, this.options, options);

        // Hide avatar and info of a message if that message and the previous
        // one are both comments wrote by the same author at the same minute
        var prev_msg;
        _.each(msgs, function (msg) {
            if (!prev_msg || (Math.abs(msg.date.diff(prev_msg.date)) > 60000) || prev_msg.message_type !== 'comment' || msg.message_type !== 'comment' || (prev_msg.author_id[0] !== msg.author_id[0])) {
                msg.display_author = true;
            } else {
                msg.display_author = !options.squash_close_messages;
            }
            prev_msg = msg;
        });

        this.$el.html(QWeb.render('mail.ChatThread', {
            messages: msgs,
            options: options,
            ORDER: ORDER,
        }));
    },

});

});

确保在__openerp__.py文件中包含声明js的文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41042275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档