跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. [分享]view xml 中的 button 调用web客户端事件

[分享]view xml 中的 button 调用web客户端事件

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
6 帖子 4 发布者 10.2k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • mrshellyM 离线
    mrshellyM 离线
    mrshelly
    写于 最后由 编辑
    #1

    最近写一个模块 需要 在客户端干点事.
    按常规的方法, 应该是写个 客户端模块. 在 客户端 init, start, render 去渲染个按钮出来干事.暂时还不太理解WEB模块如何很好地同服务器端通讯.

    所以, 还是使用传统的OE server 模块来干这事.
    OE 提供 ir.actions.client (客户端事件) 来让服务端与 客户端进行事件交互.

    所以, 只需要在 view xml 中. 添加个 button 并调用服务端事件, 然后 服务端返回一个 ir.actions.client 事件给客户端即可. 不知道哪位大大有更好的办法

    <br />....<br />&nbsp; &nbsp; &nbsp; &nbsp;  &lt;button name=&quot;act_start&quot; type=&quot;object&quot; string=&quot;Start&quot;/&gt;<br />....<br />
    



    然后 在对象中定义该对象 act_start  方法

    <br />....<br />&nbsp; &nbsp; def act_start(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; ret = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;type&#039;: &#039;ir.actions.client&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;tag&#039;: &#039;my_sample.bt_start&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; return ret<br />....<br />
    



    然后 在 模块JS文件中, 去定义JS部分的对象

    <br />....<br />openerp.my_sample = function (instance) {<br />&nbsp; &nbsp; instance.web.client_actions.add(&#039;my_sample.bt_start&#039;, &#039;instance.my_sample .btn_start&#039;);<br />&nbsp; &nbsp; instance.my_sample.btn_start = function(parent, action){<br />&nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; alert(&#039;test&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; // and do something...<br />&nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; };<br />};<br />....<br />
    



    这时候. 不出异常. 点击 按钮即可调用 btn_start 方法了...

    1 条回复 最后回复
    0
    • R 离线
      R 离线
      rufeng1199
      写于 最后由 编辑
      #2

      我也在关注  tag的作用,oe在这部分完全没介绍啊

      1 条回复 最后回复
      0
      • L 离线
        L 离线
        l315276651
        写于 最后由 编辑
        #3

        [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 />&nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; //id<br />&nbsp; &nbsp; &nbsp; &nbsp; action.context.active_id<br />&nbsp; &nbsp; &nbsp; &nbsp; //ids<br />&nbsp; &nbsp; &nbsp; &nbsp; action.context.active_ids<br />&nbsp; &nbsp; &nbsp; &nbsp; //_name<br />&nbsp; &nbsp; &nbsp; &nbsp; action.context.active_model<br />&nbsp; &nbsp; &nbsp; &nbsp; // 更多参数 请查看相关文档 或 用js调试 自行发掘<br />&nbsp; &nbsp; &nbsp; &nbsp; alert(&#039;test&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; // and do something...<br />&nbsp; &nbsp; &nbsp; &nbsp; return false;<br />&nbsp; &nbsp; };
        


        =============================================
        自定义参数 传递方式 :

        <br />def act_start(self, cr, uid, ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; context={}<br />&nbsp; &nbsp; &nbsp; &nbsp; context[&quot;key&quot;]=&quot;value&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ret = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;type&#039;: &#039;ir.actions.client&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;tag&#039;: &#039;lcd_video.btnPerview&#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;context&#039;:context,<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; return ret<br />
        
        1 条回复 最后回复
        0
        • mrshellyM 离线
          mrshellyM 离线
          mrshelly
          写于 最后由 编辑
          #4

          赞.................

          1 条回复 最后回复
          0
          • D 离线
            D 离线
            d_yang
            写于 最后由 编辑
            #5

            我是在wizard执行的最后一步来执行client action的。
            client action return false, wizard不会关闭的。

            可以

            <br /> return {&#039;type&#039;: &#039;ir.actions.act_window_close&#039;};<br />
            


            problem solved.

            1 条回复 最后回复
            0

            • 登录

            • 没有帐号? 注册

            • 登录或注册以进行搜索。
            • 第一个帖子
              最后一个帖子
            0
            • 版块
            • 标签
            • 热门
            • 用户
            • 群组