【问题标题】:How to customize the OpenERP 6.1 WebClient HTML DOM?如何自定义 OpenERP 6.1 WebClient HTML DOM?
【发布时间】:2012-07-02 20:50:30
【问题描述】:

OpenERP web 客户端的页面可以变得非常宽,列表视图中有很多列。在短屏幕上,这是一个麻烦,因为居中的菜单与内容一起无法到达右侧。我决定快速解决这个问题:使菜单左对齐。对于普通的网站,这对于标准的 JQuery 来说是小菜一碟,但是这个 OpenERP web 的东西几乎完全是用 JS 生成的!

生成的 HTML 具有以下菜单结构:

<div class="menu" id="oe_menu">
  <table align="left">
    <tbody>
      <tr>
        <td>
          <a href="#" data-menu="3">
            Settings
          </a>
        </td>
        <!--other menus...-->
      </tr>
    </tbody>
  </table>
</div>

使用 JQuery 的方式是(在 JS 控制台中测试):

$('div.menu table[align=center]').attr('align','left');

虽然通常的$(document).ready()会失败,因为加载DOM的时间只是OpenERP web客户端的初始化。

我的要求是这需要从一个模块中进行管理。 Simahawk 得到了类似主题的答案 - hooking into the logout event,它为我指明了正确的方向,但没有解决我的任务。

【问题讨论】:

    标签: javascript jquery css dom openerp


    【解决方案1】:

    我从 web_livechat 模块中找到并修改了一段代码,最终成功了。我的模块名为camara,这很重要,因为 openerp 对象的新方法必须在您的模块之后调用 - static/src/js/tweaks.js:

    // openerp.camara(openerp) is executed when the module is loaded - UI is not rendered yet!
    
    openerp.camara = function(openerp) {
    
        // so we hook into (override) the Header do_update() call 
        // which is executed upon session validation by the WebClient
        // we have to call the overriden parent method
        // then we hook onto the update_promise 
        // which executes our code after the update is done.
    
        openerp.web.Header.include({
            do_update: function() {
            var self = this;
            this._super();
            this.update_promise.then(function() {
                // change menu alignment to the left
                // because with wide views, it runs out of reach
                $('div.menu table[align=center]').attr('align','left')
            });
            }
        });
    
    }
    

    js文件需要包含在__openerp__.py中:

    'js': ["static/src/js/tweaks.js"]
    

    剩下的问题:

    • 您喜欢这种方法并认为这是一种合适的方法吗?
    • 如果没有,请提供其他解决方案。

    我自己觉得这很笨拙,这就是我问的原因。我想过使用 CSS,但没有设法覆盖表格的 align 属性。

    【讨论】:

    猜你喜欢
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 2012-12-27
    • 2019-12-30
    • 2011-04-19
    • 2014-04-17
    相关资源
    最近更新 更多