標籤:style blog color 使用 檔案 art
最近寫一個模組 需要 在用戶端幹點事.
按常規的方法, 應該是寫個 用戶端模組. 在 用戶端 init, start, render 去渲染個按鈕出來幹事.暫時還不太理解WEB模組如何很好地同伺服器端通訊.
所以, 還是使用傳統的OE server 模組來幹這事.
OE 提供 ir.actions.client (用戶端事件) 來讓服務端與 用戶端進行事件互動.
所以, 只需要在 view xml 中. 添加個 button 並調用服務端事件, 然後 服務端返回一個 ir.actions.client 事件給用戶端即可. 不知道哪位大大有更好的辦法
<button name="act_start" type="object" string="Start"/>
然後 在對象中定義該對象 act_start 方法
def act_start(self, cr, uid, ids, context=None): context={} context["key"]="value" ret = { ‘type‘: ‘ir.actions.client‘, ‘tag‘: ‘lcd_video.btnPerview‘, ‘context‘:context, } return ret
然後 在 模組JS檔案中, 去定義JS部分的對象
instance.my_sample.btn_start = function(parent, action){ var self = this; //id action.context.active_id //ids action.context.active_ids //_name action.context.active_model // 更多參數 請查看相關文檔 或 用js調試 自行發掘 alert(‘test‘); // and do something... return false; };這時候. 不出異常. 點擊 按鈕即可調用 btn_start 方法了...