2012-07-02 62 views
3

OpenERP Web客戶端的頁面可以在列表視圖中顯示很多列。在短屏幕上,這是一個麻煩,因爲中心菜單的內容與右側無法觸及。我決定爲此找到一個快速修復:使菜單對齊到左側。對於普通的網站來說,這將是標準JQuery的一塊蛋糕,但是這個OpenERP網絡事物在JS中幾乎完全生成了!如何自定義OpenERP 6.1 WebClient HTML DOM?

生成的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指出我在正確的方向,但沒有解決我的任務。

回答

3

我發現並從其中最後工作的web_livechat模塊改性的一段代碼。我的模塊被稱爲camara,這是很重要的,因爲OpenERP的對象的新方法必須的模塊後,被稱爲 - 靜態/ 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屬性。

+1

是的,這是正確的。請考慮看看官方文檔這裏http://doc.openerp.com/trunk/developers/web/addons/也可能對您有用此http://planet.domsense.com/en/2012/01/openerp - 新的Web客戶端-6-1-JavaScript的鉤/這http://planet.domsense.com/en/2012/04/how-to-create-an-openerp-module-the-easy-way/ – simahawk

+0

謝謝Simahawk,我已經看過你的文章,很好的工作。 – Rbjz