[分享]view xml 中的 button 调用web客户端事件
- 
最近写一个模块 需要 在客户端干点事. 
 按常规的方法, 应该是写个 客户端模块. 在 客户端 init, start, render 去渲染个按钮出来干事.暂时还不太理解WEB模块如何很好地同服务器端通讯.
 所以, 还是使用传统的OE server 模块来干这事.
 OE 提供 ir.actions.client (客户端事件) 来让服务端与 客户端进行事件交互.
 所以, 只需要在 view xml 中. 添加个 button 并调用服务端事件, 然后 服务端返回一个 ir.actions.client 事件给客户端即可. 不知道哪位大大有更好的办法<br />....<br />        <button name="act_start" type="object" string="Start"/><br />....<br />
 然后 在对象中定义该对象 act_start 方法<br />....<br />    def act_start(self, cr, uid, ids, context=None):<br />        ret = {<br />            'type': 'ir.actions.client',<br />            'tag': 'my_sample.bt_start',<br />        }<br />        return ret<br />....<br />
 然后 在 模块JS文件中, 去定义JS部分的对象<br />....<br />openerp.my_sample = function (instance) {<br />    instance.web.client_actions.add('my_sample.bt_start', 'instance.my_sample .btn_start');<br />    instance.my_sample.btn_start = function(parent, action){<br />        var self = this;<br />        alert('test');<br />        // and do something...<br />        return false;<br />    };<br />};<br />....<br />
 这时候. 不出异常. 点击 按钮即可调用 btn_start 方法了...
- 
我也在关注 tag的作用,oe在这部分完全没介绍啊 
- 
[quote author=l315276651 link=topic=14690.msg28138#msg28138 date=1401933677] 
 目前我也遇到了这样的问题 ,
 我是通过 添加 html的input标签
 然后用js调用Python方法,
 但感觉很怪 ,你这样的方式 不错 ,只是有一个问题,
 怎么传递参数呢 如 ids
 [/quote]
 目前我也遇到了这样的问题 ,
 我是通过 添加 html的input标签
 然后用js调用Python方法,
 但感觉很怪 ,你这样的方式 不错 ,只是有一个问题,
 怎么传递参数呢 如 ids
 =============================================
 传递参数已经解决,代码如下instance.my_sample.btn_start = function(parent, action){<br />        var self = this;<br />        //id<br />        action.context.active_id<br />        //ids<br />        action.context.active_ids<br />        //_name<br />        action.context.active_model<br />        // 更多参数 请查看相关文档 或 用js调试 自行发掘<br />        alert('test');<br />        // and do something...<br />        return false;<br />    };
 =============================================
 自定义参数 传递方式 :<br />def act_start(self, cr, uid, ids, context=None):<br />        context={}<br />        context["key"]="value"<br />                <br />        ret = {<br />            'type': 'ir.actions.client',<br />            'tag': 'lcd_video.btnPerview',<br />            'context':context,<br />        }<br />        return ret<br />
